/* Persist Brands daily ROAS.
   One typeface (Archivo, variable width + weight). Colour is reserved for data:
   blue = revenue, orange = ad spend, aqua = ROAS; blue/red tint = above/below target. */

@font-face {
  font-family: "Archivo";
  src: url("/fonts/archivo-var.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-stretch: 62% 125%;
  font-display: swap;
}

:root {
  color-scheme: light;
  --page: #f3f4f2;
  --surface: #ffffff;
  --ink: #16181b;
  --ink-2: #5d636b;
  --rule: #e4e6e3;
  --axis: #c3c6c2;
  --wash: rgba(22, 24, 27, 0.05);
  --wash-2: rgba(22, 24, 27, 0.09);
  --rev: #257de0;
  --spend: #f47230;
  --roas: #00b894;
  --pos: #257de0;
  --neg: #ec4647;
  --mid: #efefef;
  --good: #0aac23;
  --warn: #fbb315;
  --crit: #dc3c3d;
  --up: #006c10;
  --down: #b3262a;
  --focus: #257de0;
  --shadow: 0 6px 24px rgba(22, 24, 27, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0e1012;
    --surface: #16191c;
    --ink: #eceeed;
    --ink-2: #9aa09c;
    --rule: #272b2f;
    --axis: #454a4e;
    --wash: rgba(236, 238, 237, 0.06);
    --wash-2: rgba(236, 238, 237, 0.11);
    --rev: #338ced;
    --spend: #e76624;
    --roas: #00a888;
    --pos: #338ced;
    --neg: #eb6263;
    --mid: #383838;
    --up: #53c556;
    --down: #eb6263;
    --focus: #6aabf1;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0e1012;
  --surface: #16191c;
  --ink: #eceeed;
  --ink-2: #9aa09c;
  --rule: #272b2f;
  --axis: #454a4e;
  --wash: rgba(236, 238, 237, 0.06);
  --wash-2: rgba(236, 238, 237, 0.11);
  --rev: #338ced;
  --spend: #e76624;
  --roas: #00a888;
  --pos: #338ced;
  --neg: #eb6263;
  --mid: #383838;
  --up: #53c556;
  --down: #eb6263;
  --focus: #6aabf1;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }
:root { --row: color-mix(in oklab, var(--ink) 5%, var(--surface)); }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font: 400 14px/1.45 "Archivo", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-stretch: 100%;
}
[hidden] { display: none !important; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 22px; font-weight: 650; line-height: 1.2; }
h2 { font-size: 16px; font-weight: 650; line-height: 1.25; }
h3 { font-size: 14px; font-weight: 650; }
a { color: inherit; }
code { font: inherit; font-stretch: 92%; background: var(--wash); padding: 1px 5px; border-radius: 4px; }
.muted { color: var(--ink-2); }
.num { font-stretch: 86%; font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 6px; z-index: 50; }
.skip:focus { left: 8px; }

/* ---------- header ---------- */
.top { background: var(--surface); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 20; }
.top-in { max-width: 1360px; margin: 0 auto; padding: 0 24px; min-height: 52px; display: flex; align-items: center; gap: 28px; flex-wrap: wrap; }
.brand { font-weight: 750; font-stretch: 112%; font-size: 15px; letter-spacing: 0.01em; }
.nav { display: flex; gap: 4px; }
.nav a { text-decoration: none; padding: 6px 10px; border-radius: 6px; color: var(--ink-2); font-weight: 550; }
.nav a:hover { background: var(--wash); color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--wash-2); }
.top-right { margin-left: auto; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.sync-state { color: var(--ink-2); margin-right: 6px; display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.dot.bad { background: var(--crit); }
.dot.idle { background: var(--axis); }

/* ---------- controls ---------- */
.btn {
  font: inherit; font-weight: 600; color: var(--ink); background: var(--surface);
  border: 1px solid var(--axis); border-radius: 7px; padding: 6px 12px; cursor: pointer; text-decoration: none; display: inline-block; line-height: 1.3;
}
.btn:hover { background: var(--wash); }
.btn.solid { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.btn.solid:hover { opacity: 0.88; }
.btn.quiet { border-color: transparent; background: transparent; color: var(--ink-2); padding: 6px 9px; }
.btn.quiet:hover { color: var(--ink); background: var(--wash); }
.btn.small { padding: 3px 9px; font-size: 13px; }
.btn[disabled] { opacity: 0.5; cursor: default; }
input[type="text"], input[type="password"], input[type="number"], input[type="date"], select, textarea {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--axis); border-radius: 7px; padding: 6px 9px; min-width: 0;
}
textarea { width: 100%; min-height: 64px; resize: vertical; }
label { font-weight: 600; display: block; }
label input, label select, label textarea { font-weight: 400; display: block; margin-top: 4px; }
label input[type="checkbox"] { display: inline-block; }
.hint { color: var(--ink-2); font-size: 13px; margin-top: 4px; max-width: 68ch; }
.form-error { color: var(--down); font-weight: 600; }

.seg { display: inline-flex; background: var(--wash); border-radius: 8px; padding: 2px; gap: 2px; flex-wrap: wrap; }
.seg button { font: inherit; font-weight: 600; color: var(--ink-2); background: transparent; border: 0; border-radius: 6px; padding: 5px 11px; cursor: pointer; }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--rule); }

.pill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 650; padding: 1px 8px; border-radius: 999px; background: var(--wash-2); white-space: nowrap; }
.pill.bad { background: color-mix(in oklab, var(--crit) 16%, var(--surface)); }
.pill.ok { background: color-mix(in oklab, var(--good) 16%, var(--surface)); }

