/* Reset & Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: 'Roboto', sans-serif;
    color: #333;
    background: #f4f4f4;
}

#capture-area {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* Global Header (New) */
.main-header {
    position: relative;
    width: 100%;
    background: #f8f9fa;
    /* Consistent with sidebar */
    text-align: center;
    padding: 12px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    /* Soft shadow/border */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.03);
    z-index: 10;
    flex-shrink: 0;
    /* Prevents shrinking */
    display: flex;
    justify-content: center;
    align-items: center;
}

.header-badge {
    position: absolute;
    right: 20px;
    top: 50%;
    transform: translateY(-50%);
    background: #c62828;
    color: #fff;
    font-size: 11px;
    font-weight: bold;
    padding: 5px;
    padding-right: 10px;
    border-radius: 5px;
    box-shadow: 0 1px 3px rgba(198, 40, 40, 0.3);
    letter-spacing: 0.5px;
    white-space: nowrap;
}

.map-title {
    font-size: 18px;
    font-weight: 800;
    text-transform: uppercase;
    color: #000;
    margin: 0;
    white-space: nowrap;
}

.app-container {
    display: flex;
    flex: 1;
    /* Takes remaining height */
    width: 100%;
    min-height: 0;
    /* Crucial for nested flex scrolling */
    overflow: hidden;
}

/* Map Section (Left) */
#map {
    flex: 1;
    height: 100%;
    min-height: 0;
    /* Crucial for flex */
    z-index: 1;
    border-right: 1px solid #ddd;
    position: relative;
}

/* Inset Map (Tambelan) */
#tambelan-map-container {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 300px;
    /* slightly smaller scale */
    height: 200px;
    z-index: 1000;
    background: #fff;
    border: 2px solid #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    overflow: hidden;
}

.inset-label {
    position: absolute;
    top: 5px;
    left: 5px;
    background: rgba(255, 255, 255, 0.8);
    padding: 2px 5px;
    font-size: 12px;
    font-weight: bold;
    z-index: 1001;
    border-radius: 2px;
    pointer-events: none;
}

#tambelan-map {
    width: 100%;
    height: 100%;
}

/* Sidebar Section (Right) */
#sidebar {
    width: 330px;
    /* optimized width */
    height: 100%;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    z-index: 2;
    padding: 12px 16px;
    /* Reduced from 20px */
    box-shadow: -2px 0 10px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    flex-shrink: 0;
    min-height: 0;
    /* Allow shrinking in flex containers */
}

/* Sidebar Header */
.sidebar-header {
    text-align: center;
    margin-bottom: 0;
    flex-shrink: 0;
}

.logos {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 0px;
    /* Compact */
}

.logo-bmkg svg {
    /* Scale down the SVG inside slightly */
    height: 48px !important;
    width: auto !important;
    margin-bottom: 4px;
}

.station-name {
    font-size: 14px;
    /* Reduced from 16px */
    font-weight: bold;
    line-height: 1.3;
    text-transform: uppercase;
    color: #444;
}

.update-info {
    margin-top: 6px;
    margin-bottom: 8px;
    display: flex;
    justify-content: center;
}

/* Time Blocks */
.time-block {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    background: #e9ecef;
    padding: 4px 10px;
    border-radius: 12px;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
    white-space: nowrap;
}

.time-label {
    color: #555;
    font-weight: normal;
}

.time-val {
    color: #222;
    font-weight: bold;
}

.separator {
    border: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    margin: 8px 0;
    /* Compact */
    flex-shrink: 0;
}

/* === Dashboard Cards === */
.sidebar-card {
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 1px 5px rgba(0, 0, 0, 0.05);
    padding: 10px 15px;
    /* Compact */
    margin-bottom: 10px;
    /* Compact */
    border: 1px solid rgba(0, 0, 0, 0.05);
    flex-shrink: 0;
}

.sidebar-section-title {
    font-size: 13px;
    /* Smaller */
    font-weight: bold;
    text-transform: uppercase;
    color: #666;
    margin-bottom: 5px;
    letter-spacing: 0.5px;
    flex-shrink: 0;
}

