:root {
  color-scheme: light;
  --bg: #f6f6f4;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --border: #e3e2de;
  --text: #0b0b0b;
  --text-2: #52514e;
  --text-3: #85847f;
  --accent: #2a78d6;
  --accent-soft: #e4eefb;
  --good: #0ca30c;
  --warning: #c98500;
  --serious: #d4622f;
  --critical: #d03b3b;
  --good-soft: #e3f4e3;
  --critical-soft: #fbe6e6;
  --warning-soft: #fdf2d9;
  --m1: #2a78d6; --m2: #eb6834; --m3: #1baf7a; --m4: #8a5cd6; --m5: #c99a1e; --m6: #d6457f;
  /* ordinal pipeline ramp (blue 250 -> 650) */
  --st1: #86b6ef; --st2: #6da7ec; --st3: #5598e7; --st4: #3987e5;
  --st5: #2a78d6; --st6: #256abf; --st7: #1c5cab; --st8: #104281;
  --st-out: #b4b3ad;
  --band-hard: #e34948; --band-ok: #0ca30c; --band-easy: #2a78d6; --band-easy-p: #86b6ef; --band-pend: #b4b3ad;
  --diff-add: #e3f4e3; --diff-del: #fbe6e6; --diff-hunk: #e4eefb;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #33332f;
    --text: #f0efec; --text-2: #c3c2b7; --text-3: #8e8d86;
    --accent: #3987e5; --accent-soft: #1c2b40;
    --good-soft: #17301a; --critical-soft: #3a1c1c; --warning-soft: #362a10;
    --m1: #3987e5; --m2: #d95926; --m3: #199e70; --m4: #9d74ea; --m5: #d6ab35; --m6: #e3628f;
    --st1: #184f95; --st2: #1c5cab; --st3: #256abf; --st4: #2a78d6;
    --st5: #3987e5; --st6: #5598e7; --st7: #6da7ec; --st8: #9ec5f4;
    --st-out: #55544f;
    --band-easy: #3987e5; --band-easy-p: #1c5cab; --band-hard: #e66767; --band-pend: #55544f;
    --diff-add: #17301a; --diff-del: #3a1c1c; --diff-hunk: #1c2b40;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121211; --surface: #1a1a19; --surface-2: #242422; --border: #33332f;
  --text: #f0efec; --text-2: #c3c2b7; --text-3: #8e8d86;
  --accent: #3987e5; --accent-soft: #1c2b40;
  --good-soft: #17301a; --critical-soft: #3a1c1c; --warning-soft: #362a10;
  --m1: #3987e5; --m2: #d95926; --m3: #199e70; --m4: #9d74ea; --m5: #d6ab35; --m6: #e3628f;
  --st1: #184f95; --st2: #1c5cab; --st3: #256abf; --st4: #2a78d6;
  --st5: #3987e5; --st6: #5598e7; --st7: #6da7ec; --st8: #9ec5f4;
  --st-out: #55544f;
  --band-easy: #3987e5; --band-easy-p: #1c5cab; --band-hard: #e66767; --band-pend: #55544f;
  --diff-add: #17301a; --diff-del: #3a1c1c; --diff-hunk: #1c2b40;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }
h1 { font-size: 22px; margin: 0 0 4px; font-weight: 650; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; font-weight: 650; }
h3 { font-size: 13px; margin: 0 0 8px; font-weight: 650; color: var(--text-2); text-transform: uppercase; letter-spacing: 0.04em; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px;
  padding: 10px 24px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; color: var(--text); white-space: nowrap; }
.brand span { color: var(--text-3); font-weight: 500; }
.crumbs { color: var(--text-3); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.crumbs a { color: var(--text-2); }
.top-right { display: flex; gap: 10px; align-items: center; color: var(--text-3); font-size: 12px; white-space: nowrap; }
select, input[type=search], button {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 9px;
}
button { cursor: pointer; }
button:hover { background: var(--surface-2); }
input[type=search] { min-width: 220px; }

main { max-width: 1400px; margin: 0 auto; padding: 24px; }
.sub { color: var(--text-2); margin: 0 0 20px; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.section { margin-top: 20px; }
.grid2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 960px) { .grid2, .grid3 { grid-template-columns: minmax(0, 1fr); } main { padding: 16px; } .topbar { padding: 10px 16px; } }

/* project cards */
.projects { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; }
.pcard { display: block; color: inherit; }
.pcard:hover { text-decoration: none; border-color: var(--accent); }
.pcard .name { font-size: 17px; font-weight: 650; }
.pcard .desc { color: var(--text-2); margin: 4px 0 12px; min-height: 42px; }
.pcard .stats { display: flex; gap: 18px; margin-top: 10px; }
.pcard .stats b { display: block; font-size: 20px; font-variant-numeric: tabular-nums; }
.pcard .stats span { color: var(--text-3); font-size: 12px; }
.empty { color: var(--text-3); font-style: italic; padding: 8px 0; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.kpi { padding: 12px 14px; }
.kpi .v { font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; line-height: 1.2; }
.kpi .l { color: var(--text-2); font-size: 12px; }
.kpi .h { color: var(--text-3); font-size: 11.5px; }

/* segmented bar */
.segbar { display: flex; height: 22px; gap: 2px; border-radius: 4px; overflow: hidden; background: var(--surface); }
.segbar.thin { height: 8px; }
.segbar > div { min-width: 3px; position: relative; cursor: pointer; }
.segbar > div:hover { filter: brightness(1.12); }
.legend { display: flex; flex-wrap: wrap; gap: 6px 14px; margin-top: 10px; font-size: 12px; color: var(--text-2); }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
.legend b { color: var(--text); font-variant-numeric: tabular-nums; }

/* pipeline cards */
.pipeline { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 8px; }
.pstage {
  border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; cursor: pointer; background: var(--surface);
  border-top: 3px solid var(--c, var(--border));
}
.pstage:hover, .pstage.on { background: var(--accent-soft); }
.pstage .n { font-size: 20px; font-weight: 650; font-variant-numeric: tabular-nums; }
.pstage .lab { font-weight: 600; font-size: 12.5px; }
.pstage .ph { color: var(--text-3); font-size: 11px; }

/* badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 1px 8px;
  border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-2); white-space: nowrap;
}
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c, var(--text-3)); }
.badge.pass { background: var(--good-soft); color: var(--good); border-color: transparent; }
.badge.fail { background: var(--critical-soft); color: var(--critical); border-color: transparent; }
.badge.warn { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

/* tables */
.tablewrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--text-2); font-size: 12px; padding: 7px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; }
th.sort { cursor: pointer; }
th.sort:hover { color: var(--text); }
td { padding: 7px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--surface-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.tid { font-family: var(--mono); font-size: 12px; overflow-wrap: anywhere; }
td.task { min-width: 300px; max-width: 460px; }
td.nowrap, td.owner { white-space: nowrap; }
.ttitle { color: var(--text-2); font-size: 12px; }
.note { color: var(--text-2); font-size: 12px; max-width: 360px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* pass meter */
.meter { display: inline-flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; }
.meter .track { width: 54px; height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; display: flex; }
.meter .fill { height: 100%; background: var(--c); border-radius: 3px; }
.meter .q { color: var(--text-3); }

/* filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; color: var(--text-2); }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }

/* stepper */
.stepper { display: flex; gap: 0; margin: 16px 0 4px; overflow-x: auto; }
.step { flex: 1; min-width: 92px; text-align: center; position: relative; font-size: 12px; color: var(--text-3); padding-top: 18px; }
.step::before { content: ""; position: absolute; top: 6px; left: 0; right: 0; height: 2px; background: var(--border); }
.step:first-child::before { left: 50%; } .step:last-child::before { right: 50%; }
.step .bul { position: absolute; top: 0; left: 50%; transform: translateX(-50%); width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid var(--border); z-index: 1; }
.step.done { color: var(--text-2); } .step.done::before { background: var(--accent); }
.step.done .bul { background: var(--accent); border-color: var(--accent); }
.step.cur { color: var(--text); font-weight: 650; }
.step.cur .bul { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.step .ph { display: block; font-size: 10.5px; color: var(--text-3); font-weight: 400; }

/* tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 20px 0 16px; overflow-x: auto; }
.tab { padding: 8px 14px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tab:hover { color: var(--text); }
.tab.on { color: var(--text); border-bottom-color: var(--accent); }
.tab .cnt { color: var(--text-3); font-size: 11px; margin-left: 4px; }

/* markdown */
.md { line-height: 1.6; max-width: 900px; }
.md h1 { font-size: 20px; margin: 0 0 12px; } .md h2 { font-size: 16px; margin: 22px 0 8px; } .md h3 { font-size: 14px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 18px 0 6px; }
.md code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; }
.md pre { background: var(--surface-2); padding: 12px; border-radius: 6px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md table { width: auto; } .md td, .md th { border: 1px solid var(--border); }

/* code / diff */
pre.code { background: var(--surface-2); border-radius: 6px; padding: 12px; overflow: auto; max-height: 640px; margin: 0; white-space: pre; }
pre.wrap { white-space: pre-wrap; word-break: break-word; }
.diff { background: var(--surface-2); border-radius: 6px; overflow: auto; max-height: 720px; font-family: var(--mono); font-size: 12px; }
.diff div { white-space: pre; padding: 0 12px; min-height: 17px; }
.diff .a { background: var(--diff-add); } .diff .d { background: var(--diff-del); }
.diff .h { background: var(--diff-hunk); color: var(--text-2); } .diff .f { font-weight: 700; color: var(--text); padding-top: 6px; }

details { border: 1px solid var(--border); border-radius: 6px; margin-bottom: 8px; background: var(--surface); }
details > summary { cursor: pointer; padding: 8px 12px; list-style: none; display: flex; gap: 8px; align-items: center; }
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; color: var(--text-3); font-size: 11px; }
details[open] > summary::before { content: "▾"; }
details > .body { padding: 0 12px 12px; }

/* checklist */
.check { display: flex; gap: 8px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.check:last-child { border-bottom: none; }
.check .ic { width: 18px; flex: none; font-weight: 700; }
.check .ic.ok { color: var(--good); } .check .ic.no { color: var(--critical); } .check .ic.na { color: var(--text-3); }

/* sample dots */
.dots { display: inline-flex; gap: 3px; flex-wrap: wrap; }
.sdot { width: 12px; height: 12px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border); }
.sdot.p { background: var(--good); border-color: var(--good); }
.sdot.f { background: var(--critical); border-color: var(--critical); }
.sdot.q { background: var(--surface-2); border-style: dashed; }
.sdot.h { background: var(--warning); border-color: var(--warning); }
.sdot.old { opacity: 0.35; }

/* timeline */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: grid; grid-template-columns: 150px 90px minmax(0, 1fr); gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.tl .ts { color: var(--text-3); font-variant-numeric: tabular-nums; font-size: 12px; }
@media (max-width: 700px) { .tl li { grid-template-columns: 1fr; gap: 2px; } }

/* trace */
.trace { display: flex; flex-direction: column; gap: 8px; }
.msg { border-radius: 8px; padding: 10px 14px; border: 1px solid var(--border); background: var(--surface); }
.msg.user { background: var(--accent-soft); border-color: transparent; }
.msg.thinking { color: var(--text-2); font-style: italic; background: var(--surface-2); border-color: transparent; }
.msg .who { font-size: 11px; color: var(--text-3); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 4px; font-style: normal; }
.msg .txt { white-space: pre-wrap; word-break: break-word; }
.toolcall > summary { font-family: var(--mono); font-size: 12px; }
.toolcall .cmd { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }
.toolcall pre { max-height: 420px; }

/* modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 24px; }
.modal .box { background: var(--surface); border-radius: 10px; width: min(1100px, 100%); max-height: 90vh; display: flex; flex-direction: column; border: 1px solid var(--border); }
.modal .hd { display: flex; justify-content: space-between; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.modal .bd { overflow: auto; padding: 12px 16px; }
.modal pre.code { max-height: none; }

.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 4px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); } .kv dd { margin: 0; word-break: break-word; }
.banner { padding: 10px 14px; border-radius: 6px; margin: 12px 0; }
.banner.parked { background: var(--warning-soft); color: var(--text); }
.loading { color: var(--text-3); padding: 40px 0; text-align: center; }
.err { color: var(--critical); }
.tip { position: fixed; pointer-events: none; z-index: 60; background: var(--text); color: var(--bg); font-size: 12px; padding: 6px 9px; border-radius: 6px; max-width: 320px; }

.msg .txt.clamp { max-height: 180px; overflow: hidden; -webkit-mask-image: linear-gradient(180deg, #000 70%, transparent); mask-image: linear-gradient(180deg, #000 70%, transparent); }
.msg button.more { margin-top: 6px; padding: 2px 8px; font-style: normal; }
.step .badge { display: inline-flex; }

@media (max-width: 700px) {
  .topbar { flex-wrap: wrap; gap: 6px 12px; }
  .crumbs { order: 3; flex-basis: 100%; }
  #updated { display: none; }
  input[type=search] { min-width: 0; width: 100%; }
  .badge { white-space: normal; }
}
