/* =========================================================================
   Sarya COGS dashboard — design system
   Two themes via [data-theme] on <html>; defaults to system preference.
   ======================================================================= */

:root {
  /* Spacing scale (4px base) */
  --s-1: 4px;  --s-2: 8px;  --s-3: 12px; --s-4: 16px;
  --s-5: 20px; --s-6: 24px; --s-7: 32px; --s-8: 48px;

  /* Radii */
  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;

  /* Fonts */
  --font-sans: "Inter", -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Semantic tokens (dark is the default) */
  --bg:          #060b1d;
  --bg-grad:     radial-gradient(1400px 800px at -10% -10%, #1b2b55 0%, transparent 60%),
                 radial-gradient(1200px 800px at 110% 110%, #0f3b4d 0%, transparent 55%),
                 linear-gradient(160deg, #060b1d 0%, #0b1328 100%);
  --surface:     #121a2d;
  --surface-2:   #182340;
  --surface-3:   #1f2b4e;
  --surface-glass: rgba(18, 26, 45, 0.78);
  --line:        #253156;
  --line-soft:   #1b2440;
  --text:        #e8ecf7;
  --text-2:      #c9d3f0;
  --muted:       #8891b4;
  --muted-2:     #5e6a90;
  --accent:      #6ea8ff;
  --accent-2:    #4ade80;
  --accent-grad: linear-gradient(135deg, #6ea8ff 0%, #4ade80 160%);
  --good:        #4ade80;
  --warn:        #fbbf24;
  --bad:         #f87171;
  --kpi-grad:    linear-gradient(135deg, rgba(110,168,255,.08) 0%, rgba(74,222,128,.05) 100%);
  --chart-grid:  #1e2846;
  --chart-text:  #8891b4;
  --shadow-sm:   0 1px 2px rgba(0,0,0,.3);
  --shadow:      0 10px 32px rgba(0,0,0,.3);
  --shadow-strong: 0 20px 60px rgba(0,0,0,.4);
}

/* Light theme — guarded so it only activates on explicit opt-in */
:root[data-theme="light"] {
  --bg:          #f6f8fc;
  --bg-grad:     radial-gradient(1400px 800px at -10% -10%, #e3edff 0%, transparent 60%),
                 radial-gradient(1200px 800px at 110% 110%, #e6f8ee 0%, transparent 55%),
                 linear-gradient(160deg, #f6f8fc 0%, #eef3fa 100%);
  --surface:     #ffffff;
  --surface-2:   #f3f6fb;
  --surface-3:   #e7edf6;
  --surface-glass: rgba(255,255,255,0.82);
  --line:        #e1e7f1;
  --line-soft:   #eef2f8;
  --text:        #0b1328;
  --text-2:      #253156;
  --muted:       #6b7490;
  --muted-2:     #99a2bd;
  --accent:      #2f6bff;
  --accent-2:    #16a34a;
  --accent-grad: linear-gradient(135deg, #2f6bff 0%, #16a34a 160%);
  --good:        #16a34a;
  --warn:        #d97706;
  --bad:         #dc2626;
  --kpi-grad:    linear-gradient(135deg, rgba(47,107,255,.04) 0%, rgba(22,163,74,.04) 100%);
  --chart-grid:  #e1e7f1;
  --chart-text:  #6b7490;
  --shadow-sm:   0 1px 2px rgba(15,23,42,.04);
  --shadow:      0 10px 32px rgba(15,23,42,.06);
  --shadow-strong: 0 20px 60px rgba(15,23,42,.1);
}

/* System-preference auto, only when the user hasn't picked a theme */
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) {
    --bg:          #f6f8fc;
    --bg-grad:     radial-gradient(1400px 800px at -10% -10%, #e3edff 0%, transparent 60%),
                   radial-gradient(1200px 800px at 110% 110%, #e6f8ee 0%, transparent 55%),
                   linear-gradient(160deg, #f6f8fc 0%, #eef3fa 100%);
    --surface:     #ffffff;
    --surface-2:   #f3f6fb;
    --surface-3:   #e7edf6;
    --surface-glass: rgba(255,255,255,0.82);
    --line:        #e1e7f1;
    --line-soft:   #eef2f8;
    --text:        #0b1328;
    --text-2:      #253156;
    --muted:       #6b7490;
    --muted-2:     #99a2bd;
    --accent:      #2f6bff;
    --accent-2:    #16a34a;
    --accent-grad: linear-gradient(135deg, #2f6bff 0%, #16a34a 160%);
    --good:        #16a34a;
    --warn:        #d97706;
    --bad:         #dc2626;
    --kpi-grad:    linear-gradient(135deg, rgba(47,107,255,.04) 0%, rgba(22,163,74,.04) 100%);
    --chart-grid:  #e1e7f1;
    --chart-text:  #6b7490;
    --shadow-sm:   0 1px 2px rgba(15,23,42,.04);
    --shadow:      0 10px 32px rgba(15,23,42,.06);
    --shadow-strong: 0 20px 60px rgba(15,23,42,.1);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { color-scheme: dark light; }
:root[data-theme="light"] { color-scheme: light; }

body {
  background: var(--bg); background: var(--bg-grad);
  color: var(--text); font-family: var(--font-sans);
  min-height: 100vh;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color .25s ease, color .25s ease;
  position: relative;
}
/* Subtle noise texture overlay for depth (no network cost: inline SVG) */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140' viewBox='0 0 140 140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 0.4 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)' opacity='.4'/></svg>");
  opacity: .14; mix-blend-mode: overlay;
}
:root[data-theme="light"] body::before { opacity: .22; mix-blend-mode: multiply; }
.topbar, main { position: relative; z-index: 1; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* -------- Topbar -------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--s-4) var(--s-6); background: var(--surface-glass);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; z-index: 50;
}
.brand {
  display: flex; align-items: center; gap: var(--s-3); font-size: 14px; letter-spacing: .2px;
  color: var(--text); text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-logo {
  height: 32px; width: auto; display: block;
  transition: filter .25s ease;
  /* Logo is dark line-art on transparent bg; invert for dark theme so it reads as white. */
  filter: invert(1) brightness(1.05);
}
:root[data-theme="light"] .brand-logo { filter: none; }
@media (prefers-color-scheme: light) {
  :root:not([data-theme]) .brand-logo { filter: none; }
}
:root[data-theme="dark"] .brand-logo { filter: invert(1) brightness(1.05); }
.brand .dot { opacity: .35; color: var(--muted); }
.brand span:last-child { color: var(--text-2); font-weight: 500; }
.topbar nav { display: flex; align-items: center; gap: var(--s-4); }
.topbar nav a {
  font-size: 13px; color: var(--muted); font-weight: 500;
  transition: color .15s;
}
.topbar nav a:hover { color: var(--text); text-decoration: none; }

/* Theme toggle button */
.theme-toggle {
  width: 36px; height: 36px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-2); font-size: 13px; font-weight: 700;
  transition: all .18s ease; padding: 0;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--accent); }
#themeToggle:hover { transform: rotate(15deg); }
.theme-toggle svg { width: 18px; height: 18px; }

/* Freshness pill in topbar */
.user-pill {
  display: inline-flex; align-items: center; padding: 5px 12px;
  border-radius: var(--r-pill); background: var(--surface-2);
  border: 1px solid var(--line); font-size: 12px; font-weight: 600;
  color: var(--text-2); letter-spacing: .2px;
}
@media (max-width: 640px) { .user-pill { display: none; } }

.fresh-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 10px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid var(--line);
  font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .2px;
  cursor: default;
}
.fresh-pill .fresh-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--good); box-shadow: 0 0 0 3px rgba(74, 222, 128, .18);
  animation: pulse-dot 2.4s ease-in-out infinite;
}
.fresh-pill.stale .fresh-dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(251, 191, 36, .18); }
.fresh-pill.old   .fresh-dot { background: var(--bad);  box-shadow: 0 0 0 3px rgba(248, 113, 113, .18); }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }
@media (max-width: 640px) { .fresh-pill .fresh-text { display: none; } }

/* Help / shortcuts overlay */
.help-overlay {
  position: fixed; inset: 0; background: rgba(6,11,29,.6);
  backdrop-filter: blur(6px); z-index: 100; display: none;
  align-items: flex-start; justify-content: center;
  padding: 10vh 16px 0;
  animation: cmdk-fade .18s ease both;
}
.help-overlay.open { display: flex; }
.help-card {
  width: 100%; max-width: 640px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-strong); animation: cmdk-rise .22s cubic-bezier(.2,.7,.3,1) both;
  padding: var(--s-5) var(--s-6);
}
.help-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--s-4); }
.help-head h3 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: -.2px; }
.help-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4) var(--s-5); }
@media (max-width: 640px) { .help-grid { grid-template-columns: 1fr; } }
.help-group h4 { margin: 0 0 var(--s-2); font-size: 10px; letter-spacing: 1px; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.help-row { display: flex; align-items: center; gap: var(--s-2); padding: 6px 0; font-size: 12px; color: var(--text-2); }
kbd {
  display: inline-block; padding: 2px 7px; min-width: 22px; text-align: center;
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 5px; color: var(--text); box-shadow: 0 1px 0 var(--line);
}
.help-chip { display: inline-block; padding: 2px 8px; font-size: 10px; letter-spacing: .5px; text-transform: uppercase; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-pill); color: var(--muted); font-weight: 600; }
.help-foot { font-size: 12px; color: var(--muted); line-height: 1.5; }
.help-foot strong { color: var(--text-2); }

