/* ================================================================= */
/* === 1. ZMIENNE I BAZA === */
/* ================================================================= */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

:root {
    --primary: #E60000;
    --primary-dark: #C00000;
    --primary-light: #FF3333;
    --secondary: #333333;
    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;
    --info: #3b82f6;
    --background: #f8fafc;
    --surface: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --border-light: #f1f5f9;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --radius-lg: 0.75rem;
    --radius-md: 0.5rem;
    --nav-height: 65px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { 
    font-family: 'Roboto', sans-serif; 
    line-height: 1.6; 
    color: var(--text-primary); 
    background-color: var(--background);
    /* Zabezpieczenie miejsca na menu dolne na telefonach */
    padding-bottom: calc(var(--nav-height) + 20px + env(safe-area-inset-bottom));
}

/* ================================================================= */
/* === 2. STRONA LOGOWANIA === */
/* ================================================================= */
.login-page { 
    min-height: 100vh; display: flex; align-items: center; justify-content: center; 
    padding: 1rem; background-color: var(--background);
    position: fixed; top: 0; left: 0; width: 100%; z-index: 2000; overflow-y: auto;
}
.login-container { 
    background: var(--surface); padding: 2.5rem; border-radius: 1rem; 
    box-shadow: 0 10px 25px rgba(0,0,0,0.1); width: 100%; max-width: 400px; 
    border: 1px solid var(--border); text-align: center; 
}
.logo-container { margin-bottom: 2rem; }
.epaka-logo { max-width: 180px; height: auto; margin: 0 auto 1rem auto; display: block; }
.login-subtitle { color: var(--text-secondary); font-size: 0.9rem; }

/* Wybór użytkownika (Avatary) */
.user-selection-grid { display: flex; justify-content: center; gap: 15px; margin-bottom: 2rem; }
.user-avatar { display: flex; flex-direction: column; align-items: center; cursor: pointer; transition: transform 0.2s ease, opacity 0.2s; width: 90px; opacity: 0.6; }
.user-avatar:hover { transform: translateY(-3px); opacity: 1; }
.user-avatar img { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; box-shadow: 0 4px 6px rgba(0,0,0,0.1); margin-bottom: 0.5rem; border: 3px solid transparent; transition: all 0.2s; background-color: #eee; }
.user-avatar span { font-size: 0.9rem; font-weight: 500; color: var(--text-secondary); }
.user-avatar.selected { opacity: 1; transform: scale(1.1); }
.user-avatar.selected img { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(230, 0, 0, 0.15); }
.user-avatar.selected span { color: var(--primary); font-weight: bold; }

/* ================================================================= */
/* === 3. UKŁAD I NAGŁÓWEK === */
/* ================================================================= */
.dashboard { min-height: 100vh; background: var(--background); }
.dashboard-header { background: var(--surface); border-bottom: 1px solid var(--border); padding: 0.5rem 0; position: sticky; top: 0; z-index: 100; }

.header-content {
    display: grid;
    grid-template-columns: 50px 1fr 50px; /* Avatar - Logo - Puste/Logout */
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
    min-height: 50px;
}

.brand-with-logo { justify-self: center; }
.brand-logo { height: 35px; }

/* Avatar w nagłówku */
.header-avatar {
    width: 40px; height: 40px; border-radius: 50%; overflow: hidden;
    cursor: pointer; border: 2px solid var(--border);
    transition: transform 0.2s, border-color 0.2s;
}
.header-avatar:hover { transform: scale(1.05); border-color: var(--primary); }
.header-avatar img { width: 100%; height: 100%; object-fit: cover; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem; }
.section { background: var(--surface); border-radius: var(--radius-lg); padding: 1.5rem; margin-bottom: 1.5rem; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; border-bottom: 2px solid var(--border-light); padding-bottom: 1rem; }
.section-title { font-size: 1.25rem; font-weight: 700; color: var(--text-primary); }

/* ================================================================= */
/* === 4. FORMULARZE I PRZYCISKI === */
/* ================================================================= */
.form-group { margin-bottom: 1.5rem; text-align: left; }
.form-label { display: block; font-weight: 500; margin-bottom: 0.5rem; color: var(--text-secondary); }
.form-input, .form-select { width: 100%; padding: 0.875rem 1rem; border: 2px solid var(--border); border-radius: var(--radius-md); font-size: 1rem; background: var(--background); transition: border-color 0.2s; }
.form-input:focus, .form-select:focus { outline: none; border-color: var(--primary); }

.btn { display: inline-flex; align-items: center; justify-content: center; padding: 0.875rem 1.5rem; border: none; border-radius: var(--radius-md); font-weight: 700; cursor: pointer; width: 100%; transition: 0.2s; text-decoration: none; }
.btn-primary { background: var(--primary); color: white; }
.btn-secondary { background: var(--secondary); color: white; }
.btn-danger { background: var(--error); color: white; }
.btn-success { background: var(--success); color: white; }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.8rem; width: auto; }

/* ================================================================= */
/* === 5. KOMPONENTY UI === */
/* ================================================================= */

/* --- Pulpit (Dashboard Cards) --- */
.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; }
.dashboard-card { background: var(--surface); padding: 1.5rem; border-radius: var(--radius-lg); border: 1px solid var(--border); transition: transform 0.2s; }
.dashboard-value { font-size: 1.8rem; font-weight: 700; }

