:root {
    --color-bg: #f0f2f5;
    --color-surface: #ffffff;
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #eff6ff;
    --color-secondary: #64748b;
    --color-success: #16a34a;
    --color-success-light: #f0fdf4;
    --color-danger: #dc2626;
    --color-danger-light: #fef2f2;
    --color-warning: #d97706;
    --color-warning-light: #fffbeb;
    --color-info: #0891b2;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-border: #e2e8f0;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 16px;
    --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
    --transition: .18s ease;
    --sidebar-width: 240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── LOGIN ────────────────────────────────────────── */
.login-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    padding: 1rem;
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 420px;
}

.login-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.login-logo .logo-icon {
    width: 64px;
    height: 64px;
    background: var(--color-primary);
    border-radius: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: .75rem;
}

.login-logo .logo-icon svg { width: 32px; height: 32px; fill: #fff; }

.login-logo h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--color-text);
}

.login-logo p {
    color: var(--color-text-muted);
    font-size: .9rem;
}

/* ── LAYOUT ───────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── SIDEBAR ──────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: #1e293b;
    color: #cbd5e1;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform var(--transition);
}

.sidebar-brand {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid #334155;
    display: flex;
    align-items: center;
    gap: .75rem;
}

.sidebar-brand .brand-icon {
    width: 36px;
    height: 36px;
    background: var(--color-primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sidebar-brand .brand-icon svg { width: 18px; height: 18px; fill: #fff; }

.sidebar-brand span {
    font-weight: 700;
    font-size: .95rem;
    color: #f1f5f9;
    line-height: 1.2;
}

.sidebar-brand small {
    display: block;
    font-size: .7rem;
    font-weight: 400;
    color: #94a3b8;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: .75rem 0;
}

.nav-section-label {
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: #475569;
    padding: .5rem 1.25rem .25rem;
}

.nav-collapsible {
    max-height: 0;
    overflow: hidden;
    transition: max-height .25s ease;
}
.nav-collapsible.open {
    max-height: 200px;
}
.nav-toggle { color: #94a3b8; font-size: .75rem; }
.nav-toggle svg { fill: #94a3b8; }
.nav-toggle:hover { color: #e2e8f0; }
.nav-toggle:hover svg { fill: #e2e8f0; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem 1.25rem;
    color: #94a3b8;
    border-radius: 0;
    font-size: .875rem;
    transition: background var(--transition), color var(--transition);
    border-left: 3px solid transparent;
}

.sidebar-nav a svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }

.sidebar-nav a:hover {
    background: #334155;
    color: #f1f5f9;
    text-decoration: none;
}

.sidebar-nav a.active {
    background: #1e40af22;
    color: #93c5fd;
    border-left-color: var(--color-primary);
}

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid #334155;
    font-size: .8rem;
    color: #64748b;
}

.sidebar-footer .user-name { color: #94a3b8; font-weight: 600; }

.sidebar-footer a {
    color: #ef4444;
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    margin-top: .5rem;
    font-size: .8rem;
}

.sidebar-footer a svg { width: 14px; height: 14px; fill: currentColor; }
.sidebar-footer a:hover { text-decoration: none; color: #fca5a5; }

/* ── MAIN CONTENT ─────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 0 1.75rem;
    height: 60px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow);
}

.topbar-title { font-size: 1.125rem; font-weight: 700; }

.topbar-right { display: flex; align-items: center; gap: 1rem; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .875rem;
    color: var(--color-text-muted);
}

.topbar-user .avatar {
    width: 34px;
    height: 34px;
    background: var(--color-primary-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: .8rem;
    color: var(--color-primary);
    border: 2px solid var(--color-border);
}

.page-body {
    padding: 1.75rem;
    flex: 1;
}

/* ── MOBILE TOGGLE ────────────────────────────────── */
.sidebar-toggle {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: .4rem;
    color: var(--color-text);
}

.sidebar-toggle svg { width: 22px; height: 22px; fill: currentColor; }

/* ── CARDS ────────────────────────────────────────── */
.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--color-border);
}

