/* ============================================================
   SecKit Print Styles (v3 — natürlicher Fluss, Editorial)
   Nur für @media print — wird zusätzlich zu app.css geladen.
   Ziel: professionelle Finaldokumente ohne verwaiste
   Wörter/Zeilen, Überschriften bleiben bei ihrem Text.
   ============================================================ */

/* @page auf Top-Level — Chrome ignoriert @page innerhalb @media in manchen Versionen */
@page {
  size: A4;
  margin: 22mm 20mm 22mm 20mm;

  @bottom-left {
    content: "Vertraulich \2022 Nur f\00FCr den Empf\00E4nger";
    font-size: 8pt;
    color: #6b6862;
    font-family: "Source Serif 4", Georgia, serif;
    font-style: italic;
  }

  @bottom-center { content: ""; }

  @bottom-right {
    content: "Seite " counter(page);
    font-size: 8pt;
    color: #57534e;
    font-family: "Source Serif 4", Georgia, serif;
  }

  @top-right {
    content: "VERTRAULICH";
    font-size: 7.5pt;
    color: #b91c1c;
    font-family: "Inter", "Segoe UI", sans-serif;
    font-weight: 600;
    letter-spacing: 0.12em;
  }
}

/* Deckblatt/erste Seite ohne Kopf-/Fußzeile */
@page :first {
  @top-right { content: ""; }
  @bottom-left { content: ""; }
  @bottom-right { content: ""; }
}

@media print {
  /* ── Immer Hell-Palette drucken, egal welches App-Theme aktiv ist ──
     Im Dunkelmodus sind --text-* helle Grautöne → auf weißem Papier
     unsichtbar. Hier auf druckbare, dunkle Werte zwingen (Markenfarbe
     --primary bleibt unangetastet). */
  :root, .dark, html.dark {
    --text-1:        #1a1a1a !important;
    --text-2:        #3f3f3f !important;
    --text-3:        #666666 !important;
    --text:          #1a1a1a !important;
    --text-light:    #3f3f3f !important;
    --text-muted:    #666666 !important;
    --border:        #cfcfcf !important;
    --border-md:     #b6b6b6 !important;
    --bg:            #ffffff !important;
    --surface:       #ffffff !important;
    --card-bg:       #ffffff !important;
    --bg-accent:     #f3f3f1 !important;
    --accent:        #1e3a5f !important;
    --accent-text:   #1e3a5f !important;
    --accent-bg:     #eef2f7 !important;
    --success:       #15803d !important;
    --success-text:  #15803d !important;
    --success-bg:    #edf6ef !important;
    --warning:       #b45309 !important;
    --warning-text:  #b45309 !important;
    --warning-bg:    #fbf3e6 !important;
    --danger:        #b91c1c !important;
    --danger-text:   #b91c1c !important;
    --danger-bg:     #fbeeee !important;
  }

  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  body {
    background: #fff !important;
    color: #1c1a17 !important;
    margin: 0 !important;
  }

  /* Dokument-Grundsatz: Serif-Überschriften, humanistischer Fließtext */
  .document {
    max-width: 100% !important;
    font-family: "Source Serif 4", Georgia, "Times New Roman", serif !important;
    font-size: 10.5pt !important;
    line-height: 1.55 !important;
    color: #1c1a17 !important;
  }

  /* ── Überschriften: bleiben bei ihrem Folgetext ─────────── */
  .document h1 {
    font-family: "Source Serif 4", Georgia, serif !important;
    break-after: avoid !important;
    page-break-after: avoid !important;
  }

  .document h2,
  .document h3,
  .document h4,
  .document h5,
  .document h6 {
    font-family: "Source Serif 4", Georgia, serif !important;
    break-after: avoid !important;
    page-break-after: avoid !important;
    /* Überschrift nie allein am Seitenende: mind. Folgezeilen mitnehmen */
    orphans: 3 !important;
    widows: 3 !important;
  }

  /* Absatz direkt nach Überschrift nicht vom Titel trennen */
  .document h1 + *,
  .document h2 + *,
  .document h3 + *,
  .document h4 + * {
    break-before: avoid !important;
    page-break-before: avoid !important;
  }

  /* Optionaler, bewusster Kapitelumbruch (per Klasse), NICHT automatisch */
  .document .page-break,
  .document h2.chapter-break {
    break-before: page !important;
    page-break-before: always !important;
  }
  .document .page-break { height: 0; }

  /* ── Fließtext: keine verwaisten Wörter/Zeilen ──────────── */
  .document p {
    orphans: 2 !important;
    widows: 2 !important;
    text-align: justify !important;
    hyphens: auto !important;
    -webkit-hyphens: auto !important;
    hyphenate-limit-chars: 6 3 3;
    margin: 0 0 0.55rem !important;
  }

  /* Listen: Punkt nicht über Seitengrenze trennen */
  .document li {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
    orphans: 2 !important;
    widows: 2 !important;
  }

  /* Tabellen: Zeilen zusammenhalten, Kopf auf jeder Seite */
  .document tr {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  .document thead { display: table-header-group !important; }
  .document table { break-inside: auto; }
  .document table.allow-break tr { break-inside: auto !important; }

  /* Unterschriften-/Freigabeblöcke zusammenhalten */
  .document .doc-footer,
  .document .signature-block {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* Info-/Warnboxen nicht trennen */
  .document .info-box,
  .document .warning-box,
  .document .success-box,
  .document .danger-box {
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }

  /* ── Demo-Wasserzeichen (nur wenn demo-config.js body.seckit-demo setzt) ── */
  body.seckit-demo .document {
    position: relative;
  }

  body.seckit-demo .document::before {
    content: "DEMO \2014 SecKit Testversion";
    position: fixed;
    top: 45%;
    left: 8%;
    transform: rotate(-32deg);
    font-family: "Inter", "Segoe UI", sans-serif;
    font-size: 42pt;
    font-weight: 800;
    letter-spacing: 0.08em;
    color: rgba(185, 28, 28, 0.16);
    z-index: 9999;
    pointer-events: none;
    white-space: nowrap;
  }

  /* UI-Elemente niemals drucken */
  .no-print,
  .app-sidebar,
  .app-header,
  #sidebarToggle,
  .sk-wizard-header,
  .preview-header,
  .preview-toolbar,
  .preview-footer,
  .sk-toast-container,
  .section-toggle-btn,
  .list-item-toolbar,
  .table-row-toolbar,
  .annotation-marker {
    display: none !important;
  }
}
