/* --- CHAT --- */
#chat-root {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: 500px;
    z-index: 1000;
}

/* --- THEME & COLOR VARIABLES --- */
:root {
    --bg-color: #e2e8f0;
    --panel-bg: rgba(150, 181, 212, 0.7);
    --accent-color: #319795;
    --text-primary: #2d3748;
    --text-secondary: #718096;
    --border-color: rgba(45, 55, 72, 0.2);
    --icon-fill: #2d3748;
    --header-bg: rgba(150, 181, 212, 0.4);
}

/* --- GLOBAL & TYPOGRAPHY --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
}

h1,
h2,
h4,
strong {
    font-weight: 600;
}

/* --- LAYOUT & MAP --- */
#map {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 100%;
    left: 0;
    transition: width 0.3s ease-in-out, left 0.3s ease-in-out;
}

body.sidebar-active #map {
    width: calc(100% - 320px);
    left: 320px;
}

header {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    padding: 15px 30px;
    z-index: 2;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--header-bg);
    backdrop-filter: blur(10px);
    transition: transform 0.3s ease-in-out, width 0.3s ease-in-out;
    pointer-events: none;
}

header>* {
    pointer-events: auto;
}

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

.logo svg {
    fill: var(--accent-color);
}

.logo h1 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

/* --- SIDEBAR --- */
#sidebar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 320px;
    transform: translateX(-320px);
    transition: transform 0.3s ease-in-out;
    z-index: 3;
}

body.sidebar-active #sidebar {
    transform: translateX(0);
}

#sidebar-toggle {
    position: absolute;
    top: 50%;
    left: 320px;
    transform: translateY(-50%);
    transition: transform 0.3s ease-in-out;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-left: none;
    cursor: pointer;
    width: 40px;
    height: 48px;
    border-radius: 0 8px 8px 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

body.sidebar-active #sidebar-toggle {
    transform: translateY(-50%) rotate(180deg);
}

#sidebar-content {
    width: 100%;
    height: 100%;
    padding: 20px;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border-color);
}

#sidebar-content h2 {
    margin-top: 60px;
    margin-bottom: 20px;
}

/* --- CONTROLS --- */
.control-group {
    margin-bottom: 25px;
    font-weight: 300;
}

.control-group label {
    color: var(--text-secondary);
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 4px;
    background: var(--text-secondary);
    border-radius: 5px;
    outline: none;
    margin-top: 10px;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--accent-color);
    cursor: pointer;
    border-radius: 50%;
    border: 3px solid #edf2f7;
}

select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 100%;
    padding: 8px 30px 8px 12px;
    margin-top: 5px;
    background-color: rgba(255, 255, 255, 0.4);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-family: 'Poppins', sans-serif;
    font-size: 0.9em;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='%232d3748'%3E%3Cpath d='M7 10l5 5 5-5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 1.2em;
}

select:focus {
    outline: none;
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(49, 151, 149, 0.2);
}

.checkbox-group {
    margin-top: 10px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    cursor: pointer;
    padding: 5px 0;
}

.checkbox-label input {
    display: none;
}

.checkbox-custom {
    width: 18px;
    height: 18px;
    border: 2px solid var(--text-secondary);
    border-radius: 4px;
    margin-right: 10px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.checkbox-custom::after {
    content: '✔';
    color: white;
    font-size: 12px;
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.2s;
}

.checkbox-label input:checked+.checkbox-custom {
    background-color: var(--accent-color);
    border-color: var(--accent-color);
}

.checkbox-label input:checked+.checkbox-custom::after {
    opacity: 1;
    transform: scale(1);
}

/* Accordion Styles */
.accordion-header {
    background-color: transparent;
    border: none;
    border-top: 1px solid var(--border-color);
    width: 100%;
    padding: 15px 5px;
    text-align: left;
    font-family: 'Poppins', sans-serif;
    font-size: 1.1em;
    font-weight: 600;
    color: var(--text-primary);
    cursor: pointer;
    position: relative;
    transition: background-color 0.2s;
}

#accordion-container>button:last-of-type {
    border-bottom: 1px solid var(--border-color);
}

.accordion-header:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.accordion-header::after {
    content: '\25B8';
    font-size: 0.8em;
    color: var(--text-secondary);
    position: absolute;
    right: 10px;
    transition: transform 0.3s ease;
}

.accordion-header.active::after {
    transform: rotate(90deg);
}

.accordion-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
    padding: 0 15px;
}

.accordion-panel.active {
    padding: 20px 15px;
    max-height: 500px;
}

/* --- LEGENDS & TOOLBAR --- */
.legend {
    position: absolute;
    bottom: 30px;
    left: 20px;
    transition: left 0.3s ease-in-out;
    /* Match sidebar animation */
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    padding: 15px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    z-index: 1001;
    min-width: 200px;
}

body.sidebar-active .legend {
    left: 350px;
    /* Sidebar width (320px) + margin (30px) */
}

.legend h4 {
    margin-bottom: 10px;
}

.legend-key {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 8px;
    vertical-align: middle;
    border-radius: 50%;
}

#flood-legend div:not(:last-child) {
    margin-bottom: 5px;
}

.svi-gradient,
.precip-gradient,
.forecast-gradient,
.gauge-height-gradient {
    height: 15px;
    width: 100%;
    border-radius: 3px;
    margin-bottom: 5px;
}