/* Total Hotspot Section */
.total-section {
    text-align: center;
    background: linear-gradient(135deg, #ffffff 0%, #f9f9f9 100%);
    border-left: 4px solid #333;
    transition: transform 0.1s;
    padding: 8px 5px;
    /* Even more compact */
}

.total-section:active {
    transform: scale(0.98);
}

.total-section:hover {
    background: #f0f0f0;
}

.total-label {
    font-size: 14px;
    font-weight: bold;
    color: #555;
    letter-spacing: 0.5px;
}

.total-value {
    font-size: 28px;
    /* Reduced from 36px */
    font-weight: 800;
    color: #000;
    margin: 2px 0;
    line-height: 1;
}

.total-sub {
    font-size: 11px;
    color: #888;
}

/* Stats Container (Horizontal Box) */
.stats-container {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    /* Compact */
    margin-bottom: 5px;
    flex-shrink: 0;
}

.stat-card {
    flex: 1;
    background: #fff;
    border-radius: 6px;
    padding: 8px 4px;
    /* Compact */
    text-align: center;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    border-bottom: 3px solid transparent;
}

.stat-value {
    font-size: 22px;
    /* Reduced from 28px */
    font-weight: 800;
    color: #333;
}

.stat-label {
    font-size: 11px;
    /* Compact */
    color: #666;
    margin-top: 2px;
    font-weight: 500;
}

/* Confidence Colors (Flat Modern) */
.low-card {
    border-bottom-color: #2E7D32;
}

.medium-card {
    border-bottom-color: #F9A825;
}

.high-card {
    border-bottom-color: #C62828;
}

.low-card .stat-value {
    color: #2E7D32;
}

.medium-card .stat-value {
    color: #F9A825;
}

.high-card .stat-value {
    color: #C62828;
}

/* Satellite Compact Section - Disabled */
.satellite-compact {
    display: none;
    /* Hidden via CSS requirement */
}

/* North Arrow Control */
.north-arrow-control {
    background: transparent;
    border: none;
    box-shadow: none;
    margin-top: 5px;
    margin-right: 5px;
}

.north-arrow-control svg {
    filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.7));
}

/* Tooltip Permanent Label */
.village-label {
    background-color: transparent;
    border: none;
    box-shadow: none;
}

.village-label-content {
    background-color: rgba(255, 255, 255, 0.85);
    border: 1px solid rgba(0, 0, 0, 0.1);
    font-size: 11px;
    font-weight: bold;
    color: #111;
    padding: 2px 5px;
    white-space: nowrap;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
    pointer-events: none;
    display: inline-block;
    transform: translate(-50%, -100%);
    margin-top: -8px;
}

/* Popup */
.leaflet-popup-content-wrapper {
    border-radius: 6px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.2);
}

.leaflet-popup-content {
    margin: 12px;
}

/* Village List Section - PRIORITIZED AREA */
.village-list-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    /* MAXIMUM space priority */
    min-height: 0;
    /* Allow shrinking */
    margin-top: 5px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    /* Contains children */
}

.village-list-container {
    flex: 1;
    /* Takes all available wrapper space */
    overflow-y: auto;
    padding-right: 4px;
    scroll-behavior: smooth;
}

/* Custom Scrollbar for list */
.village-list-container::-webkit-scrollbar {
    width: 6px;
}

.village-list-container::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.village-list-container::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
}

.village-list-container::-webkit-scrollbar-thumb:hover {
    background: #aaa;
}

.village-item {
    background: #fff;
    border: 1px solid #eaeaea;
    padding: 8px 10px;
    margin-bottom: 5px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}

.village-item:hover {
    border-color: #1976D2;
    background: #f4f8ff;
    transform: translateY(-1px);
    box-shadow: 0 3px 6px rgba(25, 118, 210, 0.1);
}

.village-item-info {
    display: flex;
    flex-direction: column;
}

.village-name {
    font-size: 13px;
    font-weight: bold;
    color: #333;
    white-space: nowrap;
}

.village-region {
    font-size: 11px;
    color: #777;
    margin-top: 2px;
    white-space: nowrap;
}

