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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    height: 100vh;
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100vh;
    z-index: 1;
}

/* Start below Tethys's fixed 50px app header, which otherwise covers the
   sidebar's title and close button. */
.sidebar {
    position: fixed;
    top: 50px;
    right: -400px;
    width: 400px;
    height: calc(100vh - 50px);
    background: white;
    box-shadow: -2px 0 10px rgba(0,0,0,0.1);
    transition: right 0.3s ease;
    z-index: 1000;
    overflow-y: auto;
    padding: 20px;
}

.sidebar.open {
    right: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #e0e0e0;
}

.sidebar-header h2 {
    color: #2c3e50;
    font-size: 24px;
}

.close-btn {
    background: #e74c3c;
    color: white;
    border: none;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.close-btn:hover {
    background: #c0392b;
}

.info-section {
    margin-bottom: 25px;
}

.info-section h3 {
    color: #34495e;
    font-size: 16px;
    margin-bottom: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.info-item {
    display: flex;
    justify-content: space-between;
    padding: 12px;
    margin-bottom: 8px;
    background: #f8f9fa;
    border-radius: 6px;
    border-left: 4px solid #3498db;
}

.info-label {
    font-weight: 600;
    color: #555;
}

.info-value {
    color: #2c3e50;
    text-align: right;
    max-width: 60%;
    word-wrap: break-word;
}

.sidebar-attribution {
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
}

.sidebar-attribution-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #7f8c8d;
    margin-bottom: 4px;
    line-height: 1.35;
}

.sidebar-attribution-sub {
    font-size: 11px;
    color: #95a5a6;
    margin-bottom: 14px;
    line-height: 1.4;
}

/*
 * Partner marks use background-image on fixed-ratio tiles (not <img>),
 * so huge source files never blow up layout — BYU and CIROH always share one grid row.
 */
.sidebar-attribution-logos.partners-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 150px;
    margin: 0 auto;
}

.partners-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
}

.partners-cell {
    aspect-ratio: 1 / 1;
    width: 100%;
    min-height: 0;
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.partners-wide {
    width: 100%;
    height: 42px;
    background-color: transparent;
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
}

.huc8-code {
    font-size: 28px;
    font-weight: bold;
    color: #2980b9;
    text-align: center;
    padding: 15px;
    background: #ecf0f1;
    border-radius: 8px;
    margin-bottom: 20px;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

.loading-spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #3498db;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 20px auto;
}

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

.no-selection {
    text-align: center;
    padding: 60px 20px;
    color: #95a5a6;
}

.no-selection svg {
    width: 80px;
    height: 80px;
    margin-bottom: 20px;
    opacity: 0.3;
}

/* Custom popup styles */
.leaflet-popup-content-wrapper {
    border-radius: 8px;
}

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

.popup-title {
    font-weight: bold;
    font-size: 16px;
    color: #2980b9;
    margin-bottom: 8px;
}

.popup-info {
    font-size: 14px;
    color: #555;
    margin: 4px 0;
}

.popup-click {
    margin-top: 10px;
    font-size: 12px;
    color: #7f8c8d;
    font-style: italic;
}

/*
 * Smooth interpolation when Leaflet scales the preview PNG (so flood edges look softer).
 * Pane class: createPane('floodOverlayPane') → leaflet-floodOverlayPane-pane.
 */
.leaflet-pane.leaflet-floodOverlayPane-pane img,
img.flood-raster-crisp.leaflet-image-layer {
    image-rendering: auto;
    -ms-interpolation-mode: bicubic;
    opacity: 1 !important;
    transform: translateZ(0);
}

.flood-streamflow-marker {
    background: transparent !important;
    border: none !important;
}

/* Labels must stack above the flood raster (pane z-index set in JS). */
.leaflet-floodLabelsPane-pane {
    overflow: visible !important;
    pointer-events: none !important;
}

.flood-streamflow-marker-inner {
    position: relative;
    left: 0;
    top: 0;
    display: inline-block;
    box-sizing: border-box;
    white-space: nowrap;
    padding: 7px 12px;
    font-size: 14px;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: -0.02em;
    color: #0d1b2a;
    background: #ffffff;
    background-clip: padding-box;
    border: 2px solid #0d47a1;
    border-radius: 8px;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.9) inset,
        0 2px 10px rgba(0, 0, 0, 0.35),
        0 1px 3px rgba(0, 0, 0, 0.2);
    pointer-events: none;
}

.leaflet-floodLabelsPane-pane .leaflet-marker-icon {
    margin-left: 0 !important;
    margin-top: 0 !important;
    overflow: visible !important;
}

#flood-legend {
    pointer-events: auto;
}

.flood-legend-toggle-wrap {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e8eaed;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    pointer-events: auto;
}

