@import url('https://fonts.googleapis.com/css2?family=Hanken+Grotesk:wght@400;500;600;700;800&family=IBM+Plex+Mono:wght@400;500&display=swap');

:root {
  --paper: #F2F4F6; --panel: #FFFFFF; --ink: #17212B; --ink-2: #4A5866; --ink-3: #7A8794;
  --rule: #D3DAE1; --rule-2: #E6EBEF;
  --rail: #0E5E6F; --rail-soft: #E3F0F2; --rail-2: #2D8496;
  --amber: #C7841A; --amber-soft: #FBF1DF;
  --green: #2F7D4F; --green-soft: #E4F2E9; --red: #B4441C; --red-soft: #F8E6DE;
  --radius: 6px; --radius-lg: 10px;
  --mono: 'IBM Plex Mono', ui-monospace, monospace;
  --sans: 'Hanken Grotesk', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #12181E; --panel: #1A222A; --ink: #E7ECF0; --ink-2: #A9B5C0; --ink-3: #7D8B97;
    --rule: #2E3943; --rule-2: #252F38; --rail: #4FB3C5; --rail-soft: #173139; --rail-2: #7CCAD8;
    --amber: #E3A846; --amber-soft: #3A2E17; --green: #5DBB84; --green-soft: #183223;
    --red: #E2774F; --red-soft: #3A2019; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #12181E; --panel: #1A222A; --ink: #E7ECF0; --ink-2: #A9B5C0; --ink-3: #7D8B97;
  --rule: #2E3943; --rule-2: #252F38; --rail: #4FB3C5; --rail-soft: #173139; --rail-2: #7CCAD8;
  --amber: #E3A846; --amber-soft: #3A2E17; --green: #5DBB84; --green-soft: #183223;
  --red: #E2774F; --red-soft: #3A2019; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 15px/1.55 var(--sans); }
a { color: var(--rail); text-underline-offset: 2px; }
code, .mono { font-family: var(--mono); font-size: .86em; }
h1, h2, h3 { line-height: 1.15; letter-spacing: -0.015em; margin: 0; }
h1 { font-size: clamp(28px, 4.2vw, 44px); font-weight: 800; letter-spacing: -0.03em; }
h2 { font-size: 20px; font-weight: 700; }
h3 { font-size: 15.5px; font-weight: 700; }
p { margin: 0 0 .8em; }
.muted { color: var(--ink-2); }
.faint { color: var(--ink-3); font-size: 13px; }
:focus-visible { outline: 2px solid var(--rail); outline-offset: 2px; border-radius: 3px; }

/* ---- top bar */
.top { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--rule); }
.top-in { max-width: 1320px; margin: 0 auto; padding: 10px 20px; display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 800; letter-spacing: -0.02em; color: var(--ink); text-decoration: none; font-size: 16.5px; }
.brand svg { flex: none; }
.nav { display: flex; gap: 2px; flex-wrap: wrap; flex: 1; }
.nav a { color: var(--ink-2); text-decoration: none; padding: 6px 8px; border-radius: var(--radius); font-weight: 500; font-size: 13.5px; white-space: nowrap; }
.nav a:hover { color: var(--ink); background: var(--rule-2); }
.nav a[aria-current="page"] { color: var(--ink); background: var(--panel); box-shadow: inset 0 0 0 1px var(--rule); }
.mode { font-size: 12.5px; padding: 4px 10px; border-radius: 99px; border: 1px solid var(--rule); color: var(--ink-2); white-space: nowrap; }
.mode b { font-weight: 600; }
.mode.live { border-color: color-mix(in srgb, var(--green) 40%, transparent); color: var(--green); }
.mode .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 6px; vertical-align: 1px; }

main { max-width: 1320px; margin: 0 auto; padding: 24px 20px 64px; }
.foot { max-width: 1320px; margin: 0 auto; padding: 18px 20px 36px; color: var(--ink-3); font-size: 12.5px; border-top: 1px solid var(--rule); }

