/* Sensor-Feldbuch
   Idee: ein Arbeitsgerät für draußen. Kühler Betongrund, tiefgrüne Tinte,
   und als einziges lautes Element das gelbe Maßband mit Skalenstrichen,
   das durch die Abschnitte führt. */

:root {
  --papier: #E4E9E6;
  --flaeche: #FFFFFF;
  --tinte: #16261F;
  --tinte-2: #465750;
  --linie: #BAC6C0;
  --band: #FFCC1A;
  --band-tinte: #16261F;
  --kopf: #16261F;
  --kopf-text: #EEF3F0;
  --blau: #1A55A0;
  --gruen: #1D6A43;
  --rot: #AE2419;
  --orange: #945000;
  --radius-feld: 6px;
  --radius-knopf: 10px;
  --kopfhoehe: 52px;
  --schrift: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --papier: #0D1411;
    --flaeche: #15201B;
    --tinte: #E3EBE7;
    --tinte-2: #A3B3AC;
    --linie: #33443C;
    --blau: #8AB6F0;
    --gruen: #6FC596;
    --rot: #FF8B80;
    --orange: #FFB365;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--papier);
  color: var(--tinte);
  font: 17px/1.45 var(--schrift);
  font-variant-numeric: tabular-nums;
  min-height: 100dvh;
}

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 0 16px calc(110px + env(safe-area-inset-bottom));
}

h1 { font-size: 1.6rem; line-height: 1.15; font-weight: 800; letter-spacing: -0.015em; margin: 24px 0 18px; }
h2 { font-size: 1.1rem; line-height: 1.25; font-weight: 750; margin: 0 0 8px; }
p { margin: 0 0 8px; }
a { color: var(--blau); }

:focus-visible { outline: 3px solid var(--blau); outline-offset: 2px; }

.unsichtbar {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  opacity: 0;
}

/* ---------- Kopf ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: var(--kopfhoehe);
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--kopf);
  color: var(--kopf-text);
}
.marke-app { color: inherit; text-decoration: none; font-weight: 800; font-size: 1.05rem; letter-spacing: -0.01em; }

.syncstate {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: 36px; padding: 0 12px;
  border: 1px solid rgba(238, 243, 240, 0.35); border-radius: 999px;
  background: transparent; color: var(--kopf-text);
  font: 600 0.88rem/1 var(--schrift); cursor: pointer;
}
.punkt { width: 10px; height: 10px; border-radius: 50%; background: #9FB0A8; flex: none; }
.syncstate[data-art="ok"] .punkt { background: #5CC98F; }
.syncstate[data-art="wartend"] .punkt { background: var(--band); }
.syncstate[data-art="fehler"] .punkt { background: #FF6A5C; }
.syncstate[data-art="laeuft"] .punkt { background: var(--band); animation: pulsieren 1s ease-in-out infinite; }
@keyframes pulsieren { 50% { opacity: 0.3; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 50px; padding: 0 18px;
  border: 2px solid var(--tinte); border-radius: var(--radius-knopf);
  background: var(--flaeche); color: var(--tinte);
  font: 650 1rem/1.15 var(--schrift); text-align: center; text-decoration: none;
  cursor: pointer; position: relative;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: translateY(1px); }
.btn.primaer { background: var(--band); color: var(--band-tinte); border-color: var(--band-tinte); }
.btn.sekundaer { background: var(--flaeche); }
.btn.gefahr { color: var(--rot); border-color: var(--rot); background: var(--flaeche); }
.btn.klein { min-height: 42px; padding: 0 12px; font-size: 0.94rem; }
.btn.gross { min-height: 58px; width: 100%; font-size: 1.06rem; }
.btn:disabled { opacity: 0.4; cursor: default; transform: none; }
.btn:focus-within { outline: 3px solid var(--blau); outline-offset: 2px; }
.btn:has(.unsichtbar:focus-visible) { outline: 3px solid var(--blau); outline-offset: 2px; }

.link {
  background: none; border: 0; padding: 0; margin: 0;
  color: var(--blau); font: inherit; text-align: left;
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer;
}

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

/* ---------- Tabs und Listen ---------- */
.tabs {
  display: flex; overflow-x: auto; scrollbar-width: none;
  margin: 0 -16px 18px; padding: 0 8px;
  border-bottom: 1px solid var(--linie);
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: 15px 10px 12px; white-space: nowrap;
  color: var(--tinte-2); text-decoration: none; font-weight: 650;
  border-bottom: 3px solid transparent;
}
.tabs a[aria-current="page"] { color: var(--tinte); border-bottom-color: var(--tinte); }

