/* NerveStack demo: compact, information-dense layout. Tokens first; every page reads them. */
:root {
  --bg: #0b0d12; --panel: #12161d; --panel2: #181d26; --line: #232a35; --line2: #2f3846;
  --text: #dbe1ea; --muted: #8c96a6; --faint: #5f6979;
  --accent: #4c8dff; --accent-ink: #ffffff; --accent2: #a78bfa; --brand: #2ee6a6; --brand2: #8b93ff;
  --crit: #f0505f; --warn: #e5a53b; --ok: #34c37a; --info: #4cb6e8; --maint: #8c96a6;
  --crit-bg: rgba(240, 80, 95, .13); --warn-bg: rgba(229, 165, 59, .13); --ok-bg: rgba(52, 195, 122, .12); --info-bg: rgba(76, 182, 232, .12);
  --shadow: none;
  /* chart series and heatmap ramps (docs/ui-ux-spec.md section 3) */
  --c1: #4c8dff; --c2: #a78bfa; --c3: #4cb6e8; --c4: #e5a53b; --c5: #f0505f; --c6: #c084fc; --c7: #f472b6; --c8: #94a3b8;
  --heat2: #a78bfa; --heat3: #e5a53b; --heat4: #f0505f; --heat-good: #34c37a;
  --crit-soft: #ff8a96; --band-crit: rgba(255, 93, 110, .16); --band-warn: rgba(255, 181, 71, .10);
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  --mono: "Cascadia Mono", "Cascadia Code", Consolas, "SF Mono", monospace;
  color-scheme: dark;
}
:root[data-theme="slate"] {
  --bg: #161b24; --panel: #1d2330; --panel2: #242b3a; --line: #2e3646; --line2: #3a4457;
  --text: #e3e8ef; --muted: #9aa5b6; --faint: #6f7a8c;
}
:root[data-theme="graphite"] {
  --bg: #1b1c1f; --panel: #232428; --panel2: #2a2c31; --line: #33363c; --line2: #41454c;
  --text: #e7e7e9; --muted: #a2a5ac; --faint: #767a83;
  --accent: #5b95ff;
}
:root[data-theme="dimmed"] {
  --bg: #22272e; --panel: #2a3039; --panel2: #313843; --line: #3a424e; --line2: #4a5360;
  --text: #dbe2ea; --muted: #a0aab8; --faint: #7a8594;
  --accent: #5c98ff; --crit: #ff6573; --warn: #eab44f; --ok: #43d08a; --info: #5cc2f0;
}
:root[data-theme="storm"] {
  --bg: #2b313b; --panel: #333a46; --panel2: #3b4351; --line: #475163; --line2: #566176;
  --text: #eef1f5; --muted: #b3bcc9; --faint: #8e98a8;
  --accent: #6aa1ff; --crit: #ff6b78; --warn: #f0b955; --ok: #4bd690; --info: #66c8f2;
}
:root[data-theme="light"] {
  /* soft paper, not pure white; text near-black, secondary text dark enough to read at 11-12 px (WCAG AA) */
  --bg: #eef1f5; --panel: #fbfcfd; --panel2: #f3f5f8; --line: #e0e5ec; --line2: #cdd5df;
  --text: #1f2733; --muted: #465063; --faint: #636d7f;
  --accent: #3a68c4; --accent-ink: #ffffff; --accent2: #7660c0; --brand: #1f8f68; --brand2: #5b63c8;
  --crit: #bd4450; --warn: #8a5f14; --ok: #287650; --info: #2c73a3; --maint: #6b7685;
  --crit-bg: rgba(189, 68, 80, .08); --warn-bg: rgba(154, 106, 24, .09); --ok-bg: rgba(44, 125, 85, .08); --info-bg: rgba(44, 115, 163, .08);
  /* calm, mid-saturation series colours that stay distinct */
  --c1: #4a78c2; --c2: #8a72c4; --c3: #3b97a6; --c4: #c4914a; --c5: #c26a74; --c6: #5e9a70; --c7: #ad7aa3; --c8: #8c97a6;
  /* soothing heat ramp: mist blue -> sand -> soft coral */
  --heat2: #a9c6e0; --heat3: #e6c58f; --heat4: #d99a93; --heat-good: #a7d3b6;
  --crit-soft: #d68d95; --band-crit: rgba(189, 68, 80, .08); --band-warn: rgba(196, 145, 74, .10);
  --shadow: none;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 13px/1.4 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; font-variant-numeric: tabular-nums; }
