/* Import Inter font */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&display=swap');

:root {
    --primary-color: #016F6C;
    --secondary-color: #EE8F14;
    --accent-color: #2D3748;
    --light-bg: #F7FAFC;
    --primary: #016F6C;
    --secondary: #EE8F14;
    --accent: #2D3748;
    --light: #F7FAFC;
    --white: #FFFFFF;
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --border-radius: 8px;
    --transition: all 0.3s ease;
    /* Dynamic overlay sizing (updated by JS when docking/resizing) */
    --charts-overlay-width: 0px;
    --charts-overlay-height: 0px;

    /* background color used for the background */
    --background: var(--primary);
    /* background-inverse color used for contrast - background */
    --background-inverse: #ffff;    
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: var(--white);
    color: var(--accent-color);
    overflow-x: hidden;
}

main {
    overflow-y: auto;
}

.top-nav {
    background: linear-gradient(135deg, var(--primary-color) 0%, #028A88 100%);
    color: var(--white);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    height: 64px;
    box-shadow: var(--shadow);
    z-index: 1000;
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-left i {
    font-size: 24px;
    color: var(--secondary-color);
}

/* logo image in header */
.nav-logo {
    width: 36px;
    height: 36px;
    object-fit: contain;
    display: inline-block;
}
.nav-partners {
    width: 100%;
    height: 36px;
    object-fit: contain;
    display: inline-block;
}

.top-nav h1 {
    font-size: 24px;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.nav-right {
    display: flex;
    gap: 8px;
}

.nav-btn {
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--white);
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    transition: var(--transition);
}

.nav-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.filter-bar {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    padding: 12px 18px;
    z-index: 900;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
    max-width: 96vw;
    animation: slideDown 0.4s ease-out;
    display: flex;
    flex-direction: column; /* selectors row, actions row */
    align-items: stretch;
    gap: 8px;
}

.filter-selects {
    display: flex;
    gap: 12px;

    flex-wrap: nowrap; /* keep selectors on a single row; allow horizontal scroll if overflow */
    justify-content: center;
    align-items: center;
    overflow-x: auto;
    padding-bottom: 2px;
}

.filter-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    width: 100%;
    margin-top: 6px;
}

/* Responsive: stack filters vertically on narrow viewports */
@media (max-width: 800px) {
    .filter-bar { flex-direction: column; padding: 18px 20px; }
    .filter-selects { flex-wrap: wrap; overflow-x: visible; }
    .filter-actions { margin-left: 0; }
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-20px);
    }

    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

.filter-bar.open {
    opacity: 1;
    visibility: visible;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 0 20px rgba(1, 111, 108, 0.1);
}

.filter-bar-content {
    display: flex;
    align-items: end;
    gap: 24px;
    flex-wrap: wrap;
    justify-content: center;
}

.filter-bar .filter-group {
    margin-bottom: 0;
    min-width: 140px;
    text-align: center;
}

.filter-bar .filter-group label {
    font-size: 12px;
    margin-bottom: 8px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--accent-color);
    font-weight: 500;
}

.filter-bar .filter-group label i {
    font-size: 16px;
    color: var(--primary-color);
}

/* Custom styling for bootstrap-select to match the app theme */
.bootstrap-select .dropdown-toggle {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--accent-color);
    min-width: 160px;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    box-shadow: none;
}
.bootstrap-select .dropdown-toggle:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(1,111,108,0.08);
}
.bootstrap-select .dropdown-toggle .filter-option {
    color: var(--accent-color);
}
.bootstrap-select .dropdown-toggle .caret {
    color: var(--primary-color);
}
.bootstrap-select .dropdown-menu {
    background: rgba(255,255,255,0.98);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 8px;
    position: absolute; /* ensure it floats above other content */
    z-index: 200000 !important;
    /* force the parent NOT to scroll; the inner list will be the scrollable element */
    overflow: visible !important;
    max-height: none !important;
}

/* The inner container (.inner) holds the selectable list and should be the scrolling element */
.bootstrap-select .dropdown-menu .inner {
    /* Enforce a hard max height so roughly 10 rows are visible across browsers */
    max-height: 360px !important; /* ~10 rows at ~34-36px each */
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
}

