/*
  Mini App — Aussehen im Jarvis-Stil.

  ÜBERNOMMEN VOM LAPTOP-COCKPIT (`scripts/ui/hud.css`), aber nicht kopiert.
  Dieselben Farben und dieselbe Haltung — kantig, dunkel, technisch —, jedoch für einen
  Daumen auf einem Telefon gebaut statt für eine Maus auf 27 Zoll:

  - Kein durchscheinendes Glas und keine Zierlinien. Auf einem Handy im Sonnenlicht ist
    Kontrast wichtiger als Atmosphäre.
  - Anfassbares ist mindestens 44 px hoch. Das ist keine Empfehlung, das ist die Grenze,
    unter der man danebentippt.
  - Zahlen in Mono mit fester Ziffernbreite, damit eine Temperatur beim Aktualisieren
    nicht hin und her springt.

  FARBE HAT BEDEUTUNG (dieselbe Regel wie im Cockpit):
    kühl/cyan = ein Zustand, den Jarvis beobachtet
    warm/amber = etwas ist aktiv oder will etwas von dir
*/

:root {
  --bg: #05080c;
  --panel: #0b1119;
  --panel-hoch: #121a24;
  --line: rgba(120, 200, 220, .14);
  --line-stark: rgba(120, 200, 220, .32);

  --acc: #22d3ee;
  --acc-dim: #1595b5;
  --warm: #fbbf24;
  --good: #34d399;
  --bad: #fb7185;
  --zweit: #8b5cf6;

  --txt: #dbe6ef;
  --dim: #8b98ad;

  --anzeige: "Chakra Petch", "Bahnschrift", "Segoe UI Semibold", system-ui, sans-serif;
  --text: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  --r: 3px;                 /* kantig — das ist der Jarvis-Look */
  --gap: 8px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

body {
  margin: 0;
  padding: 0 12px calc(20px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--txt);
  font: 15px/1.5 var(--text);
  -webkit-font-smoothing: antialiased;
}

/* --- Kopf --- */

.kopf {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 2px 12px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 12px;
}

.kopf-titel {
  font: 600 17px/1 var(--anzeige);
  letter-spacing: 2.5px;
  text-transform: uppercase;
  color: var(--acc);
}

/* Das Alter des Zustands steht dauerhaft im Kopf. Bei einem Briefkasten mit Taktung ist
   „vor 4 s" die ehrliche Auskunft — eine Anzeige, die Altes als aktuell ausgibt, belügt
   einen genau dann, wenn es darauf ankommt. */
.kopf-alter {
  font: 500 11px/1 var(--mono);
  letter-spacing: .5px;
  color: var(--dim);
  display: flex;
  align-items: center;
  gap: 6px;
}
.kopf-alter::before {
  content: "";
  width: 6px; height: 6px;
  background: var(--good);
  box-shadow: 0 0 8px var(--good);
}
.kopf-alter.ist-alt { color: var(--warm); }
.kopf-alter.ist-alt::before { background: var(--warm); box-shadow: 0 0 8px var(--warm); }

/* --- Reiter --- */

.reiter { display: flex; gap: 2px; margin-bottom: 14px; }

.reiter-knopf {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel);
  color: var(--dim);
  font: 600 12px/1 var(--anzeige);
  letter-spacing: 1.4px;
  text-transform: uppercase;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s;
}
.reiter-knopf.ist-aktiv {
  color: var(--acc);
  border-color: var(--line-stark);
  background: var(--panel-hoch);
  box-shadow: inset 0 -2px 0 var(--acc);
}
.reiter-knopf:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }

/* --- Ansichten & Abschnitte --- */

.ansicht { display: none; }
.ansicht.ist-sichtbar { display: block; }

.abschnitt {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 20px 0 8px;
  font: 600 10px/1 var(--anzeige);
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}
.abschnitt::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
.abschnitt:first-child { margin-top: 4px; }

/* --- Kacheln (Messwerte auf einen Blick) --- */

.kacheln {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: var(--gap);
}

.kachel {
  padding: 10px 11px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  border-left: 2px solid var(--acc-dim);
}
.kachel.ist-warm { border-left-color: var(--warm); }
.kachel.ist-gut { border-left-color: var(--good); }
.kachel.ist-schlecht { border-left-color: var(--bad); }

