/* === STYL BAZOWY I UKŁAD === */
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    line-height: 1.6;
    background-color: #f4f7f6;
    color: #333;
    margin: 0;
}

/* === SIDEBAR (PASEK BOCZNY) === */
.sidebar {
    width: 220px;
    background-color: #212c39;
    color: white;
    padding: 20px;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    z-index: 500;
    transition: transform 0.3s ease;
}

.sidebar h1 {
    font-size: 24px;
    margin-top: 0;
    text-align: center;
}

.sidebar nav { flex-grow: 1; }
.sidebar nav ul {
    list-style-type: none;
    padding: 0;
    margin: 30px 0 0 0;
    display: flex;
    flex-direction: column;
    height: 100%;
}
.sidebar nav li { margin-bottom: 10px; }

.sidebar nav a {
    text-decoration: none;
    color: #ecf0f1;
    display: block;
    padding: 12px 15px;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.sidebar nav a:hover { background-color: #34495e; }
.sidebar nav a[href="{{ request.path }}"] {
    background-color: #3498db;
    color: white;
    font-weight: bold;
}

.sidebar nav li.account-link {
    border-top: 1px solid #34495e;
    margin-bottom: 15%;
}

/* === CONTENT (TREŚĆ GŁÓWNA) === */
.content {
    margin-left: 220px;
    padding: 30px;
    max-width: 1200px;
    margin-top: 20px;
    margin-bottom: 20px;
    margin-right: auto;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    box-sizing: border-box;
    transition: margin-left 0.3s ease;
}

body.full-width-content .content { max-width: 95%; }

/* === ELEMENTY UI === */
button {
    font-size: 16px;
    padding: 12px 20px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    margin-bottom: 20px;
    transition: background-color 0.2s;
}
button:hover { background-color: #0056b3; }
button:disabled { background-color: #bdc3c7; cursor: not-allowed; }

#deleteButton { background-color: #c0392b;  border: #c0392b;}
#deleteButton:hover { background-color: #a53024;  border: #a53024;}

#cancelButton, #addCancelButton, #importCancelButton { background-color: #7f8c8d; }
#cancelButton:hover, #addCancelButton:hover, #importCancelButton:hover { background-color: #6c7a7b; }

#resultsContainer {
    /* Wygląd ramki */
    border: 1px solid #ddd;
    background-color: #fdfdfd;
    
    /* KLUCZOWE ZMIANY DLA PASKA PRZEWIJANIA: */
    width: 100%;
    max-height: 50vh;      /* Maksymalna wysokość to 80% widoku ekranu */
    overflow: auto;        /* Włącza paski przewijania (poziomy i pionowy) gdy potrzebne */
    position: relative;    /* Kontekst dla sticky header */
    padding: 0;            /* Reset paddingu, żeby nagłówek przykleił się idealnie do góry */
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

/* Upewniamy się, że tabela zachowuje proporcje */
#resultsContainer table {
    width: 100%;
    border-collapse: separate; /* Wymagane dla sticky header w niektórych przeglądarkach */
    border-spacing: 0;
}

/* PRZYKLEJONY NAGŁÓWEK TABELI */
#resultsContainer th {
    position: sticky;
    top: 0;
    z-index: 10;
    /* Musi mieć tło, inaczej treść będzie prześwitywać pod spodem przy przewijaniu */
    background-color: #e9ecef; 
    border-top: none;
    border-bottom: 2px solid #ddd; /* Mocniejsza linia oddzielająca */
    box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1); /* Delikatny cień pod nagłówkiem */
}

/* Korekta obramowania komórek przy sticky header */
#resultsContainer th, #resultsContainer td {
    border-left: none;
    border-right: 1px solid #ddd;
    border-bottom: 1px solid #ddd;
}
#resultsContainer th:first-child, #resultsContainer td:first-child {
    border-left: 1px solid #ddd;
}

