/* ============================================
   AIFied Dark Theme — Linear/Vercel-inspired
   Design system 2026
   ============================================ */

:root {
  /* ─── Surfaces (softer, warmer zinc palette — not pure black) ─── */
  --bg:            #0f1013;
  --surface-1:    #16171b;
  --surface-2:    #1c1d22;
  --surface-3:    #22232a;
  --surface-4:    #2a2b33;

  /* ─── Borders (visible enough to structure the UI) ─── */
  --border-subtle: #24252c;
  --border:        #2e2f38;
  --border-strong: #3a3c47;

  /* ─── Text ─── */
  --text-primary:   #f4f4f5;
  --text-secondary: #c9cad0;
  --text-tertiary:  #8b8c95;
  --text-disabled:  #5c5d65;

  /* ─── Brand accent (violet) ─── */
  --accent-50:  #f5f3ff;
  --accent-100: #ede9fe;
  --accent-200: #ddd6fe;
  --accent-300: #c4b5fd;
  --accent-400: #a78bfa;
  --accent-500: #8b5cf6;
  --accent-600: #7c3aed;
  --accent-700: #6d28d9;
  --accent-800: #5b21b6;
  --accent:      var(--accent-600);
  --accent-hover: var(--accent-500);
  --accent-glow: rgba(124, 58, 237, 0.15);

  /* ─── Semantic ─── */
  --success:      #22c55e;
  --success-bg:   rgba(34, 197, 94, 0.1);
  --danger:       #ef4444;
  --danger-bg:    rgba(239, 68, 68, 0.1);
  --warning:      #eab308;
  --warning-bg:   rgba(234, 179, 8, 0.1);
  --info:         #3b82f6;
  --info-bg:      rgba(59, 130, 246, 0.1);

  /* ─── Spacing scale (8px baseline) ─── */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-8: 32px;
  --sp-10: 40px;
  --sp-12: 48px;
  --sp-16: 64px;

  /* ─── Radius ─── */
  --r-sm: 6px;
  --r:    8px;
  --r-md: 10px;
  --r-lg: 12px;
  --r-xl: 16px;
  --r-2xl: 20px;
  --r-full: 9999px;

  /* ─── Shadows ─── */
  --shadow-sm:  0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow:     0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-md:  0 8px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg:  0 16px 48px rgba(0, 0, 0, 0.55);
  --glow-accent: 0 0 0 1px rgba(124, 58, 237, 0.4), 0 4px 16px rgba(124, 58, 237, 0.25);

  /* ─── Transitions ─── */
  --t-fast: 100ms cubic-bezier(0.16, 1, 0.3, 1);
  --t:      150ms cubic-bezier(0.16, 1, 0.3, 1);
  --t-slow: 250ms cubic-bezier(0.16, 1, 0.3, 1);

  /* ─── Fonts ─── */
  --font-sans: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, "JetBrains Mono", "SF Mono", Menlo, monospace;

  /* ─── Layout ─── */
  --sidebar-w: 240px;
  --header-h: 56px;

  /* ─── Type scale ─── */
  --fs-11: 11px;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-15: 15px;
  --fs-16: 16px;
  --fs-18: 18px;
  --fs-20: 20px;
  --fs-24: 24px;
  --fs-32: 32px;
  --fs-40: 40px;
  --fs-48: 48px;
}

/* ─── Reset + base ─── */
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: 1.5;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body { min-height: 100vh; }

img, video, iframe { max-width: 100%; height: auto; display: block; }

a { color: inherit; text-decoration: none; }
a:hover { color: var(--text-primary); }

button {
  font-family: inherit;
  border: 0;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 0;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--text-primary);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: var(--sp-2) var(--sp-3);
  transition: border-color var(--t), box-shadow var(--t);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
input::placeholder, textarea::placeholder { color: var(--text-tertiary); }

::selection { background: var(--accent-glow); color: var(--text-primary); }

