/* ═══════════════════════════════════════════════════════════════════════════
   PRINT STYLESHEET — Monatsplan als Aushang / PDF
   Nur aktiv für @media print (siehe <link media="print"> in index.html).
   Reduziert die Ansicht auf den reinen Dienstplan-Raster: alle Chrome-,
   Modal-, Navigations- und Interaktionselemente werden ausgeblendet,
   Theme-Variablen werden durch feste Druckfarben ersetzt.

   ZIEL: Die komplette Tabelle muss — unabhängig von der Monatslänge
   (28–31 Tage) — vollständig auf EINE A4-Querseite passen, ohne dass sich
   Elemente überlagern oder den Seitenrand überragen. Dafür sorgen ein festes
   Tabellenlayout (table-layout: fixed; width: 100% → Spalten schrumpfen
   automatisch auf die verfügbare Breite) und durchgängig kompakte, klar
   begrenzte Zellinhalte.
   ═══════════════════════════════════════════════════════════════════════════ */

@media print {
  html, body {
    background: #fff !important;
    color: #0F172A !important;
    height: auto !important;
    overflow: visible !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  #app-header,
  #plan-bar,
  #stats-bar,
  #period-flyout,
  #grid-kbd-hint,
  .overlay,
  #mobile-nav,
  #mobile-day-list,
  #toast,
  .cell-quick-popover,
  #rp-context-menu {
    display: none !important;
  }

  main {
    display: block !important;
    padding: 0 !important;
    margin: 0 !important;
  }

  #print-header {
    display: block !important;
    margin: 0 0 8px;
    padding: 0 0 6px;
    border-bottom: 2px solid #0F172A;
  }

  #print-header-title {
    font-family: var(--font-sans, sans-serif);
    font-size: 15px;
    font-weight: 700;
    color: #0F172A;
  }

  #print-header-period {
    font-family: var(--font-mono, monospace);
    font-size: 12px;
    font-weight: 600;
    color: #0F172A;
    margin-top: 1px;
  }

  #print-header-meta {
    font-size: 9px;
    color: #475569;
    margin-top: 2px;
  }

  #grid-wrapper {
    display: block !important;
    width: 100% !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    background: #fff !important;
    border: none !important;
    box-shadow: none !important;
  }

  /* Festes Layout: Spalten teilen sich die verfügbare Breite gleichmäßig auf,
     egal ob der Monat 28 oder 31 Tage hat → niemals horizontaler Überlauf.
     Zusätzlich wird die Tabelle bei vielen Mitarbeitenden über --print-scale
     (in printPlan() aus der Zeilenzahl berechnet) gleichmäßig verkleinert, so
     dass sie auch vertikal vollständig auf eine Seite passt. Die inverse Breite
     hält die Seite dabei randscharf gefüllt. */
  #plan-table {
    width: calc(100% / var(--print-scale, 1)) !important;
    table-layout: fixed !important;
    border-collapse: collapse !important;
    font-size: 8px !important;
    transform: scale(var(--print-scale, 1));
    transform-origin: top left;
  }

  /* Namensspalte bekommt eine feste, schmale Breite; die Tagesspalten teilen
     sich den Rest. Damit bleibt der Plan auch bei 31 Tagen randscharf. */
  #plan-table .th-corner,
  #plan-table .td-name {
    width: 92px !important;
    max-width: 92px !important;
  }

  #plan-table th,
  #plan-table td {
    border: 0.5px solid #94A3B8 !important;
    color: #0F172A !important;
    padding: 1px 1px !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    line-height: 1.15 !important;
    height: auto !important;
    min-width: 0 !important;
    max-width: none;
  }

  #plan-table thead th,
  #plan-table .td-name,
  #plan-table tfoot td {
    background: #EEF2F7 !important;
    color: #0F172A !important;
    font-weight: 700;
  }

  /* Wochenend-/Feiertagsspalten dezent hervorheben (Struktur statt Einheitsbrei). */
  #plan-table .th-day.is-fri,
  #plan-table .td-cell.is-fri,
  #plan-table .th-day.is-weekend,
  #plan-table .td-cell.is-weekend,
  #plan-table .th-day.is-holiday,
  #plan-table .td-cell.is-holiday {
    background: #F1F5F9 !important;
  }

  /* Inner text spans carry their own theme-light colours (e.g. .emp-label is
     white in dark mode) that the cell-level overrides above can't reach, so
     employee names, the corner caption and the footer/legend labels would print
     near-invisible on the light background. Force them dark. The RD-Neurorad
     band keeps its own white-on-teal styling (separate .td-name-rbn class) and
     stays legible, so it is intentionally excluded here. */
  .th-corner-inner,
  #plan-table .td-name .emp-label,
  .tr-stat .td-stat-lbl,
  .tr-stat .stat-lbl-text {
    color: #0F172A !important;
    font-size: 8px !important;
  }

  #plan-table .td-name .emp-label {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
  }

  /* Day header: compact stacked number/weekday. */
  #plan-table .th-day-inner {
    padding: 1px 0 !important;
    gap: 0 !important;
  }

  /* Assignment chips: keep inline, never wrap or overflow the cell. */
  #plan-table .cell-assign,
  #plan-table .cell-assign-rbn,
  #plan-table .mdc-assign-chip {
    font-size: 7.5px !important;
    padding: 0 !important;
    line-height: 1.1 !important;
  }

  /* Decorative/interactive bits that add height or clutter on paper. */
  .day-status-stripe,
  .kbd-hint-group,
  .cell-conflict-flag,
  .cell-pin-flag,
  .cell-multi-badge,
  .emp-sub,
  .td-name-meta {
    display: none !important;
  }

  /* Keep every row on the same page — no row may be split across pages. */
  #plan-table tr,
  #plan-table thead,
  #plan-table tfoot {
    page-break-inside: avoid !important;
    break-inside: avoid !important;
  }
  #plan-table thead { display: table-header-group !important; }

  /* Preserve the role-band structure on paper with a firm divider. */
  #plan-table .tr-band-start .td-name,
  #plan-table .tr-band-start .td-cell {
    border-top: 1.5px solid #0F172A !important;
  }

  #print-footer {
    display: block !important;
    margin-top: 6px;
    font-size: 8px;
    color: #64748B;
    text-align: right;
  }

  @page {
    size: A4 landscape;
    margin: 8mm;
  }
}

/* ═══════════════════════════════════════════════════════════════════════════
   PRINT PREVIEW STYLES (Screen)
   ═══════════════════════════════════════════════════════════════════════════ */

.pp-page {
  --print-preview-scale: 1;
}

.pp-page.portrait {
  --print-preview-scale: 0.7;
}

.pp-page.landscape {
  --print-preview-scale: 0.65;
}