/* Defensive: override any Bootstrap-added 'show' or 'open' overflow rules */
.bootstrap-select .dropdown-menu.show,
.bootstrap-select .dropdown-menu.open {
    overflow: visible !important;
    max-height: none !important;
}

.bootstrap-select .dropdown-menu .inner.show {
    overflow: auto !important;
}
.bootstrap-select .dropdown-menu .inner li a {
    color: var(--accent-color);
    padding: 6px 12px;
    font-size: 13px;
    line-height: 28px; /* normalize height */
    min-height: 28px;
}
.bootstrap-select .bs-actionsbox .btn {
    font-size: 12px;
    color: var(--primary-color);
}
.bootstrap-select .dropdown-menu .selected a {
    background: linear-gradient(90deg, rgba(1,111,108,0.06), rgba(238,143,20,0.04));
}

/* Ensure only the inner list scrolls even if bootstrap toggles 'show' on multiple elements */
.bootstrap-select .dropdown-menu.show,
.bootstrap-select .dropdown-menu.open {
    overflow: visible !important;
}
.bootstrap-select .dropdown-menu .inner.show {
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
}


/* Slider group for year range */
.slider-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    align-items: stretch;
}
.slider-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.slider-row input[type="range"] {
    flex: 1;
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    height: 6px;
    background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
    border-radius: 6px;
    outline: none;
    z-index: 5;
}
.slider-row input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--primary-color);
}
.slider-row span {
    min-width: 44px;
    text-align: center;
    font-weight: 600;
    color: var(--accent-color);
}

.filter-bar .modern-select {
    padding: 10px 14px;
    font-size: 14px;
    min-width: 140px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--accent-color);
}

.filter-bar .modern-select:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 2px rgba(1, 111, 108, 0.2);
}

.filter-bar .filter-actions {
    margin-top: 0;
    flex-direction: row;
    gap: 12px;
    justify-content: center;
}

.filter-bar .btn-primary,
.filter-bar .btn-secondary {
    padding: 10px 16px;
    font-size: 13px;
    min-width: 90px;
    border-radius: 20px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.filter-bar .btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #028A88 100%);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.filter-bar .btn-primary:hover {
    background: linear-gradient(135deg, #028A88 0%, var(--primary-color) 100%);
    box-shadow: 0 4px 12px rgba(1, 111, 108, 0.3);
}

.filter-bar .btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: var(--accent-color);
}

.filter-bar .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

.modern-select {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid #E2E8F0;
    border-radius: var(--border-radius);
    background: var(--white);
    font-size: 14px;
    transition: var(--transition);
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-repeat: no-repeat;
    background-size: 16px;
    padding-right: 40px;
}

.modern-select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(1, 111, 108, 0.1);
}

.filter-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}

.btn-primary,
.btn-secondary {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: var(--border-radius);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary-color) 0%, #028A88 100%);
    color: var(--white);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: var(--light-bg);
    color: var(--accent-color);
    border: 2px solid #E2E8F0;
}

.btn-secondary:hover {
    background: #EDF2F7;
    border-color: var(--accent-color);
}

.map-container {
    margin-left: 0;
    margin-top: 0px;
    /* Make room for top nav (64px) and optional bottom charts overlay height */
    height: calc(100vh - 64px - var(--charts-overlay-height));
    /* When docked to the right, reserve space so the map isn't overlapped */
    margin-right: var(--charts-overlay-width);
    position: relative;
    background: var(--white);
}

#map {
    height: 100%;
    width: 100%;
    border-radius: var(--border-radius);
}

.map-controls {
    position: absolute;
    top: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 1000;
}

.map-fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    color: var(--primary-color);
    font-size: 18px;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

/* positioned variant for top-left action button */
.map-fab-left {
    position: absolute;
    left: 10px;
    /* position below the top nav (64px) + drawers (240px) +  20px spacing */
    top: 270px;
    z-index: 999;
}

/* Map legend */
.map-legend {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 900;
    /* glass look */
    background: rgba(255,255,255,0.50);
    backdrop-filter: blur(80px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.12);
    padding: 12px 14px;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.12);
    font-size: 13px;
    color: var(--accent-color);
    min-width: 180px;
    width: 220px;
    transition: bottom 320ms cubic-bezier(.2,.9,.2,1), height 320ms cubic-bezier(.2,.9,.2,1), padding 240ms ease, box-shadow 240ms ease;
    overflow: visible;
}

