/**
 * Vorgangsakte — Papier-Layout (eine Seite DIN A4 hoch).
 *
 * Alle Regeln sind auf .akte-doc gescoped. Ohne diese Kapselung würden die
 * Element-Selektoren (table, th, h2) das Dashboard überschreiben, sobald die
 * Vorschau dort eingeblendet wird.
 *
 * Die Ein-Seiten-Zusage trägt drei Maßnahmen:
 *   1. dichtes Raster statt kleiner Schrift (Lesbarkeit vor Dichte, aber kein
 *      verschenkter Platz),
 *   2. `break-inside: avoid` auf Tabellen, Karten und Abschnitten, damit ein
 *      Überlauf nie mitten in einer Zeile passiert,
 *   3. eine Höhenmessung im Dialog, die warnt, bevor gedruckt wird.
 */


/* ---------------------------------------------------------------
   Schutzschicht gegen das Dashboard-Stylesheet
   ---------------------------------------------------------------
   Die Vorschau liegt im Dashboard, dessen Stylesheet mehrere Element-Regeln
   ohne Klasse setzt: `header` bekommt dort eine feste Höhe von 64 px, einen
   blauen Grund und ein dreispaltiges Raster, `th` einen blauen Grund mit weißer
   Versalschrift. Beides schlug ungebremst auf das Blatt durch (blauer Balken
   statt Kopfzeile, blaue Tabellenköpfe). Diese Schicht stellt für alles
   innerhalb von .akte-doc die Papier-Voreinstellungen wieder her; die
   inhaltlichen Regeln darunter bauen darauf auf. */
.akte-doc header,
.akte-doc footer,
.akte-doc section,
.akte-doc article,
.akte-doc aside {
    all: revert;
    display: block;
    background: none;
    color: inherit;
    height: auto;
    min-height: 0;
    padding: 0;
    margin: 0;
    box-shadow: none;
    position: static;
    z-index: auto;
    border: none;
}
.akte-doc table { width: 100%; border-collapse: collapse; }
.akte-doc th,
.akte-doc td {
    background: none;
    color: inherit;
    font-size: inherit;
    font-weight: inherit;
    text-transform: none;
    letter-spacing: normal;
    white-space: normal;
}
.akte-doc h1, .akte-doc h2, .akte-doc h3 { color: inherit; }
.akte-doc dl, .akte-doc dt, .akte-doc dd { margin: 0; }

.akte-doc {
    --ak-text: #1a1a1a;
    --ak-leise: #5c6b7a;
    --ak-linie: #ccd6e0;
    --ak-blau: #0080c9;
    --ak-flaeche: #f4f8fb;
    box-sizing: border-box;
    width: 210mm;
    min-height: 297mm;
    padding: 14mm 14mm 10mm;
    margin: 0 auto;
    background: #fff;
    color: var(--ak-text);
    font-family: "Open Sans", "Segoe UI", system-ui, sans-serif;
    font-size: 9.5pt;
    line-height: 1.42;
}
.akte-doc *, .akte-doc *::before, .akte-doc *::after { box-sizing: border-box; }

/* --- Kopf --- */
.akte-doc .ak-kopf { margin-bottom: 5mm; }
.akte-doc .ak-kopf-zeile {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8mm;
    padding-bottom: 2mm;
    border-bottom: 2px solid var(--ak-blau);
    margin-bottom: 3mm;
}
.akte-doc .ak-kopf h1 {
    margin: 0;
    font-family: "Montserrat", "Segoe UI", system-ui, sans-serif;
    font-size: 14pt;
    font-weight: 700;
    letter-spacing: -0.01em;
}
.akte-doc .ak-id {
    font-family: "Fira Code", ui-monospace, Consolas, monospace;
    color: var(--ak-blau);
}
.akte-doc .ak-firma { font-size: 8pt; color: var(--ak-leise); white-space: nowrap; }
.akte-doc .ak-firma b { color: var(--ak-blau); font-weight: 700; }