/* ---- panels */
.panel { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-lg); padding: 18px; }
.panel + .panel { margin-top: 16px; }
.grid2 > .panel + .panel, .grid3 > .panel + .panel { margin-top: 0; }
.panel-h { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-h p { margin: 2px 0 0; color: var(--ink-2); font-size: 13.5px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 900px) { .grid2, .grid3 { grid-template-columns: 1fr; } }

/* ---- buttons, inputs */
.btn { font: 600 14px var(--sans); border-radius: var(--radius); padding: 8px 14px; border: 1px solid var(--rule); background: var(--panel);
  color: var(--ink); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--rail); border-color: var(--rail); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.amber { background: var(--amber); border-color: var(--amber); color: #1d1405; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { font: 14.5px var(--sans); color: var(--ink); background: var(--panel); border: 1px solid var(--rule);
  border-radius: var(--radius); padding: 8px 10px; width: 100%; }
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--ink-2); margin: 10px 0 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---- status chips */
.chip { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; padding: 2px 9px; border-radius: 99px;
  background: var(--rule-2); color: var(--ink-2); white-space: nowrap; }
.chip.ok, .chip.pass, .chip.auto_resolved, .chip.approved { background: var(--green-soft); color: var(--green); }
.chip.warn, .chip.needs_review, .chip.human_review { background: var(--amber-soft); color: var(--amber); }
.chip.fail, .chip.error, .chip.blocked, .chip.overridden { background: var(--red-soft); color: var(--red); }
.chip.running, .chip.new { background: var(--rail-soft); color: var(--rail); }
.chip.paused { background: var(--amber-soft); color: var(--amber); }

/* ---- tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 600; color: var(--ink-2); padding: 6px 8px; border-bottom: 1px solid var(--rule); white-space: nowrap; }
.tbl td { padding: 7px 8px; border-bottom: 1px solid var(--rule-2); vertical-align: top; }
.tbl td.num, .tbl th.num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

/* ---- KPI strip */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px; background: var(--rule);
  border: 1px solid var(--rule); border-radius: var(--radius-lg); overflow: hidden; }
.kpi { background: var(--panel); padding: 14px 16px; }
.kpi .v { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .l { font-size: 13px; color: var(--ink-2); }
.kpi .s { font-size: 12px; color: var(--ink-3); }

/* ---- the routing rail (signature element) */
.rail { position: relative; padding-left: 4px; }
.station { position: relative; display: grid; grid-template-columns: 28px 1fr; gap: 10px; padding-bottom: 14px; }
.station::before { content: ""; position: absolute; left: 13px; top: 22px; bottom: -2px; width: 2px; background: var(--rule); }
.station:last-child::before { display: none; }
.station.done::before { background: var(--rail); }
.node { width: 28px; height: 28px; border-radius: 50%; border: 2px solid var(--rule); background: var(--panel); display: grid; place-items: center;
  font: 600 11px var(--mono); color: var(--ink-3); position: relative; z-index: 1; }
.station.done .node { background: var(--rail); border-color: var(--rail); color: #fff; }
.station.ready .node, .station.active .node { border-color: var(--rail); color: var(--rail); }
.station.active .node::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--rail); opacity: .5;
  animation: ping 1.4s ease-out infinite; }
