/* ════════════════════════════════════════════════════════════════════
   MELODIAVOSS STATS v2 — Design System
   Inspired by Linear, Vercel, Stripe, Plausible
   ════════════════════════════════════════════════════════════════════ */

/* ── TOKENS ──────────────────────────────────────────────────────── */
:root {
  --brand: #4f46e5;
  --brand-2: #818cf8;
  --brand-soft: #e0e7ff;
  --ink: #1F1B2E;
  --ink-2: #2E2A39;

  --bg: #FAF8F5;
  --bg-2: #F4F1EC;
  --card: #FFFFFF;
  --line: #ECE7DE;
  --line-2: #DFD9CE;

  --text: #1F1B2E;
  --text-2: #4A4656;
  --muted: #76718A;
  --dim: #A09BAE;

  --up: #0F9D58;
  --up-soft: #E3F4EB;
  --down: #DC2626;
  --down-soft: #FCE7E7;
  --warn: #D97706;
  --warn-soft: #FEF3C7;
  --info: #2563EB;
  --info-soft: #DBEAFE;

  --r-sm: 6px;
  --r: 10px;
  --r-lg: 14px;
  --r-xl: 20px;

  --shadow-sm: 0 1px 2px rgba(31, 27, 46, 0.04), 0 0 0 1px var(--line);
  --shadow: 0 1px 2px rgba(31, 27, 46, 0.04), 0 4px 12px rgba(31, 27, 46, 0.05), 0 0 0 1px var(--line);
  --shadow-lg: 0 4px 12px rgba(31, 27, 46, 0.06), 0 24px 48px rgba(31, 27, 46, 0.10), 0 0 0 1px var(--line);

  --sidebar-w: 232px;
  --topbar-h: 56px;
  --filter-h: 52px;

  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
}

[data-theme="dark"] {
  --bg: #0E0C14;
  --bg-2: #15131C;
  --card: #1A1825;
  --line: #2A2735;
  --line-2: #34303F;

  --text: #F5F2EC;
  --text-2: #C8C2D4;
  --muted: #918BA1;
  --dim: #6B6677;

  --up-soft: rgba(15, 157, 88, 0.15);
  --down-soft: rgba(220, 38, 38, 0.15);
  --warn-soft: rgba(217, 119, 6, 0.18);
  --info-soft: rgba(37, 99, 235, 0.18);
  --brand-soft: rgba(217, 119, 87, 0.15);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3), 0 0 0 1px var(--line);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35), 0 0 0 1px var(--line);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.4), 0 24px 48px rgba(0, 0, 0, 0.5), 0 0 0 1px var(--line);
}

/* ── BASE ────────────────────────────────────────────────────────── */
* { box-sizing: border-box; margin: 0; padding: 0; }
*::selection { background: var(--brand-soft); color: var(--ink); }

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
  font-feature-settings: "cv11", "ss01", "ss03";
}
.mono, .num { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-variant-numeric: tabular-nums; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3, h4 { font-weight: 700; letter-spacing: -0.01em; }
h1 { font-size: 24px; letter-spacing: -0.02em; }
h2 { font-size: 19px; letter-spacing: -0.015em; }
h3 { font-size: 14px; }
p { line-height: 1.55; }

/* ── APP LAYOUT ──────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}
[data-sidebar="collapsed"] .app { grid-template-columns: 64px 1fr; }
[hidden] { display: none !important; }

/* ── SIDEBAR ─────────────────────────────────────────────────────── */
.sidebar {
  background: var(--bg-2);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 10px;
  height: var(--topbar-h);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.logo { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo-mark {
  width: 32px; height: 32px; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: white; font-weight: 800; font-size: 16px;
  display: grid; place-items: center;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
  flex-shrink: 0;
}
.logo-text { display: flex; flex-direction: column; min-width: 0; }
.logo-text strong { font-size: 13.5px; font-weight: 700; white-space: nowrap; }
.logo-text small { font-size: 11px; color: var(--muted); white-space: nowrap; }
[data-sidebar="collapsed"] .logo-text { display: none; }
[data-sidebar="collapsed"] .sidebar-head { padding: 14px 16px 10px; }

.nav { padding: 8px 8px; overflow-y: auto; flex: 1; }
.nav::-webkit-scrollbar { width: 6px; }
.nav::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }
.nav-group { margin-bottom: 14px; }
.nav-group-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.6px;
  color: var(--dim); font-weight: 700; padding: 6px 10px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 10px; border-radius: 8px; color: var(--text-2);
  font-weight: 500; font-size: 13.5px;
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
  position: relative;
}
.nav-item:hover { background: var(--card); color: var(--text); }
.nav-item.on { background: var(--card); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-sm); }
[data-theme="dark"] .nav-item.on { background: var(--bg-2); color: var(--text); border: 1px solid var(--line); }
.nav-item .ico { width: 20px; text-align: center; font-size: 13px; color: var(--muted); flex-shrink: 0; }
.nav-item.on .ico { color: var(--brand); }
.nav-badge {
  margin-left: auto; font-size: 10.5px; font-weight: 700;
  background: var(--bg); color: var(--muted); padding: 2px 7px; border-radius: 10px;
  font-variant-numeric: tabular-nums;
}
.nav-badge.accent { background: var(--brand-soft); color: var(--brand); }
[data-sidebar="collapsed"] .nav-group-label,
[data-sidebar="collapsed"] .nav-item span:not(.ico),
[data-sidebar="collapsed"] .nav-badge { display: none; }
[data-sidebar="collapsed"] .nav-item { justify-content: center; }

