/* =============================================
   System Zarządzania Grafikiem DPS - Style
   Bootstrap 5.3.2 + Custom
   ============================================= */

/* Formularz wewnątrz wiersza tabeli */
form.contents { display: contents; }

/* Custom searchable select */
.searchable-select { position: relative; }
.searchable-select .ss-toggle { width: 100%; text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }
.searchable-select .ss-dropdown { position: absolute; z-index: 1050; width: 100%; min-width: 200px; top: 100%; left: 0; margin-top: 2px; }
.searchable-select .ss-item { cursor: pointer; white-space: nowrap; }
.searchable-select .ss-item:hover { background: #f0f4ff; }

/* ---- CSS Variables ---- */
:root {
    --nav-bg: #2c3e50;
    --nav-hover: #34495e;
    --sidebar-width: 200px;
    --sidebar-bg: #f8f9fa;
    --sidebar-border: #e9ecef;
    --primary-color: #3498db;
    --text-dark: #2c3e50;
    --text-muted: #7f8c8d;
    --navbar-height: 56px;
}

/* ---- Base ---- */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: #f0f2f5;
    overflow-x: hidden;
}

/* ---- Top Navbar ---- */
.bg-dark-nav {
    background-color: var(--nav-bg) !important;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    z-index: 1030;
}

.navbar {
    height: var(--navbar-height);
    padding: 0 1rem;
}

.navbar-brand {
    font-weight: 600;
    font-size: 1.1rem;
    letter-spacing: 0.3px;
}

.sidebar-toggle {
    border: none;
    font-size: 1.2rem;
    padding: 0.25rem 0.5rem;
}

.sidebar-toggle:hover {
    color: var(--primary-color) !important;
}

/* ---- App Wrapper (sidebar + main) ---- */
.app-wrapper {
    display: flex;
    min-height: calc(100vh - var(--navbar-height));
    margin-top: var(--navbar-height);
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    min-height: calc(100vh - var(--navbar-height));
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    flex-shrink: 0;
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 1020;
    transition: transform 0.3s ease;
}

.sidebar-content {
    padding: 1rem 0;
}

.sidebar-section {
    margin-bottom: 1.5rem;
}

.sidebar-heading {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    padding: 0.5rem 1.25rem;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

.sidebar-nav {
    list-style: none;
    padding: 0;
    margin: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.6rem 1.25rem;
    color: #495057;
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
}

.sidebar-link i {
    width: 20px;
    text-align: center;
    margin-right: 0.75rem;
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: color 0.2s ease;
}

.sidebar-link:hover {
    background-color: #e9ecef;
    color: var(--text-dark);
    text-decoration: none;
}

.sidebar-link:hover i {
    color: var(--primary-color);
}

.sidebar-link.active {
    background-color: #e3f0fc;
    color: var(--primary-color);
    border-left-color: var(--primary-color);
    font-weight: 500;
}

.sidebar-link.active i {
    color: var(--primary-color);
}

/* ---- Main Content ---- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-width: 0;
}

/* ---- Stat Cards ---- */
.stat-card {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    border-radius: 0.75rem;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
}

.stat-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    border-radius: 50%;
}

/* ---- Cards ---- */
.card {
    border-radius: 0.75rem;
}

.card-header {
    border-radius: 0.75rem 0.75rem 0 0 !important;
}

/* ---- Tables ---- */
.table th {
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-muted);
    border-bottom-width: 2px;
}

.table td {
    vertical-align: middle;
}

/* ---- Badges ---- */
.badge {
    font-weight: 500;
    letter-spacing: 0.3px;
}

/* ---- Flash alerts ---- */
.flash-alert {
    animation: slideInDown 0.3s ease;
}

@keyframes slideInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---- Login Page ---- */
.login-page {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-container {
    background: white;
    padding: 2.5rem;
    border-radius: 1rem;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.2);
    width: 100%;
    max-width: 420px;
    margin: 1rem;
}

/* ---- Dropdown user ---- */
.dropdown-item-text {
    padding: 0.25rem 1rem;
}

/* ---- Confirm action buttons ---- */
.confirm-action {
    cursor: pointer;
}

/* ---- Footer ---- */
.app-footer {
    margin-left: var(--sidebar-width);
    border-top: 1px solid var(--sidebar-border);
    background: white;
}

/* ---- Form styling ---- */
.form-label {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-dark);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(52, 152, 219, 0.15);
}

/* ---- Search input in tables ---- */
#tableSearch {
    border-radius: 1rem;
    padding-left: 1rem;
}

/* ---- Scrollbar styling ---- */
.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #ced4da;
    border-radius: 2px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: #adb5bd;
}

/* =============================================
   Responsive
   ============================================= */

