/*
 * Dashboard · 1920 × 1080
 *
 * Farbsystem (OKLCH-basiert, Werte als Hex für ältere Kiosk-Browser):
 * - Eine Akzentfarbe: Lime #c8f542 (Farbton ≈ 123°). Nur für die Hauptaktion, aktive
 *   Zustände (lädt, Klima läuft, laufender Termin, „Heute“), die beste Route und Füllstände.
 * - Neutrale Töne leicht Richtung Akzent getönt (Chroma ≈ 0.007). Kein reines Schwarz.
 * - Bereit-Zustand Türkis #64ebdb (OKLCH 0.86 / 0.12 / 185°): gleiche Familie wie das Lime.
 * - Warnung Bernstein (72°), Fehler Koralle (28°) — deutlich vom Akzent abgesetzt.
 * - Kontrast auf --surface: --ink 15:1, --muted 7:1, --faint 3:1 (nur Deko).
 *
 * Typo-System (eine Größe pro Elementart, dashboardweit):
 *   --t-hero   64  die eine Hauptzahl eines Widgets (Temperatur, Ladestand, Fahrzeit)
 *   --t-value  28  Werte und Zustände (Reichweite, kW, „Geschlossen“, Smart Charging)
 *   --t-text   20  lesbarer Text (Termintitel, Route, Tagesnamen)
 *   --t-label  18  Widget-Titel, Feld-Labels (grau, 500)
 *   --t-meta   16  Stand, Zeiten, Orte, Nebeninfos (grau)
 *
 * Karten-Rezept: --surface, 1 px Hairline, 1 px helle Oberkante, Radius 20, Innenabstand 28.
 * Kopfzeile jedes Widgets: links Titel, rechts nur der Datenstand („Stand 18:09“).
 */
/* Inter wird mitgeliefert (assets/fonts, SIL OFL 1.1), damit das Dashboard auf jedem Gerät gleich aussieht. */
@font-face {
  font-family: "Inter Dashboard";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(fonts/inter-latin-ext-wght-normal.woff2) format("woff2-variations"), url(fonts/inter-latin-ext-wght-normal.woff2) format("woff2");
  unicode-range: U+0100-02AF,U+0304,U+0308,U+0329,U+1E00-1E9F,U+1EF2-1EFF,U+2020,U+20A0-20AB,U+20AD-20C0,U+2113,U+2C60-2C7F,U+A720-A7FF;
}
@font-face {
  font-family: "Inter Dashboard";
  font-style: normal;
  font-display: swap;
  font-weight: 100 900;
  src: url(fonts/inter-latin-wght-normal.woff2) format("woff2-variations"), url(fonts/inter-latin-wght-normal.woff2) format("woff2");
  unicode-range: U+0000-00FF,U+0131,U+0152-0153,U+02BB-02BC,U+02C6,U+02DA,U+02DC,U+0304,U+0308,U+0329,U+2000-206F,U+2074,U+20AC,U+2122,U+2191,U+2193,U+2212,U+2215,U+FEFF,U+FFFD;
}

:root {
  --bg: #0e0f0c;
  --surface: #161814;
  --surface-2: #20211d;
  --ink: #edefea;
  --muted: #a3a69e;
  --faint: #686a64;
  --line: rgba(237, 239, 234, 0.10);
  --line-strong: rgba(237, 239, 234, 0.18);
  --edge: rgba(255, 255, 255, 0.05);
  --strip: #8a8d85;      /* Statusstreifen: grau, dunkle Schrift (Kontrast 6:1) */
  --strip-ink: #0e0f0c;

  --accent: #c8f542;
  --accent-ink: #131808;
  --accent-soft: rgba(200, 245, 66, 0.14);
  --ready: #64ebdb;
  --warn: #ffb649;
  --bolt: #ffe14a;       /* nur Blitz im Gewittersymbol: klares Gelb, kein Grünstich */
  --danger: #f17264;

  /* Leinwand & Raster */
  --canvas-w: 1920px;
  --canvas-h: 1080px;
  --pad: 32px;
  --gap: 24px;
  --statusbar-h: 72px;
  --card-pad: 28px;

  /* Typo */
  --font: "Inter Dashboard", "Inter", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --t-hero: 64px;
  --t-value: 28px;
  --t-text: 20px;
  --t-label: 18px;
  --t-meta: 16px;

  /* Punkte: Zustand / Liste */
  --dot: 14px;
  --dot-sm: 8px;

  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 999px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Leinwand ---------- */

.canvas {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--canvas-w);
  height: var(--canvas-h);
  padding: var(--pad);
  display: grid;
  grid-template-rows: 1fr var(--statusbar-h);
  gap: var(--gap);
  transform-origin: 0 0;
}

