:root {
    --sidebar-width: 250px;
    --primary: #0d6efd;
    --primary-dark: #0a58ca;
    --success: #198754;
    --warning: #ffc107;
    --danger: #dc3545;
    --info: #0dcaf0;
    --accent: #20c997;
    --bg-body: #f0f2f5;
    --bg-card: #ffffff;
    --text-muted: #6c757d;
    --border-color: #e9ecef;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
    --sidebar-bg: linear-gradient(180deg, #1a1d23 0%, #212529 100%);
    --page-loader-bg: rgba(255,255,255,0.92);
    --table-hover-bg: rgba(13,110,253,0.04);
    --input-bg: #ffffff;
    --input-border: #dee2e6;
}

[data-bs-theme="dark"] {
    --bg-body: #1a1d23;
    --bg-card: #212529;
    --text-muted: #adb5bd;
    --border-color: #343a40;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.4);
    --page-loader-bg: rgba(26,29,35,0.92);
    --table-hover-bg: rgba(13,110,253,0.1);
    --input-bg: #2b3035;
    --input-border: #495057;
}

* { box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--bg-body);
    color: var(--bs-body-color, #212529);
    line-height: 1.6;
}

/* ── Layout ── */
html, body { height: 100%; margin: 0; }

/* ── Sidebar ── */
#sidebar-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    overflow-y: auto;
    background: var(--sidebar-bg);
    transition: margin-left 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 100;
}
#sidebar-wrapper::-webkit-scrollbar { width: 4px; }
#sidebar-wrapper::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }
#sidebar-wrapper .sidebar-heading {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.3px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
#sidebar-wrapper .list-group-item {
    border: none;
    padding: 11px 20px;
    font-size: 0.9rem;
    background: transparent;
    color: rgba(255,255,255,0.75);
    transition: var(--transition);
    border-left: 3px solid transparent;
}
#sidebar-wrapper .list-group-item:hover {
    background: rgba(255,255,255,0.06) !important;
    color: #fff;
    border-left-color: var(--primary);
    padding-left: 24px;
}
#sidebar-wrapper .list-group-item.active-link {
    background: rgba(13,110,253,0.15) !important;
    color: #fff;
    border-left-color: var(--primary);
}
#sidebar-wrapper .list-group-item i {
    margin-right: 10px;
    width: 20px;
    text-align: center;
}
#sidebar-wrapper .role-badge-area {
    background: rgba(255,255,255,0.04);
    border-bottom: 1px solid rgba(255,255,255,0.06);
}
#wrapper.toggled #sidebar-wrapper { margin-left: calc(-1 * var(--sidebar-width)); }

/* ── Navbar ── */
.navbar { padding: 0.5rem 1rem; }
.navbar-brand { font-weight: 700; letter-spacing: 0.5px; }
#menu-toggle {
    border-radius: var(--radius-sm);
    padding: 0.3rem 0.6rem;
    font-size: 1.2rem;
}
.dropdown-menu {
    border: none;
    box-shadow: var(--shadow-md);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0;
}
.dropdown-item { padding: 0.5rem 1rem; border-radius: 6px; }
.dropdown-item:hover { background: var(--border-color); }

/* ── Page Content ── */
#page-content-wrapper {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
#main-content {
    flex: 1;
}

/* ── Cards ── */
.card {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
    border-radius: var(--radius) var(--radius) 0 0 !important;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
}
.card-header.bg-white {
    background: var(--bg-card) !important;
}
.card-footer {
    border-radius: 0 0 var(--radius) var(--radius) !important;
    background: var(--bg-card);
}

/* Stat cards */
.stat-card {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    transition: var(--transition);
}
.stat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.stat-card .stat-icon {
    position: absolute;
    right: 15px;
    bottom: 15px;
    font-size: 3rem;
    opacity: 0.15;
    line-height: 1;
}
.stat-card .stat-value { font-size: 2rem; font-weight: 700; }
.stat-card .stat-label { font-size: 0.85rem; font-weight: 500; opacity: 0.85; }

