/* =====================================================================
   Design tokens
   ===================================================================== */
:root {
    --red: rgb(189, 72, 91);
    --bg: rgb(212, 230, 242);
    --border: 1px solid var(--red);
    --line-width: 1px;
    --form-scale: 1;

    /* Semantic surfaces */
    --bg-page: #e5e7eb;
    --bg-surface: #ffffff;
    --bg-section: #f3f4f6;
    --bg-row: #f9fafb;
    --bg-input-focus: #fff7f8;

    /* Text */
    --text: #1a1a1a;
    --text-soft: #4b5563;
    --text-muted: #6b7280;
    --text-on-dark: #ffffff;
    --text-th: #374151;
    --text-control: #1e293b;

    /* Status — success */
    --ok-bg: #d1fae5;
    --ok-fg: #065f46;
    --ok-border: #047857;
    --ok-accent: #10b981;

    /* Status — warning (Einvernehmen) */
    --warn-bg: #fffbeb;
    --warn-fg: #92400e;
    --warn-border: #b45309;
    --warn-tag-bg: #fef3c7;

    /* Status — error (Unterschrift / fail) */
    --err-bg: #fef2f2;
    --err-fg: #991b1b;
    --err-border: #b91c1c;
    --err-tag-bg: #fee2e2;
    --err-strong: #dc2626;

    /* Misc */
    --border-soft: #e5e7eb;
    --border-row: #f1f5f9;
    --border-control: #cbd5e1;
    --focus-ring: #2563eb;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    background: var(--bg-page);
    font-family: Arial, Helvetica, sans-serif;
    color: var(--red);
    -webkit-font-smoothing: antialiased;
    min-height: 100vh;
}

/* =====================================================================
   Page layout (form + help card side by side)
   ===================================================================== */
.page-wrap {
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    gap: 15px;
    transform-origin: top center;
    transform: scale(var(--form-scale));
    will-change: transform;
}

.form,
.erl-card {
    position: relative;
    width: 704px;
    height: 1000px;
    background: var(--bg-surface);
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
}

.bg-tint {
    position: absolute;
    left: 0;
    top: 0;
    width: 704px;
    height: 1000px;
    background: var(--bg);
}

/* =====================================================================
   Form primitives (absolute-positioned via inline style on each element)
   ===================================================================== */
.box,
.cell {
    position: absolute;
    border: var(--border);
    background: var(--bg-surface);
}

.label,
.section-h,
.muster-footer {
    position: absolute;
    color: var(--red);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1;
}

.label {
    white-space: nowrap;
}

.section-h {
    font-weight: 700;
    white-space: nowrap;
}

.muster-footer {
    font-size: 8px;
}

.small-label {
    position: absolute;
    color: var(--red);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 8px;
    line-height: 1.08;
    text-align: center;
    font-weight: 400;
    pointer-events: none;
}

.rule {
    position: absolute;
    background: var(--red);
    height: var(--line-width);
}

.vtick {
    position: absolute;
    background: var(--red);
    width: var(--line-width);
}

.fill {
    position: absolute;
    background: var(--bg-surface);
}

.title {
    position: absolute;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: 700;
    color: var(--red);
    font-size: 22px;
    letter-spacing: -0.3px;
    line-height: 1;
}

.ital {
    font-style: italic;
}

/* =====================================================================
   Checkbox
   ===================================================================== */
.chk {
    position: absolute;
    border: var(--border);
    background: var(--bg-surface);
    cursor: pointer;
    user-select: none;
}

.chk:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

.chk.ticked::after {
    content: '\2715';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #000;
    font-weight: 700;
    font-size: 17px;
    line-height: 1;
}

.chk[data-group="left"].ticked::after {
    font-size: 31px;
}

/* =====================================================================
   IK single-character inputs
   ===================================================================== */
.ik-input {
    position: absolute;
    border: var(--border);
    border-top: none;
    background: var(--bg-surface);
    color: #000;
    caret-color: #000;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    font-weight: 600;
    text-align: center;
    outline: none;
    padding: 0;
    text-transform: uppercase;
}

.ik-input:focus {
    background: var(--bg-input-focus);
}

/* =====================================================================
   Generic text input / textarea
   ===================================================================== */
.ti {
    position: absolute;
    border: none;
    background: transparent;
    color: #000;
    caret-color: #000;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    outline: none;
    padding: 0;
    text-align: left;
}