/* When charts overlay is open, move legend above it */
.charts-overlay.open ~ .map-container .map-legend,
body:has(.charts-overlay.open) .map-legend {
    bottom: calc(var(--charts-overlay-height, 450px) + 20px);
}

/* When charts overlay is docked to the right, move legend left to avoid overlap */
.charts-overlay.dock-right.open ~ .map-container .map-legend,
body:has(.charts-overlay.dock-right.open) .map-legend {
    right: calc(var(--charts-overlay-width, 420px) + 20px);
    bottom: 20px; /* Reset bottom position when docked right */
}
.map-legend h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: var(--primary-color);
}
.map-legend .legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    transition: opacity 220ms ease, transform 260ms ease;
}
.map-legend .legend-swatch {
    width: 12px;
    height: 12px;
    border-radius: 3px;
    border: 1px solid rgba(0,0,0,0.06);
}
.map-legend .legend-note {
    margin-top: 6px;
    font-size: 12px;
    color: #4A5568;
    transition: opacity 220ms ease, transform 260ms ease;
}

.map-fab:hover {
    background: var(--white);
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.map-fab-text {
    min-width: 44px;
    height: 32px;
    border-radius: 8px;
    border: none;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    color: var(--primary-color);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
}

.map-fab-text:hover {
    background: var(--white);
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.map-fab-text:active {
    transform: scale(0.95);
}

/* Chart info card (glass) positioned above FABs to avoid overlap */
.chart-info-card {
    position: absolute;
    right: 20px;
    bottom: 96px;
    /* above the FAB stack (56px + gap) */
    width: 300px;
    max-width: 40vw;
    background: rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
    padding: 12px;
    z-index: 1100;
    transform-origin: bottom right;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition);
}

.chart-info-card.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.chart-info-card .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.close-btn-small {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.12);
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    color: var(--accent-color);
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
}

.chart-info-card .card-body p {
    font-size: 13px;
    color: var(--accent-color);
}

.details-drawer {
    position: fixed;
    right: -360px;
    top: 64px;
    width: 360px;
    height: calc(70vh - 64px);
    background: rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-left: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    transition: var(--transition);
    z-index: 1050;
    display: flex;
    flex-direction: column;
}

.details-drawer.open {
    /* Offset the open drawer by the charts overlay width when docked to right.
       --charts-overlay-width is updated by JS when the overlay is resized/docked. */
    right: calc(var(--charts-overlay-width, 0px) + 16px);
}

/* The header is now outside the scrollable content. Make the inner body scrollable. */
.details-drawer .drawer-body {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 12px 16px;
    flex: 1 1 auto; /* expand to fill remaining space beneath header */
}

.details-drawer .drawer-content {
    /* Remove previous drawer scrolling responsibilities - content will be inside .drawer-body */
    display: block;
}

/* Popup compact layout and CTA style for view details */
.popup-compact {
    font-size: 13px;
    color: var(--accent-color);
}
.popup-compact small {
    color: rgba(45,55,72,0.8);
}
.view-details-btn {
    background: linear-gradient(180deg, rgba(1,111,108,1), rgba(1,111,108,0.95));
    color: white;
    border: none;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 12px;
    cursor: pointer;
}
.view-details-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(1,111,108,0.16); }

/* Detail drawer action buttons */
.detail-actions {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}
.btn-small {
    background: rgba(255,255,255,0.06);
    color: var(--primary-color);
    border: 1px solid rgba(255,255,255,0.06);
    padding: 6px 8px;
    border-radius: 8px;
    font-size: 13px;
    cursor: pointer;
}
.btn-small:hover { background: rgba(255,255,255,0.10); }
.details-drawer .panel-header{
    display: flex;
    justify-content: space-between;
    align-items: center; /* vertically center h4 and close button */
    padding: 12px;
}

/* Ensure header title has no unexpected margins and aligns nicely */
.details-drawer .panel-header h4,
.details-drawer .panel-header h3,
.details-drawer .panel-header h2 {
    margin: 0;
    line-height: 1.1;
    display: flex;
    align-items: center;
    gap: 8px;
}


.drawer-content p {
    margin-bottom: 12px;
    font-size: 14px;
    line-height: 1.5;
}

.drawer-content strong {
    color: var(--primary-color);
}