/* light: normal smoothing keeps small text from going thin and grey */
:root[data-theme="light"] body { -webkit-font-smoothing: auto; line-height: 1.45; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--muted); } .faint { color: var(--faint); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- shell ---------- */
.ns-app { display: grid; grid-template-rows: 44px 36px 1fr; height: 100vh; }
.ns-top { display: flex; align-items: center; gap: 12px; padding: 0 12px; border-bottom: 1px solid var(--line); background: var(--panel); }
.ns-brand { display: flex; align-items: center; gap: 8px; font-weight: 650; letter-spacing: .2px; font-size: 14.5px; }
.ns-brand svg { width: 22px; height: 22px; }
.ns-org { color: var(--muted); font-size: 12.5px; padding-left: 12px; border-left: 1px solid var(--line2); }
.ns-search { flex: 1; max-width: 460px; margin-left: 8px; display: flex; align-items: center; gap: 8px; height: 28px; padding: 0 10px; border: 1px solid var(--line2); border-radius: 5px; background: var(--panel2); color: var(--faint); cursor: text; font-size: 12.5px; }
.ns-search kbd, .kbd { font: 10.5px var(--mono); padding: 0 5px; border: 1px solid var(--line2); border-radius: 3px; color: var(--muted); margin-left: auto; }
.ns-top-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.seg { display: inline-flex; background: var(--panel2); border: 1px solid var(--line2); border-radius: 5px; padding: 1px; }
.seg button { border: 0; background: none; padding: 2px 9px; border-radius: 4px; cursor: pointer; color: var(--muted); font-size: 12px; line-height: 20px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.live { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.live i { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 0 var(--ok); animation: pulse 2s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(52,195,122,.6); } 70% { box-shadow: 0 0 0 6px rgba(52,195,122,0); } 100% { box-shadow: 0 0 0 0 rgba(52,195,122,0); } }
.icon-btn { width: 28px; height: 28px; border-radius: 5px; border: 1px solid var(--line2); background: var(--panel2); cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.icon-btn svg { width: 14px; height: 14px; }
.theme-menu { position: fixed; z-index: 60; min-width: 220px; padding: 4px; border-radius: 7px; border: 1px solid var(--line2); background: var(--panel); box-shadow: 0 10px 30px rgba(0,0,0,.35); display: none; }
.theme-menu.on { display: block; }
.theme-menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 6px 8px; border: 0; border-radius: 5px; background: none; color: var(--text); font: 12.5px var(--font); text-align: left; cursor: pointer; }
.theme-menu button:hover { background: var(--panel2); }
.theme-menu button.on { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.theme-menu .sw { display: flex; width: 34px; height: 18px; border-radius: 4px; overflow: hidden; border: 1px solid var(--line2); flex: none; }
.theme-menu .sw i { flex: 1; }
.theme-menu small { display: block; color: var(--faint); font-size: 11px; }
.icon-btn:hover { color: var(--text); }

.ns-tabs { display: flex; align-items: stretch; gap: 0; padding: 0 6px; border-bottom: 1px solid var(--line); background: var(--panel); overflow-x: auto; scrollbar-width: none; }
.ns-tab { display: flex; align-items: center; gap: 6px; padding: 0 11px; color: var(--muted); font-size: 12.5px; border-bottom: 2px solid transparent; white-space: nowrap; }
.ns-tab:hover { color: var(--text); background: var(--panel2); }
.ns-tab.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.ns-tab .cnt { font-size: 10.5px; font-weight: 700; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; display: inline-grid; place-items: center; }
.cnt.crit { background: var(--crit-bg); color: var(--crit); } .cnt.warn { background: var(--warn-bg); color: var(--warn); }

.ns-body { display: grid; grid-template-columns: 1fr 272px; min-height: 0; }
.ns-body.rail-off { grid-template-columns: 1fr 0; }
.ns-main { overflow: auto; padding: 12px 14px 28px; min-width: 0; }
.ns-rail { border-left: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 10px 10px 24px; }
.rail-off .ns-rail { display: none; }
.rail-h { display: flex; align-items: center; justify-content: space-between; font-size: 10.5px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--faint); margin: 12px 2px 6px; }
.rail-h:first-child { margin-top: 0; }
.sig { display: block; padding: 7px 9px; border-radius: 4px; border: 1px solid var(--line); background: var(--panel2); margin-bottom: 6px; }
.sig:hover { border-color: var(--line2); }
.sig.crit { border-left: 3px solid var(--crit); } .sig.warn { border-left: 3px solid var(--warn); } .sig.info { border-left: 3px solid var(--info); }
.sig .t { font-weight: 600; font-size: 12px; line-height: 1.3; }
.sig .m { display: flex; gap: 6px; align-items: center; margin-top: 3px; font-size: 11px; color: var(--muted); }
.chg { display: flex; gap: 8px; padding: 4px 2px; font-size: 12px; border-bottom: 1px solid var(--line); }
.chg .when { color: var(--faint); min-width: 50px; }

/* ---------- page ---------- */
.ph { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 10px; min-height: 30px; }
.ph h1 { margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.1px; }
.ph .sub { color: var(--muted); font-size: 12px; margin-top: 1px; }
.crumb { font-size: 11.5px; color: var(--muted); margin-bottom: 3px; }
.crumb a:hover { color: var(--accent); }
.grid { display: grid; gap: 8px; grid-template-columns: repeat(12, 1fr); margin-bottom: 8px; }
.s2 { grid-column: span 2; } .s3 { grid-column: span 3; } .s4 { grid-column: span 4; } .s5 { grid-column: span 5; } .s6 { grid-column: span 6; } .s7 { grid-column: span 7; } .s8 { grid-column: span 8; } .s12 { grid-column: span 12; }
@media (max-width: 1100px) { .s2 { grid-column: span 4; } .s3 { grid-column: span 6; } .s4, .s5, .s7, .s8, .s6 { grid-column: span 12; } }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; min-width: 0; }
.card > .hd { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px 0; min-height: 26px; }
.card > .hd h3 { margin: 0; font-size: 12px; font-weight: 650; color: var(--text); }
.card > .hd .x { font-size: 11px; color: var(--muted); }
.card > .bd { padding: 6px 10px 8px; }
.card.flush > .bd { padding: 4px 0 2px; }
.chart { height: 170px; } .chart.tall { height: 230px; } .chart.short { height: 118px; } .chart.xl { height: 330px; }

.kpi { padding: 7px 10px 8px; }
.kpi .l { font-size: 10.5px; color: var(--muted); display: flex; align-items: center; gap: 5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.kpi .v { font-size: 20px; font-weight: 650; letter-spacing: -.3px; margin-top: 1px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 12px; color: var(--muted); font-weight: 500; margin-left: 3px; }
.kpi .d { font-size: 11px; margin-top: 1px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi.crit .v { color: var(--crit); } .kpi.warn .v { color: var(--warn); } .kpi.ok .v { color: var(--ok); }

.hero { display: flex; gap: 14px; align-items: center; padding: 7px 12px; border-radius: 6px; border: 1px solid var(--line); border-left: 3px solid var(--crit); background: var(--panel); margin-bottom: 8px; }
.hero.okay { border-left-color: var(--ok); }
.hero .big { font-size: 13px; font-weight: 650; }
.hero .score { margin-left: auto; text-align: right; display: flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.hero .score b { font-size: 20px; letter-spacing: -.5px; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex: none; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.crit { background: var(--crit); } .dot.maint { background: var(--maint); } .dot.info { background: var(--info); }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 10.5px; font-weight: 650; padding: 1px 6px; border-radius: 3px; white-space: nowrap; line-height: 16px; }
.pill.crit { background: var(--crit-bg); color: var(--crit); } .pill.warn { background: var(--warn-bg); color: var(--warn); } .pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.info { background: var(--info-bg); color: var(--info); } .pill.maint, .pill.mute { background: var(--panel2); color: var(--muted); border: 1px solid var(--line2); }
.sev { font: 700 10.5px var(--mono); padding: 1px 5px; border-radius: 3px; }
.sev.P1 { background: var(--crit); color: #fff; } .sev.P2 { background: var(--crit-bg); color: var(--crit); } .sev.P3 { background: var(--warn-bg); color: var(--warn); } .sev.P4 { background: var(--panel2); color: var(--muted); border: 1px solid var(--line2); }

/* sites strip */
.sites { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 6px; margin-bottom: 8px; }
.site { padding: 6px 9px 6px 11px; border-radius: 5px; border: 1px solid var(--line); background: var(--panel); position: relative; overflow: hidden; }
.site:hover { border-color: var(--line2); }
.site::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--ok); }
.site.warn::before { background: var(--warn); } .site.crit::before { background: var(--crit); }
.site .n { font-weight: 600; font-size: 12px; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.site .k { font-size: 9.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); }
.site .r { display: flex; justify-content: space-between; align-items: center; font-size: 11px; color: var(--muted); margin-top: 2px; }

/* tables */
.tbl-tools { display: flex; gap: 6px; align-items: center; padding: 0 10px 6px; flex-wrap: wrap; }
.tbl-tools input, .tbl-tools select, .inp { height: 26px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); border-radius: 4px; padding: 0 8px; font: inherit; font-size: 12px; }
.tbl-tools input { width: 220px; }
.tbl-wrap { overflow: auto; max-height: 520px; }
table.t { width: 100%; border-collapse: collapse; font-size: 12px; }
table.t th { position: sticky; top: 0; background: var(--panel); text-align: left; font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 5px 10px; border-bottom: 1px solid var(--line2); cursor: pointer; white-space: nowrap; user-select: none; z-index: 1; }
table.t th.r, table.t td.r { text-align: right; white-space: nowrap; }
table.t th .ar { opacity: .6; font-size: 9px; }
table.t td { padding: 4px 10px; height: 28px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr[data-href] { cursor: pointer; }
table.t tbody tr:hover { background: var(--panel2); }
.tbl-foot { padding: 6px 10px; font-size: 11px; color: var(--faint); }
.bar { height: 5px; border-radius: 3px; background: var(--panel2); overflow: hidden; min-width: 60px; }
.bar > i { display: block; height: 100%; border-radius: 3px; background: var(--accent); }
.bar.warn > i { background: var(--warn); } .bar.crit > i { background: var(--crit); }
.barcell { display: flex; align-items: center; gap: 6px; }
.barcell .bar { flex: 1; }

/* incident detail */
.ai { border-left: 3px solid var(--accent2); }
.ai-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent2); }
.ai p { font-size: 13px; line-height: 1.5; margin: 4px 0 0; }
.chain { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.node-chip { padding: 4px 9px; border-radius: 4px; border: 1px solid var(--line2); background: var(--panel2); font-size: 12px; }
.node-chip.root { border-color: var(--crit); background: var(--crit-bg); }
.node-chip .k { font-size: 9.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--faint); display: block; }
.arrow { color: var(--faint); font-size: 14px; }
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: grid; grid-template-columns: 54px 12px 1fr; gap: 6px; padding: 3px 0; font-size: 12px; }
.tl .tm { color: var(--faint); font-family: var(--mono); font-size: 11px; padding-top: 1px; }
.tl .b { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; background: var(--line2); }
.tl .b.detect, .tl .b.signal { background: var(--warn); } .tl .b.rca { background: var(--accent2); } .tl .b.resolve { background: var(--ok); } .tl .b.change { background: var(--info); } .tl .b.action, .tl .b.notify { background: var(--muted); }
ol.acts { margin: 2px 0 0; padding-left: 18px; font-size: 12px; } ol.acts li { margin: 3px 0; }
.conf { display: flex; align-items: center; gap: 8px; }
.conf .bar { width: 100px; }