.flood-legend-toggle-wrap .flood-toggle-label {
    font-size: 12px;
    color: #444;
    line-height: 1.3;
    flex: 1;
    min-width: 0;
}

.flood-toggle-switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 26px;
    flex-shrink: 0;
}

.flood-toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.flood-toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #cfd8dc;
    border-radius: 26px;
    transition: background 0.2s;
}

.flood-toggle-slider::before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
    transition: transform 0.2s;
}

.flood-toggle-switch input:checked + .flood-toggle-slider {
    background: #2980b9;
}

.flood-toggle-switch input:checked + .flood-toggle-slider::before {
    transform: translateX(18px);
}

.flood-toggle-switch input:focus-visible + .flood-toggle-slider {
    outline: 2px solid #3498db;
    outline-offset: 2px;
}

/* Full-screen progress while NWM flood map is generating */
.flood-generate-overlay {
    position: fixed;
    inset: 0;
    z-index: 2500;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(2px);
}

.flood-generate-overlay.flood-generate-overlay--visible {
    display: flex;
}

.flood-generate-modal {
    position: relative;
    background: #fff;
    padding: 28px 32px 32px;
    border-radius: 14px;
    max-width: 440px;
    width: 92%;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.22);
    text-align: center;
}

.flood-generate-modal-title {
    font-size: 18px;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 6px;
}

.flood-generate-modal-sub {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 18px;
}

.flood-generate-modal-msg {
    font-size: 15px;
    font-weight: 600;
    color: #0f172a;
    line-height: 1.5;
    margin-top: 16px;
    min-height: 2.8em;
}

.flood-generate-spinner {
    width: 44px;
    height: 44px;
    margin: 8px auto 0;
}