.drawer-content a {
    color: var(--secondary-color);
    text-decoration: none;
    font-weight: 500;
}

.drawer-content a:hover {
    text-decoration: underline;
}

.charts-overlay {
    position: fixed;
    bottom: -450px;
    left: 0;
    right: 0;
    height: 450px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(25px);
    -webkit-backdrop-filter: blur(25px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 24px 24px 0 0;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    transition: var(--transition);
    z-index: 1000;
    overflow-y: auto;
}

.charts-overlay.open {
    bottom: 0;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 0 20px rgba(1, 111, 108, 0.1);
}

.charts-overlay:not(.open) {
    height: 0;
}

/* When the overlay is closed we still need to hide inner content (charts/table)
   because some child panels use their own backgrounds and can remain visible
   even when the container height is 0. The `.collapsed` class is added via
   JS after the close transition finishes and forces child content to be
   visually removed and non-interactive. */
.charts-overlay.collapsed .charts-content,
.charts-overlay.collapsed .chart-container,
.charts-overlay.collapsed .panel-header {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
    pointer-events: none !important;
}

.charts-content {
    padding: 4px 32px;
    /* make charts layout a horizontal flex row with equal-width panels */
    display: flex;
    flex-direction: row;
    gap: 24px;
    align-items: stretch;
    flex-wrap: wrap; /* wrap on small screens */
}

.chart-container {
    /* equal-width flexible panels */
    flex: 1 1 320px; /* grow, shrink, base width */
    min-width: 280px;
    height: 356px;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--border-radius);
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    transition: var(--transition);
}

.chart-container:hover {
    background: rgba(255, 255, 255, 0.9);
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
}

.chart-container h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--primary-color);
    text-align: center;
}

.chart-container canvas {
    width: 100% !important;
    height: calc(100% - 40px) !important;
    /* leave space for title and legend */
    display: block;
    margin: 0 auto;
}

.plotly-chart {
    width: 100% !important;
    height: calc(100% - 40px) !important;
    /* leave space for title and legend */
}

.chart-center {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
}




.charts-overlay .panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 32px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.charts-overlay .panel-header h2 {
    font-size: 20px;
    font-weight: 600;
    color: var(--primary-color);
    display: flex;
    align-items: center;
    gap: 8px;
}

.charts-overlay .close-btn {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.24);
    color: var(--accent-color);
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: var(--transition);
}

/* Make drawer close button visually consistent */
.details-drawer .close-btn {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.24);
    color: var(--accent-color);
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: var(--transition);
}

.details-drawer .close-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

.charts-overlay .close-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Analytics view toggle */
.view-toggle {
    display: inline-flex;
    gap: 6px;
    margin-left: 12px;
}
.toggle-btn {
    background: rgba(255,255,255,0.06);
    color: var(--black);
    border: 1px solid rgba(255,255,255,0.06);
    padding: 6px 8px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    display: inline-flex;
    gap: 6px;
    align-items: center;
}
.toggle-btn.active {
    background: var(--white);
    color: var(--accent-color);
    border-color: rgba(0,0,0,0.06);
}

/* Dock button with label for clarity */
.dock-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    /* stronger visible default so it's obvious on dark glass header */
    background: rgba(255,255,255,0.88);
    color: var(--accent-color);
    border: 1px solid rgba(0,0,0,0.06);
    border-radius: 10px;
    font-weight: 600;
    box-shadow: 0 6px 14px rgba(2,136,136,0.06);
}
.dock-btn .dock-label { font-size: 13px; font-weight: 600; display: inline-block; color: var(--accent-color); }
@media (max-width: 480px) {
    .dock-btn .dock-label { display: none; }
}

/* Make dock button hover/focus more visible against glass background */
.dock-btn:hover,
.dock-btn:focus,
.dock-btn:focus-visible {
    background: rgba(255,255,255,0.95);
    color: var(--accent-color);
    border-color: rgba(0,0,0,0.06);
    box-shadow: 0 6px 18px rgba(0,0,0,0.18);
    transform: translateY(-1px);
}
.dock-btn:active {
    transform: translateY(0);
}
.dock-btn:focus-visible {
    outline: 3px solid rgba(1,111,108,0.12);
    outline-offset: 2px;
}

