:root {
  /* Chart colours: the validated 8-slot categorical palette, in its fixed order. */
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100;
  --s5: #e87ba4; --s6: #008300; --s7: #6250d6; --s8: #e34948;
  --s-other: #b4b2a9;
  --grid: #e1e0d9;
  --axis: #898781;
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e2e5ea;
  --accent: #317a4b;
  --accent-text: #ffffff;
  --hover: #f0f4f1;
  --danger: #b42318;
  --manual: #d97706;
  --deleted: #98a2b3;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --panel: #1a1f27;
    --text: #e6e8ec;
    --muted: #98a2b3;
    --line: #2c333e;
    --accent: #4fa36c;
    --hover: #222a33;
    --danger: #f97066;
    --manual: #fbbf24;
    --deleted: #5d6675;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500;
    --s5: #d55181; --s6: #008300; --s7: #9085e9; --s8: #e66767;
    --s-other: #5d5c57;
    --grid: #2c2c2a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0; }
h1 { font-size: 18px; margin: 0; }
h2 { font-size: 16px; margin: 16px 0 8px; }

button, select, input {
  font: inherit;
  color: inherit;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
}
button { cursor: pointer; }
button:hover { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
button.primary:hover { filter: brightness(1.08); }
button.ghost { background: transparent; }
button.danger { color: var(--danger); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* sign in */
.login { display: flex; align-items: center; justify-content: center; min-height: 100%; padding: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 24px; }
.login-card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.login-card label, .dialog label { display: flex; flex-direction: column; gap: 4px; }

/* layout */
#app-view { display: flex; flex-direction: column; height: 100%; }
.topbar { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.stats { display: flex; gap: 14px; color: var(--muted); font-size: 13px; flex-wrap: wrap; flex: 1; }
#user-wrap, #signin-button { margin-left: auto; }
.stats b { color: var(--text); font-weight: 600; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 16px; }
.toolbar label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.toolbar label.check, label.check { flex-direction: row; gap: 6px; }
#search { flex: 1 1 260px; min-width: 200px; }
.spacer { flex: 1; }

.menu-wrap { position: relative; }
.menu { position: absolute; top: calc(100% + 4px); left: 0; z-index: 20; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: 0 6px 24px rgb(0 0 0 / 0.15); padding: 4px; min-width: 200px; display: flex; flex-direction: column; }
.menu-right { left: auto; right: 0; }
.menu button { border: 0; text-align: left; background: transparent; padding: 7px 10px; }
.menu button:hover { background: var(--hover); }
.menu.columns { max-height: 60vh; overflow: auto; padding: 8px 12px; gap: 4px; }
.menu.columns label { display: flex; gap: 6px; align-items: center; white-space: nowrap; }
.topbar .menu-wrap .menu { left: auto; right: 0; }

/* views and tabs */
.view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.tabs { display: flex; gap: 4px; }
.tabs button { border-color: transparent; background: transparent; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--hover); border-color: var(--line); color: var(--text); font-weight: 600; }
.info { margin: 0 16px 8px; color: var(--muted); font-size: 13px; }
.radio { display: flex; flex-direction: row !important; gap: 8px; align-items: flex-start; }
.radio input { margin-top: 3px; }
.status { color: var(--muted); min-height: 1.2em; margin: 0; }

/* table */
.table-wrap { flex: 1; overflow: auto; margin: 0 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
table { border-collapse: collapse; width: max-content; min-width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: 6px 10px; text-align: left; white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
.grid thead th { position: sticky; top: 0; background: var(--panel); z-index: 5; font-weight: 600; cursor: pointer; user-select: none; box-shadow: inset 0 -1px var(--line); }
.grid thead th.actions-col { cursor: default; }
.grid thead th .arrow { color: var(--muted); margin-left: 4px; }
.grid tbody tr:hover { background: var(--hover); }
.grid td.editable { cursor: text; }
.grid td.manual::after { content: " ●"; color: var(--manual); font-size: 10px; }
.grid td.code { font-family: ui-monospace, Consolas, monospace; }
.grid tr.deleted td { color: var(--deleted); }
.grid tr.deleted td.code { text-decoration: line-through; }
.grid .num-col { position: sticky; left: 0; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums;
  background: var(--panel); box-shadow: inset -1px 0 var(--line); cursor: default; }
.grid thead th.num-col { z-index: 6; }
.grid tr:hover td.num-col { background: var(--hover); }
.grid td.actions-col { position: sticky; right: 0; background: var(--panel); box-shadow: inset 1px 0 var(--line); }
.grid tr:hover td.actions-col { background: var(--hover); }
.grid td.actions-col button { padding: 2px 8px; font-size: 12px; margin-left: 4px; }
.grid td.editing { padding: 2px 4px; overflow: visible; }
.grid td.editing input, .grid td.editing select { width: 100%; min-width: 140px; padding: 3px 6px; }
.empty { text-align: center; color: var(--muted); padding: 40px; }

.pager { display: flex; align-items: center; gap: 8px; padding: 8px 16px; color: var(--muted); }
.pager label { display: flex; gap: 6px; align-items: center; }
.hint { margin: 0 16px 10px; color: var(--muted); font-size: 12px; }
.manual-sample { color: var(--manual); }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--panel); color: var(--text); max-width: min(960px, 96vw); }
dialog::backdrop { background: rgb(0 0 0 / 0.35); }
.dialog { padding: 20px; display: flex; flex-direction: column; gap: 10px; min-width: 320px; }
.dialog.wide { min-width: min(760px, 92vw); }
.dialog h2:first-child { margin-top: 0; }
.dialog-body { max-height: 60vh; overflow: auto; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
table.small th, table.small td { padding: 4px 8px; font-size: 13px; max-width: 260px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.secret { font-family: ui-monospace, Consolas, monospace; background: var(--hover); padding: 10px; border-radius: 6px; word-break: break-all; user-select: all; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 8px; z-index: 50; }
.toast.error-toast { background: var(--danger); color: #fff; }

@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; }
  /* No room to pin the buttons: let them scroll with the row. */
  .grid td.actions-col, .grid .num-col { position: static; box-shadow: none; }
  .table-wrap { margin: 0 8px; }
  .toolbar, .pager { padding-left: 8px; padding-right: 8px; }
  .pager { flex-wrap: wrap; }
}
.row-actions { display: flex; gap: 6px; }

/* dashboard */
.dash { overflow: auto; padding: 4px 16px 24px; gap: 16px; }
.dash h2 { font-size: 20px; margin: 8px 0 2px; }
.dash h3 { font-size: 15px; margin: 0 0 2px; }
.dash p.muted { margin: 0; font-size: 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.tile, .panel, .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.tile { padding: 14px 16px; }
.tile .label { color: var(--muted); font-size: 12px; }
.tile .value { font-size: 26px; font-weight: 600; margin: 2px 0; }
.tile .sub { color: var(--muted); font-size: 12px; }
.panel { padding: 16px; }
.panel-head, .section-head { display: flex; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.panel-head > div:first-child, .section-head > div:first-child { flex: 1; min-width: 200px; }
.panel-head label, .section-head label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.chart { position: relative; height: 260px; }
.chart.small { height: 180px; }
.chart svg { display: block; width: 100%; height: 100%; overflow: visible; }
.chart .axis text { fill: var(--axis); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .grid line { stroke: var(--grid); stroke-width: 1; }
.chart .base { stroke: var(--axis); stroke-width: 1; }
.chart .cross { stroke: var(--axis); stroke-width: 1; }
.chart .empty-note { fill: var(--muted); font-size: 13px; }
.tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  box-shadow: 0 6px 24px rgb(0 0 0 / 0.15); padding: 8px 10px; font-size: 12px; z-index: 10; min-width: 160px; }
.tip .row { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.tip .row span:first-child { display: flex; gap: 6px; align-items: center; }
.tip b { display: block; margin-bottom: 4px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; font-size: 12px; color: var(--muted); margin-top: 8px; }
.section-head .legend { margin-top: 4px; }
.key { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card { padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.card h4 { margin: 0; font-size: 14px; display: flex; gap: 8px; align-items: center; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .meta { font-size: 12px; color: var(--muted); }
.card .meta b { color: var(--text); font-weight: 600; }
.card svg.spark { width: 100%; height: 48px; display: block; }
.card .spark-note { height: 48px; display: flex; align-items: center; color: var(--muted); font-size: 12px; }
.seg { display: flex; gap: 2px; height: 8px; }
.seg span { border-radius: 4px; min-width: 2px; }
.card .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; font-size: 12px; color: var(--muted); }
.card .stats b { display: block; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
button.more { margin-top: 10px; }
.log-wrap { max-height: 420px; }
table.log { width: 100%; }
table.log td.num, table.log th.num { text-align: right; font-variant-numeric: tabular-nums; }
.delta { color: var(--muted); font-size: 11px; margin-left: 4px; }
#checkpoint-form { margin-bottom: 8px; }
#checkpoint-form input { flex: 1 1 260px; }
@media (max-width: 700px) {
  .dash { padding: 4px 8px 16px; }
  .chart { height: 220px; }
}
.legend > span { display: inline-flex; align-items: center; }

/* row checkboxes, visibility presets */
.grid label.pick { display: flex; gap: 8px; align-items: center; justify-content: space-between; min-width: 64px; cursor: pointer; }
.grid label.pick input { margin: 0; }
.grid tr.picked td { background: var(--hover); }
.grid tr.jh td.db { color: var(--muted); }
.menu-title { font-size: 12px; color: var(--muted); margin: 6px 0 2px; }
.menu label.preset { align-items: flex-start; white-space: normal; padding: 2px 0; }
.menu label.preset input { margin-top: 3px; }
.menu-note { margin: 4px 10px 6px; color: var(--muted); font-size: 12px; max-width: 260px; }
#selection { display: inline-flex; gap: 6px; align-items: center; color: var(--text); }
#selection button { padding: 2px 8px; }

/* dashboard, plain version */
.dash-head h2 { margin: 8px 0 2px; }
.overview { display: grid; grid-template-columns: minmax(220px, 1fr) 3fr; gap: 12px; align-items: stretch; }
.hero { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 16px 20px; display: flex; flex-direction: column; justify-content: center; }
.hero-value { font-size: 48px; font-weight: 600; line-height: 1.1; }
.hero-label { color: var(--muted); margin-top: 4px; }
.panel h3 { margin: 0 0 2px; }
.attention { list-style: none; margin: 10px 0 0; padding: 0; }
.attention li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.attention li:first-child { border-top: 0; }
.attention .count { font-size: 20px; font-weight: 600; min-width: 90px; text-align: right; font-variant-numeric: tabular-nums; }
.attention .what { flex: 1; }
.attention .what small { display: block; color: var(--muted); }
.attention li.ok .count { color: var(--muted); }
.hbars { display: grid; grid-template-columns: max-content 1fr max-content; gap: 8px 12px; align-items: center; margin-top: 10px; }
.hbars .name { color: var(--text); white-space: nowrap; }
.hbars .track { height: 14px; }
.hbars .bar { height: 14px; background: var(--s1); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbars .val { font-variant-numeric: tabular-nums; color: var(--text); }
.hbars .val small { color: var(--muted); margin-left: 6px; }
table.compare { width: 100%; margin-top: 10px; }
table.compare th, table.compare td { padding: 6px 10px; }
table.compare td.num, table.compare th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.compare td.barcell { width: 40%; }
table.compare .bar { height: 10px; background: var(--s1); border-radius: 0 4px 4px 0; min-width: 2px; }
.facts { display: flex; flex-wrap: wrap; gap: 8px 24px; margin-top: 10px; }
.facts span b { font-variant-numeric: tabular-nums; }
.linkish { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; font: inherit; }
.changes { list-style: none; margin: 8px 0 0; padding: 0; }
.changes li { display: grid; grid-template-columns: 140px 1fr; gap: 12px; padding: 8px 0; border-top: 1px solid var(--line); }
.changes li:first-child { border-top: 0; }
.changes .when { color: var(--muted); font-variant-numeric: tabular-nums; }
.changes .by { color: var(--muted); font-size: 12px; }
@media (max-width: 700px) {
  .overview { grid-template-columns: 1fr; }
  .hero-value { font-size: 40px; }
  .changes li { grid-template-columns: 1fr; gap: 2px; }
  .attention .count { min-width: 64px; font-size: 18px; }
}
