/* Wohnmobil — dunkel, aber nicht schwarz.
 *
 * Regeln, die diese Datei zusammenhalten. Wer eine bricht, bekommt das
 * Bunte zurück, das hier rausgeflogen ist:
 *
 * 1. EIN Akzent. Er zeigt den Zustand der Batterie und sonst nichts.
 *    Temperatur, Uhrzeit und Trend sind Text, keine Farben.
 * 2. EINE Flächenstufe. Karten heben sich durch Helligkeit ab, nicht
 *    zusätzlich durch Rahmen. Fläche + Rahmen + Radius gleichzeitig ist
 *    der Grund, warum Oberflächen billig aussehen.
 * 3. Farbe nur, wo sie etwas bedeutet. Am Balken sind das die beiden
 *    schlechten Enden; die Mitte bleibt neutral.
 * 4. Abstände aus einer Leiter: 4 / 8 / 12 / 18 / 26.
 * 5. Jede Fläche, die JavaScript später füllt, hat hier schon ihre
 *    endgültige Höhe. Sonst springt das Layout, sobald Daten eintreffen.
 *
 * Kein reines Schwarz: auf OLED wirkt #000 unter jeder Karte wie ein Loch
 * und Kanten flimmern beim Scrollen.
 */

:root {
  --bg: #0d0d0f;
  --card: #16161a;
  --card-2: #1f1f24;
  --line: rgba(255, 255, 255, 0.06);

  --text: #f2f2f4;
  --text-2: #9d9da6;
  --text-3: #6b6b74;

  --green: #5fcf87;           /* leicht entsättigt — Neon wirkt billig */
  --amber: #e0a83c;
  --red:   #e2645c;

  --accent: var(--green);
  --limit: var(--amber);

  --r: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* Zustand -> Akzent. JavaScript setzt nur das Attribut, nie eine Farbe. */
html[data-status="low"]     { --accent: var(--red); }
html[data-status="near"]    { --accent: var(--amber); }
html[data-status="high"]    { --accent: var(--amber); }
html[data-status="offline"] { --accent: var(--text-3); }
html[data-status="unknown"] { --accent: var(--text-3); }

* { box-sizing: border-box; }

html {
  background: var(--bg);        /* auch hinter dem Overscroll-Bereich */
  color-scheme: dark;
}
html, body {
  margin: 0;
  min-height: 100%;
  color: var(--text);
  font: 400 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text",
        system-ui, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }

/* Tastaturfokus bleibt sichtbar, Mausklicks bekommen keinen Ring. */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  margin: -1px; padding: 0; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 18px) 18px calc(var(--safe-b) + 26px);
}

/* ---------------------------------------------------------------- Kopfzeile */

header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 0 2px 18px; min-height: 34px;
}
h1 { margin: 0; font-size: 19px; font-weight: 600; letter-spacing: -0.02em; }