input.ti {
    display: flex;
    align-items: flex-end;
    line-height: 1;
}

textarea.ti {
    resize: none;
    line-height: 1.2;
    padding: 0;
    vertical-align: top;
}

.ti:focus {
    background: var(--bg-input-focus);
    border-color: #8a8a8a;
}

/* =====================================================================
   Context-aware help panel (inside .erl-card)
   ===================================================================== */
.info-panel {
    position: absolute;
    left: 31px;
    top: 31px;
    right: 48px;
    bottom: 48px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
    overflow: auto;
}

.info-panel__header {
    display: flex;
    align-items: center;
    gap: 13px;
    padding-bottom: 18px;
    border-bottom: 2px solid var(--red);
}

.info-panel__title {
    font-size: 22px;
    font-weight: 700;
    color: var(--red);
    flex: 1;
    line-height: 1.2;
}

.info-panel__badge {
    font-size: 10px;
    font-weight: 700;
    padding: 5px 16px;
    border-radius: 5px;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

.info-panel__badge[data-mandatory="true"] {
    background: #fde2e5;
    color: var(--red);
}

.info-panel__badge[data-mandatory="false"] {
    background: var(--bg-page);
    color: var(--text-soft);
}

.info-panel__section-title {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.info-panel__section-body {
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
}

.info-panel__examples {
    list-style: none;
    padding: 0;
    margin-top: 12px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.info-panel__examples li {
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    padding: 6px 14px;
    background: var(--ok-bg);
    border-left: 4px solid var(--ok-accent);
    border-radius: 3px;
    white-space: pre-wrap;
    color: var(--ok-fg);
}

.info-panel__fill-btn {
    align-self: flex-start;
    margin-top: 12px;
    padding: 8px 14px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 13px;
    font-weight: 600;
    background: var(--red);
    color: var(--text-on-dark);
    border: 1px solid var(--red);
    border-radius: 6px;
    cursor: pointer;
}

.info-panel__fill-btn:hover:not(:disabled) {
    filter: brightness(0.95);
}

.info-panel__fill-btn:disabled {
    background: var(--bg-section);
    color: var(--text-muted);
    border-color: var(--border-control);
    cursor: not-allowed;
}

.info-panel__validation-status {
    font-size: 13px;
    font-weight: 700;
    padding: 8px 18px;
    border-radius: 5px;
}

.info-panel__validation-status[data-valid="true"] {
    background: var(--ok-bg);
    color: var(--ok-fg);
}

.info-panel__validation-status[data-valid="false"] {
    background: var(--err-tag-bg);
    color: var(--err-fg);
}

.info-panel__validation-hint {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 8px;
}

.info-panel--empty .info-panel__title {
    color: #9ca3af;
}

/* Änderung auf der Verordnung — per-category items */
.info-panel__aenderung {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.info-panel__aenderung li {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 16px;
    line-height: 1.5;
    color: var(--text);
    padding: 12px 14px;
    border-radius: 4px;
    border-left: 4px solid #9ca3af;
    background: var(--bg-row);
}

.info-panel__aenderung-tag {
    align-self: flex-start;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 4px 10px;
    border-radius: 3px;
    white-space: nowrap;
}

.info-panel__aenderung li[data-typ="unterschrift"] {
    border-left-color: var(--err-border);
    background: var(--err-bg);
}

.info-panel__aenderung li[data-typ="unterschrift"] .info-panel__aenderung-tag {
    background: var(--err-tag-bg);
    color: var(--err-fg);
}

.info-panel__aenderung li[data-typ="einvernehmen"] {
    border-left-color: var(--warn-border);
    background: var(--warn-bg);
}

.info-panel__aenderung li[data-typ="einvernehmen"] .info-panel__aenderung-tag {
    background: var(--warn-tag-bg);
    color: var(--warn-fg);
}

.info-panel__aenderung li[data-typ="information"] {
    border-left-color: var(--ok-border);
    background: var(--ok-bg);
}

.info-panel__aenderung li[data-typ="information"] .info-panel__aenderung-tag {
    background: var(--ok-bg);
    color: var(--ok-fg);
}

/* =====================================================================
   Toolbar
   ===================================================================== */
.toolbar {
    position: fixed;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}

.toolbar button {
    padding: 8px 12px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 13px;
    background: var(--bg-surface);
    border: 1px solid var(--border-control);
    border-radius: 4px;
    cursor: pointer;
    color: var(--text-control);
    min-width: 110px;
    text-align: left;
}

.toolbar button:hover {
    background: #f1f5f9;
}

.toolbar button:disabled {
    opacity: 0.5;
    cursor: wait;
}

/* =====================================================================
   Invalid-field marking
   ===================================================================== */
.ti.invalid {
    outline: 2px solid var(--err-strong);
    outline-offset: -2px;
    background: rgba(254, 226, 226, 0.65);
}

.ik-input.invalid {
    outline: 2px solid var(--err-strong);
    outline-offset: -1px;
    background: rgba(254, 226, 226, 0.65);
}

.chk.invalid {
    border-color: var(--err-strong);
    box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.45);
}

/* =====================================================================
   Modal dialog (shared by validate dialog and examples picker)
   ===================================================================== */
.validate-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: none;
    align-items: flex-start;
    justify-content: center;
    z-index: 1000;
    padding: 60px 16px;
    overflow: auto;
}

.validate-overlay[data-open="true"] {
    display: flex;
}

.validate-dialog {
    background: var(--bg-surface);
    border-radius: 8px;
    width: 640px;
    max-width: 100%;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.35);
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.validate-dialog__title {
    font-size: 20px;
    font-weight: 700;
    color: var(--red);
    line-height: 1.2;
}

.validate-dialog__summary {
    font-size: 15px;
    font-weight: 600;
    padding: 12px 14px;
    border-radius: 4px;
    line-height: 1.4;
}

.validate-dialog__summary[data-ok="true"] {
    background: var(--ok-bg);
    color: var(--ok-fg);
}

.validate-dialog__summary[data-ok="false"] {
    background: var(--err-tag-bg);
    color: var(--err-fg);
}

.validate-dialog__toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.validate-dialog__toggle input {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.validate-dialog__empty {
    font-size: 15px;
    font-weight: 600;
    padding: 14px;
    border-radius: 4px;
    background: var(--ok-bg);
    color: var(--ok-fg);
    text-align: center;
}

.validate-dialog__table-wrap {
    overflow: auto;
    max-height: 60vh;
    border: 1px solid var(--border-soft);
    border-radius: 4px;
}

.validate-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
    line-height: 1.4;
}

.validate-table thead th {
    position: sticky;
    top: 0;
    background: var(--bg-section);
    color: var(--text-th);
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 700;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-soft);
}

.validate-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-row);
    vertical-align: top;
    color: var(--text);
}