.listenkopf { margin-bottom: 18px; }

.liste { list-style: none; margin: 0; padding: 0; background: var(--flaeche); border: 1px solid var(--linie); border-radius: 8px; overflow: hidden; }
.eintrag + .eintrag { border-top: 1px solid var(--linie); }
.eintrag > a, .eintrag-knopf {
  display: grid; grid-template-columns: 1fr auto; column-gap: 12px; row-gap: 2px;
  width: 100%; padding: 14px 14px 14px 12px;
  border: 0; border-left: 6px solid var(--linie); background: none;
  color: inherit; font: inherit; text-align: left; text-decoration: none; cursor: pointer;
}
.eintrag-titel { grid-column: 1; font-weight: 750; font-size: 1.04rem; overflow-wrap: anywhere; }
.eintrag-zeile { grid-column: 1; font-size: 0.94rem; color: var(--tinte-2); overflow-wrap: anywhere; }
.leise { font-size: 0.86rem; }
.badge {
  grid-column: 2; grid-row: 1 / span 3; align-self: center;
  padding: 4px 8px; border-radius: 4px;
  background: var(--papier); color: var(--tinte-2);
  font-size: 0.8rem; font-weight: 700; white-space: nowrap;
}
.sync-ausstehend > a, .sync-fehler > a { border-left-color: var(--band); }
.sync-synchron > a { border-left-color: var(--gruen); }
.sync-konflikt > a, .sync-fehler > a { border-left-color: var(--rot); }
.sync-konflikt .badge, .sync-fehler .badge { color: var(--rot); }
.sync-synchron .badge { color: var(--gruen); }
.status-aktiv > .eintrag-knopf { border-left-color: var(--gruen); }
.status-beendet > .eintrag-knopf { border-left-color: var(--tinte-2); }
.status-gestoert > .eintrag-knopf { border-left-color: var(--rot); }

.leer { padding: 28px 4px; }
.leer h1 { margin-top: 0; font-size: 1.3rem; }
.leer .btn { margin-top: 8px; }

.suchzeile { margin-bottom: 12px; }
.export { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 18px; color: var(--tinte-2); font-size: 0.94rem; }

.block { background: var(--flaeche); border: 1px solid var(--linie); border-radius: 8px; padding: 16px; margin-bottom: 12px; }

/* ---------- Formular: Kopf und Maßband ---------- */
.formkopf { display: flex; align-items: baseline; gap: 12px; padding-top: 12px; min-width: 0; }
.zurueck { flex: none; font-weight: 650; text-decoration: none; padding: 6px 0; }
.formtitel { font-weight: 750; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; color: var(--tinte-2); }

.band {
  position: sticky; top: var(--kopfhoehe); z-index: 20;
  display: flex; overflow-x: auto; scrollbar-width: none;
  margin: 10px -16px 0;
  background-color: var(--band);
  background-image:
    repeating-linear-gradient(90deg, var(--band-tinte) 0 2px, transparent 2px 60px),
    repeating-linear-gradient(90deg, var(--band-tinte) 0 1px, transparent 1px 12px);
  background-size: 100% 13px, 100% 6px;
  background-repeat: no-repeat;
  background-attachment: local;
  box-shadow: 0 1px 0 rgba(22, 38, 31, 0.35);
}
.band::-webkit-scrollbar { display: none; }
.seg {
  flex: none; display: inline-flex; align-items: baseline; gap: 5px;
  padding: 19px 13px 9px;
  border: 0; border-right: 1px solid rgba(22, 38, 31, 0.28);
  background: transparent; color: var(--band-tinte);
  font: 700 0.9rem/1 var(--schrift); cursor: pointer; white-space: nowrap;
}
.seg:first-child { padding-left: 16px; }
.seg-zustand { font-weight: 900; min-width: 0.6em; }
.seg.fehlt .seg-zustand { color: #A51D12; }
.seg.leer .seg-name { opacity: 0.62; }
.seg.aktiv { background: var(--band-tinte); color: var(--band); }
.seg.aktiv .seg-name { opacity: 1; }
.seg.aktiv.fehlt .seg-zustand { color: #FF8F84; }
.seg:focus-visible { outline: 3px solid var(--blau); outline-offset: -3px; }

.sektion { padding-top: 2px; }

/* ---------- Felder ---------- */
.feld { margin: 0 0 22px; padding: 0; border: 0; min-width: 0; scroll-margin-top: 130px; border-radius: 8px; transition: box-shadow 0.3s; }
.feld.klein { margin-bottom: 12px; display: block; }
.feld.markiert { box-shadow: 0 0 0 4px var(--papier), 0 0 0 7px var(--band); }
.feldlabel { display: block; padding: 0; margin-bottom: 6px; font-weight: 650; font-size: 0.95rem; }
.feld.klein .feldlabel { font-size: 0.86rem; margin-bottom: 4px; }
.pflichtmarke { color: var(--rot); font-weight: 800; }
.hint { font-size: 0.88rem; color: var(--tinte-2); margin: 6px 0 0; max-width: 62ch; }

input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), select, textarea {
  width: 100%; min-height: 50px;
  padding: 11px 12px;
  border: 1.5px solid var(--linie); border-radius: var(--radius-feld);
  background: var(--flaeche); color: var(--tinte);
  font: 1.06rem/1.3 var(--schrift);
  appearance: none; -webkit-appearance: none;
}
select {
  padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 20px center, right 14px center;
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}
textarea { min-height: 110px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--tinte); }
input[aria-invalid="true"] { border-color: var(--rot); box-shadow: inset 0 0 0 1px var(--rot); }
.mono { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace !important; letter-spacing: 0.04em; }

