/* TRUL-Kartenkiste — Bedienung mit Handschuhen, bei Sonnenlicht, im Stehen.
   Deshalb: große Flächen (min. 56 px), hoher Kontrast, kein Hover-Zustand als
   Träger von Information, kein Dark Mode als Standard (Build-Brief §12). */

:root {
  --thw: #0b3d91;          /* THW-Blau */
  --thw-hell: #1a5fd0;
  --grund: #ffffff;
  --grund-2: #eef1f5;
  --linie: #c3ccd8;
  --text: #101720;
  --text-schwach: #4a5768;
  --warn: #c0392b;
  --ok: #15803d;
  --offline: #8a5a00;
  --tippziel: 56px;
  --radius: 14px;
  --schatten: 0 6px 24px rgba(16, 23, 32, 0.22);
}

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

html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--grund);
  color: var(--text);
  font: 500 17px/1.35 system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
}

/* Bezugsrahmen für alles Weitere.
 *
 * Karte, Kopfzeile, Fußleiste und Blätter sind absolut positioniert. Ohne
 * einen positionierten Vorfahren beziehen sie sich auf den initialen
 * Bezugsrahmen — und der entspricht auf iOS Safari nicht dem sichtbaren
 * Bereich. Auf dem iPad lag das geöffnete Blatt deshalb unter der Fußleiste
 * statt über der Karte, auf dem Telefon schaute das geschlossene Blatt unten
 * heraus: "bottom: 0" lag jenseits des Sichtbaren.
 *
 * fixed statt absolute, weil damit auch die einfahrende Safari-Leiste den
 * Rahmen nicht mehr verschiebt. Gleiche Bauweise wie beim Zugangsschutz
 * weiter unten, der auf dem Gerät immer richtig saß. */
#app { position: fixed; inset: 0; overflow: hidden; }

#karte { position: absolute; inset: 0; }

/* --- Kopfzeile ------------------------------------------------------- */
#kopf {
  position: absolute; top: 0; left: 0; right: 0; z-index: 30;
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
  background: linear-gradient(180deg, rgba(255,255,255,.97) 70%, rgba(255,255,255,0));
  pointer-events: none;
}
#kopf > * { pointer-events: auto; }
#titel { white-space: nowrap; font-weight: 800; font-size: 16px; letter-spacing: .2px; color: var(--thw); }
#status { display: flex; gap: 6px; margin-left: auto; flex-wrap: wrap; justify-content: flex-end; }
/* Auf dem Telefon zählt jeder Millimeter Karte: mit der aktiven Lage sind es
   vier Chips, die sonst den Titel in eine dritte Zeile drücken. Der Titel ist
   Zierde — in der installierten App steht er ohnehin im Fenstertitel. */
@media (max-width: 430px) { #titel { display: none; } }

.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; white-space: nowrap;
  background: var(--grund-2); color: var(--text-schwach);
  border: 1px solid var(--linie);
}
/* Die aktive Lage ist zugleich Schalter — im Einsatz die Angabe, die am
   häufigsten geprüft und gewechselt wird. */
button.chip {
  font: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
  max-width: 42vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  min-height: 30px;
}
button.chip::before { content: "\25C6"; margin-right: 2px; color: var(--thw); }
button.chip:active { transform: translateY(1px); }