.validate-table tbody tr:last-child td {
    border-bottom: none;
}

.validate-table tbody tr[data-status="fail"] td {
    background: var(--err-bg);
}

.validate-row--clickable {
    cursor: pointer;
}

.validate-row--clickable:hover td {
    filter: brightness(0.97);
}

.validate-row__message {
    font-size: 13px;
    font-weight: 600;
    color: var(--err-fg);
    margin-top: 4px;
}

.validate-status {
    display: inline-block;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
}

.validate-status--pass {
    background: var(--ok-bg);
    color: var(--ok-fg);
}

.validate-status--fail {
    background: var(--err-tag-bg);
    color: var(--err-fg);
}

.validate-dialog__close {
    align-self: flex-end;
    padding: 8px 18px;
    background: var(--red);
    color: var(--text-on-dark);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.validate-dialog__close:hover {
    opacity: 0.9;
}

/* =====================================================================
   Examples picker (uses the same overlay/dialog shell)
   ===================================================================== */
.examples-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.examples-list li {
    padding: 14px 16px;
    border: 1px solid var(--border-soft);
    border-radius: 6px;
    background: var(--bg-surface);
    cursor: pointer;
    transition: background 0.1s, border-color 0.1s;
}

.examples-list li:hover {
    background: var(--bg-row);
    border-color: var(--red);
}

.examples-list__title {
    font-size: 15px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 6px;
    line-height: 1.3;
}

.examples-list__desc {
    font-size: 13px;
    line-height: 1.45;
    color: var(--text-soft);
}

/* =====================================================================
   Optional QR code (Therapieziele box) + its dialog
   ===================================================================== */
/* Drawn above the Therapieziele textarea; absolute-positioned via inline
   left/top/width/height like the other form primitives. */
.qr-render {
    position: absolute;
    background: #fff;
}

.qr-render[hidden] {
    display: none;
}

.qr-render__img {
    display: block;
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
}

.qr-dialog__hint {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    margin: 0;
}

.qr-dialog__input {
    width: 100%;
    box-sizing: border-box;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    padding: 8px 10px;
    border: 1px solid var(--border-control);
    border-radius: 4px;
    resize: vertical;
}

.qr-dialog__error {
    font-size: 13px;
    font-weight: 600;
    color: var(--red);
    margin: 0;
}

.qr-dialog__error[hidden] {
    display: none;
}

.qr-dialog__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* PDF-export quality picker: one full-width button per quality preset. */
.export-dialog__options {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.export-dialog__options .qr-dialog__btn {
    text-align: center;
}

.qr-dialog__btn {
    padding: 8px 18px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.qr-dialog__btn--primary {
    background: var(--red);
    color: var(--text-on-dark);
    border: none;
}

.qr-dialog__btn--ghost {
    background: var(--bg-surface);
    color: var(--text-control);
    border: 1px solid var(--border-control);
}

.qr-dialog__btn:hover {
    opacity: 0.9;
}

/* Mobile Ausfüllen preview */
.mform__qr-btn {
    align-self: flex-start;
    padding: 10px 14px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border-control);
    border-radius: 6px;
    color: var(--text-control);
    cursor: pointer;
}

.mform__qr {
    margin-top: 10px;
}

.mform__qr[hidden] {
    display: none;
}

.mform__qr img {
    display: block;
    width: 180px;
    max-width: 100%;
    height: auto;
    image-rendering: pixelated;
}

/* =====================================================================
   First-run intro dialog
   ===================================================================== */
.intro-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 24px;
    overflow: auto;
}

.intro-overlay[hidden] {
    display: none;
}

.intro-dialog {
    background: var(--bg-surface);
    color: var(--text);
    border-radius: 12px;
    max-width: 520px;
    width: 100%;
    padding: 24px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.35);
    font-family: Arial, Helvetica, sans-serif;
    display: flex;
    flex-direction: column;
    gap: 16px;
    max-height: 90vh;
    max-height: 90dvh;
    overflow: auto;
}

