/* ============================================================
   LARROUDE AI ASSISTANT — DESIGN TOKENS
   Single source of truth for all visual properties.
   Import order: tokens.css -> base.css -> components.css
   ============================================================ */

:root {
  /* ---- NEUTRAL SCALE ---- */
  --color-neutral-0:    #ffffff;
  --color-neutral-50:   #f9f9f9;
  --color-neutral-100:  #f2f2f2;
  --color-neutral-150:  #ebebeb;
  --color-neutral-200:  #e0e0e0;
  --color-neutral-300:  #c7c7c7;
  --color-neutral-400:  #a3a3a3;
  --color-neutral-500:  #737373;
  --color-neutral-600:  #525252;
  --color-neutral-700:  #3d3d3d;
  --color-neutral-800:  #2a2a2a;
  --color-neutral-850:  #1f1f1f;
  --color-neutral-900:  #161616;
  --color-neutral-950:  #0d0d0d;

  /* ---- ACCENT (warm gold) ---- */
  --color-accent-50:  #fdf8ed;
  --color-accent-100: #f9edcf;
  --color-accent-200: #f3d98f;
  --color-accent-300: #ecbf4a;
  --color-accent-400: #e5a913;
  --color-accent-500: #c48e0e;
  --color-accent-600: #9b6f0a;

  /* ---- SEMANTIC ---- */
  --color-success-bg:     #e8f5e9;
  --color-success-text:   #1b5e20;
  --color-success-border: #4caf50;
  --color-warning-bg:     #fff8e1;
  --color-warning-text:   #e65100;
  --color-warning-border: #ffa726;
  --color-error-bg:       #fce4ec;
  --color-error-text:     #b71c1c;
  --color-error-border:   #e53935;
  --color-info-bg:        #e3f2fd;
  --color-info-text:      #0d47a1;
  --color-info-border:    #1e88e5;

  /* ---- CHART PALETTE ---- */
  --chart-1: #d4960a;   /* Primary gold (brand) */
  --chart-2: #6366f1;   /* Indigo */
  --chart-3: #0d9488;   /* Teal */
  --chart-4: #db2777;   /* Pink */
  --chart-5: #ea580c;   /* Orange */
  --chart-6: #8b5cf6;   /* Violet */
  --chart-7: #737373;   /* Gray (previous period only) */
  --chart-8: #ec4899;   /* Pink (extended) */
  --chart-9: #14b8a6;   /* Teal light (extended) */
  --chart-10: #f97316;  /* Amber (extended) */
  --chart-positive: #16a34a;
  --chart-negative: #dc2626;

  /* ---- EXTENDED SEMANTIC COLORS ---- */
  --color-purple-bg:   rgb(243 232 255);
  --color-purple-text: #7c3aed;
  --color-indigo-bg:   rgb(224 231 255);
  --color-indigo-text: #4f46e5;

  /* ---- SURFACES ---- */
  --surface-page:        var(--color-neutral-50);
  --surface-raised:      var(--color-neutral-0);
  --surface-overlay:     var(--color-neutral-0);
  --surface-sunken:      var(--color-neutral-100);
  --surface-interactive: var(--color-neutral-150);
  --surface-selected:    var(--color-accent-50);
  --surface-header-btn:       rgb(255 255 255 / 0.08);
  --surface-header-btn-hover: rgb(255 255 255 / 0.15);

  /* ---- TEXT ---- */
  --text-primary:   var(--color-neutral-900);
  --text-secondary: var(--color-neutral-500);
  --text-tertiary:  var(--color-neutral-400);
  --text-disabled:  var(--color-neutral-300);
  --text-inverse:   var(--color-neutral-0);
  --text-accent:    var(--color-accent-500);

  /* ---- BORDERS ---- */
  --border-subtle:  var(--color-neutral-150);
  --border-default: var(--color-neutral-200);
  --border-strong:  var(--color-neutral-400);
  --border-focus:   var(--color-accent-400);

  /* ---- TYPOGRAPHY ---- */
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Playfair Display', Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
  --text-xs:   0.6875rem;
  --text-sm:   0.8125rem;
  --text-base: 0.9375rem;
  --text-md:   1rem;
  --text-lg:   1.125rem;
  --text-xl:   1.25rem;
  --text-2xl:  1.5rem;
  --text-3xl:  1.875rem;
  --text-4xl:  2.25rem;
  --fw-regular:  400;
  --fw-medium:   500;
  --fw-semibold: 600;
  --fw-bold:     700;
  --lh-tight:  1.2;
  --lh-snug:   1.375;
  --lh-normal: 1.5;
  --ls-tight:  -0.02em;
  --ls-wide:   0.04em;
  --ls-caps:   0.08em;

  /* ---- SPACING (4px base) ---- */
  --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;
  --space-16: 4rem;

  /* ---- RADIUS ---- */
  --radius-xs:   2px;
  --radius-sm:   4px;
  --radius-md:   8px;
  --radius-lg:   12px;
  --radius-xl:   16px;
  --radius-2xl:  24px;
  --radius-full: 9999px;

  /* ---- SHADOWS ---- */
  --shadow-xs:  0 1px 2px 0 rgb(0 0 0 / 0.04);
  --shadow-sm:  0 1px 3px 0 rgb(0 0 0 / 0.06), 0 1px 2px -1px rgb(0 0 0 / 0.04);
  --shadow-md:  0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
  --shadow-lg:  0 10px 15px -3px rgb(0 0 0 / 0.08), 0 4px 6px -4px rgb(0 0 0 / 0.05);
  --shadow-xl:  0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.06);
  --shadow-focus: 0 0 0 3px rgb(229 169 19 / 0.3);

  /* ---- TRANSITIONS ---- */
  --dur-fast:   100ms;
  --dur-base:   200ms;
  --dur-slow:   350ms;
  --ease-out:   cubic-bezier(0.0, 0, 0.2, 1);
  --ease-inout: cubic-bezier(0.4, 0, 0.2, 1);

  /* ---- LAYOUT ---- */
  --sidebar-width:     260px;
  --sidebar-collapsed: 64px;
  --header-height:     56px;
  --content-max-width: 1200px;
  --grid-gap:          1.25rem;

  /* ---- Z-INDEX ---- */
  --z-base:     1;
  --z-raised:   10;
  --z-dropdown: 100;
  --z-sticky:   200;
  --z-overlay:  300;
  --z-modal:    400;
  --z-toast:    500;
}

