/* Terminal sheet. Near-black ground, hairline-framed panels, one monospace face throughout.
   Colour is kept for meaning: green for added, red for removed or failed, amber for unsure.
   Charts are greyscale dots and hatching. Grid: 12 columns, 16px gutter. */
@font-face { font-family: "IBM Plex Mono"; font-weight: 400; font-display: swap; src: url(/ui/assets/fonts/mono-400.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-display: swap; src: url(/ui/assets/fonts/mono-500.woff2) format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 600; font-display: swap; src: url(/ui/assets/fonts/mono-600.woff2) format("woff2"); }

:root {
  color-scheme: dark;
  --ground: #0c0c0d; --surface: #141415; --raised: #1c1c1e; --active: #232326;
  --border: #262629; --rule: #1e1e21; --control: #34343a;
  --text: #ececee; --muted: #9a9aa0; --faint: #86868d; --accent: #ececee;
  --primary: #ececee; --primary-ink: #0c0c0d;
  --positive: #3fcf8e; --negative: #f0555a; --warning: #e6a23c;
  --dot-1: #f2f2f3; --dot-2: #c4c4c8; --dot-3: #7f7f86; --dot-off: #2a2a2e;
  --radius-card: 10px; --radius-control: 6px;
  --sidebar-width: 236px; --gap: 16px; --pad: 20px; --control-height: 32px;
  --fs-title: 22px; --fs-section: 15px; --fs-kpi: 26px; --fs-body: 14px; --fs-small: 12px;
  --mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; background: var(--ground); }
body { margin: 0; background: var(--ground); color: var(--text); font: var(--fs-body)/20px var(--mono); -webkit-font-smoothing: antialiased; }
h1, h2, h3, p, ul, ol, dl, dd { margin: 0; }
ul, ol { padding: 0; list-style: none; }
button, input, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
:focus-visible { outline: 1px solid var(--text); outline-offset: 2px; border-radius: 4px; }
::selection { background: #3a3a40; }
code, .mono { font-family: var(--mono); font-size: 13px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.up { color: var(--positive); } .down { color: var(--negative); }
table, .num { font-variant-numeric: tabular-nums; }

/* ---- shell ---- */
.app { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); grid-template-rows: 52px minmax(0, 1fr); min-height: 100svh; }
.topbar { grid-column: 2; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 var(--pad); color: var(--muted); border-bottom: 1px solid var(--border); }
.crumbs { display: flex; gap: 8px; min-width: 0; white-space: nowrap; overflow: hidden; }
.crumbs span:last-child { color: var(--text); }
.linkish { height: 28px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius-control); background: none; color: var(--muted); cursor: pointer; }
.linkish:hover { color: var(--text); border-color: var(--control); }
.sidebar { grid-row: 1 / span 2; position: sticky; top: 0; height: 100svh; display: flex; flex-direction: column; padding: 0 12px 12px; overflow: auto; border-right: 1px solid var(--border); }
.brand { display: flex; align-items: center; gap: 10px; height: 52px; margin: 0 4px 12px; font-weight: 600; letter-spacing: 0.01em; }
.brand svg { flex: none; }
.nav-label { margin: 0 6px 8px; font-size: var(--fs-small); color: var(--faint); }
.nav-item { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 40px; margin-bottom: 6px; padding: 0 12px; border: 1px solid var(--border); border-radius: var(--radius-control); background: var(--surface); color: var(--muted); }
.nav-item:hover { color: var(--text); border-color: var(--control); text-decoration: none; }
.nav-item[aria-current="page"] { color: var(--text); border-color: var(--control); background: var(--raised); }
.nav-item .stack { font-size: var(--fs-small); color: var(--faint); }
.nav-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet { grid-column: 2; min-width: 0; padding: var(--pad); }

/* ---- title ---- */
.title-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
h1 { font-size: var(--fs-title); line-height: 30px; font-weight: 500; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.sub { margin-top: 4px; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.finding { margin-top: 14px; max-width: 90ch; }
.notice { margin-top: 12px; padding: 10px 12px; border: 1px solid #4a3a1f; border-radius: var(--radius-control); background: #1d1810; color: #f0c27a; }
.notice.err { border-color: #5a2427; background: #1f1112; color: #ff9a9d; }
.notice a { color: inherit; }
.actions { display: flex; align-items: center; gap: 8px; flex: none; }

/* ---- tabs: one segmented bar ---- */
.tabs { display: flex; margin: 20px 0 var(--gap); border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); overflow-x: auto; scrollbar-width: none; }
.tabs a { flex: 1 0 auto; display: flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 14px; color: var(--muted); white-space: nowrap; }
.tabs a + a { border-left: 1px solid var(--border); }
.tabs a:hover { color: var(--text); text-decoration: none; background: var(--raised); }
.tabs a[aria-selected="true"] { color: var(--text); background: var(--active); font-weight: 500; }
.tabs .count { color: var(--faint); font-weight: 400; font-size: var(--fs-small); }

/* ---- KPIs ---- */
.kpis { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); margin-bottom: var(--gap); padding: 18px 4px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); }
.kpi { display: block; padding: 0 16px; }
.kpi:hover { text-decoration: none; }
.kpi:hover .kpi-label { color: var(--text); }
.kpi-label { color: var(--muted); font-size: 13px; }
.kpi-value { margin-top: 6px; font-size: var(--fs-kpi); line-height: 30px; font-weight: 500; letter-spacing: -0.02em; }
.kpi-delta { display: flex; gap: 8px; margin-top: 6px; font-size: var(--fs-small); }

/* ---- blocks ---- */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--gap); align-items: start; }
.col-7 { grid-column: span 7; } .col-5 { grid-column: span 5; } .col-12 { grid-column: 1 / -1; }
.stack-blocks { display: grid; gap: var(--gap); min-width: 0; }
.panel { min-width: 0; padding: 18px var(--pad) var(--pad); border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); }
.panel > header { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 28px; margin-bottom: 14px; }
h2 { font-size: var(--fs-section); line-height: 22px; font-weight: 500; overflow-wrap: anywhere; }
.meta { color: var(--faint); font-size: var(--fs-small); line-height: 18px; }
.chip { display: inline-flex; align-items: center; flex: none; height: 26px; padding: 0 9px; border: 1px solid var(--control); border-radius: var(--radius-control); color: var(--muted); font-size: var(--fs-small); white-space: nowrap; }
a.chip:hover { color: var(--text); border-color: var(--muted); text-decoration: none; }
.rows li { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 0; min-width: 0; }
.rows li + li { border-top: 1px solid var(--rule); }
.rows .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.sign { flex: none; width: 14px; font-weight: 600; text-align: center; }
.sign.add { color: var(--positive); } .sign.del { color: var(--negative); } .sign.chg { color: var(--warning); }
.tag { flex: none; color: var(--faint); font-size: var(--fs-small); }
.commit[aria-current="true"] a { color: var(--text); font-weight: 500; }
.commit a { color: var(--muted); }
.tally { flex: none; font-size: var(--fs-small); color: var(--faint); }