/* Sidebar hidden by default on mobile */
@media (max-width: 767.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    .sidebar.show {
        transform: translateX(0);
        box-shadow: 4px 0 10px rgba(0, 0, 0, 0.1);
    }

    .main-content {
        margin-left: 0;
    }

    .app-footer {
        margin-left: 0;
    }

    .login-container {
        padding: 2rem;
        margin: 1rem;
    }

    .stat-icon {
        width: 48px;
        height: 48px;
    }

    .stat-icon i {
        font-size: 1.25rem !important;
    }
}

/* Sidebar overlay backdrop on mobile */
.sidebar-backdrop {
    display: none;
    position: fixed;
    top: var(--navbar-height);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 1019;
}

.sidebar-backdrop.show {
    display: block;
}

/* Medium screens */
@media (min-width: 768px) and (max-width: 991.98px) {
    :root {
        --sidebar-width: 220px;
    }
}

/* Print styles */
@media print {
    .sidebar,
    .navbar,
    .app-footer,
    .sidebar-backdrop {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #dee2e6;
    }
}

/* =============================================
   Grafik – tabela Pracownicy × Dni
   ============================================= */

/* Kontener karty */
.schedule-wrapper {
    overflow: hidden;
}

/* Poziomy i pionowy scroll; sticky thead działa wewnątrz tego kontenera */
.schedule-scroll {
    overflow-x: auto;
    overflow-y: auto;
    max-height: calc(100vh - var(--navbar-height) - 160px);
    min-height: 200px;
    -webkit-overflow-scrolling: touch;
}

/* Główna tabela */
.schedule-table {
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.8rem;
    min-width: 900px;
    width: 100%;
}

.my-schedule-table {
    min-width: unset;
}

.schedule-table th,
.schedule-table td {
    border: 1px solid #dee2e6;
    padding: 0;
    vertical-align: middle;
    white-space: nowrap;
}

/* Nagłówki */
.schedule-table thead th {
    background: #2c3e50;
    color: #fff;
    text-align: center;
    font-weight: 600;
    font-size: 0.72rem;
    padding: 4px 3px;
    position: sticky;
    top: 0;
    z-index: 10;
}

/* Kolumna: Pracownik */
.col-name {
    min-width: 160px;
    max-width: 200px;
    text-align: left !important;
    padding: 4px 8px !important;
    position: sticky;
    left: 0;
    z-index: 11;
    background: #fff;
}

/* Kolumna: Inicjały */
.col-init {
    width: 38px;
    text-align: center !important;
    padding: 2px !important;
    position: sticky;
    left: 160px;  /* szerokość col-name */
    z-index: 11;
    background: #fff;
}

/* Kolumna: Etat */
.col-et {
    width: 42px;
    text-align: center !important;
    padding: 2px 3px !important;
    position: sticky;
    left: 198px;  /* 160 + 38 */
    z-index: 11;
    background: #fff;
}

/* Narożniki tabeli: thead + sticky-left → najwyższy z-index */
.schedule-table thead th.col-name,
.schedule-table thead th.col-init,
.schedule-table thead th.col-et {
    z-index: 12;
    background: #2c3e50;
}

/* Separatory grup: ciemne tło na sticky cols */
.group-separator .col-name,
.group-separator .col-init,
.group-separator .col-et {
    background: #2c3e50;
}

