/* ---------------------------------------------------------------------------
   DEKRA Bildvorlage — Grundgerüst.

   Die Farbtokens heißen wie in der TrUL-App (--panel, --line, --blue …), damit
   die portierten Regelblöcke unverändert übernommen werden können. Belegt sind
   sie hier mit dem DEKRA-Grün: `--blue` ist also grün — der Name bleibt, weil
   sonst jeder Nachzug aus der TrUL-App von Hand umgeschrieben werden müsste.
--------------------------------------------------------------------------- */

:root {
  --gruen: #008143;
  --gruen-hell: #64b32c;
  --blue: var(--gruen);

  --surface: #f4f6f4;
  --surface-muted: #e8ece9;
  --panel: #ffffff;
  --panel-muted: #eef1ef;
  --line: #d6dbd7;
  --border: #d6dbd7;
  --text: #16241c;
  --text-muted: #5d6b63;
  --muted: #5d6b63;
  --rot: #c2311f;

  --radius-sm: 10px;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 40, 30, 0.08);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface: #101612;
    --surface-muted: #161d19;
    --panel: #1a221d;
    --panel-muted: #232c26;
    --line: #2f3a33;
    --border: #2f3a33;
    --text: #e6ece8;
    --text-muted: #9bab a1;
    --text-muted: #9babA1;
    --muted: #9baba1;
    --blue: #35a96a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

body.pdf-overlay-open { overflow: hidden; }

#app {
  max-width: 900px;
  margin: 0 auto;
  padding: 16px 16px calc(32px + env(safe-area-inset-bottom, 0px));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

#app.app-loading { align-items: center; padding-top: 80px; }

.boot-screen { text-align: center; color: var(--text-muted); }
.boot-screen img { width: 180px; max-width: 60vw; margin-bottom: 14px; }

/* --- Kopf ---------------------------------------------------------------- */

.kopf {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 5px solid var(--gruen);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.kopf__logo { width: 116px; height: auto; flex-shrink: 0; }
.kopf__text h1 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
.kopf__text p { margin: 2px 0 0; font-size: 12.5px; color: var(--text-muted); }

@media (max-width: 560px) {
  .kopf { flex-direction: column; align-items: flex-start; gap: 10px; }
}

/* --- Blöcke und Formularfelder ------------------------------------------- */

.karte-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.karte-block > h2 {
  margin: 0 0 4px;
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--gruen);
}

.feld-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
  margin-top: 12px;
  align-items: end;
}

.input-field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.input-field--wide { grid-column: 1 / -1; }
.input-field > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.01em;
}
.input-field > span em { font-style: normal; font-weight: 500; color: var(--gruen); }

.input-field input,
.input-field select {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
}
.input-field input:focus,
.input-field select:focus {
  outline: none;
  border-color: var(--gruen);
  box-shadow: 0 0 0 3px rgba(0, 129, 67, 0.16);
}
.input-field input.ist-uebernommen {
  border-color: var(--gruen);
  background: rgba(0, 129, 67, 0.09);
  transition: background 0.4s ease;
}

