/* ID-Radar — Leitstand bei Nachtschicht.
   Tiefes Petrol-Navy, Bernstein als Signalfarbe, Koralle = short (unterspeist),
   Teal = long (überspeist). Zahlen in Mono, Labels in Space Grotesk. */

:root {
  --bg: #0b1322;
  --panel: #111c31;
  --panel-2: #0e1728;
  --line: #22304d;
  --text: #eaf0fb;
  --muted: #8fa0bc;
  --amber: #f5b63f;
  --short: #ff7a59;   /* NRV-Saldo positiv = unterspeist = System short */
  --long: #3fd0a4;    /* NRV-Saldo negativ = überspeist  = System long  */
  --wind: #6fa8ff;
  --radius: 14px;
  --font-label: "Space Grotesk", system-ui, sans-serif;
  --font-data: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background:
    radial-gradient(1200px 500px at 80% -10%, #14223d 0%, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: var(--font-label);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* --- Topbar ---------------------------------------------------------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  /* safe-area: im PWA-Vollbild (iPhone) nicht unter Uhrzeit/Batterie rutschen */
  padding: calc(14px + env(safe-area-inset-top, 0px))
           calc(16px + env(safe-area-inset-right, 0px)) 10px
           calc(16px + env(safe-area-inset-left, 0px));
  position: sticky; top: 0; z-index: 5;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { font-size: 1.05rem; font-weight: 600; letter-spacing: .04em; margin: 0; }
.brand-sub { color: var(--muted); font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.live-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--long); align-self: center;
  box-shadow: 0 0 0 0 rgba(63, 208, 164, .5);
  animation: pulse 2.4s infinite;
}
.live-dot.err { background: var(--short); animation: none; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(63,208,164,.45); }
  70% { box-shadow: 0 0 0 8px rgba(63,208,164,0); }
  100% { box-shadow: 0 0 0 0 rgba(63,208,164,0); }
}
.topbar-right { display: flex; align-items: center; gap: 10px; }
.stamp { font-family: var(--font-data); font-size: .72rem; color: var(--muted); }
.btn {
  font-family: var(--font-label); font-size: .8rem; font-weight: 500;
  color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 9px;
  padding: 7px 12px; cursor: pointer;
}
.btn:hover { border-color: var(--amber); }
.btn:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