/* ---- DARK MODE ---- */
[data-theme="dark"] {
  --surface-page:        var(--color-neutral-950);
  --surface-raised:      var(--color-neutral-900);
  --surface-overlay:     var(--color-neutral-850);
  --surface-sunken:      var(--color-neutral-800);
  --surface-interactive: var(--color-neutral-800);
  --surface-selected:    rgb(229 169 19 / 0.12);

  --text-primary:   var(--color-neutral-50);
  --text-secondary: var(--color-neutral-400);
  --text-tertiary:  var(--color-neutral-600);
  --text-disabled:  var(--color-neutral-700);
  --text-inverse:   var(--color-neutral-900);

  --border-subtle:  var(--color-neutral-800);
  --border-default: var(--color-neutral-700);
  --border-strong:  var(--color-neutral-500);

  --shadow-xs: 0 1px 2px 0 rgb(0 0 0 / 0.3);
  --shadow-sm: 0 1px 3px 0 rgb(0 0 0 / 0.4), 0 1px 2px -1px rgb(0 0 0 / 0.3);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.45), 0 2px 4px -2px rgb(0 0 0 / 0.3);

  --chart-8: #f472b6;
  --chart-9: #2dd4bf;
  --chart-10: #fb923c;
  --chart-positive: #4ade80;
  --chart-negative: #f87171;

  --color-purple-bg:   rgb(59 7 100 / 0.15);
  --color-purple-text: #a78bfa;
  --color-indigo-bg:   rgb(49 46 129 / 0.15);
  --color-indigo-text: #818cf8;

  --color-success-bg:     rgb(27 94 32 / 0.15);
  --color-success-text:   #66bb6a;
  --color-success-border: #388e3c;
  --color-warning-bg:     rgb(230 81 0 / 0.15);
  --color-warning-text:   #ffa726;
  --color-warning-border: #f57c00;
  --color-error-bg:       rgb(183 28 28 / 0.15);
  --color-error-text:     #ef5350;
  --color-error-border:   #d32f2f;
  --color-info-bg:        rgb(13 71 161 / 0.15);
  --color-info-text:      #42a5f5;
  --color-info-border:    #1976d2;
}

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