/* ---------- layout ---------- */
main { max-width: 1360px; margin: 0 auto; padding: 20px 24px 64px; }
.center-card { max-width: 520px; margin: 9vh auto 0; background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; padding: 28px; display: grid; gap: 16px; }
.center-card form { display: grid; gap: 10px; }
.setup-list { margin: 0; display: grid; gap: 4px; }
.setup-list dt { font-weight: 650; margin-top: 8px; }
.setup-list dd { margin: 0; color: var(--ink-2); }

.filters { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.filters .custom { display: inline-flex; align-items: center; gap: 6px; }
.filters .period { margin-left: auto; color: var(--ink-2); }

.banner { border: 1px solid var(--rule); background: var(--surface); border-radius: 10px; padding: 10px 14px; margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; }
.banner .icon { font-weight: 800; flex: none; width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: #fff; background: var(--crit); }
.banner.info .icon { background: var(--ink-2); }
.banner.sample { border-style: dashed; }
.banner ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); }
.banner details summary { cursor: pointer; font-weight: 600; }

.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 12px; margin-bottom: 16px; }
.panel-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; padding: 14px 18px 0; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 12px 18px 18px; }

/* ---------- the equation ---------- */
.equation { display: grid; grid-template-columns: minmax(0, 1.25fr) auto minmax(0, 1.25fr) auto minmax(0, 1fr); align-items: start; column-gap: clamp(10px, 2.2vw, 34px); padding: 22px 24px 20px; }
.term-label { font-weight: 600; color: var(--ink-2); display: flex; align-items: center; gap: 7px; }
.swatch { width: 14px; height: 3px; border-radius: 2px; flex: none; }
.figure { font-weight: 620; font-stretch: 76%; font-size: clamp(38px, 5.6vw, 82px); line-height: 1.02; letter-spacing: -0.012em; margin: 4px 0 8px; white-space: nowrap; }
.term.result .figure { font-weight: 720; }
.op { font-weight: 250; font-stretch: 100%; color: var(--ink-2); font-size: clamp(30px, 4.2vw, 60px); line-height: 1; padding-top: clamp(26px, 3.2vw, 38px); user-select: none; }
.facts { display: grid; gap: 2px; color: var(--ink-2); }
.facts b { color: var(--ink); font-weight: 600; }
.delta { display: inline-flex; align-items: baseline; gap: 4px; color: var(--ink); font-weight: 600; }
.delta .arrow { font-size: 10px; }
.delta.up .arrow { color: var(--up); }
.delta.down .arrow { color: var(--down); }
.target-chip { display: inline-block; border-radius: 5px; padding: 0 7px; font-weight: 600; color: var(--ink); }

@media (max-width: 860px) {
  .equation { grid-template-columns: 1fr; row-gap: 4px; }
  .op { padding: 2px 0; font-size: 30px; }
  .figure { font-size: clamp(44px, 14vw, 72px); }
}