main { max-width: 1600px; margin: var(--s-6) auto; padding: 0 var(--s-6) var(--s-8); }
@media (max-width: 640px) {
  main { padding: 0 var(--s-4) var(--s-7); margin: var(--s-4) auto; }
  .topbar { padding: var(--s-3) var(--s-4); }
}

/* -------- Buttons -------- */
button, .btn-primary, .btn-ghost {
  font-family: var(--font-sans); font-size: 13px; font-weight: 600;
  padding: 10px 16px; border-radius: var(--r-sm); border: 1px solid transparent;
  cursor: pointer; transition: all .15s ease; letter-spacing: .2px;
  display: inline-flex; align-items: center; gap: var(--s-2);
}
.btn-primary {
  background: var(--accent-grad); color: #fff;
  box-shadow: 0 6px 18px rgba(47, 107, 255, .25);
}
:root:not([data-theme="light"]) .btn-primary { color: #061024; }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 10px 24px rgba(47, 107, 255, .32); }
.btn-ghost { background: var(--surface); color: var(--text-2); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
button:disabled { opacity: .55; cursor: wait; transform: none !important; }
button[hidden], [hidden] { display: none !important; }

/* -------- View tabs -------- */
.viewtabs {
  display: flex; align-items: center; gap: 2px; margin-bottom: var(--s-5);
  padding-bottom: 2px; border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.tab {
  background: transparent; color: var(--muted); border: none;
  border-bottom: 2px solid transparent; border-radius: 0;
  padding: 10px 18px 14px; font-weight: 600; font-size: 13px;
  letter-spacing: .2px; cursor: pointer; transition: color .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab-sub { color: var(--muted); font-weight: 400; margin-left: 6px; font-size: 12px; }
.tab.active .tab-sub { color: var(--accent); opacity: .9; }
.viewtabs-meta {
  margin-left: auto; color: var(--muted); font-size: 11px;
  letter-spacing: .3px; padding-right: var(--s-2);
}
.viewtabs-meta strong { color: var(--text-2); font-weight: 600; }
.pill {
  display: inline-block; padding: 2px 10px; border-radius: var(--r-pill);
  background: rgba(251, 191, 36, .14); color: var(--warn);
  font-size: 10px; letter-spacing: .5px; text-transform: uppercase; font-weight: 600;
}
.view.hidden { display: none; }
@media (max-width: 820px) { .viewtabs-meta { display: none; } }

/* -------- Floating pill-style control bar -------- */
.controls { margin-bottom: var(--s-5); }
.controls-row {
  display: flex; align-items: center; gap: var(--s-3); flex-wrap: wrap;
  background: var(--surface-glass);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--line);
  border-radius: var(--r-pill); padding: 10px 14px;
  box-shadow: var(--shadow);
}
.ctrl {
  display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 14px 6px 12px; border-radius: var(--r-pill);
  background: var(--surface-2); border: 1px solid transparent;
  transition: all .18s ease; cursor: pointer;
}
.ctrl:hover { background: var(--surface-3); border-color: var(--line); transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.ctrl:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,107,255,.15); }
.ctrl .ctrl-ico {
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  color: var(--accent); font-size: 14px; flex-shrink: 0;
}
.ctrl .ctrl-text { display: flex; flex-direction: column; line-height: 1.1; gap: 0; }
.ctrl .ctrl-label {
  font-size: 9px; letter-spacing: .8px; color: var(--muted);
  text-transform: uppercase; font-weight: 700;
}
.ctrl select, .ctrl input {
  background: transparent; color: var(--text); border: none;
  padding: 0; font-size: 13px; font-weight: 600;
  font-family: var(--font-sans); letter-spacing: 0; text-transform: none;
  width: auto; min-width: 60px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
}
.ctrl select:focus, .ctrl input:focus { outline: none; }
.ctrl.has-select { padding-right: 24px; position: relative; }
.ctrl.has-select::after {
  content: "⌄"; position: absolute; right: 10px; top: 50%;
  transform: translateY(-60%); color: var(--muted); font-size: 14px; pointer-events: none;
}

/* -------- Custom select dropdown (replaces native <select>) -------- */
.cs-wrap { position: relative; display: inline-block; }
.cs-trigger {
  background: transparent; border: none; color: var(--text);
  font-size: 13px; font-weight: 600; font-family: var(--font-sans);
  cursor: pointer; padding: 0; letter-spacing: 0; min-width: 70px; text-align: left;
}
.cs-panel {
  /* position:fixed so we escape stacking contexts from backdrop-filter parents.
     Coordinates get set in JS from getBoundingClientRect(). */
  position: fixed;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow-strong);
  z-index: 2000; min-width: 240px; max-height: 420px; overflow-y: auto;
  padding: 6px;
  opacity: 0; visibility: hidden; transform: translateY(-6px) scale(.98);
  transform-origin: top left;
  transition: opacity .16s ease, transform .16s cubic-bezier(.2,.7,.3,1), visibility 0s linear .16s;
}
/* Panel lives on <body>, so target it directly with its own .open class */
.cs-panel.open {
  opacity: 1; visibility: visible; transform: translateY(0) scale(1);
  transition: opacity .16s ease, transform .16s cubic-bezier(.2,.7,.3,1), visibility 0s;
}
.cs-group {
  padding: 10px 12px 6px; font-size: 10px; letter-spacing: 1.2px;
  color: var(--muted); font-weight: 700; text-transform: uppercase;
  position: sticky; top: -6px;  /* match .cs-panel's 6px padding */
  background: var(--surface);
  border-bottom: 1px solid var(--line-soft);
  margin: 0 -6px;  /* bleed to the panel edges so sticky bg is solid */
  padding-left: 18px; padding-right: 18px;
  z-index: 2;
}
.cs-group:first-child { padding-top: 6px; }
.cs-opt {
  padding: 8px 12px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  cursor: pointer; color: var(--text-2); font-size: 13px;
  transition: background .1s;
}
.cs-opt:hover, .cs-opt.highlight { background: var(--surface-2); color: var(--text); }
.cs-opt.selected {
  background: var(--accent); color: #fff; font-weight: 600;
}
:root:not([data-theme="light"]) .cs-opt.selected { color: #061024; }
.cs-opt .cs-check {
  width: 14px; height: 14px; opacity: 0; transition: opacity .1s;
}
.cs-opt.selected .cs-check { opacity: 1; }
.cs-opt .cs-tag { font-size: 10px; color: var(--muted); font-weight: 500; }
.cs-opt.selected .cs-tag { color: inherit; opacity: .8; }

/* Scrollbar inside dropdown */
.cs-panel::-webkit-scrollbar { width: 6px; }
.cs-panel::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
.controls-actions { margin-left: auto; display: flex; gap: var(--s-2); align-items: center; }
.controls-actions .fab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 18px; border-radius: var(--r-pill);
  font-size: 13px; font-weight: 600; letter-spacing: .2px; cursor: pointer;
  transition: all .18s ease; border: 1px solid transparent;
  font-family: var(--font-sans);
}
.controls-actions .fab-primary {
  background: var(--accent-grad); color: #fff;
  box-shadow: 0 6px 20px rgba(47,107,255,.3);
}
:root:not([data-theme="light"]) .controls-actions .fab-primary { color: #061024; }
.controls-actions .fab-primary:hover { transform: translateY(-2px); box-shadow: 0 10px 28px rgba(47,107,255,.4); }
.controls-actions .fab-ghost {
  background: var(--surface-2); color: var(--text-2); border-color: var(--line);
}
.controls-actions .fab-ghost:hover { border-color: var(--accent); color: var(--accent); transform: translateY(-1px); }
.controls-actions .fab-icon {
  width: 38px; height: 38px; padding: 0; justify-content: center; font-size: 15px;
}

/* Toast notification */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface); color: var(--text);
  border: 1px solid var(--line); box-shadow: var(--shadow-strong);
  padding: 12px 20px; border-radius: var(--r-pill); font-size: 13px; font-weight: 500;
  z-index: 200; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast .toast-ico { color: var(--good); margin-right: 8px; }

/* -------- Preset chips -------- */
.chip-row {
  display: flex; gap: var(--s-2); flex-wrap: wrap;
  margin-top: var(--s-3);
}
.chip {
  padding: 6px 14px; border-radius: var(--r-pill);
  background: var(--surface); border: 1px solid var(--line);
  color: var(--muted); font-size: 12px; font-weight: 500;
  cursor: pointer; transition: all .15s ease;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.active {
  background: var(--accent); color: #fff; border-color: var(--accent);
}
:root:not([data-theme="light"]) .chip.active { color: #061024; }
@media (max-width: 820px) {
  .controls-row { border-radius: var(--r-md); padding: var(--s-3); }
  .ctrl { flex: 1 1 auto; }
  .controls-actions { width: 100%; margin-left: 0; justify-content: stretch; }
  .controls-actions .fab { flex: 1; justify-content: center; }
  .controls-actions .fab-icon { flex: 0 0 38px; }
}

/* -------- KPI grid -------- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: var(--s-3); margin: var(--s-5) 0;
}
.kpi {
  position: relative;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s-5) var(--s-5);
  box-shadow: var(--shadow-sm);
  transition: transform .18s ease, border-color .18s, box-shadow .18s;
}
.kpi:hover {
  transform: translateY(-3px); border-color: var(--accent); box-shadow: var(--shadow);
  z-index: 10;  /* so the hovered card's popover sits over its neighbours */
}
/* Subtle 3D tilt on hover — reads as "crafted" without being disorienting */
.kpi { perspective: 800px; }
.kpi:hover .kpi-value { transform: translateZ(2px); }
.kpi .kpi-value { transition: transform .25s cubic-bezier(.2,.7,.3,1); }
/* Hero number: gradient text + larger size */
.kpi.hero .kpi-value {
  font-size: 36px; letter-spacing: -1px;
  background: var(--accent-grad);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.kpi.hero .kpi-value .unit { color: var(--muted); -webkit-text-fill-color: var(--muted); margin-right: 8px; }
.kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--accent); opacity: .8;
  border-radius: var(--r-md) 0 0 var(--r-md);
}
.kpi.accent-good::before { background: var(--good); }
.kpi.accent-warn::before { background: var(--warn); }
.kpi.accent-bad::before  { background: var(--bad); }

.kpi-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: var(--s-2);
}
.kpi-label {
  font-size: 11px; letter-spacing: 1px; color: var(--muted);
  text-transform: uppercase; font-weight: 600;
}
.kpi-spark {
  opacity: .85; margin-top: -2px; margin-right: -4px;
  width: 90px; height: 28px; pointer-events: none;
}
.kpi-spark svg { display: block; }
.kpi-num { display: inline-block; }
.kpi-value {
  font-size: 28px; font-weight: 700; letter-spacing: -.6px;
  font-variant-numeric: tabular-nums; line-height: 1.1; color: var(--text);
}
.kpi-value .unit { font-size: 12px; color: var(--muted); font-weight: 500; margin-right: 6px; letter-spacing: .5px; }
.kpi-sub {
  margin-top: var(--s-3); display: flex; gap: var(--s-3); align-items: center;
  font-size: 12px; color: var(--muted); flex-wrap: wrap;
}
.kpi-sub .delta { font-weight: 600; font-variant-numeric: tabular-nums; }
.delta-up { color: var(--good); }
.delta-down { color: var(--bad); }
.delta-flat { color: var(--muted); }
.kpi.hero {
  grid-column: span 2;
  background: var(--kpi-grad), var(--surface);
}
@media (max-width: 820px) { .kpi.hero { grid-column: span 1; } }