.sidebar-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; border-top: 1px solid var(--line);
  background: var(--bg-2);
  flex-shrink: 0;
}
.user-chip { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, #4A4656, var(--ink));
  color: white; font-weight: 700; font-size: 12px;
  display: grid; place-items: center; flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; min-width: 0; }
.user-info strong { font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-info small { font-size: 10.5px; color: var(--muted); }
[data-sidebar="collapsed"] .user-info { display: none; }

/* ── MAIN ────────────────────────────────────────────────────────── */
.main { display: flex; flex-direction: column; min-width: 0; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 6px 18px; min-height: var(--topbar-h);
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  flex-shrink: 0;
}
.breadcrumbs { font-weight: 600; font-size: 14px; }
.breadcrumbs .crumb-sep { color: var(--dim); margin: 0 6px; }
.breadcrumbs .crumb-sub { color: var(--muted); font-weight: 500; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.search {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 240px;
  color: var(--muted);
  transition: border 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.search:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.search input { border: 0; outline: 0; background: none; flex: 1; font-size: 13px; color: var(--text); }
.search input::placeholder { color: var(--dim); }
.search kbd, kbd {
  font-family: inherit; font-size: 10.5px;
  background: var(--bg-2); color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 4px; padding: 1px 5px;
}

.seg {
  display: inline-flex; padding: 3px;
  background: var(--card); border: 1px solid var(--line); border-radius: 9px;
}
.seg button {
  padding: 4px 12px; font-size: 12px; font-weight: 600;
  border-radius: 6px; color: var(--muted);
  transition: background 0.15s var(--ease), color 0.15s var(--ease);
}
.seg button.on { background: var(--bg-2); color: var(--ink); box-shadow: var(--shadow-sm); }

.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px; color: var(--muted);
  border: 1px solid transparent;
  transition: all 0.15s var(--ease);
  position: relative;
}
.icon-btn:hover { background: var(--card); border-color: var(--line); color: var(--text); }
[data-theme="light"] .i-moon, [data-theme="dark"] .i-sun { display: none; }

/* ── FILTER STRIP ────────────────────────────────────────────────── */
.filter-strip {
  display: flex; align-items: center; gap: 12px;
  padding: 0 18px; height: var(--filter-h);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-strip::-webkit-scrollbar { display: none; }
.chips { display: flex; gap: 4px; }
.chip {
  padding: 5px 12px; font-size: 12.5px; font-weight: 600;
  border-radius: 7px; color: var(--muted);
  border: 1px solid transparent;
  white-space: nowrap;
  transition: all 0.15s var(--ease);
}
.chip:hover { color: var(--text); background: var(--card); }
.chip.on { background: var(--ink); color: white; border-color: var(--ink); }
.date-range { display: flex; align-items: center; gap: 6px; color: var(--muted); margin-left: auto; }
.date-range input[type="date"] {
  padding: 5px 8px; font-size: 12.5px;
  background: var(--card); border: 1px solid var(--line); border-radius: 7px;
  color: var(--text); font-family: inherit;
}
.date-range input[type="date"]:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.compare-toggle { display: flex; align-items: center; gap: 6px; font-size: 12.5px; cursor: pointer; user-select: none; padding: 0 4px; }
.compare-toggle input { width: 14px; height: 14px; accent-color: var(--brand); }
.btn-ghost {
  padding: 5px 10px; font-size: 12px; font-weight: 600;
  border-radius: 7px; color: var(--muted);
  border: 1px solid var(--line);
  transition: all 0.15s var(--ease);
}
.btn-ghost:hover { color: var(--text); border-color: var(--line-2); background: var(--card); }
.btn-ghost.active { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }
.api-mode {
  display: flex; align-items: center; gap: 6px;
  font-size: 11.5px; font-weight: 600;
  color: var(--muted);
  padding: 4px 10px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.api-mode .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); }
.api-mode .dot.demo { background: var(--warn); }
.api-mode .dot.live { background: var(--up); }
.api-mode .dot.error { background: var(--down); }

/* ── VIEW ────────────────────────────────────────────────────────── */
.view { flex: 1; overflow-y: auto; padding: 20px 24px 80px; }
.view::-webkit-scrollbar { width: 8px; height: 8px; }
.view::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 4px; }
.view::-webkit-scrollbar-thumb:hover { background: var(--dim); }
.view-h {
  display: flex; align-items: flex-end; justify-content: space-between;
  margin-bottom: 20px; gap: 16px; flex-wrap: wrap;
}
.view-h h1 { font-size: 22px; }
.view-h .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.view-h .actions { display: flex; gap: 8px; }

/* ── KPI TILES ───────────────────────────────────────────────────── */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
@media (max-width: 1200px) { .kpis { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 600px) { .kpis { grid-template-columns: 1fr; } }
.kpi {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 16px 18px;
  position: relative; overflow: hidden;
  transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.kpi:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.kpi-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; }
.kpi-ico { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; font-size: 13px; color: var(--muted); background: var(--bg-2); }
.kpi-value { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.kpi-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.kpi-spark { flex: 1; height: 28px; min-width: 0; }
.kpi-spark svg { display: block; width: 100%; height: 100%; }
.kpi-chg { font-size: 11.5px; font-weight: 700; display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px; border-radius: 6px; }
.kpi-chg.up { color: var(--up); background: var(--up-soft); }
.kpi-chg.down { color: var(--down); background: var(--down-soft); }
.kpi-chg.flat { color: var(--muted); background: var(--bg-2); }
.kpi-sub { font-size: 11.5px; color: var(--dim); margin-left: auto; }

/* ── PANELS ──────────────────────────────────────────────────────── */
.panel {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg); padding: 18px;
  display: flex; flex-direction: column;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.panel-head h3 { font-size: 14px; font-weight: 700; }
.panel-head .sub { font-size: 12px; color: var(--muted); }
.panel-body { flex: 1; min-height: 0; }
.panel-actions { display: flex; gap: 4px; }
.panel-tabs { display: flex; gap: 2px; padding: 3px; background: var(--bg-2); border-radius: 8px; }
.panel-tab { padding: 4px 10px; font-size: 11.5px; font-weight: 600; color: var(--muted); border-radius: 5px; }
.panel-tab.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow-sm); }

.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; margin-bottom: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 20px; }
.grid-2-equal { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 20px; }
@media (max-width: 980px) { .grid-2, .grid-3, .grid-2-equal { grid-template-columns: 1fr; } }