/* Table styles for analytics */
.analytics-table {
    padding: 0 16px 12px 16px;
    max-height: 78%;
    overflow: auto;
    background: rgba(255,255,255,0.02);
}
.analytics-table table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    color: var(--accent-color);
}
.analytics-table th, .analytics-table td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.04);
    text-align: left;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.analytics-table th {
    background: rgba(255,255,255,0.03);
    position: sticky;
    top: 0;
    z-index: 2;
}
.analytics-table tr:hover td {
    background: rgba(255,255,255,0.02);
}

/* Make DataTable / analytics table header visually sticky when scrolling
   inside the analytics panel (both bottom-docked and right-docked). We
   apply a semi-opaque background so it remains readable over the glass
   panel and a subtle drop shadow to separate it from rows. */
#surveyPointsTable thead th,
.analytics-table thead th {
    position: sticky;
    top: 0;
    background: rgba(255,255,255,0.95);
    color: var(--accent-color);
    z-index: 5;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
}

/* Ensure the table's thead sits above any floating controls inside the panel */
.charts-overlay .analytics-table thead th {
    z-index: 6;
}

/* DataTable column filter inputs */
.analytics-table thead th input {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--accent-color);
    font-size: 11px;
}

.analytics-table thead th input:focus {
    outline: none;
    border-color: var(--primary-color);
    background: rgba(255,255,255,0.08);
}

/* Force SearchBuilder and Buttons on same line */
.dt-searchBuilder, .dt-buttons {
    display: inline-block !important;
    vertical-align: top !important;
    margin-right: 10px !important;
}

.dt-searchBuilder {
    margin-bottom: 0 !important;
}

.dt-buttons {
    margin-bottom: 0 !important;
}

.dt-searchBuilder .dtsb-searchBuilder {
    margin-bottom: 0 !important;
}

.detail-card {
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.04), rgba(255, 255, 255, 0.02));
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 16px;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.detail-item {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
    font-size: 14px;
}

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

.drawer-title h3 {
    font-size: 18px;
    margin: 0;
}

.badge {
    padding: 6px 10px;
    border-radius: 999px;
    font-weight: 600;
    font-size: 12px;
    color: #38A169;
}

.status-completed,
.badge.status-completed {
    background: linear-gradient(90deg, #2F855A, #38A169);
}

.status-in-progress,
.badge.status-in-progress {
    background: linear-gradient(90deg, #EE8F14, #F6AD55);
}

.status-planned,
.badge.status-planned {
    background: linear-gradient(90deg, #A0AEC0, #CBD5E0);
    color: #2D3748;
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.section h4 {
    margin: 8px 0 8px 0;
    font-size: 14px;
    color: var(--primary-color);
}

.section p {
    margin: 4px 0;
    font-size: 13px;
    line-height: 1.4;
}

.deliverables-list {
    list-style: none;
    padding-left: 0;
}

.deliverables-list li {
    margin-bottom: 8px;
}

.provenance div {
    font-size: 13px;
    margin-bottom: 6px;
}

.detail-action {
    display: flex;
    gap: 8px;
    justify-content: space-between;
    align-items: center;
    margin-top: 12px;
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--white);
}

.detail-item i {
    color: var(--primary-color);
    width: 16px;
}

.detail-item span {
    flex: 1;
}

.status-completed {
    color: #38A169;
    font-weight: 500;
}

.status-in-progress {
    color: var(--secondary-color);
    font-weight: 500;
}

.status-planned {
    color: #A0AEC0;
    font-weight: 500;
}

.detail-action {
    margin-top: 16px;
    text-align: center;
}

.btn-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--secondary-color);
    color: var(--white);
    padding: 10px 16px;
    border-radius: var(--border-radius);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

.btn-link:hover {
    background: #D69E2E;
    transform: translateY(-1px);
}

/* Responsive Design */
@media (max-width: 768px) {
    .filter-bar {
        max-width: 95vw;
        padding: 20px 24px;
        gap: 16px;
    }

    .filter-selects {
        gap: 16px;
    }

    .filter-bar .filter-group {
        min-width: 120px;
    }

    .filter-actions {
        gap: 12px;
    }

    .charts-overlay {
        left: 0;
    }

    .details-drawer {
        width: 100%;
        right: -100%;
    }

    .details-drawer.open {
        right: 90px;
    }

    .nav-left h1 {
        font-size: 20px;
    }

    .charts-content {
        padding: 2px 24px;
        grid-template-columns: 1fr;
    }
}

/* Loading animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.panel-header,
.filter-content,
.drawer-content,
.charts-content {
    animation: fadeIn 0.3s ease-out;
}

/* Legend toggle button */
.legend-toggle {
    position: absolute;
    top: 8px;
    right: 10px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 18px;
    color: var(--accent-color);
    transition: transform 200ms ease, background 180ms ease;
}
.legend-toggle:hover { transform: scale(1.06); background: rgba(255,255,255,0.09); }

/* Collapsed legend styles */
.map-legend.collapsed {
    /* keep width when collapsed but reduce visual height */
    height: 52px;
    padding: 6px 10px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.06);
}
.map-legend.collapsed .legend-item,
.map-legend.collapsed .legend-note {
    opacity: 0;
    transform: translateY(-6px);
    pointer-events: none;
}
.map-legend .legend-item { transition-delay: 0; }

/* Basemap selector */
.basemap-selector {
    position: fixed;
    top: 153px;
    right: 86px;
    background: rgba(255,255,255,0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    padding: 12px;
    z-index: 1100;
    display: none;
    min-width: 180px;
    font-size: 14px;
    color: var(--accent-color);
}
.basemap-selector.open {
    display: block;
}
.selector-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}
.selector-header h4 {
    margin: 0;
    font-size: 14px;
    color: var(--primary-color);
}
.settings-section {
    margin-bottom: 16px;
}
.settings-section h5 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 600;
    color: var(--primary-color);
}
.radio-group {
    display: flex;
    flex-direction: column;
}
.radio-group label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 13px;
    padding: 4px 0;
    margin-bottom: 0px !important;
}
.radio-group input[type="radio"],
.radio-group input[type="checkbox"] {
    margin: 0;
}
.basemap-selector label input[type="checkbox"] {
    margin-right: 8px;
}

