:root {
    --sidebar-width: 250px;
    --sidebar-bg: linear-gradient(180deg, #0a1628 0%, #1a2940 100%);
    --sidebar-hover: rgba(255,255,255,0.08);
    --sidebar-active: rgba(59, 130, 246, 0.25);
    --body-bg: #f0f2f5;
    --card-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.06);
    --card-hover-shadow: 0 10px 40px rgba(0,0,0,0.12);
    --primary: #1a56db;
    --primary-light: #e8effd;
    --text-muted: #6b7280;
    --navy: #0a1628;
    --navy-light: #1a2940;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--body-bg);
    color: #1f2937;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    min-height: 100vh;
    background: var(--sidebar-bg);
    transition: all 0.3s ease;
    position: sticky;
    top: 0;
    z-index: 1000;
}

.sidebar-header {
    border-bottom: 1px solid rgba(255,255,255,0.08) !important;
}

.sidebar-header h5 {
    font-weight: 600;
    letter-spacing: 0.3px;
}

.sidebar-header small {
    font-size: 0.75rem;
    opacity: 0.7;
}

.sidebar .nav-section-title {
    font-size: 0.65rem;
    letter-spacing: 1px;
    font-weight: 600;
    padding: 1rem 1.25rem 0.5rem;
}

.sidebar .nav-link {
    padding: 0.65rem 1.25rem;
    font-size: 0.875rem;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    color: rgba(255,255,255,0.7) !important;
}

.sidebar .nav-link:hover {
    background: var(--sidebar-hover);
    color: #fff !important;
    border-left-color: rgba(255,255,255,0.3);
}

.sidebar .nav-link.active {
    background: var(--sidebar-active);
    color: #fff !important;
    border-left-color: #3b82f6;
    font-weight: 500;
}

.sidebar .nav-link i {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
}

/* Header / Navbar */
.navbar.topbar {
    background: #fff !important;
    border-bottom: 1px solid #e5e7eb;
    padding: 0.5rem 1.5rem;
    min-height: 60px;
}

.navbar.topbar .navbar-brand {
    font-weight: 600;
    color: #1f2937;
}

.navbar.topbar .user-info {
    font-size: 0.875rem;
}

.navbar.topbar .badge-role {
    font-size: 0.7rem;
    font-weight: 500;
    padding: 0.25em 0.65em;
    border-radius: 50px;
}

/* Main content area */
#page-content-wrapper {
    background: var(--body-bg);
    min-height: 100vh;
}

/* Cards */
.stat-card {
    border: none;
    border-radius: 12px;
    transition: all 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--card-hover-shadow);
}

.stat-card .card-body {
    padding: 1.25rem;
}

.stat-card .stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.stat-card .stat-label {
    font-size: 0.8rem;
    font-weight: 500;
    opacity: 0.85;
    margin-bottom: 0.25rem;
}

.stat-card .stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    line-height: 1.2;
}

/* Content cards */
.content-card {
    border: none;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: all 0.3s ease;
}

.content-card:hover {
    box-shadow: var(--card-hover-shadow);
}

.content-card .card-header {
    background: transparent;
    border-bottom: 1px solid #e5e7eb;
    padding: 1rem 1.25rem;
    font-weight: 600;
}

/* Buttons */
.btn {
    border-radius: 8px;
    font-weight: 500;
    padding: 0.5rem 1.25rem;
    transition: all 0.2s ease;
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
}

.btn-primary:hover {
    background: #1a47b8;
    border-color: #1a47b8;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(26, 86, 219, 0.3);
}

.btn-outline-danger:hover {
    transform: translateY(-1px);
}

/* Tables */
.table {
    margin-bottom: 0;
}

.table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom-width: 1px;
    padding: 0.75rem 1rem;
}

.table td {
    padding: 0.75rem 1rem;
    vertical-align: middle;
}

.table-hover tbody tr:hover {
    background: #f9fafb;
}

/* Forms */
.form-control, .form-select {
    border-radius: 8px;
    border-color: #d1d5db;
    padding: 0.6rem 0.9rem;
    font-size: 0.9rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.12);
}

.form-label {
    font-weight: 500;
    font-size: 0.875rem;
    color: #374151;
}

/* Alerts */
.alert {
    border: none;
    border-radius: 10px;
}

/* Login page */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #0a1628 0%, #1a2940 50%, #1e3a5f 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-card {
    border: none;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-card .card-body {
    padding: 2.5rem;
}

.login-icon {
    width: 64px;
    height: 64px;
    background: var(--primary-light);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto;
}

.login-icon i {
    font-size: 2rem;
    color: var(--primary);
}

/* QR scan page */
.scanner-container {
    max-width: 500px;
    margin: 0 auto;
}

#qrScanner video {
    width: 100% !important;
    height: auto !important;
}

/* Tables responsive on mobile */
@media (max-width: 767px) {
    .table-responsive-cards thead { display: none; }
    .table-responsive-cards tr {
        display: block;
        margin-bottom: 1rem;
        border: 1px solid #e5e7eb;
        border-radius: 8px;
        padding: 0.75rem;
    }
    .table-responsive-cards td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.4rem 0;
        border: none;
        font-size: 0.85rem;
    }
    .table-responsive-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--text-muted);
        font-size: 0.75rem;
        text-transform: uppercase;
        flex: 0 0 40%;
    }
}