/* ============================================================
   BASE.CSS — Reset + shared structural styles
   ============================================================ */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--fw-regular);
  line-height: var(--lh-normal);
  color: var(--text-primary);
  background-color: var(--surface-page);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }
button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--color-accent-400);
  outline-offset: 2px;
}
:focus:not(:focus-visible) { outline: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* Skip link */
.skip-link {
  position: absolute;
  top: -100%;
  left: var(--space-4);
  z-index: var(--z-toast);
  padding: var(--space-2) var(--space-4);
  background: var(--color-neutral-900);
  color: var(--color-neutral-0);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  border-radius: var(--radius-md);
  transition: top var(--dur-fast) var(--ease-out);
}
.skip-link:focus { top: var(--space-4); }

/* Screen reader only */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ============================================================
   COMPONENTS.CSS — Shared UI components
   Cards, buttons, badges, inputs, tables, toasts, date picker
   ============================================================ */

/* ---- CARDS ---- */
.card {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-6);
  box-shadow: var(--shadow-sm);
}
.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-5);
  gap: var(--space-4);
}
.card__title {
  font-size: var(--text-base);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}
.card__subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}
.card__divider {
  height: 1px;
  background: var(--border-subtle);
  margin: var(--space-5) calc(-1 * var(--space-6));
}

