/* TGF Console — design system + layout. No frameworks, no external fonts. */

:root {
  --bg: #0A0F16; --panel: #101724; --card: #151E2E; --card-hi: #1A2537;
  --ink: #E6EDF6; --muted: #8FA0B5; --faint: #5C6B80; --line: #223046;
  --line-soft: #1A2536;
  --accent: #4DA3FF; --accent-ink: #0A0F16; --accent-soft: rgba(77,163,255,.13);
  --ok: #2FBF71; --warn: #F0A93B; --bad: #F0564A;
  --ok-soft: rgba(47,191,113,.14); --warn-soft: rgba(240,169,59,.15); --bad-soft: rgba(240,86,74,.15);
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 10px 30px -12px rgba(0,0,0,.5);
  --glow-ok: 0 0 10px rgba(47,191,113,.45); --glow-bad: 0 0 10px rgba(240,86,74,.5);
  --mono: ui-monospace, "SF Mono", "Cascadia Code", Consolas, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, Inter, system-ui, sans-serif;
  --r: 12px; --r-sm: 8px; --t: 190ms;
  --rail-w: 212px; --drawer-w: 372px;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #F2F5F9; --panel: #FFFFFF; --card: #FFFFFF; --card-hi: #F6F9FD;
  --ink: #17202D; --muted: #5A6A7E; --faint: #8795A8; --line: #DCE4EE;
  --line-soft: #E8EEF5;
  --accent: #1D6FE0; --accent-ink: #FFFFFF; --accent-soft: rgba(29,111,224,.09);
  --ok: #158A50; --warn: #B26205; --bad: #C2372C;
  --ok-soft: rgba(21,138,80,.1); --warn-soft: rgba(178,98,5,.1); --bad-soft: rgba(194,55,44,.09);
  --shadow: 0 1px 2px rgba(23,32,45,.06), 0 8px 24px -12px rgba(23,32,45,.14);
  --glow-ok: none; --glow-bad: none;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; height: 100%; }
body {
  margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 15px; line-height: 1.45;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 700; letter-spacing: -0.01em; }