/* ── CHART WRAPPERS ──────────────────────────────────────────────── */
.chart-wrap { position: relative; height: 240px; }
.chart-wrap.tall { height: 320px; }
.chart-wrap.short { height: 180px; }

/* ── TABLES ──────────────────────────────────────────────────────── */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  text-align: left; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px; color: var(--dim);
  padding: 8px 10px; border-bottom: 1px solid var(--line);
  background: var(--bg-2);
  position: sticky; top: 0; z-index: 1;
}
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tr.row { cursor: pointer; transition: background 0.1s var(--ease); }
.tbl tr.row:hover { background: var(--bg-2); }
.tbl td.n, .tbl th.n { text-align: right; font-variant-numeric: tabular-nums; }
.tbl-scroll { overflow: auto; max-height: 480px; }
.tbl-scroll::-webkit-scrollbar { width: 6px; height: 6px; }
.tbl-scroll::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }

.tbl-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.tbl-search { flex: 1; min-width: 200px; padding: 8px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.tbl-search:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.tbl-pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px; font-weight: 700;
  padding: 3px 8px; border-radius: 20px;
}
.tbl-pill::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }
.tbl-pill.paid { color: var(--up); background: var(--up-soft); }
.tbl-pill.pending { color: var(--warn); background: var(--warn-soft); }
.tbl-pill.refunded { color: var(--muted); background: var(--bg-2); }
.tbl-pill.failed, .tbl-pill.canceled, .tbl-pill.expired { color: var(--down); background: var(--down-soft); }
.tbl-pill.delivered { color: var(--up); background: var(--up-soft); }
.tbl-pill.in-production { color: var(--info); background: var(--info-soft); }
.tbl-pill.unfulfilled { color: var(--warn); background: var(--warn-soft); }
.tbl-pill.test { color: var(--brand); background: var(--brand-soft); margin-left: 6px; }
.tbl-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; font-size: 12px; color: var(--muted); }

