* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }

/* map takes the upper ~3/4, chat the lower ~1/4 (full width) */
:root { --chat-h: 25%; }
#map { position: absolute; top: 0; left: 0; right: 0; bottom: var(--chat-h); z-index: 0; background: #0b0f14; }

#topbar {
  position: absolute; top: 0; left: 0; right: 0; height: 42px; z-index: 700;
  display: flex; align-items: center; gap: 10px; padding: 0 14px;
  background: linear-gradient(180deg, rgba(11,15,20,.92), rgba(11,15,20,.55));
  color: #e8eef4;
}
#topbar .brand { font-weight: 700; }
#topbar .sub { color: #8fa3b3; font-size: 13px; }
#topbar .selinfo { margin-left: auto; color: #ffd479; font-size: 13px; }
.tb-btn {
  border: 1px solid #2a3a49; background: #142230; color: #cfe0ee; border-radius: 16px;
  padding: 4px 12px; font-size: 12px; cursor: pointer; text-decoration: none; display: inline-flex;
  align-items: center; gap: 6px;
}
.tb-btn.on { border-color: #4cc9a0; color: #9fdcc0; }
/* mode switch: as prominent as the Model-options panel header */
#mode-seg { display: flex; border: 1px solid #2a3a49; border-radius: 10px; overflow: hidden; }
#mode-seg .seg {
  border: none; background: #142230; color: #8fa3b3; cursor: pointer;
  padding: 9px 18px; font-size: 15px; font-weight: 600;
}
#mode-seg .seg.on { background: #1b2a3a; color: #ffd479; }
#mode-seg #mode-now.on { background: #3a2413; color: #ff9f43; }
/* Nowcast rain-radar control — stacked above the risk legend (bottom-left).
   The gradient MIRRORS RAIN_X/R/G/B in scripts/update_mrms_recent.py. */
