html, body {
    background-color: #f4f6f9;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    margin: 0 !important;
    padding: 0 !important;
    height: 100vh !important;
    max-height: 100vh !important;
    overflow: hidden !important;
    display: flex !important;
    flex-direction: column !important;
}

/* Header Area - Sticky Fixed Top */
.dashboard-header {
    position: sticky !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 1050 !important;
    background-color: #ffffff !important;
    border-bottom: 2px solid #ddd !important;
    display: flex !important;
    align-items: center !important;
    padding: 6px 15px !important;
    flex-shrink: 0 !important;
    height: 52px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08) !important;
}

.header-logos {
    display: flex;
    align-items: center;
    gap: 12px;
    border-right: 2px solid #ddd;
    padding-right: 12px;
    margin-right: 12px;
}
.header-logos img {
    height: 38px;
    object-fit: contain;
}
.header-title-area h1 {
    font-size: 16px;
    font-weight: bold;
    color: #002b5e;
    margin: 0;
    text-transform: uppercase;
}
.header-title-area p {
    margin: 0;
    color: #555;
    font-size: 10.5px;
}
.header-bg-bridge {
    flex-grow: 1;
    background-image: url('/assets/images/sungai_kapuas.jpg');
    background-size: cover;
    background-position: center;
    height: 44px;
    margin-left: 15px;
    border-radius: 8px;
    opacity: 0.9;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
}

/* Layout Container - Fits between Header & Footer */
.wrapper {
    display: flex !important;
    width: 100% !important;
    flex: 1 1 auto !important;
    height: calc(100vh - 52px - 44px) !important;
    max-height: calc(100vh - 52px - 44px) !important;
    overflow: hidden !important;
    position: relative !important;
}

/* Main Content Area - Generous 15px Bottom Gap before Footer */
#content, .main-content {
    flex: 1 1 auto !important;
    height: 100% !important;
    max-height: 100% !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding: 10px 15px 15px 15px !important;
}

/* Sidebar - Full Height Stretch */
#sidebar {
    min-width: 240px;
    max-width: 240px;
    background: #0a192f !important;
    color: #fff;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-self: stretch !important;
    flex-shrink: 0 !important;
}
#sidebar .sidebar-header {
    padding: 10px 12px;
    text-align: center;
    border-bottom: 1px solid #1c2d42;
    flex-shrink: 0;
}
#sidebar .sidebar-header h3 {
    color: #f8c300;
    font-weight: bold;
    font-size: 18px;
    margin-bottom: 2px;
}
#sidebar .sidebar-header p {
    font-size: 10px;
    margin: 0;
    line-height: 1.1;
}
#sidebar ul.components {
    padding: 6px 0;
    margin-bottom: 0;
}
#sidebar ul li a {
    padding: 6px 15px;
    font-size: 12px;
    display: block;
    color: #b0c4de;
    text-decoration: none;
    border-left: 4px solid transparent;
}
#sidebar ul li a:hover {
    color: #fff;
    background: #112240;
    border-left-color: #f8c300;
}
#sidebar ul li.active > a {
    color: #fff;
    background: #0d6efd;
    border-left-color: #0d6efd;
    font-weight: bold;
}
.sidebar-info-box {
    padding: 10px;
    font-size: 10px;
    color: #8892b0;
    border-top: 1px solid #1c2d42;
    margin-top: auto;
}
.sidebar-info-box h6 {
    color: #ccd6f6;
    font-size: 12px;
    margin-bottom: 6px;
}
.sidebar-footer {
    padding: 15px;
    border-top: 1px solid #1c2d42;
    text-align: center;
    font-size: 11px;
    color: #8892b0;
}

/* Sidebar Overlay for Mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1040;
    transition: all 0.3s ease;
}
.sidebar-overlay.active {
    display: block;
}

/* Main Content */
#content {
    width: 100%;
    padding: 12px;
    overflow-y: auto;
    flex-grow: 1;
}

/* Dashboard Cards */
.dash-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    margin-bottom: 0px;
    height: 100%;
    display: flex;
    flex-direction: column;
}
.dash-card-header {
    background: #002b5e;
    color: white;
    padding: 8px 12px;
    font-weight: bold;
    font-size: 13px;
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
    text-transform: uppercase;
}
.dash-card-body {
    padding: 10px;
    flex-grow: 1;
}