/* === Mobile ≤ 767px === */
@media (max-width: 767px) {
    /* Węższa kolumna pracownika z elipsą.
       width (nie tylko max-width) bo table-layout:auto ignoruje max-width */
    .col-name {
        width: 100px !important;
        min-width: 100px;
        max-width: 100px;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    /* !important bo double-sticky (top+left) w thead może ignorować kaskadę */
    .col-init {
        left: 100px !important;
    }
    /* Ukryj kolumnę Etat */
    .col-et {
        display: none;
    }
    /* Ukryj inicjały w widoku zespołu pracownika */
    .team-schedule-view .col-init {
        display: none;
    }
}

/* Kolumna: Dzień */
.col-day {
    width: 34px;
    min-width: 34px;
    text-align: center;
}

.col-day div:first-child {
    font-size: 0.8rem;
    line-height: 1.2;
}

.day-dow {
    font-size: 0.65rem;
    font-weight: 400;
    opacity: 0.75;
}

/* Kolumna: Godziny */
.col-hours {
    width: 52px;
    text-align: center;
    padding: 2px 4px !important;
    position: sticky;
    right: 0;
    z-index: 11;
    background: #f8f9fa;
    border-left: 2px solid #adb5bd !important;
}

.schedule-table thead .col-hours {
    background: #2c3e50;
    border-left: 2px solid #6c8396 !important;
}

/* Sobota — odcienie zieleni */
.schedule-table th.saturday,
.schedule-table td.saturday {
    background-color: #e8f5e9 !important;
}

.schedule-table thead th.saturday {
    background-color: #2e7d32 !important;
}

/* Niedziela — odcienie pomarańczowego */
.schedule-table th.sunday,
.schedule-table td.sunday {
    background-color: #fff3e0 !important;
}

.schedule-table thead th.sunday {
    background-color: #e65100 !important;
}

/* Dzisiaj */
.schedule-table th.today,
.schedule-table td.today {
    background-color: #fff3cd !important;
}

.schedule-table thead th.today {
    background-color: #f0a500 !important;
    color: #fff;
}

/* Święta ustawowe — nadpisują Sb/Nd */
.schedule-table th.holiday,
.schedule-table td.holiday {
    background-color: #fce8e8 !important;
}

.schedule-table thead th.holiday {
    background-color: #c0392b !important;
    color: #fff;
}

.holiday-dot {
    font-size: 0.6rem;
    line-height: 1;
    color: #fff;
    opacity: 0.9;
}

/* Kolorowanie wierszy w widoku "Mój grafik" (lista wierszowa) */
tr.row-saturday td { background-color: #e8f5e9 !important; }
tr.row-sunday td   { background-color: #fff3e0 !important; }
tr.row-holiday td  { background-color: #fce8e8 !important; }

/* Separator grupy */
.group-separator {
    cursor: pointer;
    user-select: none;
}

.group-separator td {
    background: #2c3e50 !important;
    color: #ecf0f1;
    font-weight: 600;
    font-size: 0.8rem;
    padding: 5px 12px !important;
    letter-spacing: 0.3px;
}

/* Komórka z tytułem grupy — sticky, trzyma się lewej krawędzi przy przewijaniu */
.group-separator td.group-sep-label {
    position: sticky;
    left: 0;
    z-index: 11;
    white-space: nowrap;
    border-top: none !important;
    border-bottom: none !important;
    border-right: none !important;
    border-left: 1px solid #dee2e6 !important;
}

/* Pusta komórka dopełniająca wiersz separatora — bez obramowania */
.group-separator td:not(.group-sep-label) {
    border: none !important;
    padding: 0;
}

.group-separator:hover td {
    background: #3d5166 !important;
}

.group-toggle-icon {
    font-size: 0.65rem;
    transition: transform 0.2s ease;
    display: inline-block;
}

.group-separator.collapsed .group-toggle-icon {
    transform: rotate(-90deg);
}

/* Kłódka grupy */
.group-lock-toggle {
    font-size: 0.75rem;
    cursor: pointer;
    opacity: 0.55;
    transition: opacity 0.15s, color 0.15s;
    vertical-align: middle;
}
.group-lock-toggle:hover {
    opacity: 1;
}
.group-lock-toggle.fa-lock {
    color: #f0a500;
    opacity: 0.9;
}
/* Zablokowana grupa — nagłówek wyróżniony */
.group-separator.group-locked td {
    background: #3a3000 !important;
}
.group-separator.group-locked:hover td {
    background: #4a3d00 !important;
}

/* Wiersze pracowników – naprzemienne tło */
.employee-row:nth-child(even) td {
    background-color: #fafafa;
}

.employee-row td.col-name {
    font-size: 0.8rem;
}

/* Komórka dyżuru */
.shift-cell {
    cursor: pointer;
    min-height: 28px;
    height: 28px;
    text-align: center;
    padding: 2px !important;
    transition: background-color 0.1s;
    position: relative;
}
.empty-cell-info {
    position: absolute;
    top: 2px;
    right: 2px;
    line-height: 1;
    pointer-events: auto;
    z-index: 1;
}
.empty-cell-info i {
    font-size: .58rem;
    color: #0d6efd;
    opacity: .8;
}

.shift-cell:hover:not(.readonly) {
    background-color: #dbeafe !important;
}

.shift-cell.readonly {
    cursor: default;
}

/* Badge dyżuru w komórce */
.shift-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    color: #fff;
    cursor: pointer;
    letter-spacing: 0.3px;
    line-height: 1.4;
}

/* Kolory typów dyżurów - dostosuj kody do swojej bazy */
.shift-R { background-color: #2980b9; }   /* Ranny */
.shift-P { background-color: #e67e22; }   /* Popołudniowy */
.shift-N { background-color: #2c3e50; }   /* Nocny */
.shift-D { background-color: #27ae60; }   /* Dodatkowy */
.shift-U { background-color: #8e44ad; }   /* Urlop */
.shift-L { background-color: #c0392b; }   /* L4 */
.shift-W { background-color: #7f8c8d; }   /* Wolny */

/* Legenda */
.schedule-legend .shift-badge {
    font-size: 0.7rem;
    padding: 2px 6px;
}

/* Multi-coverage: dyżur pokrywający kilka grup */
.shift-shared { outline: 2px solid #ffc107; outline-offset: 1px; }
.shift-shared-indicator { font-size: 0.6em; vertical-align: super; }

/* Cross-group: dyżur sporadyczny na innej grupie */
.shift-cross { outline: 2px solid #17a2b8; outline-offset: 1px; }

/* Dyżur ręczny — zablokowany przed nadpisaniem przez generator */
.shift-manual { outline: 2px solid #e74c3c; outline-offset: 1px; }

/* Dyżur przydzielony z preferencji pracownika */
.shift-preference { outline: 2px solid #95a5a6; outline-offset: 1px; }

/* Dyżur będący wynikiem zatwierdzonej zamiany dyżurów */
.shift-swapped { outline: 2px solid #27ae60; outline-offset: 1px; }

/* Dyżur zablokowany przez oczekujący wniosek zamiany — nie usunie się przy czyszczeniu grafiku */
.shift-swap-locked { outline: 2px dashed #e67e22; outline-offset: 1px; }

/* Ikonka kłódki przy zablokowanym dyżurze — link do wniosku */
.shift-lock-link { font-size: 9px; color: #e67e22; text-decoration: none; vertical-align: super; margin-right: 1px; }
.shift-lock-link:hover { color: #d35400; }

/* Dyżur skrócony do 7h — orzeczenie o niepełnosprawności znacznej/umiarkowanej */
.shift-disability { outline: 2px solid #0d6efd; outline-offset: 1px; }

/* Dyżur wynikający z wniosku o pracę w innej grupie */
.shift-group-assignment { outline: 2px dashed #6b9e7a; outline-offset: 1px; }

/* Komórka z niezrealizowaną preferencją (generator nie spełnił zatwierdzonego wniosku) */
.shift-cell.pref-unfulfilled { box-shadow: inset 0 0 0 2px #adb5bd; }

/* Komórka wstępnie zatwierdzonego wniosku (pre_approved) — widoczna tylko dla admina */
.shift-cell.pre-approved-block { box-shadow: inset 0 0 0 2px #f0a500; }

/* Duch preferowanego dyżuru — gdy komórka pusta, a preferencja jest zatwierdzona */
.pref-ghost {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 600;
    color: #6c757d;
    opacity: 0.45;
    pointer-events: none;
    user-select: none;
}

/* Badge absencji w komórce grafiku */
.absence-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0 4px;
    border-radius: 3px;
    color: #fff;
    cursor: pointer;
    letter-spacing: 0.3px;
    line-height: 1.4;
    opacity: 0.9;
    border: 1px solid rgba(0,0,0,0.15);
}

/* Badge ręcznie zablokowanego dnia wolnego */
.free-block-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    color: #495057;
    background: #dee2e6;
    border: 1px dashed #adb5bd;
    letter-spacing: 0.3px;
    line-height: 1.4;
    opacity: 0.9;
    cursor: default;
}
.free-block-badge.free-block-removable {
    cursor: pointer;
}
.free-block-badge.free-block-removable:hover {
    background: #f8d7da;
    border-color: #dc3545;
    color: #dc3545;
}

/* Sticky nagłówek + lewa kolumna w nagłówku */
.schedule-table thead th.col-name {
    z-index: 20;
    left: 0;
}
.schedule-table thead th.col-init {
    z-index: 20;
    left: 160px;
}
.schedule-table thead th.col-et {
    z-index: 20;
    left: 198px;
}
.schedule-table thead th.col-hours {
    z-index: 20;
}

/* Modal – przyciski typów dyżurów */
#shiftTypeBtns .shift-type-btn {
    font-size: 0.78rem;
    padding: 4px 6px;
}

/* Godziny – pole tylko do odczytu */
#modalHours {
    background-color: #f0f4f8;
    font-weight: 600;
    text-align: center;
}

/* Overlay generowania */
#generateOverlay {
    z-index: 9999;
}

/* Drukowanie – usuń sticky, pokaż całą tabelę */
@media print {
    .schedule-scroll {
        overflow: visible;
        max-height: none;
    }

    .col-name,
    .col-init,
    .col-et,
    .col-hours {
        position: static;
    }

    .schedule-table thead th {
        position: static;
    }

    .group-toggle-icon {
        display: none;
    }

    /* Rozwiń wszystkie grupy przy druku */
    .employee-row {
        display: table-row !important;
    }
}

/* Dropdown powiadomień — pełna szerokość na mobile */
@media (max-width: 767px) {
    #notifMenu {
        position: fixed !important;
        top: var(--navbar-height) !important;
        left: 8px !important;
        right: 8px !important;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        transform: none !important;
    }
}