/* -------- KPI hover popover -------- */
.kpi { cursor: default; }
.kpi-details {
  position: absolute; left: var(--s-5); right: var(--s-5); top: calc(100% - 10px);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s-4) var(--s-5);
  box-shadow: var(--shadow-strong);
  z-index: 20;
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: opacity .18s ease, transform .18s ease, visibility 0s linear .18s;
  pointer-events: none;
}
.kpi:hover .kpi-details {
  opacity: 1; visibility: visible; transform: translateY(0);
  transition: opacity .18s ease, transform .18s ease, visibility 0s;
}
.kpi-details h4 {
  margin: 0 0 var(--s-2); font-size: 11px; letter-spacing: 1px;
  text-transform: uppercase; color: var(--muted); font-weight: 700;
}
.kpi-details .def {
  font-size: 12px; color: var(--text-2); line-height: 1.45; margin: 0 0 var(--s-3);
}
.kpi-details .formula {
  font-family: var(--font-mono); font-size: 11px; color: var(--muted);
  background: var(--surface-2); border-radius: var(--r-sm);
  padding: 6px 10px; margin: 0 0 var(--s-3); display: inline-block;
}
.kpi-details ul {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 4px;
}
.kpi-details ul li {
  display: flex; justify-content: space-between; gap: var(--s-3);
  font-size: 12px; font-variant-numeric: tabular-nums;
  padding: 4px 0; border-bottom: 1px dashed var(--line-soft);
}
.kpi-details ul li:last-child { border-bottom: none; }
.kpi-details ul li span:first-child { color: var(--text-2); }
.kpi-details ul li span:last-child { color: var(--text); font-weight: 600; }
.kpi-details .source {
  margin-top: var(--s-3); font-size: 10px; color: var(--muted-2);
  letter-spacing: .5px; text-transform: uppercase;
}
/* The last kpi in a row drops the popover rightwards so it doesn't clip */
.kpi:last-child .kpi-details { right: 0; left: auto; width: 320px; max-width: calc(100vw - 32px); }

