:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11,11,11,0.10);
  --accent: #2a78d6;
  --good: #006300;
  --bad: #d03b3b;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4;
  --s6: #008300; --s7: #4a3aa7; --s8: #e34948;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255,255,255,0.10);
    --accent: #3987e5;
    --good: #0ca30c;
    --bad: #d03b3b;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181;
    --s6: #008300; --s7: #9085e9; --s8: #e66767;
  }
}

* { box-sizing: border-box; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page); color: var(--ink); font-size: 14px;
}
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 220px; flex-shrink: 0; padding: 20px 12px; display: flex; flex-direction: column;
  gap: 4px; border-right: 1px solid var(--border); position: sticky; top: 0; height: 100vh;
}
.brand { font-weight: 700; font-size: 15px; padding: 0 10px 16px; }
.brand span { display: block; font-weight: 400; font-size: 12px; color: var(--muted); }
.nav-btn {
  text-align: left; padding: 9px 10px; border: none; background: none; color: var(--ink-2);
  border-radius: 8px; cursor: pointer; font-size: 14px;
}
.nav-btn:hover { background: var(--surface); }
.nav-btn.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border); }
.sidebar-foot { margin-top: auto; font-size: 11px; color: var(--muted); padding: 0 10px; }

.content { flex: 1; padding: 24px 28px; max-width: 1200px; }
.tab { display: none; }
.tab.active { display: block; }
h1 { font-size: 20px; margin-bottom: 14px; }
h2 { font-size: 15px; margin-bottom: 10px; }
h3 { font-size: 13px; margin: 12px 0 6px; color: var(--ink-2); }
.hint { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
code { background: var(--surface); border: 1px solid var(--border); border-radius: 4px; padding: 1px 4px; font-size: 12px; }

.row-between { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.row-end { display: flex; gap: 8px; justify-content: flex-end; margin-top: 12px; }

.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; margin-bottom: 16px;
}
.hidden { display: none !important; }
.loading { color: var(--muted); padding: 20px 0; }

.client-entry { padding: 14px 16px; }
.client-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.client-head .name { font-weight: 700; font-size: 15px; }
.client-head .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 7px; }
.client-spend .big { font-size: 20px; font-weight: 700; }
.client-spend .sub { font-size: 12px; color: var(--ink-2); margin: 0 6px 0 4px; }
.client-spend .delta { font-size: 12px; }
.client-stats { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12.5px; color: var(--ink-2);
                margin: 8px 0 10px; }
.client-stats strong { color: var(--ink); font-variant-numeric: tabular-nums; }
.client-head.clickable { cursor: pointer; }
.client-head.clickable:hover .name { color: var(--accent); }
.open-hint { color: var(--muted); font-weight: 400; }
.ctx-entry { padding: 8px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.ctx-entry:last-child { border-bottom: none; }
.ctx-text { color: var(--ink-2); margin-top: 3px; white-space: pre-wrap; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--muted); }

.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.seg button { border: none; background: none; padding: 6px 12px; cursor: pointer; color: var(--ink-2); font-size: 13px; }
.seg button.active { background: var(--surface); color: var(--ink); font-weight: 600; }

.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--ink-2); }
.legend .item { display: flex; align-items: center; gap: 6px; }
.legend .swatch { width: 12px; height: 3px; border-radius: 2px; }
.tooltip {
  position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12px; box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  z-index: 10; min-width: 150px;
}
.tooltip .t-date { font-weight: 600; margin-bottom: 4px; }
.tooltip .t-row { display: flex; justify-content: space-between; gap: 12px; }
.tooltip .t-row .swatch { width: 8px; height: 8px; border-radius: 2px; display: inline-block; margin-right: 5px; }
.tooltip .t-val { font-variant-numeric: tabular-nums; }

.controls { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; margin-bottom: 10px; }
.ctl { display: flex; flex-direction: column; gap: 5px; }
.ctl label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.ctl-end { flex-direction: row; gap: 8px; }
select, input, textarea {
  background: var(--surface); color: var(--ink); border: 1px solid var(--baseline);
  border-radius: 8px; padding: 7px 9px; font-size: 13px; font-family: inherit;
}
textarea { width: 100%; font-family: Consolas, monospace; margin-top: 8px; }
button {
  background: var(--surface); color: var(--ink); border: 1px solid var(--baseline);
  border-radius: 8px; padding: 7px 14px; font-size: 13px; cursor: pointer; font-family: inherit;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.danger { color: var(--bad); }
button:disabled { opacity: 0.5; cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--baseline); border-radius: 16px; padding: 5px 12px; cursor: pointer;
  font-size: 12px; background: none; color: var(--ink-2);
}
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

