:root {
  --green-900: #2e6b55;
  --green-800: #3d7a62;
  --green-700: #4f8c73;
  --green-100: #e8f4ee;
  --green-050: #f4fbf7;
  --ink: #22302a;
  --muted: #66746f;
  --line: #d5e7de;
  --panel: #eff8f3;
  --white: #ffffff;
  --warning: #9a6b00;
  --danger: #9b3131;
  --shadow: 0 10px 28px rgba(20, 54, 38, 0.13);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: "Segoe UI", Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: #f7fbf8;
}

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: linear-gradient(90deg, var(--green-800), #8ab19e);
  color: white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.18);
  position: sticky;
  top: 0;
  z-index: 1000;
}

.icon-btn, .top-action, .wide-btn, .home-btn, .tab, .map-toolbar button, .load-btn {
  border: 1px solid rgba(46,107,85,.22);
  border-radius: 8px;
  padding: 9px 12px;
  background: #fff;
  color: var(--green-900);
  font-weight: 650;
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, opacity .15s ease;
}
.icon-btn:hover, .top-action:hover, .wide-btn:hover, .home-btn:hover, .map-toolbar button:hover, .load-btn:hover { transform: translateY(-1px); }
.icon-btn { font-size: 20px; line-height: 1; width: 42px; }
.top-action { margin-left: auto; background: rgba(255,255,255,.95); }
.top-action + .top-action { margin-left: 0; }
.primary { background: var(--green-800) !important; color: #fff !important; border-color: var(--green-900) !important; }
.brand { flex: 1; min-width: 0; }
.brand-title { font-size: 18px; font-weight: 800; letter-spacing: .2px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-subtitle { font-size: 12px; opacity: .9; display: block; }

.layout { display: flex; height: calc(100vh - 58px); }
.sidebar {
  width: 370px;
  min-width: 330px;
  height: 100%;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 14px;
  transition: margin-left .2s ease;
}
.sidebar.collapsed { margin-left: -370px; }
.content { flex: 1; height: 100%; overflow-y: auto; }

.home-btn { width: 100%; text-align: left; margin-bottom: 12px; background: #d7eddf; color: var(--green-900); }
.panel-section { background: rgba(255,255,255,.66); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; box-shadow: 0 2px 10px rgba(20,54,38,.04); }
.panel-section.compact { padding-bottom: 10px; }
h1, h2, h3 { margin: 0 0 12px; }
.panel-section h2 { font-size: 17px; }
label { display: block; font-size: 12px; font-weight: 800; color: var(--green-900); margin: 12px 0 6px; text-transform: uppercase; letter-spacing: .5px; }
select, input[type="file"] {
  width: 100%; padding: 10px 11px; border: 1px solid var(--line); border-radius: 8px; background: white; color: var(--ink);
}
.wide-btn { width: 100%; margin-top: 12px; }
.helper { display: block; margin-top: 8px; color: var(--muted); line-height: 1.35; }
.tabs { display: flex; gap: 8px; border-bottom: 1px solid var(--line); padding-bottom: 8px; }
.tab { flex: 1; background: #f7fbf8; }
.tab.active { background: var(--green-800); color: white; }
.hidden { display: none !important; }
.selected-card {
  background: var(--green-800);
  color: #fff;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.catalog-group { margin-bottom: 8px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: white; }
.catalog-heading { background: #cfe7d9; padding: 12px; cursor: pointer; font-weight: 800; display: flex; justify-content: space-between; align-items: center; }
.catalog-items { padding: 10px; }
.catalog-item { display: grid; grid-template-columns: 70px 1fr; gap: 10px; align-items: center; padding: 6px 0; border-bottom: 1px solid #edf5f0; }
.catalog-item:last-child { border-bottom: 0; }
.load-btn { padding: 8px 9px; font-size: 12px; }
.load-btn:disabled { background: #edf0ee; color: #8b9691; border-color: #d4dad7; cursor: not-allowed; transform: none; opacity: .72; }
.load-btn:disabled:hover { transform: none; }
.catalog-item-disabled .item-title,
.catalog-item-disabled .item-meta { color: #8b9691; }
.catalog-item-disabled { cursor: help; }
#sourceText a { color: var(--green-900); font-weight: 700; }
#sourceText a:hover { text-decoration-thickness: 2px; }
.item-title { font-size: 13px; font-weight: 700; }
.item-meta { color: var(--muted); font-size: 11px; margin-top: 3px; }
.status-pill { display:inline-block; padding:2px 6px; border-radius:999px; font-size:10px; margin-left:4px; background:#eef3f0; color:#47524d; }
.status-live { background:#e0f4e8; color:#276245; }
.status-backend { background:#fff5dc; color:#7b5200; }
.status-demo { background:#e7eeff; color:#2a4b95; }
.status-key { background:#ffe9e9; color:#8a2727; }
.api-notes { font-size: 12px; line-height: 1.45; color: var(--muted); }
.api-notes strong { color: var(--green-900); }

.map-wrap { position: relative; height: 44vh; min-height: 360px; border-bottom: 1px solid var(--line); background: white; }
#map { width: 100%; height: 100%; }
.map-toolbar { position: absolute; right: 14px; top: 14px; z-index: 500; display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.map-toolbar button { padding: 8px 10px; box-shadow: 0 3px 12px rgba(0,0,0,.12); }

.intro-panel, .analysis-panel, .report-panel { padding: 24px; }
.intro-card, .card, .report-paper { background: var(--white); border: 1px solid var(--line); border-radius: 14px; padding: 22px; box-shadow: var(--shadow); }
.intro-card h1 { background: var(--green-100); display: inline-block; padding: 14px 18px; border-radius: 8px; }
.intro-card p { line-height: 1.6; max-width: 1000px; }
.quick-grid { display: grid; grid-template-columns: repeat(4, minmax(160px,1fr)); gap: 12px; margin-top: 18px; }
.quick-grid div { background: var(--green-050); border: 1px solid var(--line); border-radius: 10px; padding: 14px; }
.analysis-header { display: flex; align-items: flex-start; gap: 14px; justify-content: space-between; margin-bottom: 14px; }
.analysis-header h1 { margin-bottom: 4px; }
.analysis-header p { margin: 0; color: var(--muted); }
.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(140px,1fr)); gap: 12px; margin-bottom: 14px; }
.summary-card { background: white; border: 1px solid var(--line); border-radius: 12px; padding: 14px; box-shadow: 0 4px 12px rgba(20,54,38,.06); }
.summary-card .value { font-size: 24px; font-weight: 850; color: var(--green-900); }
.summary-card .label { color: var(--muted); font-size: 12px; margin-top: 4px; }
.two-col { display: grid; grid-template-columns: 1.2fr .9fr; gap: 14px; }
.table-wrap { overflow: auto; max-height: 340px; border: 1px solid var(--line); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 10px; border-bottom: 1px solid #edf3ef; text-align: left; vertical-align: top; }
th { background: var(--green-800); color: white; position: sticky; top: 0; z-index: 1; }
.source-card { margin-top: 14px; }
.source-card pre { background: #f4f7f5; padding: 12px; border-radius: 8px; overflow: auto; white-space: pre-wrap; }
.report-paper { max-width: 920px; margin: 0 auto; line-height: 1.55; }
.report-paper h1 { border-bottom: 3px solid var(--green-800); padding-bottom: 12px; }
.notice { background: #fff8e6; border-left: 5px solid #d69b00; padding: 12px; }
.leaflet-popup-content { min-width: 220px; }
.leaflet-tooltip { font-weight: 700; }

@media (max-width: 1000px) {
  .layout { display: block; height: auto; }
  .sidebar { width: 100%; height: auto; min-width: 0; }
  .sidebar.collapsed { margin-left: 0; display: none; }
  .content { height: auto; }
  .quick-grid, .summary-grid, .two-col { grid-template-columns: 1fr; }
  .topbar { height: auto; min-height: 58px; flex-wrap: wrap; padding: 10px; }
  .brand-title { white-space: normal; }
}

.map-prompt {
  background: #fff8e6;
  border-left: 4px solid #d69b00;
  border-radius: 7px;
  padding: 8px 10px;
  color: #6f4b00;
  font-weight: 650;
}

.leaflet-interactive { cursor: pointer; }

.map-legend {
  background: rgba(255, 255, 255, 0.94);
  padding: 10px 12px;
  border: 1px solid #d1ded8;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,.12);
  color: #26332e;
  font-size: 13px;
  line-height: 1.35;
}
.map-legend strong {
  display: block;
  margin-bottom: 5px;
  color: #315f4c;
}
.map-legend div {
  white-space: nowrap;
  margin: 2px 0;
}
.map-legend span {
  display: inline-block;
  width: 15px;
  height: 11px;
  margin-right: 7px;
  border: 1px solid rgba(0,0,0,.15);
  vertical-align: -1px;
}

.status-line { font-weight: 700; color: var(--green-700); }

.map-legend small {
  display: block;
  margin: -2px 0 5px;
  color: #66746f;
  font-size: 11px;
}

/* Topography DEM image overlay: no rectangular image-bounds outline.
   The real selected watershed boundary remains visible as the polygon border. */
.leaflet-image-layer.topography-overlay,
.leaflet-image-layer.topography-overlay:focus,
.leaflet-image-layer.topography-overlay:active,
.topography-overlay.no-bounds-outline {
  border: 0 !important;
  outline: none !important;
  box-shadow: none !important;
}

/* Continuous topography legend. The map itself is rendered as a smooth raster;
   this legend shows the same ramp as one vertical gradient bar instead of
   separate class swatches. */
.topography-gradient-legend .gradient-legend-body {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin: 8px 0 6px;
}
.topography-gradient-legend .gradient-bar {
  width: 18px;
  height: 118px;
  border: 1px solid rgba(0,0,0,.18);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.35);
}
.topography-gradient-legend .gradient-ticks {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  white-space: nowrap;
  font-size: 13px;
  color: #26332e;
}

/* Stronger selector so the topography legend cannot fall back visually to the
   generic swatch-list legend. */
.map-legend.topography-gradient-legend div:not(.gradient-legend-body):not(.gradient-bar):not(.gradient-ticks) span {
  display: none !important;
}
.map-legend.topography-gradient-legend .gradient-bar {
  min-width: 20px;
  height: 132px;
}

/* Topography stretch comparison controls */
.stretch-experiment-buttons {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.stretch-experiment-buttons button {
  border: 1px solid rgba(46, 107, 85, 0.35);
  background: rgba(255, 255, 255, 0.85);
  border-radius: 6px;
  padding: 3px 6px;
  font-size: 11px;
  color: #2e6b55;
  cursor: pointer;
}
.stretch-experiment-buttons button.active {
  background: #2e6b55;
  color: #fff;
  font-weight: 700;
}



/* Categorical NLCD overlay: keep class-cell edges sharp when Leaflet scales
   the PNG during zooming.  Do not apply this to the continuous DEM layer. */
.leaflet-image-layer.land-use-overlay {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border: 0 !important;
  outline: none !important;
  box-shadow: none !important;
}

/* Compact NLCD legend beside the zoom control.
   The larger horizontal offset keeps the legend clear of both the +/-
   buttons and the bottom-left scale bar, even when the legend is tall. */
.landuse-legend {
  width: max-content;
  max-width: calc(100vw - 130px);
  box-sizing: border-box;
  max-height: min(390px, calc(100vh - 120px));
  overflow-y: auto;
  margin: 10px 0 0 72px !important;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.28;
}

.landuse-legend strong {
  margin-bottom: 4px;
  font-size: 13px;
}

.landuse-legend small {
  margin-bottom: 4px;
  font-size: 10.5px;
}

.landuse-legend div {
  margin: 1px 0;
}

.landuse-legend span {
  width: 14px;
  height: 10px;
  margin-right: 6px;
}

/* The JavaScript reparents this control into Leaflet's upper-left corner. */
.leaflet-top.leaflet-left > .landuse-legend {
  float: none !important;
  clear: none !important;
  margin: 10px 0 0 72px !important;
  width: max-content;
  max-width: calc(100vw - 130px);
  box-sizing: border-box;
  max-height: min(390px, calc(100vh - 120px));
  overflow-y: auto;
}


/* Keep responsive Chart.js canvases inside a bounded box.
   Setting the canvas height itself while maintainAspectRatio=false can create
   a resize feedback loop in which the canvas and card keep enlarging. */
.analysis-chart-wrap {
  position: relative;
  width: 100%;
  height: 260px;
  min-height: 260px;
  overflow: hidden;
}
.analysis-chart-wrap.is-doughnut {
  height: 500px;
  min-height: 500px;
}
.analysis-chart-wrap canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.irrigation-analysis { display:grid; gap:16px; margin-top:16px; }
.irrigation-controls { display:flex; flex-wrap:wrap; align-items:center; gap:14px; margin-bottom:12px; }
.irrigation-controls select { margin-left:6px; padding:5px 8px; }
#irrigationDatasetChecks { display:flex; flex-wrap:wrap; gap:12px; }
.irrigation-chart-wrap { position:relative; height:320px; min-height:320px; }
.metric-table-wrap { margin-top:14px; overflow-x:auto; }
.metric-table { min-width:1050px; border-collapse:collapse; }
.metric-table th:first-child { position:sticky; left:0; z-index:2; background:#f7faf8; color: var(--ink); min-width:235px; text-align:left; }
.metric-table th,.metric-table td { white-space:nowrap; padding:7px 9px; border:1px solid #d9e1dc; text-align:right; }
.metric-table th small { display:block; font-weight:normal; color:var(--muted); }
.metric-info { margin-left:5px; color:#28735b; cursor:help; }
.yearly-metric-tables { display:grid; gap:14px; }
.metric-note { color:var(--muted); font-size:.92rem; }


/* Confirmation shown before replacing an already-selected watershed. */
.watershed-change-modal {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(17, 28, 23, 0.55);
}
.watershed-change-modal.hidden { display: none; }
.watershed-change-dialog {
  width: min(520px, 100%);
  padding: 24px;
  border: 1px solid #cbd7d0;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}
.watershed-change-dialog h2 { margin: 0 0 10px; }
.watershed-change-dialog p { margin: 0; line-height: 1.55; }
.watershed-change-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 22px;
}
.watershed-change-actions button {
  padding: 9px 14px;
  border-radius: 7px;
  cursor: pointer;
}
.watershed-change-actions .secondary-action {
  border: 1px solid #9eada5;
  background: #fff;
  color: var(--ink);
}
.watershed-change-actions .primary-action {
  border: 1px solid var(--green-800);
  background: var(--green-800);
  color: #fff;
}

/* ── Multi-watershed selection checklist (restored feature) ─────────────── */
/* The global `label` rule uppercases text; reset it for checklist rows so
   watershed names display normally. */
.watershed-checklist-wrap { margin: 8px 0 4px; }
.watershed-checklist-wrap .checklist-label {
  text-transform: uppercase; /* keep the section label consistent with others */
}
#watershedFilter {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid #d5ded8;
  border-radius: 6px;
  font-size: 0.85rem;
  margin-bottom: 6px;
  background: #fff;
}
.watershed-checklist {
  max-height: 190px;
  overflow-y: auto;
  border: 1px solid #d5ded8;
  border-radius: 6px;
  background: #fbfdfc;
  padding: 4px;
}
.checklist-row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 0.82rem;
  line-height: 1.25;
  cursor: pointer;
  /* Reset the global label styling (uppercase, bold, margins) for rows */
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--ink, #22302a);
  margin: 0;
}
.checklist-row:hover { background: #e9f2ed; }
.checklist-row input[type="checkbox"] {
  margin-top: 2px;
  flex: 0 0 auto;
  accent-color: #b3541e;
}
.merged-hucs {
  color: #5c6f66;
  word-break: break-all;
}
