:root {
    --sidebar-width: 250px;
    --sidebar-collapsed: 72px;
    --navbar-height: 70px;
    --primary: #0d6efd;
    --primary-dark: #123c7a;
    --bg: #f5f7fb;
    --surface: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --radius-sm: 8px;
    --radius: 12px;
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, .04), 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 4px 14px rgba(15, 23, 42, .04);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    min-height: 100vh;
}

body.login-page {
    background: linear-gradient(135deg, #e9eef5 0%, #dde4f0 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
[data-bs-theme="dark"] body.login-page {
    background: linear-gradient(135deg, #0f1115 0%, #161b22 100%);
}
.login-container {
    width: 100%;
    max-width: 420px;
}
.login-card {
    border-radius: 16px;
    background: rgba(255,255,255,.85);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,.6);
    box-shadow: 0 10px 30px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .05);
}
[data-bs-theme="dark"] .login-card {
    background: rgba(28,31,36,.85);
    border-color: rgba(255,255,255,.08);
}
.login-logo {
    width: 96px; height: 96px;
    border-radius: 24px;
    background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary) 100%);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
}
.login-logo-img {
    height: 72px;
    max-width: 100%;
    object-fit: contain;
}
.login-logo:has(.login-logo-img) {
    background: transparent;
}

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

.offcanvas.app-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 78vw;
    max-width: 260px;
    height: 100vh;
    z-index: 1055;
    border-radius: 0;
    background: #0b1d3a;
    color: #fff;
}
.offcanvas.app-sidebar .offcanvas-body {
    overflow-y: auto;
    padding: 0;
    display: flex;
    flex-direction: column;
}
.offcanvas.app-sidebar .offcanvas-header {
    background: rgba(0,0,0,.18);
    border-bottom: 1px solid rgba(255,255,255,.08);
    padding: 10px 12px;
}
.offcanvas.app-sidebar .offcanvas-title {
    font-weight: 700;
    font-size: 15px;
    color: #fff;
}
.offcanvas.app-sidebar .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}
.offcanvas.app-sidebar .offcanvas-header img {
    height: 24px;
}
@media (max-width: 575.98px) {
    .offcanvas.app-sidebar .offcanvas-header img {
        height: 20px;
    }
}
.offcanvas.app-sidebar .nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 6px 8px !important;
}
.offcanvas.app-sidebar .nav-item {
    flex-shrink: 0;
}
.offcanvas.app-sidebar .nav-link {
    color: rgba(255,255,255,.92);
    padding: 9px 10px;
    border-radius: 8px;
    margin: 1px 0;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    font-weight: 500;
    min-height: 38px;
    transition: all .15s ease;
    white-space: nowrap;
    background: transparent;
    border: 1px solid transparent;
}
.offcanvas.app-sidebar .nav-link:hover {
    background: rgba(255,255,255,.1);
    color: #fff;
    border-color: rgba(255,255,255,.08);
}
.offcanvas.app-sidebar .nav-link.active {
    background: rgba(255,255,255,.18);
    color: #fff;
    font-weight: 600;
    border-color: rgba(255,255,255,.12);
}
.offcanvas.app-sidebar .nav-link i {
    font-size: 1.05rem;
    width: 18px;
    text-align: center;
    flex-shrink: 0;
    opacity: .95;
}
.offcanvas.app-sidebar .nav-link.text-danger:hover {
    background: rgba(220,53,69,.25);
    color: #fff;
}

@media (max-width: 575.98px) {
    .offcanvas.app-sidebar {
        width: 80vw;
        max-width: 220px;
    }
    .offcanvas.app-sidebar .offcanvas-header {
        padding: 8px 10px;
    }
    .offcanvas.app-sidebar .offcanvas-title {
        font-size: 14px;
    }
    .offcanvas.app-sidebar .nav {
        padding: 4px 6px !important;
    }
    .offcanvas.app-sidebar .nav-link {
        padding: 8px 10px;
        font-size: 13px;
        min-height: 36px;
        gap: 6px;
    }
    .offcanvas.app-sidebar .nav-link i {
        font-size: .95rem;
        width: 16px;
    }
}