table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px; border: 1px solid #ddd; text-align: left; white-space: nowrap; }
th { background-color: #e9ecef; }
.success { color: #27ae60; }
.error { color: #c0392b; }

hr.section-divider { margin: 30px 0; border: 0; border-top: 1px solid #ddd; }

/* === FORMULARZE I GRID === */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}
.form-grid > div { display: flex; flex-direction: column; }
.form-grid label { font-weight: bold; margin-bottom: 5px; }
.form-grid input, .form-grid select {
    padding: 8px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; width: 100%;
}
.form-grid input[type="checkbox"] { width: auto; }

/* === FILTRY === */
#filterForm {
    margin: 15px 0 25px 0; padding: 15px; background-color: #f9f9f9;
    border: 1px solid #eee; border-radius: 4px; display: flex; flex-wrap: wrap; gap: 15px; align-items: flex-end;
}
#filterForm span { font-weight: bold; margin-bottom: 0; display: block; width: 100%; }
#filterForm .filter-group { display: flex; flex-direction: column; }
#filterForm .filter-group label { margin-bottom: 5px; font-size: 14px; }
#filterForm .filter-input { padding: 8px; border: 1px solid #ccc; border-radius: 4px; }
#filterForm button[type="submit"] { margin-bottom: 0; }

/* === MODALE === */
.hidden { display: none; }

/* Tło modali */
#editModalBackdrop, 
#addModalBackdrop, 
#importModalBackdrop, 
#closeSessionBackdrop {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 1000;
}

/* Główne okna modali */
#editModal, 
#addModal, 
#importModal, 
#closeSessionModal {
    position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
    background: white; padding: 25px; border-radius: 8px; z-index: 1001;
    width: 90%; box-shadow: 0 5px 15px rgba(0,0,0,0.3); box-sizing: border-box;
    max-height: 90vh; overflow-y: auto; overflow-x: visible; 
}

/* Szerokości specyficzne */
#editModal, 
#addModal,
#closeSessionModal { max-width: 800px; }
#importModal { max-width: 500px; }

/* Przyciski zamykania X */
#modalCloseButton, 
#addModalCloseButton, 
#importModalCloseButton,
#closeSessionCloseButton {
    position: absolute; top: 15px; right: 20px; font-size: 24px; cursor: pointer; color: #aaa;
}

#modalStatus, #insertStatus, #importStatus { margin-top: 15px; font-weight: bold; }
hr.modal-divider { border: 0; border-top: 1px solid #eee; margin: 20px 0; }
.modal-actions { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 10px; }
.modal-actions button { margin-bottom: 0; }
#editForm .form-group-status { grid-column: 1 / -1; flex-direction: row; align-items: center; }
#editForm .form-group-status input { margin-left: 10px; }

/* Panel informacyjny wewnątrz modali (np. Zamykanie Sesji) */
.info-box {
    background-color: #f8f9fa; /* Jasnoszary dla Light Mode */
    padding: 15px;
    border-radius: 6px;
    border: 1px solid #e9ecef;
    margin-bottom: 20px;
    font-size: 0.95em;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

/* === RESPONSYWNOŚĆ === */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: 250px; }
    .sidebar.active { transform: translateX(0); }
    .content { margin-left: 0; width: 100%; padding: 15px; }
    .form-grid { grid-template-columns: 1fr; }
    #editModal, #addModal, #importModal, #closeSessionModal { width: 95%; padding: 15px; }
} 

/* ========================================= */
/* === MULTI-SELECT & INPUT FIX === */
/* ========================================= */

/* 1. Ujednolicenie zwykłego inputa */
#filterForm .filter-input {
    box-sizing: border-box;
    width: 100%;
    height: 40px; 
    padding: 0 12px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 16px; 
    line-height: normal; 
    background-color: #fff;
}

/* 2. Reset KONTENERA Multiselecta */
.multiselect-container {
    box-sizing: border-box;
    width: 100%;
    min-width: 200px;
    position: relative;
    border: none !important;
    padding: 0 !important;
    background: transparent !important;
    margin: 0 !important;
}

/* 3. Stylizacja TRIGGERA */
.multiselect-trigger {
    box-sizing: border-box;
    width: 100%;
    height: 40px; 
    border: 1px solid #ccc; 
    border-radius: 4px;
    background: #fff;
    padding: 0 12px; 
    display: flex;
    align-items: center; 
    justify-content: space-between; 
    font-size: 14px; 
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    color: #333; 
}

