:root {
    --bg-dark: #0f111a;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --accent: #3b82f6;
    --accent-hover: #60a5fa;
    --glass-bg: #1e1e24; /* Lighter color logic to distinguish from map/background */
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-blur: blur(16px);
    
    /* Layout Constants */
    --left-sidebar-total: 368px;  /* 24 + 320 + 24 */
    --right-sidebar-total: 368px; /* 24 + 320 + 24 */
    --bottom-panel-total: 244px;  /* 220 + 24 */
}

/* Collapse States */
body.collapse-left { --left-sidebar-total: 24px; }
body.collapse-right { --right-sidebar-total: 24px; }
body.collapse-bottom { --bottom-panel-total: 0px; }

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Outfit', sans-serif;
    color: var(--text-main);
    overflow: hidden;
    background: var(--bg-dark);
    /* App feel, prevents body scroll */
}

/* Map takes center screen between two sidebars */
#map {
    position: absolute;
    top: 24px;
    left: var(--left-sidebar-total);
    width: calc(100vw - var(--left-sidebar-total) - var(--right-sidebar-total));
    height: calc(100vh - 48px - var(--bottom-panel-total));
    z-index: 0;
    background: #f2f2f5;
    border-radius: 0;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
    transition: all 0.3s ease;
}

/* Prevent browser focus outline/bounding box rectangle on clicked map vector paths */
.leaflet-container path:focus,
.leaflet-container svg:focus,
.leaflet-container :focus,
.leaflet-interactive:focus,
path.leaflet-interactive:focus,
.leaflet-pane svg path:focus {
    outline: none !important;
}

/* Map Title Container */
.map-title-container {
    position: absolute;
    top: 40px;
    left: calc(var(--left-sidebar-total) + 24px);
    z-index: 1000;
    color: #ffffff;
    pointer-events: none;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
    transition: left 0.3s ease;
}

.map-title-container h2 {
    font-size: 1.6rem;
    font-weight: 500;
    margin: 0;
    letter-spacing: 0.5px;
}

/* Floating Toggles */
.panel-toggle {
    position: absolute;
    width: 32px;
    height: 32px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: var(--glass-blur);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.5);
    transition: all 0.3s ease;
}
.panel-toggle:hover {
    background: var(--accent);
}

.toggle-left {
    left: calc(var(--left-sidebar-total) - 16px);
    top: 50%;
}
body.collapse-left .toggle-left {
    transform: rotate(180deg);
}

.toggle-right {
    right: calc(var(--right-sidebar-total) - 16px);
    top: 50%;
}
body.collapse-right .toggle-right {
    transform: rotate(180deg);
}

.toggle-bottom {
    bottom: calc(var(--bottom-panel-total) + 16px);
    left: calc(var(--left-sidebar-total) + (100vw - var(--left-sidebar-total) - var(--right-sidebar-total)) / 2);
    transform: translateX(-50%);
}
body.collapse-bottom .toggle-bottom {
    bottom: 24px;
    transform: translateX(-50%) rotate(180deg);
}

/* Glassmorphism Classes */
.glass-panel {
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
}

.glass-panel-inner {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}





/* Make leaflet controls match the dark theme */
.leaflet-bar a {
    background-color: var(--glass-bg) !important;
    border: 1px solid var(--glass-border) !important;
    color: var(--text-main) !important;
    backdrop-filter: var(--glass-blur);
}

.leaflet-bar a:hover {
    background-color: var(--accent) !important;
}

/* Fix Leaflet Draw plugin sprites using an SVG invert trick */
.leaflet-draw-toolbar a {
    background-color: rgba(240, 238, 229, 0.75) !important;
    border: 1px solid rgba(0, 0, 0, 0.3) !important;
    filter: invert(1);
    color: black !important;
}

.leaflet-draw-toolbar a:hover {
    background-color: #c47d09 !important;
    /* Inverts mathematically to #3b82f6 (blue hover) */
}

/* GAPA/NAPA Polygons Label (Small Map Label) */
.gapa-label {
    background: transparent !important;
    border: none !important;
    box-shadow: none !important;
    color: #ffffff !important;
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
    font-size: 0.78rem !important;
    text-shadow:
        -1px -1px 0 rgba(0, 0, 0, 0.85),
         1px -1px 0 rgba(0, 0, 0, 0.85),
        -1px  1px 0 rgba(0, 0, 0, 0.85),
         1px  1px 0 rgba(0, 0, 0, 0.85),
         0 0 6px rgba(0, 0, 0, 0.95);
    letter-spacing: 0.3px;
    text-align: center;
    pointer-events: none;
    padding: 0 !important;
    white-space: nowrap;
}

.gapa-label::before {
    display: none !important;
}

/* ── Boundary click popup ──────────────────────────────── */
.boundary-popup .leaflet-popup-content-wrapper {
    background: rgba(15, 17, 26, 0.92) !important;
    backdrop-filter: blur(18px) !important;
    -webkit-backdrop-filter: blur(18px) !important;
    border: 1px solid rgba(96, 165, 250, 0.3) !important;
    border-radius: 14px !important;
    box-shadow: 0 12px 36px rgba(0, 0, 0, 0.65) !important;
    padding: 0 !important;
    overflow: hidden;
}

