[hidden] { display: none !important; }
/* Browser-Testmodus: ruhiges, modernes Layout; funktioniert ab 320 px Breite, ohne Inline-Stile (CSP). */
:root {
  color-scheme: light;
  --bg: #f4f6fb; --card: #ffffff; --text: #1b2333; --muted: #5b6577; --line: #e2e7f0;
  --primary: #2453d6; --primary-dark: #1b40a8; --primary-soft: #eaf0ff;
  --on-primary: #ffffff; --ok: #157347; --ok-soft: #e7f6ee; --bad: #b42318; --bad-soft: #fdecea; --warn: #8a5a00; --warn-soft: #fff6dd;
  --radius: 14px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
}
/* Dunkel: automatisch nach Systemeinstellung, außer ausdrücklich „Hell“ gewählt; oder ausdrücklich „Dunkel“. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]) {
    color-scheme: dark;
    --bg: #0f1422; --card: #171e2f; --text: #e6eaf3; --muted: #9aa6bd; --line: #2a3448;
    --primary: #6d93ff; --primary-dark: #8aa8ff; --primary-soft: #1f2a46; --on-primary: #0b1020;
    --ok: #5fd39a; --ok-soft: #12301f; --bad: #ff8a80; --bad-soft: #3a1a1a; --warn: #f5c45b; --warn-soft: #33290f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
  }
}
:root[data-theme=dark] {
  color-scheme: dark;
  --bg: #0f1422; --card: #171e2f; --text: #e6eaf3; --muted: #9aa6bd; --line: #2a3448;
  --primary: #6d93ff; --primary-dark: #8aa8ff; --primary-soft: #1f2a46; --on-primary: #0b1020;
  --ok: #5fd39a; --ok-soft: #12301f; --bad: #ff8a80; --bad-soft: #3a1a1a; --warn: #f5c45b; --warn-soft: #33290f;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .3);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 16px/1.55 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 1.6rem; line-height: 1.25; margin: 0 0 .5rem; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .25rem; }
p { margin: .4rem 0 .8rem; }
code { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .9em; background: var(--primary-soft); padding: 0 .3em; border-radius: 4px; word-break: break-all; }

/* Kopf */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.brand { font-weight: 700; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.logo { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; background: var(--primary-soft); }
.topbar nav { display: flex; flex-wrap: wrap; gap: 4px; flex: 1 1 auto; }
.topbar nav button { background: transparent; border: 0; color: var(--muted); padding: 8px 12px; border-radius: 999px; font-weight: 500; }
.topbar nav button:not([aria-current=page]):hover { background: var(--primary-soft); color: var(--primary); }
.topbar nav button[aria-current=page] { background: var(--primary); color: var(--on-primary); }
.testbanner { margin: 0; padding: 6px 20px; background: var(--warn-soft); color: var(--warn); font-size: .85rem; text-align: center; }

main { max-width: 1040px; margin: 0 auto; padding: 24px 16px 48px; }
main.narrow { max-width: 460px; }

/* Karten */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; margin: 0 0 18px; box-shadow: var(--shadow); }
.hero { text-align: left; padding: 32px; }
.lead { font-size: 1.08rem; color: var(--muted); max-width: 46em; }
.grid { display: grid; grid-template-columns: 1fr; gap: 18px; }
.grid .card { margin: 0; }
.action p { color: var(--muted); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.status-card { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.meta { color: var(--muted); margin: 0; }
.hint-line { color: var(--muted); margin: -6px 4px 18px; }
.state { padding: 8px 14px; border-radius: 999px; font-weight: 600; white-space: nowrap; }
.state.active { background: var(--ok-soft); color: var(--ok); }
.state.released { background: var(--warn-soft); color: var(--warn); }
.state.unknown { background: var(--bad-soft); color: var(--bad); }
.state-inline { padding: 10px 14px; border-radius: 10px; }
.state-inline.ok { background: var(--ok-soft); color: var(--ok); }
.state-inline.wait { background: var(--warn-soft); color: var(--warn); }

/* Listen */
.howto, .timeline { padding-left: 1.3em; }
.howto li, .timeline li { margin: .35rem 0; }
.checklist { list-style: none; padding: 0; }
.checklist li::before { content: "✓ "; color: var(--ok); font-weight: 700; }
.checklist li.offen { color: var(--bad); }
.checklist li.offen::before { content: "✗ "; color: var(--bad); }
.banner { padding: 12px 16px; border-radius: 12px; margin: 0 0 16px; }
.banner p { margin: 4px 0; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-left: 6px solid var(--warn); }
.status-list { list-style: none; padding: 0; }
.status-list li { padding: 6px 0; }
.files { padding-left: 1.2em; word-break: break-all; font-size: .9rem; }

/* Schrittanzeige */
.stepper { display: flex; gap: 8px; list-style: none; padding: 0; margin: 0 0 20px; flex-wrap: wrap; counter-reset: s; }
.stepper li { flex: 1 1 120px; padding: 8px 10px; border-radius: 10px; background: var(--primary-soft); color: var(--muted); font-size: .9rem; font-weight: 600; }
.stepper li::before { content: attr(data-step-label) " · "; }
.stepper li.current { background: var(--primary); color: var(--on-primary); }
.stepper li.done { background: var(--ok-soft); color: var(--ok); }

/* Formulare */
label { display: block; margin: 0 0 14px; font-weight: 600; }
input[type=text], input[type=password], input[type=email], #mail-karte input[type=number], select, textarea { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; font-weight: 400; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 10px; transition: border-color .15s, box-shadow .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(36, 83, 214, .18); }
textarea { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .85rem; resize: vertical; }
fieldset { border: 0; padding: 0; margin: 0 0 14px; min-width: 0; }
legend { font-weight: 600; margin-bottom: 8px; padding: 0; }
.choices { display: grid; gap: 10px; }
.choice { display: grid; grid-template-columns: auto 1fr; gap: 2px 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; cursor: pointer; margin: 0; font-weight: 400; }
.choice:hover { border-color: var(--muted); }
.choice input { grid-row: 1 / span 2; margin-top: 4px; accent-color: var(--primary); }
.choice-title { font-weight: 600; }
.choice-text { color: var(--muted); font-size: .92rem; }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice:has(input:disabled) { opacity: .55; cursor: not-allowed; }
.choices.compact .choice { padding: 8px 12px; }
.help { color: var(--muted); font-size: .92rem; font-weight: 400; }

/* Knöpfe */
button, a.button { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 600; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s; }
button.primary, a.button.primary { background: var(--primary); color: var(--on-primary); }
button.primary:hover { background: var(--primary-dark); }
button.secondary, a.button.secondary { background: var(--primary-soft); color: var(--primary); }
button.ghost, a.button.ghost { background: transparent; color: var(--primary); border-color: var(--line); }
button.ghost:hover, a.button.ghost:hover { border-color: var(--primary); }
button.big { padding: 14px 26px; font-size: 1.05rem; }
button.small, a.button.small { padding: 6px 12px; font-size: .9rem; }
button:disabled { opacity: .6; cursor: wait; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
textarea + button, label + button.small { margin-top: -6px; margin-bottom: 14px; }

/* Rückmeldungen direkt am Knopf */
.feedback:empty { display: none; }
.feedback { margin-top: 12px; padding: 12px 14px; border-radius: 10px; font-weight: 500; }
.feedback p { margin: 0; }
.feedback.success { background: var(--ok-soft); color: var(--ok); }
.feedback.error { background: var(--bad-soft); color: var(--bad); }
.feedback.busy, .feedback.info { background: var(--primary-soft); color: var(--primary-dark); }
.feedback.busy p::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
.tech { margin-top: 8px; font-weight: 400; color: var(--muted); }
.tech pre { white-space: pre-wrap; word-break: break-word; font-size: .8rem; background: var(--card); padding: 8px; border-radius: 8px; }

/* Aufklapper */
details > summary { cursor: pointer; font-weight: 600; color: var(--primary); padding: 4px 0; }
details[open] > summary { margin-bottom: 10px; }
.expert > summary { color: var(--muted); }

/* „?“-Hinweise beim Darüberfahren oder Fokus */
.tip { position: relative; display: inline-grid; place-items: center; width: 20px; height: 20px; margin-left: 4px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); font-size: .8rem; font-weight: 700; cursor: help; vertical-align: 2px; }
.tip::after { content: attr(data-tip); position: absolute; left: 50%; top: 130%; transform: translateX(-50%); width: min(280px, 80vw); padding: 10px 12px; background: var(--text); color: var(--card); font-size: .85rem; font-weight: 400; line-height: 1.4; border-radius: 10px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .15s; z-index: 10; text-align: left; }
.tip:hover::after, .tip:focus::after { opacity: 1; }

/* Notfallblätter */
.sheets { display: grid; gap: 12px; }
.sheet { border: 1px solid var(--line); border-left: 5px solid var(--primary); border-radius: 12px; padding: 12px 14px; }
.sheet.r { border-left-color: var(--bad); }
.sheet h3 { margin-top: 0; }
.sheet-lines { margin-top: 10px; display: grid; gap: 8px; }
.sheet-lines .line { display: grid; grid-template-columns: minmax(80px, auto) 1fr; gap: 2px 10px; padding: 8px; background: var(--bg); border-radius: 8px; }
.sheet-lines .key { font-weight: 700; }
.sheet-lines .val { background: transparent; padding: 0; }
.sheet-lines .explain { grid-column: 2; color: var(--muted); font-size: .9rem; }
.sheet-lines .hinweis { grid-column: 1 / -1; color: var(--muted); font-size: .9rem; }

/* Post */
.mails { display: grid; gap: 8px; }
.mail { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; }
.mail summary { color: var(--text); }
.mail .meta { font-weight: 400; color: var(--muted); }
.mail .when { display: inline-block; min-width: 9.5em; margin-right: 10px; color: var(--muted); font-weight: 400; font-variant-numeric: tabular-nums; }
.mailtext { white-space: pre-wrap; word-break: break-word; font-size: .8rem; background: var(--bg); padding: 10px; border-radius: 8px; max-height: 260px; overflow: auto; }

/* Hilfe */
.prose { max-width: 820px; }
.prose dt { font-weight: 700; margin-top: 12px; }
.prose dd { margin: 4px 0 0; color: var(--text); }
.prose ul { margin: 6px 0; }

/* Anmeldung */
#meldung { color: var(--bad); }
dialog { border: 0; border-radius: var(--radius); box-shadow: var(--shadow); width: min(520px, 94vw); padding: 22px; }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog select { width: 100%; }
menu { display: flex; gap: 10px; justify-content: flex-end; padding: 0; margin: 14px 0 0; }

@media (max-width: 640px) {
  body { font-size: 15px; }
  .topbar { padding: 8px 12px; }
  .topbar nav button { padding: 6px 10px; }
  main { padding: 14px 10px 40px; }
  .card, .hero { padding: 16px; }
  h1 { font-size: 1.35rem; }
  .grid { grid-template-columns: 1fr; }
  .sheet-lines .line { grid-template-columns: 1fr; }
  .sheet-lines .explain { grid-column: 1; }
  .tip::after { left: auto; right: -10px; transform: none; }
}

/* Countdown */
.countdown { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: center; }
.countdown.ok { border-left: 6px solid var(--ok); }
.countdown.warn { border-left: 6px solid var(--warn); background: var(--warn-soft); }
.countdown.done { border-left: 6px solid var(--muted); }
.countdown p { margin: 0; }
.cd-label { color: var(--muted); font-weight: 600; }
.cd-big { font-size: 2.6rem; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.cd-mid { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.cd-sub { color: var(--muted); font-size: .92rem; }
.cd-side { border-left: 1px solid var(--line); padding-left: 18px; display: grid; gap: 2px; }
@media (max-width: 640px) {
  .countdown { grid-template-columns: 1fr; }
  .cd-side { border-left: 0; border-top: 1px solid var(--line); padding: 12px 0 0; }
  .cd-big { font-size: 2rem; }
}

/* Gefahrenbereich */
.action.danger { border-color: var(--bad); }
button.danger { background: var(--bad); color: var(--on-primary); }

/* Druckansicht: nur das gewählte Blatt */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0 0 12px; }
.kv dt { font-weight: 600; }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.kv code.fp { letter-spacing: .02em; }
@media (max-width: 520px) { .kv { grid-template-columns: 1fr; } .kv dd { margin-bottom: 6px; } }
.notfallkarte-mini { margin: 10px 0; padding: 10px 14px; border: 1px dashed var(--line); border-radius: 10px; }
.notfallkarte-mini h4 { margin: 0 0 6px; font-size: .95rem; }
@media print {
  body.print-sheet * { visibility: hidden; }
  body.print-sheet .to-print, body.print-sheet .to-print * { visibility: visible; }
  body.print-sheet .to-print { position: absolute; left: 0; top: 0; width: 100%; border: 0; }
  body.print-sheet .to-print .actions { display: none; }
}

/* Fristen und zweite Adresse */
fieldset.fristen { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 0 0 14px; }
fieldset.fristen legend { padding: 0 6px; font-weight: 600; }
fieldset.fristen label, #fristen-form label { display: block; margin: 8px 0; }
[data-adressen] .line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 8px; margin: 6px 0; background: var(--bg); border-radius: 8px; }

/* Dateien (spec/dateien-v1.md) */
.nur-test { margin: 0 0 12px; padding: 8px 12px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-weight: 600; }
fieldset.groesse { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin: 0 0 14px; }
fieldset.groesse legend { padding: 0 6px; font-weight: 600; }
fieldset.groesse label.choice[data-gesperrt] { opacity: .55; }
fieldset.groesse .groesse-eigen input[type=text] { width: 7.5rem; }
fieldset.groesse .groesse-fehler { display: block; margin-top: 4px; }
fieldset.groesse .groesse-fehler.fehler { color: var(--bad, #b3261e); font-weight: 600; }
.dat-kopf { display: flex; flex-wrap: wrap; gap: 4px 0; align-items: baseline; margin: 0 0 6px; }
.dat-ungespeichert { color: var(--warn); font-weight: 600; }
.dat-speicher { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 6px 0 12px; }
.dat-speicher progress, .dat-upload progress { width: 220px; max-width: 100%; height: 12px; }
.dat-speicher-text { color: var(--muted); font-size: .9rem; }
.dat-kruemel { margin: 0 0 10px; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; }
.dat-hier { font-weight: 700; }
button.linklike { background: transparent; border: 0; padding: 2px 4px; color: var(--primary); text-decoration: underline; font-weight: 600; cursor: pointer; font: inherit; }
.dat-werkzeug { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 0 0 10px; }
.dat-ersetzen { font-size: .9rem; color: var(--muted); }
.dat-neuer-ordner { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 10px; }
.dat-neuer-ordner input { flex: 1 1 200px; }
.dat-ablage { border: 2px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center; color: var(--muted); margin: 0 0 12px; }
.dat-ablage.aktiv { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.dat-uploads { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 6px; }
.dat-upload { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; padding: 8px 10px; border-radius: 8px; background: var(--bg); }
.dat-upload[data-zustand=fehler] { background: var(--bad-soft); color: var(--bad); }
.dat-upload[data-zustand=fertig] { background: var(--ok-soft); }
.dat-upload-name { font-weight: 600; overflow-wrap: anywhere; }
.dat-liste { width: 100%; border-collapse: collapse; }
.dat-liste caption { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.dat-liste th, .dat-liste td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.dat-name { overflow-wrap: anywhere; }
.dat-groesse, .dat-datum { white-space: nowrap; color: var(--muted); font-size: .92rem; }
.dat-aktionen { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.dat-warn { font-weight: 600; color: var(--bad); }
.dat-mini { display: block; max-width: 96px; max-height: 72px; margin-top: 4px; border-radius: 6px; border: 1px solid var(--line); }
dialog.dat-vorschau { width: min(860px, 96vw); }
dialog.dat-vorschau img { display: block; max-width: 100%; max-height: 70vh; margin: 0 auto 12px; }
@media (max-width: 640px) {
  .dat-liste thead { display: none; }
  .dat-liste tr { display: block; padding: 6px 0; border-bottom: 1px solid var(--line); }
  .dat-liste td { display: block; border: 0; padding: 2px 6px; }
}

/* Echter Mailversand (spec/echter-mailversand-v1.md §3) */
#mail-karte h3 { margin: 22px 0 6px; font-size: 1.05rem; }
#mail-karte details > summary { cursor: pointer; font-weight: 600; margin: 10px 0; }
.pill { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: .9rem; font-weight: 600; background: var(--primary-soft); color: var(--primary-dark); }
.pill[data-zustand="an"] { background: var(--ok-soft); color: var(--ok); }
.pill[data-zustand="gesperrt"] { background: var(--bad-soft); color: var(--bad); }
.pill[data-zustand="aus"], .pill[data-zustand="nicht_eingerichtet"] { background: var(--warn-soft); color: var(--warn); }
.field-error { display: block; color: var(--bad); font-size: .9rem; font-weight: 600; }
.field-error:empty { display: none; }
input[aria-invalid="true"], textarea[aria-invalid="true"], select[aria-invalid="true"] { border-color: var(--bad); }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
label.check input { margin-top: 4px; }
ol.steps { list-style: none; padding: 0; margin: 10px 0; }
ol.steps li { padding: 8px 12px; margin: 6px 0; border-radius: 10px; background: var(--primary-soft); }
ol.steps li.step.ok { background: var(--ok-soft); }
ol.steps li.step.bad { background: var(--bad-soft); }
ol.steps li.step-title { background: transparent; padding-left: 0; font-weight: 700; }
ul.mail-verlauf { padding-left: 18px; margin: 6px 0; }
button.danger-text { color: var(--bad); }

/* Runde 16: Mailversand-Zustand in der Kopfzeile, Fortschritt beim Anlegen */
.mail-badge { font-size: .8rem; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--border, currentColor); background: var(--warn-soft); color: var(--warn); cursor: pointer; font-weight: 600; white-space: nowrap; }
.mail-badge[data-zustand="an"] { background: var(--ok-soft); color: var(--ok); }
.mail-badge[data-zustand="gesperrt"], .mail-badge[data-zustand="still"] { background: var(--warn-soft); color: var(--warn); border-width: 2px; }
.progress { margin: 8px 0; }
.progress .bar { height: 14px; border-radius: 8px; background: var(--primary-soft); overflow: hidden; }
.progress .bar span { display: block; height: 100%; background: var(--primary); transition: width .4s linear; }
.progress p { margin: 4px 0; }
.progress .phase { font-weight: 600; }
.progress ol { list-style: none; display: flex; gap: 8px; padding: 0; margin: 6px 0; flex-wrap: wrap; font-size: .85rem; color: var(--muted); }
.progress ol li.done { color: var(--ok); }
.progress ol li.current { color: inherit; font-weight: 600; }