.icon-btn {
  display: grid; place-items: center;
  width: 34px; height: 34px; border-radius: 10px;
  color: var(--text-2);
  transition: background 160ms ease, color 160ms ease, transform 110ms ease;
}
.icon-btn svg { fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.icon-btn svg circle { fill: var(--bg); }
.icon-btn:active { background: var(--card-2); color: var(--text); transform: scale(0.94); }

.back { color: var(--text-2); text-decoration: none; font-size: 15px; }
.head-spacer { width: 56px; }        /* hält den Titel mittig */
.page-settings h1 { font-size: 17px; }

/* ------------------------------------------------------------------ Karten */

.card {
  background: var(--card);
  border-radius: var(--r);
  padding: 18px;
  margin-bottom: 12px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 26px; }
h2 { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: 0.02em; color: var(--text-2); }

/* -------------------------------------------------------------- Hauptwert */

.card-lead { padding: 24px 18px 0; }

.lead-num { margin: 0; text-align: center; white-space: nowrap; }
.lead-num span {
  font-size: clamp(46px, 15vw, 58px);
  font-weight: 600; line-height: 1;
  letter-spacing: -0.04em;              /* groß: eng */
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  transition: color 400ms ease;
}
/* Feste Größe, an die Ziffernoberkante gesetzt. Als em-Anteil auf der
   Grundlinie verschwindet das V unter den Ziffern. */
.lead-num i {
  font-style: normal; font-size: 17px; font-weight: 500;
  color: var(--text-3); margin-left: 4px; vertical-align: 0.9em;
}

/* min-height, damit die leere Zeile vor dem Laden schon Platz hat. */
.lead-state {
  margin: 6px 0 22px; min-height: 19px;
  text-align: center; font-size: 13px;
  letter-spacing: 0.02em; color: var(--text-2);
}

/* -------------------------------------------------------------- Balken */

/* aspect-ratio muss zu BAR in app.js passen — sie reserviert die
   Höhe, bevor das SVG Inhalt hat. */
#bar { display: block; width: 100%; height: auto; aspect-ratio: 300 / 34; overflow: visible; }
#bar #bar-track { fill: none; stroke: rgba(255,255,255,0.08); stroke-width: 6; stroke-linecap: round; }
/* Gedämpft: die Zonen sind Kontext, der Istwert steht davor. Bei voller
   Sättigung wirkt eine halbe Skala Rot wie ein Alarm, obwohl alles gut ist. */
#bar #bar-zone-low,
#bar #bar-zone-high { fill: none; stroke-width: 6; stroke-linecap: butt; opacity: 0.26; }
#bar #bar-zone-low  { stroke: var(--red); }
#bar #bar-zone-high { stroke: var(--amber); }
#bar #bar-zone-low[hidden],
#bar #bar-zone-high[hidden],
#bar #bar-limit[hidden],
#bar #bar-value[hidden] { display: none; }
/* Marke statt Füllung: eine Füllung würde die Zonen überdecken, und dann
   wäre die Farbe wieder umsonst. */
#bar #bar-limit { stroke: var(--limit); stroke-width: 2; stroke-linecap: round; }
#bar #bar-value {
  fill: var(--accent);
  stroke: var(--card); stroke-width: 2.5;
  transition: fill 400ms ease;
}

.scale-legend {
  display: flex; justify-content: space-between;
  margin: 6px 0 0; min-height: 16px;
  font-size: 11px; font-variant-numeric: tabular-nums;
  color: var(--text-3);
}
.scale-legend #scale-limit { color: var(--limit); }

/* Kein Kästchen pro Wert — drei Spalten, getrennt durch Haarlinien.
   Negative Ränder: die Linie läuft über die volle Kartenbreite. Endet sie
   im Innenabstand, sieht die Karte unfertig aus. */
.stats {
  display: grid; grid-template-columns: repeat(3, 1fr);
  margin: 22px -18px 0;
  border-top: 1px solid var(--line);
}
.stats > div { padding: 12px 0 14px; text-align: center; border-right: 1px solid var(--line); }
.stats > div:last-child { border-right: 0; }
.stats dt { font-size: 11px; letter-spacing: 0.04em; color: var(--text-3); }
.stats dd {
  margin: 3px 0 0;
  font-size: 18px; font-weight: 600;
  letter-spacing: -0.015em;
  font-variant-numeric: tabular-nums;
}
html[data-charge="charging"] .stats dd #charge { color: var(--green); }
.stats dd i { font-style: normal; font-size: 0.65em; font-weight: 500; color: var(--text-3); margin-left: 1px; }

/* ---------------------------------------------------------------- Diagramm */

.ranges { display: flex; gap: 1px; }
.ranges button {
  border: 0; background: none; padding: 4px 7px;
  font-size: 12px; color: var(--text-3); white-space: nowrap;
  border-radius: 7px; cursor: pointer;
  transition: color 160ms ease, background 160ms ease, transform 110ms ease;
}
.ranges button:active { transform: scale(0.92); }
.ranges button.on { background: var(--card-2); color: var(--text); }

.read {
  margin: 18px 0 4px; min-height: 26px;
  font-size: 13px; color: var(--text-3); font-variant-numeric: tabular-nums;
}
.read b {
  font-size: 21px; font-weight: 600; letter-spacing: -0.025em;
  color: var(--accent); transition: color 400ms ease;
}
.read i { font-style: normal; font-size: 13px; color: var(--text-3); margin-left: 3px; }
.read span { margin-left: 8px; }