/* ── BARS (custom) ───────────────────────────────────────────────── */
.bar-row {
  display: grid; grid-template-columns: 130px 1fr 90px;
  align-items: center; gap: 10px;
  padding: 6px 0; font-size: 13px;
}
.bar-track { background: var(--bg-2); border-radius: 4px; height: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 4px; transition: width 0.5s var(--ease); }
.bar-fill.alt { background: linear-gradient(90deg, var(--ink), var(--text-2)); }
.bar-row .num { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text-2); }
.bar-label { color: var(--text-2); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── FUNNEL ──────────────────────────────────────────────────────── */
.funnel { display: flex; flex-direction: column; gap: 4px; }
.funnel-stage { display: grid; grid-template-columns: 140px 1fr 90px; align-items: center; gap: 12px; padding: 4px 0; }
.funnel-bar-track { background: var(--bg-2); height: 36px; border-radius: 8px; position: relative; overflow: hidden; }
.funnel-bar { position: absolute; inset: 0; right: auto; background: linear-gradient(90deg, var(--brand), var(--brand-2)); border-radius: 8px; min-width: 4px; transition: width 0.6s var(--ease); }
.funnel-bar .funnel-count { position: absolute; right: -8px; top: 50%; transform: translate(100%, -50%); color: var(--text); font-weight: 700; font-size: 13px; padding-left: 8px; white-space: nowrap; }
.funnel-value { text-align: right; }
.funnel-value strong { display: block; font-size: 14px; }
.funnel-bar.tone-2 { background: linear-gradient(90deg, #2563EB, #60A5FA); }
.funnel-bar.tone-3 { background: linear-gradient(90deg, #7C3AED, #A78BFA); }
.funnel-bar.tone-4 { background: linear-gradient(90deg, #059669, #34D399); }
.funnel-bar.tone-5 { background: linear-gradient(90deg, var(--ink), var(--text-2)); }
.funnel-drop { font-size: 11px; color: var(--dim); margin: 2px 0 4px 152px; display: flex; align-items: center; gap: 4px; }
.funnel-drop .arr { color: var(--down); }
.funnel-label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.funnel-value { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ── HEATMAP ─────────────────────────────────────────────────────── */
.heat { overflow-x: auto; }
.heat-grid { display: grid; grid-template-columns: 36px repeat(24, minmax(22px, 1fr)); gap: 3px; min-width: 640px; }
.heat-axis { font-size: 10px; color: var(--dim); text-align: center; }
.heat-axis.y { text-align: right; padding-right: 4px; }
.heat-cell { aspect-ratio: 1; border-radius: 3px; min-height: 18px; transition: transform 0.1s var(--ease); }
.heat-cell:hover { transform: scale(1.15); z-index: 1; position: relative; box-shadow: 0 0 0 1px var(--ink); }

/* ── PILL / BADGE ────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 5px;
  background: var(--bg-2); color: var(--text-2);
}
.pill.dk { background: rgba(79, 70, 229, 0.12); color: #4f46e5; }
.pill.se { background: rgba(37, 99, 235, 0.12); color: #2563EB; }
.pill.no { background: rgba(124, 58, 237, 0.12); color: #7C3AED; }

/* ── BUTTONS ─────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%; padding: 11px; font-size: 14px; font-weight: 700;
  color: white; border: 0; border-radius: 9px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  cursor: pointer; transition: transform 0.15s var(--ease), box-shadow 0.15s var(--ease);
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(79, 70, 229, 0.35); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  padding: 8px 14px; font-size: 13px; font-weight: 600;
  background: var(--card); color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer;
  transition: all 0.15s var(--ease);
}
.btn-secondary:hover { border-color: var(--line-2); background: var(--bg-2); }
.btn-danger { padding: 6px 12px; font-size: 12px; font-weight: 600; color: var(--down); background: var(--down-soft); border: 0; border-radius: 6px; cursor: pointer; }
.btn-danger:hover { background: rgba(220, 38, 38, 0.2); }

/* ── LOGIN ───────────────────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center;
  background: var(--bg);
  padding: 20px;
}
.login::before {
  content: ''; position: absolute; inset: 0;
  background:
    radial-gradient(circle at 20% 30%, rgba(79, 70, 229, 0.15), transparent 50%),
    radial-gradient(circle at 80% 70%, rgba(124, 58, 237, 0.10), transparent 50%);
  pointer-events: none;
}
.login-card {
  position: relative;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-xl); padding: 36px 32px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-lg);
}
.login-mark {
  width: 44px; height: 44px; border-radius: 12px;
  background: linear-gradient(135deg, var(--brand), var(--brand-2));
  color: white; font-weight: 800; font-size: 22px;
  display: grid; place-items: center;
  margin: 0 auto 16px;
  box-shadow: 0 4px 16px rgba(79, 70, 229, 0.3);
}
.login-card h1 { font-size: 22px; text-align: center; }
.login-card p { font-size: 13px; color: var(--muted); text-align: center; margin-top: 4px; }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 22px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-2); }
.login-card input {
  padding: 10px 12px; background: var(--bg-2); border: 1px solid var(--line);
  border-radius: 8px; font-size: 14px; color: var(--text);
  transition: border 0.15s var(--ease), box-shadow 0.15s var(--ease);
}
.login-card input:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); background: var(--card); }
.login-err { color: var(--down); font-size: 12.5px; min-height: 16px; margin-top: 4px; }
.login-hint { font-size: 11.5px; color: var(--dim); text-align: center; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.login-hint code { background: var(--bg-2); padding: 1px 5px; border-radius: 3px; font-size: 11px; }

/* ── DETAIL SHEET ────────────────────────────────────────────────── */
.sheet-bg {
  position: fixed; inset: 0; z-index: 90;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  display: flex; justify-content: flex-end;
}
[data-theme="dark"] .sheet-bg { background: rgba(0, 0, 0, 0.6); }
.sheet {
  width: 100%; max-width: 580px;
  background: var(--card); border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
  animation: slideIn 0.25s var(--ease);
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.1);
}
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.sheet-close {
  position: absolute; top: 14px; right: 14px;
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--bg-2); color: var(--muted);
  display: grid; place-items: center; z-index: 2;
}
.sheet-close:hover { background: var(--line); color: var(--text); }
.sheet-body { padding: 32px 28px; overflow-y: auto; flex: 1; }
.sheet-body::-webkit-scrollbar { width: 6px; }
.sheet-body::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }
.sheet-head { margin-bottom: 20px; }
.sheet-head h2 { font-size: 20px; }
.sheet-head .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.mrow { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.mrow:last-child { border-bottom: 0; }
.mrow .k { color: var(--muted); }
.mrow .v { font-weight: 600; }
.sect-h { font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--dim); font-weight: 700; margin: 18px 0 8px; }
.props { background: var(--bg-2); border-radius: 8px; padding: 12px 14px; font-size: 13px; line-height: 1.7; }
.props b { color: var(--muted); font-weight: 600; }
.tl { list-style: none; }
.tl li { position: relative; padding: 0 0 12px 18px; font-size: 12.5px; }
.tl li::before { content: ''; position: absolute; left: 0; top: 5px; width: 7px; height: 7px; border-radius: 50%; background: var(--brand); }
.tl li .t { color: var(--dim); font-size: 11px; }

/* ── TOASTS ──────────────────────────────────────────────────────── */
.toast-stack {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--ink); color: white;
  padding: 11px 16px; border-radius: 9px;
  font-size: 13px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  animation: toastIn 0.25s var(--ease);
  pointer-events: auto;
  max-width: 360px;
}
.toast.success { background: var(--up); }
.toast.error { background: var(--down); }
.toast.warn { background: var(--warn); }
@keyframes toastIn { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── COMMAND PALETTE ─────────────────────────────────────────────── */
.palette-bg {
  position: fixed; inset: 0; z-index: 150;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(4px);
  display: grid; place-items: start center;
  padding-top: 12vh;
}
.palette {
  width: 100%; max-width: 540px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: paletteIn 0.18s var(--ease);
}
@keyframes paletteIn { from { transform: translateY(-10px); opacity: 0; } to { transform: none; opacity: 1; } }
.palette input {
  width: 100%; padding: 16px 18px;
  background: transparent; border: 0; outline: 0;
  font-size: 16px; color: var(--text);
  border-bottom: 1px solid var(--line);
}
.palette-list { max-height: 380px; overflow-y: auto; padding: 6px; }
.palette-list::-webkit-scrollbar { width: 6px; }
.palette-list::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 3px; }
.palette-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 7px;
  cursor: pointer; transition: background 0.1s var(--ease);
}
.palette-item:hover, .palette-item.active { background: var(--bg-2); }
.palette-item .ico { width: 22px; text-align: center; color: var(--muted); }
.palette-item .label { font-weight: 500; font-size: 14px; }
.palette-item .sub { color: var(--muted); font-size: 12px; margin-left: auto; }
.palette-foot {
  padding: 8px 14px; font-size: 11.5px; color: var(--muted);
  border-top: 1px solid var(--line);
  display: flex; gap: 14px; background: var(--bg-2);
}

/* ── SKELETON ────────────────────────────────────────────────────── */
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }
.skel {
  background: linear-gradient(90deg, var(--bg-2) 0%, var(--line) 50%, var(--bg-2) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 6px;
  color: transparent !important;
}

/* ── EMPTY STATE ─────────────────────────────────────────────────── */
.empty {
  padding: 40px 20px; text-align: center; color: var(--muted);
  font-size: 13px;
}
.empty .ico { font-size: 28px; margin-bottom: 8px; opacity: 0.4; }

/* ── UTILITIES ───────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-1 { flex: 1; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; } .gap-16 { gap: 16px; }
.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; } .mb-12 { margin-bottom: 12px; } .mb-16 { margin-bottom: 16px; } .mb-24 { margin-bottom: 24px; }
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.right { text-align: right; }
.center { text-align: center; }
.hide { display: none !important; }
.spacer { flex: 1; }
.hidden-sm { display: initial; }
@media (max-width: 760px) { .hidden-sm { display: none; } }
.mobile-only { display: none; }
@media (max-width: 760px) { .mobile-only { display: grid; } }
.mobile-status-line { display: none; }

/* ── MOBILE ──────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  :root { --sidebar-w: 280px; }

  /* Hard kill for any horizontal scroll — page-level only. Inner
     panels that legitimately need wide content (heatmap, cohort,
     wide tables) get their own overflow containers below. */
  html, body { height: auto; overflow-x: clip; }
  body { overflow-y: auto; position: relative; }

  /* Single-column app shell — force explicit widths to defeat any
     inherited iOS Safari constraint. The big error we kept hitting
     was .main rendering at ~120px on a 390px viewport. */
  .app {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
  }
  .main {
    min-width: 0;
    width: 100%;
    max-width: 100vw;
    grid-column: 1;
  }
  .view {
    width: 100%;
    min-width: 0;
    max-width: 100vw;
  }

  /* Sidebar becomes left-edge drawer, removed from flow */
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 80;
    width: var(--sidebar-w); max-width: 90vw;
    transform: translateX(-100%);
    transition: transform 0.25s var(--ease);
  }
  [data-mobile-nav="open"] .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  [data-mobile-nav="open"] .sidebar-bg {
    position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    backdrop-filter: blur(2px); z-index: 75;
    animation: fadeIn 0.2s var(--ease);
  }

  /* Mobile drawer always shows full state regardless of persisted
     desktop collapsed pref. localStorage carried over from desktop. */
  [data-sidebar="collapsed"] .app { grid-template-columns: 1fr !important; }
  [data-sidebar="collapsed"] .logo-text { display: flex !important; }
  [data-sidebar="collapsed"] .nav-group-label { display: block !important; }
  [data-sidebar="collapsed"] .nav-item span:not(.ico) { display: inline !important; }
  [data-sidebar="collapsed"] .nav-badge { display: inline-block !important; }
  [data-sidebar="collapsed"] .user-info { display: flex !important; }
  [data-sidebar="collapsed"] .user-info strong,
  [data-sidebar="collapsed"] .user-info small { display: inline !important; }
  [data-sidebar="collapsed"] .nav-item { justify-content: flex-start !important; }
  [data-sidebar="collapsed"] .sidebar-head { padding: 14px 14px 10px !important; }
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

  /* Topbar row 1: hamburger | page title | refresh | filter.
     Row 2: date preset chips in a full-width horizontal scroll strip.
     Custom dates / compare / market / theme live in the filter sheet.
     display:contents makes .topbar-actions children flex items of the
     topbar itself so the chips can wrap onto their own row. */
  .topbar { padding: 6px 10px; gap: 6px; height: auto; min-height: 52px; flex-wrap: wrap; row-gap: 8px; }
  .topbar-actions { display: contents; }
  .topbar-actions .date-mini,
  .topbar-actions .date-arrow,
  .topbar-actions .compare-toggle.mini { display: none; }
  .topbar-actions .chips.compact {
    order: 10; flex-basis: 100%; min-width: 0;
    overflow-x: auto; scrollbar-width: none;
    -ms-overflow-style: none;
    -webkit-overflow-scrolling: touch;
  }
  .topbar-actions .chips.compact::-webkit-scrollbar { display: none; }
  .breadcrumbs { font-size: 16px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .icon-btn { width: 38px; height: 38px; }
  #refreshBtn { width: 38px; height: 38px; }

  /* Filter strip: just date chips (horiz scroll) + nothing else.
     Custom dates / compare / save / theme live in the filter sheet. */
  .filter-strip {
    padding: 8px 10px; height: auto;
    flex-wrap: nowrap; gap: 0;
    background: var(--bg-2);
  }
  .filter-strip .chips {
    flex: 1; min-width: 0;
    overflow-x: auto; scrollbar-width: none;
    -ms-overflow-style: none;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    padding-right: 4px;
  }
  .filter-strip .chips::-webkit-scrollbar { display: none; }
  .filter-strip .chip { scroll-snap-align: start; padding: 6px 12px; font-size: 13px; }
  .filter-strip .date-range,
  .filter-strip .api-mode { display: none; }

  /* Status line above bottom tab: shows auto-refresh state on mobile */
  .mobile-status-line {
    display: flex; align-items: center; justify-content: space-between;
    padding: 6px 14px; gap: 8px;
    font-size: 11.5px; font-weight: 600;
    color: var(--muted);
    background: var(--bg);
    border-top: 1px solid var(--line);
    position: fixed; left: 0; right: 0; bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    z-index: 70;
    pointer-events: none;
  }
  .mobile-status-line .pill-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--up); display: inline-block; margin-right: 6px; }
  .mobile-status-line.warn .pill-dot { background: var(--warn); }
  .mobile-status-line.error .pill-dot { background: var(--down); }

  /* Content: full-bleed with tab-bar safe area */
  .view {
    padding: 12px 12px calc(86px + env(safe-area-inset-bottom, 0px));
    overflow-x: hidden;
  }
  .view-h { margin-bottom: 12px; }
  .view-h h1 { font-size: 20px; }

  /* KPI tiles: 2 columns on phone, 1 column on very small */
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
  .kpi { padding: 12px 13px; min-width: 0; }
  .kpi-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .kpi-value { white-space: nowrap; }
  .kpi-value { font-size: 19px; letter-spacing: -0.015em; }
  .kpi-label { font-size: 11px; }
  .kpi-foot { gap: 6px; margin-top: 6px; }
  .kpi-ico { width: 24px; height: 24px; font-size: 12px; }

  /* Stack every multi-col grid */
  .grid-2, .grid-3, .grid-2-equal, .pages-grid { grid-template-columns: 1fr !important; }
  .grid-2 > *, .grid-3 > *, .grid-2-equal > * { min-width: 0; width: 100%; }

  /* Panels: never wider than viewport */
  .panel { min-width: 0; max-width: 100%; width: 100%; }
  .panel-head { flex-wrap: wrap; min-width: 0; }
  .panel-tabs { flex-wrap: wrap; }
  .panel-head > * { min-width: 0; }
  .panel-head .panel-tabs { min-width: 0; flex: 1; }

  /* Anything in the view can shrink, never forces overflow */
  .view > * { min-width: 0; max-width: 100%; }
  .view h1, .view h2, .view h3, .view p, .view .sub, .view .panel,
  .view .grid-2, .view .grid-3 { min-width: 0; }

  /* Charts: shorter on phone so they don't dominate */
  .chart-wrap { width: 100%; height: 200px; }
  .chart-wrap.tall { height: 240px; }
  .chart-wrap.short { height: 160px; }
  .chart-wrap canvas { max-width: 100% !important; }

  /* View header: stack text and actions — !important to override
     any stale cache or higher-specificity rule */
  .view-h { flex-direction: column !important; align-items: stretch !important; gap: 8px; width: 100%; max-width: 100%; min-width: 0; }
  .view-h > div { width: 100% !important; min-width: 0; max-width: 100%; }
  .view-h .actions { width: 100%; }
  .view-h .actions .btn-secondary { flex: 1; min-width: 0; }
  .view-h h1 { white-space: normal; width: 100%; }

  /* Headings: never let them wrap mid-word */
  .view h1, .view .view-h h1 {
    word-break: break-word; overflow-wrap: anywhere;
  }

  /* Tighter panels */
  .panel { padding: 14px; border-radius: 12px; }
  .panel-head h3 { font-size: 13.5px; }
  .panel-head .sub { font-size: 11.5px; }

  /* Heatmap / cohort: contained horizontal scroll, no page overflow */
  .heat, .cohort { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -14px; padding: 0 14px; }

  /* Tables: contained scroll */
  .tbl { font-size: 12.5px; }
  .tbl th, .tbl td { padding: 9px 8px; }
  .tbl th { font-size: 10.5px; }
  .tbl-scroll { -webkit-overflow-scrolling: touch; }
  .tbl-search { font-size: 14px; padding: 10px 12px; }

  /* Detail sheet: full-screen */
  .sheet { max-width: 100%; }
  .sheet-body { padding: 22px 18px; }
  .sheet-head h2 { font-size: 18px; }

  /* Funnel: tighter columns */
  .funnel-stage { grid-template-columns: 96px 1fr 70px; gap: 8px; font-size: 12px; }
  .funnel-bar-track { height: 28px; }
  .funnel-drop { margin-left: 104px; }

  /* Bar rows */
  .bar-row { grid-template-columns: 100px 1fr 70px; gap: 8px; font-size: 12.5px; }

  /* Toast position above bottom tab */
  .toast-stack { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); right: 12px; left: 12px; align-items: stretch; }
  .toast { max-width: 100%; }

  /* Command palette: full-screen on mobile */
  .palette-bg { padding: 8px; align-items: stretch; }
  .palette { border-radius: 14px; max-width: 100%; }
  .palette-input, .palette input { font-size: 16px; } /* 16px+ prevents iOS zoom-on-focus */

  /* Login form: same font-size guard */
  .login-card input { font-size: 16px; }

  /* Tickers */
  .ticker { padding: 8px 12px; }
  .ticker-label { font-size: 11px; }

  /* Empty state */
  .empty { padding: 28px 16px; font-size: 12.5px; }

  /* AB cards tighter */
  .ab-card { padding: 12px; }
  .ab-variant { padding: 8px 10px; }
  .ab-variant .rate { font-size: 16px; }
}