/* ---- KPI CARDS ---- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--grid-gap);
}
@media (min-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (min-width: 1024px) {
  .kpi-grid { grid-template-columns: repeat(5, 1fr); }
}

.kpi-card {
  background: var(--surface-raised);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: var(--space-5) var(--space-6);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  transition: box-shadow var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.kpi-card:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
}
.kpi-card__header {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.kpi-card__icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: var(--surface-sunken);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  flex-shrink: 0;
}
.kpi-card__label {
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  flex: 1;
}
.kpi-card__body {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-3);
}
.kpi-card__value {
  display: flex;
  align-items: baseline;
  gap: var(--space-1);
  line-height: 1;
}
.kpi-card__currency {
  font-size: var(--text-base);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
}
.kpi-card__number {
  font-size: var(--text-2xl);
  font-weight: var(--fw-bold);
  color: var(--text-primary);
  letter-spacing: var(--ls-tight);
  font-variant-numeric: tabular-nums;
}
@media (min-width: 1024px) {
  .kpi-card__number { font-size: var(--text-3xl); }
}
.kpi-card__trend {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  flex-shrink: 0;
}
.kpi-card__trend-value {
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}
.kpi-card__trend-label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
}
.kpi-card__trend--up   .kpi-card__trend-value { color: var(--color-success-text); }
.kpi-card__trend--down .kpi-card__trend-value { color: var(--color-error-text); }
.kpi-card__trend--flat .kpi-card__trend-value { color: var(--text-secondary); }
.kpi-card__sparkline { height: 36px; margin-top: var(--space-1); }
.kpi-card__sparkline canvas { width: 100% !important; height: 36px !important; }

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  line-height: 1;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background-color var(--dur-base) var(--ease-out),
              color var(--dur-base) var(--ease-out),
              box-shadow var(--dur-base) var(--ease-out),
              transform var(--dur-fast) var(--ease-out);
  user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn--primary {
  background: var(--color-neutral-900);
  color: var(--color-neutral-0);
  border-color: var(--color-neutral-900);
}
.btn--primary:hover { background: var(--color-neutral-700); }
[data-theme="dark"] .btn--primary {
  background: var(--color-neutral-0);
  color: var(--color-neutral-900);
}
[data-theme="dark"] .btn--primary:hover { background: var(--color-neutral-200); }

.btn--secondary {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--border-default);
}
.btn--secondary:hover { background: var(--surface-sunken); border-color: var(--border-strong); }

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

.btn--accent {
  background: var(--color-accent-400);
  color: var(--color-neutral-900);
  font-weight: var(--fw-semibold);
}
.btn--accent:hover { background: var(--color-accent-300); }

.btn--sm { padding: calc(var(--space-1) + 2px) var(--space-3); font-size: var(--text-sm); }
.btn--lg { padding: var(--space-3) var(--space-6); font-size: var(--text-md); border-radius: var(--radius-lg); }
.btn--icon { padding: var(--space-2); width: 36px; height: 36px; }

.btn.is-loading { color: transparent; pointer-events: none; position: relative; }
.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- BADGES ---- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-wide);
  text-transform: uppercase;
  border-radius: var(--radius-full);
  white-space: nowrap;
  line-height: 1.6;
}
.badge--critical { background: var(--color-error-bg);   color: var(--color-error-text); }
.badge--high     { background: #fff0e6;                 color: #c05200; }
.badge--medium   { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge--low      { background: var(--color-info-bg);    color: var(--color-info-text); }
.badge--success  { background: var(--color-success-bg); color: var(--color-success-text); }
.badge--neutral  { background: var(--surface-sunken);   color: var(--text-secondary); }
[data-theme="dark"] .badge--high { background: rgb(192 82 0 / 0.15); color: #fb923c; }

/* Trend badges */
.trend-badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}
.trend-badge--up   { color: var(--color-success-text); }
.trend-badge--down { color: var(--color-error-text); }
.trend-badge--flat { color: var(--text-secondary); }

/* ---- FORM INPUTS ---- */
.form-field { display: flex; flex-direction: column; gap: var(--space-2); }
.form-label {
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  color: var(--text-primary);
}
.form-input {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  color: var(--text-primary);
  background: var(--surface-sunken);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  transition: border-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
  -webkit-appearance: none;
  appearance: none;
}
.form-input::placeholder { color: var(--text-tertiary); }
.form-input:hover { border-color: var(--border-strong); }
.form-input:focus {
  border-color: var(--border-focus);
  background: var(--surface-raised);
  box-shadow: var(--shadow-focus);
  outline: none;
}
.form-input--error { border-color: var(--color-error-border); }
.form-hint { font-size: var(--text-xs); color: var(--text-secondary); }
.form-hint--error { color: var(--color-error-text); }

/* ---- DATA TABLE ---- */
.table-wrapper {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.data-table th {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: var(--ls-caps);
  text-transform: uppercase;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-default);
  white-space: nowrap;
}
.data-table th.text-right { text-align: right; }
.data-table td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  vertical-align: middle;
}
.data-table td.text-right { text-align: right; font-variant-numeric: tabular-nums; }
.data-table td.text-bold { font-weight: var(--fw-semibold); }
.data-table tr:hover { background: var(--surface-interactive); }