details summary { cursor: pointer; color: var(--ink-2); font-size: 13px; }

.metrics-picker {
  border: 1px solid var(--border); border-radius: 10px; padding: 12px;
  margin-top: 10px; max-height: 380px; overflow-y: auto; background: var(--page);
}
.metrics-picker .row-between { position: sticky; top: -12px; background: var(--page); padding: 4px 0 8px; z-index: 2; }
.mg { margin-bottom: 10px; }
.mg h3 { margin: 8px 0 4px; }
.mg h3 .count { color: var(--muted); font-weight: 400; }
.mg-items { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 2px 12px; }
.mg-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--ink-2);
           padding: 3px 4px; border-radius: 6px; cursor: pointer; }
.mg-item:hover { background: var(--surface); }
.mg-item input { accent-color: var(--accent); }

.tbl-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; margin-top: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; }
th, td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th { position: sticky; top: 0; background: var(--surface); color: var(--ink-2); font-size: 11.5px;
     text-transform: uppercase; letter-spacing: 0.03em; cursor: pointer; user-select: none; }
th .arrow { font-size: 10px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: color-mix(in srgb, var(--accent) 6%, transparent); }

.acct-block { margin-bottom: 18px; }
h2 .count { color: var(--muted); font-weight: 400; font-size: 13px; }
.meta { color: var(--muted); font-size: 12px; }

.wf-item { display: flex; align-items: center; gap: 10px; }
.wf-item .grow { flex: 1; }
.wf-item .steps { color: var(--muted); font-size: 12px; }
.wf-step-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; flex-wrap: wrap; }

.out-row { display: flex; gap: 10px; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.out-row:last-child { border-bottom: none; }
.out-row .grow { flex: 1; }
.out-row .meta { color: var(--muted); font-size: 12px; }
.out-row a { color: var(--accent); cursor: pointer; }
pre#out-viewer-body { white-space: pre-wrap; font-size: 12px; max-height: 480px; overflow: auto; }

.error { background: color-mix(in srgb, var(--bad) 8%, var(--surface)); border: 1px solid var(--bad);
         color: var(--ink); border-radius: 10px; padding: 10px 12px; margin: 10px 0; font-size: 13px; }

.goal-panel textarea { width: 100%; font-family: inherit; margin-top: 6px; }
.chip-badge { display: inline-block; border: 1px solid var(--baseline); border-radius: 10px;
              padding: 2px 9px; font-size: 11px; color: var(--ink-2); margin-left: 4px; }
.chip-badge.chip-up { color: var(--good); border-color: var(--good); }
.chip-badge.chip-down { color: var(--bad); border-color: var(--bad); }
.sugg { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-top: 8px;
        background: var(--page); }
.sugg .sugg-actions { margin-top: 8px; display: flex; gap: 8px; }
pre.findings { white-space: pre-wrap; font-size: 12.5px; background: var(--page);
               border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-top: 8px; }
.followup-banner { border-color: var(--accent); }
.goal-label { font-size: 12px; color: var(--ink-2); font-weight: 600; }
.suggestion {
  display: flex; align-items: center; gap: 10px; border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; margin-top: 8px; background: var(--page);
}
.suggestion .grow { flex: 1; }
.suggestion .steps { color: var(--ink-2); font-size: 12.5px; margin: 2px 0; }
.filters { margin-top: 12px; border-top: 1px solid var(--grid); padding-top: 10px; }
#filter-rows { margin-top: 8px; }

.auth-screen {
  position: fixed; inset: 0; z-index: 100; background: var(--page);
  display: flex; align-items: center; justify-content: center;
}
.auth-card { width: 360px; display: flex; flex-direction: column; gap: 12px; }
.auth-card h1 { margin-bottom: 0; }
.auth-card input { width: 100%; }
.sidebar-foot select { width: 100%; }
