/* Bodenschätzung – mobil zuerst, hell/dunkel, Druckansicht */

:root {
  --bg: #f5f1ea;
  --surface: #ffffff;
  --surface-2: #efe8dd;
  --text: #2a241e;
  --muted: #6d6358;
  --border: #dcd2c4;
  --control: #8a7e70;   /* Rahmen von Bedienelementen: mind. 3:1 (WCAG 1.4.11) */
  --accent: #6f4a2a;
  --accent-text: #ffffff;
  --accent-soft: #f0e3d4;
  --green: #3b6a2a;
  --green-soft: #e3eedb;
  --warn: #8a5300;
  --warn-soft: #fbecd2;
  --err: #a8261d;
  --err-soft: #f9e0dd;
  --focus: #2f6fd1;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(60 40 20 / 8%), 0 2px 8px rgb(60 40 20 / 6%);
  --tabs-h: 62px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a1714;
    --surface: #24201c;
    --surface-2: #2e2924;
    --text: #ece5db;
    --muted: #a99e91;
    --border: #3d3630;
    --control: #857a6d;
    --accent: #d39b65;
    --accent-text: #1a1714;
    --accent-soft: #3a2c1f;
    --green: #8dbb72;
    --green-soft: #26321f;
    --warn: #e6b062;
    --warn-soft: #3a2d18;
    --err: #f08a80;
    --err-soft: #3d1f1c;
    --focus: #7fb0ff;
    --shadow: none;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1a1714; --surface: #24201c; --surface-2: #2e2924; --text: #ece5db; --muted: #a99e91;
  --border: #3d3630; --control: #857a6d; --accent: #d39b65; --accent-text: #1a1714; --accent-soft: #3a2c1f;
  --green: #8dbb72; --green-soft: #26321f; --warn: #e6b062; --warn-soft: #3a2d18;
  --err: #f08a80; --err-soft: #3d1f1c; --focus: #7fb0ff; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom));
}
h1, h2, h3 { line-height: 1.25; margin: 1.2em 0 .5em; }
h1 { font-size: 1.6rem; margin-top: .6em; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---------- Rahmen der App ---------- */
.kopf {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.marke { display: flex; align-items: center; gap: 8px; font-weight: 700; text-decoration: none; color: var(--text); }
.marke svg { color: var(--accent); }
.kopf-rechts { display: flex; align-items: center; gap: 8px; }
.modus { font-size: .8rem; padding: 2px 10px; border-radius: 99px; background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.sync-status {
  font-size: .8rem; font-weight: 600; text-decoration: none; padding: 4px 10px 4px 22px; border-radius: 99px;
  border: 1px solid var(--border); color: var(--text); position: relative; white-space: nowrap; min-height: 32px; display: inline-flex; align-items: center;
}
.sync-status::before { content: ""; position: absolute; left: 9px; top: 50%; width: 8px; height: 8px; margin-top: -4px; border-radius: 50%; background: var(--muted); }
.sync-status[data-art="ok"]::before { background: var(--green); }
.sync-status[data-art="offen"]::before, .sync-status[data-art="laeuft"]::before { background: var(--warn); }
.sync-status[data-art="fehler"]::before { background: var(--err); }

main { max-width: 960px; margin: 0 auto; padding: 0 16px 32px; outline: none; }
.laden { color: var(--muted); padding: 2rem 0; }

.tabs {
  position: fixed; inset: auto 0 0 0; z-index: 10;
  display: grid; grid-template-columns: repeat(6, 1fr);
  height: calc(var(--tabs-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: .68rem; text-decoration: none; color: var(--muted); min-width: 0;
  overflow: hidden; white-space: nowrap;
}
.tabs svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabs a[aria-current="page"] { color: var(--accent); font-weight: 700; box-shadow: inset 0 3px 0 var(--accent); }

@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .tabs { position: sticky; top: 51px; height: auto; display: flex; justify-content: center; gap: 4px; padding: 4px 16px; border-top: 0; border-bottom: 1px solid var(--border); }
  .tabs a { flex-direction: row; font-size: .9rem; gap: 6px; padding: 8px 14px; border-radius: 8px; }
  .tabs a[aria-current="page"] { background: var(--accent-soft); box-shadow: inset 0 -3px 0 var(--accent); }
  .tabs svg { width: 18px; height: 18px; }
}

/* ---------- Grundbausteine ---------- */
.einleitung { font-size: 1.05rem; color: var(--muted); margin-top: 0; }
.hinweis { color: var(--muted); font-size: .88rem; }
.quelle { color: var(--muted); font-size: .78rem; word-break: break-word; }
.nowrap { white-space: nowrap; }

.karte {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; margin: 14px 0; box-shadow: var(--shadow);
}
.karte > h2:first-child, .karte > h3:first-child { margin-top: 0; }

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  min-height: 44px; padding: 8px 16px; border-radius: 8px;
  border: 1px solid var(--control); background: var(--surface-2); color: var(--text);
}
.btn:hover { border-color: var(--accent); }
.btn.primaer { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.btn.klein { min-height: 40px; padding: 6px 12px; font-size: .9rem; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.link-btn {
  font: inherit; background: none; border: 0; padding: 4px 0; color: var(--accent);
  text-decoration: underline; cursor: pointer; text-align: left;
}
.link-btn:disabled { color: var(--muted); text-decoration: none; cursor: default; }
.icon-btn { font-size: 1.6rem; line-height: 1; background: none; border: 0; color: var(--muted); cursor: pointer; width: 44px; height: 44px; }

.aktionen { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0; }

.segmente { display: inline-flex; border: 1px solid var(--control); border-radius: 10px; padding: 3px; background: var(--surface-2); margin: 4px 0 8px; }
.segment { font: inherit; font-weight: 600; border: 0; background: none; color: var(--muted); padding: 8px 18px; border-radius: 8px; min-height: 40px; cursor: pointer; }
.segment[aria-pressed="true"], .segment[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: inset 0 -3px 0 var(--accent); }

/* ---------- Formulare ---------- */
.feld { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; min-width: 0; flex: 1 1 160px; }
.feld.schmal { flex: 0 1 96px; }
.feld-label { font-size: .85rem; font-weight: 600; color: var(--muted); }
input:not([type="checkbox"]):not([type="radio"]), select, textarea {
  font: inherit; width: 100%; min-height: 44px; padding: 8px 10px;
  border: 1px solid var(--control); border-radius: 8px; background: var(--surface); color: var(--text);
}
textarea { resize: vertical; }
::placeholder { color: var(--muted); opacity: 1; }
.reihe { display: flex; flex-wrap: wrap; gap: 0 12px; align-items: flex-end; }
.mit-knopf { display: flex; gap: 8px; }
.mit-knopf select { flex: 1; min-width: 70px; }
.knopf-feld { flex: 0 0 auto; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; cursor: pointer; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; accent-color: var(--accent); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); margin: 12px 0; padding: 6px 14px 8px; }
legend { font-weight: 600; padding: 0 6px; font-size: .92rem; }

.meldung { padding: 8px 12px; border-radius: 8px; font-size: .92rem; margin: 6px 0; background: var(--surface-2); color: var(--text); }
.meldung.ok { background: var(--green-soft); color: var(--green); }
.meldung.warnung, .meldung.kein-rahmen, .meldung.hinweis { background: var(--warn-soft); color: var(--warn); }
.meldung.abweichung { background: var(--err-soft); color: var(--err); }

/* ---------- Tabellen ---------- */
.tabelle-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 8px 0; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.tabelle { border-collapse: collapse; width: 100%; font-size: .92rem; }
.tabelle caption { text-align: left; padding: 10px 12px 4px; font-weight: 600; color: var(--muted); font-size: .85rem; }
.tabelle th, .tabelle td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.tabelle thead th { background: var(--surface-2); font-size: .82rem; white-space: nowrap; }
.tabelle tbody th small { display: block; font-weight: 400; color: var(--muted); font-size: .78rem; }
.symbol { font-weight: 700; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.kompakt { margin: 0; padding-left: 1.1em; }

/* Schätzungsrahmen: schmale Kopfspalten, die beim horizontalen Scrollen stehen bleiben */
.rahmen { --art-b: 46px; --ent-b: 40px; border-collapse: separate; border-spacing: 0; }
.rahmen th, .rahmen td { text-align: center; white-space: nowrap; padding: 7px 6px; font-variant-numeric: tabular-nums; }
.rahmen th.art, .rahmen th.ent { position: sticky; z-index: 1; padding: 7px 4px; }
.rahmen th.art { left: 0; width: var(--art-b); min-width: var(--art-b); max-width: var(--art-b); }
.rahmen th.ent { left: var(--art-b); width: var(--ent-b); min-width: var(--ent-b); max-width: var(--ent-b); box-shadow: inset -1px 0 0 var(--border), 4px 0 6px -4px rgb(0 0 0 / 25%); }
.rahmen tbody th.art { background: var(--surface-2); }
.rahmen tbody th.ent { background: var(--surface); color: var(--muted); }
.rahmen tbody th.art small { display: block; font-size: .68rem; font-weight: 400; color: var(--muted); }
.rahmen abbr { text-decoration: none; cursor: help; }
.rahmen thead th.gruppe { text-align: left; }
.rahmen thead th.gruppe > span { display: inline-block; position: sticky; left: calc(var(--art-b) + var(--ent-b) + 6px); }
.tabellen-titel { margin: 12px 0 0; font-weight: 600; color: var(--muted); font-size: .85rem; }
.rahmen tr.gruppe-start > * { border-top: 2px solid var(--border); }
.rahmen td.wert { cursor: pointer; }
.rahmen td.wert:hover { background: var(--accent-soft); color: var(--text); }
.rahmen td.aktiv, .rahmen td.aktiv:hover { background: var(--accent); color: var(--accent-text); font-weight: 700; }
.rahmen td.leer { color: var(--muted); }
.rahmen td.klein { font-size: .8rem; text-align: left; }
.zellinfo { min-height: 1.5em; font-weight: 600; margin: 4px 0; }

/* ---------- Fingerprobe ---------- */
.verlauf { list-style: none; padding: 0; margin: 0 0 8px; }
.verlauf li { border-left: 3px solid var(--border); padding: 2px 0 2px 12px; }
.verlauf .link-btn { text-decoration: none; display: flex; flex-direction: column; color: var(--text); }
.verlauf-frage { font-size: .82rem; color: var(--muted); }
.verlauf-antwort { font-weight: 600; text-decoration: underline; text-decoration-color: var(--border); }
.schritt { margin: 0; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--accent); font-weight: 700; }
.frage h3 { margin: 4px 0 12px; font-size: 1.15rem; }
.antworten { display: grid; gap: 8px; }
.antwort { text-align: left; }
.ergebnis-karte { border-color: var(--green); }
.ergebnis-karte h3 { font-size: 1.3rem; margin: 4px 0 8px; }
.merkmale dt { font-size: .82rem; color: var(--muted); font-weight: 600; margin-top: 8px; }
.merkmale dd { margin: 0; }
details.direkt { margin-top: 12px; }
details.direkt summary { cursor: pointer; font-weight: 600; padding: 8px 0; }

/* ---------- Zustandsstufe ---------- */
.vorschlag { margin: 12px 0; }
.vorschlag-kopf { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.vorschlag-titel { font-size: 1.25rem; font-weight: 700; margin: 0; }
.seiten-marke { font-size: .78rem; font-weight: 700; padding: 2px 10px; border-radius: 99px; }
.seiten-marke.aufbau { background: var(--green-soft); color: var(--green); }
.seiten-marke.abbau { background: var(--warn-soft); color: var(--warn); }
.gruende { font-size: .9rem; color: var(--muted); padding-left: 1.2em; }
.stufen-karten { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stufe-karte { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; background: var(--surface); }
.stufe-kopf { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 8px; align-items: baseline; }
.stufe-kopf strong { font-size: 1.1rem; }
.stufe-karte ul { padding-left: 1.1em; margin: 8px 0; font-size: .92rem; }
.spanne { font-weight: 600; color: var(--accent); margin: 6px 0; }

/* ---------- Grabloch ---------- */
.schicht { border-top: 1px dashed var(--border); padding: 10px 0 4px; }
.schicht:first-of-type { border-top: 0; padding-top: 0; }
.schicht-kopf { display: flex; justify-content: space-between; align-items: center; }
.zuab { border-top: 1px solid var(--border); margin-top: 14px; }
.zuab-zeile .link-btn { margin-bottom: 18px; }
.ergebnis { border: 2px solid var(--accent); }
.klassenzeichen { font: 700 1.6rem/1.2 ui-monospace, "Cascadia Mono", Consolas, monospace; margin: 4px 0 10px; word-break: break-word; }
.werte { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; margin: 0; }
.werte dt { color: var(--muted); }
.werte dd { margin: 0; font-weight: 600; font-variant-numeric: tabular-nums; }
.werte dd.gross { font-size: 1.3rem; color: var(--accent); }

/* ---------- Feldteil ---------- */
.btn.gefahr { color: var(--err); border-color: var(--err-soft); }
.btn.gefahr:hover { border-color: var(--err); }
a.btn { display: inline-flex; align-items: center; text-decoration: none; }
.feld.voll { flex-basis: 100%; }
.meta-zeile { margin: 6px 0 0; font-size: .78rem; }
.brotkrumen { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: .88rem; margin: 12px 0 0; color: var(--muted); }
.brotkrumen a { color: var(--muted); }
.brotkrumen [aria-current="page"] { color: var(--text); font-weight: 600; text-decoration: none; }
.abschnitt-kopf { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 18px; }
.abschnitt-kopf h2 { margin: 0; }
.eintraege { list-style: none; padding: 0; margin: 10px 0; display: grid; gap: 8px; }
.eintraege a, .kompakt-liste li > span {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.eintraege a:hover { border-color: var(--accent); }
.eintraege a span, .kompakt-liste li > span span { color: var(--muted); font-size: .88rem; }
.formular { max-width: 420px; }
.formular .btn { margin-top: 8px; }
details > summary { cursor: pointer; font-weight: 600; padding: 8px 0; }

/* ---------- Karte (Leaflet) ---------- */
.karte-rahmen {
  position: relative; height: min(70vh, 560px); margin: 12px 0; z-index: 0;
  border: 1px solid var(--border); border-radius: var(--radius); background: #d9d4cb;
}
.karte-rahmen.karte-fehler { height: auto; padding: 12px; background: var(--surface); }
.karte-rahmen.leaflet-container { font: inherit; font-size: .9rem; }
/* Punkte: Farben per CSS, damit sie zum Farbschema passen */
.leaflet-interactive.karte-punkt { stroke: var(--accent); fill: #fff; }
.leaflet-interactive.karte-punkt.bestimmend { stroke: #fff; fill: var(--accent); }
.leaflet-tooltip.karte-beschriftung {
  font: 700 12px/1 system-ui, sans-serif; color: #2a241e; padding: 2px 5px;
  background: rgb(255 255 255 / 88%); border: 0; box-shadow: 0 1px 3px rgb(0 0 0 / 30%);
}
.leaflet-tooltip.karte-beschriftung::before { display: none; }
.karte-popup { display: grid; gap: 4px; font-size: .9rem; color: #2a241e; }
.karte-popup a { font-weight: 600; color: #6f4a2a; }
.leaflet-touch .leaflet-bar a { width: 40px; height: 40px; line-height: 40px; }
/* Eigener Standort: Kartenfarben fest (Kacheln sind immer hell) */
.karte-standort-knopf {
  display: grid; place-items: center; width: 34px; height: 34px; padding: 0; margin: 0;
  border: 0; border-radius: 4px; background: #fff; color: #2a241e; cursor: pointer;
}
.leaflet-touch .karte-standort-knopf { width: 40px; height: 40px; }
.karte-standort-knopf:hover { background: #f4f4f4; }
.karte-standort-knopf svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.karte-standort-knopf svg .kern { fill: currentColor; stroke: none; opacity: 0; }
.karte-standort-knopf[aria-pressed="true"] { color: #1557c0; }
.karte-standort-knopf[aria-pressed="true"] svg .kern { opacity: 1; }
.karte-standort-knopf.sucht svg { animation: karte-sucht 1.2s ease-in-out infinite; }
@keyframes karte-sucht { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .karte-standort-knopf.sucht svg { animation: none; } }
.leaflet-interactive.karte-ich { stroke: #fff; fill: #1557c0; }
.leaflet-interactive.karte-genauigkeit { stroke: #1557c0; stroke-width: 1.5; fill: #1557c0; fill-opacity: .12; }
.karte-meldung { margin: -4px 0 12px; }
.karte-meldung:empty { display: none; }
.legende { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 3px solid var(--accent); vertical-align: middle; }
.legende.bestimmend { background: var(--accent); }

/* ---------- Dialog ---------- */
.dialog {
  width: min(720px, calc(100vw - 16px)); max-height: calc(100dvh - 16px);
  padding: 0; border: 1px solid var(--border); border-radius: 14px;
  background: var(--bg); color: var(--text);
}
.dialog::backdrop { background: rgb(0 0 0 / 45%); }
.dialog-kopf { position: sticky; top: 0; z-index: 1; display: flex; justify-content: space-between; align-items: center; padding: 6px 8px 6px 16px; background: var(--surface); border-bottom: 1px solid var(--border); }
.dialog-kopf h2 { margin: 0; font-size: 1.1rem; }
.dialog-inhalt { padding: 4px 16px 16px; }

/* ---------- Start & Wissen ---------- */
.kacheln { display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin: 16px 0; }
.kachel {
  display: flex; flex-direction: column; gap: 4px; padding: 16px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.kachel strong { color: var(--accent); font-size: 1.08rem; }
.kachel span { color: var(--muted); font-size: .92rem; }
.kachel:hover { border-color: var(--accent); }
.wissen .inhalt { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.wissen .inhalt a { padding: 6px 12px; border-radius: 99px; background: var(--surface-2); text-decoration: none; font-size: .9rem; }
.wissen section { scroll-margin-top: 120px; }
.begriffe dt { font-weight: 700; margin-top: 10px; }
.begriffe dd { margin: 2px 0 0; }

/* ---------- Druck ---------- */
.nur-druck { display: none; }
@media print {
  :root { --bg: #fff; --surface: #fff; --surface-2: #f2f2f2; --text: #000; --muted: #444; --border: #999; }
  body { padding: 0; font-size: 11pt; background: #fff; }
  .kein-druck, .kopf, .tabs, dialog { display: none !important; }
  .nur-druck { display: block; }
  main { max-width: none; padding: 0; }
  .bericht h1 { font-size: 16pt; margin: 0 0 4pt; }
  .bericht h2 { font-size: 12pt; margin: 12pt 0 4pt; }
  .bericht-meta { color: #444; margin: 0 0 8pt; }
  .bericht .tabelle { font-size: 9.5pt; }
  .bericht .tabelle th, .bericht .tabelle td { padding: 3pt 5pt; border: 1px solid #999; }
  .bericht .tabelle.schmal { width: auto; min-width: 60%; }
  .bericht tr { break-inside: avoid; }
  .seitenumbruch { break-before: page; }
}