p { margin: 0 0 .55rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.mono { font-family: var(--mono); }

/* ---- App frame ----------------------------------------------------------- */
#app { display: flex; flex-direction: column; height: 100%; }

.banner {
  flex: none; background: #0D1420; color: #C7D3E4; border-bottom: 1px solid var(--line);
  font-size: .74rem; padding: .3rem 1rem; text-align: center;
}
:root[data-theme="light"] .banner { background: #17202D; color: #D8E1EC; }
.banner b { color: #fff; }

.topbar {
  flex: none; display: flex; align-items: center; gap: .9rem; padding: .55rem 1rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.brand .mark { width: 30px; height: 30px; flex: none; }
.brand h1 { font-size: 1.02rem; white-space: nowrap; }
.brand .sub { display: block; font-size: .68rem; color: var(--muted); font-weight: 500; letter-spacing: .02em; white-space: normal; }

.scenarios { display: flex; gap: .35rem; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
.scenarios::-webkit-scrollbar { display: none; }
.sc-chip {
  border: 1px solid var(--line); background: var(--card); color: var(--muted);
  border-radius: 999px; padding: .34rem .8rem; font-size: .8rem; cursor: pointer;
  white-space: nowrap; min-height: 36px; transition: all var(--t) ease;
}
.sc-chip:hover { color: var(--ink); border-color: var(--accent); }
.sc-chip[aria-checked="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 650; }

.top-right { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.pill-sim {
  font-family: var(--mono); font-size: .68rem; font-weight: 700; letter-spacing: .06em;
  color: var(--warn); background: var(--warn-soft); border: 1px solid var(--warn);
  border-radius: 999px; padding: .3rem .65rem; white-space: nowrap; cursor: pointer;
  min-height: 32px; display: inline-flex; align-items: center;
}
.iconbtn {
  position: relative; border: 1px solid var(--line); background: var(--card); border-radius: 9px;
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--muted); transition: all var(--t) ease;
}
.iconbtn:hover { color: var(--ink); border-color: var(--accent); }
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn .cnt {
  position: absolute; top: -6px; right: -6px; background: var(--bad); color: #fff;
  font-size: .62rem; font-weight: 700; border-radius: 999px; min-width: 17px; height: 17px;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* ---- Sim bar (playback) -------------------------------------------------- */
.simbar {
  flex: none; display: flex; align-items: center; gap: .8rem; padding: .45rem 1rem;
  background: var(--panel); border-bottom: 1px solid var(--line); font-size: .8rem;
}
.simbar .transport { display: flex; align-items: center; gap: .4rem; }
.simbar .scrub { flex: 1; display: flex; align-items: center; gap: .7rem; min-width: 120px; }
.simbar input[type="range"] {
  flex: 1; accent-color: var(--accent); height: 22px; margin: 0; min-width: 60px;
}
.simclock { font-family: var(--mono); font-size: .78rem; color: var(--ink); white-space: nowrap; }
.simclock .d { color: var(--muted); }
.speed {
  border: 1px solid var(--line); background: var(--card); color: var(--ink); border-radius: 8px;
  padding: .25rem .4rem; font-size: .76rem; cursor: pointer;
}
.sim-note { color: var(--faint); font-size: .7rem; white-space: nowrap; }

/* ---- Body: rail + main --------------------------------------------------- */
.body { flex: 1; display: flex; min-height: 0; }

.rail {
  flex: none; width: var(--rail-w); background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding: .6rem .5rem; gap: .15rem; overflow-y: auto;
}
.rail a {
  display: flex; align-items: center; gap: .65rem; color: var(--muted); border-radius: 9px;
  padding: .5rem .65rem; font-size: .84rem; font-weight: 550; min-height: 40px;
  transition: all var(--t) ease; border: 1px solid transparent;
}
.rail a:hover { color: var(--ink); background: var(--card); text-decoration: none; }
.rail a[aria-current="page"] { color: var(--ink); background: var(--accent-soft); border-color: var(--line); }
.rail a[aria-current="page"] svg { color: var(--accent); }
.rail svg { width: 18px; height: 18px; flex: none; }
.rail .spacer { flex: 1; }
.rail .foot { font-size: .66rem; color: var(--faint); padding: .5rem .65rem; line-height: 1.5; }

main {
  flex: 1; min-width: 0; overflow-y: auto; overflow-x: hidden; padding: 1.1rem 1.2rem 2.5rem;
  scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) { main { scroll-behavior: auto; } }
.view { display: none; max-width: 1440px; margin: 0 auto; }
.view.active { display: block; }
.view-head { display: flex; align-items: baseline; gap: .8rem; margin-bottom: 1rem; flex-wrap: wrap; }
.view-head h2 { font-size: 1.22rem; }
.view-head .note { color: var(--muted); font-size: .82rem; }

/* ---- Cards & grid -------------------------------------------------------- */
.grid { display: grid; gap: .9rem; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: .9rem 1rem; box-shadow: var(--shadow); min-width: 0;
}
.card .card-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .6rem; }
.card .card-head h3 { font-size: .86rem; font-weight: 650; }
.card .card-head .right { margin-left: auto; display: flex; gap: .4rem; align-items: center; }
.label { font-size: .66rem; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); font-weight: 650; }

.prov {
  font-family: var(--mono); font-size: .62rem; padding: .13rem .42rem; border-radius: 999px;
  border: 1px solid var(--line); color: var(--muted); background: var(--panel);
  cursor: help; white-space: nowrap; display: inline-flex; align-items: center; gap: .25rem;
}
.prov.warn { color: var(--warn); border-color: var(--warn); background: var(--warn-soft); }
.prov.badge-live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 55%, transparent); }
.prov.badge-fault { color: var(--bad); border-color: var(--bad); background: var(--bad-soft); font-weight: 700; }

.chip-btn {
  border: 1px solid var(--line); background: var(--card); color: var(--muted); border-radius: 999px;
  padding: .28rem .7rem; font-size: .76rem; cursor: pointer; min-height: 34px;
  transition: all var(--t) ease; white-space: nowrap;
}
.chip-btn:hover { color: var(--ink); border-color: var(--accent); }
.chip-btn[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--ink); font-weight: 600; }

.btn {
  border: 1px solid var(--line); background: var(--card-hi); color: var(--ink); border-radius: 9px;
  padding: .5rem .9rem; font-size: .84rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: .45rem; min-height: 40px;
  transition: all var(--t) ease;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger-outline { border-color: var(--bad); color: var(--bad); background: transparent; }

/* ---- Overview ------------------------------------------------------------ */
.ov-hero { display: grid; grid-template-columns: minmax(280px, 1.25fr) 2fr; gap: .9rem; margin-bottom: .9rem; }
.verdict { display: flex; flex-direction: column; gap: .45rem; justify-content: center; position: relative; overflow: hidden; }
.verdict .v-state { font-size: 1.62rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.verdict .v-sub { color: var(--muted); font-size: .86rem; }
.verdict.state-ok .v-state { color: var(--ok); }
.verdict.state-warn .v-state { color: var(--warn); }
.verdict.state-bad .v-state { color: var(--bad); }
.verdict .v-dot { position: absolute; top: 1rem; right: 1rem; width: 11px; height: 11px; border-radius: 50%; }
.verdict.state-ok .v-dot { background: var(--ok); box-shadow: var(--glow-ok); }
.verdict.state-warn .v-dot { background: var(--warn); }
.verdict.state-bad .v-dot { background: var(--bad); box-shadow: var(--glow-bad); animation: pulse 1.6s ease infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .verdict.state-bad .v-dot { animation: none; } }

.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: .9rem; }
@media (max-width: 1060px) { .kpis { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); } }
.v-hints { margin: .6rem 0 0; padding-left: 1.05rem; font-size: .78rem; color: var(--muted); }
.v-hints li { margin-bottom: .25rem; }
.kpi { cursor: pointer; transition: border-color var(--t) ease; }
.kpi:hover { border-color: var(--accent); }
.kpi .k-top { display: flex; align-items: baseline; gap: .5rem; }
.kpi .k-name { font-size: .76rem; color: var(--muted); font-weight: 600; }
.kpi .k-val { font-size: 1.86rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.05; margin: .15rem 0; }
.kpi .k-val .u { font-size: .78rem; color: var(--muted); font-weight: 600; margin-left: .25rem; }
.kpi.state-warn .k-val { color: var(--warn); }
.kpi.state-bad .k-val { color: var(--bad); }
.kpi .k-band { position: relative; height: 5px; border-radius: 4px; background: var(--line-soft); margin: .35rem 0 .3rem; }
.kpi .k-band .fill { position: absolute; inset: 0; border-radius: 4px; background: linear-gradient(90deg, var(--warn-soft), var(--ok-soft) 30%, var(--ok-soft) 70%, var(--warn-soft)); }
.kpi .k-band .mark { position: absolute; top: -3.5px; width: 3px; height: 12px; border-radius: 2px; background: var(--ink); }
.kpi .k-meta { display: flex; align-items: center; gap: .45rem; font-size: .7rem; color: var(--muted); flex-wrap: wrap; }
.kpi .delta { font-family: var(--mono); font-size: .68rem; }
.kpi .delta.up { color: var(--warn); } .kpi .delta.down { color: var(--accent); } .kpi .delta.flat { color: var(--faint); }
.kpi .spark { height: 42px; margin-top: .3rem; }

.ov-mid { display: grid; grid-template-columns: 1.35fr 1fr; gap: .9rem; margin-top: .9rem; }
.gauges3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
.gauge-cell { text-align: center; }
.gauge-cell .g-chart { height: 138px; }
.gauge-cell .g-verdict { font-size: .72rem; color: var(--muted); margin-top: .35rem; }
.suppressed-note { display: flex; align-items: center; justify-content: center; height: 132px; color: var(--bad); font-size: .8rem; text-align: center; padding: 0 .6rem; }

/* ---- Twin ---------------------------------------------------------------- */
.twin-wrap { display: grid; grid-template-columns: minmax(0, 1.9fr) minmax(300px, 1fr); gap: .9rem; align-items: stretch; }
.twin-svg-card { padding: .6rem; display: flex; flex-direction: column; justify-content: center; gap: .5rem; min-width: 0; }
.twin-svg { width: 100%; height: auto; max-height: 100%; display: block; flex: 0 1 auto; }
.flow { fill: none; stroke-width: 3.2; stroke-linecap: round; }
.flow.hot { stroke: #E06A4E; } .flow.cold { stroke: #4DA3FF; } .flow.makeup { stroke: #35B98F; } .flow.blowdown { stroke: #9A86E8; } .flow.dose { stroke: var(--warn); stroke-width: 2.4; }
.flow.animated { stroke-dasharray: 7 9; animation: flowdash 1.1s linear infinite; }
.flow.dose.animated { stroke-dasharray: 3 8; }
@keyframes flowdash { to { stroke-dashoffset: -16; } }
@media (prefers-reduced-motion: reduce) { .flow.animated { animation: none; } .fanblade { animation: none !important; } }
.equip { fill: var(--card-hi); stroke: var(--muted); stroke-width: 1.6; }
.equip-label { font-size: 14px; fill: var(--ink); font-family: var(--sans); font-weight: 650; }
.svg-tag { font-size: 11.5px; fill: var(--muted); font-family: var(--mono); }
.fanblade { transform-origin: center; animation: spin 2.6s linear infinite; }
.fanblade.paused { animation-play-state: paused; }
@keyframes spin { to { transform: rotate(360deg); } }
.basin-water { fill: rgba(77,163,255,.22); }

.tagpanels { display: flex; flex-direction: column; gap: .9rem; min-width: 0; }
.twin-lower { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: .9rem; margin-top: .9rem; align-items: start; }
/* Twin rail only: stack name over value so 18 recirc tags fit 3-up instead of
   2-up. Keeps the rail's height near the fixed-aspect schematic beside it. */
.twin-wrap .tagpanel .tp-grid { grid-template-columns: repeat(auto-fit, minmax(92px, 1fr)); }
.twin-wrap .tagpanel .tag { flex-wrap: wrap; justify-content: flex-start; align-items: baseline; gap: .1rem .3rem; padding: .3rem .45rem; min-height: 42px; }
.twin-wrap .tagpanel .tag .t-kind { order: 1; align-self: center; }
.twin-wrap .tagpanel .tag .t-name { order: 2; flex: 1 1 auto; font-size: .62rem; line-height: 1.15; }
.twin-wrap .tagpanel .tag .t-val { order: 3; flex: 1 0 100%; font-size: .74rem; }
.tagpanel .tp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .35rem; }
.tag {
  display: flex; align-items: center; justify-content: space-between; gap: .4rem;
  background: var(--panel); border: 1px solid var(--line-soft); border-radius: 8px;
  padding: .32rem .5rem; cursor: pointer; min-height: 38px; transition: border-color var(--t) ease;
}
.tag:hover { border-color: var(--accent); }
.tag .t-name { font-size: .68rem; color: var(--muted); }
.tag .t-val { font-family: var(--mono); font-size: .8rem; font-weight: 650; white-space: nowrap; }
.tag.state-warn .t-val { color: var(--warn); } .tag.state-bad .t-val { color: var(--bad); }
.tag .t-kind { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.tag .t-kind.live { background: var(--ok); } .tag .t-kind.estimated { background: var(--accent); }
.tag .t-kind.lab { background: var(--warn); } .tag .t-kind.fault { background: var(--bad); box-shadow: var(--glow-bad); }
.kindlegend { display: flex; gap: .8rem; font-size: .68rem; color: var(--muted); flex-wrap: wrap; margin-top: .5rem; }
.kindlegend i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; margin-right: .3rem; }

.pumps { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .6rem; }
.pump { display: flex; align-items: center; gap: .6rem; background: var(--panel); border: 1px solid var(--line-soft); border-radius: 9px; padding: .5rem .6rem; }
.pump .p-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; background: var(--faint); }
.pump.running .p-dot { background: var(--ok); box-shadow: var(--glow-ok); }
.pump.held .p-dot { background: var(--bad); box-shadow: var(--glow-bad); }
.pump .p-name { font-size: .74rem; font-weight: 600; }
.pump .p-state { font-size: .66rem; color: var(--muted); font-family: var(--mono); }

/* ---- Slideover ----------------------------------------------------------- */
.slideover {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(430px, 94vw); z-index: 70;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  transform: translateX(102%); transition: transform 240ms ease; display: flex; flex-direction: column;
}
.slideover.open { transform: none; }
.slideover .so-head { display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.slideover .so-body { padding: 1rem; overflow-y: auto; }
@media (prefers-reduced-motion: reduce) { .slideover { transition: none; } }

/* ---- Analytics ----------------------------------------------------------- */
.an-controls { display: flex; gap: .35rem; flex-wrap: wrap; margin-bottom: .8rem; align-items: center; }
.an-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: .9rem; }
.stat-table { width: 100%; border-collapse: collapse; font-size: .76rem; }
.stat-table td { padding: .22rem .3rem; border-bottom: 1px solid var(--line-soft); }
.stat-table td:last-child { text-align: right; font-family: var(--mono); }

/* ---- Forecast ------------------------------------------------------------ */
.fc-controls { display: flex; align-items: center; gap: .8rem; flex-wrap: wrap; margin-bottom: .8rem; }
.model-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .9rem; margin-top: .9rem; }
.model-card .m-status { font-size: .72rem; font-weight: 700; font-family: var(--mono); }
.model-card .m-status.ran { color: var(--ok); }
.model-card .m-status.not-ran { color: var(--muted); }
.model-card p { font-size: .78rem; color: var(--muted); }