/* -------- Cards & grids -------- */
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-3); margin-top: var(--s-3); }
@media (max-width: 1100px) { .card-grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-md); padding: var(--s-5); margin-top: var(--s-3);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: var(--s-3);
  margin-bottom: var(--s-3); flex-wrap: wrap;
}
.card h2 {
  margin: 0; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: 1.2px; font-weight: 700;
}
.small { font-size: 11px; }
.muted { color: var(--muted); }

/* -------- Tables -------- */
.table-wrap { overflow-x: auto; max-height: 440px; overflow-y: auto; }
.table-wrap::-webkit-scrollbar { height: 8px; width: 8px; }
.table-wrap::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.table-wrap::-webkit-scrollbar-thumb:hover { background: var(--muted-2); }
.table-wrap::-webkit-scrollbar-track { background: transparent; }

.data-table {
  width: 100%; border-collapse: separate; border-spacing: 0;
  font-size: 13px; font-variant-numeric: tabular-nums;
}
.data-table th, .data-table td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft);
  white-space: nowrap;
}
.data-table th {
  position: sticky; top: 0; background: var(--surface);
  color: var(--muted); font-weight: 600; text-transform: uppercase;
  font-size: 10px; letter-spacing: 1px; border-bottom-color: var(--line);
  z-index: 1;
}
.data-table td.n, .data-table th.n { text-align: right; }
.data-table tbody tr { transition: background .12s; }
.data-table tbody tr:hover td { background: var(--surface-2); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table td:first-child { color: var(--text); font-weight: 500; }

/* Totals row at the bottom of every breakdown */
.data-table tfoot tr.total-row {
  position: sticky; bottom: 0;
}
.data-table tfoot tr.total-row td {
  background: var(--surface-2);
  border-top: 2px solid var(--line);
  border-bottom: none;
  font-weight: 700;
  color: var(--text);
  padding: 12px 12px;
}
.data-table tfoot tr.total-row td:first-child {
  letter-spacing: .2px; text-transform: uppercase; font-size: 11px;
}
.data-table tfoot tr.total-row td:first-child .small {
  text-transform: none; letter-spacing: 0; font-weight: 500;
  margin-left: 6px; color: var(--muted);
}

.gp-good { color: var(--good); font-weight: 600; }
.gp-warn { color: var(--warn); font-weight: 600; }
.gp-bad  { color: var(--bad); font-weight: 600; }

/* mini bar inside table cell */
.bar {
  display: block; height: 6px; background: var(--surface-2);
  border-radius: 3px; width: 100%; min-width: 60px;
  overflow: hidden;
}
.bar > span {
  display: block; height: 100%; background: var(--accent); border-radius: 3px;
  transition: width .3s ease;
}
.share-col { width: 100px; min-width: 100px; }

/* table layout — fixed column widths help side-by-side cards look aligned */
.data-table { table-layout: auto; }
.data-table th:first-child, .data-table td:first-child {
  max-width: 280px; overflow: hidden; text-overflow: ellipsis;
}

/* -------- Chart container -------- */
.chart-wrap { position: relative; height: 320px; }
@media (max-width: 640px) { .chart-wrap { height: 260px; } }

/* -------- Login (card) -------- */
.auth { max-width: 360px; margin: 100px auto; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--s-7);
  text-align: center; box-shadow: var(--shadow); }