.kachel-name {
  font: 500 10px/1.2 var(--anzeige);
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 6px;
  /* Lange Namen umbrechen statt abschneiden — abgeschnittene Beschriftungen sind der
     häufigste Grund, warum man eine Anzeige nicht versteht. */
  overflow-wrap: anywhere;
}

.kachel-wert {
  font: 600 19px/1.1 var(--mono);
  font-variant-numeric: tabular-nums;      /* Zahlen springen beim Takt nicht */
  color: var(--txt);
  overflow-wrap: anywhere;
}
.kachel-wert.ist-warm { color: var(--warm); }
.kachel-wert.ist-gut { color: var(--good); }
.kachel-wert.ist-schlecht { color: var(--bad); }
.kachel-klein { font-size: 14px; }

/* Balken für alles, was einen Anteil hat (Speicher, Platte, Last) */
.balken {
  height: 3px;
  margin-top: 7px;
  background: rgba(255, 255, 255, .07);
  overflow: hidden;
}
.balken-fuellung {
  height: 100%;
  background: var(--acc);
  transition: width .4s ease;
}
.balken-fuellung.ist-warm { background: var(--warm); }
.balken-fuellung.ist-schlecht { background: var(--bad); }

/* --- Gruppen --- */

.gruppe {
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: var(--panel);
  overflow: hidden;
}
.gruppe + .gruppe { margin-top: var(--gap); }

.gruppe-kopf {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 46px;
  padding: 10px 12px;
  cursor: pointer;
  list-style: none;
  user-select: none;
  font: 600 12px/1 var(--anzeige);
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--txt);
}
.gruppe-kopf::-webkit-details-marker { display: none; }
.gruppe-kopf::after {
  content: "";
  width: 7px; height: 7px;
  border-right: 1.5px solid var(--dim);
  border-bottom: 1.5px solid var(--dim);
  transform: rotate(-45deg);
  margin-left: auto;
  transition: transform .18s;
}
.gruppe[open] > .gruppe-kopf::after { transform: rotate(45deg); }

.gruppe-zahl {
  font: 500 10px/1 var(--mono);
  letter-spacing: .5px;
  color: var(--dim);
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.gruppe-zahl.ist-an { color: var(--warm); border-color: rgba(251, 191, 36, .4); }

.gruppe-inhalt { padding: 0 8px 8px; }

/* --- Zeilen --- */

.liste { display: flex; flex-direction: column; gap: 4px; }

.zeile {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 48px;
  padding: 9px 11px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background .14s, border-color .14s;
}
.zeile:active { background: var(--panel-hoch); }
.zeile:focus-visible { outline: 2px solid var(--acc); outline-offset: -2px; }
.zeile.ist-an { background: rgba(251, 191, 36, .07); border-color: rgba(251, 191, 36, .22); }
.zeile.ist-still { cursor: default; }
.zeile.ist-wartend { opacity: .45; }

.zeile-text { flex: 1; min-width: 0; }

/* KEIN nowrap/ellipsis mehr. Aufgabentexte waren dadurch nach der halben Zeile zu Ende,
   und gerade die langen sind die wichtigen. Lieber drei Zeilen als ein Rätsel. */
.zeile-name { display: block; overflow-wrap: anywhere; }
.zeile-unten {
  display: block;
  margin-top: 3px;
  font: 500 11px/1.3 var(--mono);
  letter-spacing: .4px;
  color: var(--dim);
}

.zeile-wert {
  font: 500 13px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  flex: none;
}
.zeile-wert.ist-an { color: var(--warm); }

/* Der Punkt trägt die Aussage nie allein — daneben steht immer Text. Farbe als einziger
   Bedeutungsträger schließt aus, wer sie nicht unterscheiden kann. */
.punkt {
  width: 7px; height: 7px;
  flex: none;
  background: var(--dim);
  opacity: .45;
}
.punkt.ist-an { background: var(--warm); opacity: 1; box-shadow: 0 0 8px var(--warm); }
.punkt.ist-gut { background: var(--good); opacity: 1; }
.punkt.ist-schlecht { background: var(--bad); opacity: 1; box-shadow: 0 0 8px var(--bad); }

/* --- Aufgaben --- */

.haken {
  width: 22px; height: 22px;
  flex: none;
  border: 1.5px solid var(--dim);
  border-radius: var(--r);
  display: grid;
  place-items: center;
  font-size: 13px;
  color: transparent;
  align-self: flex-start;
  margin-top: 2px;
}
.zeile.ist-erledigt .haken { border-color: var(--acc); color: var(--acc); }
.zeile.ist-erledigt .zeile-name { text-decoration: line-through; color: var(--dim); }

.zeile.ist-hoch { border-left: 2px solid var(--bad); }
.zeile.ist-niedrig { opacity: .72; }

/* --- Uhrzeit-Spalte bei Terminen --- */

.uhr {
  font: 600 13px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--acc);
  flex: none;
  min-width: 42px;
}

