@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

/* =============================================================================
   Autobalas Admin — design tokens & shell (matches chat.autobalas.com)
   ========================================================================== */
:root {
  color-scheme: light;

  /* Neutral ramp (cool slate) */
  --n-0: #ffffff;
  --n-50: #f3f8f6;
  --n-100: #eaf3f0;
  --n-150: #dce9e5;
  --n-200: #dce9e5;
  --n-300: #b9d0ca;
  --n-400: #94a9a3;
  --n-500: #71827d;
  --n-600: #526b64;
  --n-700: #2d4a42;
  --n-800: #183f37;
  --n-900: #102923;

  /* Brand green */
  --brand-50: #e9f8f5;
  --brand-100: #d2f1ed;
  --brand-200: #9bded7;
  --brand-500: #119c8f;
  --brand-600: #0d887c;
  --brand-700: #0b6d63;
  --brand-vivid: #25d366;

  /* Sidebar shell */
  --sidebar-bg: #062a24;
  --sidebar-hover: #0b3b33;
  --sidebar-text: #c7ddd7;
  --sidebar-muted: #8fb0a8;
  --sidebar-active: #119c8f;
  --sidebar-border: rgba(220, 233, 229, 0.12);

  /* Semantics */
  --primary: var(--brand-500);
  --primary-hover: var(--brand-600);
  --primary-active: var(--brand-700);
  --primary-soft: var(--brand-50);
  --primary-soft-border: var(--brand-200);
  --surface-app: #f3f8f6;
  --surface: #ffffff;
  --surface-sunken: #f3f8f6;
  --surface-hover: #eaf3f0;
  --text-primary: #102923;
  --text-secondary: #526b64;
  --text-muted: #71827d;
  --text-faint: #94a9a3;
  --border: #dce9e5;
  --border-subtle: #dce9e5;
  --border-strong: #b9d0ca;

  --success: #067647;
  --success-soft: #ecfdf3;
  --success-border: #abefc6;
  --error: #e1584f;
  --error-soft: #fef3f2;
  --error-border: #fecdca;
  --warning: #b7791f;
  --warning-soft: #fffaeb;
  --warning-border: #fedf89;
  --info: #119c8f;
  --info-soft: #e9f8f5;
  --info-border: #9bded7;
  --tag: #6941c6;
  --tag-soft: #f4f3ff;
  --tag-border: #d9d6fe;

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --text-2xs: 0.6875rem;
  --text-xs: 0.75rem;
  --text-sm: 0.8125rem;
  --text-base: 0.875rem;
  --text-md: 0.9375rem;
  --text-lg: 1.0625rem;
  --text-xl: 1.25rem;
  --text-2xl: 1.5rem;
  --text-3xl: 1.875rem;

  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;
  --space-12: 3rem;

  --radius-xs: 4px;
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --radius-full: 999px;

  --shadow-xs: 0 1px 2px rgba(6, 42, 36, 0.04);
  --shadow-sm: 0 6px 18px rgba(6, 42, 36, 0.07);
  --shadow-md: 0 10px 28px rgba(6, 42, 36, 0.08);
  --shadow-lg: 0 18px 46px rgba(6, 42, 36, 0.14);
  --shadow-xl: 0 24px 64px rgba(6, 42, 36, 0.22);
  --ring: 0 0 0 3px rgba(17, 156, 143, 0.18);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur: 180ms;
  --dur-slow: 280ms;

  --sidebar-w: 280px;
  --sidebar-w-collapsed: 84px;
  --mobile-header-h: 56px;
  --page-max: 1320px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--surface-app);
  color: var(--text-primary);
  font-size: var(--text-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
[hidden] { display: none !important; }
svg { display: block; }

/* =============================================================================
   LOGIN
   ========================================================================== */
.login-container {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-8);
  padding: var(--space-8);
  background:
    radial-gradient(circle at 20% 10%, rgba(17, 156, 143, 0.12), transparent 34%),
    var(--surface-app);
}
.login-card {
  width: 100%;
  max-width: 420px;
  padding: var(--space-10);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-6);
}
.login-logo .logo-img {
  width: min(300px, 100%);
  height: auto;
  max-height: 120px;
  object-fit: contain;
  padding: var(--space-3);
  border-radius: var(--radius-lg);
  background: #ffffff;
}
.login-admin-label {
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}
.login-form { text-align: left; }
.login-form .form-group { margin-bottom: var(--space-4); }
.login-form label {
  display: block;
  margin-bottom: var(--space-2);
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--text-secondary);
}
.login-form input {
  width: 100%;
  min-height: 44px;
  padding: 0 var(--space-3);
  font-family: inherit;
  font-size: var(--text-md);
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.login-form input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: var(--ring);
}
.input-wrapper { position: relative; }
.input-wrapper input { padding-right: 2.75rem; }
.toggle-visibility {
  position: absolute;
  right: var(--space-2);
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-1);
  background: none;
  border: 0;
  color: var(--text-muted);
  cursor: pointer;
}
.toggle-visibility:hover { color: var(--text-secondary); }
.toggle-visibility svg { width: 20px; height: 20px; }
.hint { display: block; margin-top: var(--space-2); font-size: var(--text-xs); }
.hint--error { color: var(--error); }
.login-footer { font-size: var(--text-xs); color: var(--text-muted); text-align: center; }