.akte-doc .ak-kopf-felder {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2mm 4mm;
    margin: 0;
}
.akte-doc .ak-feld { min-width: 0; }
.akte-doc .ak-feld dt {
    font-size: 6.8pt;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ak-leise);
}
.akte-doc .ak-feld dd {
    margin: 0;
    font-size: 9.5pt;
    font-weight: 600;
    overflow-wrap: anywhere;
}
.akte-doc .ak-mono { font-family: "Fira Code", ui-monospace, Consolas, monospace; }

/* --- Abschnitte --- */
.akte-doc .ak-abschnitt {
    margin-bottom: 4mm;
    break-inside: avoid;
    page-break-inside: avoid;
}
.akte-doc .ak-abschnitt h2 {
    margin: 0 0 1.5mm;
    padding-bottom: 1mm;
    border-bottom: 1px solid var(--ak-linie);
    font-family: "Montserrat", "Segoe UI", system-ui, sans-serif;
    font-size: 9.5pt;
    font-weight: 700;
    color: var(--ak-blau);
    letter-spacing: 0.01em;
}
.akte-doc .ak-text {
    margin: 0;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}
.akte-doc .ak-sollist {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2mm 4mm;
    margin: 2mm 0 0;
    padding: 2mm 3mm;
    background: var(--ak-flaeche);
    border-radius: 2mm;
}

/* --- Tabellen --- */
.akte-doc .ak-tab {
    width: 100%;
    border-collapse: collapse;
    break-inside: avoid;
    page-break-inside: avoid;
}
.akte-doc .ak-tab th,
.akte-doc .ak-tab td {
    padding: 1.2mm 2mm;
    text-align: left;
    border-bottom: 1px solid var(--ak-linie);
    vertical-align: top;
}
.akte-doc .ak-tab thead th {
    font-size: 7.2pt;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--ak-leise);
    border-bottom-width: 1.5px;
}
.akte-doc .ak-num { text-align: right; font-variant-numeric: tabular-nums; }
.akte-doc .ak-kosten { width: 70mm; }
.akte-doc .ak-kosten th {
    font-weight: 400;
    color: var(--ak-leise);
    border-bottom: none;
    padding-left: 0;
}
.akte-doc .ak-kosten td { text-align: right; font-variant-numeric: tabular-nums; border-bottom: none; }
.akte-doc .ak-summe th, .akte-doc .ak-summe td {
    border-top: 1.5px solid var(--ak-text);
    font-weight: 700;
    color: var(--ak-text);
    padding-top: 1.5mm;
}

/* --- Foto --- */
.akte-doc .ak-foto { margin: 0; break-inside: avoid; page-break-inside: avoid; }
.akte-doc .ak-foto img {
    display: block;
    max-width: 100%;
    max-height: 70mm;
    object-fit: contain;
    border: 1px solid var(--ak-linie);
    border-radius: 1mm;
}
.akte-doc .ak-foto figcaption {
    margin-top: 1mm;
    font-size: 7.5pt;
    color: var(--ak-leise);
}

.akte-doc .ak-erp { grid-template-columns: repeat(4, 1fr); }

/* --- Fuß --- */
.akte-doc .ak-fuss {
    display: flex;
    justify-content: space-between;
    gap: 6mm;
    margin-top: 5mm;
    padding-top: 2mm;
    border-top: 1px solid var(--ak-linie);
    font-size: 7.2pt;
    color: var(--ak-leise);
}

/* --- Druck --- */
@page { size: A4 portrait; margin: 0; }

@media print {
    .akte-doc {
        width: auto;
        min-height: auto;
        margin: 0;
        padding: 12mm 12mm 8mm;
        box-shadow: none;
    }
    .akte-doc .ak-foto img { max-height: 65mm; }
}

.akte-doc .ak-foto-fehlt {
    margin: 0;
    padding: 6mm;
    border: 1px dashed var(--ak-linie);
    border-radius: 1mm;
    color: var(--ak-leise);
    font-size: 8pt;
    text-align: center;
}
