/* Leitstand — glass panels over a deep field; colour is reserved for state (ok / warning / fault / maintenance). */
@font-face { font-family: "Geist"; src: url("fonts/geist-latin.woff2") format("woff2"); font-weight: 100 900; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("fonts/jetbrains-mono-latin.woff2") format("woff2"); font-weight: 100 800; font-display: swap; }

:root {
  --font: "Geist", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Consolas, monospace;
  --radius: 18px;
}
html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B1220;
  --glow-a: rgba(56, 189, 248, .20);
  --glow-b: rgba(99, 102, 241, .22);
  --panel: rgba(255, 255, 255, .06);
  --panel-solid: #141C2E;
  --stroke: rgba(255, 255, 255, .13);
  --text: #E8EEF8;
  --muted: #9FB0C8;
  --accent: #5CC8F0;
  --ok: #34D399; --warn: #FBBF24; --fault: #F87171; --maint: #A78BFA;
  --ok-t: #6EE7B7; --warn-t: #FCD34D; --fault-t: #FCA5A5; --maint-t: #C4B5FD;
  --shadow: 0 24px 48px -28px rgba(0, 0, 0, .8);
}
html[data-theme="light"] {
  color-scheme: light;
  --bg: #EEF2F8;
  --glow-a: rgba(14, 165, 233, .20);
  --glow-b: rgba(99, 102, 241, .16);
  --panel: rgba(255, 255, 255, .68);
  --panel-solid: #FFFFFF;
  --stroke: rgba(15, 23, 42, .14);
  --text: #0F172A;
  --muted: #475569;
  --accent: #0369A1;
  --ok: #059669; --warn: #D97706; --fault: #DC2626; --maint: #7C3AED;
  --ok-t: #065F46; --warn-t: #92400E; --fault-t: #991B1B; --maint-t: #5B21B6;
  --shadow: 0 24px 48px -30px rgba(15, 23, 42, .35);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 1rem; -webkit-text-size-adjust: 100%; }
body { margin: 0; min-height: 100dvh; background: radial-gradient(60rem 40rem at 85% -10%, var(--glow-a), transparent 60%), radial-gradient(50rem 40rem at -10% 60%, var(--glow-b), transparent 60%), var(--bg); background-attachment: fixed; color: var(--text); font: 400 .9688rem/1.5 var(--font); }
h1, h2, p, ul, dl, dd { margin: 0; padding: 0; }
ul { list-style: none; }
a { color: inherit; text-underline-offset: .2em; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 8px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: .5rem; z-index: 30; padding: .6rem 1rem; background: var(--panel-solid); border: 1px solid var(--stroke); border-radius: 10px; }
.skip:focus { left: .5rem; }