.einheit { display: flex; align-items: stretch; gap: 8px; }
.einheit > input { flex: 1; min-width: 0; }
.einheit-text { display: inline-flex; align-items: center; min-width: 2.6em; color: var(--tinte-2); font-weight: 650; }
.einheit > .btn { flex: none; min-height: 50px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  position: relative; display: inline-flex; align-items: center;
  min-height: 46px; padding: 0 15px;
  border: 1.5px solid var(--linie); border-radius: 999px;
  background: var(--flaeche); cursor: pointer; font-weight: 550;
  -webkit-tap-highlight-color: transparent;
}
.chip:has(input:checked) { background: var(--tinte); border-color: var(--tinte); color: var(--papier); }
.chip:has(input:focus-visible) { outline: 3px solid var(--blau); outline-offset: 2px; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

details.manuell { margin-top: 12px; }
details.manuell summary { cursor: pointer; font-weight: 650; color: var(--blau); padding: 8px 0; }

.wiederholung { display: grid; gap: 10px; }
.wh-eintrag { padding: 12px; border: 1.5px solid var(--linie); border-radius: 8px; background: var(--flaeche); }

/* ---------- Position ---------- */
.pos { padding: 16px; margin-bottom: 10px; background: var(--flaeche); border: 1.5px solid var(--tinte); border-radius: 8px; }
.pos.leer { border-style: dashed; border-color: var(--linie); }
.pos-koord { display: flex; flex-wrap: wrap; gap: 2px 20px; font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.2; }
.pos.leer .pos-koord { color: var(--tinte-2); font-size: 1.25rem; }
.pos-meta { margin-top: 6px; color: var(--tinte-2); font-size: 0.92rem; }
.pos-knoepfe { display: grid; grid-template-columns: 1.2fr 1fr; gap: 8px; }

.karte { flex: 1; min-height: 240px; border-radius: 6px; border: 1px solid var(--linie); }
.karte-info { margin: 8px 0 0; font-weight: 650; }
.kreuz { border: 3px solid #16261F; border-radius: 50%; background: rgba(255, 204, 26, 0.45); box-shadow: 0 0 0 2px #fff; }
.kreuz::after { content: ""; position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: #16261F; }

.scanvideo { flex: 1; width: 100%; min-height: 240px; object-fit: cover; background: #000; border-radius: 6px; }

/* ---------- Fotos ---------- */
.kompass {
  position: sticky; top: calc(var(--kopfhoehe) + 44px); z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px;
  margin: 0 0 6px; padding: 10px 12px;
  background: var(--flaeche); border: 1.5px solid var(--tinte); border-radius: 8px;
}
.kompass-wert { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; min-width: 5.5em; }
.kompass-text { font-size: 0.88rem; color: var(--tinte-2); flex: 1 1 12em; }

.fotokat { padding: 18px 0; border-top: 1px solid var(--linie); scroll-margin-top: 150px; }
.fotokat:first-of-type { border-top: 0; }
.fotokat-kopf { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.fotokat-kopf h2 { margin: 0; font-size: 1.05rem; }
.marke { font-size: 0.84rem; font-weight: 750; color: var(--tinte-2); white-space: nowrap; }
.marke.fehlt { color: var(--rot); }
.marke.ok { color: var(--gruen); }
.richtung-hinweis { display: block; margin-top: 4px; font-size: 0.88rem; color: var(--tinte-2); min-height: 1.2em; }
.richtung-hinweis.passt { color: var(--gruen); font-weight: 750; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; margin: 12px 0; }
.thumb { position: relative; aspect-ratio: 1; padding: 0; border: 0; border-radius: 4px; overflow: hidden; background: var(--linie); cursor: pointer; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.nicht-hochgeladen { position: absolute; top: 6px; right: 6px; width: 14px; height: 14px; border-radius: 50%; background: var(--band); border: 2px solid #16261F; }
.thumb-richtung { position: absolute; left: 4px; bottom: 4px; padding: 1px 5px; border-radius: 3px; background: rgba(22, 38, 31, 0.82); color: #fff; font-size: 0.75rem; font-weight: 700; }
.foto-knoepfe { display: flex; gap: 8px; margin-top: 12px; }
.foto-knoepfe > .btn { flex: 1; }

.foto-gross img { display: block; width: 100%; max-height: 62dvh; object-fit: contain; background: #000; border-radius: 6px; }
.foto-meta { list-style: none; padding: 0; margin: 10px 0 0; font-size: 0.9rem; color: var(--tinte-2); }

/* ---------- Abschluss ---------- */
.statusblock { padding: 14px 16px; margin-bottom: 18px; background: var(--flaeche); border: 1px solid var(--linie); border-left: 6px solid var(--linie); border-radius: 8px; }
.statusblock strong { display: block; font-size: 1.05rem; margin-bottom: 2px; }
.statusblock p { margin: 0; color: var(--tinte-2); }
.statusblock.sync-ausstehend { border-left-color: var(--band); }
.statusblock.sync-synchron { border-left-color: var(--gruen); }
.statusblock.sync-fehler, .statusblock.sync-konflikt { border-left-color: var(--rot); }

.pruefliste { margin-bottom: 22px; }
.pruefliste ul { list-style: none; margin: 0; padding: 0; }
.pruefliste li { padding: 10px 0; border-top: 1px solid var(--linie); }
.fehlerliste h2 { color: var(--rot); }
.hinweisliste h2 { color: var(--orange); }
.wo { display: block; font-size: 0.82rem; color: var(--tinte-2); margin-top: 2px; }
.bereit { font-weight: 750; color: var(--gruen); font-size: 1.05rem; margin-bottom: 22px; }

.aktionen { display: grid; gap: 8px; margin-top: 28px; padding-top: 18px; border-top: 2px solid var(--tinte); }

.banner { margin: 14px 0 0; padding: 14px; background: var(--flaeche); border: 2px solid var(--rot); border-radius: 8px; }
.banner-knoepfe { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.banner-knoepfe .btn { flex: 1 1 12em; }

/* ---------- Untere Leiste ---------- */
.leiste {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  background: var(--flaeche); border-top: 2px solid var(--tinte);
  padding: 10px max(16px, env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}
.leiste-innen { display: flex; gap: 10px; max-width: 648px; margin: 0 auto; }
.leiste-innen .btn:first-child { flex: 0 0 34%; }
.leiste-innen .btn:last-child { flex: 1; }

/* ---------- Dialog und Toast ---------- */
dialog {
  width: calc(100vw - 24px); max-width: 560px; max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: 12px;
  background: var(--flaeche); color: var(--tinte);
}
dialog::backdrop { background: rgba(8, 14, 11, 0.62); }
dialog.voll { width: 100vw; max-width: none; height: 100dvh; max-height: none; margin: 0; border-radius: 0; }
.dlg { padding: 20px; }
.dlg h2 { font-size: 1.25rem; }
.dlg-voll { display: flex; flex-direction: column; gap: 8px; height: 100%; padding: calc(12px + env(safe-area-inset-top)) 16px calc(12px + env(safe-area-inset-bottom)); }
.dlg-knoepfe { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dlg-knoepfe .btn { flex: 1 1 10em; }

#toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); z-index: 60;
  width: max-content; max-width: calc(100vw - 32px); padding: 12px 16px;
  background: var(--kopf); color: var(--kopf-text);
  border-left: 6px solid var(--band); border-radius: 8px;
  font-weight: 600; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  opacity: 0; transform: translate(-50%, 16px); pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
#toast.zeigen { opacity: 1; transform: translate(-50%, 0); }
#toast.ok { border-left-color: #5CC98F; }
#toast.fehler { border-left-color: #FF6A5C; }

@media (min-width: 720px) {
  .band { margin-left: 0; margin-right: 0; border-radius: 0 0 6px 6px; }
  .tabs { margin-left: 0; margin-right: 0; }
}

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