/* logs + traces */
.log { font-family: var(--mono); font-size: 11.5px; display: grid; grid-template-columns: 140px 46px 120px 1fr; gap: 8px; padding: 2px 10px; border-bottom: 1px solid var(--line); line-height: 18px; }
.log:hover { background: var(--panel2); }
.log .lv-error { color: var(--crit); font-weight: 700; } .log .lv-warn { color: var(--warn); font-weight: 700; } .log .lv-info { color: var(--info); }
.wf { padding: 2px 10px 8px; }
.wf-row { display: grid; grid-template-columns: 200px 1fr 70px; gap: 8px; align-items: center; font-size: 11.5px; padding: 1px 0; }
.wf-track { position: relative; height: 12px; background: var(--panel2); border-radius: 2px; }
.wf-track i { position: absolute; top: 2px; bottom: 2px; border-radius: 2px; background: var(--accent2); }
.wf-track i.db { background: var(--warn); } .wf-track i.ext { background: var(--info); } .wf-track i.root { background: var(--accent); }

.kv { display: grid; grid-template-columns: 120px 1fr; gap: 3px 10px; font-size: 12px; margin: 0; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; }
.tabs2 { display: flex; gap: 6px; margin-bottom: 8px; }
.empty { padding: 20px; text-align: center; color: var(--muted); }
.legend-row { display: flex; gap: 12px; flex-wrap: wrap; font-size: 11px; color: var(--muted); }
.legend-row span { display: inline-flex; align-items: center; gap: 5px; }

/* command palette */
.pal-bg { position: fixed; inset: 0; background: rgba(5,8,12,.55); display: none; z-index: 50; }
.pal-bg.on { display: block; }
.pal { position: absolute; left: 50%; top: 10vh; transform: translateX(-50%); width: min(600px, 92vw); background: var(--panel); border: 1px solid var(--line2); border-radius: 6px; box-shadow: 0 20px 60px rgba(0,0,0,.4); overflow: hidden; }
.pal input { width: 100%; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--text); font: inherit; font-size: 14px; padding: 11px 14px; outline: none; }
.pal ul { list-style: none; margin: 0; padding: 4px; max-height: 50vh; overflow: auto; }
.pal li { display: flex; gap: 8px; align-items: center; padding: 6px 10px; border-radius: 4px; cursor: pointer; font-size: 12.5px; }
.pal li .k { margin-left: auto; font-size: 11px; color: var(--faint); }
.pal li.sel { background: var(--panel2); outline: 1px solid var(--line2); }
.foot-note { margin-top: 14px; font-size: 11px; color: var(--faint); text-align: center; }