/* Rank badges for tables */
.rank-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px; height: 24px;
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
}
.rank-badge--1 { background: #f9edcf; color: #9b6f0a; }
.rank-badge--2 { background: #f0f0f0; color: #525252; }
.rank-badge--3 { background: #fce8d8; color: #8b4513; }
[data-theme="dark"] .rank-badge--1 { background: rgb(155 111 10 / 0.25); color: #ecbf4a; }
[data-theme="dark"] .rank-badge--2 { background: rgb(115 115 115 / 0.25); color: #c7c7c7; }
[data-theme="dark"] .rank-badge--3 { background: rgb(139 69 19 / 0.25); color: #f0a070; }

/* Mini bar for percentage columns */
.mini-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}
.mini-bar__fill {
  height: 4px;
  background: var(--color-accent-300);
  border-radius: var(--radius-full);
  min-width: 4px;
  max-width: 80px;
  flex-shrink: 0;
  transition: width var(--dur-slow) var(--ease-out);
}
.mini-bar__label {
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  white-space: nowrap;
  font-size: var(--text-sm);
}

/* ---- DATE RANGE CONTROL ---- */
.date-range-control {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--surface-raised);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-full);
  padding: var(--space-1) var(--space-2);
  box-shadow: var(--shadow-xs);
}
.period-chips {
  display: flex;
  align-items: center;
  gap: 2px;
}
.period-chip { display: contents; }
.period-chip__input {
  position: absolute;
  opacity: 0;
  width: 0; height: 0;
}
.period-chip__label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  cursor: pointer;
  user-select: none;
  transition: background-color var(--dur-base) var(--ease-out), color var(--dur-base) var(--ease-out);
  white-space: nowrap;
}
.period-chip__label:hover { color: var(--text-primary); background: var(--surface-sunken); }
.period-chip__input:checked + .period-chip__label {
  background: var(--color-neutral-900);
  color: var(--color-neutral-0);
}
[data-theme="dark"] .period-chip__input:checked + .period-chip__label {
  background: var(--color-neutral-0);
  color: var(--color-neutral-900);
}
.period-chip__input:focus-visible + .period-chip__label {
  outline: 2px solid var(--color-accent-400);
  outline-offset: 2px;
}
.date-range-control__sep {
  width: 1px;
  height: 20px;
  background: var(--border-default);
  flex-shrink: 0;
}
.date-range-trigger {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--fw-medium);
  color: var(--text-secondary);
  background: none;
  border: none;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background-color var(--dur-base) var(--ease-out), color var(--dur-base) var(--ease-out);
  white-space: nowrap;
}
.date-range-trigger:hover { color: var(--text-primary); background: var(--surface-sunken); }
.date-range-trigger.is-active { background: var(--surface-selected); color: var(--text-accent); }

/* Flatpickr overrides */
.flatpickr-calendar {
  background: var(--surface-overlay) !important;
  border: 1px solid var(--border-default) !important;
  border-radius: var(--radius-xl) !important;
  box-shadow: var(--shadow-xl) !important;
  font-family: var(--font-sans) !important;
}
.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange {
  background: var(--color-neutral-900) !important;
  border-color: var(--color-neutral-900) !important;
  color: var(--color-neutral-0) !important;
}
.flatpickr-day.inRange {
  background: var(--surface-selected) !important;
  border-color: transparent !important;
}
.flatpickr-day:hover { background: var(--surface-interactive) !important; }
.flatpickr-months .flatpickr-month {
  background: var(--surface-overlay) !important;
  color: var(--text-primary) !important;
}

@media (max-width: 640px) {
  .date-range-control {
    flex-direction: column;
    align-items: stretch;
    border-radius: var(--radius-lg);
    gap: var(--space-2);
    padding: var(--space-2);
  }
  .date-range-control__sep { display: none; }
  .period-chips { justify-content: space-between; }
  .date-range-trigger { justify-content: center; }
}

/* ---- CHART CONTAINERS ---- */
.chart-container {
  position: relative;
  width: 100%;
}
.chart-container--sm { height: 200px; }
.chart-container--md { height: 280px; }
.chart-container--lg { height: 320px; }
@media (max-width: 768px) {
  .chart-container--lg { height: 260px; }
}

/* ---- DASHBOARD GRID ---- */
.dashboard-grid {
  display: grid;
  gap: var(--grid-gap);
}
.dashboard-grid--2col {
  grid-template-columns: 1fr;
}
@media (min-width: 768px) {
  .dashboard-grid--2col { grid-template-columns: repeat(2, 1fr); }
}

/* ---- PAGE HEADER ---- */
.page-header {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  margin-bottom: var(--space-6);
}
@media (min-width: 640px) {
  .page-header {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}
.page-header__title {
  font-size: var(--text-xl);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
}
.page-header__subtitle {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  margin-top: var(--space-1);
}

/* ---- TOAST ---- */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--color-neutral-900);
  color: var(--color-neutral-0);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  font-size: var(--text-sm);
  max-width: 360px;
  pointer-events: all;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast__message { flex: 1; line-height: var(--lh-snug); }
.toast--success { border-left: 3px solid var(--color-success-border); }
.toast--warning { border-left: 3px solid var(--color-warning-border); }
.toast--error   { border-left: 3px solid var(--color-error-border); }

/* ---- EMPTY STATE ---- */
.empty-state {
  text-align: center;
  padding: var(--space-12) var(--space-6);
  color: var(--text-secondary);
}
.empty-state__icon {
  font-size: 2.5rem;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}
.empty-state__title {
  font-size: var(--text-lg);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-2);
}
.empty-state__desc {
  font-size: var(--text-sm);
  max-width: 360px;
  margin: 0 auto;
}