/* ---- Advisor ------------------------------------------------------------- */
.adv-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, 1fr); gap: .9rem; }
.rec-dose { font-size: 2.2rem; font-weight: 800; letter-spacing: -.02em; line-height: 1; }
.rec-dose .u { font-size: .9rem; color: var(--muted); font-weight: 600; }
.rec-state { font-family: var(--mono); font-size: .68rem; font-weight: 700; letter-spacing: .05em; padding: .22rem .55rem; border-radius: 999px; }
.rec-state.proposed { color: var(--accent); background: var(--accent-soft); border: 1px solid var(--accent); }
.rec-state.blocked { color: var(--bad); background: var(--bad-soft); border: 1px solid var(--bad); }
.rec-rationale { margin: .6rem 0 0; padding-left: 1.1rem; font-size: .82rem; }
.rec-rationale li { margin-bottom: .3rem; }
.checks { display: flex; flex-direction: column; gap: .4rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; background: var(--panel); border: 1px solid var(--line-soft); border-radius: 9px; padding: .45rem .6rem; }
.check .c-ic { flex: none; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: .7rem; font-weight: 800; margin-top: .1rem; }
.check.pass .c-ic { background: var(--ok-soft); color: var(--ok); }
.check.fail .c-ic { background: var(--bad-soft); color: var(--bad); }
.check.fail { border-color: var(--bad); }
.check .c-name { font-size: .78rem; font-weight: 650; }
.check .c-detail { font-size: .7rem; color: var(--muted); }
.decision-btns { display: flex; gap: .6rem; align-items: center; margin-top: .7rem; flex-wrap: wrap; }
.held-note { color: var(--bad); font-weight: 700; font-size: .9rem; }
.inv-cards { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.inv { background: var(--panel); border: 1px solid var(--line-soft); border-radius: 9px; padding: .55rem .65rem; }
.inv .i-chem { font-size: .74rem; font-weight: 650; }
.inv .i-days { font-size: 1.3rem; font-weight: 800; }
.inv .i-days.low { color: var(--warn); }
.inv .i-meta { font-size: .66rem; color: var(--muted); }
.oplog { list-style: none; margin: 0; padding: 0; font-size: .76rem; }
.oplog li { display: flex; gap: .6rem; padding: .4rem 0; border-bottom: 1px solid var(--line-soft); align-items: baseline; }
.oplog .lt { font-family: var(--mono); font-size: .66rem; color: var(--faint); white-space: nowrap; }

/* ---- Safety -------------------------------------------------------------- */
.saf-pipe { display: flex; align-items: stretch; gap: .5rem; flex-wrap: wrap; }
.saf-node { flex: 1 1 180px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; position: relative; }
.saf-node .lamp { width: 12px; height: 12px; border-radius: 50%; position: absolute; top: .6rem; right: .6rem; }
.saf-node.pass .lamp { background: var(--ok); box-shadow: var(--glow-ok); }
.saf-node.fail .lamp { background: var(--bad); box-shadow: var(--glow-bad); animation: pulse 1.4s ease infinite; }
.saf-node.fail { border-color: var(--bad); }
.saf-node .s-name { font-size: .78rem; font-weight: 700; padding-right: 1.2rem; }
.saf-node .s-detail { font-size: .68rem; color: var(--muted); margin-top: .25rem; }
.saf-arrow { align-self: center; color: var(--faint); flex: none; }
.meter { margin: .5rem 0; }
.meter .m-track { height: 9px; border-radius: 6px; background: var(--line-soft); position: relative; overflow: hidden; }
.meter .m-fill { position: absolute; inset: 0 auto 0 0; border-radius: 6px; background: var(--accent); }
.meter .m-fill.warn { background: var(--warn); } .meter .m-fill.bad { background: var(--bad); }
.meter .m-lbl { display: flex; justify-content: space-between; font-size: .68rem; color: var(--muted); margin-top: .25rem; }

/* ---- Methods ------------------------------------------------------------- */
.methods-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.ran-list { list-style: none; margin: 0; padding: 0; font-size: .8rem; }
.ran-list li { display: flex; gap: .6rem; padding: .35rem 0; border-bottom: 1px solid var(--line-soft); align-items: baseline; }
.ran-list .r-what { color: var(--muted); min-width: 90px; font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; }
.formula { background: var(--panel); border: 1px solid var(--line-soft); border-radius: 9px; padding: .6rem .7rem; font-family: var(--mono); font-size: .76rem; margin: .4rem 0; overflow-x: auto; }
.whatif label { display: block; font-size: .74rem; color: var(--muted); margin: .5rem 0 .15rem; }
.whatif input[type="range"] { width: 100%; accent-color: var(--accent); }
.isnot { display: grid; grid-template-columns: 1fr 1fr; gap: .9rem; }
.isnot ul { margin: .3rem 0 0; padding-left: 1.1rem; font-size: .8rem; }
.isnot li { margin-bottom: .3rem; }
.pipe-steps { display: flex; gap: .5rem; flex-wrap: wrap; align-items: stretch; }
.pipe-step { flex: 1 1 150px; background: var(--panel); border: 1px solid var(--line-soft); border-radius: 9px; padding: .5rem .6rem; }
.pipe-step .n { font-family: var(--mono); color: var(--accent); font-size: .68rem; }
.pipe-step .t { font-size: .76rem; font-weight: 650; }
.pipe-step .d { font-size: .66rem; color: var(--muted); }

/* ---- Alerts drawer ------------------------------------------------------- */
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--drawer-w), 96vw); z-index: 80;
  background: var(--panel); border-left: 1px solid var(--line); box-shadow: var(--shadow);
  transform: translateX(102%); transition: transform 240ms ease; display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