/* section navigation and in-page tabs */
.subnavs { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: -2px 0 10px; align-items: center; }
.subgrp { display: flex; align-items: center; gap: 6px; }
.sublbl { min-width: 92px; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--faint); }
.subnavs .subnav { margin: 0; }
.subnav { display: flex; gap: 0; flex-wrap: wrap; margin: -2px 0 10px; border: 1px solid var(--line); border-radius: 5px; background: var(--panel); width: fit-content; overflow: hidden; }
.subnav a { padding: 4px 12px; color: var(--muted); font-size: 12px; border-right: 1px solid var(--line); }
.subnav a:last-child { border-right: 0; }
.subnav a:hover { color: var(--text); background: var(--panel2); }
.subnav a.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.ptabs { display: flex; gap: 0; margin: 0 0 10px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.ptabs a { padding: 5px 11px; color: var(--muted); font-size: 12.5px; border-bottom: 2px solid transparent; white-space: nowrap; display: inline-flex; gap: 5px; align-items: center; }
.ptabs a:hover { color: var(--text); }
.ptabs a.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.ptabs .cnt { font-size: 10.5px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; display: inline-grid; place-items: center; background: var(--panel2); }
.seg a.segbtn, a.segbtn, span.segbtn { display: inline-block; padding: 2px 9px; border-radius: 4px; color: var(--muted); font-size: 12px; line-height: 20px; cursor: pointer; white-space: nowrap; }
.seg a.segbtn.on, a.segbtn.on, span.segbtn.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
table.t tr.grp td { background: var(--panel2); font-size: 12px; }
table.t.mx td, table.t.mx th { padding: 3px 5px; }

/* WAN Observatory stage (constellation and geography) */
.wo-bar { display: flex; gap: 12px; align-items: center; font-size: 12.5px; }
.wo-main { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
.wo-main.with-drawer { grid-template-columns: minmax(0, 1fr) 420px; }
@media (max-width: 1400px) { .wo-main.with-drawer { grid-template-columns: 1fr; } }
.wo-stage { position: relative; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; height: min(70vh, 760px); min-height: 460px;
  background: radial-gradient(ellipse at 50% 45%, color-mix(in srgb, var(--accent) 7%, var(--panel)) 0%, var(--panel) 62%); }
.wo-stage svg, .wo-stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.wo-stage canvas { pointer-events: none; }
.wo-stage svg text { font-family: var(--mono); }
.wo-legend { position: absolute; left: 10px; bottom: 10px; display: flex; flex-wrap: wrap; gap: 5px 13px; font-size: 11px; color: var(--muted);
  background: color-mix(in srgb, var(--bg) 78%, transparent); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; max-width: calc(100% - 20px); backdrop-filter: blur(6px); }
.wo-legend i { display: inline-block; width: 18px; border-top: 3px solid; vertical-align: middle; margin-right: 5px; }
.wo-corner { position: absolute; right: 10px; top: 10px; display: flex; gap: 6px; }
.wo-chip { display: inline-flex; align-items: center; font: 500 10.5px var(--mono); padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line2); color: var(--muted); white-space: nowrap; }
.wo-chip.warn { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 45%, transparent); }
.wo-node { cursor: pointer; outline: none; }
.wo-node circle, .wo-node path, .wo-spoke { transition: opacity .25s, stroke-width .6s, stroke .4s; }
.wo-node:focus-visible .wo-halo, .wo-node:hover .wo-halo { opacity: .55; }
.wo-dim { opacity: .12; }
@keyframes wo-pulse { 0% { transform: scale(1); opacity: .75; } 100% { transform: scale(2.3); opacity: 0; } }
.wo-alarm { fill: none; stroke-width: 2; transform-box: fill-box; transform-origin: center; animation: wo-pulse 1.8s ease-out infinite; }
.wo-drawer { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; display: flex; flex-direction: column; max-height: min(86vh, 980px); overflow: hidden; animation: wo-slide .3s ease; }
@keyframes wo-slide { from { opacity: 0; transform: translateX(12px); } to { opacity: 1; transform: none; } }
.wo-dh { padding: 13px 15px 10px; border-bottom: 1px solid var(--line); }
.wo-dh h3 { margin: 0; font-size: 17px; font-weight: 700; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.wo-dh .meta { font: 11.5px var(--mono); color: var(--faint); margin-top: 3px; }
.wo-db { overflow: auto; padding: 12px 15px 16px; display: flex; flex-direction: column; gap: 12px; }
.wo-card { border: 1px solid var(--line2); border-radius: 10px; padding: 10px 12px; background: var(--panel2); }
.wo-card .hd { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.wo-card .nm { font-weight: 700; font-size: 14px; }
.wo-kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 3px 10px; font-size: 12px; margin-top: 7px; }
.wo-kv .k { color: var(--faint); } .wo-kv .v { font-family: var(--mono); overflow-wrap: anywhere; }
.wo-sub { font-size: 10px; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); margin: 11px 0 5px; font-weight: 600; }
@media (prefers-reduced-motion: reduce) { .wo-alarm, .wo-drawer { animation: none; } }

