:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --sidebar-bg: linear-gradient(180deg, #1e1b4b 0%, #312e81 100%);
    --sidebar-width: 260px;
    --topbar-height: 64px;
    --body-bg: #f1f5f9;
    --card-bg: #ffffff;
    --text-color: #0f172a;
    --muted: #64748b;
    --border: #e2e8f0;
}

[data-theme="dark"] {
    --body-bg: #0f172a;
    --card-bg: #1e293b;
    --text-color: #f1f5f9;
    --muted: #94a3b8;
    --border: #334155;
}

* { box-sizing: border-box; }
body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--body-bg);
    color: var(--text-color);
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

.app-wrapper { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #fff;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 1040;
    transition: transform .3s ease;
    overflow-y: auto;
}
@media (min-width: 992px) {
    body.sidebar-collapsed .sidebar {
        transform: translateX(-100%);
    }
    body.sidebar-collapsed .main-content {
        margin-left: 0;
    }
}
.sidebar-brand {
    display: flex; align-items: center; gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,.1);
    position: relative;
}
.sidebar-close {
    display: none;
    width: 36px;
    height: 36px;
    border: 1px solid rgba(255, 255, 255, .25);
    border-radius: 10px;
    background: rgba(255, 255, 255, .1);
    color: #fff;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background .2s;
}
.sidebar-close:hover { background: rgba(255, 255, 255, .2); }
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .55);
    z-index: 1035;
    opacity: 0;
    transition: opacity .3s ease;
    backdrop-filter: blur(2px);
}
.sidebar-backdrop.show {
    display: block;
    opacity: 1;
}
.sidebar-toggle {
    color: var(--text-color);
    text-decoration: none;
    padding: 6px 10px;
    font-size: 1.15rem;
}
.sidebar-toggle:hover { color: var(--primary); }
.brand-icon {
    width: 42px; height: 42px; border-radius: 12px;
    background: rgba(255,255,255,.15);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem;
}
.sidebar-brand strong { display: block; font-size: 1rem; }
.sidebar-brand small { color: rgba(255,255,255,.7); font-size: .75rem; }

.sidebar-nav { padding: 12px 10px; }
.sidebar-nav .nav-link {
    display: flex; align-items: center; gap: 10px;
    color: rgba(255,255,255,.85);
    padding: 10px 14px;
    border-radius: 10px;
    text-decoration: none;
    margin-bottom: 4px;
    transition: all .2s;
    font-weight: 500;
    font-size: .9rem;
}
.sidebar-nav .nav-link:hover,
.sidebar-nav .nav-link.active {
    background: rgba(255,255,255,.15);
    color: #fff;
}
.sidebar-nav .badge { margin-left: auto; }

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    transition: margin .3s;
}
.topbar {
    height: var(--topbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center;
    padding: 0 20px;
    position: sticky; top: 0; z-index: 1030;
}
.page-heading { font-size: 1.15rem; font-weight: 700; margin: 0; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.content-area { padding: 20px; }

.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 20px;
    height: 100%;
    transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,.08); }
.stat-card .icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; margin-bottom: 12px;
}
.stat-card h3 { font-size: 1.75rem; font-weight: 800; margin: 0; }
.stat-card p { color: var(--muted); margin: 4px 0 0; font-size: .875rem; }

.card-panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
}
.card-panel .card-header {
    background: transparent;
    border-bottom: 1px solid var(--border);
    padding: 16px 20px;
    font-weight: 700;
}
.card-panel .card-body { padding: 20px; }

.btn-primary {
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border: 0;
}
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-dark), #6d28d9); }

.upload-steps { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 20px; }
.upload-step {
    flex: 1; min-width: 100px; text-align: center;
    padding: 10px; border-radius: 10px;
    background: var(--card-bg); border: 2px solid var(--border);
    font-size: .8rem; font-weight: 600; color: var(--muted);
}
.upload-step.active { border-color: var(--primary); color: var(--primary); background: rgba(79,70,229,.08); }
.upload-step.done { border-color: #10b981; color: #10b981; }

.file-preview-thumb {
    width: 48px; height: 48px; border-radius: 8px;
    object-fit: cover; cursor: pointer;
    border: 1px solid var(--border);
}
.file-preview-thumb.pdf-icon {
    display: flex; align-items: center; justify-content: center;
    background: #fee2e2; color: #dc2626; font-size: 1.2rem;
}

.viewer-body { min-height: 400px; max-height: 75vh; overflow: auto; text-align: center; background: #111; }
.viewer-body img { max-width: 100%; transition: transform .3s; }
.viewer-body canvas { max-width: 100%; }
.pdf-controls { background: var(--card-bg); padding: 10px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.pending-overdue { background: #fef2f2 !important; }
.pending-overdue td { color: #b91c1c; font-weight: 600; }

.filter-panel { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }

.upload-waiting-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}
.upload-waiting-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 36px 40px;
    text-align: center;
    max-width: 420px;
    width: 90%;
    box-shadow: 0 24px 48px rgba(0, 0, 0, 0.2);
}
#toggleFilters.active,
.toggle-filters-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #1e1b4b, #4f46e5, #0ea5e9);
    display: flex; align-items: center; justify-content: center;
    padding: 24px;
}
.login-card {
    width: 100%; max-width: 440px;
    background: #fff; border-radius: 20px;
    box-shadow: 0 24px 60px rgba(0,0,0,.25);
    overflow: hidden;
}
.login-card .card-body { padding: 32px; }
.login-brand { text-align: center; margin-bottom: 24px; }
.login-brand .icon {
    width: 64px; height: 64px; border-radius: 16px;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #fff; display: inline-flex;
    align-items: center; justify-content: center;
    font-size: 1.5rem; margin-bottom: 12px;
}

.select2-container--bootstrap-5 .select2-selection { min-height: 38px; }
.form-select-sm + .select2-container--bootstrap-5 .select2-selection { min-height: 31px; font-size: .875rem; }
[data-theme="dark"] .select2-container--bootstrap-5 .select2-selection {
    background-color: var(--card-bg);
    color: var(--text-color);
    border-color: var(--border);
}
[data-theme="dark"] .select2-container--bootstrap-5 .select2-dropdown {
    background-color: var(--card-bg);
    border-color: var(--border);
}
[data-theme="dark"] .select2-container--bootstrap-5 .select2-results__option { color: var(--text-color); }

@media (max-width: 991px) {
    .sidebar {
        transform: translateX(-100%);
        width: min(280px, 88vw);
        box-shadow: none;
    }
    .sidebar.show {
        transform: translateX(0);
        box-shadow: 8px 0 32px rgba(0, 0, 0, .25);
    }
    .sidebar-close { display: inline-flex; }
    .main-content { margin-left: 0; width: 100%; }
    body.sidebar-open { overflow: hidden; }
    .content-area { padding: 14px; }
    .page-heading { font-size: 1rem; }
    .topbar { padding: 0 12px; }
}

@media print {
    .sidebar, .topbar, .filter-panel, .dataTables_filter, .dataTables_length, .dataTables_paginate { display: none !important; }
    .main-content { margin: 0; }
    .content-area { padding: 0; }
}