/* Scrollbar */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--surface-4); border-radius: var(--r-full); border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ─── Layout primitives ─── */
.app-layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface-1);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: var(--sp-4);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-weight: 700;
  font-size: var(--fs-15);
  color: var(--text-primary);
  padding: var(--sp-2);
  margin-bottom: var(--sp-4);
  letter-spacing: -0.01em;
}
.sidebar-brand-mark {
  width: 22px; height: 22px;
  border-radius: var(--r-sm);
  background: var(--accent);
  display: grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 800;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r);
  color: var(--text-secondary);
  font-size: var(--fs-14);
  font-weight: 500;
  transition: background var(--t-fast), color var(--t-fast);
  cursor: pointer;
  position: relative;
}
.nav-item:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-item.active {
  background: var(--surface-2);
  color: var(--text-primary);
}
.nav-item .nav-icon {
  width: 16px; height: 16px;
  color: currentColor;
  opacity: 0.75;
  flex-shrink: 0;
}
.nav-item .nav-badge {
  margin-left: auto;
  font-size: var(--fs-11);
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--r-full);
  background: var(--danger);
  color: #fff;
  min-width: 18px;
  text-align: center;
}
.nav-item .kbd {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-tertiary);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--surface-2);
}

.sidebar-footer {
  margin-top: auto;
  padding-top: var(--sp-3);
  border-top: 1px solid var(--border-subtle);
}
.sidebar-user {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2);
  border-radius: var(--r);
  cursor: pointer;
  transition: background var(--t-fast);
}
.sidebar-user:hover { background: var(--surface-2); }
.sidebar-user-avatar {
  width: 28px; height: 28px;
  border-radius: var(--r-full);
  background: linear-gradient(135deg, var(--accent-500), var(--accent-700));
  display: grid; place-items: center;
  color: #fff; font-size: var(--fs-12); font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name {
  font-size: var(--fs-13); font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-plan {
  font-size: var(--fs-11); color: var(--text-tertiary);
  text-transform: uppercase; letter-spacing: 0.04em;
}

.nav-section {
  font-size: var(--fs-11);
  font-weight: 600;
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--sp-4) var(--sp-3) var(--sp-2);
}

/* ─── Main content ─── */
.main {
  padding: var(--sp-8);
  max-width: 1400px;
}
.main-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--sp-8);
}
.main-title {
  font-size: var(--fs-24);
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary);
}
.main-subtitle {
  font-size: var(--fs-13);
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ─── Card ─── */
.card {
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  transition: border-color var(--t);
}
.card:hover { border-color: var(--border); }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.card-title {
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--text-primary);
}
.card-sub {
  font-size: var(--fs-12);
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ─── KPI display (Linear-style big numbers) ─── */
.kpi {
  display: flex; flex-direction: column; gap: var(--sp-1);
}
.kpi-label {
  font-size: var(--fs-11);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.kpi-value {
  font-size: var(--fs-32);
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.kpi-delta {
  font-size: var(--fs-12);
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.kpi-delta.pos { color: var(--success); }
.kpi-delta.neg { color: var(--danger); }

/* ─── Buttons ─── */
.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: var(--sp-2) var(--sp-4);
  border-radius: var(--r);
  font-size: var(--fs-13);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), color var(--t-fast);
  border: 1px solid transparent;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--text-primary);
  color: var(--bg);
  font-weight: 600;
}
.btn-primary:hover { background: #fff; }

.btn-accent {
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}
.btn-accent:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--surface-3);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--surface-4); border-color: var(--border-strong); }

.btn-ghost {
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--surface-2); color: var(--text-primary); }

.btn-danger {
  color: var(--danger);
}
.btn-danger:hover { background: var(--danger-bg); }

.btn-sm { padding: 4px var(--sp-3); font-size: var(--fs-12); }
.btn-lg { padding: var(--sp-3) var(--sp-5); font-size: var(--fs-14); }