.svi-gradient {
    background: linear-gradient(to right, #4d9221, #f1b621, #c51b7d);
}

.precip-gradient {
    background: linear-gradient(to right, #ffffcc, #a1dab4, #41b6c4, #2c7fb8, #253494);
}

/* --- UPDATED ---: A more natural blue gradient for the forecast. */
.forecast-gradient {
    background: linear-gradient(to right, #edf8fb, #74a9cf, #023858);
}

/* River gauge water level gradient: green (low) -> yellow -> red -> purple (very high) */
.gauge-height-gradient {
    background: linear-gradient(to right, #2ecc71, #f1c40f, #e74c3c, #8e44ad);
}

.svi-labels,
.precip-labels,
.gauge-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.8em;
    color: var(--text-secondary);
}

#map-controls-toolbar {
    position: absolute;
    top: 80px;
    right: 30px;
    z-index: 2;
    display: flex;
    flex-direction: column;
    gap: 15px;
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
}

.map-control-button {
    background: transparent;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s;
    width: 40px;
    height: 40px;
}

.map-control-button:hover {
    background-color: rgba(49, 151, 149, 0.1);
}

.map-control-button svg,
#sidebar-toggle svg {
    fill: var(--icon-fill);
}

/* --- Push-aside rules --- */
body.sidebar-active header {
    transform: translateX(320px);
    width: calc(100% - 320px);
}

/* --- MAPBOX OVERRIDES --- */
.mapboxgl-popup {
    max-width: 240px;
    font-family: 'Poppins', sans-serif;
    z-index: 10;
}

.mapboxgl-popup-content {
    background: var(--panel-bg);
    backdrop-filter: blur(10px);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    padding: 10px 15px;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15);
}

.mapboxgl-popup-content h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px 0;
}

.mapboxgl-popup-content p {
    font-size: 0.9em;
    color: var(--text-secondary);
    margin: 0;
}

.mapboxgl-popup-anchor-bottom .mapboxgl-popup-tip {
    border-top-color: var(--border-color);
}

.mapboxgl-popup-anchor-top .mapboxgl-popup-tip {
    border-bottom-color: var(--border-color);
}

.mapboxgl-popup-anchor-left .mapboxgl-popup-tip {
    border-right-color: var(--border-color);
}

.mapboxgl-popup-anchor-right .mapboxgl-popup-tip {
    border-left-color: var(--border-color);
}

/* --- MODAL STYLES --- */
.hidden {
    display: none !important;
}

/* Positions the main modal container in the top-left corner.
  Adjust top/left/width values as needed.
*/
#modal {
    /* Positioning (existing) */
    position: absolute;
    top: 70px;
    left: 30px;
    width: 350px;
    max-width: 90vw;
    right: auto;
    bottom: auto;
    transform: none;
    transition: left 0.3s ease-in-out;
    z-index: 2;

    /* --- VIBRANT, COLORFUL STYLE --- */
    background: linear-gradient(135deg, rgba(230, 245, 255, 0.85), rgba(200, 225, 255, 0.9));
    /* Light blue gradient */
    backdrop-filter: blur(14px);
    /* Slightly stronger blur */
    /* border: 2px solid #007BFF; Bright blue border */
    border-radius: 16px;
    /* Softer corners */
    box-shadow: 0 8px 25px rgba(0, 123, 255, 0.3), 0 4px 10px rgba(0, 0, 0, 0.1);
    /* Enhanced shadow with color */
    color: #1A202C;
    /* Darker text for better contrast */
}

/* --- ADD THIS NEW RULE --- */
/* This moves the modal to the right when the sidebar is open */
body.sidebar-active #modal {
    left: 350px;
    /* 320px (sidebar width) + 30px (margin) */
}

#modal-content {
    max-height: 450px;
    overflow-y: auto;
    padding: 20px;
    padding-top: 15px;
}

/* Custom scrollbar for modal content */
#modal-content::-webkit-scrollbar {
    width: 6px;
}

#modal-content::-webkit-scrollbar-track {
    background: transparent;
}

#modal-content::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

#modal-content::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

#modal-close-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    background: transparent;
    border: none;
    font-size: 1.5rem;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    line-height: 1;
}

#modal-close-btn:hover {
    color: var(--text-primary);
    background-color: rgba(0, 0, 0, 0.08);
}

#modal-content h3 {
    font-size: 1.2rem;
    font-weight: 800;
    color: #2d3748;
    margin-bottom: 8px;
}

#modal-content h4 {
    font-size: 0.75rem;
    font-weight: 700;
    color: #2d3748;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    margin-bottom: 10px;
    margin-top: 24px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
}

#modal-content .location {
    color: var(--text-secondary);
    font-size: 0.9em;
    margin-top: -5px;
    margin-bottom: 15px;
}

#modal-content p {
    margin-bottom: 10px;
    color: var(--text-secondary);
}

#modal-content strong {
    color: var(--text-primary);
}

.modal-visualizer {
    margin-bottom: 15px;
    margin-top: 5px;
}

.modal-gradient-bar {
    position: relative;
    width: 100%;
    height: 8px;
    border-radius: 4px;
}

.gradient-marker {
    position: absolute;
    top: -4px;
    width: 16px;
    height: 16px;
    background-color: white;
    border: 2px solid var(--accent-color);
    border-radius: 50%;
    transform: translateX(-50%);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.modal-labels {
    font-size: 0.75em;
    display: flex;
    justify-content: space-between;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Updated table styles for the modal */
.modal-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 0.85em;
}

.modal-table th,
.modal-table td {
    border-bottom: 1px solid var(--border-color);
    padding: 10px 4px;
    text-align: left;
    vertical-align: top;
}

.modal-table thead tr {
    background-color: transparent;
}

.modal-table th {
    color: var(--text-secondary);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.9em;
    padding-bottom: 6px;
}

.modal-table td:first-child {
    font-weight: 500;
    color: var(--text-primary);
    width: 40%;
}

.modal-table td {
    color: var(--text-secondary);
}

.modal-table td b {
    color: var(--text-primary);
    font-weight: 800;
}

.modal-table tr:last-child td {
    border-bottom: none;
}