.boundary-popup .leaflet-popup-content {
    margin: 0 !important;
    width: auto !important;
}

.boundary-popup .leaflet-popup-tip {
    background: rgba(15, 17, 26, 0.92) !important;
}

.boundary-popup .leaflet-popup-close-button {
    color: rgba(255,255,255,0.4) !important;
    font-size: 1rem !important;
    top: 8px !important;
    right: 10px !important;
    z-index: 10;
}
.boundary-popup .leaflet-popup-close-button:hover {
    color: #fff !important;
}

/* Simple single-line popup (loading / error) */
.boundary-popup-inner {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
}

.boundary-popup-icon {
    font-size: 1.1rem;
    line-height: 1;
    flex-shrink: 0;
}

.boundary-popup-name {
    font-family: 'Outfit', sans-serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: #e2e8f0;
    letter-spacing: 0.3px;
    flex: 1;
}

/* Loading spinner */
.bp-loading-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(96,165,250,0.3);
    border-top-color: #60a5fa;
    border-radius: 50%;
    animation: bp-spin 0.8s linear infinite;
    flex-shrink: 0;
}
@keyframes bp-spin { to { transform: rotate(360deg); } }

.bp-no-data {
    font-size: 0.8rem;
    color: var(--text-muted, #94a3b8);
    margin-left: 8px;
}

/* Rich table popup */
.boundary-popup-body {
    min-width: 320px;
}

.boundary-popup-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px 8px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.bp-source {
    font-family: 'Outfit', sans-serif;
    font-size: 0.7rem;
    color: rgba(148,163,184,0.7);
    padding: 4px 16px 6px;
    letter-spacing: 0.2px;
}

/* Forecast table */
.bp-table {
    width: 100%;
    border-collapse: collapse;
    font-family: 'Outfit', sans-serif;
    font-size: 0.78rem;
}

.bp-table thead tr {
    background: rgba(59, 130, 246, 0.15);
}

.bp-table th {
    padding: 6px 8px;
    text-align: center;
    color: #93c5fd;
    font-weight: 500;
    font-size: 0.72rem;
    white-space: nowrap;
    border-bottom: 1px solid rgba(255,255,255,0.07);
}

.bp-table tbody tr:nth-child(even) {
    background: rgba(255,255,255,0.03);
}

.bp-table tbody tr:hover {
    background: rgba(96,165,250,0.1);
}

.bp-td-time {
    padding: 5px 8px;
    text-align: center;
    color: #60a5fa;
    font-weight: 600;
    white-space: nowrap;
}

.bp-td {
    padding: 5px 8px;
    text-align: center;
    color: #e2e8f0;
    white-space: nowrap;
}

/* ── Smooth Polygon Transitions ────────────────────────────────────────── */
path.leaflet-interactive {
    transition: fill 0.4s ease-in-out, fill-opacity 0.35s ease, stroke 0.3s ease !important;
}

/* ── Floating District Overview Summary Card ──────────────────────────────── */
.district-summary-card {
    position: absolute;
    top: 85px;
    left: calc(var(--left-sidebar-total) + 24px);
    z-index: 1000;
    padding: 10px 16px;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(12px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    pointer-events: auto;
    transition: left 0.3s ease, transform 0.2s ease;
}

.district-summary-card:hover {
    transform: translateY(-2px);
}

.ds-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 6px;
}

.ds-title {
    font-size: 0.82rem;
    font-weight: 600;
    color: #94a3b8;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.ds-badge {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: rgba(59, 130, 246, 0.25);
    color: #60a5fa;
    border: 1px solid rgba(96, 165, 250, 0.4);
}

.ds-metrics {
    display: flex;
    align-items: center;
    gap: 14px;
}

.ds-metric {
    display: flex;
    flex-direction: column;
}

.ds-label {
    font-size: 0.68rem;
    color: #64748b;
    font-weight: 500;
}

.ds-val {
    font-size: 0.95rem;
    font-weight: 700;
    color: #f8fafc;
}

.ds-val.ds-min {
    color: #93c5fd;
}

.ds-val.ds-max {
    color: #fca5a5;
}

.ds-divider {
    width: 1px;
    height: 24px;
    background: rgba(255, 255, 255, 0.1);
}

/* ── Live Floating Ward Map Badges ────────────────────────────────────────── */
.custom-ward-badge-container {
    z-index: 650 !important;
}

.ward-map-badge {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3px 8px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.82);
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(8px);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
    color: #ffffff;
    font-family: 'Outfit', sans-serif;
    text-align: center;
    white-space: nowrap;
    pointer-events: none;
    transition: transform 0.2s ease, background 0.3s ease, border-color 0.3s ease;
}

.ward-map-badge-name {
    font-size: 0.62rem;
    font-weight: 500;
    color: rgba(248, 250, 252, 0.85);
    line-height: 1.1;
    max-width: 110px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ward-map-badge-val {
    font-size: 0.82rem;
    font-weight: 700;
    line-height: 1.1;
    margin-top: 1px;
}

.ward-map-badge-status {
    font-size: 0.60rem;
    font-weight: 600;
    padding: 1px 5px;
    border-radius: 6px;
    margin-top: 2px;
    line-height: 1;
    letter-spacing: 0.2px;
}