/* ── Tables ── */
.table th {
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom-width: 1px;
}
.table td { vertical-align: middle; font-size: 0.9rem; }
.table-hover tbody tr {
    transition: var(--transition);
}
.table-hover tbody tr:hover {
    background-color: var(--table-hover-bg);
    transform: scale(1.002);
}
.table {
    --bs-table-bg: var(--bg-card);
    --bs-table-color: var(--bs-body-color, #212529);
}
.table-light {
    --bs-table-bg: var(--border-color);
    --bs-table-color: var(--bs-body-color, #212529);
}
.table-striped > tbody > tr:nth-of-type(odd) {
    --bs-table-accent-bg: rgba(0,0,0,0.02);
}

/* ── Badges ── */
.badge {
    font-weight: 500;
    padding: 0.35em 0.7em;
    border-radius: 6px;
    font-size: 0.78rem;
}
.badge.bg-success { background: #198754 !important; }
.badge.bg-danger { background: #dc3545 !important; }
.badge.bg-warning { background: #ffc107 !important; color: #212529 !important; }
.badge.bg-info { background: #0dcaf0 !important; color: #212529 !important; }
.badge.bg-secondary { background: #adb5bd !important; }
.status-badge { min-width: 85px; display: inline-block; text-align: center; }

/* ── Forms ── */
.form-control, .form-select {
    border-radius: var(--radius-sm);
    border: 1.5px solid var(--input-border);
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
    transition: var(--transition);
    background-color: var(--input-bg);
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13,110,253,0.12);
}
.form-control[readonly] {
    background-color: var(--bg-body);
    cursor: not-allowed;
    opacity: 0.85;
}
.form-label { font-weight: 500; font-size: 0.85rem; color: var(--bs-body-color, #495057); margin-bottom: 0.3rem; }
.form-text { font-size: 0.78rem; margin-top: 0.2rem; }
.invalid-feedback { font-size: 0.8rem; }

/* ── Stepper / Progress ── */
.stepper-wrapper {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
    position: relative;
}
.stepper-wrapper::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 40px;
    right: 40px;
    height: 2px;
    background: #dee2e6;
    transform: translateY(-50%);
    z-index: 0;
}
.stepper-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    z-index: 1;
    cursor: pointer;
}
.stepper-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #dee2e6;
    color: #6c757d;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    transition: var(--transition);
}
.stepper-step.active .stepper-circle {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 0 0 4px rgba(13,110,253,0.2);
}
.stepper-step.completed .stepper-circle {
    background: var(--success);
    color: #fff;
}
.stepper-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-top: 0.4rem;
    font-weight: 500;
}
.stepper-step.active .stepper-label { color: var(--primary); }

/* ── Pagination ── */
.pagination .page-link {
    border: none;
    margin: 0 2px;
    border-radius: var(--radius-sm);
    color: var(--primary);
    font-weight: 500;
    padding: 0.4rem 0.75rem;
}
.pagination .page-link:hover { background: var(--border-color); }
.pagination .active .page-link {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(13,110,253,0.3);
}

/* ── Buttons ── */
.btn {
    border-radius: var(--radius-sm);
    font-weight: 500;
    padding: 0.45rem 1rem;
    transition: var(--transition);
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-lg { border-radius: 10px; padding: 0.6rem 1.5rem; }
.btn-sm { border-radius: 6px; padding: 0.25rem 0.6rem; }
.btn-group .btn { transform: none; }

/* ── Alerts / Toasts ── */
.alert {
    border-radius: 10px;
    border: none;
    animation: slideDown 0.3s ease;
}

.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
}
.toast-notification {
    min-width: 300px;
    border: none;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    animation: slideInRight 0.35s ease;
}

/* ── Map ── */
#location-map, #detail-map, #facilities-map { z-index: 1; border-radius: var(--radius-sm); }
.custom-marker { background: none; border: none; }
.leaflet-popup-content-wrapper {
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}

/* ── Timeline ── */
.timeline {
    position: relative;
    padding-left: 2rem;
}
.timeline::before {
    content: '';
    position: absolute;
    left: 8px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: #dee2e6;
}
.timeline-item {
    position: relative;
    padding-bottom: 1.2rem;
}
.timeline-item:last-child { padding-bottom: 0; }
.timeline-dot {
    position: absolute;
    left: -1.7rem;
    top: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px var(--primary);
}
.timeline-dot.success { background: var(--success); box-shadow: 0 0 0 2px var(--success); }
.timeline-dot.warning { background: var(--warning); box-shadow: 0 0 0 2px var(--warning); }
.timeline-dot.danger { background: var(--danger); box-shadow: 0 0 0 2px var(--danger); }
.timeline-content { font-size: 0.88rem; }
.timeline-time { font-size: 0.75rem; color: var(--text-muted); }

/* ── Detail Grid ── */
.detail-grid .detail-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.detail-grid .detail-item:last-child { border-bottom: none; }
.detail-grid .detail-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}
.detail-grid .detail-label { font-size: 0.78rem; color: var(--text-muted); font-weight: 500; }
.detail-grid .detail-value { font-size: 0.92rem; font-weight: 500; }

/* ── Skeleton Loader ── */
.skeleton {
    background: linear-gradient(90deg, var(--border-color) 25%, var(--bg-card) 50%, var(--border-color) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: 6px;
}

/* ── Empty States ── */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
}
.empty-state i { font-size: 3.5rem; color: var(--border-color); margin-bottom: 1rem; }
.empty-state h5 { color: var(--text-muted); }
.empty-state p { color: #adb5bd; max-width: 400px; margin: 0 auto 1.5rem; }

/* ── Misc ── */
.section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}
.chart-container { position: relative; height: 250px; width: 100%; }
.filter-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.78rem;
}

/* ── Animations ── */
@keyframes slideDown {
    from { opacity: 0; transform: translateY(-15px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
    from { opacity: 0; transform: translateX(50px); }
    to { opacity: 1; transform: translateX(0); }
}
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes countUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
.fade-in { animation: fadeIn 0.3s ease; }

/* ── Responsive ── */
@media (max-width: 991.98px) {
    #sidebar-wrapper {
        margin-left: calc(-1 * var(--sidebar-width));
    }
    #wrapper.toggled #sidebar-wrapper { margin-left: 0; }
    #wrapper.toggled::before {
        content: '';
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.4);
        z-index: 99;
    }
    #page-content-wrapper {
        margin-left: 0;
    }
    .stat-card .stat-value { font-size: 1.6rem; }
}

