:root {
    --sidebar-width: 260px;
    --topbar-height: 56px;
    --primary: #b32424;
    --primary-dark: #7f1d1d;
    --sidebar-bg: #221715;
    --sidebar-hover: #3a2823;
    --sidebar-active: #b32424;
    --sidebar-text: #ddcfc9;
    --sidebar-section: #93807a;
    --body-bg: #f1f5f9;
    --card-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
    --card-shadow-hover: 0 4px 12px rgba(0,0,0,.12);
    --transition: all .2s ease;

    /* re-theme Bootstrap's "primary" utilities (badges, alerts, text/border) to red */
    --bs-primary: #b32424;
    --bs-primary-rgb: 179, 36, 36;
    --bs-primary-text-emphasis: #6e1616;
    --bs-primary-bg-subtle: #fbecea;
    --bs-primary-border-subtle: #f0b8b3;
    --bs-link-color: #b32424;
    --bs-link-hover-color: #7f1d1d;
}

* { box-sizing: border-box; }

body {
    background: var(--body-bg);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 0.875rem;
    color: #334155;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6,
.page-title, .card-header, .stat-value, .navbar-brand, .sidebar-header .fw-semibold,
.modal-title, .btn {
    font-family: 'Lexend', 'Inter', system-ui, -apple-system, sans-serif;
}

/* ---- Bootstrap "primary" utility overrides ----
   Bootstrap 5.3 compiles .bg-primary/.text-primary/.border-primary/.btn-primary/
   .btn-outline-primary with hardcoded blue hex values, NOT var(--bs-primary).
   Overriding the CSS variables above isn't enough on its own — these explicit
   overrides are what actually turns the app red. */
.bg-primary { background-color: var(--primary) !important; }
.text-primary { color: var(--primary) !important; }
.border-primary { border-color: var(--primary) !important; }
a { color: var(--primary); }
a:hover, a:focus { color: var(--primary-dark); }

.btn-primary {
    color: #fff !important;
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    background-color: var(--primary-dark) !important;
    border-color: var(--primary-dark) !important;
}
.btn-outline-primary {
    color: var(--primary) !important;
    border-color: var(--primary) !important;
}
.btn-outline-primary:hover, .btn-outline-primary:focus, .btn-outline-primary:active {
    color: #fff !important;
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}
.dropdown-item.active, .dropdown-item:active {
    background-color: var(--primary) !important;
    color: #fff !important;
}
.form-check-input:checked {
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}
.page-link { color: var(--primary); }
.active > .page-link, .page-link.active {
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}

/* ---- Topbar ---- */
#topbar,
#topbar.bg-primary,
#topbar.navbar,
body #topbar {
    height: var(--topbar-height);
    z-index: 1050;
    background-color: var(--primary) !important;
    background-image: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 100%) !important;
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed;
    top: var(--topbar-height);
    left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--topbar-height));
    background: var(--sidebar-bg);
    overflow-y: auto;
    overflow-x: hidden;
    transition: transform .25s ease;
    z-index: 1040;
    scrollbar-width: thin;
    scrollbar-color: #55403b transparent;
}

.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-thumb { background: #55403b; border-radius: 4px; }

.sidebar-header { background: rgba(255,255,255,.05); }

.sidebar-nav .nav-link {
    color: var(--sidebar-text);
    border-radius: 8px;
    margin: 1px 0;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: var(--transition);
    white-space: nowrap;
    font-size: 0.84rem;
}
.sidebar-nav .nav-link i { font-size: 1rem; min-width: 20px; }
.sidebar-nav .nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }

.sidebar-section {
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--sidebar-section);
    padding: 16px 12px 4px;
    list-style: none;
}

/* ---- Content Wrapper ---- */
#content-wrapper {
    margin-left: var(--sidebar-width);
    padding-top: var(--topbar-height);
    min-height: 100vh;
    transition: margin-left .25s ease;
}

/* Sidebar collapsed */
body.sidebar-collapsed .sidebar { transform: translateX(calc(-1 * var(--sidebar-width))); }
body.sidebar-collapsed #content-wrapper { margin-left: 0; }

/* Mobile */
@media (max-width: 768px) {
    .sidebar { transform: translateX(calc(-1 * var(--sidebar-width))); }
    #content-wrapper { margin-left: 0; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open::after {
        content: '';
        position: fixed; inset: 0;
        background: rgba(0,0,0,.4);
        z-index: 1039;
    }
}