@media (prefers-reduced-motion: reduce) { .drawer { transition: none; } }
.drawer .d-head { display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem; border-bottom: 1px solid var(--line); }
.drawer .d-body { flex: 1; overflow-y: auto; padding: .6rem .8rem; }
.alert-card { border: 1px solid var(--line-soft); border-left-width: 3px; border-radius: 9px; background: var(--card); padding: .55rem .7rem; margin-bottom: .55rem; }
.alert-card.sev-critical { border-left-color: var(--bad); }
.alert-card.sev-warning { border-left-color: var(--warn); }
.alert-card .a-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.alert-card .a-text { font-size: .78rem; font-weight: 600; flex: 1 1 100%; margin-top: .2rem; }
.alert-card .a-time { font-family: var(--mono); font-size: .64rem; color: var(--faint); }
.alert-card .a-state { font-size: .62rem; font-family: var(--mono); padding: .1rem .4rem; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.alert-card .a-state.active { color: var(--bad); border-color: var(--bad); }
.alert-card .a-state.resolved { color: var(--ok); border-color: var(--ok); }
.alert-card .a-ack { margin-left: auto; }
.empty-note { color: var(--muted); font-size: .8rem; text-align: center; padding: 1.4rem .5rem; }

/* ---- Tooltip / popover ---------------------------------------------------- */
.pop {
  position: fixed; z-index: 95; max-width: 340px; background: var(--card-hi); color: var(--ink);
  border: 1px solid var(--line); border-radius: 9px; padding: .55rem .7rem; font-size: .74rem;
  box-shadow: var(--shadow); line-height: 1.45;
}
.pop .p-title { font-weight: 700; margin-bottom: .2rem; font-size: .72rem; }
.pop code, .formula code { font-family: var(--mono); font-size: .68rem; color: var(--accent); }

.footline { max-width: 1440px; margin: 2rem auto 0; padding-top: .8rem; border-top: 1px solid var(--line); color: var(--faint); font-size: .72rem; display: flex; gap: 1rem; flex-wrap: wrap; }

.chart { width: 100%; }
.chart-lg { height: 300px; } .chart-md { height: 230px; } .chart-sm { height: 160px; }

.scrim { position: fixed; inset: 0; background: rgba(4,8,14,.5); z-index: 60; opacity: 0; pointer-events: none; transition: opacity var(--t) ease; }
.scrim.on { opacity: 1; pointer-events: auto; }

/* ---- Loading skeleton ----------------------------------------------------- */
.skel { position: relative; overflow: hidden; background: var(--line-soft); border-radius: 8px; min-height: 80px; }
.skel::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.05), transparent);
  animation: shimmer 1.4s infinite; }