/* ── A/B TEST COMPONENTS ─────────────────────────────────────────── */
.ab-card { padding: 16px; border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 12px; }
.ab-variants { display: flex; flex-direction: column; gap: 8px; }
.ab-variant { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: var(--bg-2); border-radius: 8px; }
.ab-variant.winner { background: var(--up-soft); border: 1px solid rgba(15, 157, 88, 0.3); }
.ab-variant .name { font-weight: 600; font-size: 13px; flex: 1; }
.ab-variant .rate { font-weight: 800; font-size: 18px; }
.ab-variant .meta { color: var(--muted); font-size: 11.5px; }
.ab-winner-badge { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 5px; background: var(--up); color: white; }

/* ── DASHBOARD TICKER ────────────────────────────────────────────── */
.ticker { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: var(--r); margin-bottom: 16px; overflow: hidden; }
.ticker-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); white-space: nowrap; }
.ticker-stream { display: flex; gap: 16px; overflow: hidden; flex: 1; }
.ticker-item { display: flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--text-2); white-space: nowrap; animation: tickerIn 0.5s var(--ease); }
.ticker-item strong { color: var(--up); font-weight: 700; }
.ticker-item .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--up); animation: pulse 2s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
@keyframes tickerIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── HEALTH DOT ──────────────────────────────────────────────────── */
.health { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.health .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--up); }
.health.warn .dot { background: var(--warn); }
.health.down .dot { background: var(--down); }

