/* ==========================================================================
   Baumkontrolle – Feldoberfläche
   Entworfen für ein Telefon im Freien: hoher Kontrast bei Sonnenlicht,
   Bedienung mit dem Daumen, Zustände immer sichtbar statt versteckt.
   ========================================================================== */

:root {
  --papier:        #eef1ec;
  --papier-tief:   #e3e8e1;
  --flaeche:       #ffffff;
  --tinte:         #17211b;
  --tinte-leise:   #56655b;
  --linie:         #c2ccc1;
  --moos:          #1d5c3c;
  --moos-hell:     #2a7a51;
  --signal:        #e4530a;

  --d-keine:       #4b7a5a;
  --d-gering:      #8a9e33;
  --d-mittel:      #d69a11;
  --d-hoch:        #e4530a;
  --d-akut:        #b32218;
  --d-unbestimmt:  #8c9a8f;

  --schrift: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Roboto Mono", Menlo, monospace;

  --leiste: 62px;
  --radius: 3px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --papier:      #131a15;
    --papier-tief: #0d120f;
    --flaeche:     #1b241d;
    --tinte:       #e6ece6;
    --tinte-leise: #9aab9d;
    --linie:       #334136;
    --moos:        #4fa578;
    --moos-hell:   #63bd8d;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

body {
  font-family: var(--schrift);
  font-size: 16px;
  line-height: 1.45;
  color: var(--tinte);
  background: var(--papier);
  -webkit-text-size-adjust: 100%;
  font-variant-numeric: tabular-nums;
}

button, input, textarea, select { font: inherit; color: inherit; }

/* --------------------------------------------------------------- Gerüst */

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.ansicht {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom);
}

.ansicht[hidden] { display: none; }

/* Die Karte füllt den Bereich vollständig und scrollt nicht mit. */
.ansicht.voll {
  padding: 0;
  overflow: hidden;
  position: relative;
}

.spalte {
  max-width: 44rem;
  margin: 0 auto;
  padding: 18px 16px 32px;
}

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

.kopf {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--flaeche);
  border-bottom: 1px solid var(--linie);
}

.kopf h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
  flex: 1;
}

.netzstand {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--tinte-leise);
  white-space: nowrap;
}

.punkt {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--moos);
  flex: none;
}
.punkt.offline { background: var(--tinte-leise); }
.punkt.wartend { background: var(--signal); }

/* --------------------------------------------------------------- Navigation */

.navleiste {
  display: flex;
  border-top: 1px solid var(--linie);
  background: var(--flaeche);
  padding-bottom: env(safe-area-inset-bottom);
  flex: none;
}

.navleiste button {
  flex: 1;
  min-height: var(--leiste);
  border: 0;
  background: none;
  color: var(--tinte-leise);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  cursor: pointer;
  border-top: 2px solid transparent;
  margin-top: -1px;
}

.navleiste button[aria-current="page"] {
  color: var(--moos);
  border-top-color: var(--moos);
  font-weight: 600;
}

.navleiste svg { width: 22px; height: 22px; }

.navleiste .zaehler {
  position: absolute;
  transform: translate(14px, -14px);
  background: var(--signal);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 17px;
  height: 17px;
  border-radius: 9px;
  padding: 0 4px;
  display: grid;
  place-items: center;
}

/* --------------------------------------------------------------- Karte */

#karte { width: 100%; height: 100%; background: var(--papier-tief); }

.leaflet-container { font: inherit; background: var(--papier-tief); }

.baum-marker {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 0 0 1px rgba(0,0,0,.35);
}

.karte-hinweis {
  position: absolute;
  z-index: 500;
  left: 50%;
  transform: translateX(-50%);
  bottom: 14px;
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  padding: 7px 12px;
  font-size: 13px;
  box-shadow: 0 2px 8px rgba(0,0,0,.14);
}

.popup h3 { margin: 0 0 2px; font-size: 15px; }
.popup img {
  width: 100%;
  max-width: 210px;
  border-radius: var(--radius);
  display: block;
  margin: 8px 0;
  background: var(--papier-tief);
}
.popup .meta { color: var(--tinte-leise); font-size: 13px; }
.popup a.knopf { display: block; text-align: center; margin-top: 8px; }

/* --------------------------------------------------------------- GPS-Anzeige
   Das Kernstück: unter Baumkronen wird GPS schlecht, und genau das muss
   der Kontrolleur sehen, bevor er auslöst – nicht hinterher am Schreibtisch. */

.gps {
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  background: var(--flaeche);
  padding: 12px 14px;
}