.village-count {
    background: #e3f2fd;
    color: #1565c0;
    font-weight: 800;
    font-size: 12px;
    padding: 2px 8px;
    border-radius: 12px;
    min-width: 25px;
    text-align: center;
    box-shadow: inset 0 0 2px rgba(0, 0, 0, 0.05);
}

/* Sidebar Bottom (Fixed relative to sidebar) */
.sidebar-bottom {
    display: flex;
    flex-direction: column;
    margin-top: 10px;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    padding-top: 10px;
    background: #f8f9fa;
    flex-shrink: 0;
}

.sidebar-footer {
    padding: 6px;
    font-size: 11px;
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.05);
    margin-bottom: 8px;
    color: #666;
    text-align: center;
}

/* Download Button */
.download-btn {
    width: 100%;
    padding: 8px 10px;
    background-color: #007bff;
    color: white;
    border: none;
    border-radius: 6px;
    font-size: 13px;
    font-weight: bold;
    cursor: pointer;
    transition: background-color 0.2s;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.download-btn:hover {
    background-color: #0056b3;
}

.download-btn:active {
    transform: translateY(1px);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 3000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal.show {
    display: flex;
}

.modal-content {
    background-color: #fefefe;
    padding: 20px;
    border: 1px solid #888;
    width: 90%;
    max-width: 800px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.close-modal {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    align-self: flex-end;
    cursor: pointer;
    margin-top: -10px;
}

.close-modal:hover,
.close-modal:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

.modal-content h2 {
    margin-top: 0;
    margin-bottom: 5px;
    font-size: 18px;
    text-transform: uppercase;
    color: #333;
    border-bottom: 2px solid #ddd;
    padding-bottom: 10px;
}

.modal-subtitle {
    font-size: 13px;
    color: #666;
    margin-bottom: 15px;
    font-style: italic;
}

.table-container {
    overflow-y: auto;
    flex: 1;
}

#hotspot-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

#hotspot-table th,
#hotspot-table td {
    border: 1px solid #ddd;
    padding: 8px;
    text-align: left;
}

#hotspot-table th {
    background-color: #f2f2f2;
    position: sticky;
    top: 0;
    color: #333;
}

#hotspot-table tr:nth-child(even) {
    background-color: #f9f9f9;
}

#hotspot-table tr:hover {
    background-color: #f1f1f1;
}

/* Error Overlay */
#error-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 2000;
    display: flex;
    justify-content: center;
    align-items: center;
}

.error-box {
    background: white;
    padding: 20px 40px;
    border-radius: 8px;
    text-align: center;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.hidden {
    display: none !important;
}

/* Responsive */
@media (max-width: 768px) {

    body,
    .app-container {
        flex-direction: column;
    }

    .app-container {
        flex-direction: column-reverse;
        /* Sidebar on TOP, Map on BOTTOM */
    }

    /* On mobile, sidebar needs a constrained height to allow list scrolling natively,
       or we make it flex take remaining space. Since map usually wants a fixed height on mobile */
    #map {
        flex: 1;
        min-height: 50vh;
    }

    .map-title {
        font-size: 13px;
        white-space: normal;
    }

    #sidebar {
        width: 100%;
        height: auto !important;
        max-height: 22vh !important;
        flex: none;
        overflow-y: auto !important;
        border-top: 2px solid #ccc;
        margin-top: -10px;
    }

    .header-badge {
        font-size: 8px;
        padding: 2px;
        margin-top: 8px;
    }

    .village-list-wrapper {
        flex: none !important;
    }

    .village-list-container {
        flex: none !important;
        overflow-y: visible !important;
        max-height: none !important;
    }

    #tambelan-map-container {
        bottom: 10px;
        left: 10px;
        width: 175px;
        /* smaller on mobile */
        height: 100px;
    }

    .inset-label {
        font-size: 11px;
    }

    .update-info {
        margin-top: 0px;
    }

    .station-name {
        font-size: 12px;
    }
}

/* Capture Mode Overrides */
.capture-mode {
    overflow: visible !important;
}

.capture-mode .download-btn {
    display: none !important;
}

.capture-mode .village-list-container {
    overflow: hidden !important;
}