/* --- Kasa --- */
.cash-display { background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%); border: 1px solid #cbd5e1; border-radius: var(--radius-lg); padding: 2rem; text-align: center; margin-bottom: 1.5rem; }
.cash-amount { font-size: 3rem; font-weight: 700; color: var(--text-primary); }

/* --- Kurierzy --- */
.couriers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 1rem; }
.courier-card { 
    background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius-lg); 
    padding: 1rem; text-align: center; cursor: pointer; 
    display: flex; flex-direction: column; align-items: center; justify-content: center; 
    overflow: hidden; transition: all 0.3s ease;
}
.courier-card img { height: 45px; width: auto; max-width: 100%; object-fit: contain; margin-bottom: 0.5rem; filter: grayscale(100%); opacity: 0.4; transition: all 0.3s ease; }
.courier-card.visited { border-color: var(--success); background: #f0fdf4; }
.courier-card.visited img { filter: grayscale(0%); opacity: 1; transform: scale(1.05); }
.courier-card:hover img { opacity: 0.8; }
.courier-card.visited:hover img { opacity: 1; }

/* --- Dziennik & Wnioski --- */
.logbook-entry { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.logbook-entry.type-message { border-left: 4px solid var(--info); }
.logbook-entry.type-order { border-left: 4px solid var(--warning); }

/* --- Statystyki Admina --- */
.admin-stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.stat-card { background: var(--surface); padding: 1.5rem; border-radius: var(--radius-lg); box-shadow: var(--shadow-md); border: 1px solid var(--border-light); display: flex; align-items: center; gap: 1.5rem; cursor: pointer; position: relative; overflow: hidden; }
.stat-card.type-warning::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--warning); }
.stat-card.type-success::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--success); }
.stat-card.type-danger::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--error); }
.stat-card.type-info::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--info); }

/* --- Tabela Grafiku (Desktop Base) --- */
.schedule-table { width: 100%; border-collapse: separate; border-spacing: 0; border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; }
.schedule-table th, .schedule-table td { padding: 1rem; border: 1px solid var(--border-light); text-align: left; }
.schedule-table th { background: var(--background); font-weight: 700; }

/* --- Skeleton Loader --- */
.skeleton { background: linear-gradient(90deg, #f1f5f9 0px, #e2e8f0 40px, #f1f5f9 80px); background-size: 300px 100%; animation: shimmer 1.5s infinite linear; border-radius: 4px; }
@keyframes shimmer { 0% { background-position: -300px 0; } 100% { background-position: 300px 0; } }

/* ================================================================= */
/* === 6. MODALE (PROFIL I WNIOSKI) === */
/* ================================================================= */
.request-modal, #profileModal {
    display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5); z-index: 3000;
}

