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

/* ── TOKENS ──────────────────────────────────────────────────────── */
:root {
  --brand: #B85C3C;
  --brand-2: #D97757;
  --brand-soft: #FBE6DB;
  --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(184, 92, 60, 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: 0 18px; 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(184, 92, 60, 0.12); color: #B85C3C; }
.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(184, 92, 60, 0.25);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(184, 92, 60, 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(184, 92, 60, 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(184, 92, 60, 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 ──────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  :root { --sidebar-w: 240px; }
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; z-index: 80;
    width: var(--sidebar-w); transform: translateX(-100%);
    transition: transform 0.25s var(--ease);
  }
  [data-mobile-nav="open"] .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .search { display: none; }
  .topbar { padding: 0 12px; gap: 8px; }
  .filter-strip { padding: 0 12px; }
  .view { padding: 16px; }
  .seg button { padding: 4px 8px; }
}

/* ── 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; }