/* --- Grid & Cards ----------------------------------------------------- */
.grid {
  display: grid; gap: 14px;
  grid-template-columns: 1fr;
  padding: 14px 14px 8px;
  max-width: 1080px; width: 100%; margin: 0 auto;
  flex: 1;
}
@media (min-width: 900px) {
  .grid { grid-template-columns: 1fr 1fr; }
  .card-wide { grid-column: 1 / -1; }
}
.card {
  background: linear-gradient(180deg, var(--panel) 0%, var(--panel-2) 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 16px;
}
.eyebrow {
  font-size: .68rem; font-weight: 600; letter-spacing: .14em;
  text-transform: uppercase; color: var(--muted);
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px;
}
.pill {
  font-family: var(--font-data); font-size: .68rem; letter-spacing: 0;
  text-transform: none; color: var(--amber);
  border: 1px solid color-mix(in srgb, var(--amber) 45%, transparent);
  border-radius: 999px; padding: 2px 9px;
}

/* --- Zahlen ----------------------------------------------------------- */
.big-num { font-family: var(--font-data); font-size: 2.4rem; font-weight: 600; line-height: 1.05; font-variant-numeric: tabular-nums; }
.mid-num { font-family: var(--font-data); font-size: 1.25rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.mid-num.small { font-size: 1rem; }
.unit { font-size: .55em; color: var(--muted); font-weight: 400; }
.sub { color: var(--muted); font-size: .74rem; margin-top: 2px; }
.pos { color: var(--short); }
.neg { color: var(--long); }

.kpi-row { display: flex; gap: 18px; flex-wrap: wrap; margin-bottom: 10px; }
.kpi { min-width: 90px; }

/* --- Signatur: Saldo-Band --------------------------------------------- */
.saldo-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.aep-box { text-align: right; }
.saldo-band {
  display: flex; align-items: center; gap: 10px;
  margin: 16px 0 6px;
}
.band-side { font-size: .6rem; letter-spacing: .12em; color: var(--muted); white-space: nowrap; }
.band-rail {
  position: relative; flex: 1; height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg,
    color-mix(in srgb, var(--long) 35%, transparent) 0%,
    var(--panel-2) 46%, var(--panel-2) 54%,
    color-mix(in srgb, var(--short) 35%, transparent) 100%);
  border: 1px solid var(--line);
}
.band-zero {
  position: absolute; left: 50%; top: -4px; bottom: -4px; width: 1px;
  background: var(--muted); opacity: .6;
}
.band-needle {
  position: absolute; top: -5px; bottom: -5px; width: 4px; left: 50%;
  border-radius: 2px; background: var(--text);
  box-shadow: 0 0 10px rgba(245, 182, 63, .0);
  transition: left .6s ease, background .3s ease, box-shadow .3s ease;
}
.band-needle.pos { background: var(--short); box-shadow: 0 0 12px color-mix(in srgb, var(--short) 60%, transparent); }
.band-needle.neg { background: var(--long); box-shadow: 0 0 12px color-mix(in srgb, var(--long) 60%, transparent); }

.spark-row { margin-top: 12px; }
.spark-label { text-align: right; }
/* Saldo-Verlauf steht auf der breiten Kachel — mehr Höhe gegen die Stauchung. */
.spark-row .chart-wrap.spark { height: 100px; }
@media (min-width: 900px) { .spark-row .chart-wrap.spark { height: 140px; } }

/* Chart.js braucht einen Container mit fester Höhe, sonst bleibt die
   Zeichenfläche unsichtbar (responsive:true + kein Höhen-Anker = leer). */
.chart-wrap { position: relative; width: 100%; }
.chart-wrap.spark { height: 52px; }
.chart-wrap.tall { height: 190px; }
/* Auf breiten Bildschirmen sind die Karten deutlich breiter — mehr Höhe,
   damit die Kurve nicht flachgedrückt wirkt. */
@media (min-width: 900px) {
  .chart-wrap.tall { height: 300px; }
}
/* AEP-Schätzer-Sparkline in der Systempuls-Kachel (rechtsbündig, kompakt). */
.chart-wrap.aep-spark { height: 44px; width: min(210px, 46vw); margin: 6px 0 0 auto; }

/* Minütlicher NRV-Saldo: feine Lavendel-Linie, klar von den Balken abgesetzt. */
.minute-row { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--line); }
.minute-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.minute-title { color: #b296ff; }
.minute-now { font-family: var(--font-data); white-space: nowrap; }
.minute-now #saldoMinVal { font-size: 1.05rem; font-weight: 600; }
.minute-now #saldoMinVal.pos { color: var(--short); }
.minute-now #saldoMinVal.neg { color: var(--long); }
.minute-now .sub { margin-left: 4px; }
.minute-live {
  margin-left: 6px; font-size: .62rem; letter-spacing: .02em;
  color: #b296ff; vertical-align: middle;
}
.spark-row.minute-row .chart-wrap.spark.minute-spark { height: 72px; }
@media (min-width: 900px) { .spark-row.minute-row .chart-wrap.spark.minute-spark { height: 92px; } }

/* --- NRV-Ampel-Badge --------------------------------------------------- */
.ampel-badge {
  display: inline-flex; align-items: center; gap: 6px;
  text-transform: none; letter-spacing: 0; font-weight: 500;
  font-size: .72rem; color: var(--text);
}
/* Wichtig: sonst überschreibt display:inline-flex das hidden-Attribut. */
.ampel-badge[hidden] { display: none; }
.ampel-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.ampel-dot.gruen { background: var(--long);  box-shadow: 0 0 8px color-mix(in srgb, var(--long) 65%, transparent); }
.ampel-dot.gelb  { background: var(--amber); box-shadow: 0 0 8px color-mix(in srgb, var(--amber) 65%, transparent); }
.ampel-dot.rot   { background: var(--short); box-shadow: 0 0 8px color-mix(in srgb, var(--short) 65%, transparent); }

/* --- Ausfall-Liste ----------------------------------------------------- */
.outage-list { list-style: none; margin: 0; padding: 0; }
.outage-list li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
  font-size: .82rem;
}
.outage-list li:last-child { border-bottom: none; }
.outage-name { font-weight: 500; }
.outage-meta { color: var(--muted); font-size: .72rem; margin-top: 2px; }
.outage-mw { font-family: var(--font-data); color: var(--amber); white-space: nowrap; }
.outage-tag {
  font-size: .62rem; letter-spacing: .08em; text-transform: uppercase;
  border-radius: 4px; padding: 1px 6px; margin-left: 8px;
  border: 1px solid var(--line); color: var(--muted);
}
.outage-tag.forced { color: var(--short); border-color: color-mix(in srgb, var(--short) 50%, transparent); }