/* ---------- Karten (Widgets und Fußleiste teilen ein Rezept) ---------- */

.widget,
.statusbar {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: inset 0 1px 0 var(--edge);
}

/* ---------- Fußleiste: Uhr, Stand, Neu laden ---------- */

.statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  padding: 0 12px 0 var(--card-pad);
}

.statusbar-clock {
  display: flex;
  align-items: baseline;
  gap: 16px;
}

.clock-time {
  font-size: var(--t-value);
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1;
}

.clock-date,
.status-text {
  font-size: var(--t-meta);
  color: var(--muted);
}

.statusbar-status {
  display: flex;
  align-items: center;
  gap: 20px;
}

.btn-icon {
  /* Nur ein kleiner Pfeil (Fernseher ohne Maus/Touch): dient vor allem als Ladeanzeige */
  appearance: none;
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: opacity 0.15s ease;
}
.btn-icon:hover { opacity: 0.8; }
.btn-icon:active { transform: scale(0.96); }
.btn-icon:disabled { cursor: progress; }
.btn-icon:disabled svg { animation: spin 0.9s linear infinite; }
.btn-icon:focus-visible { outline: 3px solid var(--accent); outline-offset: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Raster ---------- */

.grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols, 12), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows, 8), minmax(0, 1fr));
  gap: var(--gap);
  min-height: 0;
}

/* ?grid=1 — Rasterzellen sichtbar machen */
.grid-cell {
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  color: var(--faint);
  font-size: 14px;
  padding: 6px 8px;
  pointer-events: none;
}
[data-debug-grid] .widget { outline: 2px solid var(--accent-soft); }

/* ---------- Widget-Rahmen ---------- */

.widget {
  position: relative;
  z-index: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.widget-body {
  flex: 1;
  min-height: 0;
  padding: var(--card-pad);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.widget-body.is-loading::after {
  content: "";
  display: block;
  width: 45%;
  height: 24px;
  border-radius: 8px;
  background: linear-gradient(90deg, var(--surface-2), #2a2c27, var(--surface-2));
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.widget-body.is-stale { opacity: 0.6; }
.widget-body.is-error .widget-msg { color: var(--danger); }
.widget-body.is-empty .widget-msg { color: var(--muted); }
.widget-msg { margin: auto 0; font-size: var(--t-text); line-height: 1.4; }

/* Statusstreifen: systemische Infos (Quelle, Stand) aus dem Layout heraus */
.widget-foot {
  flex: none;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 5px var(--card-pad) 6px;
  background: var(--strip);
  color: var(--strip-ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
}
.widget-foot[hidden] { display: none; }

/* ---------- Bausteine ---------- */

.w-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
}
.w-label {
  margin: 0;
  white-space: nowrap;
  font-size: var(--t-label);
  font-weight: 500;
  color: var(--muted);
}
.w-meta {
  font-size: var(--t-meta);
  color: var(--faint);
  white-space: nowrap;
}

.w-hero {
  font-size: var(--t-hero);
  font-weight: 650;
  letter-spacing: -0.04em;
  line-height: 1;
}
.w-value {
  font-size: var(--t-value);
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.15;
}
.w-unit {
  font-size: 0.4em;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--muted);
  margin-left: 0.2em;
}
.w-value .w-unit { font-size: 0.64em; }
.w-text { font-size: var(--t-text); line-height: 1.35; }
.w-sub { font-size: var(--t-meta); color: var(--muted); }
.w-field { font-size: var(--t-label); font-weight: 500; color: var(--muted); }

.is-muted { color: var(--muted); }
.is-warn { color: var(--warn); }
.is-danger { color: var(--danger); }
.is-accent { color: var(--accent); }

/* Zustandspunkte: --dot für Zustände, --dot-sm in Listen */
.dot {
  flex: none;
  display: inline-block;
  width: var(--dot);
  height: var(--dot);
  border-radius: 50%;
  background: var(--faint);
}
.dot.is-on { background: var(--accent); animation: pulse 2.4s ease-out infinite; }
.dot.is-accent { background: var(--accent); }
.dot.is-ready { background: var(--ready); }
.dot.is-fault { background: var(--danger); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(200, 245, 66, 0.45); }
  70%, 100% { box-shadow: 0 0 0 12px rgba(200, 245, 66, 0); }
}

.w-badge {
  padding: 3px 12px;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-strong);
  font-size: var(--t-meta);
  font-weight: 500;
  color: var(--muted);
}

/* ---------- Energie (Batterie + Laden) ---------- */

/* kompakt (3 halbe Rasterzeilen): engere Abstände */
[data-widget="car-energy"] .widget-body { justify-content: space-between; gap: 10px; }
.en-main { display: grid; gap: 12px; }

.en-top {
  display: flex;
  align-items: baseline;
  gap: 16px;
}
.en-range { margin-left: auto; display: flex; align-items: baseline; gap: 10px; }

.soc {
  position: relative;
}
.soc-bar {
  position: relative;
  height: 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
}
.soc-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.6s ease;
}
.soc-bar.is-charging .soc-fill {
  background-image: linear-gradient(90deg, transparent 0, rgba(255, 255, 255, 0.35) 50%, transparent 100%);
  background-size: 200px 100%;
  background-repeat: no-repeat;
  animation: charge-sweep 2.4s linear infinite;
}
@keyframes charge-sweep { from { background-position: -200px 0; } to { background-position: calc(100% + 200px) 0; } }
.soc-target {
  position: absolute;
  top: -5px;
  height: 22px;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--ink);
}