/* Docked to right (sidebar) variant */
.charts-overlay.dock-right {
    bottom: 0;
    top: 64px; /* below top nav */
    right: -420px; /* hidden by default until .open */
    left: auto;
    width: 420px;
    /* height set in .open */
    /* top-left and bottom-right square to align with resizer */
    border-radius: 0 12px 0 12px;
    transition: right 280ms ease, width 160ms ease, height 160ms ease;
    overflow-y: auto;
}
.charts-overlay.dock-right.open {
    right: 0;
    height: calc(100% - 84px);
}
.charts-overlay.dock-right:not(.open) {
    height: 0;
}

/* Small draggable resizer handle */
    .charts-overlay.dock-right .analytics-table {
         max-height: 100%;
    }
.charts-overlay .resizer {
    position: absolute;
    background: rgba(0,0,0,0.06);
    z-index: 1200;
}
.charts-overlay .resizer.horizontal {
    height: 8px;
    left: 0;
    right: 0;
    top: 0px;
    cursor: ns-resize;
}
.charts-overlay .resizer.vertical {
    width: 8px;
    top: 0;
    bottom: 0;
    left: 0px;
    cursor: ew-resize;
}

/* make the vertical resizer more visible and touch friendly */
.charts-overlay .resizer.vertical {
    background: linear-gradient(90deg, rgba(0,0,0,0.06), rgba(0,0,0,0.10));
}
.charts-overlay .resizer:hover { background: rgba(0,0,0,0.12); }
.charts-overlay .resizer { touch-action: none; }

/* When docked to right, charts content should stack vertically for better side layout */
.charts-overlay.dock-right .charts-content {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 12px;
}

.charts-overlay.dock-right .chart-container {
    height: 284px;
    flex: none;
}

/* Analytics table when docked to right should fill remaining area */
.charts-overlay.dock-right #analytics-table {
    height: calc(100% - 81px);
    overflow: auto;
}

/* Table row selected state for persistent selection */
.selected-row {
    background-color: #fff3bf !important; /* highlight color */
    transition: background-color 0.25s ease;
}

/* Marker selected highlight (outer ring) */
.selected-marker-ring {
    pointer-events: none;
}