.auth h1 { margin: 0 0 4px; font-size: 20px; }
.auth form { display: flex; flex-direction: column; gap: var(--s-3); margin-top: var(--s-5); }
.auth input {
  padding: 12px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text);
  font-size: 16px; text-align: center; letter-spacing: 4px;
}

/* -------- Error banner / alert -------- */
.alert {
  padding: 10px 14px; border-radius: var(--r-sm);
  background: rgba(248, 113, 113, .1); border: 1px solid rgba(248, 113, 113, .3);
  color: var(--bad); font-size: 13px; text-align: center; margin-top: var(--s-4);
}

/* -------- Mobile polish -------- */
@media (max-width: 640px) {
  .kpi-value { font-size: 22px; }
  .data-table th, .data-table td { padding: 8px 10px; font-size: 12px; }
  .card { padding: var(--s-4); }
  .kpi { padding: var(--s-4) var(--s-4); }
}

/* -------- Entrance animations -------- */
@keyframes fade-rise {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
.kpi, .card, .controls-row {
  animation: fade-rise .5s cubic-bezier(.2,.7,.3,1) both;
}
.kpi-grid .kpi:nth-child(1) { animation-delay: .02s; }
.kpi-grid .kpi:nth-child(2) { animation-delay: .07s; }
.kpi-grid .kpi:nth-child(3) { animation-delay: .12s; }
.kpi-grid .kpi:nth-child(4) { animation-delay: .17s; }
.kpi-grid .kpi:nth-child(5) { animation-delay: .22s; }
.card-grid { animation: fade-rise .5s .18s cubic-bezier(.2,.7,.3,1) both; }

/* -------- Scrollbars (webkit) -------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb {
  background: var(--line); border-radius: var(--r-pill);
  border: 2px solid transparent; background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--muted-2); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
html { scrollbar-color: var(--line) transparent; scrollbar-width: thin; }

/* -------- Section header icons (set via data-icon attr) -------- */
.card h2 { display: inline-flex; align-items: center; gap: var(--s-2); }
.card h2[data-icon]::before {
  content: ""; display: inline-block; width: 14px; height: 14px;
  background-color: var(--muted); mask-repeat: no-repeat; mask-size: contain;
  -webkit-mask-repeat: no-repeat; -webkit-mask-size: contain;
}
.card h2[data-icon="channel"]::before  { mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='M3 3v18h18'/><path d='M7 15l4-4 4 4 6-6'/></svg>"); -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='M3 3v18h18'/><path d='M7 15l4-4 4 4 6-6'/></svg>"); }
.card h2[data-icon="brand"]::before    { mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='M20 7l-8-4-8 4 8 4 8-4z'/><path d='M4 12l8 4 8-4'/><path d='M4 17l8 4 8-4'/></svg>"); -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='M20 7l-8-4-8 4 8 4 8-4z'/><path d='M4 12l8 4 8-4'/><path d='M4 17l8 4 8-4'/></svg>"); }
.card h2[data-icon="customer"]::before { mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2'/><circle cx='9' cy='7' r='4'/><path d='M23 21v-2a4 4 0 00-3-3.87'/><path d='M16 3.13a4 4 0 010 7.75'/></svg>"); -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='M17 21v-2a4 4 0 00-4-4H5a4 4 0 00-4 4v2'/><circle cx='9' cy='7' r='4'/><path d='M23 21v-2a4 4 0 00-3-3.87'/><path d='M16 3.13a4 4 0 010 7.75'/></svg>"); }
.card h2[data-icon="category"]::before { mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='3' width='7' height='7' rx='1'/><rect x='14' y='3' width='7' height='7' rx='1'/><rect x='3' y='14' width='7' height='7' rx='1'/><rect x='14' y='14' width='7' height='7' rx='1'/></svg>"); -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='3' width='7' height='7' rx='1'/><rect x='14' y='3' width='7' height='7' rx='1'/><rect x='3' y='14' width='7' height='7' rx='1'/><rect x='14' y='14' width='7' height='7' rx='1'/></svg>"); }
.card h2[data-icon="flag"]::before     { mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z'/><line x1='4' y1='22' x2='4' y2='15'/></svg>"); -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><path d='M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z'/><line x1='4' y1='22' x2='4' y2='15'/></svg>"); }
.card h2[data-icon="trend"]::before    { mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='22 7 13.5 15.5 8.5 10.5 2 17'/><polyline points='16 7 22 7 22 13'/></svg>"); -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><polyline points='22 7 13.5 15.5 8.5 10.5 2 17'/><polyline points='16 7 22 7 22 13'/></svg>"); }
.card h2[data-icon="rebate"]::before   { mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='10'/><path d='M8 14s1.5 2 4 2 4-2 4-2'/><line x1='9' y1='9' x2='9.01' y2='9'/><line x1='15' y1='9' x2='15.01' y2='9'/></svg>"); -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'><circle cx='12' cy='12' r='10'/><path d='M8 14s1.5 2 4 2 4-2 4-2'/><line x1='9' y1='9' x2='9.01' y2='9'/><line x1='15' y1='9' x2='15.01' y2='9'/></svg>"); }

