/* Crawl Ledger. Light and dark tokens; dark is selected per step, not inverted. */
:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f2ee;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #6f6d68;
  --axis-text: #898781;
  --grid: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.22);
  --focus: #2a78d6;
  --btn-bg: #0b0b0b;
  --btn-ink: #ffffff;
  --hover-wash: rgba(11, 11, 11, 0.05);
  --code-bg: #f3f2ee;
  --critical: #c23434;
  --good: #006300;
  --warn-ink: #8a5a00;
  --cat-human: #a8a69e;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #6250d6;
  --series-8: #e34948;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px rgba(11, 11, 11, 0.05);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #a3a198;
    --axis-text: #898781; --grid: #2c2c2a; --baseline: #383835; --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.24);
    --focus: #5598e7; --btn-bg: #f0efec; --btn-ink: #0b0b0b; --hover-wash: rgba(255, 255, 255, 0.06); --code-bg: #131312;
    --critical: #e66767; --good: #0ca30c; --warn-ink: #fab219; --cat-human: #6b6a64;
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321; --ink: #f0efec; --ink-2: #c3c2b7; --muted: #a3a198;
  --axis-text: #898781; --grid: #2c2c2a; --baseline: #383835; --border: rgba(255, 255, 255, 0.10); --border-strong: rgba(255, 255, 255, 0.24);
  --focus: #5598e7; --btn-bg: #f0efec; --btn-ink: #0b0b0b; --hover-wash: rgba(255, 255, 255, 0.06); --code-bg: #131312;
  --critical: #e66767; --good: #0ca30c; --warn-ink: #fab219; --cat-human: #6b6a64;
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500; --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 15px/1.55 var(--font); }
h1, h2, h3 { line-height: 1.2; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.12rem; font-weight: 650; }
h3 { font-size: 0.95rem; font-weight: 650; margin-bottom: 6px; }
p { margin: 0 0 10px; }
code { font-family: var(--mono); font-size: 0.88em; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
a { color: inherit; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.muted { color: var(--muted); }
.small { font-size: 0.84rem; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 12px; top: 12px; z-index: 10; background: var(--surface); padding: 8px 12px; border-radius: 8px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Top bar */
.topbar { border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 56px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.01em; }
.brand-mark { width: 26px; height: 26px; }
.bm-bg { fill: var(--ink); } .bm-bar { fill: var(--surface); } .bm-hot { fill: var(--series-2); }

/* Buttons */
.btn { appearance: none; border: 0; background: var(--btn-bg); color: var(--btn-ink); font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 10px; cursor: pointer; }
.btn:hover { opacity: 0.88; }
.ghost-btn { appearance: none; border: 1px solid var(--border-strong); background: transparent; color: var(--ink); font: inherit; font-size: 0.86rem; padding: 6px 12px; border-radius: 9px; cursor: pointer; white-space: nowrap; }
.ghost-btn:hover { background: var(--hover-wash); }

/* Hero */
.hero { padding-top: 40px; padding-bottom: 24px; }
.hero h1 { font-size: clamp(1.8rem, 4.2vw, 2.7rem); font-weight: 750; letter-spacing: -0.025em; max-width: 18ch; }
.lede { font-size: 1.06rem; color: var(--ink-2); max-width: 70ch; margin-top: 14px; }
.privacy { font-size: 0.9rem; color: var(--ink-2); }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px; }
.wrap.card { max-width: 1140px; }
.source { margin-bottom: 24px; }
.card-head { margin-bottom: 14px; }
.card-head p { margin: 4px 0 0; }
.card-head.row { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.results { padding: 0 20px; }
.results > .card, .results > .kpis { max-width: 1140px; margin-left: auto; margin-right: auto; }

/* Tabs and segmented controls */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; overflow-x: auto; }
.tabs [role="tab"] { appearance: none; background: none; border: 0; border-bottom: 2px solid transparent; color: var(--muted); font: inherit; font-weight: 600; font-size: 0.9rem; padding: 8px 12px; cursor: pointer; white-space: nowrap; margin-bottom: -1px; }
.tabs [role="tab"][aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs [role="tab"]:hover { color: var(--ink); }
.pane { margin-bottom: 8px; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button { appearance: none; border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 0.86rem; font-weight: 600; padding: 6px 12px; border-radius: 8px; cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1px var(--border); }

/* Inputs */
textarea, input[type="search"], input[type="number"], select {
  font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 9px; padding: 8px 10px;
}
textarea { width: 100%; font-family: var(--mono); font-size: 0.8rem; line-height: 1.5; resize: vertical; margin: 6px 0 10px; }
.drop { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; text-align: center; border: 1.5px dashed var(--border-strong); border-radius: 12px; padding: 28px 16px; cursor: pointer; }
.drop:hover, .drop.over { background: var(--hover-wash); }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.drop:focus-within { outline: 2px solid var(--focus); outline-offset: 2px; }
.drop-icon { font-size: 1.5rem; }
.robots { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 12px; }
.robots summary, .table-view summary { cursor: pointer; font-weight: 600; font-size: 0.9rem; }
.progress { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.progress-bar { flex: 1; height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progress-bar span { display: block; height: 100%; width: 0; background: var(--ink); transition: width 0.15s; }
.status-line { margin: 10px 0 0; }

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.kpi-label { font-size: 0.82rem; color: var(--muted); font-weight: 600; }
.kpi-value { font-size: 1.85rem; font-weight: 720; letter-spacing: -0.02em; line-height: 1.15; }
.kpi-name { font-size: 1.2rem; overflow-wrap: anywhere; }
.kpi-sub { font-size: 0.84rem; color: var(--ink-2); }

/* Chart */
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 16px; padding: 0; margin: 0 0 10px; font-size: 0.82rem; color: var(--ink-2); }
.legend li { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; flex: none; }
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid { stroke: var(--grid); stroke-width: 1; shape-rendering: crispEdges; }
.chart .base { stroke: var(--baseline); stroke-width: 1; shape-rendering: crispEdges; }
.chart text { fill: var(--axis-text); font-size: 11px; font-variant-numeric: tabular-nums; font-family: var(--font); }
.chart .hit { fill: transparent; cursor: default; outline: none; }
.chart .hit:hover, .chart .hit:focus-visible, .chart .hit.on { fill: var(--hover-wash); }
.chart .hit:focus-visible { stroke: var(--focus); stroke-width: 1.5; }
.tooltip { position: fixed; z-index: 30; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--border-strong); border-radius: 10px; padding: 10px 12px; font-size: 0.8rem; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16); min-width: 190px; max-width: 280px; }
.tooltip .tt-title { font-weight: 650; margin-bottom: 6px; }
.tooltip .tt-row { display: grid; grid-template-columns: 12px auto 1fr; align-items: center; gap: 6px; line-height: 1.6; }
.tooltip .tt-key { width: 12px; height: 2px; border-radius: 1px; }
.tooltip .tt-val { font-weight: 650; font-variant-numeric: tabular-nums; }
.tooltip .tt-lab { color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tooltip .tt-total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 6px; color: var(--ink-2); }
.table-view { margin-top: 12px; }

/* Tables */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
table.data th, table.data td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data th { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 650; white-space: nowrap; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data th[data-sort] { cursor: pointer; user-select: none; }
table.data th[data-sort]:hover { color: var(--ink); }
table.data th[aria-sort="descending"]::after { content: " ↓"; }
table.data th[aria-sort="ascending"]::after { content: " ↑"; }
.agents tbody tr { cursor: pointer; }
.agents tbody tr:hover { background: var(--hover-wash); }
.agent-name { font-weight: 650; display: flex; align-items: center; gap: 8px; min-width: 170px; }
.agent-name button { all: unset; cursor: pointer; overflow-wrap: anywhere; }
.agent-name button:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 3px; }
.agent-op { color: var(--muted); font-size: 0.78rem; font-weight: 400; display: block; }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 0.72rem; font-weight: 600; padding: 1px 7px; border-radius: 99px; border: 1px solid var(--border-strong); color: var(--ink-2); white-space: nowrap; }
.badge.bad { color: var(--critical); border-color: currentColor; }
.badge.ok { color: var(--good); border-color: currentColor; }
.bwcell { min-width: 150px; }
.bw { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.bw-track { flex: 1; max-width: 90px; height: 8px; background: var(--surface-2); border-radius: 4px; overflow: hidden; }
.bw-fill { height: 100%; border-radius: 0 4px 4px 0; min-width: 2px; }
.show-sm { display: none; }
.bw-pct { color: var(--muted); font-size: 0.76rem; display: block; text-align: right; }
.rb { white-space: nowrap; font-size: 0.8rem; }
.rb.bad { color: var(--critical); font-weight: 600; }
.act { padding: 5px 8px; font-size: 0.82rem; font-weight: 600; }
.act.block { color: var(--critical); border-color: currentColor; }
.act.ratelimit { color: var(--warn-ink); border-color: currentColor; }
.act.changed { box-shadow: 0 0 0 2px var(--focus); }
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; justify-content: space-between; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { appearance: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border-strong); background: transparent; color: var(--ink-2); font: inherit; font-size: 0.8rem; padding: 4px 10px; border-radius: 99px; cursor: pointer; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--page); border-color: var(--ink); }
#agentSearch { min-width: 220px; flex: 0 1 260px; }

/* Rules */
.rules-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-bottom: 8px; }
.rl-input { font-size: 0.86rem; color: var(--ink-2); display: inline-flex; align-items: center; gap: 8px; }
.rl-input input { width: 76px; }
.savings { display: flex; flex-wrap: wrap; gap: 6px 28px; align-items: baseline; background: var(--surface-2); border-radius: 12px; padding: 14px 16px; margin: 12px 0 16px; }
.savings .big { font-size: 1.7rem; font-weight: 750; letter-spacing: -0.02em; }
.savings .of { color: var(--ink-2); }
.savings .split { font-size: 0.84rem; color: var(--ink-2); }
.code-wrap { position: relative; }
.code-actions { position: absolute; right: 10px; top: 10px; display: flex; gap: 6px; }
.code-actions .ghost-btn { background: var(--surface); }
.code { margin: 0; background: var(--code-bg); border: 1px solid var(--border); border-radius: 12px; padding: 16px; padding-top: 48px; font: 0.78rem/1.6 var(--mono); overflow: auto; max-height: 460px; white-space: pre; }