/* Settings modal styling (centralized in main stylesheet) */
.settingsModal{
    display: none;
    position: fixed;
    top: 56px; /* below header */
    right: 22px;
    z-index: 20000;
    background: #fff;
    border: 1px solid #ddd;
    padding: 12px;
    box-shadow: 0 6px 18px rgba(0,0,0,0.12);
    border-radius: 6px;
    min-width: 220px;
}
.settingsModal.open { display: block; }
.settingsModal > div { display:flex; align-items:center; gap:12px; cursor:pointer; padding:10px 8px; border-radius:6px; }
.ettingsModal-item { display:flex; align-items:center; gap:12px; }
.settingsModal img { width:20px; height:20px; margin-right:8px; opacity:0.92 }

/* nicer separators instead of heavy hr */
.settingsModal hr { border: none; border-top: 1px solid rgba(16,24,32,0.06); margin:6px 0; }

/* hover and focus states */
.settingsModal > div:hover,
.settingsModal > div:focus {
    background: linear-gradient(180deg, rgba(1,111,108,0.06), rgba(1,111,108,0.03));
    outline: none;
}

/* pointer caret to tie modal to user button */
.settingsModal::before {
    content: '';
    position: absolute;
    top: -8px;
    right: 28px;
    width: 14px;
    height: 14px;
    background: inherit;
    transform: rotate(45deg);
    border-left: 1px solid rgba(0,0,0,0.06);
    border-top: 1px solid rgba(0,0,0,0.06);
}

/* improved typography */
.settingsModal { font-size: 14px; color: var(--accent-color); }
.settingsModal a { color: inherit; text-decoration: none; }
.settingsModal a:hover { text-decoration: underline; }

.settingsModal hr{
    margin-top: 0.2rem;
    margin-bottom: 0.2rem;
}

/* Improve contrast/readability for glass UI when satellite basemap (photography) is active */
body.satellite-basemap .filter-bar,
body.satellite-basemap .charts-overlay,
body.satellite-basemap .map-legend,

body.satellite-basemap .basemap-selector,
body.satellite-basemap .chart-info-card,
body.satellite-basemap .details-drawer {
    background: #dee2e6 !important; /* grey glass */
   
    border-color: rgba(255,255,255,0.08) !important;
    box-shadow: 0 18px 60px rgba(0,0,0,0.7) !important;
    backdrop-filter: blur(6px) saturate(120%) !important;
    -webkit-backdrop-filter: blur(6px) saturate(120%) !important;
}





/* Ensure settings modal icons remain visible */
body.satellite-basemap .settingsModal img { filter: brightness(0) invert(1); }

/* small tweak for map legend swatches over photography */
body.satellite-basemap .map-legend .legend-swatch { box-shadow: 0 1px 4px rgba(0,0,0,0.6); }

/* Loading overlay */
.loading-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.5);
    backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    border-radius: var(--border-radius);
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.loading-text {
    margin-top: 12px;
    font-size: 14px;
    color: var(--accent-color);
    font-weight: 500;
}

/* Drawer loading */
.drawer-loading {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    height: 200px;
}

/* Card */
.card-header.header {
    font-weight: bold;
    color: var(--primary-color);
}

/* Close button specifically inside the filter bar (top-right) */
.filter-bar #close-filter-bar {
    position: absolute;
    right: 12px;
    top: 8px;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--accent-color);
    cursor: pointer;
    z-index: 1200;
}
.filter-bar #close-filter-bar:hover { background: rgba(255,255,255,0.08); transform: translateY(-1px); }

/* Make analytics table rows indicate clickable/interactive behavior on hover */
.analytics-table tbody tr:hover { cursor: pointer; }

/* Ensure pointer is shown for DataTables generated rows as well */
#surveyPointsTable tbody tr:hover { cursor: pointer; }

/* ====================================== */
/* Train cluster custom styling (used by marker cluster iconCreateFunction) */
/* ====================================== */
.train-cluster {
    pointer-events: auto; /* ensure cluster is clickable */
}
.train-cluster-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    position: relative;
}
.train-cluster-icon svg {
    display: block;
    width: 18px;
    height: 18px;
    opacity: 0.95;
}
.train-cluster-count {
    position: relative;
    font-size: 10px;
    color: var(--primary-color);
}
.train-cluster-icon.small { width: 36px; height: 36px; }
.train-cluster-icon.medium { width: 46px; height: 46px; }
.train-cluster-icon.large { width: 60px; height: 60px; }