/* ─── Status dot ─── */
.dot {
  width: 6px; height: 6px;
  border-radius: var(--r-full);
  display: inline-block;
  flex-shrink: 0;
}
.dot-live {
  background: var(--success);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
  animation: pulse-live 1.6s ease-in-out infinite;
}
.dot-on   { background: var(--success); box-shadow: 0 0 6px rgba(34, 197, 94, 0.6); }
.dot-off  { background: var(--surface-4); }
.dot-warn { background: var(--warning); }
.dot-err  { background: var(--danger); }
@keyframes pulse-live {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6); }
  50%      { box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

/* ─── Chip / Badge ─── */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px var(--sp-2);
  border-radius: var(--r-full);
  font-size: var(--fs-11);
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--text-secondary);
}
.chip-accent { background: var(--accent-glow); color: var(--accent-300); border-color: transparent; }
.chip-success { background: var(--success-bg); color: var(--success); border-color: transparent; }
.chip-danger  { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.chip-warning { background: var(--warning-bg); color: var(--warning); border-color: transparent; }

/* ─── Table (dashboard-style dense list) ─── */
.table {
  width: 100%;
  border-collapse: collapse;
}
.table th, .table td {
  padding: var(--sp-3) var(--sp-4);
  text-align: left;
  border-bottom: 1px solid var(--border-subtle);
}
.table th {
  font-size: var(--fs-11);
  color: var(--text-tertiary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  background: var(--surface-1);
}
.table td { font-size: var(--fs-13); color: var(--text-secondary); }
.table tr:hover td { background: var(--surface-2); }
.table tr:last-child td { border-bottom: 0; }

/* ─── Toggle switch (dark) ─── */
.switch {
  position: relative;
  display: inline-block;
  width: 32px;
  height: 18px;
  cursor: pointer;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider {
  position: absolute; inset: 0;
  background: var(--surface-4);
  border-radius: var(--r-full);
  transition: background var(--t);
}
.switch-slider::before {
  content: '';
  position: absolute;
  height: 14px; width: 14px;
  left: 2px; top: 2px;
  background: var(--text-primary);
  border-radius: 50%;
  transition: transform var(--t);
}
.switch input:checked + .switch-slider { background: var(--accent); }
.switch input:checked + .switch-slider::before { transform: translateX(14px); }

/* ─── Divider ─── */
.divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--sp-4) 0;
}

/* ─── Grid utilities ─── */
.grid { display: grid; gap: var(--sp-4); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
@media (max-width: 900px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.flex { display: flex; gap: var(--sp-3); }
.flex-col { display: flex; flex-direction: column; gap: var(--sp-3); }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-1 { flex: 1; min-width: 0; }
.gap-1 { gap: var(--sp-1); }
.gap-2 { gap: var(--sp-2); }
.gap-4 { gap: var(--sp-4); }
.gap-6 { gap: var(--sp-6); }

/* ─── Text utilities ─── */
.text-primary { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-tertiary { color: var(--text-tertiary); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-accent  { color: var(--accent-400); }
.mono { font-family: var(--font-mono); }
.tabular { font-variant-numeric: tabular-nums; }
.tight { letter-spacing: -0.02em; }

/* ─── Mobile drawer ─── */
.mobile-menu { display: none; }
@media (max-width: 900px) {
  .app-layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    transform: translateX(-100%);
    transition: transform var(--t);
    z-index: 100;
  }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .sidebar-overlay {
    position: fixed; inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 99;
    display: none;
  }
  .sidebar-overlay.open { display: block; }
  .mobile-menu {
    display: inline-flex;
    align-items: center; justify-content: center;
    width: 36px; height: 36px;
    border-radius: var(--r);
  }
  .mobile-menu:hover { background: var(--surface-2); }
  .main { padding: var(--sp-4); }
}

/* ─── Toast ─── */
.toast-container {
  position: fixed; bottom: var(--sp-6); right: var(--sp-6);
  display: flex; flex-direction: column; gap: var(--sp-2);
  z-index: 1000;
  pointer-events: none;
}
.toast {
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-3) var(--sp-4);
  min-width: 240px;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in var(--t) both;
  font-size: var(--fs-13);
}
.toast.success { border-left: 2px solid var(--success); }
.toast.error   { border-left: 2px solid var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ─── Modal ─── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  z-index: 500;
  display: grid; place-items: center;
  padding: var(--sp-4);
  animation: fade-in var(--t) both;
}
.modal {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  max-width: 480px;
  width: 100%;
  padding: var(--sp-6);
  box-shadow: var(--shadow-lg);
  animation: modal-in var(--t) both;
}
.modal-header { margin-bottom: var(--sp-4); }
.modal-title  { font-size: var(--fs-18); font-weight: 700; color: var(--text-primary); }
.modal-sub    { font-size: var(--fs-13); color: var(--text-secondary); margin-top: 4px; }
.modal-body   { display: flex; flex-direction: column; gap: var(--sp-4); }
.modal-actions {
  display: flex; gap: var(--sp-2); justify-content: flex-end;
  margin-top: var(--sp-6);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }

/* ─── Field ─── */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label {
  font-size: var(--fs-12);
  font-weight: 500;
  color: var(--text-secondary);
}
.field-hint { font-size: var(--fs-12); color: var(--text-tertiary); }

/* ─── Empty state ─── */
.empty {
  text-align: center;
  padding: var(--sp-8) var(--sp-4);
  color: var(--text-tertiary);
  font-size: var(--fs-13);
}
