/* ═══════════════════════════════════════════════════════════════════════════
   modules/a4-render/a4-render.css
   Phase C1 (2026-05-08 EOD): A4-Rendering Foundation

   User-Wunsch: "Aja die Vorlagen sollen immer und ich meine IMMER als A4
   Zettel gerandert und dargestellt werden."

   Architektur:
     - 1 mm = exakt 1 mm bei 100% Zoom (CSS mm-Unit)
     - A4 = 210mm × 297mm (Hochformat default, A4 Querformat optional)
     - Page-Margin via CSS-Var --scA4-margin (default 20mm, anpassbar)
     - Multi-Page: Pages werden untereinander angeordnet, mit Gap
     - Zoom via CSS transform: scale() — die mm-Maße bleiben absolut korrekt
     - Print-CSS: alles außerhalb Document wird ausgeblendet, Pages werden
       direkt für den Drucker rendered

   Klassen-Hierarchie:
     .scA4-doc           Container (grauer Hintergrund + Scroll)
       .scA4-doc-toolbar Zoom-Controls + Page-Counter (sticky)
       .scA4-doc-pages   Wrapper für die Pages (transformierbar)
         .scA4-page      Einzel-Seite
           .scA4-page-bg     Hintergrund (Rasterlinien optional)
           .scA4-page-content   Content-Area innerhalb Margin
           .scA4-page-num    Seitenzahl
           .scA4-page-margins   Margin-Indicator (gestrichelt, optional)
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Container ──────────────────────────────────────────────────────────── */
.scA4-doc {
  position: relative;
  background: #e0e8e5;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: 100%;
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --scA4-margin: 20mm;
  --scA4-zoom: 1;
  --scA4-page-w: 210mm;
  --scA4-page-h: 297mm;
}
.scA4-doc.scA4-landscape {
  --scA4-page-w: 297mm;
  --scA4-page-h: 210mm;
}

/* ── Toolbar (Zoom + Pages) ─────────────────────────────────────────────── */
.scA4-doc-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #fafbfc, #e0e8e5);
  border-bottom: 1px solid #cbd5d1;
  font-size: 0.78rem;
  color: #1a2926;
  flex-shrink: 0;
  z-index: 5;
  flex-wrap: wrap;
}
.scA4-doc-toolbar-spacer { flex: 1; }
.scA4-tb-btn {
  padding: 5px 9px;
  border-radius: 6px;
  border: 1px solid #cbd5d1;
  background: #fff;
  color: #1a2926;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: background .12s, border-color .12s;
}
.scA4-tb-btn:hover {
  background: #f4f6f8;
  border-color: #488078;
}
.scA4-tb-btn.act {
  background: #488078;
  color: #fff;
  border-color: #488078;
}
.scA4-tb-btn[disabled] {
  opacity: .45;
  cursor: not-allowed;
}
.scA4-tb-zoom {
  display: inline-flex;
  align-items: center;
  background: #fff;
  border: 1px solid #cbd5d1;
  border-radius: 6px;
  overflow: hidden;
}
.scA4-tb-zoom button {
  border: none;
  background: transparent;
  padding: 5px 10px;
  cursor: pointer;
  color: #1a2926;
  font-family: inherit;
  font-size: 0.74rem;
}
.scA4-tb-zoom button:hover { background: #f4f6f8; }
.scA4-tb-zoom .scA4-tb-zoom-val {
  padding: 5px 10px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  min-width: 50px;
  text-align: center;
  border-left: 1px solid #cbd5d1;
  border-right: 1px solid #cbd5d1;
  font-size: 0.74rem;
}
.scA4-tb-pageinfo {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  background: rgba(72,128,120,.10);
  color: #3a6b65;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.72rem;
}

/* ── Pages-Container ────────────────────────────────────────────────────── */
.scA4-doc-pages-wrap {
  flex: 1;
  overflow: auto;
  background: #d4dbd9;
  padding: 24px 0;
  scroll-behavior: smooth;
  position: relative;
}
.scA4-doc-pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  transform-origin: top center;
  transform: scale(var(--scA4-zoom));
  transition: transform .15s ease-out;
  /* Gegenkompensation für Container-Höhe: bei kleinem Zoom wird der
     transformierte Inhalt breiter/höher als nötig — wir lassen das CSS
     einfach machen, der overflow-Container scrollt. */
  width: max-content;
  margin: 0 auto;
}

/* ── A4-Page ────────────────────────────────────────────────────────────── */
.scA4-page {
  width: var(--scA4-page-w);
  min-height: var(--scA4-page-h);
  height: var(--scA4-page-h);
  background: #ffffff;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.18), 0 1px 3px rgba(0, 0, 0, 0.08);
  position: relative;
  flex-shrink: 0;
  color: #1a2926;
  font-size: 11pt;
  line-height: 1.45;
  /* CSS Subpixel-Antialiasing fuer Mm-Genauigkeit */
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}
.scA4-page.scA4-page-active {
  outline: 2px solid #488078;
  outline-offset: 4px;
}