.gps-zeile {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.gps-wert {
  font-size: 26px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.gps-urteil { font-size: 14px; font-weight: 600; }
.gps-urteil.gut     { color: var(--moos); }
.gps-urteil.mittel  { color: var(--d-mittel); }
.gps-urteil.schlecht{ color: var(--signal); }

.gps-balken {
  height: 4px;
  background: var(--papier-tief);
  margin: 10px 0 8px;
  position: relative;
  overflow: hidden;
}

.gps-balken i {
  position: absolute;
  inset: 0 auto 0 0;
  display: block;
  background: var(--moos);
  transition: width .35s ease, background-color .35s ease;
}
.gps-balken i.mittel   { background: var(--d-mittel); }
.gps-balken i.schlecht { background: var(--signal); }

.gps-koordinaten {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--tinte-leise);
  word-break: break-all;
}

/* --------------------------------------------------------------- Erfassen */

.block { margin-top: 22px; }

.block > h2 {
  margin: 0 0 8px;
  font-size: 15px;
  font-weight: 600;
}

.block > h2 .neben {
  font-weight: 400;
  color: var(--tinte-leise);
  margin-left: 6px;
}

.fotofeld {
  position: relative;
  border: 1px dashed var(--linie);
  border-radius: var(--radius);
  background: var(--flaeche);
  min-height: 168px;
  display: grid;
  place-items: center;
  overflow: hidden;
}

.fotofeld img {
  width: 100%;
  display: block;
  max-height: 46dvh;
  object-fit: cover;
}

.fotofeld .leer {
  color: var(--tinte-leise);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}

.fotofeld .erneut {
  position: absolute;
  right: 8px; bottom: 8px;
}

.aufnahme {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  background: var(--flaeche);
  padding: 12px 14px;
}

.mikro {
  width: 54px; height: 54px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--moos);
  background: var(--flaeche);
  color: var(--moos);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.mikro svg { width: 24px; height: 24px; }
.mikro[data-laeuft="1"] {
  background: var(--signal);
  border-color: var(--signal);
  color: #fff;
}

.pegel {
  flex: 1;
  height: 26px;
  display: flex;
  align-items: flex-end;
  gap: 2px;
}
.pegel span {
  flex: 1;
  background: var(--linie);
  height: 3px;
  transition: height .08s linear, background-color .2s;
}
.pegel span.an { background: var(--moos-hell); }

.zeit {
  font-family: var(--mono);
  font-size: 15px;
  min-width: 4.2em;
  text-align: right;
}

textarea {
  width: 100%;
  min-height: 88px;
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  background: var(--flaeche);
  padding: 10px 12px;
  resize: vertical;
}

input[type="text"], select {
  width: 100%;
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  background: var(--flaeche);
  padding: 10px 12px;
}

.schalter {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  background: var(--flaeche);
  cursor: pointer;
}
.schalter input { width: 20px; height: 20px; accent-color: var(--moos); }
.schalter .text { font-size: 14px; }
.schalter .text small { display: block; color: var(--tinte-leise); }

/* Miniaturen der aufgenommenen Bilder unter dem Kamerafeld */

.miniaturen {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.miniatur {
  position: relative;
  width: 74px;
  height: 74px;
  flex: none;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--linie);
  background: var(--papier-tief);
}

.miniatur img { width: 100%; height: 100%; object-fit: cover; display: block; }

.miniatur .rolle {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  background: rgba(23, 33, 27, .72);
  color: #fff;
  font-size: 10.5px;
  text-align: center;
  padding: 1px 0;
}

.miniatur .weg {
  position: absolute;
  top: 2px; right: 2px;
  width: 24px; height: 24px;
  border: 0;
  border-radius: 50%;
  background: rgba(23, 33, 27, .78);
  color: #fff;
  font-size: 15px;
  line-height: 1;
  display: grid;
  place-items: center;
  cursor: pointer;
  padding: 0;
}

/* Bildergalerie in Protokoll und Kartenfenster: waagerecht wischbar,
   mit Einrasten. Dafür braucht es keine zusätzliche Bibliothek. */

.galerie {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-radius: var(--radius);
}
.galerie::-webkit-scrollbar { display: none; }

.galerie figure {
  margin: 0;
  flex: 0 0 100%;
  scroll-snap-align: center;
  position: relative;
}

.galerie img {
  width: 100%;
  display: block;
  border-radius: var(--radius);
  background: var(--papier-tief);
}

.galerie figcaption {
  position: absolute;
  left: 8px; bottom: 8px;
  background: rgba(23, 33, 27, .72);
  color: #fff;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 12px;
}

.galerie-punkte {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-top: 8px;
}
.galerie-punkte i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--linie);
}
.galerie-punkte i.an { background: var(--moos); }

.popup .galerie { max-width: 210px; margin: 8px 0; }
.popup .galerie figure { flex-basis: 210px; }

@media print {
  .galerie {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4mm;
    overflow: visible;
  }
  .galerie figure { flex: none; }
  .galerie-punkte { display: none; }
}