.chart-wrap { position: relative; }
/* pan-y: senkrecht scrollt die Seite weiter, waagerecht liest man ab. */
#chart { display: block; width: 100%; height: 124px; touch-action: pan-y; cursor: crosshair; }
#chart #chart-line {
  fill: none; stroke: var(--accent); stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
  transition: stroke 400ms ease;
}
#chart #chart-limit { stroke: var(--limit); stroke-width: 1; stroke-dasharray: 2 4; opacity: 0.55; }
#chart .grid-line { stroke: var(--line); stroke-width: 1; }
#chart .grid-label { fill: var(--text-3); font-size: 10px; font-variant-numeric: tabular-nums; }
#chart .point { fill: var(--accent); transition: fill 400ms ease; }
#chart #chart-cursor { stroke: rgba(255,255,255,0.3); stroke-width: 1; }
#chart #chart-dot { fill: var(--accent); stroke: var(--card); stroke-width: 2.5; }
#chart-scrub[hidden] { display: none; }

#chart-empty {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  font-size: 13px; color: var(--text-3);
}
#chart-empty[hidden] { display: none; }

.axis {
  display: flex; justify-content: space-between;
  margin: 8px 0 0; min-height: 16px;
  font-size: 11px; font-variant-numeric: tabular-nums; color: var(--text-3);
}

/* ------------------------------------------------------------ Frischezeile */

.stamp {
  margin: 6px 0 0; min-height: 16px;
  text-align: center; font-size: 11px; color: var(--text-3);
}
html[data-conn="off"] .stamp { color: var(--amber); }

/* --------------------------------------------------------- Alarm-Seite */

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 15px 0;
  border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.row:first-of-type { padding-top: 2px; }
.row-label { flex: 1; color: var(--text); }
.row-label em {
  display: block; margin-top: 2px;
  font-style: normal; font-size: 12px; line-height: 1.35;
  color: var(--text-3);
}
.row > i { font-style: normal; width: 26px; font-size: 13px; color: var(--text-3); }

.nudge { display: inline-flex; align-items: center; background: var(--card-2); border-radius: 10px; }
.nudge b {
  min-width: 56px; text-align: center;
  font-size: 16px; font-weight: 600;
  font-variant-numeric: tabular-nums; padding: 7px 0;
}
.nudge button {
  width: 36px; padding: 7px 0; border: 0; background: none;
  font-size: 17px; color: var(--text-2); cursor: pointer;
  transition: background 90ms ease, transform 90ms ease, color 90ms ease;
}
.nudge button:active { background: rgba(255,255,255,0.1); color: var(--text); transform: scale(0.9); }

#apply {
  width: 100%; margin-top: 18px; padding: 13px;
  border: 0; border-radius: 12px;
  background: var(--card-2); color: var(--text-3);
  font-size: 15px; font-weight: 600; letter-spacing: -0.01em;
  cursor: default;
  transition: transform 110ms ease, background 200ms ease, color 200ms ease;
}
/* Erst wenn wirklich etwas offen ist, wird der Knopf aktiv — und dann
   deutlich, damit man ihn nicht übersieht. */
html[data-dirty="yes"] #apply { background: var(--text); color: var(--bg); cursor: pointer; }
#apply:active:not(:disabled) { transform: scale(0.98); }

.note { margin: 16px 0 0; font-size: 12px; line-height: 1.45; color: var(--text-3); }

/* -------------------------------------------------------------------- Toast */

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 22px);
  max-width: calc(100vw - 40px);
  padding: 11px 18px; border-radius: 999px;
  background: var(--card-2);
  font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
  opacity: 0; pointer-events: none;
  transform: translate(-50%, 12px) scale(0.95);
  transition: opacity 200ms ease, transform 260ms cubic-bezier(.2,.9,.3,1);
}
#toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); pointer-events: auto; }
#toast[data-kind="bad"] { color: var(--red); }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 120ms !important; }
  .ranges button:active, .nudge button:active, #apply:active, .icon-btn:active { transform: none; }
}
@media (prefers-contrast: more) {
  :root { --line: rgba(255,255,255,0.22); --text-2: #c9c9d0; --text-3: #93939c; --card: #202027; }
}