/* -------- Avatars (initials badges) -------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 50%;
  font-size: 10px; font-weight: 700; margin-right: 8px; letter-spacing: .3px;
  vertical-align: -5px; flex-shrink: 0;
}

/* -------- Insights ribbon -------- */
.insights {
  display: flex; gap: var(--s-2); overflow-x: auto;
  margin: var(--s-4) 0 var(--s-2); padding: 2px;
  scroll-snap-type: x proximity;
}
.insights::-webkit-scrollbar { display: none; }
.insight {
  flex: 0 0 auto; display: inline-flex; align-items: center; gap: var(--s-2);
  padding: 8px 12px; border-radius: var(--r-pill);
  background: var(--surface); border: 1px solid var(--line);
  font-size: 12px; color: var(--text-2); white-space: nowrap;
  scroll-snap-align: start; transition: all .15s;
  box-shadow: var(--shadow-sm);
}
.insight:hover { border-color: var(--accent); color: var(--text); }
.insight .ins-ico { font-size: 14px; }
.insight.good { border-color: color-mix(in oklab, var(--good) 40%, var(--line)); }
.insight.warn { border-color: color-mix(in oklab, var(--warn) 40%, var(--line)); }
.insight.bad  { border-color: color-mix(in oklab, var(--bad) 40%, var(--line)); }
.insight.good .ins-ico { color: var(--good); }
.insight.warn .ins-ico { color: var(--warn); }
.insight.bad  .ins-ico { color: var(--bad); }