/* Specific Card Styles */
.stat-box {
    text-align: center;
    padding: 10px 5px;
    border: 1px solid #eee;
    border-radius: 6px;
    margin-bottom: 5px;
    background: #fafafa;
}
.stat-box .icon {
    font-size: 20px;
    color: #0d6efd;
    margin-bottom: 2px;
}
.stat-box.green .icon { color: #198754; }
.stat-box.orange .icon { color: #fd7e14; }

.stat-box h4 {
    font-size: 18px;
    font-weight: bold;
    color: #002b5e;
    margin: 3px 0;
}
.stat-box h5 {
    font-size: 14px;
}
.stat-box p {
    font-size: 11px;
    color: #666;
    margin: 0;
}

#map {
    height: 400px;
    width: 100%;
    border-radius: 6px;
}

/* Ranking Table */
.ranking-table th {
    font-size: 12px;
    color: #555;
}
.ranking-table td {
    font-size: 13px;
    vertical-align: middle;
}
.rank-badge {
    display: inline-block;
    width: 24px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    border-radius: 50%;
    color: white;
    font-weight: bold;
    font-size: 12px;
}
.rank-badge.rank-1-3 { background: #198754; } /* Green */
.rank-badge.rank-4-6 { background: #a3cc24; } /* Light Green */
.rank-badge.rank-7-9 { background: #ffc107; } /* Yellow */
.rank-badge.rank-10 { background: #fd7e14; }  /* Orange */

.status-tinggi { color: #198754; font-weight: bold; }
.status-sedang { color: #fd7e14; font-weight: bold; }
.status-rendah { color: #dc3545; font-weight: bold; }

/* Footer - Always Anchored at Bottom */
.dashboard-footer {
    position: sticky !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    z-index: 1040 !important;
    background: #ffffff !important;
    border-top: 2px solid #002b5e !important;
    padding: 8px 20px !important;
    display: flex !important;
    justify-content: space-between !important;
    font-size: 11.5px !important;
    color: #333 !important;
    align-items: center !important;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.08) !important;
    flex-shrink: 0 !important;
}
.footer-item {
    display: flex;
    align-items: center;
    gap: 8px;
}
.footer-item i {
    font-size: 16px;
    color: #002b5e;
}

/* Fullscreen Map Styles */
#map:fullscreen, .fullscreen-map:fullscreen, div[id^="map"]:fullscreen {
    width: 100vw !important;
    height: 100vh !important;
    z-index: 999999 !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #fff !important;
}
#map:-webkit-full-screen, .fullscreen-map:-webkit-full-screen, div[id^="map"]:-webkit-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    z-index: 999999 !important;
    padding: 0 !important;
    margin: 0 !important;
    background: #fff !important;
}

/* Responsive Styles for Mobile & Tablets */
@media (max-width: 991.98px) {
    body {
        overflow-y: auto !important;
        height: auto !important;
    }

    .wrapper {
        flex-direction: column;
    }

    #content, .container-fluid[style*="height"] {
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
    }

    #sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        z-index: 1050;
        margin-left: -260px;
        box-shadow: 4px 0 15px rgba(0,0,0,0.3);
        overflow-y: auto;
    }

    #sidebar.active {
        margin-left: 0;
    }

    /* Header styling on tablet/mobile */
    .dashboard-header {
        padding: 8px 10px;
        flex-wrap: wrap;
        gap: 8px;
        align-items: center;
    }

    .header-logos {
        gap: 8px;
        padding-right: 8px;
        margin-right: 8px;
        border-right: 1px solid #ddd;
    }

    .header-logos img {
        height: 32px;
    }

    .header-title-area {
        flex: 1 1 180px;
        min-width: 0;
    }

    .header-title-area h1 {
        font-size: 12px;
        line-height: 1.25;
        margin: 0;
        word-break: break-word;
    }

    .header-title-area p {
        font-size: 10px;
        line-height: 1.1;
        margin-top: 2px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* Prevent text collisions in flex bars */
    .d-flex.justify-content-between {
        flex-wrap: wrap !important;
        gap: 8px !important;
    }

    .d-flex.justify-content-between > h5,
    .d-flex.justify-content-between > h6 {
        margin-bottom: 4px !important;
        font-size: 0.9rem !important;
    }

    .form-select[style*="width"] {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Card Header Titles */
    .dash-card-header, .card-header {
        font-size: 11px !important;
        line-height: 1.3 !important;
        word-wrap: break-word;
        white-space: normal !important;
        padding: 6px 10px !important;
    }

    #map {
        height: 320px;
    }

    .dash-card {
        margin-bottom: 12px;
        height: auto;
    }

    .dash-card-body[style*="height: 0"] {
        height: auto !important;
        min-height: 200px;
    }

    .dashboard-footer {
        flex-direction: column;
        gap: 8px;
        text-align: center;
        padding: 12px 10px;
    }

    .footer-item {
        justify-content: center;
    }
}

@media (max-width: 576px) {
    .dashboard-header {
        padding: 6px 8px;
    }

    .header-logos img {
        height: 26px;
    }

    .header-title-area h1 {
        font-size: 11px;
        line-height: 1.2;
    }

    .header-title-area p {
        display: none;
    }

    .stat-box {
        padding: 6px 4px !important;
        word-wrap: break-word;
    }

    .stat-box h4, .stat-box h5 {
        font-size: 14px !important;
    }

    .stat-box p, .stat-box small {
        font-size: 9.5px !important;
        line-height: 1.2 !important;
    }

    #map {
        height: 260px;
    }
}

/* Leaflet Popup Styling - Prevent Clipping */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.25);
    padding: 2px;
}