/* Strzałka */
.multiselect-trigger:after {
    content: '▼';
    font-size: 10px;
    margin-left: 10px;
    color: #666;
    flex-shrink: 0;
}

/* 4. Lista rozwijana (Opcje) */
.multiselect-options {
    display: none;
    position: absolute;
    top: 100%; 
    left: 0;
    right: 0;
    background: #fff;
    border: 1px solid #ccc;
    border-top: none; 
    max-height: 200px;
    overflow-y: auto;
    z-index: 2000;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    border-radius: 0 0 4px 4px;
    margin-top: -1px; 
}

.multiselect-options.active { display: block; }

.multiselect-option {
    padding: 8px 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #eee;
    font-size: 14px;
}

.multiselect-option:hover { background-color: #f5f5f5; }

.multiselect-option:last-child { border-bottom: none; }

.multiselect-option input[type="checkbox"] {
    margin-right: 10px;
    width: auto;
    height: auto; 
    cursor: pointer;
}

.multiselect-option label {
    cursor: pointer;
    width: 100%;
    font-weight: normal;
    margin: 0;
    user-select: none;
}

/* ========================================= */
/* === QR CODE MODAL === */
/* ========================================= */

.qr-modal {
    display: none; 
    position: fixed; 
    z-index: 2000; 
    left: 0;
    top: 0;
    width: 100%; 
    height: 100%; 
    overflow: auto; 
    background-color: rgba(0,0,0,0.5); 
    justify-content: center;
    align-items: center;
}

.qr-modal.flex-active { display: flex; }

.qr-modal-content {
    background-color: #fefefe;
    padding: 30px;
    border: 1px solid #888;
    width: 350px;
    border-radius: 8px; 
    text-align: center;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
    position: relative;
}

#qrcode-container {
    margin: 20px auto;
    display: flex;
    justify-content: center;
    padding: 10px;
    background: white; 
}

.qr-close-btn {
    background-color: #7f8c8d;
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 15px;
    font-size: 14px;
    transition: background-color 0.2s;
}

.qr-close-btn:hover { background-color: #6c7a7b; }

.qr-download-btn {
    background-color: #27ae60; 
    color: white;
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    margin-top: 15px;
    margin-right: 10px; 
    font-size: 14px;
    transition: background-color 0.2s;
}

.qr-download-btn:hover { background-color: #219150; }

/* ========================================= */
/* === DARK MODE (TRYB CIEMNY) === */
/* ========================================= */

/* 1. GŁÓWNE TŁO I TEKST */
body.dark-mode {
    background-color: #121212;
    color: #e0e0e0;
}

/* 2. KONTENERY I PANELE */
/* Zmienia tło białych "kart" (content, modale, filtry) na ciemnoszary */
body.dark-mode .content,
body.dark-mode #filterForm,
body.dark-mode #editModal,
body.dark-mode #addModal,
body.dark-mode #importModal,
body.dark-mode #closeSessionModal,
body.dark-mode .qr-modal-content {
    background-color: #1e1e1e; 
    color: #e0e0e0;            
    border-color: #333;        
    box-shadow: 0 2px 5px rgba(0,0,0,0.5); 
}

/* 5. TABELE W DARK MODE */
body.dark-mode #resultsContainer {
    background-color: #1e1e1e;
    border-color: #444;
}

body.dark-mode #resultsContainer th {
    /* Ciemne tło dla przyklejonego nagłówka */
    background-color: #2c2c2c !important; 
    color: #fff;
    border-color: #555;
    border-bottom: 2px solid #555;
}

body.dark-mode #resultsContainer td {
    border-color: #444;
    color: #e0e0e0;
}

body.dark-mode #resultsContainer tr:hover {
    background-color: #2a2a2a;
}

/* Specyfika dla nagłówka w modalu zamykania sesji */
body.dark-mode #closeSessionModal h3 {
    color: #ffffff;
    border-bottom: 1px solid #333;
    padding-bottom: 10px;
    margin-bottom: 15px;
}