.flood-generate-cancel-text {
    margin-top: 18px;
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 600;
    color: #c0392b;
    background: #fff;
    border: 2px solid rgba(192, 57, 43, 0.45);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.flood-generate-cancel-text:hover {
    background: #fef2f2;
    border-color: #c0392b;
    color: #a93226;
}

/* Celebration-style success after flood map generation */
.flood-success-overlay {
    position: fixed;
    inset: 0;
    z-index: 2600;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
}

.flood-success-overlay.flood-success-overlay--visible {
    display: flex;
    animation: floodSuccessFadeIn 0.35s ease-out;
}

@keyframes floodSuccessFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes floodSuccessPop {
    0% { opacity: 0; transform: scale(0.92) translateY(12px); }
    70% { opacity: 1; transform: scale(1.02) translateY(0); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

.flood-success-card {
    position: relative;
    max-width: 420px;
    width: 100%;
    padding: 32px 28px 28px;
    border-radius: 20px;
    text-align: center;
    background: linear-gradient(145deg, #ffffff 0%, #f0f9ff 45%, #e0f2fe 100%);
    border: 1px solid rgba(14, 165, 233, 0.35);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.8) inset,
        0 24px 56px rgba(2, 132, 199, 0.18),
        0 8px 24px rgba(15, 23, 42, 0.12);
    animation: floodSuccessPop 0.45s cubic-bezier(0.34, 1.3, 0.64, 1) both;
}

.flood-success-close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 10;
    width: 40px;
    height: 40px;
    border: 2px solid rgba(15, 23, 42, 0.18);
    border-radius: 50%;
    background: #fff;
    color: #1e293b;
    font-size: 26px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
    transition: background 0.2s, color 0.2s, border-color 0.2s, transform 0.15s;
}

.flood-success-close:hover {
    background: #f1f5f9;
    color: #0f172a;
    border-color: rgba(14, 165, 233, 0.45);
}

.flood-success-close:active {
    transform: scale(0.94);
}

.flood-success-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: conic-gradient(from 200deg, #0ea5e9, #38bdf8, #7dd3fc, #0ea5e9);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    box-shadow: 0 8px 24px rgba(14, 165, 233, 0.35);
}

.flood-success-icon-inner {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 30px;
}

.flood-success-heading {
    font-size: 22px;
    font-weight: 800;
    color: #0c4a6e;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
    line-height: 1.25;
}

.flood-success-tagline {
    font-size: 14px;
    color: #0369a1;
    font-weight: 600;
    margin-bottom: 14px;
}

.flood-success-detail {
    font-size: 13px;
    color: #475569;
    line-height: 1.55;
    text-align: left;
    background: rgba(255, 255, 255, 0.75);
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 20px;
    border: 1px solid rgba(148, 163, 184, 0.35);
}

.flood-success-detail strong {
    color: #1e293b;
}

.flood-success-ok {
    width: 100%;
    max-width: 220px;
    padding: 12px 20px;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    border: none;
    border-radius: 999px;
    cursor: pointer;
    background: linear-gradient(135deg, #0284c7 0%, #0ea5e9 50%, #38bdf8 100%);
    box-shadow: 0 4px 14px rgba(2, 132, 199, 0.45);
    transition: transform 0.15s, box-shadow 0.2s;
}

.flood-success-ok:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(2, 132, 199, 0.5);
}

.flood-success-ok:active {
    transform: translateY(0);
}

/* ---- Hydrograph panel (issue #25) ------------------------------------- */
.hydrograph-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
    flex-wrap: wrap;
}

.hydrograph-ctl {
    font-size: 12px;
    font-weight: 600;
    color: #555;
    display: flex;
    align-items: center;
    gap: 6px;
}

.hydrograph-ctl select {
    font-size: 12px;
    padding: 4px 6px;
    border: 1px solid #ddd;
    border-radius: 4px;
    background: #fff;
    color: #2c3e50;
}

.hydrograph-rp-ctl {
    gap: 4px;
    cursor: pointer;
}

.hydrograph-rp-ctl input {
    margin: 0;
    cursor: pointer;
}

/* Segmented control: the active unit is shown filled, so the current state is
   readable at a glance rather than inferred from a "switch to..." label. */
.hydrograph-units {
    display: inline-flex;
    border: 1px solid #ddd;
    border-radius: 4px;
    overflow: hidden;
}

.hydrograph-unit-btn {
    font-size: 12px;
    padding: 4px 9px;
    border: none;
    background: #fff;
    color: #7f8c8d;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.hydrograph-unit-btn + .hydrograph-unit-btn {
    border-left: 1px solid #ddd;
}

.hydrograph-unit-btn:hover:not(.is-active) {
    background: #f1f3f5;
}

.hydrograph-unit-btn.is-active {
    background: #2980b9;
    color: #fff;
    font-weight: 600;
}

.hydrograph-panel {
    background: #f8f9fa;
    border-radius: 6px;
    padding: 10px;
}

/* width:100% is why the click handler converts through getScreenCTM() rather
   than trusting offsetX -- the SVG is scaled to whatever the sidebar allows. */
.hydrograph-panel svg {
    width: 100%;
    height: auto;
    display: block;
    background: #fff;
    border: 1px solid #e3e6e8;
    border-radius: 4px;
    cursor: crosshair;
}

/* The plot takes keyboard focus so arrow keys can step between samples; make
   that state obvious, since otherwise there is no clue the keys will do anything. */
.hydrograph-panel svg:focus-visible {
    outline: 2px solid #2980b9;
    outline-offset: 1px;
}

.hydrograph-panel svg:focus {
    border-color: #2980b9;
}

.hydrograph-note {
    font-size: 11px;
    color: #7f8c8d;
    line-height: 1.35;
    margin: 8px 0 0;
}

.hydrograph-error {
    color: #c0392b;
}

.hydrograph-btn {
    width: 100%;
    padding: 10px;
    margin-top: 10px;
    /* Same blue as the "Show on map" button — both reveal something for the
       selected watershed, so they read as a pair. */
    background: #3498db;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.hydrograph-btn:hover:not(:disabled) {
    background: #2980b9;
}

.hydrograph-btn:disabled {
    background: #b2bec3;
    cursor: default;
}

/* ---- Retrospective / Forecast / Return Period tabs (issue #31) --------- */
.mode-tabs {
    display: flex;
    margin: -5px 0 18px;
    border: 1px solid #d6dde3;
    border-radius: 8px;
    overflow: hidden;
}

.mode-tab {
    flex: 1;
    padding: 9px 10px;
    border: none;
    background: #f4f6f8;
    color: #5d6d7e;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.mode-tab + .mode-tab {
    border-left: 1px solid #d6dde3;
}

.mode-tab:hover:not(.is-active) {
    background: #eaeef1;
}

.mode-tab.is-active {
    background: #2980b9;
    color: #fff;
}

/* Amber marks everything forecast, so it is never mistaken for the archive. */
.mode-tab[data-mode="forecast"].is-active {
    background: #d35400;
}

/* Teal for return periods: a design flood, apart from the archive's blue and
   the forecast's amber. */
.mode-tab[data-mode="rp"].is-active {
    background: #138d75;
}

.mode-tab:focus-visible {
    outline: 2px solid #2c3e50;
    outline-offset: -2px;
}

/* ---- Forecast page ------------------------------------------------------ */
.forecast-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 7px;
    border-radius: 10px;
    background: #fdebd0;
    color: #a04000;
    font-size: 10px;
    letter-spacing: 0.6px;
    vertical-align: middle;
}

.forecast-panel {
    padding: 15px;
    background: #fff8f0;
    border: 1px solid #f5d5b5;
    border-radius: 8px;
    margin-top: 10px;
}

.forecast-cycle {
    font-size: 13px;
    color: #2c3e50;
    line-height: 1.4;
    margin-bottom: 12px;
}

.forecast-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
}