/* --- Hinweise / Zustände ----------------------------------------------- */
.module-note {
  margin-top: 10px; padding: 10px 12px;
  background: color-mix(in srgb, var(--amber) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--amber) 30%, transparent);
  border-radius: 10px; font-size: .78rem; color: var(--text);
}
.module-note code { font-family: var(--font-data); font-size: .72rem; color: var(--amber); }
.source-note { margin-top: 8px; }

.foot {
  text-align: center; color: var(--muted); font-size: .68rem;
  padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
}

/* --- Login -------------------------------------------------------------- */
.login-body { align-items: center; justify-content: center; }
.login-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 26px; width: min(340px, 90vw); display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 1.2rem; letter-spacing: .04em; }
.login-card input {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px;
  color: var(--text); padding: 10px 12px; font-family: var(--font-data);
}
.login-card input:focus-visible { outline: 2px solid var(--amber); }
.btn-full { width: 100%; padding: 10px; }
.login-error { color: var(--short); font-size: .8rem; margin: 0; }

/* --- Lage-Header --------------------------------------------------------- */
.card-lage { padding: 14px 16px; }
.lage-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.lage-score { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.score-ring {
  width: 62px; height: 62px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-data); font-size: 1.35rem; font-weight: 600;
  border: 3px solid var(--line); color: var(--text);
  background: var(--panel-2);
}
.score-ring.ok   { border-color: var(--long);  box-shadow: 0 0 14px color-mix(in srgb, var(--long) 35%, transparent); }
.score-ring.warn { border-color: var(--amber); box-shadow: 0 0 14px color-mix(in srgb, var(--amber) 35%, transparent); }
.score-ring.crit { border-color: var(--short); box-shadow: 0 0 14px color-mix(in srgb, var(--short) 45%, transparent); }
.score-label { font-size: .66rem; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.lage-text-wrap { flex: 1; min-width: 220px; }
.lage-text { font-size: .95rem; line-height: 1.45; }
.lage-chips { margin-top: 6px; }
.lage-clock { display: flex; flex-direction: column; gap: 6px; min-width: 150px; }
.clock-item { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.clock-label { font-size: .66rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); white-space: nowrap; }
.clock-val { font-family: var(--font-data); font-size: 1.05rem; font-weight: 600; color: var(--amber); }
.clock-val.small { font-size: .85rem; color: var(--text); }
.clock-item.gc .clock-val { color: var(--amber); }

/* --- Chips ---------------------------------------------------------------- */
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chips-right { justify-content: flex-end; }
.chip {
  font-family: var(--font-data); font-size: .68rem;
  color: var(--muted); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 9px; white-space: nowrap;
}
.chip-warn  { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 45%, transparent); }
.chip-short { color: var(--short); border-color: color-mix(in srgb, var(--short) 45%, transparent); }
.chip-long  { color: var(--long);  border-color: color-mix(in srgb, var(--long) 45%, transparent); }

/* --- Frequenz-Box im Systempuls ------------------------------------------- */
.freq-box { text-align: right; }
.chart-wrap.freq-spark { height: 44px; width: min(190px, 42vw); margin: 6px 0 0 auto; }

/* --- Preise + Nachbarn ----------------------------------------------------- */
.price-flex { display: flex; gap: 20px; flex-wrap: wrap; }
.price-main { flex: 2 1 340px; min-width: 0; }
.price-neighbors { flex: 1 1 170px; min-width: 160px; }
.board-title { letter-spacing: .08em; text-transform: uppercase; font-size: .64rem; margin-bottom: 8px; }
.neighbor-list { list-style: none; margin: 0; padding: 0; }
.neighbor-list li {
  display: flex; align-items: baseline; gap: 8px;
  padding: 5px 0; border-bottom: 1px solid var(--line);
  font-size: .8rem;
}
.neighbor-list li:last-child { border-bottom: none; }
.nb-zone { font-weight: 600; width: 42px; letter-spacing: .04em; }
.nb-price { font-family: var(--font-data); margin-left: auto; }
.nb-spread { font-family: var(--font-data); width: 52px; text-align: right; color: var(--muted); font-size: .74rem; }
.nb-spread.nb-higher { color: var(--amber); }
.nb-spread.nb-lower  { color: var(--wind); }

/* --- EPEX Intraday Continuous ---------------------------------------------- */
.epex-flex { display: flex; gap: 20px; flex-wrap: wrap; align-items: flex-start; }
.epex-current { flex: 1 1 220px; min-width: 190px; }
.epex-mini-row { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 10px; }
.epex-charts { flex: 3 1 440px; min-width: 260px; }
.epex-spark-cell { min-width: 0; }
.epex-spark-cell .spark-caption { text-align: left; color: var(--muted); }
.chart-wrap.epex-spark { height: 66px; }
@media (min-width: 900px) { .chart-wrap.epex-spark { height: 78px; } }
/* Ein großer kombinierter EPEX-Tagesverlauf statt vier Einzel-Sparklines. */
.chart-wrap.epex-combined { height: 240px; }
@media (min-width: 900px) { .chart-wrap.epex-combined { height: 320px; } }