.station.skipped .node { border-style: dashed; }
.station.skipped .st-name { color: var(--ink-3); }
.station.issue .node { background: var(--amber); border-color: var(--amber); color: #1d1405; }
.station.human .node { background: var(--panel); border-color: var(--amber); color: var(--amber); }
@keyframes ping { from { transform: scale(.8); opacity: .6; } to { transform: scale(1.35); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .station.active .node::after { animation: none; opacity: .4; } }
.st-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.st-name { font-weight: 700; font-size: 14.5px; }
.st-kind { font-size: 12px; color: var(--ink-3); }
.st-why { font-size: 13px; color: var(--ink-2); margin-top: 1px; }
.st-meta { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.st-meta code { font-size: 11.5px; }

/* ---- case store */
.board { display: flex; flex-direction: column; gap: 6px; }
.slot { border: 1px solid var(--rule-2); border-radius: var(--radius); padding: 7px 10px; background: var(--panel); }
.slot.fresh { border-color: var(--rail); box-shadow: 0 0 0 2px var(--rail-soft); }
.slot-h { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.slot-k { font: 500 12.5px var(--mono); color: var(--rail); }
.slot-w { font-size: 11.5px; color: var(--ink-3); white-space: nowrap; }
.slot-v { font-size: 13px; color: var(--ink-2); margin-top: 2px; overflow-wrap: anywhere; }

/* ---- misc */
.quote { border-left: 3px solid var(--rule); padding: 8px 12px; color: var(--ink); background: var(--rule-2); border-radius: 0 var(--radius) var(--radius) 0; }
mark.pii { background: var(--rail-soft); color: var(--rail); padding: 0 3px; border-radius: 3px; }
mark.inj { background: var(--red-soft); color: var(--red); padding: 0 3px; border-radius: 3px; }
.reasons { margin: 6px 0 0; padding-left: 18px; }
.reasons li { margin: 2px 0; }
.empty { padding: 28px; text-align: center; color: var(--ink-2); }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--paper);
  padding: 10px 16px; border-radius: var(--radius); font-size: 14px; z-index: 50; max-width: min(92vw, 560px); }
.bar { height: 8px; background: var(--rule-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--rail); }
details summary { cursor: pointer; font-weight: 600; font-size: 13.5px; color: var(--ink-2); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 720px) {
  .top-in { gap: 8px 12px; padding: 8px 16px; }
  .nav { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -4px; }
  .nav a { white-space: nowrap; }
  .mode { white-space: normal; font-size: 12px; margin-left: auto; }
  main { padding: 18px 16px 48px; }
  .panel { padding: 14px; }
}

/* ---- Ask this page */
.ask-fab { position: fixed; right: 20px; bottom: 20px; z-index: 40; display: inline-flex; align-items: center; gap: 8px;
  background: var(--rail); color: #fff; border: 0; border-radius: 99px; padding: 11px 18px 11px 14px; font: 600 14.5px var(--sans);
  cursor: pointer; box-shadow: 0 6px 18px rgba(14, 94, 111, .28); }
.ask-fab:hover { filter: brightness(1.08); }
.ask-fab[hidden] { display: none; }
.ask { position: fixed; right: 20px; bottom: 20px; z-index: 45; width: min(420px, calc(100vw - 32px)); height: min(620px, calc(100vh - 100px));
  background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius-lg); box-shadow: 0 16px 40px rgba(16, 33, 43, .22);
  display: flex; flex-direction: column; overflow: hidden; }
.ask[hidden] { display: none; }
.ask-h { padding: 12px 14px; border-bottom: 1px solid var(--rule); display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.ask-h h2 { font-size: 16px; }
.ask-h p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-2); }
.ask-x { background: none; border: 0; color: var(--ink-2); font-size: 22px; line-height: 1; cursor: pointer; padding: 2px 6px; border-radius: var(--radius); }
.ask-x:hover { background: var(--rule-2); color: var(--ink); }
.ask-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.ask-sugg { display: flex; flex-direction: column; gap: 6px; }
.ask-sugg button { text-align: left; background: var(--rail-soft); color: var(--rail); border: 0; border-radius: var(--radius); padding: 8px 10px;
  font: 500 13.5px var(--sans); cursor: pointer; }
.ask-sugg button:hover { filter: brightness(.97); }
.msg-q { align-self: flex-end; max-width: 85%; background: var(--ink); color: var(--paper); padding: 8px 12px; border-radius: 12px 12px 3px 12px; font-size: 14px; }
.msg-a { align-self: flex-start; max-width: 94%; font-size: 14px; }
.msg-a .txt { white-space: pre-line; }
.msg-a .none { color: var(--ink-2); background: var(--rule-2); padding: 8px 12px; border-radius: var(--radius); }
.msg-a .meta { font-size: 12px; color: var(--ink-3); margin-top: 6px; display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.msg-a .meta .ok { color: var(--green); font-weight: 600; }
.src { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.src button { text-align: left; background: none; border: 0; border-left: 3px solid var(--rail); padding: 3px 8px; color: var(--ink-2);
  font: 13px var(--sans); cursor: pointer; }
.src button:hover { color: var(--ink); background: var(--rule-2); }
.ask-f { border-top: 1px solid var(--rule); padding: 10px; display: flex; gap: 8px; }
.ask-f input { flex: 1; }
.typing { color: var(--ink-3); font-size: 13px; }
.flash { outline: 3px solid var(--amber) !important; outline-offset: 3px; border-radius: 4px; transition: outline-color 1.6s; }
@media (max-width: 560px) {
  .ask { right: 0; bottom: 0; width: 100vw; height: 82vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .ask-fab { right: 14px; bottom: 14px; }
}