.intro-dialog__title {
    font-size: 22px;
    font-weight: 700;
    color: var(--red);
    margin: 0;
}

.intro-dialog__body {
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
}

.intro-dialog__body p {
    margin: 0 0 12px;
}

.intro-dialog__list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.intro-dialog__list li {
    padding: 10px 12px;
    background: var(--bg-section);
    border-radius: 8px;
    font-size: 14px;
    line-height: 1.45;
}

.intro-dialog__list strong {
    color: var(--red);
}

.intro-dialog__actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    flex-wrap: wrap;
}

.intro-dialog__btn {
    padding: 10px 16px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    min-height: 44px;
}

.intro-dialog__btn--primary {
    background: var(--red);
    color: var(--text-on-dark);
    border: 1px solid var(--red);
}

.intro-dialog__btn--primary:hover {
    filter: brightness(0.95);
}

.intro-dialog__btn--ghost {
    background: transparent;
    color: var(--text-soft);
    border: 1px solid var(--border-control);
}

.intro-dialog__btn--ghost:hover {
    background: var(--bg-section);
}

body.intro-open {
    overflow: hidden;
}

@media (max-width: 768px) {
    .intro-overlay {
        padding: 12px;
        align-items: flex-end;
    }

    .intro-dialog {
        padding: 18px;
        max-height: 85dvh;
        border-radius: 14px;
    }

    .intro-dialog__title {
        font-size: 18px;
    }

    .intro-dialog__actions {
        flex-direction: column-reverse;
        gap: 8px;
    }

    .intro-dialog__btn {
        width: 100%;
    }
}

/* =====================================================================
   Default state for mobile-introduced elements (apply at any viewport).
   These are toggled per-view by `body[data-view=...]` selectors below.
   ===================================================================== */
#mobile-help-sheet,
#mobile-help-backdrop {
    display: none;
}

#mobile-form {
    display: none;
}

/* Fill view (any viewport): hide the canonical .form, show the friendly form. */
body[data-view="fill"] .form {
    display: none;
}

body[data-view="fill"] #mobile-form {
    display: block;
    background: var(--bg-surface);
    color: var(--text);
    font-family: Arial, Helvetica, sans-serif;
}

/* During PDF export, force the canonical layout regardless of view so
   html2canvas can rasterize `.form`. Brief visual flash is acceptable. */
body.rendering-pdf .form {
    display: block !important;
}

