/* RadioPlan — app.css
   Custom styles that complement Tailwind CDN.
   Grid table, sticky columns, shift badges, absence indicators,
   print layout, scrollbar styling, cell hover, department headers.
*/

/* ── Base ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

/* Alpine.js: Elemente mit x-cloak verstecken bis Alpine initialisiert ist */
[x-cloak] { display: none !important; }

/* ── Schedule Grid Table ───────────────────────────────────────────────────── */
#schedule-grid {
    border-collapse: separate;
    border-spacing: 0;
    width: 100%;
    font-size: 0.75rem; /* 12px */
}

/* Horizontal scroll wrapper */
.grid-scroll-wrapper {
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* Custom thin scrollbar for the grid */
.grid-scroll-wrapper::-webkit-scrollbar {
    height: 5px;
}
.grid-scroll-wrapper::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 3px;
}
.grid-scroll-wrapper::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}
.grid-scroll-wrapper::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ── Sticky Columns ────────────────────────────────────────────────────────── */
#schedule-grid th.col-name,
#schedule-grid td.col-name {
    position: sticky;
    left: 0;
    z-index: 10;
    background: inherit;
    min-width: 160px;
    max-width: 160px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    /* Right border shadow to indicate sticky */
    box-shadow: 2px 0 4px -1px rgba(0,0,0,.08);
}

#schedule-grid th.col-saldo,
#schedule-grid td.col-saldo {
    position: sticky;
    left: 160px;
    z-index: 10;
    background: inherit;
    min-width: 70px;
    max-width: 70px;
    box-shadow: 2px 0 4px -1px rgba(0,0,0,.08);
}

/* Header row stickiness (z-index higher than body cells) */
#schedule-grid thead th {
    position: sticky;
    top: 0;
    z-index: 20;
    background: #f8fafc;
}

#schedule-grid thead th.col-name,
#schedule-grid thead th.col-saldo {
    z-index: 30; /* Corner cells: both sticky axes */
}

/* ── Grid Cells ────────────────────────────────────────────────────────────── */
#schedule-grid td.grid-cell {
    min-width: 48px;
    max-width: 64px;
    height: 36px;
    padding: 2px 3px;
    vertical-align: middle;
    border-right: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    cursor: pointer;
    transition: background-color .1s ease;
    position: relative;
}

#schedule-grid td.grid-cell:hover {
    background-color: #eff6ff !important;
    outline: 2px solid #bfdbfe;
    outline-offset: -2px;
    z-index: 1;
}

#schedule-grid td.grid-cell.cell-weekend {
    background-color: #fafafa;
}

#schedule-grid td.grid-cell.cell-holiday {
    background-color: #fef3c7;
}

#schedule-grid td.grid-cell.cell-today {
    background-color: #eff6ff;
    outline: 2px solid #93c5fd;
    outline-offset: -2px;
}

/* Cell with no entries */
#schedule-grid td.grid-cell.cell-empty::after {
    display: none;
}

/* ── Shift Badges ──────────────────────────────────────────────────────────── */
.shift-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 700;
    line-height: 1.4;
    letter-spacing: .01em;
    white-space: nowrap;
    margin: 1px;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.shift-badge--wish {
    opacity: 0.55;
    border: 1px dashed currentColor;
    font-style: italic;
}

/* ── Absence Indicators ────────────────────────────────────────────────────── */
.absence-indicator {
    display: block;
    width: 100%;
    height: 3px;
    border-radius: 1px;
    margin-top: 2px;
}

.absence-indicator--urlaub   { background-color: #60a5fa; }
.absence-indicator--krank    { background-color: #f87171; }
.absence-indicator--frei     { background-color: #34d399; }
.absence-indicator--default  { background-color: #a78bfa; }

/* Absence overlay within a cell */
td.grid-cell.cell-absent {
    background-color: #f0fdf4 !important;
}
td.grid-cell.cell-absent-pending {
    background-color: #fffbeb !important;
}

/* ── Department Header Rows ────────────────────────────────────────────────── */
#schedule-grid tr.dept-header td {
    background-color: #1e3a5f;
    color: #e2e8f0;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: 4px 8px;
    border-bottom: 2px solid #1e40af;
}

/* ── KW (Calendar Week) Header Row ────────────────────────────────────────── */
#schedule-grid tr.kw-row th {
    font-size: 0.6rem;
    font-weight: 600;
    color: #6b7280;
    background: #f8fafc;
    padding: 2px 0;
    text-align: center;
    border-bottom: 1px solid #e5e7eb;
}

/* ── Totals / Footer Row ───────────────────────────────────────────────────── */
#schedule-grid tfoot td {
    background: #f1f5f9;
    font-weight: 700;
    font-size: 0.7rem;
    color: #374151;
    border-top: 2px solid #e2e8f0;
    text-align: center;
}

/* ── Modal overlay ─────────────────────────────────────────────────────────── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .45);
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal-panel {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0,0,0,.25);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
}

/* Modal scrollbar */
.modal-panel::-webkit-scrollbar { width: 4px; }
.modal-panel::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* ── Print Layout ──────────────────────────────────────────────────────────── */
@media print {
    /* Hide navigation, buttons, modals, toasts */
    nav,
    .no-print,
    #toast-container,
    .modal-backdrop,
    button,
    .grid-scroll-wrapper::-webkit-scrollbar {
        display: none !important;
    }

    body {
        background: #fff !important;
        font-size: 11px;
    }

    .grid-scroll-wrapper {
        overflow: visible !important;
    }

    #schedule-grid {
        font-size: 9px;
    }

    #schedule-grid td.col-name,
    #schedule-grid th.col-name,
    #schedule-grid td.col-saldo,
    #schedule-grid th.col-saldo {
        position: static !important;
        box-shadow: none !important;
    }

    #schedule-grid td.grid-cell {
        min-width: 30px;
        max-width: 36px;
        height: auto;
        padding: 1px 2px;
        cursor: default;
    }

    #schedule-grid td.grid-cell:hover {
        background: inherit !important;
        outline: none !important;
    }

    .shift-badge {
        padding: 0 3px;
        font-size: 7px;
    }

    /* Page break control */
    tr.dept-header { page-break-before: auto; }

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

/* ── Responsive helpers ────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    #schedule-grid td.grid-cell {
        min-width: 36px;
    }

    .shift-badge {
        font-size: 0.6rem;
        padding: 1px 3px;
    }
}

/* ── Utility: visually hidden (accessible) ─────────────────────────────────── */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0,0,0,0);
    white-space: nowrap;
    border-width: 0;
}

/* ── Loading spinner ───────────────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #e5e7eb;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin .6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