/* ---- Cards ---- */
.card {
    border: none;
    border-radius: 12px;
    box-shadow: var(--card-shadow);
    transition: var(--transition);
}
.card:hover { box-shadow: var(--card-shadow-hover); }
.card-header { background: transparent; border-bottom: 1px solid #e2e8f0; font-weight: 600; }

/* Stat Cards */
.stat-card {
    border-radius: 14px;
    padding: 1.25rem 1.5rem;
    color: #fff;
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: -20px; right: -20px;
    width: 100px; height: 100px;
    border-radius: 50%;
    background: rgba(255,255,255,.12);
}
.stat-card .stat-icon { font-size: 2.2rem; opacity: .85; }
.stat-card .stat-value { font-size: 2rem; font-weight: 800; line-height: 1; }
.stat-card .stat-label { font-size: .78rem; opacity: .88; margin-top: 4px; }
.stat-card .stat-change { font-size: .75rem; margin-top: 8px; }

.bg-stat-primary { background: linear-gradient(135deg, #5c1414, #8f1c1c); }
.bg-stat-success { background: linear-gradient(135deg, #15803d, #22c55e); }
.bg-stat-warning { background: linear-gradient(135deg, #b45309, #f59e0b); }
.bg-stat-danger  { background: linear-gradient(135deg, #b91c1c, #ef4444); }
.bg-stat-info    { background: linear-gradient(135deg, #0e7490, #06b6d4); }
.bg-stat-purple  { background: linear-gradient(135deg, #6d28d9, #a78bfa); }

/* ---- Tables ---- */
.table th { font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: #64748b; white-space: nowrap; }
.table td { vertical-align: middle; }
.table-hover tbody tr:hover { background: #f8fafc; }

/* ---- Badges ---- */
.badge { font-weight: 500; letter-spacing: .02em; }

/* ---- Forms ---- */
.form-control, .form-select {
    border-radius: 8px;
    border-color: #e2e8f0;
    font-size: .875rem;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(179,36,36,.12);
}
.form-label { font-weight: 500; color: #475569; }

/* ---- Buttons ---- */
.btn { border-radius: 8px; font-weight: 500; font-size: .875rem; transition: var(--transition); }
.btn-primary { background: var(--primary); border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

/* ---- Page Title ---- */
.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: #1e293b;
    display: flex;
    align-items: center;
    gap: .5rem;
}
.breadcrumb-item, .breadcrumb-item.active { font-size: .8rem; }

/* ---- Timeline ---- */
.timeline { position: relative; padding-left: 2rem; }
.timeline::before {
    content: '';
    position: absolute;
    left: .75rem;
    top: 0; bottom: 0;
    width: 2px;
    background: #e2e8f0;
}
.timeline-item { position: relative; padding-bottom: 1.5rem; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
    position: absolute;
    left: -1.75rem;
    top: 4px;
    width: 14px; height: 14px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px currentColor;
}

/* ---- QR Code display ---- */
.qr-container {
    background: #fff;
    border: 2px dashed #e2e8f0;
    border-radius: 12px;
    padding: 1rem;
    text-align: center;
    max-width: 220px;
    margin: 0 auto;
}
.qr-container img { max-width: 180px; height: auto; }

/* ---- Login page ---- */
.login-page {
    min-height: 100vh;
    background: linear-gradient(135deg, #4a1010 0%, #d6342c 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}
.login-card {
    background: #fff;
    border-radius: 20px;
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}

/* ---- Misc ---- */
.text-muted { color: #94a3b8 !important; }
.border-start-primary { border-left: 4px solid var(--primary) !important; }
.border-start-success { border-left: 4px solid #22c55e !important; }
.border-start-warning { border-left: 4px solid #f59e0b !important; }
.border-start-danger  { border-left: 4px solid #ef4444 !important; }

/* Print */
@media print {
    .sidebar, #topbar, .btn, .no-print { display: none !important; }
    #content-wrapper { margin-left: 0 !important; padding-top: 0 !important; }
    .card { box-shadow: none !important; }
}

/* Loading spinner */
.spinner-overlay {
    position: fixed; inset: 0;
    background: rgba(255,255,255,.7);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Empty state */
.empty-state { text-align: center; padding: 4rem 2rem; color: #94a3b8; }
.empty-state i { font-size: 3.5rem; margin-bottom: 1rem; display: block; }
