:root {
  --bg: #f6f5f0;
  --surface: #ffffff;
  --surface-2: #eceae1;
  --text: #1c2420;
  --muted: #55605a;
  --line: #d6d3c6;
  --brand: #2f6b3a;
  --brand-text: #ffffff;
  --brand-soft: #dcebdc;
  --ok: #1f6b34;
  --ok-bg: #e0f0e3;
  --nein: #9b2c2c;
  --nein-bg: #f7e1e0;
  --pruefen: #8a5a00;
  --pruefen-bg: #fbefcf;
  --teil: #1f5a7a;
  --teil-bg: #dcecf5;
  --focus: #0b57d0;
  --manuell: #a24b00;
  --manuell-bg: #fde7d0;
  --radius: 14px;
  --tap: 52px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101612;
    --surface: #1a221d;
    --surface-2: #232d26;
    --text: #e8ece8;
    --muted: #a3afa7;
    --line: #34423a;
    --brand: #5fa66b;
    --brand-text: #08140b;
    --brand-soft: #1f3324;
    --ok: #7fd18f;
    --ok-bg: #19301f;
    --nein: #f19a96;
    --nein-bg: #3a1e1d;
    --pruefen: #f0c36a;
    --pruefen-bg: #38300f;
    --teil: #8cc4e3;
    --teil-bg: #1a2e3a;
    --focus: #8ab4f8;
    --manuell: #ffb066;
    --manuell-bg: #3d2610;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 17px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.skip { position: absolute; left: -999px; }
.skip:focus { left: 8px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }

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

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--brand); color: var(--brand-text);
}
.topbar-title { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title span { font-size: 13px; opacity: .9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.icon-btn {
  appearance: none; border: 0; background: transparent; color: inherit;
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: rgb(255 255 255 / .15); }

main {
  max-width: 720px; margin: 0 auto;
  padding: 16px 16px 40px;
  outline: none;
}

h1 { font-size: 1.55rem; line-height: 1.25; margin: 8px 0 12px; }
h2 { font-size: 1.15rem; line-height: 1.3; margin: 24px 0 8px; }
p { margin: 0 0 12px; }

.notice {
  background: var(--pruefen-bg); color: var(--pruefen);
  border-radius: var(--radius); padding: 12px 14px; margin: 12px 0 20px;
  font-size: 0.95rem;
}

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px; margin: 12px 0;
}

.progress { color: var(--muted); font-size: 0.9rem; margin: 4px 0 0; }

.question { font-size: 1.3rem; line-height: 1.35; margin: 6px 0 14px; font-weight: 650; }

.btn {
  appearance: none; display: block; width: 100%; text-align: left;
  min-height: var(--tap); padding: 12px 16px; margin: 10px 0;
  font: inherit; font-weight: 600; color: var(--text);
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  cursor: pointer;
}
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-text); border-color: var(--brand); text-align: center; }
.btn.secondary { background: var(--surface-2); text-align: center; font-weight: 500; }
.btn.small { display: inline-block; width: auto; min-height: 44px; margin: 4px 8px 4px 0; padding: 8px 14px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.module-btn strong { display: block; font-size: 1.1rem; }
.module-btn span { display: block; font-weight: 400; color: var(--muted); font-size: 0.95rem; margin-top: 2px; }

details.hilfe {
  background: var(--surface-2); border-radius: var(--radius);
  padding: 10px 14px; margin: 10px 0;
}
details.hilfe summary { cursor: pointer; font-weight: 600; min-height: 32px; }
details.hilfe p { margin: 8px 0 0; font-size: 0.98rem; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 12px 0 4px; }
.chips-label { width: 100%; font-size: 0.85rem; color: var(--muted); margin: 0; }
.chip {
  appearance: none; font: inherit; font-size: 0.88rem; cursor: pointer;
  min-height: 36px; padding: 4px 12px; border-radius: 999px;
  background: var(--brand-soft); color: var(--text); border: 1px solid var(--line);
}
.chip.warn { background: var(--pruefen-bg); color: var(--pruefen); border-color: transparent; }

.num-row { display: flex; gap: 8px; align-items: center; margin: 12px 0; }
.num-row input {
  flex: 1; min-height: var(--tap); font: inherit; font-size: 1.2rem;
  padding: 8px 14px; border-radius: var(--radius);
  border: 2px solid var(--line); background: var(--surface); color: var(--text);
}
.num-row .unit { font-weight: 600; }
.error { color: var(--nein); margin: 4px 0 8px; font-size: 0.95rem; }

.nav-row { display: flex; gap: 8px; margin-top: 18px; }
.nav-row .btn { margin: 0; text-align: center; }

.result {
  border-radius: var(--radius); padding: 16px; margin: 8px 0 12px;
  border: 2px solid transparent;
}
.result h1 { margin-top: 0; }
.result .badge {
  display: inline-block; font-size: 0.85rem; font-weight: 700; letter-spacing: .02em;
  padding: 2px 10px; border-radius: 999px; margin-bottom: 8px; background: rgb(0 0 0 / .08);
}
.result.ok { background: var(--ok-bg); color: var(--ok); border-color: var(--ok); }
.result.nein { background: var(--nein-bg); color: var(--nein); border-color: var(--nein); }
.result.pruefen { background: var(--pruefen-bg); color: var(--pruefen); border-color: var(--pruefen); }
.result.teil { background: var(--teil-bg); color: var(--teil); border-color: var(--teil); }
.result p { color: var(--text); }

ol.pfad { list-style: none; padding: 0; margin: 8px 0; counter-reset: s; }
ol.pfad li {
  counter-increment: s; position: relative;
  padding: 10px 12px 10px 44px; margin: 8px 0;
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
}
ol.pfad li::before {
  content: counter(s); position: absolute; left: 10px; top: 10px;
  width: 24px; height: 24px; border-radius: 50%;
  display: grid; place-items: center; font-size: 0.8rem; font-weight: 700;
  background: var(--brand); color: var(--brand-text);
}
ol.pfad .f { display: block; color: var(--muted); font-size: 0.92rem; }
ol.pfad .a { display: block; font-weight: 650; }
ol.pfad .r { display: block; font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.status-badge {
  display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 1px 8px;
  border-radius: 999px; margin-right: 6px;
}
.status-gelesen { background: var(--ok-bg); color: var(--ok); }
.status-teilweise, .status-indirekt { background: var(--teil-bg); color: var(--teil); }
.status-offen { background: var(--pruefen-bg); color: var(--pruefen); }

.src h3 { margin: 0 0 4px; font-size: 1rem; }
.src p { margin: 4px 0; font-size: 0.93rem; color: var(--muted); }
.src a { color: var(--brand); font-weight: 600; }
@media (prefers-color-scheme: dark) { .src a { color: #8fd09b; } }

dialog {
  width: min(92vw, 560px); max-height: 85vh; overflow: auto;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--text); padding: 18px;
}
dialog::backdrop { background: rgb(0 0 0 / .5); }
dialog h2 { margin-top: 0; }
.sheet-actions { margin-top: 12px; }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%); background: var(--text); color: var(--bg);
  padding: 10px 16px; border-radius: 999px; font-size: 0.95rem; z-index: 20;
}

@media (prefers-reduced-motion: no-preference) {
  main > * { animation: in .18s ease-out; }
  @keyframes in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
}

/* ---------- Ergänzungen: Bibliothek, Dialoge, Editor ---------- */

.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; align-items: center; }
.row-actions .grow { flex: 1; min-width: 0; }
.btn.small.linkbtn { text-decoration: none; display: inline-flex; align-items: center; color: var(--text); font-weight: 600; }
.btn.danger { border-color: var(--nein); color: var(--nein); }
.btn.small.primary { background: var(--brand); color: var(--brand-text); border-color: var(--brand); }
.btn.small.icon { min-width: 40px; padding: 6px 10px; text-align: center; }
.btn.warn { background: var(--pruefen-bg); color: var(--pruefen); border-color: var(--pruefen); }