/* Responsive */
@media (max-width: 767px) {
    .sidebar {
        position: fixed;
        left: -100%;
        z-index: 1050;
        transition: left 0.3s ease;
    }
    .sidebar.show {
        left: 0;
    }
    #page-content-wrapper {
        width: 100%;
    }
    .stat-card .stat-value {
        font-size: 1.4rem;
    }
    .login-card .card-body {
        padding: 1.5rem;
    }
    main.p-3 {
        padding: 0.75rem !important;
    }
    .card-body.p-4 {
        padding: 1rem !important;
    }
    .card-body.p-5 {
        padding: 1.25rem !important;
    }
    .row.g-3 > [class*="col-"] {
        padding-bottom: 0.5rem;
    }
    #qrScanner {
        min-height: 200px !important;
    }
    .btn-lg {
        padding: 0.5rem 1rem;
        font-size: 0.9rem;
    }
    h2 { font-size: 1.25rem; }
    h3.card-title { font-size: 1rem; }
}

@media (min-width: 768px) {
    .sidebar {
        margin-left: 0 !important;
    }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* Badges */
.badge { font-weight: 500; border-radius: 6px; }

/* Pagination */
.pagination .page-link {
    border-radius: 8px;
    margin: 0 2px;
    border: none;
    color: var(--primary);
}

.pagination .page-item.active .page-link {
    background: var(--primary);
}

/* Print */
@media print {
    .sidebar, .topbar, footer, .btn, .alert, .no-print { display: none !important; }
    #page-content-wrapper { margin-left: 0 !important; }
    body { background: #fff; font-size: 12pt; }
    .card { border: 1px solid #ddd !important; box-shadow: none !important; }
    .card-body { padding: 1rem !important; }
    a { color: #000 !important; text-decoration: underline; }
    .badge { border: 1px solid #000; color: #000 !important; background: #fff !important; }
}

/* Accessibility Toolbar */
.accessibility-toolbar {
    background: #e5e7eb;
    padding: 4px 16px;
    display: flex;
    justify-content: flex-end;
    border-bottom: 1px solid #d1d5db;
}

.accessibility-toolbar .btn-sm {
    font-size: 0.8rem;
    padding: 2px 8px;
}

.access-btn {
    min-width: 32px;
}

/* Font sizes */
body.font-sm { font-size: 14px; }
body.font-md { font-size: 16px; }
body.font-lg { font-size: 18px; }
body.font-xl { font-size: 20px; }

body.font-sm .sidebar .nav-link { font-size: 0.8rem; }
body.font-lg .sidebar .nav-link { font-size: 0.95rem; }
body.font-xl .sidebar .nav-link { font-size: 1.05rem; }

body.font-sm h2 { font-size: 1.25rem; }
body.font-lg h2 { font-size: 1.75rem; }
body.font-xl h2 { font-size: 2rem; }

/* High Contrast */
body.high-contrast {
    background: #000 !important;
    color: #fff !important;
}

body.high-contrast .card,
body.high-contrast .content-card,
body.high-contrast .stat-card {
    background: #1a1a1a !important;
    border-color: #fff !important;
    color: #fff !important;
}

body.high-contrast .card-header {
    border-bottom-color: #333 !important;
}

body.high-contrast .navbar.topbar {
    background: #1a1a1a !important;
    border-bottom-color: #333 !important;
}

body.high-contrast .navbar.topbar .navbar-brand,
body.high-contrast .navbar.topbar .user-info {
    color: #fff !important;
}

body.high-contrast .sidebar {
    background: #000 !important;
}

body.high-contrast .sidebar .nav-link {
    color: #fff !important;
}

body.high-contrast .table {
    color: #fff !important;
}

body.high-contrast .table th,
body.high-contrast .table td {
    border-color: #333 !important;
}

body.high-contrast .table-hover tbody tr:hover {
    background: #222 !important;
}

body.high-contrast .form-control,
body.high-contrast .form-select {
    background: #1a1a1a !important;
    color: #fff !important;
    border-color: #555 !important;
}

body.high-contrast .text-muted {
    color: #aaa !important;
}

body.high-contrast .alert-success {
    background: #003300 !important;
    color: #fff !important;
}

body.high-contrast .alert-danger {
    background: #330000 !important;
    color: #fff !important;
}

body.high-contrast .btn-primary {
    background: #fff !important;
    color: #000 !important;
    border-color: #fff !important;
}

body.high-contrast a {
    color: #66b3ff !important;
}

body.high-contrast .table-hover tbody tr:hover {
    background: #222 !important;
}

body.high-contrast .pagination .page-link {
    background: #1a1a1a !important;
    color: #fff !important;
}

body.high-contrast .pagination .page-item.active .page-link {
    background: #fff !important;
    color: #000 !important;
}

body.high-contrast .badge {
    border: 1px solid #fff;
}