.en-state {
  display: flex;
  align-items: center;
  gap: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.en-state .w-sub { margin-left: auto; text-align: right; }

/* ---------- Fahrzeugstatus: eine Zeile, Icon + Aussage ---------- */

.st-row {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 24px;
  align-items: center;
}
.st-item { display: flex; align-items: center; gap: 12px; min-width: 0; white-space: nowrap; }
.st-item .w-text { overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.st-icon { flex: none; width: 26px; height: 26px; color: var(--ink); }
.st-icon.is-accent { color: var(--accent); }
.st-icon.is-warn { color: var(--warn); }
.st-icon.is-muted { color: var(--faint); }

/* ---------- Wetter ---------- */

.wx-icon { display: block; flex: none; }
.wx-icon-lg { width: 64px; height: 64px; color: var(--ink); }
.wx-icon-sm { width: 24px; height: 24px; color: var(--muted); }
/* Farbakzente in den Wettersymbolen: Sonne Bernstein, Regentropfen Türkis */
.wx-sun { stroke: var(--warn); }
.wx-drop { stroke: var(--ready); }
.wx-bolt { stroke: var(--bolt); }

.wx-now { display: flex; align-items: center; gap: 20px; }
.wx-now-text { display: grid; gap: 4px; margin-left: 8px; }

.wx-icon-md { width: 28px; height: 28px; color: var(--ink); }

/* Tagesverlauf und Woche: Beschriftung hochkant links wie die KW im Kalender (.cal-kw) */
.wx-sec {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  column-gap: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}
.wx-side {
  display: flex;
  justify-content: center;
  border-right: 2px solid var(--line-strong);
  padding-right: 6px;
  margin-right: -8px;
}
.wx-side span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: var(--t-meta);
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  align-self: flex-start;
}
.wx-sec.is-current .wx-side { border-right-color: var(--accent); }
.wx-sec.is-current .wx-side span { color: var(--accent); }

.wx-hours,
.wx-week {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  min-width: 0;
}
.wx-week { grid-template-columns: repeat(7, minmax(0, 1fr)); }

.wx-slot,
.wx-day { display: grid; justify-items: center; gap: 4px; }
.wx-slot-time,
.wx-day-name { font-size: var(--t-meta); font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.wx-day.is-today .wx-day-name { color: var(--accent); }
.wx-slot-temp { font-size: var(--t-text); font-weight: 600; line-height: 1.1; font-variant-numeric: tabular-nums; }
.wx-day-temp { display: flex; align-items: baseline; gap: 3px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.wx-day-max { font-size: var(--t-label); font-weight: 600; color: var(--ink); }
.wx-day-min { font-size: var(--t-meta); color: var(--muted); }
.wx-day-sep { font-size: var(--t-meta); color: var(--faint); }
/* Abschnitte gleichmäßig verteilen, statt freien Platz an einer Stelle zu sammeln */
[data-widget="weather"] .widget-body { justify-content: space-between; }
/* Regenwahrscheinlichkeit ab 30 %, überall türkis; Zeile nur, wenn ein Wert sie braucht */
.wx-rain { min-height: 20px; font-size: var(--t-meta); font-weight: 500; color: var(--ready); font-variant-numeric: tabular-nums; }

/* ---------- Arbeitsweg ---------- */

.commute-map {
  flex: 1;
  min-height: 0;
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface-2);
}
.commute-map-svg { display: block; width: 100%; height: 100%; }
.commute-map-img { display: block; width: 100%; height: 100%; object-fit: cover; }
.map-streets path { fill: none; stroke: var(--line-strong); stroke-width: 2; }
.map-route { fill: none; stroke-linecap: round; }
.map-route.main { stroke: var(--accent); stroke-width: 7; }
.map-route.alt { stroke: var(--faint); stroke-width: 5; }
.map-pin { stroke: var(--surface-2); stroke-width: 4; }
.map-pin.start { fill: var(--accent); }
.map-pin.end { fill: var(--ink); }

/* Fahrzeugstandort (nur wenn nicht zu Hause) */
.commute-where {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}
.commute-where[hidden] { display: none; }
.commute-where .w-text {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.commute-where .w-sub { margin-left: auto; white-space: nowrap; }

.commute-summary { display: grid; gap: 6px; }
.commute-top { display: flex; align-items: baseline; gap: 16px; }
.commute-arrive { margin-left: auto; display: flex; align-items: baseline; gap: 10px; }

.alt-list { list-style: none; margin: 0; padding: 0; display: grid; }
.alt-list .w-field { padding-bottom: 6px; }
.alt {
  display: grid;
  grid-template-columns: var(--dot-sm) minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.alt .dot { width: var(--dot-sm); height: var(--dot-sm); }
.alt-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Kalender ---------- */

.cal-list {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Kalenderwoche: KW hochkant links, senkrechte Klammer, kräftige Linie zwischen Wochen */
.cal-week {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr);
  column-gap: 18px;
  padding: 18px 0;
  border-top: 2px solid var(--line-strong);
}
.cal-week:first-child { border-top: 0; padding-top: 4px; }
.cal-kw {
  display: flex;
  justify-content: center;
  border-right: 2px solid var(--line-strong);
  padding-right: 6px;
  margin-right: -8px;
}
.cal-kw span {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: var(--t-meta);
  font-weight: 600;
  color: var(--muted);
  white-space: nowrap;
  align-self: flex-start;
}
.cal-week.is-current .cal-kw { border-right-color: var(--accent); }
.cal-week.is-current .cal-kw span { color: var(--accent); }

.cal-week-days { display: grid; gap: 16px; min-width: 0; }
.cal-day { display: grid; gap: 8px; }
.cal-day-head { display: flex; align-items: baseline; gap: 12px; }
.cal-day-name { font-size: var(--t-text); font-weight: 600; }
.cal-day-date { font-size: var(--t-meta); color: var(--muted); }
.cal-day-head.is-today .cal-day-name { color: var(--accent); }
.cal-empty { margin-left: auto; font-size: var(--t-meta); color: var(--faint); }
.cal-day.is-empty .cal-day-name { font-weight: 500; }

.cal-events { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.cal-event {
  display: grid;
  grid-template-columns: 116px var(--dot-sm) minmax(0, 1fr);
  align-items: baseline;
  column-gap: 16px;
}
.cal-time { font-size: var(--t-meta); color: var(--muted); white-space: nowrap; }
.cal-dot {
  width: var(--dot-sm);
  height: var(--dot-sm);
  border-radius: 50%;
  background: var(--faint);
  align-self: center;
}
.cal-text { display: grid; gap: 2px; min-width: 0; }
.cal-title {
  font-size: var(--t-text);
  font-weight: 500;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-loc {
  font-size: var(--t-meta);
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-event.is-allday .cal-dot { border-radius: 2px; }
.cal-event.is-now .cal-dot { background: var(--accent); animation: pulse 2.4s ease-out infinite; }
.cal-event.is-now .cal-time { color: var(--accent); }
.cal-event.is-past { opacity: 0.45; }

/* ---------- Platzhalter ---------- */

.placeholder-body {
  flex: 1;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
}

/* ---------- Hinweise ---------- */

.notice {
  position: absolute;
  left: var(--pad);
  right: var(--pad);
  bottom: calc(var(--pad) + var(--statusbar-h) + var(--gap));
  z-index: 10;
  padding: 16px 20px;
  border-radius: var(--r-md);
  background: #2a1713;
  border: 1px solid rgba(241, 114, 100, 0.45);
  color: #ffd6cf;
  font-size: var(--t-meta);
  line-height: 1.4;
}
.notice p { margin: 0; }
.notice p + p { margin-top: 6px; }
.notice code { color: var(--ink); }
.notice + .notice { bottom: calc(var(--pad) + var(--statusbar-h) + var(--gap) + 96px); }

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