/* --- Segmented-Filter (z. B. Ausfall-Ticker: Alle/Ungeplant/Geplant) -------- */
.seg { display: inline-flex; gap: 0; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg-btn {
  font-family: var(--font-label); font-size: .74rem; font-weight: 500;
  color: var(--muted); background: var(--panel-2);
  border: none; border-right: 1px solid var(--line);
  padding: 8px 14px; min-height: 36px; cursor: pointer;
  touch-action: manipulation; /* verhindert Doppeltipp-Zoom auf iOS */
}
.seg-btn:last-child { border-right: none; }
.seg-btn.active { color: var(--text); background: var(--panel); box-shadow: inset 0 -2px 0 var(--amber); }
.seg-btn:focus-visible { outline: 2px solid var(--amber); outline-offset: -2px; }

/* --- Flex-Stack (konventionell) -------------------------------------------- */
.conv-list { list-style: none; margin: 0; padding: 0; }
.conv-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 0; font-size: .78rem;
}
.conv-name { width: 108px; color: var(--muted); }
.conv-rail { flex: 1; height: 9px; background: var(--panel-2); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.conv-bar { height: 100%; background: color-mix(in srgb, var(--amber) 60%, transparent); border-radius: 999px; }
.conv-mw { font-family: var(--font-data); width: 76px; text-align: right; }
.conv-delta { font-family: var(--font-data); width: 48px; text-align: right; font-size: .7rem; color: var(--muted); }

/* --- Legenden-Farbtupfer & Beschriftungs-Helfer ------------------------------ */
.lg-short { color: var(--short); }
.lg-long  { color: var(--long); }
.band-scale { font-size: .58rem; letter-spacing: 0; color: var(--muted); opacity: .8; text-transform: none; }
.band-side { text-align: center; line-height: 1.5; }
.spark-caption { text-align: right; font-size: .62rem; margin-top: 2px; }
[title] { cursor: help; }
.btn[title], a[title] { cursor: pointer; }

/* --- Trends ----------------------------------------------------------------- */
.trend { font-family: var(--font-data); font-size: .68rem; color: var(--muted); }
.t-up   { color: var(--short); }
.t-down { color: var(--long); }

/* --- Mobile-Feinschliff (Handy hochkant) ------------------------------------- */
@media (max-width: 600px) {
  .lage-row { gap: 12px; }
  .lage-clock { flex-direction: row; min-width: 0; width: 100%; justify-content: space-between; }
  .big-num { font-size: 2rem; }

  /* Dichter packen: mehr Inhalt pro Bildschirm, weniger Scrollen */
  .grid { padding: 10px 10px 6px; gap: 10px; }
  .card { padding: 12px 12px 14px; }
  .kpi-row { gap: 12px 16px; }
  .topbar {
    padding: calc(10px + env(safe-area-inset-top, 0px))
             calc(12px + env(safe-area-inset-right, 0px)) 8px
             calc(12px + env(safe-area-inset-left, 0px));
  }
  .brand-sub { display: none; } /* Platz für Stempel + Button */

  /* Charts: hoch genug zum Ablesen, aber keine halbe Bildschirmseite */
  .chart-wrap.tall { height: 180px; }
  .chart-wrap.epex-combined { height: 220px; }
  .spark-row .chart-wrap.spark { height: 84px; }

  /* Systempuls: Frequenz/AEP-Boxen linksbündig untereinander statt gequetscht */
  .saldo-head { flex-direction: column; gap: 12px; }
  .freq-box, .aep-box { text-align: left; }
  .chart-wrap.freq-spark, .chart-wrap.aep-spark { margin: 6px auto 0 0; width: min(240px, 78vw); }
  .chips-right { justify-content: flex-start; }

  /* Listen: Umbruch statt Abschneiden */
  .outage-list li { flex-wrap: wrap; }
  .outage-mw { margin-left: auto; }
  .conv-name { width: 92px; }

  /* Fingerfreundliche Ziele (min. ~40 px) */
  .btn { padding: 9px 14px; min-height: 40px; }
  .seg-btn { padding: 9px 12px; min-height: 40px; flex: 1; }
  .seg { display: flex; width: 100%; }
}

/* Tooltips: auf Touch-Geräten kein Hilfe-Cursor-Gimmick */
@media (hover: none) {
  [title] { cursor: default; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