/* ===== Stage 1 foundation (docs/ui-ux-spec.md §2–4) ===== */
/* verdict line: the page's one sentence */
.verdict { display: flex; align-items: center; gap: 12px; padding: 10px 2px 12px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.verdict .vd-ico { flex: none; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font: 700 12px var(--mono); color: var(--bg); background: var(--muted); }
.verdict.ok .vd-ico { background: var(--ok); } .verdict.warn .vd-ico { background: var(--warn); } .verdict.crit .vd-ico { background: var(--crit); }
.verdict.crit .vd-ico { box-shadow: 0 0 0 0 color-mix(in srgb, var(--crit) 55%, transparent); animation: vd-pulse 1.2s ease-out 1; }
.verdict .vd-t { font-size: 16px; line-height: 1.35; font-weight: 500; color: var(--text); }
.verdict .vd-t b { font-weight: 650; }
.verdict .vd-t .m { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }
.verdict .vd-a { margin-left: auto; display: flex; gap: 6px; flex: none; }
.vd-btn { padding: 5px 11px; border-radius: 5px; border: 1px solid var(--line2); color: var(--text); font-size: 12px; font-weight: 600; white-space: nowrap; }
.vd-btn:hover { background: var(--panel2); }
.vd-btn.pri { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
@keyframes vd-pulse { to { box-shadow: 0 0 0 10px transparent; } }

/* vital strip: one band, dividers, no boxes */
.vitals { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin: 4px 0 14px; border-bottom: 1px solid var(--line); }
.vt { position: relative; padding: 8px 14px 10px; border-left: 1px solid var(--line); min-width: 0; }
.vt:first-child { border-left: 0; padding-left: 2px; }
.vt[data-href] { cursor: pointer; } .vt[data-href]:hover { background: color-mix(in srgb, var(--panel2) 60%, transparent); }
.vt-l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.vt-v { display: flex; align-items: baseline; gap: 3px; margin-top: 2px; }
.vt-v b { font: 600 22px/1.15 var(--mono); letter-spacing: -.5px; color: var(--text); }
.vt-v small { font: 12px var(--mono); color: var(--faint); }
.vt.ok .vt-v b { color: var(--ok); } .vt.warn .vt-v b { color: var(--warn); } .vt.crit .vt-v b { color: var(--crit); }
.vt-d { font-size: 11.5px; color: var(--faint); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vt .spark { position: absolute; right: 12px; top: 26px; width: 84px; height: 22px; }
.spark .sp-l { fill: none; stroke: var(--accent); stroke-width: 1.4; stroke-linejoin: round; stroke-dasharray: 1; stroke-dashoffset: 0; animation: sp-draw .9s cubic-bezier(.33,1,.68,1) both; vector-effect: non-scaling-stroke; }
.spark .sp-a { fill: color-mix(in srgb, var(--accent) 12%, transparent); stroke: none; }
.spark.ok .sp-l { stroke: var(--ok); } .spark.ok .sp-a { fill: color-mix(in srgb, var(--ok) 12%, transparent); }
.spark.warn .sp-l { stroke: var(--warn); } .spark.warn .sp-a { fill: color-mix(in srgb, var(--warn) 12%, transparent); }
.spark.crit .sp-l { stroke: var(--crit); } .spark.crit .sp-a { fill: color-mix(in srgb, var(--crit) 12%, transparent); }
@keyframes sp-draw { from { stroke-dashoffset: 1; } }

/* main visual + notes column; sections divided by rules, not boxes */
.anat { display: grid; grid-template-columns: minmax(0, 8fr) minmax(0, 4fr); gap: 0; margin-bottom: 14px; border-bottom: 1px solid var(--line); }
.anat > .main { padding: 0 16px 14px 2px; min-width: 0; }
.anat > .notes { padding: 0 2px 14px 16px; border-left: 1px solid var(--line); min-width: 0; }
.sec-h { display: flex; align-items: baseline; gap: 8px; margin: 4px 0 8px; }
.sec-h h3 { margin: 0; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.sec-h .x { margin-left: auto; font-size: 11.5px; color: var(--faint); }
.sec-h a.x { color: var(--accent); }
.notes .sec-h + .nlist { margin-bottom: 14px; }
.nlist { display: flex; flex-direction: column; }
.nlist .ni { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 8px; padding: 5px 0; border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent); font-size: 12.5px; line-height: 1.35; }
.nlist .ni:first-child { border-top: 0; }
.nlist .ni .w { color: var(--faint); font: 11px var(--mono); padding-top: 1px; }
.nlist .ni .tag { font-size: 10.5px; color: var(--accent2); margin-left: 4px; }
.chart.tall { height: 270px; }
.legend-inline { display: flex; gap: 14px; font-size: 11.5px; color: var(--muted); margin: -2px 0 4px; }
.legend-inline i { display: inline-block; width: 10px; height: 2px; border-radius: 1px; vertical-align: middle; margin-right: 5px; }
.legend-inline i.ev { width: 0; height: 10px; border-left: 1px dashed var(--faint); }

/* detail rows: compact rows with inline sparklines */
.rows2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 28px; margin-bottom: 14px; }
.srow { display: grid; grid-template-columns: 10px minmax(0, 1.6fr) minmax(0, 1fr) 96px 54px; align-items: center; gap: 10px; padding: 5px 2px; border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent); font-size: 12.5px; }
.srow:hover { background: color-mix(in srgb, var(--panel2) 55%, transparent); }
.srow .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srow .nm small { display: block; font-weight: 400; color: var(--faint); font-size: 11px; }
.srow .mt { color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.srow .val { font: 12px var(--mono); text-align: right; color: var(--muted); }
.srow .spark { width: 96px; height: 20px; }
.srow.head { border-top: 0; font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 600; }
.srow.head:hover { background: none; }

@media (max-width: 1100px) { .anat { grid-template-columns: 1fr; } .anat > .notes { border-left: 0; padding-left: 2px; } .rows2 { grid-template-columns: 1fr; } }
@media (prefers-reduced-motion: reduce) { .spark .sp-l, .verdict .vd-ico { animation: none !important; } }

/* ===== Stage 2 interaction (docs/ui-ux-spec.md section 5) ===== */
.fresh { margin-left: auto; padding-left: 10px; font: 10.5px var(--mono); color: var(--faint); white-space: nowrap; }
.fresh::before { content: ""; display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-right: 5px; vertical-align: 1px; box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 60%, transparent); animation: fr-beat 2s ease-out infinite; }
.fresh.stale::before { background: var(--warn); animation: none; }
.hd .fresh + .x, .sec-h .fresh + .x { margin-left: 10px; }
@keyframes fr-beat { 70% { box-shadow: 0 0 0 5px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }
.ns-drawer { position: fixed; top: 44px; right: 0; bottom: 0; width: min(520px, 92vw); z-index: 70; background: var(--panel); border-left: 1px solid var(--line2); box-shadow: -14px 0 40px rgba(0,0,0,.28); transform: translateX(104%); transition: transform .24s cubic-bezier(.2,.8,.2,1); display: flex; flex-direction: column; }
.ns-drawer.on { transform: none; }
.nd-h { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.nd-t { font-size: 14px; font-weight: 650; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nd-x { border: 0; background: none; color: var(--muted); font-size: 14px; cursor: pointer; padding: 4px 6px; border-radius: 4px; }
.nd-x:hover { background: var(--panel2); color: var(--text); }
.nd-b { padding: 12px 14px 20px; overflow-y: auto; }
.nd-sum { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 12px; }
.nd-chart { height: 130px; margin-bottom: 8px; }
.nlist .ni.mv .w { font-weight: 600; }
.nlist .up { color: var(--crit); } .nlist .dn { color: var(--ok); }
.ns-hcard { position: fixed; z-index: 80; width: 300px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--line2); background: var(--panel); box-shadow: 0 12px 32px rgba(0,0,0,.3); font-size: 12px; opacity: 0; pointer-events: none; transition: opacity .14s ease; }
.ns-hcard.on { opacity: 1; pointer-events: auto; }
.hc-top { display: flex; align-items: center; gap: 7px; } .hc-top b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hc-k { margin-left: auto; color: var(--faint); font-size: 11px; white-space: nowrap; }
.hc-m { color: var(--muted); margin-top: 2px; }
.hc-s { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--line); }
.hc-l { color: var(--faint); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; } .hc-v { font: 600 16px var(--mono); }
.hc-s .spark { width: 120px; height: 28px; }
.hc-r { margin-top: 6px; color: var(--muted); line-height: 1.35; } .hc-r.crit { color: var(--crit); }
.hc-a { display: flex; gap: 6px; margin-top: 10px; } .hc-a .vd-btn { padding: 3px 10px; cursor: pointer; font-family: inherit; }
.ns-toast { position: fixed; left: 50%; bottom: 22px; z-index: 90; transform: translate(-50%, 20px); max-width: 720px; padding: 9px 14px; border-radius: 8px; background: var(--text); color: var(--bg); font-size: 12.5px; box-shadow: 0 10px 30px rgba(0,0,0,.3); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.ns-toast.on { opacity: 1; transform: translate(-50%, 0); }
@media (prefers-reduced-motion: reduce) { .ns-drawer, .ns-toast, .ns-hcard { transition: none; } .fresh::before { animation: none; } }

/* role picker (role homes) */
.role-btn { height: 28px; padding: 0 10px; border-radius: 5px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); font: 12px var(--font); cursor: pointer; white-space: nowrap; }
.role-btn:hover { border-color: var(--accent); }
.role-menu button { padding: 7px 10px; }

/* investigation notebook */
.pin-btn { margin-left: 8px; width: 22px; height: 20px; display: inline-grid; place-items: center; border: 0; border-radius: 4px; background: none; color: var(--faint); cursor: pointer; opacity: .55; }
.card:hover .pin-btn, .sec-h:hover .pin-btn, .anat:hover .pin-btn { opacity: 1; }
.pin-btn:hover { color: var(--accent); background: var(--panel2); }
.nb-btn { position: relative; }
.nb-count { position: absolute; top: -5px; right: -5px; min-width: 15px; height: 15px; padding: 0 3px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font: 600 9.5px/15px var(--font); text-align: center; }
.nd-pin { margin-left: 8px; padding: 2px 9px; font-size: 11px; cursor: pointer; vertical-align: 1px; font-family: inherit; }
.nb-title { outline: none; border-radius: 4px; padding: 0 3px; margin-left: -3px; } .nb-title:focus { background: var(--panel2); }
.nb-list { display: flex; flex-direction: column; max-width: 1040px; }
.nb-item { display: grid; grid-template-columns: 84px minmax(0, 1fr); gap: 14px; padding: 14px 0; border-top: 1px solid var(--line); }
.nb-when { display: flex; flex-direction: column; font: 12px var(--mono); color: var(--muted); }
.nb-when b { color: var(--text); font-weight: 600; }
.nb-h { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; } .nb-h .faint { font-size: 11.5px; }
.nb-open { margin-left: auto; font-size: 12px; color: var(--accent); white-space: nowrap; }
.nb-x { border: 0; background: none; color: var(--faint); cursor: pointer; } .nb-x:hover { color: var(--crit); }
.nb-img { width: 100%; max-height: 300px; object-fit: contain; object-position: left; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.nb-text { border: 1px solid var(--line); border-radius: 6px; padding: 8px 12px; background: var(--panel); font-size: 12px; }
.nb-note { width: 100%; min-height: 54px; margin-top: 8px; padding: 7px 9px; border-radius: 6px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); font: 12.5px/1.45 var(--font); resize: vertical; }
.nb-empty { max-width: 640px; padding: 18px; border: 1px dashed var(--line2); border-radius: 8px; color: var(--muted); line-height: 1.5; }
@media print {
  header, nav, aside, .pin-btn, .nb-x, .nb-open, #nb-print, #nb-clear, .ns-drawer, .ns-hcard, .ns-toast, .theme-menu, #tabs { display: none !important; }
  html, body { overflow: visible !important; height: auto !important; background: #fff !important; color: #111 !important; }
  #main, #body { overflow: visible !important; height: auto !important; display: block !important; }
  .nb-item { break-inside: avoid; } .nb-note { border: 0; background: none; padding: 0; color: #111; }
}
@media print {
  :root, :root[data-theme] { --bg: #fff; --panel: #fff; --panel2: #f4f6f9; --line: #d9dfe7; --line2: #c9d1dc; --text: #111827; --muted: #3f4857; --faint: #5b6575; }
  .nb-note:placeholder-shown { display: none; }
}

/* alert stories */
.as-story { padding: 12px 2px 14px; border-bottom: 1px solid var(--line); }
.as-story.done { opacity: .72; }
.as-h { display: flex; align-items: center; gap: 9px; } .as-h b { font-size: 14px; } .as-h .vd-btn { margin-left: auto; padding: 3px 10px; }
.as-cause, .as-syms { display: grid; grid-template-columns: 82px minmax(0, 1fr); gap: 10px; margin-top: 8px; font-size: 12.5px; }
.as-cause.none { color: var(--muted); }
.as-story .lbl { color: var(--faint); font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; padding-top: 2px; }
.as-syms > div { display: flex; flex-wrap: wrap; gap: 4px 16px; }
.as-sym { display: flex; align-items: center; gap: 6px; font-size: 12.5px; }
.as-als { margin: 8px 0 0 92px; border-left: 2px solid var(--line); padding-left: 10px; }
.as-al { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto auto; align-items: center; gap: 8px; padding: 4px 0; font-size: 12.5px; }
.as-al .as-more { grid-column: 2 / -1; }
.as-btns { display: flex; gap: 4px; opacity: .6; } .as-al:hover .as-btns { opacity: 1; }
.as-btns button { font: 11.5px var(--font); padding: 2px 8px; border-radius: 4px; border: 1px solid var(--line2); background: none; color: var(--muted); cursor: pointer; }
.as-btns button:hover { color: var(--text); border-color: var(--accent); }
.as-why { margin: 4px 0 2px; padding: 8px 10px; border-radius: 6px; background: var(--panel2); display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.as-why .faint { display: inline-block; min-width: 84px; }
.as-form { display: flex; gap: 6px; margin: 4px 0; } .as-form select, .as-form input { height: 26px; border-radius: 5px; border: 1px solid var(--line2); background: var(--panel2); color: var(--text); font: 12px var(--font); padding: 0 8px; } .as-form input { flex: 1; max-width: 320px; }
.as-kids summary { cursor: pointer; color: var(--muted); font-size: 12px; padding: 4px 0; }
.as-fold { margin: 6px 0 0 92px; font-size: 11.5px; color: var(--faint); }
.as-noise td { vertical-align: top; }

/* Arabic, right to left: layout mirrors; charts keep left-to-right time axes */
.lang-btn { font: 600 14px "Segoe UI", Tahoma, sans-serif; }
:root[lang="ar"] body { font-family: "Segoe UI", "Noto Kufi Arabic", Tahoma, sans-serif; }
[dir="rtl"] [_echarts_instance_], [dir="rtl"] .chart, [dir="rtl"] .spark, [dir="rtl"] .mono, [dir="rtl"] .num { direction: ltr; }
[dir="rtl"] .vt { border-left: 0; border-right: 1px solid var(--line); }
[dir="rtl"] .vt:first-child { border-right: 0; padding-left: 14px; padding-right: 2px; }
[dir="rtl"] .vt .spark { right: auto; left: 12px; }
[dir="rtl"] .anat > .main { padding: 0 2px 14px 16px; }
[dir="rtl"] .anat > .notes { padding: 0 16px 14px 2px; border-left: 0; border-right: 1px solid var(--line); }
[dir="rtl"] .verdict .vd-a, [dir="rtl"] .sec-h .x, [dir="rtl"] .fresh, [dir="rtl"] .nb-open, [dir="rtl"] .hc-k, [dir="rtl"] .as-h .vd-btn { margin-left: 0; margin-right: auto; }
[dir="rtl"] .fresh { padding-left: 0; padding-right: 10px; }
[dir="rtl"] .ns-drawer { right: auto; left: 0; border-left: 0; border-right: 1px solid var(--line2); transform: translateX(-104%); box-shadow: 14px 0 40px rgba(0,0,0,.28); }
[dir="rtl"] .ns-drawer.on { transform: none; }
[dir="rtl"] .as-als { margin: 8px 92px 0 0; border-left: 0; border-right: 2px solid var(--line); padding-left: 0; padding-right: 10px; }
[dir="rtl"] .as-fold { margin: 6px 92px 0 0; }
[dir="rtl"] .sig { border-left: 1px solid var(--line); }
[dir="rtl"] .vt-l, [dir="rtl"] .sec-h h3, [dir="rtl"] .sublbl, [dir="rtl"] .hc-l, [dir="rtl"] .as-story .lbl { letter-spacing: 0; text-transform: none; }
/* mixed English runs inside the right-to-left layout keep their own order; numbers stay left to right */
[dir="rtl"] .vd-t, [dir="rtl"] .vd-t .m, [dir="rtl"] .nlist .ni > span, [dir="rtl"] .sig .t, [dir="rtl"] .sig .m, [dir="rtl"] .vt-d, [dir="rtl"] .srow .mt, [dir="rtl"] .srow .nm, [dir="rtl"] .chg span, [dir="rtl"] .hc-r, [dir="rtl"] .hc-m, [dir="rtl"] .ph .sub, [dir="rtl"] .as-cause > span, [dir="rtl"] .as-t, [dir="rtl"] td, [dir="rtl"] .sec-h .x, [dir="rtl"] .chg div, [dir="rtl"] .nb-h .faint { unicode-bidi: plaintext; }
[dir="rtl"] .vt-v, [dir="rtl"] .srow .val, [dir="rtl"] .hc-v { direction: ltr; }
[dir="rtl"] .vt-v { justify-content: flex-end; }
[dir="rtl"] .srow .val { text-align: left; }
[dir="rtl"] .vd-t, [dir="rtl"] .vt-d, [dir="rtl"] .srow .mt, [dir="rtl"] .srow .nm, [dir="rtl"] .sig .t, [dir="rtl"] .sig .m, [dir="rtl"] .nlist .ni > span, [dir="rtl"] .hc-r, [dir="rtl"] .hc-m, [dir="rtl"] .ph .sub, [dir="rtl"] .chg span, [dir="rtl"] .chg div, [dir="rtl"] .as-cause > span { text-align: right; }

/* brand: the supplied NerveStack logo (brand/final) */
.ns-mark { width: 26px; height: 26px; display: block; }
.ns-word { font-weight: 600; letter-spacing: -.1px; }
.ns-word b { font-weight: 650; background: linear-gradient(90deg, #4a78ff, #43d3e6); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ===== Phones (≤ 760 px): the app becomes a normal scrolling page ===== */
@media (max-width: 760px) {
  html, body { height: auto; }
  body { overflow: auto; overflow-x: hidden; }
  .ns-app { display: block; height: auto; min-height: 100vh; }
  /* header: brand + icons / search / role + range */
  .ns-top { flex-wrap: wrap; height: auto; padding: 6px 10px 8px; gap: 6px 6px; }
  .ns-top-right { display: contents; }
  .ns-org, .live, #cmp, .ns-search kbd { display: none !important; }
  .ns-brand { order: 0; }
  #rail-btn, #lang-btn, #nb-btn, #theme-btn { order: 1; }
  #rail-btn { margin-left: auto; }
  .ns-search { order: 2; flex: 1 1 100%; max-width: none; margin: 0; height: 32px; }
  #role-btn { order: 3; height: 30px; }
  #range { order: 3; margin-left: auto; }
  #range button { padding: 0 9px; }
  .ns-tabs { height: 40px; }
  .ns-tab { padding: 0 12px; font-size: 13px; }
  /* content, then the signal rail below it */
  .ns-body, .ns-body.rail-off { display: block; }
  .ns-main { overflow: visible; padding: 10px 10px 18px; }
  .ns-rail { border-left: 0; border-top: 1px solid var(--line); padding: 12px 10px 28px; }
  /* card grid: 2 columns; small cards side by side, everything else full width */
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
  .grid > .s2, .grid > .s3 { grid-column: span 1; }
  .grid > .s4, .grid > .s5, .grid > .s6, .grid > .s7, .grid > .s8, .grid > .s9, .grid > .s10, .grid > .s11, .grid > .s12 { grid-column: span 2; }
  .kpi .v { font-size: 18px; }
  .ph { flex-wrap: wrap; gap: 8px; }
  .ph h1 { font-size: 16px; }
  /* page anatomy */
  .verdict { flex-wrap: wrap; gap: 8px 10px; padding: 8px 0 10px; }
  .verdict .vd-t { font-size: 14.5px; flex: 1 1 calc(100% - 40px); }
  .verdict .vd-a { margin-left: 32px; flex-wrap: wrap; }
  .vitals { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .vt { border-left: 0; border-bottom: 1px solid var(--line); padding: 8px 6px 9px 2px; }
  .vt:nth-child(even) { border-left: 1px solid var(--line); padding-left: 10px; }
  .vt-v b { font-size: 19px; }
  .vt .spark { width: 52px; top: 30px; right: 4px; }
  .anat > .main, .anat > .notes { padding-left: 0; padding-right: 0; }
  .chart.tall { height: 230px; }
  .srow { grid-template-columns: 10px minmax(0, 1.5fr) minmax(0, 1fr) 58px; gap: 8px; }
  .srow > :nth-child(4) { display: none; }
  .legend-inline { flex-wrap: wrap; gap: 4px 12px; }
  /* anything that is a row of tabs or links scrolls sideways instead of overflowing */
  .subnavs { flex-wrap: nowrap; flex-direction: column; align-items: stretch; gap: 6px; }
  .subgrp { overflow-x: auto; scrollbar-width: none; }
  .subnav, .ptabs, .seg, .ndt-bar, .wo-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .sublbl { min-width: 0; }
  /* tables scroll inside their card */
  .card > .bd, .tbl-wrap { overflow-x: auto; }
  .card table.t { min-width: 540px; }
  /* overlays */
  .ns-drawer { width: 100vw; top: 0; }
  .theme-menu { max-width: calc(100vw - 20px); }
  .ns-toast { max-width: calc(100vw - 24px); }
  /* notebook and alert stories */
  .nb-item { grid-template-columns: 1fr; gap: 6px; }
  .nb-when { flex-direction: row; gap: 8px; }
  .as-cause, .as-syms { grid-template-columns: 1fr; gap: 2px; }
  .as-als, .as-fold { margin-left: 0; }
  .as-al { grid-template-columns: 10px minmax(0, 1fr); }
  .as-al .as-st, .as-al .as-btns { grid-column: 2; }
  .as-h { flex-wrap: wrap; }
}
/* touch screens: no hover cards (Peek is in the palette: "peek <name>") */
@media (hover: none) { .ns-hcard { display: none !important; } .pin-btn { opacity: 1; } }
@media (max-width: 760px) {
  .ph > * { min-width: 0; max-width: 100%; }
  .ph > div:last-child, .ph > span:last-child { display: flex; flex-wrap: wrap; gap: 6px; }
  .ph select, .ph input { max-width: 100%; min-width: 0; }
  .sublbl { white-space: nowrap; }
}
@media (max-width: 760px) {
  /* App Triage: bars wrap; the route graph scrolls sideways inside its panel */
  .atr > *, .atr .top, .atr .panel { min-width: 0; max-width: 100%; }
  .atr .top, .atr .maphead, .atr .pbar, .atr .fresh { flex-wrap: wrap; }
  .atr .pbar input, .atr .grow { min-width: 0; max-width: 100%; }
  .atr .panel { overflow-x: auto; }
  /* App Timeline: the lane grid scrolls sideways */
  .atl-gridwrap { overflow-x: auto; }
}
@media (max-width: 760px) {
  /* any wide data table that is not already in a scrolling wrapper: its parent scrolls sideways */
  :has(> table.atr-t), :has(> table.as-noise) { overflow-x: auto; max-width: 100%; }
}
@media (max-width: 760px) {
  .sublbl { display: none; }
  .subnavs { gap: 4px; }
  .subnav a { white-space: nowrap; padding: 6px 12px; }
}

/* ===== Tablets (761–1024 px): phone shell (wrapping header, scrolling page, rail below), desktop-like content ===== */
@media (min-width: 761px) and (max-width: 1024px) {
  html, body { height: auto; }
  body { overflow: auto; overflow-x: hidden; }
  .ns-app { display: block; height: auto; min-height: 100vh; }
  .ns-top { flex-wrap: wrap; height: auto; padding: 6px 12px 8px; gap: 6px 8px; }
  .ns-top-right { display: contents; }
  .ns-org, .live, .ns-search kbd { display: none !important; }
  .ns-brand { order: 0; }
  .ns-search { order: 1; flex: 1 1 240px; max-width: none; margin: 0 0 0 8px; }
  #rail-btn, #lang-btn, #nb-btn, #theme-btn { order: 2; }
  #role-btn, #cmp, #range { order: 3; }
  #range { margin-left: auto; }
  .ns-body, .ns-body.rail-off { display: block; }
  .ns-main { overflow: visible; }
  .ns-rail { border-left: 0; border-top: 1px solid var(--line); }
  .ph { flex-wrap: wrap; } .ph > * { min-width: 0; max-width: 100%; }
  .subnav, .ptabs, .seg { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; max-width: 100%; }
  .card > .bd, .tbl-wrap, .atr .panel, .atl-gridwrap { overflow-x: auto; }
  .atr .top, .atr .maphead, .atr .pbar { flex-wrap: wrap; }
}