/* Margin-Indicator (gestrichelter Rahmen — optional via class) */
.scA4-doc.scA4-show-margins .scA4-page::before {
  content: '';
  position: absolute;
  inset: var(--scA4-margin);
  border: 1px dashed rgba(72,128,120,.4);
  pointer-events: none;
  z-index: 0;
}

/* Seitenzahl (default rechts unten) */
.scA4-page-num {
  position: absolute;
  bottom: 8mm;
  right: 12mm;
  font-size: 9pt;
  color: #7b8c8a;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

/* Content-Area innerhalb Margin */
.scA4-page-content {
  position: absolute;
  inset: var(--scA4-margin);
  overflow: visible;
  z-index: 1;
}

/* Grid (optional, für Editor-Mode) */
.scA4-doc.scA4-show-grid .scA4-page {
  background-image:
    linear-gradient(to right, rgba(72,128,120,.06) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(72,128,120,.06) 1px, transparent 1px);
  background-size: 10mm 10mm;
}

/* ── Mobile/Tablet Auto-Fit ─────────────────────────────────────────────── */
/* A4 = 210mm = ~793px @ 96dpi. Auf Mobile (~400px) → 50% Zoom default.
   Wir lassen das im JS via setInitialZoom-Logik tunen, hier nur min-padding. */
@media (max-width: 640px) {
  .scA4-doc-pages-wrap { padding: 12px 0; }
  .scA4-doc-pages { gap: 12px; }
  .scA4-doc-toolbar { padding: 6px 10px; gap: 6px; font-size: 0.72rem; }
  .scA4-tb-btn { padding: 4px 7px; font-size: 0.7rem; }
  .scA4-tb-btn .scA4-tb-btn-label { display: none; }
}

/* ── Print-CSS ──────────────────────────────────────────────────────────── */
@media print {
  /* Alles außerhalb von .scA4-doc verstecken */
  body * { visibility: hidden !important; }
  .scA4-doc, .scA4-doc * { visibility: visible !important; }
  .scA4-doc {
    position: absolute !important;
    top: 0; left: 0;
    width: 100% !important; height: auto !important;
    background: white !important;
    padding: 0 !important;
    overflow: visible !important;
    display: block !important;
  }
  .scA4-doc-toolbar { display: none !important; }
  .scA4-doc-pages-wrap {
    overflow: visible !important;
    padding: 0 !important;
    background: white !important;
    height: auto !important;
  }
  .scA4-doc-pages {
    transform: none !important;
    gap: 0 !important;
    width: auto !important;
  }
  .scA4-page {
    box-shadow: none !important;
    margin: 0 !important;
    page-break-after: always !important;
    width: 210mm !important;
    height: 297mm !important;
    outline: none !important;
  }
  .scA4-page:last-child { page-break-after: auto !important; }
  .scA4-doc.scA4-show-margins .scA4-page::before { display: none !important; }
  .scA4-doc.scA4-show-grid .scA4-page { background-image: none !important; }
  /* @page-Konfig: 0 Margin (alle Margins kommen aus var(--scA4-margin)) */
  @page {
    size: A4 portrait;
    margin: 0;
  }
  .scA4-doc.scA4-landscape { /* Wenn Doc Landscape → entsprechend */ }
  .scA4-doc.scA4-landscape .scA4-page { width: 297mm !important; height: 210mm !important; }
}

/* ── Inhaltliche Defaults für die Page-Content-Area ─────────────────────── */
.scA4-page-content h1,
.scA4-page-content h2,
.scA4-page-content h3 { margin: 0 0 0.6em; line-height: 1.2; }
.scA4-page-content h1 { font-size: 22pt; }
.scA4-page-content h2 { font-size: 16pt; }
.scA4-page-content h3 { font-size: 13pt; }
.scA4-page-content p  { margin: 0 0 0.5em; }
.scA4-page-content table {
  border-collapse: collapse;
  width: 100%;
  font-size: 10pt;
}
.scA4-page-content table td,
.scA4-page-content table th {
  border: 1px solid #cbd5d1;
  padding: 4mm;
  vertical-align: top;
}
.scA4-page-content img { max-width: 100%; height: auto; }
.scA4-page-content .scA4-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5mm;
}
.scA4-page-content .scA4-row-2col img { width: 100%; }

/* Bildnummer-Overlay (User-Wunsch: oben links im Bild) */
.scA4-img-num {
  position: absolute;
  top: 2mm;
  left: 2mm;
  background: #1B7599;
  color: #fff;
  font-size: 8pt;
  font-weight: 700;
  padding: 1mm 2mm;
  border-radius: 1mm;
  letter-spacing: 0.04em;
  z-index: 2;
  font-variant-numeric: tabular-nums;
}