/* Modal Wniosków (Centrum) */
.request-modal { align-items: center; justify-content: center; backdrop-filter: blur(5px); }
.request-modal-content { background: var(--surface); padding: 2rem; border-radius: var(--radius-lg); max-width: 500px; width: 90%; animation: modalSlideUp 0.3s ease-out; }
@keyframes modalSlideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

/* Modal Profilu (Lewy Dolny Róg) */
#profileModal { align-items: flex-end; justify-content: flex-start; z-index: 5000; }
#profileModal .modal-content {
    background: var(--surface); width: 350px; max-height: 80vh; overflow-y: auto;
    position: absolute; bottom: 20px; left: 20px; padding: 20px;
    border-radius: 16px; box-shadow: 0 10px 25px rgba(0,0,0,0.2); border: 1px solid var(--border);
    animation: slideUp 0.3s ease-out forwards;
}
@keyframes slideUp { from { transform: translateY(100%); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.menu-section { border-bottom: 1px solid var(--border); padding-bottom: 15px; margin-bottom: 15px; }
.menu-section:last-child { border-bottom: none; margin-bottom: 0; }
.menu-title { font-size: 0.9rem; text-transform: uppercase; color: var(--text-muted); margin-bottom: 10px; font-weight: 700; }

/* Responsywność Modala Profilu */
@media (max-width: 600px) {
    #profileModal .modal-content { width: 100%; left: 0; bottom: 0; border-radius: 20px 20px 0 0; padding-bottom: 40px; }
}

/* ================================================================= */
/* === 7. NAWIGACJA (MOBILE FIRST) === */
/* ================================================================= */
.tab-content { display: none; }
.tab-content.active { display: block; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* --- Kontener (Pasek na dole) --- */
.tabs-container {
    position: fixed !important; bottom: 0 !important; left: 0 !important; width: 100% !important; z-index: 1000 !important;
    height: 65px !important;
    background: rgba(255, 255, 255, 0.98) !important;
    backdrop-filter: blur(20px) !important;
    border-top: 1px solid rgba(0,0,0,0.05) !important;
    box-shadow: 0 -5px 20px rgba(0,0,0,0.05) !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
    height: calc(65px + env(safe-area-inset-bottom)) !important;
    padding-left: 0 !important; padding-right: 0 !important; margin: 0 !important;
}

/* --- Wnętrze (Flex) --- */
.tabs {
    display: flex !important; width: 100% !important; height: 100% !important;
    margin: 0 !important; padding: 0 !important; justify-content: space-between !important;
}

/* --- Przyciski (Mobile) --- */
.tab-button {
    flex: 1 !important; display: flex !important; flex-direction: column !important;
    align-items: center !important; justify-content: center !important;
    background: transparent !important; border: none !important;
    padding: 0 !important; margin: 0 !important; height: 100% !important;
    color: #94a3b8 !important; position: relative !important;
}

.tab-button .tab-icon, .tab-button span:first-child {
    font-size: 1.4rem !important; margin-bottom: 2px !important;
    transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) !important;
    display: block !important; line-height: 1 !important;
}

.tab-button .tab-label, .tab-button span:last-child {
    font-size: 0.65rem !important; font-weight: 500 !important;
    letter-spacing: 0.3px !important; display: block !important;
}

/* Stan Aktywny (Mobile) */
.tab-button.active { color: #E60000 !important; }
.tab-button.active .tab-icon, .tab-button.active span:first-child { transform: translateY(-4px) !important; color: #E60000 !important; }
.tab-button.active::after {
    content: ''; position: absolute; top: 6px; width: 20px; height: 3px;
    background: #E60000; border-radius: 10px;
}

/* ========================================= */
/* === NAPRAWA MOBILNA (FIX ROZCIĄGANIA) === */
/* ========================================= */
@media (max-width: 768px) {
    
    /* 1. Zabezpieczenie całej strony przed rozciąganiem na boki */
    body, html {
        overflow-x: hidden !important; /* Ukryj pasek przewijania poziomego */
        width: 100% !important;
        max-width: 100% !important;
    }

    /* 2. Kontener główny */
    .container { 
        padding: 10px !important; 
        width: 100% !important; 
        box-sizing: border-box !important;
        /* Miejsce na dole na menu */
        padding-bottom: calc(65px + env(safe-area-inset-bottom) + 20px) !important; 
    }

    .dashboard-header { padding: 0.5rem 0; text-align: center; }

    /* ========================================= */
    /* =========== SIATKA PULPITU ============ */
    /* ========================================= */
    .dashboard-grid, #dashboardContent { 
        display: grid !important;
        /* Dwie kolumny, ale elastyczne (min. 0) żeby nie rozpychały */
        grid-template-columns: 1fr 1fr !important; 
        gap: 10px !important;
        width: 100% !important;
    }

    /* Kafelki ogólne */
    .dashboard-card {
        padding: 12px !important;
        min-height: 0 !important; /* Nie rozciągaj niepotrzebnie */
        height: auto !important;
        word-wrap: break-word !important; /* Złam długie słowa */
    }

    /* --- Kafelki 1 (Gotówka) - Cała szerokość --- */
    #dashboardContent > div:nth-child(1) { 
        grid-column: 1 / -1 !important; 
    }

    /* --- Kafelki 2 i 3 (Dziś/Jutro) - Obok siebie --- */
    #dashboardContent > div:nth-child(2),
    #dashboardContent > div:nth-child(3) {
        grid-column: span 1 !important; /* Zajmują po 1 kolumnie */
    }

    /* WAŻNE: Naprawa tekstów w małych kafelkach */
    #dashboardContent > div:nth-child(2) div,
    #dashboardContent > div:nth-child(3) div {
        font-size: 0.75rem !important; /* Mniejszy tekst */
        line-height: 1.3 !important;
        white-space: normal !important; /* POZWÓL ŁAMAĆ LINIE! (To naprawia rozciąganie) */
        overflow-wrap: break-word !important;
    }
    
    /* Ukryj nagłówek "Dziś pracują" jeśli zajmuje za dużo miejsca, zostaw samą treść */
    #dashboardContent > div:nth-child(2) h3,
    #dashboardContent > div:nth-child(3) h3 {
        font-size: 0.8rem !important;
        margin-bottom: 5px !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
    }

    /* --- Kafelki 4 (Kurierzy) - Cała szerokość --- */
    #dashboardContent > div:nth-child(4) { 
        grid-column: 1 / -1 !important; 
    }

    /* Lista kurierów (tekst) */
    #dashboardContent > div:nth-child(4) div {
        white-space: normal !important; /* Lista kurierów musi się zawijać */
        line-height: 1.4 !important;
    }

    /* ========================================= */
    /* =========== TABELA GRAFIKU ============ */
    /* ========================================= */
    .section:has(.schedule-table) {
        width: 100% !important; 
        margin: 0 0 1.5rem 0 !important; 
        padding: 0 !important;
        border-radius: 12px; 
        overflow: hidden; /* Ucinaj wystające elementy */
        border: 1px solid var(--border);
    }

    .schedule-table { 
        display: table !important; 
        width: 100% !important; 
        table-layout: fixed !important; /* Sztywne kolumny */
        border: none !important;
    }

    .schedule-table td:first-child {
        width: 80px !important; /* Sztywna szerokość daty */
        padding: 10px 5px !important;
    }
    
    .schedule-table td:last-child {
        /* Reszta miejsca dla godzin */
        padding: 10px !important;
    }
}