/* ---- provenance: one square per route ---- */
.waffle { display: grid; grid-template-rows: repeat(8, auto); grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 3px; max-width: 100%; }
.waffle i { display: block; aspect-ratio: 1; border-radius: 1.5px; min-width: 3px; }
.prov-spec { background: var(--dot-1); }
.prov-override { background: var(--dot-2); }
.prov-code { background: var(--dot-3); }
.prov-ai { background: repeating-linear-gradient(-45deg, var(--dot-2) 0 1.5px, transparent 1.5px 3.5px); box-shadow: inset 0 0 0 1px var(--dot-3); }
.prov-guess { background: var(--dot-off); }
.legend { display: grid; gap: 4px; margin-top: 16px; }
.legend li { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto 5ch; align-items: center; gap: 10px; min-height: 24px; }
.legend b { font-weight: 500; text-align: right; }
.legend.inline { display: flex; flex-wrap: wrap; gap: 6px 20px; margin-top: 14px; }
.legend.inline li { display: flex; color: var(--muted); font-size: var(--fs-small); }
.key { display: block; width: 10px; height: 10px; border-radius: 1.5px; }

/* ---- route areas: solid where access is read, hatched where it is not ---- */
.defs { position: absolute; width: 0; height: 0; }
.bars li { display: grid; grid-template-columns: 15ch minmax(0, 1fr) 16ch; align-items: center; gap: 14px; min-height: 30px; }
.bar-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.bar-label a { color: var(--text); }
.bar { display: block; width: 100%; height: 14px; overflow: visible; }
.bar-known { fill: var(--dot-1); }
.bar-review { fill: url(#hatch); }
.hatch-ink { fill: var(--dot-2); }
.bar-value { color: var(--text); font-size: var(--fs-small); white-space: nowrap; }
.bar-known-key { background: var(--dot-1); }
.bar-review-key { background: repeating-linear-gradient(-45deg, var(--dot-2) 0 1.5px, transparent 1.5px 3.5px); }

/* ---- security ---- */
.seg { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.seg .chip { gap: 6px; }
.chip[aria-current="true"] { color: var(--text); border-color: var(--muted); background: var(--raised); }
.table-wrap.flush { border: 0; border-radius: 0; padding: 0; background: none; }
code.snippet { display: inline-block; max-width: 56ch; color: var(--muted); font-size: var(--fs-small); overflow-wrap: anywhere; }
.sev-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.sev-strip li { display: grid; gap: 4px; padding-left: 10px; border-left: 2px solid var(--dot-off); }
.sev-strip b { font-size: 20px; line-height: 24px; font-weight: 500; }
.sev-strip .sev-critical, .sev-strip .sev-high { border-left-color: var(--negative); }
.sev-strip .sev-medium { border-left-color: var(--warning); }
.sev-strip .sev-low { border-left-color: var(--dot-3); }
ul.plain { margin: 0; padding: 0; list-style: none; }
.spark { display: inline-flex; align-items: flex-end; gap: 2px; height: 18px; }
.spark i { display: block; width: 4px; background: var(--muted); }
.spark i:last-child { background: var(--text); }
.spark .l1 { height: 3px; } .spark .l2 { height: 6px; } .spark .l3 { height: 9px; } .spark .l4 { height: 12px; } .spark .l5 { height: 15px; } .spark .l6 { height: 18px; }
td.bad { color: var(--negative); }
.sub.down { color: var(--negative); } .sub.up { color: var(--positive); }
table.perf td.n, table.perf th.n { white-space: nowrap; }
ol.steps { margin: 0; padding-left: 22px; }
ol.steps li { padding: 6px 0; overflow-wrap: anywhere; }
ol.steps li + li { border-top: 1px solid var(--rule); }
pre.code { margin: 0; padding: 12px; overflow-x: auto; border: 1px solid var(--rule); border-radius: var(--radius-control); background: var(--raised); font-size: var(--fs-small); line-height: 1.6; white-space: pre; }
ul.plain li + li { margin-top: 4px; }

/* ---- tables ---- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.toolbar form { display: flex; gap: 8px; flex: 1; max-width: 460px; }
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); padding: 0 var(--pad); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { height: 40px; padding: 0 14px 0 0; text-align: left; font-weight: 400; font-size: var(--fs-small); color: var(--faint); border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 14px 10px 0; border-bottom: 1px solid var(--rule); vertical-align: baseline; overflow-wrap: break-word; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #17171a; }
th.n, td.n { text-align: right; white-space: nowrap; }
th:last-child, td:last-child { padding-right: 0; }
td .sub { font-size: var(--fs-small); margin-top: 2px; }
td strong { font-weight: 500; }
.nowrap { white-space: nowrap; }
.evidence { max-width: 46ch; }
code.src { display: inline-block; vertical-align: top; min-width: 22ch; max-width: 42ch; overflow-wrap: break-word; }
.method { font-size: var(--fs-small); font-weight: 600; color: var(--muted); }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 8px; border: 1px solid var(--control); border-radius: var(--radius-control); font-size: var(--fs-small); white-space: nowrap; color: var(--muted); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--faint); }
.pill.pos { color: var(--positive); border-color: #1f4d39; } .pill.pos::before { background: var(--positive); }
.pill.neg { color: var(--negative); border-color: #5a2427; } .pill.neg::before { background: var(--negative); }
.pill.warn { color: var(--warning); border-color: #4a3a1f; } .pill.warn::before { background: var(--warning); }

/* ---- controls ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; height: var(--control-height); padding: 0 12px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap; transition: background-color 150ms ease, border-color 150ms ease; }
.btn:hover { background: var(--raised); border-color: var(--muted); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); color: var(--primary-ink); border-color: transparent; font-weight: 500; }
.btn.primary:hover { background: #ffffff; }
.btn.danger:hover { color: var(--negative); border-color: #5a2427; }
.input { width: 100%; height: var(--control-height); padding: 0 10px; border: 1px solid var(--control); border-radius: var(--radius-control); background: var(--ground); }
.input::placeholder { color: var(--faint); }
.input:focus { border-color: var(--muted); outline: none; }
select.input { padding-right: 6px; }
.fix summary { color: var(--muted); cursor: pointer; white-space: nowrap; list-style: none; font-size: var(--fs-small); }
.fix summary::-webkit-details-marker { display: none; }
.fix summary:hover { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.fix[open] summary { color: var(--text); margin-bottom: 8px; }
.fix-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; width: 300px; }
.fix-form label { grid-column: 1 / -1; }
.fix-form label, .form-grid label { display: grid; gap: 6px; font-size: var(--fs-small); color: var(--muted); }
.stack-form { display: grid; gap: 12px; }
.chat { display: grid; gap: 10px; max-width: 900px; }
.msg { padding: 12px 14px; border: 1px solid var(--rule); border-radius: var(--radius-card); }
.msg .who { margin-bottom: 4px; color: var(--muted); font-size: var(--fs-small); }
.msg .body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.msg.user { background: var(--raised); margin-left: 15%; }
.msg.assistant { margin-right: 15%; }
.msg.tool, .msg.event { padding: 8px 14px; color: var(--muted); font-size: var(--fs-small); margin-right: 15%; }
.msg.tool summary, .msg.event summary { cursor: pointer; }
.msg.tool .body, .msg.event .body { margin-top: 8px; max-height: 320px; overflow: auto; }
.stack-form label, .form-row label { display: grid; gap: 6px; font-size: var(--fs-small); color: var(--muted); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; align-items: end; }
textarea.input { height: auto; min-height: 72px; padding: 8px 10px; resize: vertical; font: inherit; line-height: 1.5; }
.form-grid { display: grid; grid-template-columns: 140px minmax(0, 1fr) 130px minmax(0, 1fr) auto; gap: 12px; align-items: end; }
.empty { padding: 20px; border: 1px dashed var(--control); border-radius: var(--radius-card); color: var(--muted); }
.empty code { color: var(--text); }
.spaced { margin-top: var(--gap); }
.spaced-s { margin-top: 12px; }
section > h2 + .muted, section > h2 + p { margin-top: 4px; }

/* ---- diff ---- */
.change-group { padding: 18px var(--pad) 8px; border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); }
.change-group + .change-group { margin-top: var(--gap); }
.change-group h2 { margin-bottom: 6px; }
.was { color: var(--muted); }
.field-change { display: block; font-size: var(--fs-small); color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }

/* ---- corrections ---- */
.sheet > section { padding: 18px var(--pad) var(--pad); border: 1px solid var(--border); border-radius: var(--radius-card); background: var(--surface); }
.sheet > section .table-wrap { border: 0; padding: 0; background: none; }

/* ---- login ---- */
.login { min-height: 100svh; display: grid; place-items: center; padding: 16px; }
.login-box { width: 100%; max-width: 420px; padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); }
.login-box .brand { height: auto; margin: 0 0 24px; }
.login-box h1 { font-size: 18px; line-height: 26px; }
.login-box form { display: grid; gap: 14px; margin-top: 20px; }
.login-box label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

.menu { display: none; }

@media (max-width: 1100px) {
  .col-7, .col-5 { grid-column: 1 / -1; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .kpis { grid-auto-flow: row; grid-template-columns: repeat(3, minmax(0, 1fr)); row-gap: 18px; }
}
@media (max-width: 860px) {
  :root { --pad: 16px; }
  .app { display: block; }
  .sidebar { position: static; height: auto; padding: 0 16px; flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { margin: 0; }
  .side-apps { display: none; }
  .menu { display: block; order: 3; width: 100%; }
  .menu summary { position: absolute; top: 14px; right: 16px; height: 26px; padding: 0 9px; border: 1px solid var(--control); border-radius: var(--radius-control); color: var(--muted); font-size: var(--fs-small); line-height: 24px; cursor: pointer; list-style: none; }
  .menu summary::-webkit-details-marker { display: none; }
  .menu[open] .menu-list { padding-bottom: 12px; }
  .topbar { padding: 0 16px; height: 44px; font-size: 13px; }
  .tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); overflow: visible; }
  .tabs a { flex-direction: column; gap: 0; height: 52px; padding: 0 4px; font-size: 13px; line-height: 18px; border-top: 1px solid var(--border); }
  .tabs a + a { border-left: 0; }
  .tabs a:nth-child(-n + 3) { border-top: 0; }
  .tabs a:not(:nth-child(3n + 1)) { border-left: 1px solid var(--border); }
  .title-row { flex-wrap: wrap; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bars li { grid-template-columns: 11ch minmax(0, 1fr) auto; gap: 10px; }
  .panel > header { flex-wrap: wrap; }
  .seg { justify-content: flex-start; }
  .sev-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .table-wrap.flush { padding: 0; }
  .bar-value .faint { display: none; }
  .fix-form { width: 100%; }
  .form-grid { grid-template-columns: 1fr; }
  .toolbar { flex-wrap: wrap; }
  .toolbar form { max-width: none; flex-basis: 100%; }
  /* Tables become two-line items. */
  .table-wrap { padding: 0 14px; }
  .stacked thead { display: none; }
  .stacked, .stacked tbody, .stacked tr, .stacked td { display: block; width: 100%; }
  .stacked tr { padding: 12px 0; border-bottom: 1px solid var(--rule); }
  .stacked tr:last-child { border-bottom: 0; }
  .stacked td { padding: 2px 0; border: 0; text-align: left; white-space: normal; }
  tbody tr:hover td { background: none; }
  .stacked td.n::before { content: attr(data-label) " "; color: var(--faint); }
  .stacked td.n, .stacked td.inline { display: inline-block; width: auto; margin-right: 12px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { transition-duration: 0.01ms !important; } }