/* -------- Command palette (⌘K) -------- */
.cmdk-overlay {
  position: fixed; inset: 0; background: rgba(6, 11, 29, .6);
  backdrop-filter: blur(6px); z-index: 100; display: none;
  align-items: flex-start; justify-content: center;
  padding: 10vh 16px 0;
  animation: cmdk-fade .18s ease both;
}
.cmdk-overlay.open { display: flex; }
@keyframes cmdk-fade { from { opacity: 0; } to { opacity: 1; } }
.cmdk {
  width: 100%; max-width: 560px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-strong);
  display: flex; flex-direction: column; overflow: hidden;
  animation: cmdk-rise .22s cubic-bezier(.2,.7,.3,1) both;
}
@keyframes cmdk-rise { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }
.cmdk-input {
  width: 100%; padding: 14px 18px; background: transparent;
  border: none; outline: none; font: 500 15px var(--font-sans);
  color: var(--text); border-bottom: 1px solid var(--line-soft);
}
.cmdk-input::placeholder { color: var(--muted); }
.cmdk-list { max-height: 50vh; overflow-y: auto; padding: 6px; }
.cmdk-group-label {
  padding: 10px 12px 6px; font-size: 10px; letter-spacing: 1.2px;
  text-transform: uppercase; color: var(--muted); font-weight: 700;
}
.cmdk-item {
  padding: 10px 12px; border-radius: var(--r-sm);
  display: flex; align-items: center; justify-content: space-between; gap: var(--s-3);
  cursor: pointer; color: var(--text-2); font-size: 13px;
}
.cmdk-item:hover, .cmdk-item.active { background: var(--surface-2); color: var(--text); }
.cmdk-item .cmdk-kbd {
  font-family: var(--font-mono); font-size: 10px; padding: 2px 6px;
  background: var(--surface-3); border: 1px solid var(--line); border-radius: 4px;
  color: var(--muted);
}
.cmdk-foot {
  padding: 8px 14px; font-size: 11px; color: var(--muted);
  border-top: 1px solid var(--line-soft);
  display: flex; justify-content: space-between;
}