.forecast-select {
    width: 100%;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    background: #fff;
    color: #2c3e50;
}

.forecast-hint {
    font-size: 11px;
    color: #7f8c8d;
    line-height: 1.35;
    margin-top: 4px;
}

.forecast-warn {
    color: #a04000;
}

/* Same sizes and colours as the retrospective page's buttons. */
.forecast-btn {
    width: 100%;
    padding: 10px;
    margin-top: 10px;
    border: none;
    border-radius: 6px;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.forecast-btn--generate {
    background: #27ae60;
    padding: 12px;
    margin-top: 15px;
    font-size: 16px;
}

.forecast-btn--download {
    background: #2980b9;
}

.forecast-btn--show {
    background: #3498db;
}

.forecast-btn:disabled {
    background: #b2bec3;
    cursor: default;
}

.forecast-status {
    margin-top: 10px;
    font-size: 12px;
    color: #7f8c8d;
}

.flood-legend-source {
    margin: 0 0 6px;
    max-width: 240px;
    font-size: 11px;
    line-height: 1.35;
    color: #a04000;
}

/* ---- Hydrograph outlet link ------------------------------------------- */
/* The reach ID in a hydrograph note pans the map to the outlet marker, so it
   reads as a link in the note's own size, not as another button. */
.hydrograph-outlet-link {
    padding: 0;
    border: none;
    background: none;
    font: inherit;
    color: #2980b9;
    text-decoration: underline;
    cursor: pointer;
}

.hydrograph-outlet-link:hover {
    color: #1f6391;
}

/* The outlet's tooltip shares a pane with its marker, and Leaflet stacks a
   pane's SVG at z-index 200; lift the tooltip over the marker it labels.
   Leaflet drops "Pane" from the pane's name in its class, hence
   .leaflet-hydroOutlet-pane for the pane created as 'hydroOutletPane'. */
.leaflet-hydroOutlet-pane .leaflet-tooltip {
    z-index: 300;
}

/* A clicked NWM reach: a purple diamond, apart from the orange outlet circle.
   The diamond is the inner span, since Leaflet positions the icon itself with
   a transform. */
.reach-marker span {
    display: block;
    width: 10px;
    height: 10px;
    background: #8e44ad;
    border: 2px solid #fff;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.6);
    transform: rotate(45deg);
}

.reach-popup .hydrograph-panel {
    padding: 6px;
    margin-top: 8px;
}

/* A picture in the popup, not the sidebar's clickable plot. */
.reach-popup .hydrograph-panel svg {
    cursor: default;
}

.reach-popup-remove {
    margin-top: 6px;
    padding: 0;
    border: none;
    background: none;
    color: #7f8c8d;
    font-size: 11px;
    text-decoration: underline;
    cursor: pointer;
}

/* ---- Return Period page ------------------------------------------------- */
.rp-panel {
    padding: 15px;
    background: #f0faf7;
    border: 1px solid #bfe6dc;
    border-radius: 8px;
    margin-top: 10px;
}

.rp-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border: 1px solid #e3e6e8;
    border-radius: 4px;
    font-size: 12px;
    color: #2c3e50;
}

.rp-table th,
.rp-table td {
    padding: 5px 8px;
    text-align: left;
    border-bottom: 1px solid #eef0f2;
}

.rp-table th {
    font-weight: 600;
    color: #5d6d7e;
    background: #f4f6f8;
}

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

/* A period, its swatch and its "ready" badge stay on one line. */
.rp-table td:first-child {
    white-space: nowrap;
}

.rp-table .rp-flow {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.rp-table tr.is-pickable {
    cursor: pointer;
}

.rp-table tr.is-pickable:hover td {
    background: #f4f6f8;
}

.rp-table tr.is-pickable:focus-visible {
    outline: 2px solid #138d75;
    outline-offset: -2px;
}

.rp-table tr.is-selected td {
    background: #e3f4ef;
    font-weight: 600;
}

.rp-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 6px;
    border-radius: 2px;
    vertical-align: -1px;
}

/* The period picker: the label and the unit toggle share a line above it. */
.rp-picker-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.rp-picker-head .forecast-label {
    margin-bottom: 0;
}

/* A radio dot per row, so the rows read as choices rather than data. */
.rp-radio {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-right: 7px;
    border: 2px solid #9aa7b1;
    border-radius: 50%;
    vertical-align: -2px;
    box-sizing: border-box;
}

.rp-table tr.is-selected .rp-radio {
    border-color: #138d75;
    background: radial-gradient(circle, #138d75 0 3px, #fff 3.5px);
}

.rp-ready {
    display: inline-block;
    margin-left: 4px;
    padding: 1px 6px;
    border-radius: 8px;
    background: #d4efe7;
    color: #0e6655;
    font-size: 10px;
    font-weight: 600;
    vertical-align: 1px;
}