/* =============================================================================
   BUTTONS
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0 var(--space-4);
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 650;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease), border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-primary:active:not(:disabled) { background: var(--primary-active); }
.btn-secondary {
  background: var(--surface);
  color: var(--text-secondary);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-hover); color: var(--text-primary); }
.btn-danger {
  background: var(--error-soft);
  color: var(--error);
  border-color: var(--error-border);
}
.btn-danger:hover:not(:disabled) { background: var(--error); color: #fff; border-color: var(--error); }
.btn-lg { min-height: 48px; font-size: var(--text-md); }
.btn-block { width: 100%; }

/* =============================================================================
   LAYOUT
   ========================================================================== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  z-index: 100;
  top: 0;
  left: 0;
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  box-shadow: 8px 0 28px rgba(6, 42, 36, 0.16);
  transition: width var(--dur-slow) var(--ease), transform var(--dur-slow) var(--ease);
}
.sidebar.collapsed { width: var(--sidebar-w-collapsed); }

.sidebar-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  min-height: 118px;
  padding: var(--space-5) var(--space-5) var(--space-4);
  border-bottom: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-logo {
  width: 218px;
  max-width: 100%;
  height: 62px;
  object-fit: contain;
  background: transparent;
}
.sidebar.collapsed .sidebar-header { min-height: 92px; padding: var(--space-5) var(--space-3) var(--space-3); }
.sidebar.collapsed .sidebar-logo { width: 50px; height: 50px; }
.brand-subtitle {
  color: var(--sidebar-muted);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  text-align: center;
}
.sidebar.collapsed .brand-subtitle { display: none; }

.collapse-toggle {
  position: absolute;
  top: 82px;
  right: -16px;
  z-index: 101;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 50%;
  box-shadow: var(--shadow-sm);
  color: var(--sidebar-bg);
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.collapse-toggle:hover { background: var(--sidebar-active); color: #fff; }
.collapse-toggle svg { width: 16px; height: 16px; }

.sidebar-nav {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sidebar.collapsed .sidebar-nav { padding: var(--space-4) var(--space-2); align-items: center; }

.nav-btn {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 42px;
  padding: 0.65rem 0.85rem;
  border: 0;
  border-radius: 14px;
  background: transparent;
  font-family: inherit;
  font-size: var(--text-base);
  font-weight: 650;
  color: var(--sidebar-text);
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-align: left;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-btn svg { width: 20px; height: 20px; flex-shrink: 0; color: var(--sidebar-muted); transition: color var(--dur) var(--ease); }
.nav-btn:hover { background: var(--sidebar-hover); color: #fff; }
.nav-btn:hover svg { color: #fff; }
.nav-btn.active { background: var(--sidebar-active); color: #fff; box-shadow: 0 10px 24px rgba(17, 156, 143, 0.32); }
.nav-btn.active svg { color: #fff; }
.sidebar.collapsed .nav-btn { width: 40px; justify-content: center; padding: 0.65rem; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-3);
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}
.sidebar-product-footer {
  display: grid;
  gap: 2px;
  width: 100%;
  padding: 0.85rem 0.7rem;
  border: 1px solid var(--sidebar-border);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.06);
  text-align: center;
}
.sidebar-product-name { color: #fff; font-size: var(--text-md); font-weight: 850; text-transform: lowercase; }
.sidebar-product-version { color: var(--sidebar-muted); font-size: var(--text-xs); font-weight: 650; }
.sidebar.collapsed .sidebar-product-footer { padding: 0.85rem 0.4rem; }
.sidebar.collapsed .sidebar-product-name { font-size: var(--text-xs); }

.main-content {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  min-height: 100vh;
  background: var(--surface-app);
  transition: margin-left var(--dur-slow) var(--ease), width var(--dur-slow) var(--ease);
}
.main-content.expanded { margin-left: var(--sidebar-w-collapsed); width: calc(100% - var(--sidebar-w-collapsed)); }

.shell-topbar {
  position: sticky;
  top: 0;
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  min-height: 72px;
  padding: var(--space-4) var(--space-8);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 8px 24px rgba(6, 42, 36, 0.05);
}
.shell-eyebrow {
  margin: 0;
  color: var(--primary);
  font-size: var(--text-xs);
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.shell-topbar-title {
  margin: 0;
  color: var(--text-primary);
  font-size: var(--text-lg);
  font-weight: 800;
  letter-spacing: -0.018em;
}
.shell-topbar-actions { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.shell-owner-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  max-width: 320px;
  padding: 0.35rem 0.7rem 0.35rem 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  background: #fff;
  color: var(--text-secondary);
  box-shadow: var(--shadow-xs);
  font-size: var(--text-sm);
  font-weight: 700;
}
.owner-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--sidebar-active);
  color: #fff;
  font-size: var(--text-xs);
  font-weight: 800;
}
.shell-logout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: 40px;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--error-border);
  border-radius: var(--radius-full);
  background: var(--error-soft);
  color: var(--error);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: 750;
  cursor: pointer;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.shell-logout-btn svg { width: 18px; height: 18px; }
.shell-logout-btn:hover { background: var(--error); color: #fff; }

.page { max-width: var(--page-max); margin: 0 auto; padding: var(--space-8); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); margin-bottom: var(--space-4); }
.section-head h2 { margin: 0; font-size: var(--text-xl); font-weight: 800; letter-spacing: -0.018em; }

/* =============================================================================
   COMPONENTS
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}
.grid { display: grid; gap: var(--space-4); }
.grid.metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: var(--space-4); }
.metric { display: flex; gap: var(--space-3); align-items: center; }
.metric .icon {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--brand-50);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}
.metric .icon svg { width: 22px; height: 22px; }
.metric .metric-label { display: block; color: var(--text-muted); font-size: var(--text-sm); }
.metric .metric-value { font-size: var(--text-2xl); font-weight: 800; letter-spacing: -0.018em; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
thead th {
  text-align: left;
  font-size: var(--text-2xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--surface-hover); }
td.actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
td.actions .btn { min-height: 32px; padding: 0 var(--space-3); font-size: var(--text-xs); }
.empty { text-align: center; color: var(--text-muted); padding: var(--space-6); }
.muted { color: var(--text-muted); }
code {
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  background: var(--surface-sunken);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.1rem 0.3rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: 650;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge.success { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.badge.warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.badge.danger { background: var(--error-soft); color: var(--error); border-color: var(--error-border); }
.badge.info { background: var(--info-soft); color: var(--info); border-color: var(--info-border); }
.badge.neutral { background: var(--n-100); color: var(--text-secondary); border-color: var(--border); }
.badge.violet { background: var(--tag-soft); color: var(--tag); border-color: var(--tag-border); }

.form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--space-4); }
.form label { display: flex; flex-direction: column; gap: var(--space-2); font-size: var(--text-sm); font-weight: 600; color: var(--text-secondary); }
.form input, .form select, .form textarea {
  min-height: 40px;
  padding: 0 var(--space-3);
  font-family: inherit;
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
}
.form textarea { min-height: 72px; padding: var(--space-2) var(--space-3); resize: vertical; }
.form input:focus, .form select:focus, .form textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
.form .span-2 { grid-column: span 2; }

.notice {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--info-border);
  background: var(--info-soft);
  color: var(--info);
  font-size: var(--text-sm);
  margin-bottom: var(--space-4);
}
.notice.error { background: var(--error-soft); color: var(--error); border-color: var(--error-border); }
.notice.warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }

.toast {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: 1100;
  padding: var(--space-3) var(--space-5);
  background: var(--n-900);
  color: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--text-sm);
  font-weight: 600;
  animation: toast-in var(--dur) var(--ease);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* =============================================================================
   MOBILE
   ========================================================================== */
