:root {
  --bg: #070b16; --panel: #0d1426; --line: #1c2742;
  --text: #e2e8f0; --muted: #64748b; --accent: #38bdf8;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: system-ui, -apple-system, sans-serif; }
body { display: flex; flex-direction: column; height: 100vh; }

header { display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 24px; border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #0c1326, #080d1a); }
header h1 { font-size: 19px; font-weight: 700; margin: 0; letter-spacing: .3px; line-height: 1.25; }
.headright { display: flex; align-items: center; gap: 14px; }
.status { font-size: 14px; color: var(--muted); white-space: nowrap; }
.status.live { color: #34d399; }
.status.disconnected, .status.error { color: #f87171; }
.iconbtn { background: #1e293b; color: var(--text); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 12px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap; }
.iconbtn:hover { background: #273549; }

main { flex: 1; display: flex; min-height: 0; }
#plot { flex: 1; position: relative; background: #0a1020; overflow: hidden; cursor: grab; }
#plot:active { cursor: grabbing; }
#view { position: absolute; inset: 0; transform-origin: 0 0; }
#view canvas, #view svg { position: absolute; inset: 0; width: 100%; height: 100%; }

#legend { position: absolute; top: 16px; right: 16px; display: flex; flex-direction: column;
  align-items: center; gap: 6px; font-size: 13px; color: var(--muted);
  background: rgba(8,13,26,.78); padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); }
#legend .ltitle { font-weight: 700; color: var(--text); letter-spacing: .5px; font-size: 14px; }
#legend .bar { width: 18px; height: 180px; border-radius: 4px;
  background: linear-gradient(to top, rgb(10,12,40), rgb(170,30,120), rgb(250,200,60)); }
#hint { position: absolute; left: 14px; bottom: 12px; font-size: 11px; color: var(--muted);
  background: rgba(8,13,26,.6); padding: 4px 8px; border-radius: 6px; pointer-events: none; }

#panel { width: 280px; border-left: 1px solid var(--line); padding: 16px;
  background: var(--panel); display: flex; flex-direction: column; gap: 18px; }
#readout { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--text);
  background: #0a1020; border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
#calib { display: flex; flex-direction: column; gap: 10px; }
#calib h2 { font-size: 13px; color: var(--muted); margin: 0; text-transform: uppercase; letter-spacing: .5px; }
#thresh { display: flex; flex-direction: column; gap: 8px; }
#thresh h2 { font-size: 13px; color: var(--muted); margin: 0; text-transform: uppercase; letter-spacing: .5px; }
#thresh-slider { width: 100%; accent-color: var(--accent); cursor: pointer; }
#thresh-val { font-size: 12.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
button { background: var(--accent); color: #001018; border: 0; border-radius: 8px;
  padding: 10px 14px; font-size: 14px; font-weight: 600; cursor: pointer; }
button:disabled { opacity: .5; cursor: default; }
#calib-cancel, #pipe-restart { background: #334155; color: var(--text); }
#calib-msg { font-size: 13px; color: var(--muted); min-height: 18px; }

/* Info-Overlay (Erklaerung fuer Laien + technisch Interessierte) */
#info { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(4,7,14,.72); z-index: 10; padding: 24px; }
#info[hidden] { display: none; }
#info .card { width: min(840px, 100%); max-height: 92vh; overflow: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 28px 34px; line-height: 1.6; }
#info .card a { color: var(--accent); }
#info .card code { background: #0a1020; border: 1px solid var(--line); border-radius: 4px;
  padding: 1px 5px; font-size: 13px; }
#info .card h2 { margin: 0 0 6px; font-size: 20px; }
#info .card h3 { margin: 18px 0 4px; font-size: 13px; color: var(--accent);
  text-transform: uppercase; letter-spacing: .5px; }
#info .card p { margin: 6px 0; color: #cbd5e1; font-size: 14px; }
#info-close { margin-top: 18px; }

/* Historischer View — teilt sich das Overlay-/Card-Muster mit #info */
#history { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(4,7,14,.72); z-index: 10; padding: 24px; }
#history[hidden] { display: none; }
#history .card { width: min(900px, 100%); max-height: 92vh; overflow: auto; background: var(--panel);
  border: 1px solid var(--line); border-radius: 14px; padding: 28px 34px; line-height: 1.6; }
#history .card h2 { margin: 0 0 6px; font-size: 20px; }
#history .card h3 { margin: 22px 0 6px; font-size: 13px; color: var(--accent);
  text-transform: uppercase; letter-spacing: .5px; }