body.rendering-pdf .page-wrap {
    display: flex !important;
}

body.rendering-pdf #mobile-form {
    display: none !important;
}

/* =====================================================================
   View toggle (Ausfüllen / Vorschau) — visible at every viewport.
   Desktop: in flow above .page-wrap, no surrounding box, horizontally
   centered above the form column (auto-margin centers in viewport, then
   the transform shifts left by half the (.form width + .page-wrap gap)
   so the toggle sits over the form column rather than between form and
   help card). Sticky so it stays visible while the body scrolls.
   Mobile media query below repositions as a fixed top bar.
   ===================================================================== */
.mview-toggle {
    display: flex;
    width: max-content;
    margin: 6px auto 4px;
    gap: 0;
    padding: 0;
    background: transparent;
    box-shadow: none;
    border-radius: 0;
    transform: translateX(calc((-704px - 15px) / 2));
    position: sticky;
    top: 4px;
    z-index: 90;
}

.mview-toggle__btn {
    appearance: none;
    -webkit-appearance: none;
    box-sizing: border-box;
    height: 24px;
    padding: 0 8px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    background: var(--bg-surface);
    border: none;
    color: var(--text-soft);
    cursor: pointer;
    line-height: 1;
}

.mview-toggle__btn:first-child {
    border-top-left-radius: 4px;
    border-bottom-left-radius: 4px;
}

.mview-toggle__btn:last-child {
    border-top-right-radius: 4px;
    border-bottom-right-radius: 4px;
}

.mview-toggle__btn--active {
    background: var(--red);
    color: var(--text-on-dark);
}

/* =====================================================================
   Friendly form layout (#mobile-form) — applies at any viewport when
   visible. Desktop sizes it as a 704×1000 box (the .form footprint);
   mobile-specific overrides live in the @media block.
   ===================================================================== */
.mform__section {
    background: var(--bg-surface);
    border-radius: 12px;
    margin: 0 0 16px;
    padding: 14px 14px 16px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.mform__section-title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--red);
    margin: 0 0 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-soft);
}

.mform__row {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 0;
}

.mform__row + .mform__row {
    border-top: 1px solid var(--border-row);
}

.mform__row-head {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 24px;
}

.mform__label {
    flex: 1 1 auto;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 8px;
}

.mform__badge {
    font-size: 10px;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--bg-section);
    color: var(--text-muted);
}

.mform__badge--doctor {
    background: var(--warn-tag-bg);
    color: var(--warn-fg);
}

.mform__help {
    flex: 0 0 auto;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    border: 1px solid var(--border-control);
    background: var(--bg-surface);
    color: var(--text-soft);
    font-size: 14px;
    font-weight: 700;
    line-height: 1;
    cursor: pointer;
}

.mform__help:hover,
.mform__help:active {
    background: var(--bg-section);
}

.mform__input,
.mform__textarea {
    width: 100%;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 16px;
    line-height: 1.4;
    color: var(--text);
    padding: 10px 12px;
    border: 1px solid var(--border-control);
    border-radius: 8px;
    background: var(--bg-surface);
    min-height: 44px;
}

.mform__textarea {
    resize: vertical;
}

.mform__input:focus,
.mform__textarea:focus {
    outline: 2px solid var(--focus-ring);
    outline-offset: -1px;
    background: var(--bg-input-focus);
}

.mform__input--doctor {
    background: var(--bg-row);
    color: var(--text-soft);
}

.mform__row--doctor .mform__label {
    color: var(--text-soft);
}

.mform__hint {
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.4;
    margin: 0;
}

