/* Layout: sticky control bar over a single column of cards; numbers first, then the bottleneck, then detail. */
:root {
  --red: #c8102e;
  --red-soft: #fbe9ec;
  --ink: #17191d;
  --muted: #5f6672;
  --line: #e1e3e8;
  --bg: #f3f4f6;
  --card: #ffffff;
  --ok: #1a7f37;
  --ok-soft: #e6f4ea;
  --warn: #9a6700;
  --warn-soft: #fff4d6;
  --bad: #b42318;
  --bad-soft: #fde8e7;
  --chart-a: #c8102e;
  --chart-b: #2b4c7e;
  --grid: #eceef2;
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Barlow", -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --red: #ff4d5e; --red-soft: #3a1a1f; --ink: #eceef2; --muted: #a0a6b1; --line: #2c3038; --bg: #121417; --card: #1b1e23;
    --ok: #4ac26b; --ok-soft: #13301c; --warn: #e3b341; --warn-soft: #3a2f12; --bad: #ff6b5f; --bad-soft: #3d1715;
    --chart-a: #ff4d5e; --chart-b: #7aa2e3; --grid: #262a31; color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--body); }
h1, h2 { font-family: var(--display); font-weight: 600; letter-spacing: .01em; margin: 0; text-wrap: balance; }
h2 { font-size: 22px; }
.muted { color: var(--muted); margin: 2px 0 0; }
.small { font-size: 13px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

.btn { font: 600 14px var(--body); border-radius: 8px; padding: 9px 14px; border: 1px solid transparent; cursor: pointer; white-space: nowrap; }
.btn-primary { background: var(--red); color: #fff; }
.btn-ghost { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .6; cursor: progress; }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, .seg button:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }

/* Sign in */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 28px; display: grid; gap: 8px; }
.login-logo { width: 140px; height: auto; margin-bottom: 8px; }
.login-card h1 { font-size: 30px; }
.login-card label { font-weight: 600; font-size: 14px; margin-top: 8px; }
.login-card .btn { margin-top: 12px; padding: 12px; }
.form-error { color: var(--bad); min-height: 1.2em; margin: 4px 0 0; font-size: 14px; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 5; background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-in { max-width: 1280px; margin: 0 auto; padding: 10px 16px; display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo { width: 92px; height: auto; }
.brand-name { font: 700 20px var(--display); letter-spacing: .02em; }
.brand-sub { color: var(--muted); font-size: 12px; }
.controls { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { font: 500 13px var(--body); background: var(--card); color: var(--ink); border: 0; padding: 8px 10px; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--card); }
.dates { display: inline-flex; align-items: center; gap: 6px; }
.dates input { padding: 6px 8px; font-size: 13px; }

.wrap { max-width: 1280px; margin: 0 auto; padding: 16px; display: grid; gap: 16px; }
.notices { display: grid; gap: 8px; }
.notice { background: var(--warn-soft); color: var(--ink); border: 1px solid var(--line); border-left: 4px solid var(--warn); border-radius: 8px; padding: 10px 12px; font-size: 14px; }
.notice.bad { background: var(--bad-soft); border-left-color: var(--bad); }

/* Headline tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 12px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: grid; gap: 4px; align-content: start; }
.tile-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.tile-value { font: 600 34px/1.05 var(--display); font-variant-numeric: tabular-nums; }
.tile-sub { font-size: 13px; color: var(--muted); }
.tile.good .tile-sub b { color: var(--ok); }
.tile.badv .tile-sub b { color: var(--bad); }

/* Cards */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; min-width: 0; }
.card-head.row { display: flex; flex-wrap: wrap; gap: 12px; justify-content: space-between; align-items: end; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 16px; }
.table-scroll { overflow-x: auto; }
.table-scroll.tall { max-height: 640px; overflow: auto; }

.verdict { margin: 0; font-size: 17px; padding: 12px 14px; border-radius: 8px; background: var(--red-soft); }
.verdict b { font-weight: 600; }
.verdict.calm { background: var(--ok-soft); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; background: var(--card); }
.tall th { position: sticky; top: 0; z-index: 1; }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.is-bottleneck td { background: var(--red-soft); }
.step-name { font-weight: 600; }
.step-help { display: block; font-size: 12px; color: var(--muted); font-weight: 400; max-width: 44ch; }
.group-row td { background: var(--bg); font: 600 12px var(--body); text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 6px 10px; }

.meter { position: relative; height: 10px; width: 160px; max-width: 100%; background: var(--grid); border-radius: 5px; }
.meter-fill { position: absolute; inset: 0 auto 0 0; border-radius: 5px; background: var(--muted); }
.meter-mark { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); left: 66.6%; }
.meter.ok .meter-fill { background: var(--ok); }
.meter.warn .meter-fill { background: var(--warn); }
.meter.bad .meter-fill { background: var(--bad); }

.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.low_data { background: var(--bg); color: var(--muted); }

/* Chart */
.chart { position: relative; min-height: 260px; }
.chart svg { display: block; }
.chart text { fill: var(--muted); font: 12px var(--body); }
.tip { position: fixed; z-index: 20; pointer-events: none; background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: 13px; box-shadow: 0 6px 20px rgba(0,0,0,.15); }

/* Forecast */
.fc-label { font-weight: 600; display: flex; justify-content: space-between; }
.fc-label output { font: 600 20px var(--display); }
#fc-spend { width: 100%; accent-color: var(--red); }
.fc { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin: 0; }
.fc div { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.fc dt { font-size: 12px; color: var(--muted); }
.fc dd { margin: 2px 0 0; font: 600 26px var(--display); font-variant-numeric: tabular-nums; }

/* Leads */
.lead-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.lead-tools input[type="search"] { min-width: 220px; }
.check { display: inline-flex; gap: 6px; align-items: center; font-size: 14px; color: var(--muted); }
.leads td { font-size: 13px; }
.leads .addr { font-weight: 600; font-size: 14px; }
.leads .sub { display: block; color: var(--muted); font-size: 12px; }
.leads select, .leads input { font-size: 13px; padding: 5px 6px; }
.leads input.sq { width: 70px; }
.leads input.note { width: 200px; }
.leads tr.hidden-row td { opacity: .55; }
.got { white-space: nowrap; }
.save-state { display: block; font-size: 11px; color: var(--muted); min-height: 1em; }
.save-state.err { color: var(--bad); }
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 1px 6px; border-radius: 4px; background: var(--bg); color: var(--muted); margin-left: 4px; }
.tag.red { background: var(--bad-soft); color: var(--bad); }
a { color: var(--red); }

/* Share */
#summary { width: 100%; font: 13px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.share-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* Visitors */
h3 { font: 600 17px var(--display); margin: 0; letter-spacing: .01em; }
.subcard { border: 1px solid var(--line); border-radius: 10px; padding: 14px; display: grid; gap: 10px; align-content: start; min-width: 0; }
.vtiles .tile { background: var(--bg); }
.screens { display: flex; gap: 6px; overflow-x: auto; padding: 4px 2px 8px; }
.screen { flex: 0 0 auto; display: grid; gap: 6px; min-width: 150px; text-align: left; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.screen[aria-pressed="true"] { border-color: var(--red); box-shadow: 0 0 0 2px var(--red-soft); }
.screen-name { font-size: 13px; color: var(--muted); white-space: nowrap; }
.screen-n { font: 600 26px var(--display); font-variant-numeric: tabular-nums; }
.screen-bar { height: 5px; border-radius: 3px; background: var(--grid); overflow: hidden; }
.screen-bar i { display: block; height: 100%; background: var(--chart-b); border-radius: 3px; }
.hop { flex: 0 0 auto; align-self: center; display: grid; justify-items: center; font-size: 12px; font-variant-numeric: tabular-nums; min-width: 52px; }
.hop b { color: var(--chart-b); font-size: 14px; }
.hop .lost { color: var(--bad); }
.vmap { display: grid; place-items: center; min-height: 360px; }
.vmap canvas { border: 1px solid var(--line); border-radius: 18px; background: var(--card); max-width: 100%; }
.scrollbars { width: 100%; display: grid; gap: 10px; }
.sessions { list-style: none; margin: 0; padding: 0; display: grid; max-height: 420px; overflow: auto; }
.sessions li { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.sessions .sid { font-weight: 600; font-variant-numeric: tabular-nums; }
.sessions .sub { display: block; font-size: 12px; color: var(--muted); }
.bars { display: grid; gap: 12px; }
.bar-row { display: grid; gap: 4px; font-size: 14px; }
.bar-row .top { display: flex; justify-content: space-between; gap: 10px; }
.bar-row .track { height: 7px; background: var(--grid); border-radius: 4px; overflow: hidden; }
.bar-row .track i { display: block; height: 100%; background: var(--chart-b); border-radius: 4px; }
.bar-row .good { color: var(--ok); font-weight: 600; }

@media (max-width: 640px) {
  .tile-value { font-size: 28px; }
  .brand-logo { width: 72px; }
}