#history .card p { margin: 6px 0; color: #cbd5e1; font-size: 14px; }
#history canvas { width: 100%; display: block; background: #0a1020;
  border: 1px solid var(--line); border-radius: 8px; margin-top: 6px; }
.hist-ctl { display: flex; align-items: center; gap: 10px; margin: 4px 0 2px; }
.hist-ctl label { font-size: 12.5px; color: var(--muted); }
.hist-ctl select, .hist-ctl input[type="datetime-local"] { background: #0a1020; color: var(--text);
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 8px; font-size: 13px;
  font-family: inherit; color-scheme: dark; }
.hist-ctl { flex-wrap: wrap; }
.hist-ctl .iconbtn { padding: 4px 10px; font-size: 12.5px; }
.hist-tz { font-size: 12px; color: var(--muted); }
.hist-msg { font-size: 12.5px; color: var(--muted); margin-top: 6px;
  font-variant-numeric: tabular-nums; }
.hist-ref { font-size: 12px; color: var(--muted); margin-top: 10px; }

/* Zeitraum-Leiste: gilt fuer alle Tabs -> bleibt beim Scrollen stehen. */
.hist-bar { position: sticky; top: 0; z-index: 2; background: var(--panel);
  padding: 8px 0 10px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.hist-sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }

/* Kennzahlen-Kacheln */
.hist-tiles { display: grid; gap: 10px; margin-bottom: 16px;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.hist-tile { background: #0a1020; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; }
.hist-tile .k { font-size: 11px; color: var(--muted); text-transform: uppercase;
  letter-spacing: .4px; }
.hist-tile .v { font-size: 20px; font-weight: 600; font-variant-numeric: tabular-nums;
  margin-top: 2px; }
.hist-tile .s { font-size: 11.5px; color: var(--muted); }

/* Tabs statt Endlos-Scrollen */
.hist-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.hist-tab { background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); font: inherit; font-size: 13.5px; font-weight: 600;
  padding: 8px 14px; cursor: pointer; }
.hist-tab:hover { color: var(--text); }
.hist-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.hist-panel { display: none; }
.hist-panel.is-active { display: block; }

/* Kartenansicht: Canvas + SVG-Overlay uebereinander, wie im Live-View */
.hist-view { position: relative; width: 100%; background: #0a1020;
  border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.hist-view canvas, .hist-view svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.hist-view { aspect-ratio: var(--hist-aspect, 16 / 9); cursor: grab; }
.hist-view:active { cursor: grabbing; }
/* Zoom-Ebene: wird per CSS-transform verschoben/skaliert, wie im Live-View. */
.hist-zoom { position: absolute; inset: 0; transform-origin: 0 0; }
.hist-hint { position: absolute; left: 8px; bottom: 6px; font-size: 11px;
  color: var(--muted); background: rgba(4,7,14,.6); padding: 2px 6px; border-radius: 4px;
  pointer-events: none; }
#hist-scrub { flex: 1; accent-color: var(--accent); cursor: pointer; min-width: 120px; }

/* Fresnel-Zonen-Schema im Info-Overlay */
.fresnel-fig { margin: 12px 0 4px; padding: 0; }
.fresnel-fig svg { width: 100%; height: auto; max-height: 240px;
  background: #f1f5f9; border: 1px solid var(--line); border-radius: 10px; }
.fresnel-fig figcaption { margin-top: 8px; font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.fl-zone   { fill: rgba(14,116,144,.14); stroke: #0e7490; stroke-width: 1.5; stroke-dasharray: 5 4; }
.fl-path   { stroke: #334155; stroke-width: 2; }
.fl-virt   { stroke: #64748b; stroke-width: 1.5; stroke-dasharray: 3 4; }
.fl-wall   { stroke: #1e293b; stroke-width: 4; }
.fl-anchor { fill: #d97706; stroke: #1e293b; stroke-width: 1; }
.fl-anchor-virt { fill: #fef3c7; stroke: #d97706; stroke-width: 1.5; stroke-dasharray: 2 2; }
.fl-refl   { fill: #0e7490; }
.fl-person { fill: #dc2626; stroke: #1e293b; stroke-width: 1.5; }
.fl-cap    { fill: #0f172a; font-size: 13px; font-weight: 600; }
.fl-lbl    { fill: #475569; font-size: 11px; }