.leaflet-popup-content {
    margin: 8px 10px !important;
    max-height: 220px !important;
    overflow-y: auto !important;
    font-size: 11px;
}

.dash-card-body {
    overflow: visible !important;
}

/* Fullscreen Leaflet Map Override */
#map:fullscreen,
div[id^="map"]:fullscreen,
.leaflet-container:fullscreen,
#map:-webkit-full-screen,
div[id^="map"]:-webkit-full-screen,
.leaflet-container:-webkit-full-screen {
    width: 100vw !important;
    height: 100vh !important;
    max-width: 100vw !important;
    max-height: 100vh !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
    z-index: 999999 !important;
    background: #fff !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
}

/* Sub Detail Compact Table */
.sub-compact-table td, 
.sub-compact-table th {
    padding: 3px 6px !important;
    font-size: 11px !important;
    line-height: 1.2 !important;
}

/* Print & PDF Export Cartographic Layout Styling */
@media print {
    @page {
        size: A4 landscape;
        margin: 8mm;
    }
    
    body, html, .wrapper, #content, .container-fluid {
        background: #ffffff !important;
        color: #000000 !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        padding: 0 !important;
        margin: 0 !important;
        display: block !important;
    }

    /* Hide Navigation, Footers, and Interactive Buttons */
    header.dashboard-header, 
    #sidebar, 
    .sidebar-overlay, 
    footer, 
    .navbar, 
    .btn, 
    .btn-group, 
    .no-print, 
    .leaflet-control-zoom, 
    #fsControl,
    .leaflet-control-layers {
        display: none !important;
    }

    .card {
        border: 1.5px solid #002b5e !important;
        box-shadow: none !important;
        margin-bottom: 10px !important;
        break-inside: avoid;
    }

    #mainDashboardMap, #map {
        height: 520px !important;
        width: 100% !important;
        border: 1px solid #333 !important;
    }

    #legendArea {
        max-height: none !important;
        overflow: visible !important;
    }

.village-label-tooltip {
    background: rgba(255, 255, 255, 0.98) !important;
    border: 1.5px solid #002b5e !important;
    border-radius: 4px !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3) !important;
    padding: 2px 5px !important;
    white-space: nowrap !important;
    pointer-events: none !important;
    z-index: 1500 !important;
}
.village-label-tooltip::before {
    border-top-color: #002b5e !important;
    border-bottom-color: #002b5e !important;
    border-left-color: #002b5e !important;
    border-right-color: #002b5e !important;
}