/* Explainer */
.explain .cols { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-top: 14px; }
.explain p { font-size: 0.88rem; color: var(--ink-2); }
.foot { padding-top: 6px; padding-bottom: 40px; }

/* Detail dialog */
dialog { border: 1px solid var(--border-strong); border-radius: 16px; padding: 0; background: var(--surface); color: var(--ink); width: min(820px, calc(100vw - 24px)); max-height: calc(100vh - 32px); }
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.dlg-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 18px 20px 10px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); z-index: 1; }
.dlg-head p { margin: 4px 0 0; }
.dlg-body { padding: 16px 20px 22px; }
.dlg-body h3 { margin-top: 18px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.stat b { display: block; font-size: 1.15rem; }
.stat span { font-size: 0.78rem; color: var(--muted); }
.why { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 0.9rem; }
.ua { font-family: var(--mono); font-size: 0.75rem; background: var(--code-bg); border-radius: 8px; padding: 8px 10px; margin: 6px 0; overflow-wrap: anywhere; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.two table td:first-child { overflow-wrap: anywhere; font-family: var(--mono); font-size: 0.76rem; }

@media (max-width: 900px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .explain .cols { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .wrap, .results { padding-left: 14px; padding-right: 14px; }
  .card { padding: 16px 14px; }
  .hero { padding-top: 26px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 1.45rem; }
  .kpi-name { font-size: 1.02rem; }
  .hide-sm { display: none; }
  .show-sm { display: inline-flex; }
  .explain .cols, .two { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  #agentSearch { flex: 1 1 100%; min-width: 0; }
  table.data th, table.data td { padding: 8px 6px; }
  .agent-name { min-width: 0; }
  .agent-name button { overflow-wrap: anywhere; word-break: break-word; }
  .bwcell { min-width: 74px; }
  .bw-track { display: none; }
  .rb { white-space: normal; }
  .agent-name .sw { display: none; }
  .act { padding: 4px 2px; font-size: 0.76rem; width: 86px; }
  .badge { white-space: normal; }
  .savings .big { font-size: 1.4rem; }
}
@media (forced-colors: active) {
  .bw-fill, .sw, .tt-key { forced-color-adjust: none; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------- navigation, shared reports, saving ---------- */
a.brand { color: inherit; text-decoration: none; }
.topnav { display: flex; align-items: center; gap: 14px; font-size: 0.9rem; }
.topnav a { color: var(--ink-2); text-decoration: none; }
.topnav a:hover, .topnav a[aria-current="page"] { color: var(--ink); text-decoration: underline; text-underline-offset: 3px; }
@media (max-width: 560px) { .topnav a:first-child { display: none; } .topnav { gap: 10px; } #themeLabel { display: none; } }
a.btn, a.ghost-btn { display: inline-block; text-decoration: none; }
.ghost-btn.danger { color: var(--critical); border-color: color-mix(in srgb, var(--critical) 45%, transparent); }
.ghost-btn:disabled, .btn:disabled { opacity: 0.55; cursor: progress; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.74rem; font-weight: 600; color: var(--muted); margin: 0 0 6px; }
.shared, .shared-missing { margin-top: 24px; }
.shared h1, .shared-missing h1 { margin: 0 0 4px; font-size: clamp(1.4rem, 3.4vw, 2rem); letter-spacing: -0.02em; overflow-wrap: anywhere; }
.shared-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 12px; }
#ownerActions { display: inline-flex; flex-wrap: wrap; gap: 8px; }
#ownerActions[hidden] { display: none; }
.status-line.err { color: var(--critical); }
.status-line.ok { color: var(--good); }
.share-card { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 760px) { .share-card { grid-template-columns: 1fr; } }
.share-card h2 { margin-top: 0; }
.share-form { display: grid; gap: 6px; }
.share-row, .share-result { display: flex; gap: 8px; }
.share-row input, .share-result input { flex: 1; min-width: 0; font: inherit; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); }
.share-result input { font-family: var(--mono); font-size: 0.85rem; }
@media (max-width: 460px) { .share-row { flex-direction: column; } }
.mine { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; }
.mine h3 { font-size: 0.9rem; margin: 0 0 6px; }
.mine ul { margin: 0; padding-left: 18px; font-size: 0.9rem; }
.mine li { margin: 3px 0; }
.mine li span { color: var(--muted); font-size: 0.82rem; }
/* about page */
.prose { max-width: 760px; }
.prose h2 { margin-top: 1.8em; }
.prose pre { background: var(--code-bg); padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-family: var(--mono); font-size: 0.84rem; }
.prose code { font-family: var(--mono); font-size: 0.88em; }
.prose table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
.prose td, .prose th { border-bottom: 1px solid var(--border); padding: 6px 8px; text-align: left; vertical-align: top; }