.mform__multi {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mform__checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mform__checkbox {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    cursor: pointer;
    font-size: 14px;
    color: var(--text);
    min-height: 44px;
}

.mform__checkbox input[type="checkbox"] {
    width: 22px;
    height: 22px;
    accent-color: var(--red);
    flex: 0 0 auto;
}

.mform__choice {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.mform__choice-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 1px solid var(--border-control);
    border-radius: 8px;
    font-size: 14px;
    color: var(--text);
    background: var(--bg-surface);
    min-height: 44px;
    cursor: pointer;
}

.mform__choice-item input[type="radio"] {
    width: 22px;
    height: 22px;
    accent-color: var(--red);
    flex: 0 0 auto;
}

.mform__choice-item:has(input:checked) {
    background: var(--bg-input-focus);
    border-color: var(--red);
}

.mform__row--paired .mform__pair {
    display: flex;
    gap: 8px;
}

.mform__input--grow {
    flex: 1 1 auto;
}

.mform__input--be {
    flex: 0 0 96px;
    text-align: center;
}

/* Desktop: friendly form sits in `.page-wrap` as a flex sibling alongside
   `.erl-card`, sized like the canonical `.form` it temporarily replaces.
   The per-field "?" button is redundant on desktop — the right-side help
   card already updates on hover/focus — so hide it. */
@media (min-width: 769px) {
    body[data-view="fill"] #mobile-form {
        width: 704px;
        height: 1000px;
        flex-shrink: 0;
        overflow: auto;
        padding: 24px;
        box-shadow: 0 8px 40px rgba(0, 0, 0, 0.2);
        align-self: flex-start;
    }

    .mform__help {
        display: none;
    }
}

/* =====================================================================
   Mobile breakpoint (<= 768px)
   The canonical `.form` is hidden via the `body[data-view="fill"]` rule
   above; `#mobile-form` is shown. In `data-view="preview"`, the form
   returns to flow read-only and `#mobile-form` is hidden.
   ===================================================================== */