/* ---- AVATAR ---- */
.avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-full);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  background: var(--color-neutral-900);
  color: var(--color-neutral-0);
}
.avatar--sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar--md { width: 36px; height: 36px; font-size: var(--text-sm); }
.avatar--lg { width: 44px; height: 44px; font-size: var(--text-base); }
[data-theme="dark"] .avatar {
  background: var(--color-neutral-0);
  color: var(--color-neutral-900);
}

/* ---- LOADING SKELETON ---- */
.skeleton {
  background: linear-gradient(90deg,
    var(--surface-sunken) 25%,
    var(--surface-interactive) 50%,
    var(--surface-sunken) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease infinite;
  border-radius: var(--radius-md);
}
@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ---- ICON SYSTEM ---- */
.icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  vertical-align: middle;
}
.icon svg {
  fill: currentColor;
  width: 1em;
  height: 1em;
}
.icon--sm svg { width: 0.875em; height: 0.875em; }
.icon--lg svg { width: 1.25em; height: 1.25em; }

/* ---- SEVERITY DOTS ---- */
.severity-dot {
  display: inline-block;
  width: 0.625em;
  height: 0.625em;
  border-radius: 50%;
}
.severity-dot--critical { background-color: var(--color-error-500, #ef4444); }
.severity-dot--high { background-color: var(--color-warning-500, #f97316); }
.severity-dot--medium { background-color: var(--color-warning-400, #fbbf24); }
.severity-dot--info { background-color: var(--color-success-500, #22c55e); }

/* ---- ENTRY ANIMATIONS ---- */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes slideInLeft {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

.anim-fade-in {
  animation: fadeIn var(--dur-slow) var(--ease-out) both;
}
.anim-slide-up {
  animation: slideUp var(--dur-slow) var(--ease-out) both;
}
.anim-slide-left {
  animation: slideInLeft var(--dur-slow) var(--ease-out) both;
}

/* Staggered delays for child elements */
.anim-stagger > :nth-child(1) { animation-delay: 0ms; }
.anim-stagger > :nth-child(2) { animation-delay: 50ms; }
.anim-stagger > :nth-child(3) { animation-delay: 100ms; }
.anim-stagger > :nth-child(4) { animation-delay: 150ms; }
.anim-stagger > :nth-child(5) { animation-delay: 200ms; }
.anim-stagger > :nth-child(6) { animation-delay: 250ms; }

