:root {
  color-scheme: light;
  --navy: #073b68;
  --navy-deep: #052f55;
  --blue: #087bf1;
  --blue-dark: #07357f;
  --cyan: #08baf2;
  --ink: #0a3378;
  --muted: #41618e;
  --border: #c9ddf3;
  --border-soft: #dbe9f7;
  --panel: #ffffff;
  --panel-blue: #eef6ff;
  --page: #f7fbff;
  --shadow: 0 8px 24px rgba(21, 69, 117, 0.08);
  font-size: 17px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; scroll-behavior: smooth; background: var(--page); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: linear-gradient(180deg, #f9fcff, #f4f9ff); }
button, input, select { font: inherit; }
button, a, input { -webkit-tap-highlight-color: transparent; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 68px;
  display: flex;
  align-items: center;
  gap: 28px;
  padding: 8px 24px;
  color: #fff;
  background: linear-gradient(100deg, #073b68 0%, #073a65 58%, #052f55 100%);
  box-shadow: 0 2px 7px rgba(1, 31, 60, 0.2);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 390px;
  color: inherit;
  text-decoration: none;
}

.brand-logo { width: 68px; height: 50px; fill: #0ab9f2; filter: drop-shadow(0 4px 7px rgba(0, 187, 246, 0.2)); }
.brand span { display: grid; gap: 1px; }
.brand strong { font-size: 1.62rem; line-height: 1.08; letter-spacing: -0.025em; }
.brand small { color: #03c5ff; font-size: 1rem; letter-spacing: 0.01em; }

.main-nav { margin-left: auto; display: flex; align-items: stretch; align-self: stretch; gap: 32px; }
.main-nav a, .main-nav button {
  position: relative;
  display: grid;
  place-items: center;
  padding: 0;
  color: #fff;
  border: 0;
  background: transparent;
  text-decoration: none;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 650;
}
.main-nav a::after, .main-nav button::after { content: ""; position: absolute; left: 0; right: 0; bottom: 6px; height: 2px; border-radius: 2px; background: transparent; }
.main-nav a:hover::after, .main-nav button:hover::after, .main-nav .active::after { background: #fff; }

.download-button {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 19px;
  color: #fff;
  border: 0;
  border-radius: 7px;
  background: #087bf1;
  box-shadow: 0 6px 15px rgba(0, 91, 210, 0.25);
  cursor: pointer;
  font-weight: 760;
}
.download-button:hover:not(:disabled) { background: #006ee4; }
.download-button:disabled { opacity: 0.55; cursor: not-allowed; }
.download-button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }

.explorer-page { width: 100%; padding: 2px 9px 0; }

.map-panel {
  position: relative;
  height: clamp(500px, 55vh, 620px);
  overflow: hidden;
  border: 1px solid #b8cee5;
  border-radius: 10px;
  background: #0a4a78;
  box-shadow: var(--shadow);
}
#map { position: absolute; inset: 0; }

.map-loading {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  color: #fff;
  background: rgba(3, 49, 88, 0.78);
  backdrop-filter: blur(5px);
  font-size: .96rem;
  transition: opacity 220ms ease, visibility 220ms ease;
}
.map-loading.hidden { opacity: 0; visibility: hidden; }
.spinner { width: 20px; height: 20px; border: 2px solid rgba(255,255,255,.28); border-top-color: #fff; border-radius: 50%; animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.width-legend {
  position: absolute;
  z-index: 4;
  left: 456px;
  top: 18px;
  width: 420px;
  padding: 12px 14px 11px;
  color: #fff;
  border: 1px solid rgba(255,255,255,.55);
  border-radius: 7px;
  background: rgba(4, 52, 91, 0.78);
  box-shadow: 0 5px 18px rgba(0, 31, 66, 0.22);
  backdrop-filter: blur(4px);
}
.legend-title { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: .9rem; }
.legend-title span { opacity: .78; }
.legend-classes { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); align-items: end; gap: 8px; }
.legend-classes span { min-width: 0; display: grid; gap: 6px; color: rgba(255,255,255,.94); text-align: center; font-size: .82rem; font-weight: 700; white-space: nowrap; }
.legend-swatch { width: 100%; display: block; align-self: center; border-radius: 999px; }
.legend-swatch.width-1 { height: 3px; background: #2587ff; }
.legend-swatch.width-2 { height: 5px; background: #12c9e8; }
.legend-swatch.width-3 { height: 7px; background: #31d39b; }
.legend-swatch.width-4 { height: 9px; background: #ffd21f; }
.legend-swatch.width-5 { height: 12px; background: #f23824; }

.map-tooltip {
  position: absolute;
  z-index: 7;
  max-width: 220px;
  padding: 8px 10px;
  color: #fff;
  border: 1px solid rgba(255,255,255,.52);
  border-radius: 6px;
  background: rgba(3, 48, 88, .92);
  box-shadow: 0 8px 24px rgba(0, 26, 60, .24);
  pointer-events: none;
  font-size: .9rem;
  line-height: 1.42;
  transform: translate(12px, 12px);
}
.map-tooltip strong { display: block; color: #55e5ff; font-size: .96rem; }

.maplibregl-ctrl-top-right { top: 12px; right: 8px; }
.maplibregl-ctrl-group { overflow: hidden; border: 1px solid #c6d8ee !important; border-radius: 7px !important; background: #fff !important; box-shadow: 0 4px 12px rgba(5, 49, 91, .18) !important; }
.maplibregl-ctrl-group button { width: 39px !important; height: 39px !important; }
.maplibregl-ctrl-group button + button { border-top-color: #d6e4f2 !important; }
.maplibregl-ctrl-icon { filter: hue-rotate(172deg) saturate(4); }
.maplibregl-ctrl-attrib { color: #315f8a; background: rgba(255,255,255,.82) !important; }
.maplibregl-ctrl-attrib a { color: #174c7f; }
.maplibregl-ctrl-scale { color: #fff; border-color: #fff !important; background: rgba(4, 52, 91, .42) !important; text-shadow: 0 1px 2px rgba(0,0,0,.55); }

.workspace-grid { display: block; padding: 14px 3px 0; }
.panel { border: 1px solid var(--border); border-radius: 9px; background: rgba(255,255,255,.97); box-shadow: 0 5px 18px rgba(28, 79, 128, .06); }

.settings-panel { overflow: hidden; }
.map-settings-overlay {
  position: absolute;
  z-index: 5;
  top: 18px;
  left: 18px;
  width: min(420px, calc(100% - 36px));
  max-height: calc(100% - 36px);
  overflow: auto;
  background: rgba(255,255,255,.96);
  box-shadow: 0 16px 38px rgba(1, 42, 82, .24);
  backdrop-filter: blur(9px);
}
.settings-details > summary {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border-soft);
  cursor: pointer;
  list-style: none;
}
.settings-details > summary::-webkit-details-marker { display: none; }
.summary-title { display: flex; align-items: center; gap: 12px; color: var(--blue-dark); font-size: 1.3rem; font-weight: 770; }
.summary-title svg { width: 26px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; }
.chevron { width: 21px; fill: none; stroke: var(--blue-dark); stroke-width: 2.4; transition: transform 160ms ease; }
.settings-details:not([open]) .chevron { transform: rotate(180deg); }

#settings-form { display: grid; gap: 24px; padding: 16px 17px 18px; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.field-group legend { margin-bottom: 11px; color: var(--blue-dark); font-size: 1.05rem; font-weight: 760; }
.date-row { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 9px; }
.date-row label { min-width: 0; height: 50px; display: flex; align-items: center; gap: 10px; padding: 0 12px; border: 1.5px solid #b9cfe9; border-radius: 7px; background: #fff; cursor: pointer; }
.date-row label:focus-within { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(8,123,241,.1); }
.date-row svg { flex: 0 0 auto; width: 22px; fill: none; stroke: var(--blue-dark); stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
input[type="date"] { min-width: 0; width: 100%; padding: 0; color: var(--blue-dark); border: 0; outline: 0; background: transparent; cursor: pointer; font-size: 1rem; }
input[type="date"]::-webkit-calendar-picker-indicator { opacity: 0; width: 0; }
.date-separator { color: var(--blue-dark); font-weight: 750; }
.field-error { min-height: 1em; margin: 6px 0 -9px; color: #c92f45; font-size: .84rem; }
.date-disclaimer { margin: 10px 0 0; color: var(--blue-dark); font-size: .94rem; line-height: 1.4; }
.date-disclaimer a { color: var(--blue); text-decoration: underline; text-underline-offset: 2px; }
.date-disclaimer a:hover { color: var(--blue-dark); }

.radio-option { display: inline-flex; align-items: center; gap: 9px; color: var(--blue-dark); cursor: pointer; font-size: 1rem; }
.radio-option input { position: absolute; opacity: 0; pointer-events: none; }
.radio-dot { width: 26px; height: 26px; display: inline-grid; place-items: center; border: 2px solid #a9c2df; border-radius: 50%; background: #fff; }
.radio-option input:checked + .radio-dot { border: 8px solid #2f8cf4; }
.radio-option input:focus-visible + .radio-dot { outline: 3px solid rgba(8,123,241,.2); outline-offset: 2px; }
.map-style-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.reset-button { width: 100%; min-height: 56px; display: flex; align-items: center; justify-content: center; gap: 10px; color: var(--blue-dark); border: 1.5px solid #b8d1ec; border-radius: 7px; background: #fff; cursor: pointer; font-size: 1.06rem; font-weight: 730; }
.reset-button:hover { color: #fff; border-color: var(--blue); background: var(--blue); }
.reset-button svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 2.1; stroke-linecap: round; stroke-linejoin: round; }
.network-count { margin: -11px 0 0; color: #6e88aa; text-align: center; font-size: .84rem; }

.selected-panel { width: 100%; min-width: 0; padding: 0 12px 12px; }
.selected-header { min-height: 47px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--border-soft); }
.selected-header h2 { margin: 0; color: var(--blue-dark); font-size: 1.25rem; }
.selected-header p { display: flex; align-items: center; gap: 8px; margin: 0; color: #234f8f; font-size: .9rem; }
.selected-header svg { width: 20px; flex: 0 0 auto; fill: none; stroke: var(--blue); stroke-width: 1.8; stroke-linecap: round; }

.empty-state { min-height: 390px; display: flex; align-items: center; justify-content: center; gap: 18px; padding: 34px; color: #6680a5; text-align: left; }
.empty-state > svg { width: 62px; fill: none; stroke: #20aaf1; stroke-width: 2.2; stroke-linecap: round; }
.empty-state h3 { margin: 0 0 5px; color: var(--blue-dark); font-size: 1.16rem; }
.empty-state p { max-width: 520px; margin: 0; font-size: .96rem; line-height: 1.5; }

.reach-details { display: grid; grid-template-columns: minmax(300px, 32%) minmax(0, 1fr); grid-template-areas: "summary stats" "summary chart"; gap: 10px 9px; padding-top: 10px; }
.summary-row { display: contents; }
.reach-summary-card { grid-area: summary; min-width: 0; padding: 16px 17px; border: 1px solid var(--border-soft); border-radius: 8px; background: linear-gradient(135deg, #edf6ff, #f7fbff); }
.river-title { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.river-title > svg { width: 24px; flex: 0 0 auto; fill: none; stroke: #069cf2; stroke-width: 2.2; stroke-linecap: round; }
.river-title h3 { min-width: 0; margin: 0; overflow: hidden; color: var(--blue-dark); font-size: 1.3rem; text-overflow: ellipsis; white-space: nowrap; }
.width-chip { margin-left: auto; padding: 5px 8px; color: #fff; border-radius: 4px; background: var(--blue); font-size: .9rem; font-weight: 750; white-space: nowrap; }
.reach-facts { display: grid; gap: 7px; margin: 0; }
.reach-facts div { display: flex; align-items: baseline; gap: 6px; min-width: 0; }
.reach-facts .wse-fact { flex-wrap: wrap; }
.reach-facts dt { flex: 0 0 auto; color: #264e87; font-size: 1rem; }
.reach-facts dd { min-width: 0; margin: 0; overflow: hidden; color: var(--blue-dark); font-size: 1rem; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.reach-message { min-height: 1em; margin: 11px 0 0; color: #426a9b; font-size: .96rem; line-height: 1.45; }
.reach-message.error { color: #c4384d; }
.algorithm-guide { margin-top: 16px; padding-top: 13px; border-top: 1px solid #cfe0f2; }
.algorithm-guide h4 { margin: 0 0 10px; color: var(--blue-dark); font-size: 1.08rem; }
.algorithm-guide dl { display: grid; gap: 9px; margin: 0; }
.algorithm-guide dl > div { display: grid; grid-template-columns: minmax(112px, 32%) minmax(0, 1fr); align-items: start; gap: 9px; }
.algorithm-guide dt { display: flex; align-items: center; gap: 7px; color: var(--blue-dark); font-size: 1rem; font-weight: 750; }
.algorithm-guide dt i { width: 21px; height: 4px; flex: 0 0 auto; border-radius: 999px; background: var(--series-color); }
.algorithm-guide dd { margin: 0; color: #315891; font-size: .98rem; line-height: 1.4; }

.stats-grid { grid-area: stats; min-width: 0; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--border-soft); border-radius: 8px; background: #fff; overflow: hidden; }
.stat { min-width: 0; padding: 13px 14px; border-left: 1px solid var(--border-soft); }
.stat:first-child { border-left: 0; }
.stat span { display: block; min-height: 42px; color: #315891; font-size: .84rem; line-height: 1.35; }
.stat strong { display: block; overflow: hidden; color: var(--blue-dark); font-size: clamp(1.1rem, 1.65vw, 1.48rem); font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }

.chart-section { grid-area: chart; margin: 0; padding: 8px 9px 7px; border: 1px solid var(--border-soft); border-radius: 8px; background: #fff; }
.chart-heading { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title download" "subtitle status" "legend legend"; align-items: center; gap: 8px 16px; min-height: 40px; padding: 0 2px 7px; }
.chart-heading h3 { grid-area: title; margin: 0; color: var(--blue-dark); font-size: 1.08rem; }
.chart-heading h3 span { font-weight: 560; }
.chart-heading p { grid-area: subtitle; margin: 0; color: #54719a; font-size: .92rem; }
.chart-download { grid-area: download; min-height: 38px; padding: 0 16px; border-radius: 6px; font-size: .9rem; box-shadow: 0 4px 10px rgba(0, 91, 210, .18); }
.chart-download svg { width: 16px; }
.chart-status { grid-area: status; justify-self: end; color: #486c98; font-size: .9rem; white-space: nowrap; }
.chart-status.loading::before { content: ""; width: 8px; height: 8px; display: inline-block; margin-right: 6px; border: 1.5px solid rgba(8,123,241,.22); border-top-color: var(--blue); border-radius: 50%; animation: spin 700ms linear infinite; }
.chart-legend { grid-area: legend; display: flex; align-items: center; flex-wrap: wrap; gap: 10px 24px; padding: 5px 1px 3px; color: #315891; font-size: 1rem; font-weight: 700; }
.chart-legend span { display: inline-flex; align-items: center; gap: 8px; }
.chart-legend i { width: 34px; height: 5px; display: inline-block; border-radius: 999px; background: var(--series-color); }
.chart-legend .consensus-key i { height: 8px; }
.chart-wrap { position: relative; min-height: 202px; overflow: hidden; border-top: 1px solid #edf3fa; background: #fff; }
.chart-empty { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #7890ad; font-size: .88rem; }
.chart-empty svg { width: 150px; margin-bottom: 5px; fill: none; stroke: rgba(8,123,241,.28); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-empty p { margin: 0; }
.discharge-chart { display: block; width: 100%; height: 100%; min-height: 202px; }
.chart-grid-line { stroke: #c9ddf3; stroke-width: 1; }
.chart-axis-text { fill: #315891; font-family: inherit; font-size: 13px; }
.chart-line { fill: none; stroke: var(--series-color); stroke-width: var(--series-width, 2.6); stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart-line-consensus { opacity: .82; }
.chart-point { fill: var(--series-color); stroke: #fff; stroke-width: 1.4; cursor: crosshair; vector-effect: non-scaling-stroke; }
.chart-point:hover, .chart-point:focus { fill: #ff7a00; outline: none; }
.chart-tooltip { position: absolute; z-index: 4; padding: 8px 10px; color: #fff; border-radius: 5px; background: rgba(4, 54, 104, .94); box-shadow: 0 7px 22px rgba(0,40,80,.2); pointer-events: none; font-size: .82rem; line-height: 1.4; transform: translate(-50%, -112%); white-space: nowrap; }
.chart-tooltip strong { display: block; color: #55e5ff; }

footer { padding: 21px 12px 25px; color: #57779f; text-align: center; font-size: .88rem; }
footer a { color: #175fae; font-weight: 750; text-decoration-thickness: 1px; text-underline-offset: 3px; }
footer a:hover, footer a:focus-visible { color: var(--blue-dark); }

.info-dialog { width: min(520px, calc(100% - 30px)); padding: 26px 28px; color: var(--ink); border: 1px solid var(--border); border-radius: 12px; background: #fff; box-shadow: 0 24px 80px rgba(0, 40, 86, .24); }
.info-dialog::backdrop { background: rgba(3, 35, 66, .46); backdrop-filter: blur(3px); }
.info-dialog h2 { margin: 0 0 12px; color: var(--blue-dark); }
.info-dialog p { margin: 0; color: #365d8d; line-height: 1.6; }
.info-dialog a { color: #086fd4; font-weight: 700; text-underline-offset: 3px; }
.dialog-close { position: absolute; top: 9px; right: 12px; color: #41668f; border: 0; background: transparent; cursor: pointer; font-size: 1.7rem; }

@media (max-width: 1050px) {
  .brand { min-width: 310px; }
  .brand strong { font-size: 1.45rem; }
  .main-nav { gap: 19px; }
  .map-settings-overlay { width: 390px; }
  .width-legend { left: 426px; width: 390px; }
  .reach-details { grid-template-columns: minmax(280px, 36%) minmax(0, 1fr); }
  .stats-grid { min-height: 92px; }
}

@media (max-width: 820px) {
  .topbar { flex-wrap: wrap; padding: 9px 16px 10px; gap: 9px 18px; }
  .brand { min-width: 0; flex: 1; }
  .brand-logo { width: 54px; }
  .brand strong { font-size: 1.28rem; }
  .brand small { font-size: .86rem; }
  .main-nav { order: 3; width: 100%; height: 33px; justify-content: space-between; gap: 10px; }
  .main-nav a, .main-nav button { font-size: .9rem; }
  .map-panel { height: 540px; }
  .map-settings-overlay { top: 12px; left: 12px; width: min(355px, calc(100% - 24px)); max-height: calc(100% - 24px); }
  .width-legend { top: 12px; right: 60px; left: auto; width: 340px; }
  .reach-details { grid-template-columns: minmax(240px, 34%) minmax(0,1fr); }
}

@media (max-width: 620px) {
  .topbar { position: relative; }
  .explorer-page { padding: 6px 6px 0; }
  .map-panel { height: 470px; }
  .map-settings-overlay { top: 10px; left: 10px; width: calc(100% - 20px); max-height: calc(100% - 20px); }
  .width-legend { right: 10px; left: 10px; top: auto; bottom: 10px; width: auto; }
  .workspace-grid { padding: 9px 0 0; gap: 9px; }
  .date-row { grid-template-columns: 1fr; }
  .date-separator { display: none; }
  .map-style-row { align-items: flex-start; gap: 14px; }
  .radio-option { font-size: .92rem; }
  .radio-dot { width: 22px; height: 22px; }
  .radio-option input:checked + .radio-dot { border-width: 7px; }
  .selected-header { display: block; padding: 11px 0; }
  .selected-header p { margin-top: 6px; }
  .reach-details { display: block; }
  .summary-row { display: grid; grid-template-columns: 1fr; }
  .reach-summary-card, .stats-grid { grid-area: auto; }
  .chart-section { margin-top: 10px; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .stat { border-bottom: 1px solid var(--border-soft); }
  .stat:nth-child(3) { border-left: 0; }
  .chart-heading { grid-template-columns: 1fr auto; grid-template-areas: "title title" "subtitle subtitle" "download status" "legend legend"; gap: 6px 10px; }
  .chart-download { justify-self: start; }
  .empty-state { min-height: 300px; flex-direction: column; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