/* ── COHORT MATRIX ───────────────────────────────────────────────── */
.cohort { overflow-x: auto; }
.cohort-grid { display: grid; gap: 2px; min-width: 600px; }
.cohort-cell { aspect-ratio: 1; display: grid; place-items: center; font-size: 11px; font-weight: 600; border-radius: 4px; }
.cohort-cell.h { background: transparent; color: var(--muted); aspect-ratio: auto; }
.cohort-cell.label { background: transparent; color: var(--text-2); aspect-ratio: auto; padding: 4px 8px; font-weight: 600; justify-content: flex-start; }

/* ── TEST PAGES GRID ─────────────────────────────────────────────── */
.pages-grid { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
@media (max-width: 980px) { .pages-grid { grid-template-columns: 1fr; } }
.pages-list .page-item { padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; cursor: pointer; transition: all 0.15s var(--ease); }
.pages-list .page-item:hover { background: var(--bg-2); }
.pages-list .page-item.on { background: var(--bg-2); border-color: var(--brand); }
.pages-list .page-item .pname { font-weight: 600; font-size: 13px; }
.pages-list .page-item .purl { font-size: 11px; color: var(--muted); word-break: break-all; margin-top: 2px; }
.pages-list .page-item .pnote { font-size: 11px; color: var(--muted); font-style: italic; margin-top: 4px; }
.pages-preview { background: var(--ink); border-radius: var(--r); overflow: hidden; min-height: 500px; }
.pages-preview iframe { width: 100%; height: 70vh; border: 0; display: block; }

/* ── BOTTOM SPACING FOR SCROLL ───────────────────────────────────── */
.bottom-pad { height: 40px; }

/* ── DESKTOP-ONLY UTILITY ─────────────────────────────────────────── */
.desktop-only { display: initial; }
@media (max-width: 760px) { .desktop-only { display: none !important; } }

/* ── BOTTOM TAB BAR (mobile only) ────────────────────────────────── */
.bottom-tab { display: none; }
@media (max-width: 760px) {
  .bottom-tab {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 70;
    background: var(--card);
    border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -2px 12px rgba(0, 0, 0, 0.04);
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-tab .tab {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    padding: 8px 4px;
    border-radius: 10px;
    color: var(--muted);
    transition: background 0.1s var(--ease), color 0.1s var(--ease);
    -webkit-tap-highlight-color: transparent;
    min-height: 48px;
  }
  .bottom-tab .tab:active { background: var(--bg-2); }
  .bottom-tab .tab.on { color: var(--brand); }
  .bottom-tab .tab.on .ico { transform: scale(1.08); }
  .bottom-tab .tab .ico {
    font-size: 19px;
    line-height: 1;
    transition: transform 0.15s var(--ease);
  }
  .bottom-tab .tab .lbl {
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.1px;
    line-height: 1;
  }
  .bottom-tab .tab.on .lbl { font-weight: 700; }
}

/* ── MOBILE FILTER SHEET (bottom drawer) ─────────────────────────── */
.filter-sheet-bg {
  position: fixed; inset: 0; z-index: 95;
  background: rgba(0, 0, 0, 0.45);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fadeIn 0.18s var(--ease);
}
.filter-sheet-bg[hidden] { display: none !important; }
.filter-sheet {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  max-height: 88vh;
  display: flex; flex-direction: column;
  animation: sheetUp 0.25s var(--ease);
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
}
@keyframes sheetUp {
  from { transform: translateY(100%); }
  to { transform: none; }
}
.filter-sheet-grab {
  width: 40px; height: 4px; border-radius: 2px;
  background: var(--line-2);
  margin: 8px auto 0;
  flex-shrink: 0;
}
.filter-sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px 8px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--line);
}
.filter-sheet-head h3 {
  font-size: 15px; font-weight: 700;
}
.filter-sheet-body {
  padding: 16px;
  display: flex; flex-direction: column; gap: 18px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.fs-field { display: flex; flex-direction: column; gap: 8px; }
.fs-field > label {
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.5px;
  color: var(--muted);
}
.fs-dates {
  display: flex; align-items: center; gap: 8px;
  color: var(--muted);
}
.fs-dates input[type="date"] {
  flex: 1; min-width: 0;
  padding: 10px 12px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 14px; font-family: inherit;
  color: var(--text);
}
.fs-dates input[type="date"]:focus { outline: 0; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.fs-toggle {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.fs-toggle input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand); }
.fs-actions { display: flex; gap: 8px; }
.fs-actions .btn-secondary { flex: 1; padding: 12px 14px; font-size: 13.5px; }
.seg.full {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  padding: 3px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 9px;
}
.seg.full button {
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 7px;
  color: var(--muted);
}
.seg.full button.on {
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* On desktop the filter sheet is hidden — never used */
@media (min-width: 761px) {
  .filter-sheet-bg { display: none !important; }
}


/* ── Market dropdown (replaces the 50-tab bar) ── */
.mkt-select{appearance:none;-webkit-appearance:none;background:var(--bg-2) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 10px center;border:1px solid var(--border);border-radius:9px;color:var(--text);font-size:12px;font-weight:600;font-family:inherit;padding:8px 28px 8px 12px;cursor:pointer;outline:none;max-width:210px}
.mkt-select:hover{border-color:var(--accent)}
.mkt-select:focus{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft,rgba(124,111,255,.15))}

/* ── Collapsible nav groups ── */
.nav-group.collapsible .nav-group-label{cursor:pointer;user-select:none;display:flex;align-items:center;justify-content:space-between}
.nav-group.collapsible .nav-group-label:hover{color:var(--text)}
.nav-group .chev{font-size:10px;color:var(--faint);transition:transform .15s ease;display:inline-block}
.nav-group.open .chev{transform:rotate(90deg)}
.nav-group.collapsible .nav-group-items{display:none;overflow:hidden}
.nav-group.collapsible.open .nav-group-items{display:block}


/* ── Compact single-row topbar (date controls inline) ── */
.topbar-actions{flex-wrap:wrap;row-gap:8px}
.chips.compact{display:flex;gap:2px;background:var(--bg-2);border:1px solid var(--border);border-radius:9px;padding:2px}
.chips.compact .chip{padding:5px 10px;font-size:11.5px;border-radius:7px;border:none;background:transparent;color:var(--muted);cursor:pointer;white-space:nowrap}
.chips.compact .chip:hover{color:var(--text)}
.chips.compact .chip.on{background:var(--panel);color:var(--text);box-shadow:0 1px 3px rgba(0,0,0,.25)}
.date-mini{padding:6px 8px;font-size:11.5px;width:118px}
.date-arrow{color:var(--faint);font-size:11px}
.compare-toggle.mini{display:flex;align-items:center;gap:5px;font-size:11.5px;color:var(--muted);white-space:nowrap;cursor:pointer}

/* ── Smooth accordion for collapsible nav groups ── */
.nav-group.collapsible .nav-group-items{display:block;max-height:0;overflow:hidden;transition:max-height .22s ease}
.nav-group.collapsible.open .nav-group-items{max-height:480px}