/* Glass surface. Without backdrop-filter support the panel falls back to an opaque fill. */
.panel, .side, .tip, dialog { background: var(--panel-solid); border: 1px solid var(--stroke); box-shadow: var(--shadow); }
@supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .panel, .side, .tip { background: var(--panel); -webkit-backdrop-filter: blur(18px) saturate(140%); backdrop-filter: blur(18px) saturate(140%); }
}

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 15.5rem minmax(0, 1fr); gap: 1.25rem; max-width: 1500px; margin-inline: auto; padding: 1.25rem; }
.side { position: sticky; top: 1.25rem; align-self: start; display: grid; grid-template-rows: auto 1fr auto; gap: 1.5rem; height: calc(100dvh - 2.5rem); padding: 1.25rem 1rem; border-radius: var(--radius); }
.brand { display: flex; align-items: center; gap: .7rem; color: var(--accent); text-decoration: none; }
.brand span { color: var(--text); font-weight: 700; font-size: 1.0625rem; line-height: 1.2; }
.brand small { display: block; font-weight: 400; font-size: .8125rem; color: var(--muted); }
.side nav { display: grid; align-content: start; gap: .25rem; }
.side nav a { display: flex; align-items: center; justify-content: space-between; padding: .6rem .8rem; border-radius: 10px; font-weight: 500; text-decoration: none; color: var(--muted); }
.side nav a:hover { background: var(--panel); color: var(--text); }
.side nav a[aria-current="true"] { background: var(--panel); color: var(--text); box-shadow: inset 0 0 0 1px var(--stroke); }
.badge { min-width: 1.5rem; padding: .05rem .4rem; border-radius: 999px; background: var(--fault); color: #fff; font: 700 .75rem/1.4 var(--mono); text-align: center; }
html[data-theme="dark"] .badge { color: #1F0A0A; }
.side-note { font-size: .8125rem; color: var(--muted); }

.main { display: grid; gap: 1.25rem; min-width: 0; }
.main main { display: grid; gap: 1.25rem; min-width: 0; }
.bar { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 1rem 2rem; padding: .4rem .25rem 0; }
h1 { font-size: 1.9rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.stamp { margin-top: .2rem; color: var(--muted); font-size: .875rem; }
.stamp time { font-family: var(--mono); color: var(--text); }
.live { display: inline-flex; align-items: center; gap: .35rem; margin-left: .5rem; color: var(--ok-t); font-weight: 600; }
.live::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: var(--ok); animation: pulse 2s ease-in-out infinite; }
.live.is-paused { color: var(--warn-t); }
.live.is-paused::before { background: var(--warn); animation: none; }
@keyframes pulse { 50% { opacity: .35; } }
.bar-tools { display: flex; flex-wrap: wrap; align-items: center; gap: .6rem; }
.seg { display: inline-flex; padding: .2rem; border: 1px solid var(--stroke); border-radius: 12px; background: var(--panel); }
.seg button { min-height: 2.25rem; padding: .25rem .8rem; border: 0; border-radius: 9px; background: none; color: var(--muted); font-weight: 500; cursor: pointer; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--panel-solid); color: var(--text); box-shadow: 0 0 0 1px var(--stroke); }
.tool { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; min-height: 2.65rem; min-width: 2.65rem; padding: .25rem .8rem; border: 1px solid var(--stroke); border-radius: 12px; background: var(--panel); font-weight: 500; cursor: pointer; }
.tool:hover { border-color: var(--accent); }
.tool[aria-pressed="true"] { border-color: var(--warn); color: var(--warn-t); }

/* ---------- panels ---------- */
.panel { padding: 1.15rem 1.25rem 1.25rem; border-radius: var(--radius); min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem 1.5rem; margin-bottom: 1rem; }
h2 { font-size: 1.0625rem; font-weight: 600; }
.hint { font-size: .8438rem; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1.25rem; }
/* Rows: label, value, note, then the sparkline or meter pinned to the bottom so all four cards line up. */
.kpi { display: grid; grid-template-rows: auto auto 1fr auto; gap: .25rem; }
.kpi h2 { font-size: .875rem; font-weight: 500; color: var(--muted); }
.value { font: 600 2.35rem/1.1 var(--mono); letter-spacing: -.04em; font-variant-numeric: tabular-nums; }
.value small { font: 500 1rem var(--font); letter-spacing: 0; color: var(--muted); }
.sub { display: flex; align-items: center; gap: .35rem; min-height: 1.4rem; font-size: .8438rem; color: var(--muted); }
.compass { color: var(--accent); flex: none; }
.spark { width: 100%; height: 2.2rem; margin-top: .5rem; overflow: visible; align-self: end; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.6; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.meter { height: .5rem; margin-top: 1.35rem; border-radius: 999px; background: var(--stroke); overflow: hidden; align-self: end; }
.meter span { display: block; height: 100%; border-radius: inherit; background: var(--accent); transition: width .4s; }

/* ---------- chart ---------- */
.legend { display: flex; gap: 1.2rem; font-size: .8438rem; color: var(--muted); }
.legend li { display: flex; align-items: center; gap: .45rem; }
.legend i { width: 1.4rem; height: 0; border-top: 3px solid var(--accent); }
.legend .l-forecast { border-top: 2px dashed var(--muted); }
.chart-scroll { overflow-x: auto; overflow-y: hidden; }
.chart-box { position: relative; }
#chart { display: block; width: 100%; height: auto; touch-action: pan-x pan-y; cursor: crosshair; border-radius: 10px; }
.grid line { stroke: var(--stroke); stroke-width: 1; }
.grid text { fill: var(--muted); font: 500 12px var(--mono); }
.area { fill: var(--accent); opacity: .16; }
.actual { fill: none; stroke: var(--accent); stroke-width: 2.4; stroke-linejoin: round; }
.forecast { fill: none; stroke: var(--muted); stroke-width: 1.6; stroke-dasharray: 6 5; }
.cursor { stroke: var(--text); stroke-width: 1; opacity: .55; }
.cursor-dot { fill: var(--bg); stroke: var(--accent); stroke-width: 3; }
.tip { position: absolute; z-index: 2; display: grid; gap: .1rem; padding: .55rem .75rem; border-radius: 12px; font-size: .8438rem; white-space: nowrap; pointer-events: none; transform: translate(14px, -50%); }
.tip.flip { transform: translate(calc(-100% - 14px), -50%); }
.tip b { font-weight: 600; }
.tip span { font-family: var(--mono); color: var(--muted); }

/* ---------- fleet ---------- */
.filters { display: flex; flex-wrap: wrap; gap: .6rem; }
.filters input, .filters select { min-height: 2.65rem; padding: .3rem .8rem; border: 1px solid var(--stroke); border-radius: 12px; background: var(--panel); }
.filters input { width: 12rem; }
.filters input::placeholder { color: var(--muted); opacity: 1; }
.filters select option { background: var(--panel-solid); color: var(--text); }
.filters input:hover, .filters select:hover { border-color: var(--accent); }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.2rem, 1fr)); gap: .75rem; margin-bottom: 1.25rem; }
.tile { position: relative; display: grid; grid-template-columns: auto 1fr; gap: .1rem .7rem; align-items: center; width: 100%; padding: .75rem .8rem; border: 1px solid var(--stroke); border-radius: 14px; background: var(--panel); text-align: left; cursor: pointer; overflow: hidden; }
.tile::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--state); }
.tile:hover { border-color: var(--accent); }
.tile .rotor { grid-row: 1 / span 3; fill: var(--state); }
.tile-id { font-weight: 600; }
.tile strong { font: 600 1rem var(--mono); font-variant-numeric: tabular-nums; }
.tile-state { font-size: .8125rem; color: var(--state-t); }
.is-ok { --state: var(--ok); --state-t: var(--ok-t); }
.is-warn { --state: var(--warn); --state-t: var(--warn-t); }
.is-fault { --state: var(--fault); --state-t: var(--fault-t); }
.is-maint { --state: var(--maint); --state-t: var(--maint-t); }
.rotor { transform-origin: 50% 50%; animation: spin var(--spin, 0s) linear infinite; }
.rotor.is-still { animation: none; opacity: .7; }
@keyframes spin { to { transform: rotate(360deg); } }