/* ---------- charts ---------- */
.legend { display: flex; gap: 16px; color: var(--ink-2); flex-wrap: wrap; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.key { width: 16px; height: 2px; border-radius: 1px; flex: none; }
.chart { position: relative; width: 100%; outline-offset: 4px; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { font-family: "Archivo", system-ui, sans-serif; font-stretch: 88%; font-variant-numeric: tabular-nums; font-size: 12px; fill: var(--ink-2); }
.chart text.end { fill: var(--ink); font-weight: 600; }
.grid { stroke: var(--rule); stroke-width: 1; }
.baseline { stroke: var(--axis); stroke-width: 1; }
.cross { stroke: var(--ink-2); stroke-width: 1; }
.series { fill: none; stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.series.open { stroke-dasharray: 2 5; }
.ring { stroke: var(--surface); stroke-width: 2; }
.band { fill: var(--wash); }
.target { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 4 4; }
.subhead { padding: 10px 18px 0; display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }

.tip { position: fixed; z-index: 60; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--rule); border-radius: 9px; box-shadow: var(--shadow); padding: 9px 11px; min-width: 150px; max-width: 280px; font-size: 13px; }
.tip .t-head { color: var(--ink-2); margin-bottom: 5px; }
.tip .t-row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tip .t-row .t-name { color: var(--ink-2); display: inline-flex; align-items: center; gap: 6px; }
.tip .t-row b { font-weight: 650; font-stretch: 86%; font-variant-numeric: tabular-nums; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border-radius: 0 0 11px 11px; }
table { border-collapse: collapse; width: 100%; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--rule); }
th:first-child, td:first-child { text-align: left; padding-left: 18px; }
th:last-child, td:last-child { padding-right: 18px; }
thead th { font-weight: 600; color: var(--ink-2); font-size: 13px; position: sticky; top: 0; background: var(--surface); }
thead th button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; }
thead th button:hover { color: var(--ink); }
thead th[aria-sort] button { color: var(--ink); }
tbody td { font-stretch: 86%; font-variant-numeric: tabular-nums; }
tbody td:first-child { font-stretch: 100%; font-weight: 550; max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
tbody tr:last-child td { border-bottom: 0; }
th:first-child, td:first-child { position: sticky; left: 0; z-index: 1; background: var(--surface); }
tbody tr:hover td { background: var(--row); }
tr.total td, tr.total td:first-child { font-weight: 680; background: var(--row); }
tr.loose td:first-child { font-weight: 400; color: var(--ink-2); }
td.dim, .dim { color: var(--ink-2); }
.roas-cell { display: inline-block; min-width: 54px; text-align: right; padding: 1px 7px; border-radius: 5px; font-weight: 620; }
.spark { display: inline-block; vertical-align: middle; }
.spark path { fill: none; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }

.grid-table td, .grid-table th { padding: 0; border-bottom: 1px solid var(--rule); }
.grid-table th { padding: 8px 6px; font-size: 12px; }
.grid-table th:first-child, .grid-table td:first-child { position: sticky; left: 0; background: var(--surface); z-index: 2; padding: 8px 12px 8px 18px; min-width: 170px; box-shadow: 1px 0 0 var(--rule); }
.grid-table tr.total td:first-child { background: var(--row); }
.cell { display: block; width: 100%; min-width: 58px; padding: 8px 8px; text-align: right; font: inherit; font-stretch: 86%; font-variant-numeric: tabular-nums; color: var(--ink); border: 0; background: transparent; cursor: default; }
.cell:hover, .cell:focus-visible { box-shadow: inset 0 0 0 2px var(--ink); outline: none; }
.cell.none { color: var(--ink-2); }
.scale { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); font-size: 13px; white-space: nowrap; }
.scale i { display: inline-block; width: 18px; height: 10px; border-radius: 2px; }

.empty { padding: 36px 18px; text-align: center; display: grid; gap: 10px; justify-items: center; color: var(--ink-2); }
.empty h2 { color: var(--ink); }
.foot { color: var(--ink-2); font-size: 13px; max-width: 92ch; }
.loading { opacity: 0.55; transition: opacity 0.15s; }

/* ---------- settings ---------- */
.settings { display: grid; gap: 16px; }
.settings .panel-body { display: grid; gap: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > div { display: grid; }
.row > .row { display: flex; flex-wrap: nowrap; }
.row .grow { flex: 1 1 220px; }
.row input[type="text"], .row input[type="password"] { width: 100%; }
.settings table td { font-stretch: 100%; }
.settings td.actions { display: flex; gap: 6px; justify-content: flex-end; }
.settings select { max-width: 220px; }
.status-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.status-list li { display: flex; gap: 8px; align-items: baseline; }
.status-list .err { color: var(--ink-2); }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 9px 16px; border-radius: 9px; box-shadow: var(--shadow); z-index: 70; font-weight: 600; max-width: min(90vw, 560px); }
.toast.bad { background: var(--crit); color: #fff; }

@media (max-width: 640px) {
  main { padding: 14px 12px 48px; }
  .top-in { padding: 6px 12px; gap: 10px; }
  .top-right { margin-left: 0; }
  th:first-child, td:first-child { padding-left: 12px; }
  tbody td:first-child { max-width: 132px; }
  .scale { font-size: 12px; gap: 4px; }
  .scale i { width: 12px; }
  .equation { padding: 16px 14px; }
  .filters .period { margin-left: 0; width: 100%; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media print { .top, .filters, .btn { display: none !important; } body { background: #fff; } }