/* Page loading spinner */
#page-loader {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: var(--page-loader-bg); z-index: 99999;
    display: flex; align-items: center; justify-content: center;
    flex-direction: column; gap: 16px;
    transition: opacity 0.3s ease;
    backdrop-filter: blur(2px);
}
#page-loader.hidden { opacity: 0; pointer-events: none; }
#page-loader .spinner {
    width: 44px; height: 44px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}
#page-loader .spinner-logo {
    position: absolute;
    font-size: 1.1rem;
    color: var(--primary);
    font-weight: 700;
}
#page-loader .label {
    font-size: 0.85rem;
    color: #6c757d;
    font-weight: 500;
    letter-spacing: 0.3px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.offline-banner {
    position: sticky; top: 0; z-index: 9999;
    background: #dc3545; color: #fff;
    text-align: center; padding: 8px 16px;
    font-size: 0.875rem; font-weight: 500;
}

@media print {
    #sidebar-wrapper, .navbar, footer, .btn, .btn-group, .card-header .btn,
    #menu-toggle, .no-print { display: none !important; }
    .card { box-shadow: none !important; border: 1px solid #dee2e6 !important; }
    #page-content-wrapper { margin-left: 0 !important; width: 100% !important; min-height: auto !important; }
    .badge { border: 1px solid #dee2e6; }
}