.input-hint, .map-note {
  margin: 6px 0 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

/* --- Chips und Knöpfe ----------------------------------------------------- */

.chip-row { display: flex; flex-wrap: wrap; gap: 7px; }
.chip-toggle {
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.chip-toggle--small { min-height: 34px; font-size: 13px; padding: 0 12px; }
.chip-toggle.is-active {
  background: var(--gruen);
  border-color: var(--gruen);
  color: #fff;
  font-weight: 600;
}

.primary-button {
  min-height: 48px;
  padding: 0 22px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--gruen);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.primary-button:disabled { opacity: 0.45; cursor: not-allowed; }

.ghost-button {
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.ghost-button--small { min-height: 42px; font-size: 13px; white-space: nowrap; }

.detail-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

/* --- Ablagefläche für Bilder --------------------------------------------- */

.transfer-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 22px 16px;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  cursor: pointer;
}
.transfer-drop strong { font-size: 15px; }
.transfer-drop span { font-size: 12.5px; color: var(--text-muted); }
.transfer-drop.is-over { border-color: var(--gruen); background: rgba(0, 129, 67, 0.07); }
.transfer-drop:focus-visible { outline: 2px solid var(--gruen); outline-offset: 2px; }

/* --- Eingebettete Maske --------------------------------------------------- */

.bildanlage-inline { display: block; }
.bildanlage-seite { display: block; }
.bildanlage-seite__body { display: flex; flex-direction: column; gap: 14px; }

/* ===========================================================================
   Ab hier: 1:1 aus der TrUL-App übernommene Regelblöcke (styles.css),
   Selektoren .pdf-overlay*, .qr-scan*, .bildanlage*.
   Nicht von Hand umbauen — mit tools/extract-styles.py neu ziehen.
   =========================================================================== */

/* ---------------------------------------------------------------------------
   Fullscreen-PDF-Overlay (jede PDF-Ausgabe) mit Teilen-Menü. In einer als
   Fullscreen installierten PWA hat der PDF-Viewer keine Speichern-Option — das
   Teilen-Menü ist der Weg, das PDF zu sichern/weiterzugeben.
--------------------------------------------------------------------------- */
.pdf-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  background: #33373d;
}
.pdf-overlay__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.pdf-overlay__title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pdf-overlay__actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.pdf-overlay__share,
.pdf-overlay__close {
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--line);
}
.pdf-overlay__share {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}
.pdf-overlay__close {
  background: var(--panel-muted);
  color: var(--text);
}
.pdf-overlay__inhalt {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.pdf-overlay__frame {
  flex: 1;
  width: 100%;
  border: 0;
  background: #52565c;
}
/* Mehrseitige Vorschau: je Seite ein eigener Rahmen, gescrollt wird die Liste.
   WebKit auf iPadOS lässt in einem PDF-`iframe` nicht scrollen — deshalb zeigt
   jeder Rahmen nur EINE Seite, und das Blättern übernimmt der Container. */
.pdf-overlay__inhalt--seiten {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}
.pdf-overlay__seiten {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 14px 12px calc(28px + env(safe-area-inset-bottom, 0px));
}
.pdf-overlay__seite {
  position: relative;
  margin: 0;
  width: 100%;
  max-width: 900px;
  /* Grau, nicht weiß (v219): legt der Systemviewer die Seite kleiner in den
     Kasten, als er ist, war der Rest bisher weiß und damit von der Seite nicht
     zu unterscheiden — die Seite wirkte geschrumpft. Auf Grau sieht man, wo
     das Blatt aufhört. */
  background: #d9dde3;
  border-radius: 4px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}
.pdf-overlay__seite-frame,
.pdf-overlay__seite-platz {
  display: block;
  width: 100%;
  height: 100%;
  border: 0;
}
/* Platzhalter, solange die Seite noch nicht geladen ist (Lazy-Loading). */
.pdf-overlay__seite-platz {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #eceef1;
  color: #6b7482;
  font-size: 14px;
  font-weight: 600;
}
.pdf-overlay__seite figcaption {
  position: absolute;
  right: 8px;
  bottom: 8px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(24, 28, 34, 0.72);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  pointer-events: none;
}
body.pdf-overlay-open { overflow: hidden; }
/* --- Bildanlage: Eingabemaske (Drag & Drop + vorbelegte Felder) --- */
.bildanlage-overlay {
  --surface: #ffffff;
  --text-muted: #64748b;
  position: fixed;
  inset: 0;
  /* Über dem Update-Banner (9999), aber unter der PDF-Anzeige (10000) — sonst
     verdeckt der Banner die Aktionsleiste des Dialogs. */
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(8, 14, 22, 0.72);
  backdrop-filter: blur(4px);
}
.bildanlage-sheet {
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  max-height: 100%;
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface, #fff);
  color: var(--text, #16202c);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.4);
}
.bildanlage-sheet__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: #16344f;
  color: #fff;
}
.bildanlage-sheet__title { font-weight: 600; font-size: 15px; }
.bildanlage-sheet__close {
  border: none;
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}
.bildanlage-sheet__body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.bildanlage-drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 26px 16px;
  text-align: center;
  border: 2px dashed var(--border, #c3cedb);
  border-radius: 14px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.bildanlage-drop:focus-visible,
.bildanlage-drop.is-over {
  outline: none;
  border-color: #2f6db3;
  background: rgba(47, 109, 179, 0.08);
}
.bildanlage-drop span { font-size: 13px; color: var(--text-muted, #64748b); }
.bildanlage-thumbs { display: flex; flex-wrap: wrap; gap: 12px; }
.bildanlage-thumb {
  position: relative;
  margin: 0;
  width: 148px;
  border: 1px solid var(--border, #c3cedb);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface-muted, #f2f5f9);
}
.bildanlage-thumb img { display: block; width: 100%; height: 96px; object-fit: cover; }
.bildanlage-thumb figcaption {
  padding: 5px 8px;
  font-size: 12px;
  color: var(--text-muted, #64748b);
}
.bildanlage-thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: 50%;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  background: rgba(12, 20, 32, 0.72);
  color: #fff;
}
.bildanlage-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.bildanlage-field { display: flex; flex-direction: column; gap: 5px; }
.bildanlage-field--wide { grid-column: 1 / -1; }
.bildanlage-field > span {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted, #64748b);
}
.bildanlage-field em {
  font-style: normal;
  font-weight: 500;
  color: #2f6db3;
}
.bildanlage-field input,
.bildanlage-field select {
  padding: 10px 12px;
  border: 1px solid var(--border, #c3cedb);
  border-radius: 10px;
  font-size: 15px;
  background: var(--surface, #fff);
  color: inherit;
}
.bildanlage-field input:focus,
.bildanlage-field select:focus { outline: none; border-color: #2f6db3; }
/* QR-Scanner: Vollbild-Kamera. Liegt ueber der Bildanlage-Maske, deshalb ein
   hoeherer z-index als deren Overlay. */
.qr-scan-overlay {
  position: fixed;
  inset: 0;
  /* Ueber der Bildanlage-Maske (9999) und der PDF-Anzeige (10000) — der
     Scanner wird AUS der Maske heraus geoeffnet und liegt sonst dahinter. */
  z-index: 10001;
  background: rgba(8, 12, 18, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.qr-scan-sheet {
  width: min(560px, 100%);
  background: #0f1722;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.qr-scan-sheet__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: #16344f;
  color: #fff;
}
.qr-scan-sheet__title { font-weight: 600; font-size: 15px; }
.qr-scan-sheet__build { margin-left: auto; margin-right: 10px; font-size: 11px; opacity: 0.65; }
.qr-scan-sheet__close {
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: transparent;
  color: #fff;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
}
.qr-scan-stage { position: relative; background: #000; flex: 1 1 auto; min-height: 0; }
.qr-scan-video { display: block; width: 100%; max-height: 62vh; object-fit: cover; }
/* Zielrahmen: zeigt, wohin der Code gehalten werden muss. */
.qr-scan-reticle {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(58%, 260px);
  aspect-ratio: 1;
  border: 3px solid rgba(255, 255, 255, 0.9);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
}
/* Liegt IM Videobereich statt darunter: bei hochaufloesenden Kamerabildern
   waechst das Video und schob die Zeile sonst aus dem sichtbaren Bereich. */
.qr-scan-hint {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  margin: 0;
  padding: 10px 14px 12px;
  color: #f1f5f9;
  font-size: 13px;
  text-align: center;
  background: linear-gradient(to top, rgba(8, 12, 18, 0.94), rgba(8, 12, 18, 0.55));
  /* Ein gescannter Rohwert kann lang sein und muss vollstaendig lesbar bleiben. */
  overflow-wrap: anywhere;
  max-height: 40%;
  overflow-y: auto;
}
/* Ausweg-Knopf unter dem Sucher (v287). Bewusst UNTER dem Videobild und nicht
   darin: er soll erst auffallen, wenn der Sucher nicht weiterkommt. */
.qr-scan-foto {
  display: block;
  padding: 10px 14px 12px;
  background: #16344f;
  color: #f1f5f9;
  font-size: 13px;
  text-align: center;
  cursor: pointer;
}
.qr-scan-foto span { text-decoration: underline; text-underline-offset: 3px; }
.qr-scan-overlay { padding: 0; }
.qr-scan-sheet { width: 100%; height: 100%; border-radius: 0; }
.qr-scan-video { max-height: none; flex: 1 1 auto; }
/* Koordinatenfelder: Eingabe + Scan-Knopf in einer Zeile, darunter die
   Umrechnung in UTM-REF und WGS-84 zur Kontrolle. */
.bildanlage-koord { gap: 6px; }
.bildanlage-koord__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted, #64748b);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.bildanlage-koord__row { display: flex; gap: 8px; align-items: stretch; }
.bildanlage-koord__row input { flex: 1 1 auto; min-width: 0; }
.bildanlage-koord__out {
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--text-muted, #64748b);
  min-height: 15px;
}
.bildanlage-koord__out.is-error { color: #dc2626; }
/* Kurzes Aufleuchten, wenn ein gescannter Wert im Feld landet. */
.bildanlage-koord input.ist-uebernommen {
  border-color: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.25);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}
.bildanlage-scan {
  flex: 0 0 auto;
  border: 1px solid #cbd5e1;
  background: #f1f5f9;
  color: #0f172a;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.bildanlage-scan:hover { background: #e2e8f0; }
.bildanlage-maprow {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.bildanlage-maprow .bildanlage-field { flex: 1 1 auto; min-width: 0; }
.bildanlage-maprow .bildanlage-scan { height: 40px; }
.bildanlage-hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  color: var(--text-muted, #64748b);
}
.bildanlage-sheet__actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--border, #c3cedb);
}
.bildanlage-status { font-size: 13px; color: var(--text-muted, #64748b); }
.bildanlage-status--error { color: #dc2626; }
.bildanlage-btn {
  border: none;
  border-radius: 10px;
  padding: 11px 20px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  background: #2f6db3;
  color: #fff;
}
.bildanlage-btn:disabled { opacity: 0.45; cursor: default; }
.bildanlage-overlay { padding: 0; }
.bildanlage-sheet { width: 100%; height: 100%; border-radius: 0; }
.bildanlage-grid { grid-template-columns: minmax(0, 1fr); }
/* Bildanlage als Seite statt als Popup (v252).
   Die eingebettete Fassung trägt die Formularbausteine der App (input-field,
   chip-row, primary-button) und damit deren Farbtokens — die Sheet-Optik hatte
   Weiß und Graustufen fest verdrahtet und war im Dunkelmodus unlesbar. Hier
   steht nur noch, was die Seite von einer beliebigen anderen unterscheidet. */
.bildanlage-inline {
  display: block;
}
.bildanlage-seite {
  display: grid;
  gap: 14px;
}
.bildanlage-seite__body {
  display: grid;
  gap: 14px;
}
/* Ablegezone: der Text darin gehört zur Zone, nicht zum Fließtext. */
.bildanlage-seite .transfer-drop span {
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1.35;
}
/* Selects erben in der App keine eigene Flächenfarbe — ohne diese Zeile
   stünde schwarze Schrift auf schwarzem Grund. */
.bildanlage-seite select {
  width: 100%;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-muted);
  color: var(--text);
  font: inherit;
}
/* Koordinatenzeile: Feld und Scan-Knopf nebeneinander, auf schmalen Geräten
   untereinander — der Knopf soll nicht das Feld auf zwei Zeichen quetschen. */
.bildanlage-seite .bildanlage-koord__label,
.bildanlage-seite .bildanlage-koord__out {
  color: var(--muted);
}
.bildanlage-seite .bildanlage-koord__row .ghost-button {
  flex: 0 0 auto;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--panel-muted);
}
.bildanlage-seite .bildanlage-thumb {
  background: var(--panel);
  border-color: var(--line);
}
.bildanlage-seite .bildanlage-thumb figcaption {
  color: var(--muted);
}
.bildanlage-seite .einsatz-briefing-grid {
    grid-template-columns: minmax(0, 1fr);
  }
.bildanlage-seite .bildanlage-koord__row {
    flex-wrap: wrap;
  }
.bildanlage-seite .bildanlage-koord__row .ghost-button {
    width: 100%;
    padding: 12px 14px;
  }
/* Verlaufszeile: wie die Fundstellenzeile, zusätzlich mit Vorschaubild und
   den beiden Knöpfen rechts. */
.bildanlage-zeile {
  gap: 12px;
}
.bildanlage-zeile__bild {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}
.bildanlage-zeile__aktionen {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-left: auto;
}