.mobile-header { display: none; }
.sidebar-overlay { display: none; }

@media (max-width: 767px) {
  .mobile-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 95;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--mobile-header-h);
    padding: 0 var(--space-2) 0 var(--space-1);
    background: #fff;
    box-shadow: 0 8px 22px rgba(6, 42, 36, 0.08);
    border-bottom: 1px solid var(--border);
  }
  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: var(--radius-md);
    color: var(--primary);
    cursor: pointer;
  }
  .mobile-menu-btn svg { width: 24px; height: 24px; }
  .mobile-brand { display: flex; align-items: center; }
  .mobile-brand .mobile-logo { height: 42px; width: auto; object-fit: contain; }

  .sidebar.mobile {
    width: min(86vw, 320px);
    transform: translateX(-100%);
    box-shadow: var(--shadow-xl);
  }
  .sidebar.mobile.open { transform: none; }
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 94;
    display: block;
    background: rgba(6, 42, 36, 0.48);
    backdrop-filter: blur(2px);
  }
  .collapse-toggle { display: none; }

  .main-content.mobile { margin-left: 0; width: 100%; padding-top: var(--mobile-header-h); }
  .shell-topbar { position: static; min-height: auto; padding: var(--space-4); align-items: flex-start; flex-direction: column; }
  .shell-owner-chip { display: none; }
  .page { padding: var(--space-4); }
  .grid.metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .form { grid-template-columns: 1fr; }
  .form .span-2 { grid-column: span 1; }
  .login-container { padding: var(--space-4); }
  .login-card { padding: var(--space-6); }
}
@media (max-width: 520px) {
  .grid.metrics { grid-template-columns: 1fr; }
  .page { padding: var(--space-3); }
}