/* Panel informacyjny (Operator, Wózek, MTH) - Dark Mode */
body.dark-mode .info-box {
    background-color: #2c2c2c !important; 
    color: #d1d1d1 !important;
    border: 1px solid #444 !important;
}

/* Komunikat błędu (czytelniejszy na ciemnym tle) */
body.dark-mode #mthError {
    color: #ff6b6b !important;
}

/* 3. NAGŁÓWKI I TYTUŁY */
body.dark-mode h1, 
body.dark-mode h2, 
body.dark-mode h3 {
    color: #ffffff;
}

/* 4. FORMULARZE I INPUTY */
body.dark-mode input,
body.dark-mode select,
body.dark-mode textarea,
body.dark-mode #filterForm .filter-input,
body.dark-mode #filterForm input,
body.dark-mode .multiselect-trigger,
body.dark-mode .multiselect-options {
    background-color: #2c2c2c !important;
    color: #ffffff !important;
    border-color: #555 !important;
}

body.dark-mode input:focus,
body.dark-mode select:focus,
body.dark-mode textarea:focus {
    border-color: #3498db !important;
    outline: none;
}

body.dark-mode ::placeholder {
    color: #bbbbbb;
    opacity: 1;
}

body.dark-mode .multiselect-trigger:after {
    color: #aaa;
}

body.dark-mode .multiselect-option:hover {
    background-color: #3a3a3a;
}
body.dark-mode .multiselect-option {
    border-bottom-color: #444;
}

/* Ikonka kalendarza na biało */
body.dark-mode input[type="date"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
    cursor: pointer;
}

/* 5. TABELE */
body.dark-mode table th {
    background-color: #252525;
    color: #fff;
    border-color: #444;
}
body.dark-mode table td {
    border-color: #444;
}
body.dark-mode tr:hover {
    background-color: #2a2a2a;
}

/* 6. PRZYCISKI I UI */
body.dark-mode #themeToggleBtn {
    color: #fff !important;
    border-color: #666 !important;
    background-color: transparent !important;
}

body.dark-mode .sidebar {
    background-color: #1a222c;
    border-right: 1px solid #333;
}

body.dark-mode hr {
    border-top-color: #444;
}

body.dark-mode #qrcode-container {
    background-color: #fff;
    border-radius: 4px;
}

/* ========================================= */
/* === PRZYCISKI W DARK MODE (STONOWANE) === */
/* ========================================= */

/* 1. Główne niebieskie przyciski */
body.dark-mode button,
body.dark-mode .sidebar nav a[href*="logout"] {
    transition: background-color 0.2s, border-color 0.2s;
}

body.dark-mode button {
    background-color: #155a9e;
    color: #e0e0e0;
    border: 1px solid #10467c;
}

body.dark-mode button:hover {
    background-color: #10467c;
}

/* 2. Przyciski CZERWONE (Usuwanie / Zamykanie sesji) */
body.dark-mode #deleteButton,
body.dark-mode #confirmCloseBtn { 
    background-color: #c0392b !important; 
    border-color: #c0392b !important;
    color: white !important;
}
body.dark-mode #deleteButton:hover,
body.dark-mode #confirmCloseBtn:hover { 
    background-color: #a53024 !important; 
    border-color: #a53024 !important;
}

/* 3. Przyciski SZARE (Anuluj) */
body.dark-mode #cancelButton, 
body.dark-mode #addCancelButton, 
body.dark-mode #importCancelButton,
body.dark-mode #cancelCloseBtn {
    background-color: #3a3a3a !important;
    color: #ccc !important;
    border: 1px solid #2a2a2a !important;
}

body.dark-mode #cancelButton:hover, 
body.dark-mode #addCancelButton:hover, 
body.dark-mode #importCancelButton:hover,
body.dark-mode #cancelCloseBtn:hover {
    background-color: #2a2a2a !important;
}

/* 4. Przycisk nieaktywny */
body.dark-mode button:disabled {
    background-color: #2c2c2c !important;
    color: #666 !important;
    border-color: #444 !important;
    cursor: not-allowed;
}