.pill { display: inline-flex; align-items: center; gap: .4rem; padding: .1rem .6rem; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--state) 55%, transparent); background: color-mix(in srgb, var(--state) 14%, transparent); color: var(--state-t); font-size: .8125rem; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: .45rem; height: .45rem; border-radius: 50%; background: var(--state); }

.table-wrap { overflow-x: auto; border: 1px solid var(--stroke); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; min-width: 38rem; }
th, td { padding: .6rem .9rem; text-align: left; border-bottom: 1px solid var(--stroke); white-space: nowrap; }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel); }
thead th { padding: 0; font-weight: 500; color: var(--muted); background: var(--panel); }
thead button { display: flex; align-items: center; gap: .35rem; width: 100%; padding: .6rem .9rem; border: 0; background: none; color: inherit; font-weight: inherit; cursor: pointer; }
thead .num button { justify-content: flex-end; }
thead button:hover { color: var(--text); }
thead button::after { content: "↕"; opacity: .45; font-size: .8em; }
th[aria-sort="ascending"] button, th[aria-sort="descending"] button { color: var(--text); }
th[aria-sort="ascending"] button::after { content: "↑"; opacity: 1; color: var(--accent); }
th[aria-sort="descending"] button::after { content: "↓"; opacity: 1; color: var(--accent); }
tbody th { font-weight: 600; }
.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.rowlink { padding: 0; border: 0; background: none; font-weight: 600; text-decoration: underline; text-decoration-color: var(--stroke); text-underline-offset: .25em; cursor: pointer; }
.rowlink:hover { text-decoration-color: var(--accent); }
.empty { padding: 1.4rem; color: var(--muted); }

/* ---------- log ---------- */
.log { display: grid; }
.log li { display: grid; grid-template-columns: 6.2rem minmax(0, 1fr) auto; gap: .9rem 1.1rem; align-items: start; padding: .9rem 0; border-top: 1px solid var(--stroke); }
.log li:first-child { border-top: 0; padding-top: 0; }
.log li.is-acked { opacity: .72; }
.log .pill { justify-self: start; }
.log p { margin: .1rem 0 .2rem; }
.log time { font: 400 .8125rem var(--mono); color: var(--muted); }
.acked { font-size: .8125rem; color: var(--muted); white-space: nowrap; }

.foot { padding: .25rem .25rem 1rem; font-size: .8125rem; color: var(--muted); }

/* ---------- dialog ---------- */
dialog { width: min(30rem, calc(100vw - 2rem)); padding: 1.4rem; border-radius: var(--radius); color: var(--text); }
dialog::backdrop { background: rgba(4, 8, 16, .6); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.detail-head h2 { font-size: 1.5rem; font-weight: 700; }
.state { margin-top: .5rem; }
dialog dl { margin-top: 1.1rem; border-top: 1px solid var(--stroke); }
dialog dl div { display: flex; justify-content: space-between; gap: 1rem; padding: .55rem 0; border-bottom: 1px solid var(--stroke); }
dialog dt { color: var(--muted); }
dialog dd { font-family: var(--mono); font-variant-numeric: tabular-nums; text-align: right; }
dialog .hint { margin-top: 1rem; font-size: .9063rem; color: var(--text); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); padding: .75rem; gap: .75rem; }
  .side { position: static; height: auto; grid-template-rows: auto; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: .75rem 1rem; padding: .75rem .9rem; }
  .side nav { display: flex; gap: .25rem; overflow-x: auto; }
  .side nav a { white-space: nowrap; gap: .4rem; }
  .side-note { grid-column: 1 / -1; }
  .main, .main main, .kpis { gap: .75rem; }
}
@media (max-width: 560px) {
  /* At phone width the 960-unit chart would shrink its axis labels below legibility: keep it wide and let it scroll. */
  .chart-box { min-width: 36rem; }
  .kpis { grid-template-columns: minmax(0, 1fr); }
  .side { grid-template-columns: minmax(0, 1fr); }
  .bar-tools, .seg { width: 100%; }
  .seg button { flex: 1; padding-inline: .3rem; }
  .filters, .filters input, .filters select { width: 100%; }
  .log li { grid-template-columns: minmax(0, 1fr); gap: .4rem; }
  .value { font-size: 2rem; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .rotor, .live::before { animation: none; }
  .meter span { transition: none; }
}