#mrms-ctl {
  position: absolute; left: 12px; bottom: calc(var(--chat-h) + 148px); z-index: 640;
  background: rgba(17,23,31,.92); border: 1px solid #223; border-radius: 8px;
  color: #cfe0ee; font-size: 12px; padding: 7px 11px; width: 196px;
}
#mrms-ctl .m-title { font-size: 11px; color: #8fa3b3; margin-bottom: 5px; }
#mrms-ctl .m-sub { opacity: .75; }
#mrms-ctl .m-btns { display: flex; gap: 4px; }
#mrms-ctl .m-btns button {
  flex: 1; background: #1b2a3a; color: #cfe0ee; border: 1px solid #33475e;
  border-radius: 6px; padding: 3px 0; font-size: 11px; cursor: pointer;
}
#mrms-ctl .m-btns button.on { background: #14432e; color: #7fd4a0; border-color: #2a6f4e; }
#mrms-ctl .m-scale { margin-top: 6px; }
#mrms-ctl .m-bar { height: 8px; border-radius: 4px;
  background: linear-gradient(90deg, #96d296 0%, #3caa3c 17%, #ffdc00 33%,
    #ff9600 50%, #e6281e 67%, #b4148c 83%, #780078 100%); }
#mrms-ctl .m-ticks { display: flex; justify-content: space-between;
  font-size: 9px; color: #8fa3b3; margin-top: 2px; font-variant-numeric: tabular-nums; }
#mrms-ctl .m-note { font-size: 10px; color: #8fa3b3; margin-top: 2px; }
body.font-lg #mrms-ctl { zoom: 1.18; }
body.font-xl #mrms-ctl { zoom: 1.4; }

/* nowcast flood-risk legend (bottom-left, above Leaflet attribution) */
#risk-legend {
  position: absolute; left: 12px; bottom: calc(var(--chat-h) + 46px); z-index: 640;
  background: rgba(17,23,31,.92); border: 1px solid #4a2020; border-radius: 8px;
  color: #f0d9d4; font-size: 12.5px; padding: 7px 11px;
}
#risk-legend .dot-red, #risk-legend .dot-orange, #risk-legend .dot-yellow {
  display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  margin-right: 4px;
}
#risk-legend .dot-red { background: #ff4030; box-shadow: 0 0 8px #ff4030; }
#risk-legend .dot-orange { background: #ff7a00; box-shadow: 0 0 6px #ff7a00; }
#risk-legend .dot-yellow { background: #ffb300; box-shadow: 0 0 6px #ffb300; }
#risk-legend .risk-rows { display: flex; flex-direction: column; gap: 2px; }
#risk-legend #risk-count { color: #8fa3b3; display: block; margin-top: 4px; }
/* gauge-tab close (unselect) button */
.rp-tab .x { margin-left: 7px; color: #8fa3b3; font-weight: 400; }
.rp-tab .x:hover { color: #ff6b6b; }
#auth img { width: 22px; height: 22px; border-radius: 50%; }

.panel {
  position: absolute; top: 52px; z-index: 600; width: 300px;
  max-height: calc(100% - var(--chat-h) - 70px);
  background: rgba(17,23,31,.94); color: #e8eef4; border: 1px solid #223; border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,.45); display: flex; flex-direction: column; overflow: hidden;
}
#left-panel { left: 12px; }
/* narrower bottom reach leaves the bottom-right Leaflet layers control uncovered */
#right-panel { right: 12px; width: 380px; max-height: calc(100% - var(--chat-h) - 118px); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 12px; font-weight: 600; border-bottom: 1px solid #223; background: rgba(255,255,255,.03);
}
.panel-body { padding: 12px; overflow: auto; }
.panel.collapsed .panel-body, .panel.collapsed #rp-tabs { display: none; }
.panel.hidden { display: none; }
.panel-head .toggle, .panel-head .close { background: none; border: none; color: #8fa3b3; cursor: pointer; font-size: 15px; }

/* chip to bring the results panel back after the ✕ closes it */
#rp-reopen {
  position: absolute; top: 52px; right: 12px; z-index: 601;
  border: 1px solid #3a5a7a; background: rgba(27,42,58,.96); color: #ffd479;
  border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer;
  box-shadow: 0 6px 24px rgba(0,0,0,.45);
}
#rp-reopen:hover { background: #24425c; }

/* right-panel gauge tabs */
#rp-tabs { display: flex; gap: 4px; padding: 6px 8px 0; flex-wrap: wrap; border-bottom: 1px solid #223; }
#rp-tabs:empty { display: none; }
.rp-tab {
  border: 1px solid #2a3a49; border-bottom: none; background: #0d141c; color: #a9bccd;
  border-radius: 7px 7px 0 0; padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.rp-tab.active { background: #1b2a3a; color: #ffd479; border-color: #3a5a7a; font-weight: 600; }
.rp-tab .dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px;
  background: #8fa3b3; vertical-align: 1px; }
.rp-tab.running .dot { background: #ffd479; animation: pulse 1.2s infinite; }
.rp-tab.done .dot { background: #4cc9a0; }
@keyframes pulse { 50% { opacity: .35; } }

label { display: block; font-size: 12px; color: #a9bccd; margin: 8px 0 2px; }
label.chk { display: flex; align-items: center; gap: 6px; margin-top: 12px; color: #e8eef4; }
input, select, textarea { width: 100%; padding: 6px 8px; background: #0d141c; color: #e8eef4;
  border: 1px solid #2a3a49; border-radius: 6px; font-size: 13px; font-family: inherit; }
label.chk input { width: auto; }
.hidden { display: none !important; }

#btn-feedback { white-space: nowrap; }

/* display size — scales everything except the top bar (and the map itself) */
body.font-lg #chat, body.font-lg .panel, body.font-lg .modal-card,
body.font-lg #anim, body.font-lg #q-legend { zoom: 1.18; }
body.font-xl #chat, body.font-xl .panel, body.font-xl .modal-card,
body.font-xl #anim, body.font-xl #q-legend { zoom: 1.4; }

/* parameters that don't apply to the chosen model / snow setting */
.adv-grid label.off { opacity: 0.32; }
.adv-grid label.off input { cursor: not-allowed; }
.adv-group.off { opacity: 0.32; }
.k-step-row { display: flex; gap: 6px; }
.k-step-row input { width: 64px; }
#feedback-modal textarea { resize: vertical; }

/* PDF report download (right panel report header) */
.rp-dl { float: right; padding: 3px 10px; border: 1px solid #2a3a49; background: #142230;
  color: #e8eef4; border-radius: 6px; cursor: pointer; font-size: 11.5px; }
.rp-dl:hover:not(:disabled) { background: #1b3040; }
.rp-dl:disabled { opacity: 0.6; cursor: wait; }

/* focused basins (favorites): gold star map pins + panel/profile controls */
.fav-pin { color: #ffd23f; font-size: 19px; line-height: 22px; text-align: center;
  text-shadow: 0 0 3px #000, 0 1px 2px rgba(0,0,0,.9); cursor: pointer; }
.fav-btn { background: none; border: none; color: #8fa3b3; cursor: pointer;
  font-size: 17px; line-height: 1; padding: 0 2px; margin-left: auto; }
.fav-btn.on { color: #ffd23f; }
.fav-btn.hidden { display: none; }
.fav-add { display: flex; gap: 6px; margin-top: 8px; }
.fav-add input { flex: 1; }
.fav-add button { padding: 5px 14px; border: 1px solid #2a3a49; background: #142230;
  color: #e8eef4; border-radius: 6px; cursor: pointer; font-size: 12px; }
.fav-add button:hover { background: #1b3040; }
.fav-del { padding: 5px 8px; }

/* simulation history (profile modal) */
.hist-row { display: flex; align-items: center; gap: 10px; padding: 7px 0;
  border-bottom: 1px solid #1d2936; }
.hist-info { flex: 1; font-size: 12.5px; line-height: 1.45; }
.hist-load { padding: 5px 12px; border: 1px solid #2a3a49; background: #142230;
  color: #e8eef4; border-radius: 6px; cursor: pointer; font-size: 12px; white-space: nowrap; }
.hist-load:hover { background: #1b3040; }

/* manual time override (Set / Clear) */
.k-time { border: 1px solid #223140; border-radius: 8px; padding: 8px; margin-bottom: 10px; }
.k-time label:first-child { margin-top: 0; }
.k-time-btns { display: flex; align-items: center; gap: 8px; margin-top: 4px; }
.k-time-btns button { width: auto; padding: 5px 14px; border: 1px solid #2a3a49; background: #142230;
  color: #e8eef4; border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.k-time-btns button.primary { background: #3a6ea5; border-color: #3a6ea5; font-weight: 600; }
#k-time-state { color: #ffd479; margin: 0; }

/* advanced parameters accordion */
.adv { margin-top: 14px; border-top: 1px solid #223; padding-top: 8px; }
.adv-head { cursor: pointer; font-weight: 600; font-size: 13px; color: #7fd4b0; user-select: none; }
.adv-head:hover { color: #a8f0d0; }
#adv-arrow { display: inline-block; width: 12px; }
.adv-note { font-size: 11px; color: #8fa3b3; margin: 6px 0 4px; }
.adv-group { margin-top: 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: #ffd479; font-weight: 600; }
.adv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 8px; margin-top: 4px; }
.adv-grid label { margin: 0; font-size: 11px; color: #a9bccd; }
.adv-grid input { padding: 4px 6px; font-size: 12px; }

#right-panel .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
#right-panel .stat { background: #0d141c; border: 1px solid #223; border-radius: 6px; padding: 6px 8px; }
#right-panel .stat .k { font-size: 11px; color: #8fa3b3; }
#right-panel .stat .v { font-size: 15px; font-weight: 600; }
#right-panel .plot { height: 260px; }
/* expand-to-modal affordance on the small hydrograph */
.plot-wrap { position: relative; }
.plot-expand { position: absolute; top: 2px; right: 2px; z-index: 8;
  background: rgba(13,20,28,.85); border: 1px solid #2a3a49; border-radius: 6px;
  color: #9fc3dd; font-size: 14px; line-height: 1; padding: 4px 7px; cursor: pointer; }
.plot-expand:hover { color: #fff; border-color: #4cc9a0; }
.plot-tz { right: 32px; font-size: 10px; font-weight: 600; padding: 5px 7px; }
.hm-zoom button.hm-tz { width: auto; padding: 0 8px; font-size: 11px; font-weight: 600; }
/* clicked-timestep readout (small panel + modal share the style) */
.readout { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 2px; }
.readout .ro { background: #0d141c; border: 1px solid #223; border-radius: 6px;
  padding: 4px 8px; font-size: 11px; color: #8fa3b3; }
.readout .ro b { display: block; font-size: 13px; color: #e8eef4; font-weight: 600; }
.readout .ro.t { border-color: #4cc9a0; color: #7fd4b0; }
/* enlarged hydrograph modal (double class: must beat .modal-card's 420px,
   which is defined later in this file) */
.modal-card.hydro-card { width: min(1320px, 96vw); }
#hm-scroll { overflow: auto; max-height: 64vh; margin: 6px 10px 0; }
#hm-scroll::-webkit-scrollbar { width: 10px; height: 10px; }
#hm-scroll::-webkit-scrollbar-thumb { background: #2a3a49; border-radius: 5px; }
#hm-scroll::-webkit-scrollbar-track { background: #0d141c; }
#hm-plot { width: 100%; height: min(56vh, 520px); }   /* JS overrides when zoomed */
.hm-zoom { display: flex; align-items: center; gap: 6px; margin-left: auto; margin-right: 12px; }
.hm-zoom button { width: 26px; height: 26px; border-radius: 6px; border: 1px solid #2a3a49;
  background: #0d141c; color: #9fc3dd; font-size: 15px; line-height: 1; cursor: pointer; }
.hm-zoom button:hover:not(:disabled) { color: #fff; border-color: #4cc9a0; }
.hm-zoom button:disabled { opacity: .35; cursor: default; }
#hm-zlvl { font-size: 11px; color: #8fa3b3; min-width: 38px; text-align: center;
  font-variant-numeric: tabular-nums; }
#hm-readout { padding: 0 16px; }
.hm-hint { padding: 6px 16px 12px; margin: 0; }
#right-panel .report { margin-top: 10px; font-size: 13px; line-height: 1.5; color: #cfe0ee; }
#right-panel .rp-h { font-size: 12px; font-weight: 600; color: #7fd4b0; margin-bottom: 4px; }
#right-panel .muted { color: #8fa3b3; font-size: 12px; padding: 20px 4px; text-align: center; }

/* chat: full-width bottom panel */
#chat {
  position: absolute; left: 0; right: 0; bottom: 0; height: var(--chat-h); z-index: 650;
  background: rgba(14,19,26,.98); border-top: 1px solid #2a3a49;
  display: flex; flex-direction: column; overflow: hidden;
}
#chat-log { flex: 1; overflow: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { font-size: 13.5px; line-height: 1.45; padding: 8px 12px; border-radius: 8px; max-width: 860px; }
.msg.bot { background: #16222e; color: #d8e6f2; align-self: flex-start; }
.msg.user { background: #2b4a6b; color: #fff; align-self: flex-end; }
.msg.status { background: transparent; color: #9fdcc0; align-self: flex-start; padding: 2px 6px; font-size: 12px; }
.msg.news { background: #131c26; border: 1px solid #2a3a49; color: #cfe0ee; align-self: stretch; max-width: none; }
.msg.news .news-h { font-weight: 600; color: #ffd479; margin-bottom: 4px; font-size: 12.5px; }
.msg.news a { color: #7db8ff; }
.msg .btn-row { display: flex; gap: 8px; margin-top: 8px; }
.msg .btn-row button { padding: 5px 12px; border: 1px solid #2a3a49; background: #142230; color: #e8eef4;
  border-radius: 6px; cursor: pointer; font-size: 12.5px; }
.msg .btn-row button.primary { background: #3a6ea5; border-color: #3a6ea5; font-weight: 600; }

/* per-gauge progress bars (AI info mode) */
.msg.progress { background: #131c26; border: 1px solid #2a3a49; align-self: stretch; max-width: none; padding: 8px 12px; }
.pg-row { display: flex; align-items: center; gap: 10px; margin: 4px 0; }
.pg-name { font-size: 12px; color: #ffd479; min-width: 88px; font-weight: 600; }
.pg-track { flex: 1; height: 10px; background: #0d141c; border: 1px solid #223; border-radius: 6px; overflow: hidden; }
.pg-fill { display: block; height: 100%; width: 0%;   /* display:block — a plain
  inline <span> ignores width, leaving the bar permanently empty */
  background: linear-gradient(90deg, #3a6ea5, #4cc9a0); transition: width .5s; }
.pg-fill.cal { background: linear-gradient(90deg, #a56ea5, #ffd479); }
.pg-stage { font-size: 11.5px; color: #9fdcc0; min-width: 240px; }
.pg-pct { font-size: 11px; color: #8fa3b3; min-width: 34px; text-align: right; font-variant-numeric: tabular-nums; }
.pg-stop { margin-top: 6px; text-align: right; }
.pg-stop-btn { padding: 3px 10px; font-size: 11.5px; border: 1px solid #5a3038; background: #2a161b;
  color: #f0a3ab; border-radius: 6px; cursor: pointer; }
.pg-stop-btn:disabled { opacity: .5; cursor: default; }

#chat-input { display: flex; gap: 8px; padding: 10px 16px; border-top: 1px solid #223; }
#run-scheme { width: auto; flex: none;   /* undo the global select width:100% */
  padding: 8px 6px; border: 1px solid #2a3a49; background: #142230; color: #e8eef4;
  border-radius: 6px; font-size: 13px; cursor: pointer; }
#chat-text { flex: 1; font-size: 14px; padding: 9px 12px; }
#chat button { padding: 8px 16px; border: 1px solid #2a3a49; background: #142230; color: #e8eef4; border-radius: 6px; cursor: pointer; font-size: 13px; }
#chat button.primary { background: #3a6ea5; border-color: #3a6ea5; font-weight: 600; }
#chat button:disabled { opacity: .5; cursor: default; }

/* streamflow time animation bar — floats above the chat panel */
#anim {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--chat-h) + 12px); z-index: 660;
  display: flex; align-items: center; gap: 10px; padding: 8px 14px; width: 460px; max-width: 60%;
  background: rgba(17,23,31,.94); border: 1px solid #223; border-radius: 24px; box-shadow: 0 6px 24px rgba(0,0,0,.45);
}
#anim.hidden { display: none; }
#anim-play { width: 34px; height: 34px; border-radius: 50%; border: none; background: #3a6ea5; color: #fff;
  font-size: 14px; cursor: pointer; flex: none; }
#anim-slider { flex: 1; accent-color: #4cc9a0; }
#anim-time { font-variant-numeric: tabular-nums; font-size: 12px; color: #cfe0ee; min-width: 92px; text-align: right; }

/* streamflow legend — bottom-LEFT: the results panel owns the right edge */
#q-legend {
  position: absolute; left: 12px; bottom: calc(var(--chat-h) + 12px); z-index: 640;
  background: rgba(17,23,31,.92); border: 1px solid #223; border-radius: 8px; padding: 8px 10px; color: #cfe0ee;
  width: 160px;
}
/* slide right while the Model-options panel is expanded so they never overlap */
#left-panel:not(.collapsed):not(.hidden) ~ #q-legend { left: 324px; }
#q-legend .q-title { font-size: 11px; color: #8fa3b3; margin-bottom: 5px; }
#q-legend .q-bar { height: 10px; border-radius: 4px;
  background: linear-gradient(90deg, #59626c 0%, #7e8a95 14%, #3fae5a 23%, #57c258 36%,
    #c9dd45 48%, #ffd23f 57%, #fd8d3c 70%, #f03b20 84%, #bd0026 100%); }
#q-legend .q-ticks { display: flex; justify-content: space-between; font-size: 10px; color: #8fa3b3; margin-top: 2px; }
#q-legend .q-peak { font-size: 10px; color: #8fa3b3; margin-top: 3px; }

/* inundation depth legend — same bottom-left slot as #q-legend (the two are
   never shown together: entering 2D-inundation mode hides the streamflow one).
   The gradient MIRRORS DEPTH_STOPS in hf_data/eventsim.py — change both. */
#depth-legend {
  position: absolute; left: 12px; bottom: calc(var(--chat-h) + 12px); z-index: 640;
  background: rgba(17,23,31,.92); border: 1px solid #223; border-radius: 8px;
  padding: 8px 10px; color: #cfe0ee; width: 186px;
}
#left-panel:not(.collapsed):not(.hidden) ~ #depth-legend { left: 324px; }
#depth-legend .d-title { font-size: 11px; color: #8fa3b3; margin-bottom: 5px; }
#depth-legend .d-bar { height: 10px; border-radius: 4px;
  background: linear-gradient(90deg, #2ea03c 0%, #fadc28 30%, #eb3223 65%, #82148c 100%); }
#depth-legend .d-ticks { display: flex; justify-content: space-between;
  font-size: 10px; color: #8fa3b3; margin-top: 2px; font-variant-numeric: tabular-nums; }
#depth-legend .d-note { font-size: 10px; color: #8fa3b3; margin-top: 4px; line-height: 1.35; }
body.font-lg #depth-legend { zoom: 1.18; }
body.font-xl #depth-legend { zoom: 1.4; }

/* modal */
.modal { position: fixed; inset: 0; z-index: 900; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; }
.modal-card { width: 420px; max-width: 92vw; max-height: 86vh; overflow: auto; background: #121a24;
  border: 1px solid #2a3a49; border-radius: 12px; color: #e8eef4; box-shadow: 0 12px 48px rgba(0,0,0,.6); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px;
  border-bottom: 1px solid #223; font-weight: 600; }
.modal-head button { background: none; border: none; color: #8fa3b3; font-size: 15px; cursor: pointer; }
.modal-body { padding: 14px 16px 18px; }
.modal-body h4 { margin: 16px 0 6px; color: #7fd4b0; font-size: 13px; }
.modal-body .pm-user { display: flex; gap: 10px; align-items: center; margin-bottom: 4px; }
.modal-body .pm-user img { width: 44px; height: 44px; border-radius: 50%; background: #0d141c; }
.pm-name { font-weight: 700; }
.pm-sub { color: #8fa3b3; font-size: 12px; }
.modal-body button.primary { margin-top: 10px; padding: 7px 14px; background: #3a6ea5; color: #fff;
  border: none; border-radius: 6px; cursor: pointer; }
.btn-link { display: block; margin-top: 8px; color: #7db8ff; font-size: 13px; text-decoration: none; }
.btn-link:hover { text-decoration: underline; }

/* map pins */
.pin { border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.5); }
.leaflet-container { background: #0b0f14; }

/* focused-gauge teardrop pin: white stroke reads on dark bases, dark shadow
   reads on the bright topo base */
.focus-pin { pointer-events: none; }
.focus-pin svg { filter: drop-shadow(0 2px 3px rgba(0, 0, 0, .75)); }
.fp-bounce svg { animation: fpdrop .55s cubic-bezier(.3, .8, .4, 1.15); }
@keyframes fpdrop {
  0%   { transform: translateY(-16px); }
  60%  { transform: translateY(2px); }
  100% { transform: translateY(0); }
}