/* --- Leer & Hinweis --- */

.leer {
  padding: 22px 4px;
  text-align: center;
  font-size: 13px;
  color: var(--dim);
}

.hinweis {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 28px);
  padding: 9px 16px;
  background: var(--panel-hoch);
  border: 1px solid var(--line-stark);
  border-radius: var(--r);
  color: var(--txt);
  font: 500 13px/1.3 var(--text);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s, transform .18s;
  z-index: 10;
}
.hinweis.ist-sichtbar { opacity: 1; transform: translate(-50%, 0); }
.hinweis.ist-fehler { border-color: var(--bad); color: var(--bad); }

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

/* Nicht erreichbar: sichtbar, aber erkennbar tot. Die WLED haengt an einer Steckdose —
   solange die aus ist, meldet Home Assistant sie als unavailable. Sie ganz zu verstecken
   hiess: Man musste wissen, dass es sie gibt, um sie zu finden. */
.zeile.ist-weg { opacity: .42; }
.zeile.ist-weg .punkt { background: var(--dim); box-shadow: none; }

/* --- Medien --- */

.medien {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--r);
  border-left: 2px solid var(--acc-dim);
  padding: 12px;
}
.medien + .medien { margin-top: var(--gap); }

.medien-kopf { display: flex; align-items: flex-start; gap: 12px; }
.medien-text { flex: 1; min-width: 0; }

.medien-geraet {
  font: 600 10px/1 var(--anzeige);
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 5px;
}
/* Titel dürfen umbrechen. Ein abgeschnittener Songtitel ist genau die Information, die
   man wollte — nur eben halb. */
.medien-titel { font-size: 15px; overflow-wrap: anywhere; }
.medien-titel.ist-an { color: var(--warm); }
.medien-kuenstler { font-size: 13px; color: var(--dim); margin-top: 2px; overflow-wrap: anywhere; }

.medien-vol {
  font: 500 12px/1 var(--mono);
  font-variant-numeric: tabular-nums;
  color: var(--dim);
  flex: none;
}

.medien-knoepfe { display: flex; gap: 6px; margin-top: 12px; }

.medien-knopf {
  flex: 1;
  min-height: 44px;                /* daumengerecht */
  border: 1px solid var(--line);
  border-radius: var(--r);
  background: transparent;
  color: var(--txt);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: background .14s, border-color .14s, opacity .14s;
}
.medien-knopf:active { background: var(--panel-hoch); border-color: var(--line-stark); }
.medien-knopf:focus-visible { outline: 2px solid var(--acc); outline-offset: 2px; }
.medien-knopf.ist-aus { color: var(--bad); }
.medien-knopf.ist-wartend { opacity: .4; }

/* Lautstärke: eigener Regler, weil der Standard auf Android und iOS verschieden aussieht
   und beide Male nicht zum Rest passt. */
.medien-regler {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 30px;                    /* Trefferfläche, nicht Balkenhöhe */
  margin-top: 10px;
  background: transparent;
  cursor: pointer;
}
.medien-regler::-webkit-slider-runnable-track {
  height: 3px;
  background: rgba(255, 255, 255, .1);
}
.medien-regler::-moz-range-track { height: 3px; background: rgba(255, 255, 255, .1); }
.medien-regler::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px; height: 16px;
  margin-top: -6.5px;
  background: var(--acc);
  border: 0;
  border-radius: 50%;
}
.medien-regler::-moz-range-thumb {
  width: 16px; height: 16px;
  background: var(--acc);
  border: 0;
  border-radius: 50%;
}
