:root {
  color-scheme: light;
  --page: #f9f9f9;
  --surface: #ffffff;
  --text: #191919;
  --text-2: #666666;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #257de0;
  --good: #006c10;
  --bad: #b3261e;
  --accent: #257de0;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface: #191919;
    --text: #efefef;
    --text-2: #9c9c9c;
    --grid: #303030;
    --axis: #474747;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #338ced;
    --good: #53c556;
    --bad: #f07a72;
    --accent: #338ced;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0b0b0b;
  --surface: #191919;
  --text: #efefef;
  --text-2: #9c9c9c;
  --grid: #303030;
  --axis: #474747;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #338ced;
  --good: #53c556;
  --bad: #f07a72;
  --accent: #338ced;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--page); color: var(--text); font-size: 14px; line-height: 1.45; }
h1 { font-size: 17px; margin: 0; font-weight: 650; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 620; }
h3 { font-size: 13px; margin: 0 0 10px; font-weight: 600; color: var(--text-2); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-size: 12px; }
.muted { color: var(--text-2); }

/* Top bar + filters: one row, above everything they scope */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 2;
}
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; flex: 1; }
.filters label { display: flex; align-items: center; gap: 6px; color: var(--text-2); }
select, input, button { font: inherit; color: var(--text); }
select, input {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px;
}
button { cursor: pointer; border-radius: 6px; padding: 6px 12px; border: 1px solid var(--border); background: var(--surface); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.ghost { border-color: transparent; color: var(--text-2); }
button:disabled { opacity: 0.5; cursor: default; }
.status { color: var(--text-2); font-size: 13px; }

/* Report */
.report { max-width: 1240px; margin: 0 auto; padding: 24px; display: grid; gap: 28px; transition: opacity 0.2s; }
.report[aria-busy="true"] { opacity: 0.5; }
.section { display: grid; gap: 16px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.section-head h2 { margin: 0; font-size: 18px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; min-width: 0; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.notice { border-left: 3px solid var(--bad); }
.empty { text-align: center; padding: 48px 16px; color: var(--text-2); }

/* Stat tiles */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }
@media (max-width: 640px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.tile-label { color: var(--text-2); font-size: 13px; }
.tile-value { font-size: 26px; font-weight: 620; margin: 2px 0 4px; }
.tile-delta { font-size: 12.5px; color: var(--text-2); }
.tile-delta .chg { font-weight: 600; }
.tile-delta.good .chg { color: var(--good); }
.tile-delta.bad .chg { color: var(--bad); }

/* Suggestions */
.suggestions ol { margin: 0; padding: 0; list-style: none; display: grid; gap: 14px; }
.suggestions li { display: grid; gap: 4px; padding-bottom: 14px; border-bottom: 1px solid var(--grid); }
.suggestions li:last-child { border-bottom: 0; padding-bottom: 0; }
.sug-action { margin: 0; font-weight: 560; }
.sug-reason { margin: 0; color: var(--text-2); }
.badges { display: flex; gap: 6px; }
.badge { font-size: 11.5px; font-weight: 600; padding: 1px 8px; border-radius: 99px; border: 1px solid var(--border); color: var(--text-2); }
.badge.p-high { color: var(--text); border-color: var(--text-2); }

/* Line chart */
.chart-host { position: relative; width: 100%; }
svg.chart { display: block; overflow: visible; }
svg.chart:focus { outline: none; }
svg.chart:focus-visible { outline: 2px solid var(--accent); outline-offset: 4px; border-radius: 4px; }
.chart .grid { stroke: var(--grid); stroke-width: 1; }
.chart .axis { stroke: var(--axis); stroke-width: 1; }
.chart .tick { fill: var(--text-2); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1); fill-opacity: 0.1; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .endlabel { fill: var(--text); font-size: 12px; font-weight: 600; }
.chart .crosshair { stroke: var(--text-2); stroke-width: 1; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--text-2); font-size: 12.5px; }

/* Bars (single series -> one color) */
.bars { display: grid; gap: 8px; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 30%) 1fr; align-items: center; gap: 10px; border-radius: 4px; }
.bar-row:hover .bar, .bar-row:focus-visible .bar { filter: brightness(1.15); }
.bar-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { display: flex; align-items: center; gap: 8px; min-width: 0; }
.bar { height: 12px; min-width: 2px; background: var(--series-1); border-radius: 0 4px 4px 0; flex: none; }
.bar-value { white-space: nowrap; font-variant-numeric: tabular-nums; font-size: 13px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-2); padding: 6px 8px; border-bottom: 1px solid var(--axis); white-space: nowrap; }
td { padding: 7px 8px; border-bottom: 1px solid var(--grid); vertical-align: top; }
td:first-child { word-break: break-word; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }

/* Tooltip */
.tooltip {
  position: fixed; z-index: 10; pointer-events: none; background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  font-size: 12.5px; display: grid; gap: 1px; min-width: 90px;
}
.tooltip strong { font-size: 14px; }
.tooltip span { color: var(--text-2); }

