/* Layout: one-screen instrument console. Fleet rail | workspace | analyst, each pane scrolls on its own.
   Colour: blue-graphite ground, periwinkle for interaction, semantic colours only for monitor states. */
:root {
  color-scheme: dark;
  --bg: #0e1219; --sunk: #0a0d13; --panel: #121722; --raised: #182030;
  --line: #222b3b; --line-2: #33415b;
  --fg: #e7ebf3; --fg-2: #a8b1c2; --fg-3: #7f8aa0;
  --accent: #8fa6ff; --accent-ink: #0b1020; --accent-soft: rgba(143, 166, 255, .13);
  --ok: #4fd1b0; --alert: #ffb454; --crit: #ff7a59; --mute: #5d6a85;
  --ok-soft: rgba(79, 209, 176, .12); --alert-soft: rgba(255, 180, 84, .13); --crit-soft: rgba(255, 122, 89, .13);
  --dot: rgba(143, 166, 255, .07);
  --sans: "Geist", "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f9; --sunk: #e9edf4; --panel: #ffffff; --raised: #ffffff;
  --line: #dce1ea; --line-2: #b9c3d4;
  --fg: #101521; --fg-2: #3d475a; --fg-3: #5b667d;
  --accent: #3346c8; --accent-ink: #ffffff; --accent-soft: rgba(51, 70, 200, .09);
  --ok: #0b7f68; --alert: #a35700; --crit: #c23b1c; --mute: #8a94a8;
  --ok-soft: rgba(11, 127, 104, .1); --alert-soft: rgba(163, 87, 0, .1); --crit-soft: rgba(194, 59, 28, .09);
  --dot: rgba(51, 70, 200, .06);
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 13.5px/1.5 var(--sans); -webkit-font-smoothing: antialiased; overflow: hidden; }
h1, h2, h3, p, dl, dd, ul, ol, figure { margin: 0; }
ul, ol { padding: 0; list-style: none; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.mono, code, pre, td.num, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.label { font: 500 10.5px/1.2 var(--mono); letter-spacing: .09em; text-transform: uppercase; color: var(--fg-3); }

/* shell */
.app { height: 100%; display: grid; grid-template: 44px minmax(0, 1fr) / 272px minmax(0, 1fr) 388px; }
.top { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 14px; border-bottom: 1px solid var(--line); background: var(--sunk); min-width: 0; }
.brand { display: flex; align-items: center; gap: 9px; font-weight: 600; letter-spacing: .01em; color: var(--fg); }
.brand svg { color: var(--accent); }
.crumb { color: var(--fg-3); font: 12px var(--mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.crumb b { color: var(--fg-2); font-weight: 500; }
.conn { display: flex; align-items: center; gap: 7px; font: 11.5px var(--mono); color: var(--fg-2); white-space: nowrap; }
.led { width: 7px; height: 7px; border-radius: 50%; background: var(--mute); flex: none; }
.led.ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.led.alert { background: var(--alert); box-shadow: 0 0 0 3px var(--alert-soft); }
.led.crit { background: var(--crit); box-shadow: 0 0 0 3px var(--crit-soft); }
.led.hollow { background: transparent; border: 1.5px solid var(--mute); }
.icon-btn { height: 30px; min-width: 30px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: transparent; border: 1px solid var(--line); border-radius: 5px; cursor: pointer; color: var(--fg-2); font-size: 12px; }
.icon-btn:hover { border-color: var(--line-2); color: var(--fg); }
.only-narrow { display: none; }

/* fleet rail */
.rail { border-right: 1px solid var(--line); background: var(--sunk); overflow-y: auto; padding: 14px 8px 20px; display: flex; flex-direction: column; gap: 18px; }
.rail .label { padding: 0 8px 6px; display: block; }
.rail a { color: inherit; }
.rail a:hover { text-decoration: none; }
.nav-row { display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 5px; color: var(--fg-2); min-height: 32px; }
.nav-row:hover { background: var(--panel); color: var(--fg); }
.nav-row[aria-current="page"] { background: var(--accent-soft); color: var(--fg); }
.nav-row .count { margin-left: auto; font: 11px var(--mono); color: var(--fg-3); }
.dep { border-radius: 6px; }
.dep + .dep { margin-top: 4px; }
.dep-head { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 9px; align-items: center; padding: 8px; border-radius: 6px; }
.dep-head:hover { background: var(--panel); }
.dep-head[aria-current="page"] { background: var(--accent-soft); }
.dep-name { font-weight: 550; color: var(--fg); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep-sub { grid-column: 2; display: flex; align-items: center; gap: 8px; font: 11px var(--mono); color: var(--fg-3); min-width: 0; }
.dep-sub span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dep-kids { margin: 1px 0 4px 15px; padding-left: 9px; border-left: 1px solid var(--line); }
.kid { display: flex; align-items: baseline; gap: 8px; padding: 5px 8px; border-radius: 5px; color: var(--fg-2); font-size: 12.5px; }
.kid:hover { background: var(--panel); color: var(--fg); }
.kid[aria-current="true"] { color: var(--fg); background: var(--panel); }
.kid .val { margin-left: auto; font: 11px var(--mono); color: var(--fg-3); white-space: nowrap; }
.kid .val.ok { color: var(--ok); } .kid .val.alert { color: var(--alert); } .kid .val.crit { color: var(--crit); }
.glyph { height: 12px; width: auto; flex: none; }
.glyph rect { fill: var(--fg-3); }
.glyph rect.gd { fill: var(--crit); }
.glyph.big { height: 26px; }

/* workspace */
.work { overflow-y: auto; min-width: 0; background-image: radial-gradient(var(--dot) 1px, transparent 1px); background-size: 22px 22px; }
.page { max-width: 1040px; margin: 0 auto; padding: 26px 28px 60px; display: flex; flex-direction: column; gap: 22px; }
.page-head { display: flex; flex-direction: column; gap: 8px; }
.page-head h1 { font: 600 22px/1.2 var(--sans); letter-spacing: -.01em; text-wrap: balance; }
.page-head p { color: var(--fg-2); max-width: 68ch; }
.facts { display: flex; flex-wrap: wrap; gap: 6px 18px; font: 11.5px var(--mono); color: var(--fg-3); }
.facts b { color: var(--fg-2); font-weight: 500; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tabs a { padding: 8px 12px; color: var(--fg-3); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; font-weight: 500; }
.tabs a:hover { color: var(--fg); text-decoration: none; }
.tabs a[aria-current="page"] { color: var(--fg); border-bottom-color: var(--accent); }
.block { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; }
.block > header { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 6px 16px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.block > header h2 { font: 600 14px/1.3 var(--sans); }
.block > header .hint { color: var(--fg-3); font-size: 12px; }
.block > .body { padding: 16px; display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); gap: 16px; }
.banner { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; justify-content: space-between; padding: 12px 16px; border: 1px solid var(--crit); background: var(--crit-soft); border-radius: 6px; }
.banner strong { font-weight: 600; }
.banner p { color: var(--fg-2); max-width: 70ch; }
.btn { display: inline-flex; align-items: center; gap: 8px; min-height: 34px; padding: 0 14px; border-radius: 5px; border: 1px solid var(--line-2); background: var(--raised); color: var(--fg); cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px; border-radius: 3px; font: 500 11px/1.5 var(--mono); border: 1px solid var(--line-2); color: var(--fg-2); white-space: nowrap; }
.chip.ok { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.chip.alert { color: var(--alert); border-color: var(--alert); background: var(--alert-soft); }
.chip.crit { color: var(--crit); border-color: var(--crit); background: var(--crit-soft); }
.chip.dash { border-style: dashed; }
.readout { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.readout .v { font: 400 26px/1.1 var(--mono); letter-spacing: -.02em; }
.readout .v small { font-size: 13px; color: var(--fg-3); letter-spacing: 0; }
.readout .d { color: var(--fg-3); font-size: 12px; }
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px 24px; }
.scroll { overflow-x: auto; min-width: 0; }
table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
th { text-align: left; font: 500 10.5px/1.2 var(--mono); letter-spacing: .08em; text-transform: uppercase; color: var(--fg-3); padding: 8px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td .sub { display: block; color: var(--fg-3); font: 11px var(--mono); }
tr.hl td { background: var(--crit-soft); }

/* fleet matrix */
.matrix { display: grid; grid-template-columns: minmax(190px, 1.1fr) repeat(3, minmax(170px, 1fr)); min-width: 720px; }
.matrix > * { padding: 12px 14px; border-bottom: 1px solid var(--line); border-right: 1px solid var(--line); min-width: 0; }
.matrix > *:nth-child(4n) { border-right: 0; }
.matrix > *:nth-last-child(-n+4) { border-bottom: 0; }
.matrix .mh { padding: 9px 14px; }
.mcell { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; color: inherit; }
a.mcell:hover { background: var(--raised); text-decoration: none; }
.mcell .big { font: 400 19px/1.15 var(--mono); letter-spacing: -.01em; }
.mcell .big small { font-size: 11.5px; color: var(--fg-3); }
.mcell .why { color: var(--fg-3); font-size: 12px; }
.mrow-name { display: flex; flex-direction: column; align-items: flex-start; gap: 7px; }
.mrow-name a { color: var(--fg); font-weight: 550; }
.attn li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 12px; align-items: baseline; padding: 11px 16px; border-bottom: 1px solid var(--line); }
.attn li:last-child { border-bottom: 0; }
.attn p { color: var(--fg-2); }
.attn .who { font: 11px var(--mono); color: var(--fg-3); grid-column: 2; }

/* instruments */
svg text { font-family: var(--mono); fill: var(--fg-3); }
.lm .rule { stroke: var(--line-2); } .lm .tick { stroke: var(--line-2); }
.lm .lane { fill: var(--fg-2); font-size: 10px; }
.lm .site { fill: var(--accent); } .lm .cs { fill: var(--ok); } .lm .ps { fill: none; stroke: var(--ok); stroke-width: 1.5; }
.lm .hd { fill: var(--alert); }
.hist .axis { stroke: var(--line-2); } .hist .c { fill: var(--fg-3); fill-opacity: .28; stroke: var(--fg-3); stroke-width: 1; }
.hist .f { fill: var(--alert); fill-opacity: .3; stroke: var(--alert); stroke-width: 1.2; }
.hist .zone { fill: var(--alert); fill-opacity: .06; } .hist .thr { stroke: var(--fg); stroke-width: 1; stroke-dasharray: 3 3; }
.hist .t { fill: var(--fg-2); font-size: 11px; }
.gate .zone { fill: var(--ok); fill-opacity: .09; stroke: var(--ok); stroke-dasharray: 3 3; stroke-opacity: .6; }
.gate .axis { stroke: var(--line-2); } .gate .pass { fill: var(--ok); } .gate .fail { fill: var(--panel); stroke: var(--fg-3); stroke-width: 1.5; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--fg-2); }
.legend i { display: inline-block; width: 9px; height: 9px; margin-right: 6px; border-radius: 2px; vertical-align: -1px; }
.band { display: flex; height: 12px; border-radius: 2px; overflow: hidden; gap: 1px; }
.keys { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 6px 18px; font-size: 12.5px; color: var(--fg-2); }
.keys b { float: right; font: 500 12.5px var(--mono); color: var(--fg); }
.strip { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 3px; }
.strip button { height: 26px; border-radius: 2px; border: 1px solid transparent; cursor: pointer; background: var(--ok-soft); border-color: var(--ok); padding: 0; }
.strip button.alert { background: var(--alert); border-color: var(--alert); }
.strip button.abstain, .strip button.pending { background: transparent; border: 1px dashed var(--mute); }
.strip button[aria-pressed="true"] { outline: 2px solid var(--fg); outline-offset: 1px; }
.lane-t .axis { stroke: var(--line-2); } .lane-t .seg { stroke: var(--accent); stroke-width: 2; } .lane-t .ev { fill: var(--accent); }
.lane-t .t { fill: var(--fg-2); font-size: 10px; }
.diff { display: grid; grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr); gap: 0; font: 12px var(--mono); }
.diff > div { padding: 7px 12px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.diff .k { color: var(--fg-3); } .diff .chg { color: var(--crit); background: var(--crit-soft); }
pre { margin: 0; padding: 12px; background: var(--sunk); border: 1px solid var(--line); border-radius: 5px; font-size: 11.5px; overflow: auto; max-height: 340px; }
details > summary { cursor: pointer; color: var(--fg-2); padding: 4px 0; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--fg-3); min-width: 0; }
.field input, .field select, .field textarea { background: var(--sunk); border: 1px solid var(--line-2); border-radius: 5px; padding: 7px 9px; color: var(--fg); min-width: 0; max-width: 100%; }
.field textarea { resize: vertical; }
.stages li { padding: 10px 0; border-bottom: 1px solid var(--line); }
.stages li:last-child { border-bottom: 0; }
.stages h3 { font: 600 13px var(--sans); } .stages p { color: var(--fg-2); }
.empty { color: var(--fg-3); padding: 18px 16px; }

/* analyst */
.analyst { border-left: 1px solid var(--line); background: var(--sunk); display: grid; grid-template: auto minmax(0, 1fr) auto / minmax(0, 1fr); min-width: 0; min-height: 0; }
.an-head { min-width: 0; padding: 11px 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 7px; }
.an-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.an-title h2 { font: 600 13.5px var(--sans); }
.an-ctx { font: 11px var(--mono); color: var(--fg-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.an-ctx b { color: var(--fg-2); font-weight: 500; }
.an-log { overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 16px; }
.msg { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.msg.user { align-self: flex-end; max-width: 88%; background: var(--raised); border: 1px solid var(--line); border-radius: 8px 8px 2px 8px; padding: 8px 11px; }
.msg.bot p { color: var(--fg); } .msg.bot p + p { margin-top: 0; }
.msg.bot ol { list-style: decimal; padding-left: 18px; display: flex; flex-direction: column; gap: 5px; }
.msg.bot ul.dots { list-style: disc; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; }
.msg.bot b, .msg.bot strong { font-weight: 600; }
.msg.bot .n { font-family: var(--mono); font-variant-numeric: tabular-nums; color: var(--fg); background: var(--accent-soft); padding: 0 4px; border-radius: 2px; }
.msg.bot mark { background: var(--alert-soft); color: var(--alert); border-bottom: 1px dashed var(--alert); padding: 0 2px; }
.msg .src { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; font: 11px var(--mono); color: var(--fg-3); }
.msg .src a { border: 1px solid var(--line-2); border-radius: 3px; padding: 1px 6px; color: var(--fg-2); }
.msg .src a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }
.mini { font-size: 12px; } .mini td, .mini th { padding: 5px 8px; }
.an-empty { color: var(--fg-2); display: flex; flex-direction: column; gap: 10px; }
.sugg { display: flex; flex-wrap: wrap; gap: 6px; }
.sugg button { text-align: left; background: transparent; border: 1px solid var(--line-2); border-radius: 5px; padding: 6px 10px; color: var(--fg-2); cursor: pointer; font-size: 12.5px; min-height: 32px; }
.sugg button:hover { border-color: var(--accent); color: var(--fg); }
.an-form { border-top: 1px solid var(--line); padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.an-box { display: flex; gap: 8px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line-2); border-radius: 7px; padding: 6px 6px 6px 10px; }
.an-box:focus-within { border-color: var(--accent); }
.an-box textarea { flex: 1; min-width: 0; background: transparent; border: 0; outline: 0; resize: none; padding: 5px 0; max-height: 110px; }
.an-box button { height: 30px; width: 34px; border-radius: 5px; border: 0; background: var(--accent); color: var(--accent-ink); cursor: pointer; display: grid; place-items: center; }
.an-box button:disabled { opacity: .4; cursor: not-allowed; }
.an-note { font: 10.5px/1.4 var(--mono); color: var(--fg-3); }

@media (max-width: 1240px) {
  .app { grid-template-columns: 252px minmax(0, 1fr); }
  .analyst { position: fixed; inset: 44px 0 0 auto; width: min(400px, 100%); z-index: 20; transform: translateX(100%); transition: transform .18s ease; box-shadow: -18px 0 40px rgba(0, 0, 0, .35); }
  .app.show-analyst .analyst { transform: none; }
  .only-narrow.an { display: inline-flex; }
}
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail { position: fixed; inset: 44px auto 0 0; width: min(300px, 88%); z-index: 20; transform: translateX(-100%); transition: transform .18s ease; box-shadow: 18px 0 40px rgba(0, 0, 0, .35); }
  .app.show-rail .rail { transform: none; }
  .only-narrow.fl { display: inline-flex; }
  .page { padding: 18px 16px 48px; }
  .conn span, .crumb { display: none; }
  .top { justify-content: space-between; }
}
@media (prefers-reduced-motion: reduce) { .analyst, .rail { transition: none; } }

/* sign-in and analyst controls */
.login { height: 100%; display: grid; place-items: center; padding: 24px 16px; background-image: radial-gradient(var(--dot) 1px, transparent 1px); background-size: 22px 22px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 14px; padding: 28px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
.login-card h1 { font: 600 18px/1.3 var(--sans); }
.login-card .btn { justify-content: center; min-height: 40px; }
#login-msg { color: var(--crit); min-height: 1.4em; }
.an-pick { display: flex; gap: 6px; min-width: 0; }
.an-pick select { flex: 1 1 0; min-width: 0; background: var(--panel); border: 1px solid var(--line-2); border-radius: 5px; padding: 5px 7px; color: var(--fg-2); font-size: 12px; }
form.block label > input[type=checkbox] { accent-color: var(--accent); }