.card-header {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.card-title {
    font-size: 1rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.card-title svg { width: 18px; height: 18px; fill: var(--color-primary); }

.card-body { padding: 1.25rem; }

/* ── STATS GRID ───────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.25rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 1.5rem 1.25rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    box-shadow: var(--shadow);
    min-width: 0;
}

.stat-card > div:last-child {
    min-width: 0;
    flex: 1;
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.stat-icon svg { width: 24px; height: 24px; fill: #fff; }

.stat-card .stat-value {
    font-size: 1.65rem;
    font-weight: 700;
    line-height: 1.1;
    margin-bottom: .3rem;
    word-break: break-word;
    overflow-wrap: anywhere;
}

.stat-card .stat-label {
    font-size: .8rem;
    color: var(--color-text-muted);
    line-height: 1.3;
}

.stat-icon.blue   { background: var(--color-primary); }
.stat-icon.green  { background: var(--color-success); }
.stat-icon.orange { background: var(--color-warning); }
.stat-icon.teal   { background: var(--color-info); }

/* ── TABLES ───────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

thead th {
    background: #f8fafc;
    padding: .7rem 1rem;
    text-align: left;
    font-weight: 700;
    font-size: .75rem;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--color-text-muted);
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

tbody td {
    padding: .75rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }

/* ── FORMS ────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }

.form-group label {
    display: block;
    font-size: .825rem;
    font-weight: 600;
    margin-bottom: .35rem;
    color: var(--color-text);
}

.form-group label .req { color: var(--color-danger); margin-left: .1rem; }

.form-control {
    width: 100%;
    padding: .55rem .85rem;
    border: 1.5px solid var(--color-border);
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-family: inherit;
    color: var(--color-text);
    background: var(--color-surface);
    transition: border-color var(--transition), box-shadow var(--transition);
    outline: none;
}

.form-control:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-hint {
    font-size: .75rem;
    color: var(--color-text-muted);
    margin-top: .25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.checkbox-group { display: flex; flex-direction: column; gap: .5rem; }

.checkbox-item {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .875rem;
    cursor: pointer;
    padding: .4rem .6rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--color-border);
    transition: background var(--transition);
}

.checkbox-item:hover { background: var(--color-primary-light); }

.checkbox-item input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--color-primary);
    cursor: pointer;
}

/* ── BUTTONS ──────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    border: 1.5px solid transparent;
    transition: all var(--transition);
    white-space: nowrap;
    text-decoration: none;
}

.btn svg { width: 16px; height: 16px; fill: currentColor; }

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}
.btn-primary:hover {
    background: var(--color-primary-dark);
    border-color: var(--color-primary-dark);
    text-decoration: none;
    color: #fff;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg); text-decoration: none; }

.btn-danger {
    background: var(--color-danger);
    color: #fff;
    border-color: var(--color-danger);
}
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; text-decoration: none; color:#fff; }

.btn-success {
    background: var(--color-success);
    color: #fff;
    border-color: var(--color-success);
}
.btn-success:hover { background: #15803d; text-decoration: none; color:#fff; }

.btn-sm { padding: .3rem .75rem; font-size: .8rem; }
.btn-lg { padding: .7rem 1.5rem; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── FLOATING SAVE BUTTON ─────────────────────────── */
.floating-save {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 180;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .6rem .8rem;
    background: rgba(255,255,255,.85);
    border: 1px solid var(--color-border);
    border-radius: 999px;
    box-shadow: var(--shadow-md);
    backdrop-filter: blur(8px);
}
.floating-save .hint {
    font-size: .78rem;
    color: var(--color-text-muted);
}
@media (max-width: 768px) {
    .floating-save {
        right: 14px;
        bottom: 14px;
        padding: .5rem .6rem;
    }
    .floating-save .hint { display: none; }
}

/* ── BADGES ───────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .2rem .6rem;
    border-radius: 999px;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .03em;
}

.badge-success { background: var(--color-success-light); color: var(--color-success); }
.badge-danger  { background: var(--color-danger-light);  color: var(--color-danger);  }
.badge-warning { background: var(--color-warning-light); color: var(--color-warning); }
.badge-info    { background: #e0f2fe; color: var(--color-info); }
.badge-secondary { background: #f1f5f9; color: var(--color-secondary); }

/* ── ALERTS / FLASH ───────────────────────────────── */
.alert {
    padding: .85rem 1.1rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    margin-bottom: 1rem;
}

.alert svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; margin-top: .1rem; }

.alert-success { background: var(--color-success-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-danger  { background: var(--color-danger-light);  color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--color-warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info    { background: #e0f2fe; color: #0c4a6e; border: 1px solid #bae6fd; }

/* ── MODAL ────────────────────────────────────────── */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.modal-backdrop.open { display: flex; }

.modal {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 520px;
    max-height: 90vh;
    overflow-y: auto;
    animation: modalIn .2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: translateY(-16px) scale(.97); }
    to   { opacity: 1; transform: none; }
}

.modal-header {
    padding: 1.1rem 1.4rem;
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-title { font-weight: 700; font-size: 1rem; }

.modal-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: .2rem;
    color: var(--color-text-muted);
    border-radius: var(--radius-sm);
    transition: background var(--transition);
}
.modal-close:hover { background: var(--color-bg); }
.modal-close svg { width: 20px; height: 20px; fill: currentColor; display: block; }

.modal-body { padding: 1.25rem 1.4rem; }

.modal-footer {
    padding: 1rem 1.4rem;
    border-top: 1px solid var(--color-border);
    display: flex;
    gap: .75rem;
    justify-content: flex-end;
}

/* ── PAGE HEADER ──────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}

.page-header h2 {
    font-size: 1.375rem;
    font-weight: 700;
}

.page-header p {
    color: var(--color-text-muted);
    font-size: .875rem;
    margin-top: .15rem;
}

/* ── EMPTY STATE ──────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted);
}

.empty-state svg {
    width: 48px;
    height: 48px;
    fill: var(--color-border);
    margin-bottom: 1rem;
}

.empty-state p { font-size: .9rem; }

/* ── FILTER BAR ───────────────────────────────────── */
.filter-bar {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    align-items: flex-end;
    margin-bottom: 1.25rem;
}

.filter-bar .form-group { margin-bottom: 0; }

/* ── CALENDAR (FullCalendar overrides) ────────────── */
.fc {
    font-family: inherit;
    font-size: .875rem;
}
.fc .fc-toolbar-title { font-size: 1.1rem; font-weight: 700; }
.fc .fc-button { font-size: .8rem; }
.fc .fc-button-primary {
    background: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
}
.fc .fc-button-primary:hover {
    background: var(--color-primary-dark) !important;
    border-color: var(--color-primary-dark) !important;
}
.fc .fc-event {
    border-radius: 4px;
    font-size: .75rem;
    padding: 1px 4px;
}

/* ── RESPONSIVE ───────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .sidebar-toggle {
        display: block;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .stats-grid {
        grid-template-columns: 1fr 1fr;
    }
    .page-body {
        padding: 1rem;
    }
    .topbar {
        padding: 0 1rem;
    }
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* ── SVG default in content ───────────────────────── */
main svg { width: 1.15em; height: 1.15em; fill: currentColor; vertical-align: middle; }

/* ── UTILITIES ────────────────────────────────────── */
.mt-1 { margin-top: .25rem; }
.mt-2 { margin-top: .5rem; }
.mt-3 { margin-top: .75rem; }
.mt-4 { margin-top: 1rem; }
.mb-1 { margin-bottom: .25rem; }
.mb-2 { margin-bottom: .5rem; }
.mb-3 { margin-bottom: .75rem; }
.mb-4 { margin-bottom: 1rem; }
.gap-2 { gap: .5rem; }
.d-flex { display: flex; }
.align-center { align-items: center; }
.justify-between { justify-content: space-between; }
.text-muted { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); }
.text-success { color: var(--color-success); }
.font-bold { font-weight: 700; }
.w-100 { width: 100%; }

/* ── MODAL ────────────────────────────────────────── */
/* ── PRINT: Schedule ──────────────────────────────── */
.print-schedule { display: none; }

@media print {
    /* Ukryj cały interfejs */
    .sidebar, .topbar, .sidebar-toggle,
    .page-header, .schedule-filters,
    .schedule-columns-floating,
    .floating-save,
    .alert, .flash-message { display: none !important; }

    /* Ukryj zwykłą zawartość strony */
    .main-content > .page-body > .card,
    .main-content > .page-body > form { display: none !important; }

    /* Pokaż widok do wydruku */
    .print-schedule { display: block !important; }

    /* Reset layoutu */
    body { background: #fff !important; margin: 0 !important; }
    .app-layout { display: block !important; }
    .main-content { margin-left: 0 !important; }
    .page-body { padding: 0 !important; }

    /* Nagłówek wydruku */
    .print-schedule-title {
        font-size: 1.3rem;
        font-weight: 700;
        margin-bottom: .2rem;
    }
    .print-schedule > p {
        margin-bottom: .5rem !important;
        font-size: .95rem !important;
    }

    /* Tabela wydruku */
    .print-schedule-table {
        width: 100%;
        border-collapse: collapse;
        font-size: .9rem;
        line-height: 1.35;
    }
    .print-schedule-table th {
        background: #f1f5f9 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
        padding: .25rem .6rem;
        text-align: left;
        font-size: .8rem;
        text-transform: uppercase;
        letter-spacing: .04em;
        border-bottom: 2px solid #334155;
    }
    .print-schedule-table td {
        padding: .25rem .6rem;
        border-bottom: 1px solid #e2e8f0;
    }
    .print-schedule-table tr.print-weekend td {
        background: #f8fafc !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    @page {
        size: A4 portrait;
        margin: 8mm;
    }
    /* Ukryj URL strony w stopce/nagłówku druku */
    @page { @top-left { content: none; } @top-right { content: none; } @bottom-left { content: none; } @bottom-right { content: none; } }
    html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    a[href]:after { content: none !important; }
}

.modal-overlay{position:fixed;inset:0;background:rgba(0,0,0,.45);z-index:200;display:flex;align-items:center;justify-content:center;padding:1rem;opacity:0;pointer-events:none;transition:opacity .2s}
.modal-overlay.open{opacity:1;pointer-events:auto}
.modal-box{background:#fff;border-radius:var(--radius-lg);box-shadow:var(--shadow-lg);width:100%;max-width:560px;max-height:90vh;overflow-y:auto;transform:translateY(20px);transition:transform .2s}
.modal-overlay.open .modal-box{transform:translateY(0)}
.modal-header{display:flex;align-items:center;justify-content:space-between;padding:1rem 1.25rem;border-bottom:1px solid var(--color-border)}
.modal-header h3{font-size:1.05rem;font-weight:700;margin:0}
.modal-close{background:none;border:none;font-size:1.5rem;cursor:pointer;color:var(--color-text-muted);line-height:1}
.modal-body{padding:1.25rem}
.modal-footer{padding:.75rem 1.25rem;border-top:1px solid var(--color-border);display:flex;justify-content:flex-end;gap:.5rem}