/* Token dialog */
dialog { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 20px; width: min(420px, calc(100% - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog input { width: 100%; margin: 8px 0 14px; }
.dialog-actions { display: flex; justify-content: flex-end; }

/* Suggestions card + add form */
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.suggestions h3 { margin: 18px 0 10px; }
.suggestions h3:first-of-type { margin-top: 4px; }
.add-form { display: grid; gap: 12px; }
.add-form h2 { margin: 0; }
.add-form label { display: grid; gap: 4px; font-weight: 560; }
.add-form textarea, .add-form input { width: 100%; font: inherit; font-weight: 400; }
.add-form p { margin: 0; }
.dialog-actions { gap: 8px; }
#add-dialog { width: min(560px, calc(100% - 32px)); }

/* Risk rating (label + shape, never colour alone) */
.badge.risk-low { color: var(--good); border-color: var(--good); }
.badge.risk-medium { color: var(--text); border-color: var(--text-2); }
.badge.risk-high { color: var(--bad); border-color: var(--bad); }
.risk-note { color: var(--bad); }

/* Several at once */
.pick { display: inline-flex; align-items: center; padding-right: 2px; cursor: pointer; }
.pick input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.bulk-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 10px; margin: -4px 0 12px; border: 1px solid var(--accent); border-radius: 8px; position: sticky; top: 64px; z-index: 1; background: var(--surface); }
.bulk-bar[hidden] { display: none; }
.bulk-bar span { font-weight: 600; margin-right: 4px; }
.badge.st-queued { color: var(--text-2); }

/* Sitemap card */
.sitemap-card h3 { margin: 0; color: var(--text); font-size: 14px; }
.sitemap-card p { margin: 4px 0 0; font-size: 12.5px; }
.sitemap-reasons { margin: 8px 0 0; padding-left: 18px; font-size: 13px; }

/* Views + outreach */
.views { display: flex; gap: 4px; }
.views button { border-color: transparent; color: var(--text-2); }
.views button[aria-pressed="true"] { color: var(--text); border-color: var(--border); background: var(--page); font-weight: 600; }
.finder-form { display: grid; gap: 8px; margin: 12px 0; }
.finder-form textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.finder-runs { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 13px; }
#outreach td { vertical-align: top; }
#outreach .add-form textarea { min-height: 0; }
.message { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin-bottom: 12px; display: grid; gap: 8px; }
.message-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.message input:not([type=checkbox]), .message textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 7px 9px; }
.message textarea { line-height: 1.5; resize: vertical; }
.message [disabled] { opacity: 0.85; }
.message p { margin: 0; }
.rewrite input { flex: 1; min-width: 200px; }
.small-link { font-size: 12.5px; align-self: center; }
#sending-status { margin: 0 0 10px; font-size: 13px; }
#outreach td:first-child { min-width: 180px; }

/* Chat about a suggestion */
button.ghost-outline { background: transparent; color: var(--text-2); }
dialog.chat { display: none; }
dialog.chat[open] { display: flex; flex-direction: column; gap: 12px; height: min(760px, calc(100vh - 48px)); }
dialog.chat h2 { margin: 0; }
.chat-suggestion { border-left: 3px solid var(--accent); padding: 2px 0 2px 12px; }
.chat-suggestion p { margin: 0 0 2px; }
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-right: 4px; min-height: 120px; }
.msg { max-width: 85%; padding: 8px 12px; border-radius: 10px; }
.msg p { margin: 0 0 6px; }
.msg p:last-child { margin-bottom: 0; }
.msg ul { margin: 0 0 6px; padding-left: 18px; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.assistant { align-self: flex-start; background: var(--page); border: 1px solid var(--border); }
.msg .revised { font-weight: 600; border-top: 1px solid var(--grid); padding-top: 6px; }
.chat-starters { display: flex; flex-wrap: wrap; gap: 6px; }
.chat-starters[hidden] { display: none; }
.chat-form { display: flex; gap: 8px; align-items: flex-end; }
.chat-form textarea { flex: 1; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px; resize: vertical; }

/* Site changes */
.sug-actions { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.sug-actions:empty { display: none; }
button.small { padding: 3px 10px; font-size: 12.5px; }
.badge.st-awaiting_approval { color: var(--accent); border-color: var(--accent); }
.badge.st-pushed { color: var(--good); border-color: var(--good); }
.badge.st-failed { color: var(--bad); border-color: var(--bad); }
dialog.wide { width: min(920px, calc(100% - 32px)); max-height: calc(100vh - 48px); }
.dialog-close { position: sticky; top: 0; float: right; margin: -8px -8px 0 0; }
#change-body h2 { margin-bottom: 4px; }
.change-status { margin: 4px 0 12px; }
pre.diff {
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--page); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; overflow: auto; max-height: 50vh; white-space: pre; margin: 8px 0;
}
pre.diff span { display: block; min-width: 100%; width: max-content; }
pre.diff .add { background: rgba(10, 172, 35, 0.16); }
pre.diff .del { background: rgba(220, 60, 61, 0.16); }
pre.diff .hunk { color: var(--text-2); }
pre.diff .meta { color: var(--text-2); font-weight: 600; }
.ok { color: var(--good); font-weight: 600; }
.bad { color: var(--bad); font-weight: 600; }
.change-actions { display: grid; gap: 8px; margin: 14px 0; }
.change-actions textarea { width: 100%; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
ol.log { margin: 6px 0 0; padding-left: 0; list-style: none; font-size: 12.5px; display: grid; gap: 2px; }

@media (max-width: 640px) {
  .topbar { padding: 12px 16px; }
  .report { padding: 16px; gap: 22px; }
  .tile-value { font-size: 22px; }
}
.suggestions li[hidden] { display: none; }