@keyframes shimmer { to { transform: translateX(100%); } }

/* ---- Responsive ----------------------------------------------------------- */
@media (max-width: 1060px) {
  .ov-hero, .ov-mid, .twin-wrap, .twin-lower, .an-grid, .adv-grid, .methods-grid, .isnot { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  body { overflow: auto; overflow-x: hidden; }
  #app { height: auto; min-height: 100%; }
  .kpis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .topbar { flex-wrap: wrap; gap: .5rem; }
  .top-right { margin-left: 0; width: 100%; justify-content: flex-end; }
  .scenarios { width: 100%; order: 3; }
  .simbar { flex-wrap: wrap; }
  .sim-note { display: none; }
  .body { flex-direction: column; }
  .rail { width: auto; flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: .35rem .5rem; position: sticky; top: 0; z-index: 50; }
  .rail a { flex: none; padding: .45rem .6rem; font-size: .76rem; }
  .rail .foot, .rail .spacer { display: none; }
  main { overflow: visible; padding: .9rem .8rem 2rem; }
  .kpi .k-val { font-size: 1.5rem; }
  .gauges3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .inv-cards { grid-template-columns: 1fr; }
  /* Long provenance chips overflowed the viewport on narrow screens because the
     card head never wrapped. Let the head wrap and the chip shrink. */
  .card .card-head { flex-wrap: wrap; }
  .card .card-head .right { min-width: 0; flex-wrap: wrap; }
  .card .card-head .right .prov { max-width: 100%; white-space: normal; }
  .tagpanel .tp-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  /* Narrow tags cannot fit "Magnesium hardness" and "209 ppm CaCO₃" on one row —
     stack the value under the name so long units stop overflowing the tag. */
  .tagpanel .tag { flex-wrap: wrap; justify-content: flex-start; align-items: baseline; gap: .1rem .3rem; }
  .tagpanel .tag .t-kind { order: 1; align-self: center; }
  .tagpanel .tag .t-name { order: 2; flex: 1 1 auto; }
  .tagpanel .tag .t-val { order: 3; flex: 1 0 100%; }
}
@media (max-width: 430px) {
  .kpis { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kpi .k-val { font-size: 1.32rem; }
  .simclock { font-size: .68rem; }
  .simclock .hcount { display: none; }
  .scrub .label { display: none; }
  main { padding: .8rem .6rem 2rem; }
}