/* -------- Drill-down side panel -------- */
.drill-overlay {
  position: fixed; inset: 0; background: rgba(6, 11, 29, .5);
  backdrop-filter: blur(4px); z-index: 90; display: none;
  animation: cmdk-fade .18s ease both;
}
.drill-overlay.open { display: block; }
.drill {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(540px, 100vw);
  background: var(--surface); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-strong); z-index: 91;
  transform: translateX(100%); transition: transform .25s cubic-bezier(.2,.7,.3,1);
  display: flex; flex-direction: column;
}
.drill.open { transform: translateX(0); }
.drill-head {
  padding: var(--s-5) var(--s-5) var(--s-3);
  border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: var(--s-3);
}
.drill-head .drill-close {
  margin-left: auto; background: var(--surface-2); border: 1px solid var(--line);
  width: 32px; height: 32px; border-radius: var(--r-sm); cursor: pointer; padding: 0;
  color: var(--text-2); font-size: 16px;
}
.drill-head .drill-close:hover { border-color: var(--accent); color: var(--accent); }
.drill-title { font-size: 15px; font-weight: 700; color: var(--text); margin: 0; letter-spacing: -.2px; }
.drill-crumbs {
  display: flex; gap: 6px; align-items: center; color: var(--muted);
  font-size: 11px; letter-spacing: .3px; margin-bottom: 4px;
}
.drill-crumbs .sep { opacity: .5; }
.drill-body { padding: var(--s-4) var(--s-5) var(--s-6); overflow-y: auto; flex: 1; }
.drill-body h4 {
  margin: var(--s-4) 0 var(--s-2); font-size: 11px;
  text-transform: uppercase; letter-spacing: 1px; color: var(--muted); font-weight: 700;
}
.drill-stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-2);
}
.drill-stat {
  background: var(--surface-2); border-radius: var(--r-sm); padding: 10px 12px;
}
.drill-stat .lbl { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; font-weight: 600; }
.drill-stat .val { font-size: 16px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.drill-chart { position: relative; height: 180px; margin-top: var(--s-3); }
.drill-rebate { display: flex; flex-direction: column; gap: 4px; }
.drill-rebate-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 0; font-size: 12px; border-bottom: 1px dashed var(--line-soft);
}
.drill-rebate-row:last-child { border-bottom: none; }
.drill-rebate-row .code { color: var(--muted); font-family: var(--font-mono); font-size: 10px; margin-right: 8px; }

/* -------- Clickable row style -------- */
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover td { background: var(--surface-2); }

/* -------- Skeleton loader -------- */
.skeleton {
  background:
    linear-gradient(90deg, transparent, rgba(255,255,255,.06), transparent),
    var(--surface-2);
  background-size: 200% 100%, 100% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--r-sm); color: transparent;
}
:root[data-theme="light"] .skeleton {
  background:
    linear-gradient(90deg, transparent, rgba(0,0,0,.04), transparent),
    var(--surface-2);
  background-size: 200% 100%, 100% 100%;
}
@keyframes shimmer { 0% { background-position: -100% 0, 0 0; } 100% { background-position: 200% 0, 0 0; } }

/* -------- Prefer reduced motion -------- */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