.main-wrapper {
    margin-left: 0 !important;
    width: 100% !important;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    padding-top: var(--navbar-height);
}
.top-navbar {
    height: var(--navbar-height);
    background: #fff;
    border-bottom: 1px solid var(--border);
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1050;
    overflow: visible;
}
.top-navbar .navbar-brand { color: var(--text); font-weight: 600; font-size: 18px; }
.top-navbar .dropdown { position: relative; margin-left: auto; }
.top-navbar .dropdown-toggle { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.top-navbar .dropdown-menu {
    position: absolute;
    right: 0; left: auto;
    top: calc(100% + 8px);
    z-index: 1060;
    min-width: 220px;
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px;
}
.top-navbar .dropdown-item { border-radius: var(--radius-sm); padding: 8px 12px; font-size: 14px; }
.top-navbar .dropdown-item i { width: 18px; text-align: center; }
.top-navbar .ls-wide { letter-spacing: .04em; }

.sidebar-toggle {
    width: 36px; height: 36px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    cursor: pointer;
    transition: all .15s ease;
    flex-shrink: 0;
}
.sidebar-toggle:hover { background: var(--bg); }
.sidebar-toggle i { transition: transform .25s ease; }

.main-content {
    flex: 1;
    padding: 24px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

.app-footer {
    background: #fff;
    border-top: 1px solid var(--border);
    padding: 12px 28px;
    font-size: 13px;
    color: var(--muted);
}

.main-content {
    flex: 1;
    padding: 24px;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

.app-footer {
    background: #fff;
    border-top: 1px solid var(--border);
    padding: 12px 28px;
    font-size: 13px;
    color: var(--muted);
}

/* Page header */
.page-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}
.page-header h4 { margin-bottom: 4px; }
.page-header small { color: var(--muted); }
.page-header .page-actions { margin-left: auto; }

/* Section spacing */
.section-gap { margin-bottom: 24px; }
.section-gap-sm { margin-bottom: 16px; }

/* Card system */
.card {
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    background: var(--surface);
    transition: box-shadow .15s ease;
}
.card:hover { box-shadow: var(--shadow-lg); }
.card-header {
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    background: transparent;
    padding: 14px 18px;
}
.card-body { padding: 18px; }
.card-title { font-weight: 600; margin-bottom: 4px; }
.card-subtitle { color: var(--muted); font-size: 14px; }

/* Stat card */
.stat-card {
    border-radius: var(--radius);
    background: var(--surface);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
    padding: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: transform .15s ease, box-shadow .15s ease;
    height: 100%;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon {
    width: 42px; height: 42px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.25rem;
    flex-shrink: 0;
}
.stat-label { font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.stat-value { font-size: 22px; font-weight: 700; margin: 0; line-height: 1.2; }

/* Buttons */
.btn {
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    padding: 8px 16px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all .15s ease;
}
.btn-sm { height: 36px; padding: 6px 12px; font-size: 13px; }
.btn-icon {
    width: 40px; height: 40px;
    padding: 0;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: all .15s ease;
}
.btn-icon:hover { transform: translateY(-1px); }

/* Tables */
.data-table { width: 100%; border-collapse: collapse; }
.data-table thead th {
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    background: transparent;
    padding: 12px 14px;
    white-space: nowrap;
}
.data-table tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.data-table-hover tbody tr:hover { background: #f8fafc; }
.data-table .actions { display: flex; gap: 4px; justify-content: center; flex-wrap: nowrap; }

/* Forms */
.form-control, .form-select {
    height: 44px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    border-color: var(--border);
    transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(13, 110, 253, .1);
}
.form-label {
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text);
}
textarea.form-control { height: auto; }

/* Filter bar */
.filter-bar {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
}
.filter-bar .input-group .form-control { flex: 1; }
.filter-bar .input-group .btn { height: 44px; }

/* Map */
#map { width: 100%; height: 420px; border-radius: var(--radius); overflow: hidden; z-index: 1; }

/* Responsive */
@media (max-width: 991.98px) {
    .main-content { padding: 16px; }
    .app-footer { padding: 12px 16px; }
    #map { height: 320px; }
    .data-table .actions { flex-wrap: wrap; }
    .top-navbar { padding: 0 16px; }
}

/* Dark mode */
[data-bs-theme="dark"] body { background: #0f1115; color: #e7e9ee; }
[data-bs-theme="dark"] .main-wrapper { background: #0f1115; }
[data-bs-theme="dark"] .top-navbar { background: #1c1f24; border-bottom-color: #2a2f37; }
[data-bs-theme="dark"] .top-navbar .navbar-brand { color: #e7e9ee; }
[data-bs-theme="dark"] .card { background: #1c1f24; border-color: #2a2f37; color: #e7e9ee; }
[data-bs-theme="dark"] .card-header { border-bottom-color: #2a2f37; }
[data-bs-theme="dark"] .table { color: #e7e9ee; }
[data-bs-theme="dark"] .table-light { background: #2a2f37 !important; color: #e7e9ee; }
[data-bs-theme="dark"] .form-control, [data-bs-theme="dark"] .form-select { background: #1c1f24; color: #e7e9ee; border-color: #2a2f37; }
[data-bs-theme="dark"] .text-muted { color: #9aa3af !important; }
[data-bs-theme="dark"] .app-footer { background: #1c1f24; border-top-color: #2a2f37; }
[data-bs-theme="dark"] .data-table thead th { border-bottom-color: #2a2f37; }
[data-bs-theme="dark"] .data-table tbody td { border-bottom-color: #2a2f37; }
[data-bs-theme="dark"] .data-table-hover tbody tr:hover { background: #252a33; }
[data-bs-theme="dark"] .top-navbar { background: #1c1f24; }
[data-bs-theme="dark"] .sidebar-toggle { background: #1c1f24; border-color: #2a2f37; color: #e7e9ee; }
[data-bs-theme="dark"] .filter-bar { background: #1c1f24; border-color: #2a2f37; }
[data-bs-theme="dark"] .stat-card { background: #1c1f24; border-color: #2a2f37; }

/* Utilities */
.tracking-wide { letter-spacing: .06em; }
.icon-circle {
    width: 48px; height: 48px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
}
.icon-circle-sm {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 1rem;
}
.rounded-pill { border-radius: 50rem !important; }