/* ================================================================= */
/* === 9. WERSJA KOMPUTEROWA (DESKTOP OVERRIDES) === */
/* ================================================================= */
@media (min-width: 1024px) {
    /* Nawigacja (Sticky Top Bar) */
    .tabs-container {
        position: sticky !important; top: 58px !important; bottom: auto !important; left: 0 !important;
        height: auto !important; padding: 0 !important; background: #ffffff !important;
        border-bottom: 1px solid #e2e8f0 !important; border-top: none !important;
        box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05) !important;
    }
    .tabs { max-width: 1200px !important; margin: 0 auto !important; justify-content: center !important; gap: 20px !important; }
    
    .tab-button {
        flex: 0 1 auto !important; flex-direction: row !important; padding: 15px 25px !important; gap: 10px !important;
    }
    .tab-button .tab-label, .tab-button span:last-child { font-size: 1rem !important; margin-top: 0 !important; }
    .tab-button.active { background-color: #fef2f2 !important; border-bottom: 2px solid #E60000 !important; }
    .tab-button.active .tab-icon, .tab-button.active span:first-child { transform: none !important; }
    .tab-button.active::after { display: none !important; }

    /* Layout */
    .container, .dashboard-content { padding-top: 30px !important; }
    .admin-stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ================================================================= */
/* === 10. TRYB CIEMNY (DARK MODE) === */
/* ================================================================= */
[data-theme="dark"], body.dark-mode {
    --background: #0f172a; --surface: #1e293b; --text-primary: #f8fafc; --text-secondary: #94a3b8;
    --border: #334155; --border-light: #334155;
}

body.dark-mode .dashboard-card, body.dark-mode .section, body.dark-mode .logbook-entry, 
body.dark-mode .courier-card, body.dark-mode .stat-card, body.dark-mode .modal-content, 
body.dark-mode .form-input {
    background-color: var(--surface); border-color: var(--border); color: var(--text-primary);
}

body.dark-mode .tabs-container { background: rgba(30, 41, 59, 0.98) !important; border-top-color: #334155 !important; }
body.dark-mode .tab-button { color: #94a3b8 !important; }
body.dark-mode .tab-button.active { color: #f87171 !important; }

/* Desktop Dark Mode */
@media (min-width: 1024px) {
    body.dark-mode .tabs-container { background: #1e293b !important; }
    body.dark-mode .tab-button.active { background-color: rgba(230, 0, 0, 0.15) !important; }
}

/* Fixes */
body.dark-mode .brand-logo { background: transparent; padding: 0; }
body.dark-mode .schedule-table td:first-child { background-color: #0f172a !important; color: #cbd5e1; }
body.dark-mode .schedule-table td:last-child { background-color: var(--surface) !important; }
body.dark-mode .cash-display { background: var(--surface); border-color: var(--border); }
body.dark-mode .cash-amount { color: var(--success); text-shadow: 0 0 10px rgba(16, 185, 129, 0.2); }
/* ================================================= */
/* === FIX: KURIERZY (2 KOLUMNY NA TELEFONIE) === */
/* ================================================= */

@media (max-width: 768px) {
    .couriers-grid {
        display: grid !important;
        /* Wymuś 2 kolumny, niezależnie od szerokości */
        grid-template-columns: 1fr 1fr !important; 
        gap: 10px !important;
    }

    .courier-card {
        padding: 10px !important; /* Mniejszy padding, żeby się zmieścili */
        min-height: 110px !important; /* Stała wysokość */
    }

    .courier-card img {
        height: 35px !important; /* Troszkę mniejsze logo */
        margin-bottom: 5px !important;
    }

    .courier-card strong {
        font-size: 0.9rem !important; /* Mniejszy tekst nazwy */
    }
}
/* Styl dla przycisku "+" w grafiku */
.btn-plus {
    width: 28px;
    height: 28px;
    border-radius: 50%; /* Kółko */
    background-color: #f1f5f9;
    color: #64748b;
    border: 1px solid #cbd5e1;
    font-size: 1.2rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
    padding-bottom: 2px; /* Wyrównanie optyczne plusa */
}

.btn-plus:hover {
    background-color: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: scale(1.1);
}

/* W trybie ciemnym */
body.dark-mode .btn-plus {
    background-color: #1e293b;
    border-color: #334155;
    color: #94a3b8;
}
body.dark-mode .btn-plus:hover {
    background-color: var(--primary);
    color: white;
}