.search {
  width: 100%; min-height: 48px; font: inherit; padding: 8px 14px; margin: 8px 0;
  border-radius: var(--radius); border: 2px solid var(--line); background: var(--surface); color: var(--text);
}
.hit { display: block; text-align: left; }
.hit span { display: block; font-weight: 400; color: var(--muted); font-size: .92rem; margin-top: 2px; }
mark { background: #ffe08a; color: #000; border-radius: 3px; padding: 0 1px; }

.law-text .z { margin: 0 0 7px; }
.law-text .i1 { margin-left: 1.3em; }
.law-text .i2 { margin-left: 2.6em; }
.law-text .i3 { margin-left: 3.9em; }
.law-text .fn { font-size: .88rem; color: var(--muted); font-style: italic; }
.law-text h3 { font-size: 1.05rem; margin: 22px 0 6px; scroll-margin-top: 70px; }
.law-text .abschnitt { font-size: 1.2rem; margin: 30px 0 4px; color: var(--brand); }
.norm { border-radius: 10px; padding: 0 6px; }
.norm.flash { background: var(--pruefen-bg); transition: background .4s; }
.toc { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow: auto; margin-top: 8px; }
.toc-item { text-align: left; background: none; border: 0; padding: 6px 4px; font: inherit; color: var(--text); cursor: pointer; min-height: 36px; border-radius: 8px; }
.toc-item:hover { background: var(--surface); }
.toc-item.chg { color: var(--manuell); font-weight: 600; }
.toc-sec { font-weight: 700; margin-top: 8px; color: var(--muted); font-size: .9rem; }
.geaendert { color: var(--manuell); }
.card.aktiv { border-color: var(--brand); }

.status-badge.manuell { background: var(--manuell-bg); color: var(--manuell); }
.manuell-box { background: var(--manuell-bg); color: var(--manuell); }
ol.pfad li.manuell { border-color: var(--manuell); }
ol.pfad .m { display: block; font-size: .85rem; color: var(--manuell); margin-top: 2px; }

.update-banner {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 10px 14px; background: var(--teil-bg); color: var(--teil); border-bottom: 1px solid var(--line);
}
.update-banner span { flex: 1; min-width: 12em; font-weight: 600; }
.update-banner .btn { margin: 0; }

.field { display: block; margin: 10px 0; }
.field > span { display: block; font-size: .85rem; color: var(--muted); margin-bottom: 3px; }
.field input, .field textarea, .field select, .ins-select, .ed-inspector select {
  width: 100%; font: inherit; padding: 8px 10px; min-height: 40px; border-radius: 10px;
  border: 1.5px solid var(--line); background: var(--surface); color: var(--text);
}
dialog.modal { width: min(92vw, 520px); }
dialog.modal .btn { margin: 6px 0; }
dialog.modal .sheet-actions .btn { margin: 4px 8px 4px 0; }

.check { list-style: none; padding: 0; margin: 0 0 10px; }
.check li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.check li span { display: block; font-size: .88rem; color: var(--muted); }
.check .gut strong { color: var(--ok); }
.check .schlecht strong { color: var(--nein); }

/* ---------- Editor ---------- */

html, body { max-width: 100%; overflow-x: hidden; }
body.editor-active { overflow: hidden; touch-action: pan-x pan-y; }
body.editor-active .ed { overflow: hidden; width: 100%; }
body.editor-active .ed-toolbar { overflow: hidden; }
body.editor-active main { max-width: none; padding: 0; }
body.editor-active #update-slot { display: none; }
.ed, .ed-toolbar, .ed-main, .ed-viewport, .ed-inspector, .ed-tools { min-width: 0; max-width: 100%; }
.ed { display: flex; flex-direction: column; height: calc(100dvh - 62px - env(safe-area-inset-top)); }
.ed-toolbar { display: flex; flex-wrap: wrap; gap: 6px; justify-content: space-between; padding: 6px 8px; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.ed-tools { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.ed-tools .btn, .ed-tools select { margin: 0; min-height: 38px; }
.ed-tools select { font: inherit; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface); color: var(--text); padding: 4px 8px; }
.ed-count { font-size: .82rem; color: var(--muted); }
.ed-main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.ed-viewport {
  position: relative; overflow: hidden; touch-action: none; cursor: grab; min-height: 0;
  background-color: var(--bg);
  background-image: radial-gradient(var(--line) 1.2px, transparent 1.2px); background-size: 22px 22px;
}
.ed-viewport:active { cursor: grabbing; }
.ed-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.ed-label { position: absolute; font-weight: 700; font-size: 22px; color: var(--muted); white-space: nowrap; pointer-events: none; }
.ed-node {
  position: absolute; background: var(--surface); border: 2px solid var(--line); border-radius: 12px;
  box-shadow: 0 1px 4px rgb(0 0 0 / .12); user-select: none; -webkit-user-select: none;
}
.ed-node.sel { border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 30%, transparent); }
.ed-node.manuell { border-color: var(--manuell); }
.ed-node.drop { outline: 3px dashed var(--focus); outline-offset: 3px; }
.ed-node.drag { box-shadow: 0 8px 22px rgb(0 0 0 / .3); z-index: 5; }
.ed-head { display: flex; gap: 6px; align-items: center; padding: 6px 10px; border-radius: 10px 10px 0 0; font-size: 12px; font-weight: 700; cursor: grab; background: var(--brand-soft); }
.t-zahl .ed-head { background: var(--teil-bg); }
.t-hinweis .ed-head { background: var(--pruefen-bg); }
.t-ergebnis.s-ok .ed-head { background: var(--ok-bg); }
.t-ergebnis.s-nein .ed-head { background: var(--nein-bg); }
.t-ergebnis.s-pruefen .ed-head { background: var(--pruefen-bg); }
.t-ergebnis.s-teil .ed-head { background: var(--teil-bg); }
.ed-id { margin-left: auto; font-weight: 400; color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.ed-start, .ed-badge { font-size: 10px; padding: 1px 7px; border-radius: 999px; background: var(--brand); color: var(--brand-text); }
.ed-badge { background: var(--manuell); color: var(--surface); }
.ed-body { padding: 8px 10px; font-size: 13px; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.ed-outs { list-style: none; margin: 0; padding: 0 0 6px; }
.ed-out { display: flex; align-items: center; gap: 4px; padding: 3px 0 3px 4px; font-size: 12px; border-top: 1px solid var(--line); }
.ed-lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ed-out.ziehen { background: var(--brand-soft); }
.ed-grip, .grip { cursor: grab; touch-action: none; color: var(--muted); padding: 6px 4px; user-select: none; -webkit-user-select: none; }
.ed-grip.off { visibility: hidden; padding: 0 6px; }
.ed-port {
  position: relative; width: 16px; height: 16px; flex: none; margin-right: -10px; border-radius: 50%;
  background: var(--brand); border: 2px solid var(--surface); box-shadow: 0 0 0 2px var(--brand); cursor: crosshair; touch-action: none;
}
.ed-port::after { content: ''; position: absolute; inset: -12px; }
.ed-port.offen { background: var(--surface); box-shadow: 0 0 0 2px var(--nein); }
.ed-edge { color: #8a948d; }
.ed-edge path { fill: none; stroke: currentColor; stroke-width: 2; }
.ed-edge polygon { fill: currentColor; }
.ed-edge.x-ok { color: var(--ok); }
.ed-edge.x-nein { color: var(--nein); }
.ed-edge.x-pruefen { color: var(--pruefen); }
.ed-edge.x-teil { color: var(--teil); }
.ed-edge.chg { color: var(--manuell); }
.ed-edge.chg path { stroke-dasharray: 7 4; stroke-width: 3; }
.ed-temp { fill: none; stroke: var(--focus); stroke-width: 2.5; stroke-dasharray: 4 4; }
.ed-ghost { position: fixed; transform: translate(-50%, -50%); pointer-events: none; padding: 8px 14px; border-radius: 999px; background: var(--brand); color: var(--brand-text); z-index: 50; font-weight: 600; }

.ed-inspector { overflow: auto; padding: 12px; background: var(--surface); border-left: 1px solid var(--line); min-height: 0; }
.ed-inspector h3 { font-size: 1rem; margin: 16px 0 6px; }
.ins-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.ins-foot { margin-top: 18px; }
.ins-foot .btn { margin: 0; }
.tips { padding-left: 1.1em; font-size: .9rem; color: var(--muted); }
.probleme { padding-left: 1.1em; font-size: .9rem; }
.linklike { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); text-decoration: underline; cursor: pointer; }
.rows .row { display: flex; gap: 4px; align-items: flex-start; border: 1px solid var(--line); border-radius: 10px; padding: 6px; margin: 6px 0; background: var(--surface-2); }
.rows .row.ziehen { opacity: .65; box-shadow: 0 4px 12px rgb(0 0 0 / .25); }
.row-fields { flex: 1; min-width: 0; }
.row-fields .field { margin: 6px 0; }
.inline { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.btn.small.rm { margin: 4px 0; min-height: 36px; padding: 4px 10px; }
.chip.rm { display: inline-flex; align-items: center; gap: 2px; }
.chip.rm button { border: 0; background: transparent; font-size: 18px; line-height: 1; cursor: pointer; color: inherit; padding: 0 2px; }

@media (max-width: 820px) {
  .ed-main { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .ed-inspector { max-height: 40vh; border-left: 0; border-top: 1px solid var(--line); }
  .ed-toolbar { flex-direction: column; gap: 4px; padding: 4px 6px; }
  .ed-tools { flex-wrap: nowrap; overflow-x: auto; }
  .ed-tools .btn, .ed-tools select { flex: none; white-space: nowrap; min-height: 34px; padding: 4px 10px; font-size: .9rem; }
  .ed-count { display: none; }
}
.check .neutral strong { color: var(--muted); }

/* Aktualisierungsseite */
.upd-punkt { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.upd-punkt input { flex: none; width: 22px; height: 22px; margin-top: 2px; }
.upd-punkt label { min-width: 0; overflow-wrap: anywhere; }
.upd-punkt label span { display: block; font-size: .9rem; color: var(--muted); }
.upd-row, .upd-law { padding: 8px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.upd-links { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 4px; }
.upd-prompt { width: 100%; box-sizing: border-box; font: .85rem/1.4 ui-monospace, monospace; background: var(--surface-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.pruef-btn strong { display: block; font-variant-numeric: tabular-nums; }
.pruef-btn span { display: block; font-weight: 400; color: var(--muted); font-size: .9rem; }
details.bisher { margin: 6px 0 10px; }

.tabs { display: flex; gap: 4px; margin: 0 0 12px; border-bottom: 2px solid var(--line); }
.tab { flex: 1; background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -2px; padding: 10px 6px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; min-height: 44px; }
.tab.aktiv { color: var(--brand); border-bottom-color: var(--brand); }

/* Fälle, Übernahme von Angaben, Rückweg */
.btn.vorgabe { border-color: var(--brand); box-shadow: inset 0 0 0 2px var(--brand); }
.btn .vg { display: block; font-weight: 400; font-size: .85rem; color: var(--muted); margin-top: 2px; }
.btn .sub { display: block; font-weight: 400; font-size: .9rem; margin-top: 2px; opacity: .9; }
.vorgabe-box { border-left: 4px solid var(--brand); }
.btn.rueck { margin-top: 12px; }
ol.pfad .u { display: block; font-size: .85rem; color: var(--brand); margin-top: 2px; }
ol.pfad li .btn.small { margin: 6px 0 0; }
ul.plain { list-style: none; padding: 0; margin: 8px 0; }
ul.plain li { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.fall-btn strong { font-variant-numeric: tabular-nums; }

details.weitere { margin: 1rem 0; }
details.weitere > summary { font-size: 1.25rem; font-weight: 700; cursor: pointer; padding: .5rem 0; }
ul.gebiet-liste li { display: block; padding: 10px 12px; margin: 8px 0; border: 1px solid var(--line, #d8d4c8); border-radius: 10px; background: #fff; }
ul.gebiet-liste li > span { display: block; font-size: .92rem; color: var(--muted, #555); }
ul.gebiet-liste li > span.kat { color: inherit; font-weight: 600; margin-top: 2px; }
.btn.werkzeug { margin-top: 8px; }
