/* =========================================================================
   TimeSecPlan – Druckansichten und Export-Leiste

   Die Druckregeln gelten nur auf Seiten mit einem Briefkopf (.druck-kopf,
   erzeugt von tsp_druck_kopf() in druck.php). Andere Seiten – etwa der
   Stundenzettel mit seiner eigenen Druckansicht in style.css – bleiben
   unverändert.

   Auf dem Bildschirm unsichtbar:  .druck-kopf, .druck-fuss, .nur-druck
   Auf dem Papier unsichtbar:      .nicht-drucken (Filter, Knöpfe, Aktionen)
   ========================================================================= */

/* ---------- Bildschirm ---------- */
.druck-kopf,
.druck-fuss,
.nur-druck,
.nur-export { display: none; }

.export-leiste {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    margin: 14px 0;
}
.export-leiste button,
.export-leiste a,
.druck-knopf {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: auto;
    margin: 0;
    padding: 9px 14px;
    border: 0;
    border-radius: 6px;
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    color: #fff;
    background: #34495e;
    text-decoration: none;
    cursor: pointer;
}
.export-leiste .ex-xlsx { background: #16a085; }
.export-leiste .ex-csv  { background: #2980b9; }
.export-leiste button:hover,
.export-leiste a:hover,
.druck-knopf:hover { filter: brightness(0.92); }
.export-leiste button:disabled { opacity: 0.6; cursor: wait; }
select.druck-format {
    width: auto;
    margin: 0;
    padding: 8px 10px;
    border: 1px solid #cbd5e0;
    border-radius: 6px;
    background: #fff;
    color: #2c3e50;
    font: inherit;
    font-size: 14px;
}
.export-leiste__hinweis { font-size: 12px; color: #7f8c8d; }
.export-leiste label { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #34495e; margin: 0; }
.export-leiste label input { width: auto; margin: 0; }

/* ---------- Papier ---------- */
@media print {
    @page {
        size: A4;
        margin: 12mm 10mm 14mm 10mm;
        @bottom-right {
            content: "Seite " counter(page) " von " counter(pages);
            font-family: Arial, sans-serif;
            font-size: 8pt;
            color: #555;
        }
    }
    /* Breite Tabellen (Buchungsprotokoll, Objektvergleich) im Querformat */
    @page quer { size: A4 landscape; }
    html.druck-quer body { page: quer; }   /* Auswahl "Querformat" neben dem Druck-Knopf (druck.php) */

    body:has(.druck-kopf) {
        background: #fff !important;
        color: #000 !important;
        font-family: Arial, Helvetica, sans-serif;
        font-size: 9.5pt;
        margin: 0 !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Menü, Leisten und Bedienelemente ausblenden */
    body:has(.druck-kopf) header.tsp-topbar,
    body:has(.druck-kopf) header.main-header,
    body:has(.druck-kopf) .tsp-scrim,
    body:has(.druck-kopf) .approval-bar,
    body:has(.druck-kopf) .session-timer,
    body:has(.druck-kopf) .tl-kopf,
    body:has(.druck-kopf) .export-leiste,
    body:has(.druck-kopf) .nicht-drucken,
    body:has(.druck-kopf) .nur-export,
    body:has(.druck-kopf) [hidden] { display: none !important; }

    body:has(.druck-kopf) .nur-druck { display: block !important; }

    /* Seitenrahmen und Karten flach machen */
    body:has(.druck-kopf) main,
    body:has(.druck-kopf) .container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    body:has(.druck-kopf) .card {
        box-shadow: none !important;
        border: 0 !important;
        border-radius: 0 !important;
        padding: 0 !important;
        margin: 0 0 10px 0 !important;
        background: transparent !important;
    }
    body:has(.druck-kopf) h2 { font-size: 13pt !important; margin: 8px 0 4px !important; }
    body:has(.druck-kopf) h3 { font-size: 11pt !important; margin: 6px 0 3px !important; }
    body:has(.druck-kopf) a { color: #000 !important; text-decoration: none !important; }
    body:has(.druck-kopf) .live-pulse { display: none !important; }

    /* Tabellen: mobile.css macht sie scrollbar (display:block) – auf Papier aufheben */
    body:has(.druck-kopf) table {
        display: table !important;
        width: 100% !important;
        max-width: 100% !important;
        overflow: visible !important;
        white-space: normal !important;
        border-collapse: collapse !important;
        background: none !important;
        box-shadow: none !important;
        font-size: 8.5pt !important;
        margin: 4px 0 8px 0 !important;
    }
    body:has(.druck-kopf) .tl-rahmen,
    body:has(.druck-kopf) .osl-tabelle-rahmen {
        overflow: visible !important;
        border: 0 !important;
        box-shadow: none !important;
        border-radius: 0 !important;
        max-width: 100% !important;
    }
    body:has(.druck-kopf) thead { display: table-header-group !important; }  /* Kopfzeile auf jeder Seite */
    body:has(.druck-kopf) tbody { display: table-row-group !important; }
    body:has(.druck-kopf) tr {
        display: table-row !important;
        break-inside: avoid;
        page-break-inside: avoid;
        background: transparent !important;
    }
    body:has(.druck-kopf) th,
    body:has(.druck-kopf) td {
        display: table-cell !important;
        border: 1px solid #999 !important;
        padding: 3px 5px !important;
        color: #000 !important;
        background: transparent !important;
        vertical-align: top;
        white-space: normal !important;
        overflow-wrap: anywhere;
        line-height: 1.25;
    }
    body:has(.druck-kopf) th {
        background: #e9ecef !important;
        font-weight: bold;
        text-align: left;
        position: static !important;
    }
    body:has(.druck-kopf) th {
        text-transform: none !important;
        letter-spacing: 0 !important;
        font-size: 8pt !important;
        overflow-wrap: normal !important;
        hyphens: auto;
    }
    body:has(.druck-kopf) th::after { content: none !important; }   /* Sortierpfeile */
    body:has(.druck-kopf) tr.druck-summe td { font-weight: bold; background: #f3f4f6 !important; }

    /* Briefkopf */
    .druck-kopf {
        display: block !important;
        border-bottom: 1.5px solid #000;
        padding: 0 0 5px 0;
        margin: 0 0 8px 0;
    }
    .druck-kopf__zeile { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; }
    .druck-kopf__firma { font-size: 9pt; color: #333; }
    .druck-kopf__titel { font-size: 15pt; font-weight: bold; }
    .druck-kopf__stand { font-size: 8pt; color: #333; text-align: right; }
    .druck-kopf__info  { font-size: 9pt; margin-top: 2px; }

    .druck-fuss {
        display: block !important;
        margin-top: 10px;
        font-size: 7.5pt;
        color: #555;
    }

    /* Objekt-Auswertung: Kennzahlen kompakt, jedes Objekt möglichst am Stück */
    body:has(.druck-kopf) .druck-objekt { border-top: 1.5px solid #000 !important; padding-top: 6px !important; margin-top: 12px !important; }
    body:has(.druck-kopf) .druck-objekt > div:first-child,
    body:has(.druck-kopf) .druck-objekt .grid-3 { break-inside: avoid; page-break-inside: avoid; }
    body:has(.druck-kopf) .grid-3 { display: grid !important; grid-template-columns: repeat(5, 1fr) !important; gap: 4px !important; }
    body:has(.druck-kopf) .mini-card { border: 1px solid #bbb !important; box-shadow: none !important; background: #fff !important; padding: 4px 6px !important; margin: 0 !important; }
    body:has(.druck-kopf) .mini-card h4 { font-size: 7pt !important; margin: 0 0 2px !important; color: #333 !important; }
    body:has(.druck-kopf) .mini-card p  { font-size: 10.5pt !important; margin: 0 !important; color: #000 !important; }

    /* Hilfsklassen */
    .druck-neue-seite { break-before: page; page-break-before: always; }
    .druck-zusammen   { break-inside: avoid; page-break-inside: avoid; }
}