.chip.gut { background: #e6f4ea; color: var(--ok); border-color: #a8d5b5; }
.chip.warn { background: #fdeceb; color: var(--warn); border-color: #f0b3ad; }
.chip.netz { background: #fff4dc; color: var(--offline); border-color: #e8c98a; }
.chip .punkt { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* --- Fußleiste ------------------------------------------------------- */
#leiste {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 30;
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  gap: 6px; padding: 8px 8px calc(env(safe-area-inset-bottom, 0px) + 8px);
  background: rgba(255,255,255,.96);
  border-top: 1px solid var(--linie);
}

.knopf {
  min-height: var(--tippziel);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; padding: 6px 4px;
  border: 1px solid var(--linie); border-radius: var(--radius);
  background: var(--grund); color: var(--text);
  font: 700 12px/1.1 inherit; letter-spacing: .2px;
  cursor: pointer; user-select: none;
}
.knopf svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.knopf[aria-pressed="true"] { background: var(--thw); color: #fff; border-color: var(--thw); }
.knopf:active { transform: translateY(1px); }
.knopf[disabled] { opacity: .4; }

/* --- Blätter (Sheets) ------------------------------------------------ */
.blatt {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 40;
  max-height: 78%; display: flex; flex-direction: column;
  background: var(--grund);
  border-radius: 18px 18px 0 0;
  box-shadow: var(--schatten);
  /* Reichlich über die eigene Höhe hinaus: 102 % ließen auf dem Telefon
     einen Streifen stehen, sobald der sichtbare Bereich kleiner war als der
     Bezugsrahmen. Der Zuschlag kostet nichts, das Blatt ist ohnehin weg. */
  transform: translateY(calc(100% + env(safe-area-inset-bottom, 0px) + 32px));
  transition: transform .18s ease-out;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.blatt.offen { transform: none; }
.blatt-kopf {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-bottom: 1px solid var(--linie);
}
.blatt-kopf h2 { margin: 0; font-size: 17px; font-weight: 800; }
.blatt-kopf .zu {
  margin-left: auto; min-width: 44px; min-height: 44px;
  border: 1px solid var(--linie); border-radius: 12px; background: var(--grund-2);
  font: 700 15px inherit; cursor: pointer;
}
.blatt-inhalt { overflow: auto; padding: 12px 16px 20px; -webkit-overflow-scrolling: touch; }

/* --- Listen und Formularzeilen --------------------------------------- */
.zeile {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--tippziel); padding: 8px 0;
  border-bottom: 1px solid var(--grund-2);
}
.zeile:last-child { border-bottom: 0; }
.zeile .beschriftung { flex: 1; min-width: 0; }
.zeile .beschriftung b { display: block; font-size: 16px; font-weight: 700; }
.zeile .beschriftung small { display: block; color: var(--text-schwach); font-size: 12px; font-weight: 500; }
.gruppe { margin: 14px 0 2px; font-size: 12px; font-weight: 800; letter-spacing: .8px; text-transform: uppercase; color: var(--text-schwach); }

/* Schalter: bewusst groß, kein Systemcheckbox-Zwerg */
.schalter { position: relative; width: 62px; height: 36px; flex: none; }
.schalter input { position: absolute; inset: 0; opacity: 0; margin: 0; width: 100%; height: 100%; }
.schalter span {
  position: absolute; inset: 0; border-radius: 999px;
  background: var(--linie); transition: background .15s;
}
.schalter span::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 30px; height: 30px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s;
}
.schalter input:checked + span { background: var(--thw); }
.schalter input:checked + span::after { transform: translateX(26px); }

label.feld { display: block; margin: 12px 0 0; font-size: 13px; font-weight: 700; color: var(--text-schwach); }
input[type="text"], input[type="url"], input[type="number"], select {
  width: 100%; min-height: var(--tippziel); margin-top: 6px;
  padding: 10px 12px; border: 1px solid var(--linie); border-radius: 12px;
  background: var(--grund); color: var(--text); font: 500 16px inherit;
}
input[type="range"] { width: 100%; height: 44px; accent-color: var(--thw); }

.aktion {
  width: 100%; min-height: var(--tippziel); margin-top: 14px;
  border: 0; border-radius: var(--radius);
  background: var(--thw); color: #fff; font: 800 16px inherit; cursor: pointer;
}
.aktion.zweit { background: var(--grund-2); color: var(--text); border: 1px solid var(--linie); }
.aktion.warn { background: var(--warn); }

/* Netzabhängigkeit muss sichtbar sein (Build-Brief §12) */
.netzpflicht::after {
  content: "Netz"; margin-left: 8px;
  padding: 2px 7px; border-radius: 999px;
  background: #fff4dc; color: var(--offline);
  font-size: 11px; font-weight: 800; vertical-align: middle;
}

/* --- Messanzeige ------------------------------------------------------ */
#messfeld {
  position: absolute; left: 12px; right: 12px; z-index: 25;
  bottom: calc(var(--tippziel) + 26px + env(safe-area-inset-bottom, 0px));
  display: none; gap: 14px; align-items: center;
  padding: 12px 14px; border-radius: var(--radius);
  background: rgba(255,255,255,.97); border: 1px solid var(--linie);
  box-shadow: var(--schatten);
}
#messfeld.an { display: flex; }
#messfeld .wert { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; }
#messfeld .wert small { display: block; font-size: 11px; font-weight: 700; color: var(--text-schwach); text-transform: uppercase; letter-spacing: .6px; }
#messfeld .rechts { margin-left: auto; display: flex; gap: 8px; }
#messfeld button { min-height: 44px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--linie); background: var(--grund-2); font: 700 14px inherit; }

/* --- Meldungen -------------------------------------------------------- */
#meldung {
  position: absolute; left: 12px; right: 12px; z-index: 60;
  top: calc(env(safe-area-inset-top, 0px) + 56px);
  padding: 12px 14px; border-radius: var(--radius);
  background: #101720; color: #fff; font-size: 14px; font-weight: 600;
  box-shadow: var(--schatten);
  opacity: 0; transform: translateY(-8px); transition: opacity .15s, transform .15s;
  pointer-events: none;
}
#meldung.an { opacity: 1; transform: none; }
#meldung.fehler { background: var(--warn); }

/* --- Passwort-Gate ---------------------------------------------------- */
html.kk-locked #app { display: none !important; }
#kk-gate { display: none; }
html.kk-locked #kk-gate {
  display: flex; position: fixed; inset: 0; z-index: 100000;
  flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; padding: 28px;
  background: radial-gradient(circle at 50% 28%, #16344f 0%, #0f1722 72%);
  color: #e8ecf2;
}
#kk-gate h1 { font-size: 19px; margin: 0; font-weight: 800; }
#kk-gate p { margin: 0; max-width: 300px; text-align: center; font-size: 13px; color: #9fb0c4; }
#kk-gate form { display: flex; flex-direction: column; gap: 12px; width: 100%; max-width: 280px; }
#kk-gate input {
  padding: 14px 16px; border-radius: 12px; border: 1px solid #2a3b50;
  background: #0c1420; color: #e8ecf2; font-size: 17px; text-align: center; letter-spacing: 2px;
}
#kk-gate button { padding: 14px; border-radius: 12px; border: 0; background: #1a5fd0; color: #fff; font: 800 16px inherit; }
#kk-gate .err { color: #ff8f85; font-size: 13px; min-height: 18px; }

/* MapLibre-Bedienelemente an die Tippziele anpassen */
.maplibregl-ctrl-group button { width: 40px !important; height: 40px !important; }
.maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right {
  margin-bottom: calc(var(--tippziel) + 22px + env(safe-area-inset-bottom, 0px));
}
.maplibregl-ctrl-top-right { margin-top: calc(env(safe-area-inset-top, 0px) + 52px); }


/* --- Zeichnen-Blatt --------------------------------------------------- */
.werkzeuge {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px;
}
.werkzeuge .knopf { min-height: 52px; }

.zeichenwahl {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px;
}
.zeichenknopf {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  min-height: 92px; padding: 8px 4px;
  border: 1px solid var(--linie); border-radius: var(--radius);
  background: var(--grund); cursor: pointer;
}
.zeichenknopf[aria-pressed="true"] { border-color: var(--thw); box-shadow: inset 0 0 0 2px var(--thw); }
.zeichenknopf .bild { display: block; height: 38px; }
.zeichenknopf .bild svg { height: 38px; width: auto; }
.zeichenknopf .name { font-size: 11px; font-weight: 700; line-height: 1.15; text-align: center; color: var(--text-schwach); }