/* --------------------------------------------------------------- Knöpfe */

.knopf {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border: 1px solid var(--moos);
  border-radius: var(--radius);
  background: var(--moos);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.knopf.breit { width: 100%; }
.knopf.gross { min-height: 58px; font-size: 17px; }

.knopf.leise {
  background: var(--flaeche);
  color: var(--tinte);
  border-color: var(--linie);
  font-weight: 500;
}

.knopf.klein { min-height: 38px; font-size: 14px; padding: 0 12px; }

.knopf:disabled { opacity: .45; cursor: not-allowed; }
.knopf svg { width: 18px; height: 18px; }

:where(button, a, input, textarea, select):focus-visible {
  outline: 2px solid var(--moos-hell);
  outline-offset: 2px;
}

/* --------------------------------------------------------------- Listen */

.eintrag {
  display: flex;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--linie);
  align-items: flex-start;
  width: 100%;
  background: none;
  border-left: 0; border-right: 0; border-top: 0;
  text-align: left;
  cursor: pointer;
}

.eintrag .bild {
  width: 62px; height: 62px;
  flex: none;
  border-radius: var(--radius);
  object-fit: cover;
  background: var(--papier-tief);
}

.eintrag .inhalt { flex: 1; min-width: 0; }
.eintrag .titel { font-weight: 600; font-size: 15px; }
.eintrag .zeile2 {
  color: var(--tinte-leise);
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.marke {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 20px;
  color: #fff;
  background: var(--d-unbestimmt);
  vertical-align: 1px;
}
.marke.keine{background:var(--d-keine)} .marke.gering{background:var(--d-gering)}
.marke.mittel{background:var(--d-mittel)} .marke.hoch{background:var(--d-hoch)}
.marke.akut{background:var(--d-akut)}
.marke.offen{background:var(--signal)} .marke.fehler{background:var(--d-akut)}
.marke.arbeit{background:var(--tinte-leise)}

.leerzustand {
  padding: 40px 16px;
  text-align: center;
  color: var(--tinte-leise);
}
.leerzustand p { margin: 0 0 14px; }

.abschnitt-titel {
  margin: 26px 0 4px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--tinte-leise);
}

/* --------------------------------------------------------------- Protokoll */

.protokoll-kopf img {
  width: 100%;
  border-radius: var(--radius);
  display: block;
  background: var(--papier-tief);
}

.datenzeile {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--linie);
  font-size: 14.5px;
}
.datenzeile dt { color: var(--tinte-leise); }
.datenzeile dd { margin: 0; text-align: right; }

.befund {
  border-left: 3px solid var(--linie);
  padding: 2px 0 2px 11px;
  margin: 10px 0;
}
.befund.gering { border-left-color: var(--d-gering); }
.befund.mittel { border-left-color: var(--d-mittel); }
.befund.hoch   { border-left-color: var(--d-hoch); }
.befund .wo { font-weight: 600; font-size: 14px; }

.hinweiskasten {
  border: 1px solid var(--signal);
  border-left-width: 3px;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  background: var(--flaeche);
}

.transkript {
  background: var(--flaeche);
  border: 1px solid var(--linie);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 14.5px;
  white-space: pre-wrap;
}

.knopfreihe { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.knopfreihe .knopf { flex: 1; min-width: 140px; }

/* --------------------------------------------------------------- Anmeldung */

.anmeldung {
  display: grid;
  place-items: center;
  height: 100dvh;
  padding: 24px;
}
.anmeldung form {
  width: 100%;
  max-width: 21rem;
  display: grid;
  gap: 12px;
}
.anmeldung h1 { margin: 0 0 4px; font-size: 22px; }
.anmeldung p { margin: 0 0 12px; color: var(--tinte-leise); font-size: 14px; }
.fehlertext { color: var(--d-akut); font-size: 14px; min-height: 1.2em; }

/* --------------------------------------------------------------- Meldung */

.meldung {
  position: fixed;
  left: 50%;
  bottom: calc(var(--leiste) + 16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--tinte);
  color: var(--papier);
  padding: 11px 16px;
  border-radius: var(--radius);
  font-size: 14.5px;
  z-index: 2000;
  max-width: 92vw;
  box-shadow: 0 3px 14px rgba(0,0,0,.25);
}

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

/* --------------------------------------------------------------- Druck */

@media print {
  .kopf, .navleiste, .knopfreihe, .meldung { display: none !important; }
  body { background: #fff; font-size: 11pt; }
  .ansicht { overflow: visible; height: auto; }
  .spalte { max-width: none; padding: 0; }
  .protokoll-kopf img { max-height: 90mm; object-fit: contain; }
  .transkript, .hinweiskasten, .datenzeile { break-inside: avoid; }
  a[href]::after { content: ""; }
}