@media (max-width: 768px) {
    html,
    body {
        overflow: auto;
        height: auto;
        min-height: 100vh;
        min-height: 100dvh;
        color: var(--text);
    }

    /* Make room for the fixed top toggle. */
    body {
        padding-top: calc(40px + env(safe-area-inset-top));
    }

    /* Mobile preview view: pixel-exact form in flow, no help card. */
    body[data-view="preview"] .page-wrap {
        position: static;
        padding: 8px 8px 88px;
        gap: 8px;
        pointer-events: auto;
        justify-content: flex-start;
        transform: none;
        width: max-content;
        min-width: 100%;
    }
    body[data-view="preview"] .erl-card {
        display: none;
    }

    /* Mobile fill view: hide the entire desktop chrome — `#mobile-form`
       was relocated by JS to body flow. Keep `.page-wrap` rendered for
       PDF export by toggling display via `body.rendering-pdf`. */
    body[data-view="fill"] .page-wrap {
        display: none;
    }

    /* Sticky full-width toggle bar (override the desktop pill). */
    .mview-toggle {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: auto;
        transform: none;
        border-radius: 0;
        box-shadow: none;
        background: var(--bg-page);
        border-bottom: 1px solid var(--border-soft);
        padding: max(5px, env(safe-area-inset-top)) 8px 5px;
        justify-content: center;
    }

    .mview-toggle__btn {
        flex: 0 1 96px;
        height: 28px;
        padding: 0 10px;
        font-size: 11px;
    }

    /* Mobile friendly form: full-width, scrolls in body flow.
       (#mobile-form is moved to be a body child by mobileForm.js on mobile.) */
    body[data-view="fill"] #mobile-form {
        padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
        max-width: 640px;
        margin: 0 auto;
    }

    /* Toolbar -> bottom dock */
    .toolbar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: auto;
        transform: none;
        flex-direction: row;
        justify-content: space-around;
        gap: 4px;
        padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
        background: var(--bg-surface);
        border-top: 1px solid var(--border-soft);
        box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.12);
    }

    .toolbar button {
        flex: 1 1 0;
        min-width: 0;
        text-align: center;
        font-size: 12px;
        padding: 10px 6px;
        min-height: 44px;
    }

    /* Validate / examples dialogs */
    .validate-overlay {
        padding: 24px 12px;
    }

    .validate-dialog {
        width: 100%;
        max-height: calc(100vh - 48px);
        max-height: calc(100dvh - 48px);
        overflow: auto;
        padding: 16px;
        gap: 12px;
    }

    .validate-dialog__table-wrap {
        max-height: 50vh;
        max-height: 50dvh;
        overflow: auto;
    }

    .validate-table {
        font-size: 13px;
    }

    .validate-table thead th,
    .validate-table tbody td {
        padding: 8px 10px;
        vertical-align: top;
    }

    .validate-table tbody td:nth-child(3) {
        word-break: break-word;
    }

    .examples-list li {
        padding: 16px 14px;
        min-height: 56px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .examples-list__title {
        font-size: 15px;
    }

    .examples-list__desc {
        font-size: 13px;
    }

    /* Bottom-sheet help: visible, slides in via data-open="true" */
    #mobile-help-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 1050;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease-out;
    }

    #mobile-help-backdrop[data-open="true"] {
        opacity: 1;
        pointer-events: auto;
    }

    #mobile-help-sheet {
        display: flex;
        flex-direction: column;
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 1100;
        background: var(--bg-surface);
        color: var(--text);
        font-family: Arial, Helvetica, sans-serif;
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.28);
        padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
        max-height: 70vh;
        max-height: 70dvh;
        transform: translateY(100%);
        transition: transform 200ms ease-out;
    }

    #mobile-help-sheet[data-open="true"] {
        transform: translateY(0);
    }

    .mobile-help__handle {
        align-self: center;
        width: 80px;
        height: 24px;
        padding: 10px 20px;
        margin: -4px 0 4px;
        cursor: grab;
        background-clip: content-box;
        background-color: var(--border-control);
        border-radius: 2px;
        touch-action: none;
    }

    .mobile-help__handle:active {
        cursor: grabbing;
    }

    .mobile-help__header {
        display: flex;
        align-items: center;
        gap: 8px;
        padding-bottom: 8px;
        border-bottom: 1px solid var(--border-soft);
    }

    .mobile-help__title {
        flex: 1 1 auto;
        font-size: 16px;
        font-weight: 700;
        color: var(--red);
        margin: 0;
    }

    .mobile-help__badge {
        font-size: 11px;
        font-weight: 600;
        padding: 3px 8px;
        border-radius: 999px;
        background: var(--bg-section);
        color: var(--text-soft);
    }

    .mobile-help__badge[data-mandatory="true"] {
        background: var(--err-tag-bg);
        color: var(--err-fg);
    }

    .mobile-help__close {
        flex: 0 0 auto;
        width: 36px;
        height: 36px;
        border: none;
        background: transparent;
        font-size: 24px;
        line-height: 1;
        color: var(--text-soft);
        cursor: pointer;
        border-radius: 8px;
    }

    .mobile-help__close:active {
        background: var(--bg-section);
    }

    .mobile-help__body {
        overflow: auto;
        padding-top: 10px;
        display: flex;
        flex-direction: column;
        gap: 14px;
    }

    .mobile-help__explanation {
        font-size: 14px;
        line-height: 1.45;
        color: var(--text);
        margin: 0;
    }

    .mobile-help__section h3 {
        font-size: 12px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
        color: var(--text-muted);
        margin: 0 0 6px;
    }

    .mobile-help__allowed-desc {
        font-size: 14px;
        line-height: 1.45;
        color: var(--text);
        margin: 0 0 6px;
    }

    .mobile-help__examples {
        list-style: disc inside;
        font-size: 13px;
        line-height: 1.5;
        color: var(--text-soft);
        padding: 0;
        margin: 0;
    }

    .mobile-help__fill-btn {
        margin-top: 12px;
        padding: 10px 14px;
        font-family: Arial, Helvetica, sans-serif;
        font-size: 14px;
        font-weight: 600;
        background: var(--red);
        color: var(--text-on-dark);
        border: 1px solid var(--red);
        border-radius: 8px;
        cursor: pointer;
        width: 100%;
        min-height: 44px;
    }

    .mobile-help__fill-btn:disabled {
        background: var(--bg-section);
        color: var(--text-muted);
        border-color: var(--border-control);
        cursor: not-allowed;
    }

    .mobile-help__aenderung-list {
        list-style: none;
        padding: 0;
        margin: 0;
        display: flex;
        flex-direction: column;
        gap: 8px;
    }

    .mobile-help__aenderung-list li {
        font-size: 13px;
        line-height: 1.4;
        color: var(--text);
        display: flex;
        flex-direction: column;
        gap: 4px;
        padding: 8px 10px;
        border-radius: 6px;
        background: var(--bg-section);
    }

    .mobile-help__aenderung-list li[data-typ="unterschrift"] {
        background: var(--err-tag-bg);
        color: var(--err-fg);
    }

    .mobile-help__aenderung-list li[data-typ="einvernehmen"] {
        background: var(--warn-tag-bg);
        color: var(--warn-fg);
    }

    .mobile-help__aenderung-list li[data-typ="information"] {
        background: var(--ok-bg);
        color: var(--ok-fg);
    }

    .mobile-help__aenderung-tag {
        font-size: 11px;
        font-weight: 700;
        text-transform: uppercase;
        letter-spacing: 0.04em;
    }

}


