/* RFVFMP — Clearwater Resources Engineering */
:root {
  --ink: #12263a;
  --ink-2: #3c5368;
  --muted: #6b7f91;
  --line: #dde5ec;
  --bg: #f5f8fa;
  --card: #ffffff;
  --accent: #0b6e8a;
  --accent-2: #0a4f66;
  --published: #0f8a6b;
  --progress: #d08a12;
  --planned: #8a99a8;
  --danger: #b4441c;
  --radius: 10px;
  --shadow: 0 2px 10px rgba(18, 38, 58, .10);
  --sidebar-w: 380px;
  --topbar-h: 60px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
button { font: inherit; cursor: pointer; }
[hidden] { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 0 18px;
  background: var(--ink);
  color: #fff;
  position: relative; z-index: 1001;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-mark { width: 34px; height: 34px; color: #7fd3e6; flex: none; }
.brand-text { min-width: 0; }
.brand-text h1 { font-size: 16px; font-weight: 700; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: .1px; }
.brand-org { color: #a9c3d4; font-size: 12px; text-decoration: none; }
.brand-org:hover { color: #fff; }
.topnav { display: flex; align-items: center; gap: 8px; }
.nav-btn {
  background: transparent; color: #dbe7ef; border: 1px solid rgba(255,255,255,.22);
  border-radius: 8px; padding: 6px 12px;
}
.nav-btn:hover { background: rgba(255,255,255,.08); color: #fff; }

.search { position: relative; }
.search input {
  width: 240px; padding: 7px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,.2);
  background: rgba(255,255,255,.1); color: #fff; outline: none;
}
.search input::placeholder { color: #a9c3d4; }
.search input:focus { background: #fff; color: var(--ink); }
.search-results {
  position: absolute; top: 38px; left: 0; right: 0; min-width: 300px;
  background: #fff; color: var(--ink); border-radius: 8px; box-shadow: var(--shadow); overflow: hidden;
}
.search-results button {
  display: block; width: 100%; text-align: left; padding: 9px 12px; border: 0; background: #fff;
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.search-results button:hover { background: var(--bg); }
.search-results .empty { padding: 10px 12px; color: var(--muted); font-size: 13px; }

.demo-banner {
  position: relative; z-index: 1000;
  background: #fff4dc; color: #7a4d00; border-bottom: 1px solid #f0d49a;
  text-align: center; font-size: 12.5px; font-weight: 600; padding: 6px 12px;
}

/* ---------- Layout ---------- */
.layout {
  display: flex;
  height: calc(100% - var(--topbar-h));
}
body.has-banner .layout { height: calc(100% - var(--topbar-h) - 31px); }
.sidebar {
  width: var(--sidebar-w); flex: none;
  background: var(--card); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
  position: relative; z-index: 900;
}
.panel { padding: 16px 18px; overflow-y: auto; flex: 1; }
.map-wrap { flex: 1; position: relative; }
#map { position: absolute; inset: 0; background: #e8eef2; }
.sheet-handle { display: none; }

.intro { margin: 0 0 14px; color: var(--ink-2); }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Reach list ---------- */
.reach-group { margin-bottom: 14px; }
.reach-group h3 {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted);
  margin: 4px 0 8px; font-weight: 600;
}
.reach-card {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 12px 11px 14px; margin-bottom: 8px; position: relative;
  transition: border-color .15s, box-shadow .15s;
}
.reach-card::before {
  content: ""; position: absolute; left: 0; top: 10px; bottom: 10px; width: 4px; border-radius: 0 3px 3px 0;
  background: var(--planned);
}
.reach-card.published::before { background: var(--published); }
.reach-card.in-progress::before { background: var(--progress); }
.reach-card:hover, .reach-card.hover { border-color: var(--accent); box-shadow: var(--shadow); }
.reach-card .rc-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.reach-card .rc-name { font-weight: 600; font-size: 14px; }
.reach-card .rc-limits { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.reach-card .rc-live { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 8px; font-size: 11.5px; color: var(--ink-2); white-space: nowrap;
}
.chip b { color: var(--ink); font-weight: 600; }
.chip .dot { width: 6px; height: 6px; border-radius: 50%; background: #34a853; }
.chip.stale .dot { background: #c7c7c7; }

.badge {
  display: inline-block; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .6px;
  padding: 2px 8px; border-radius: 999px; color: #fff; background: var(--planned); white-space: nowrap;
}
.badge.published { background: var(--published); }
.badge.in-progress { background: var(--progress); }

.legend-status { display: flex; flex-wrap: wrap; gap: 12px; color: var(--muted); font-size: 12px; margin-top: 6px; }
.sw { display: inline-block; width: 18px; height: 4px; border-radius: 2px; margin-right: 6px; vertical-align: middle; }
.sw-published { background: var(--published); }
.sw-progress { background: var(--progress); }
.sw-planned { background: repeating-linear-gradient(90deg, var(--planned) 0 5px, transparent 5px 8px); }

/* ---------- Detail ---------- */
.back-btn { background: none; border: 0; color: var(--accent); padding: 0; margin-bottom: 12px; font-weight: 600; }
.detail-head h2 { margin: 8px 0 2px; font-size: 19px; line-height: 1.25; }
.detail-head p { margin: 0; }
.limits { margin-top: 6px !important; font-size: 12.5px; color: var(--ink-2); }
.note {
  background: #eef6f9; border: 1px solid #cfe5ee; border-radius: 8px; padding: 9px 11px;
  font-size: 12.5px; color: var(--ink-2); margin-top: 12px;
}
.block { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 12px; }
.block-title { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--muted); font-weight: 600; margin-bottom: 8px; }
.block-title-row { display: flex; justify-content: space-between; align-items: baseline; }
.link-btn { background: none; border: 0; color: var(--accent); font-weight: 600; font-size: 12.5px; padding: 0; }
.link-btn:disabled { color: var(--muted); cursor: default; }

.gage-list { display: grid; gap: 6px; }
.gage-row {
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  background: var(--bg); border-radius: 8px; padding: 8px 10px;
}
.gage-row .g-name { font-size: 12.5px; font-weight: 500; }
.gage-row .g-id { font-size: 11px; color: var(--muted); }
.gage-row .g-val { text-align: right; white-space: nowrap; }
.gage-row .g-q { font-weight: 700; font-size: 14px; }
.gage-row .g-h { font-size: 11.5px; color: var(--muted); }

.axis { margin-bottom: 12px; }
.axis-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.axis-label { font-weight: 600; font-size: 13px; }
.axis-value { font-weight: 700; font-size: 16px; color: var(--accent-2); white-space: nowrap; }
.axis-sub { font-size: 11.5px; color: var(--muted); margin-bottom: 4px; }
.axis input[type=range] { width: 100%; accent-color: var(--accent); }
.axis-ticks { display: flex; justify-content: space-between; font-size: 10.5px; color: var(--muted); margin-top: -2px; }
.axis-now { font-size: 11.5px; color: var(--ink-2); margin-top: 3px; }
.axis-now b { color: var(--published); }
.scenario-status { font-size: 12px; color: var(--muted); min-height: 16px; }
.scenario-status.warn { color: var(--danger); }

.depth-legend { display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px 10px; margin-bottom: 10px; }
.depth-legend div { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.depth-legend i { width: 16px; height: 12px; border-radius: 3px; flex: none; }
.row-control { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--ink-2); }
.row-control input { flex: 1; accent-color: var(--accent); }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

.meta div { display: flex; justify-content: space-between; gap: 10px; font-size: 12.5px; padding: 3px 0; }
.meta span { color: var(--muted); }
.meta b { font-weight: 500; text-align: right; }

.side-foot {
  border-top: 1px solid var(--line); padding: 10px 18px; font-size: 11.5px; color: var(--muted); background: #fbfcfd;
}

/* ---------- Map controls ---------- */
.map-controls {
  position: absolute; top: 12px; right: 12px; z-index: 800;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.basemap-switch { display: flex; background: #fff; border-radius: 8px; box-shadow: var(--shadow); overflow: hidden; }
.basemap-switch button { border: 0; background: #fff; padding: 7px 11px; font-size: 12.5px; color: var(--ink-2); }
.basemap-switch button + button { border-left: 1px solid var(--line); }
.basemap-switch button.active { background: var(--ink); color: #fff; }
.toggle {
  display: flex; align-items: center; gap: 7px; background: #fff; border-radius: 8px; box-shadow: var(--shadow);
  padding: 6px 10px; font-size: 12.5px; color: var(--ink-2); cursor: pointer; user-select: none;
}
.toggle input { accent-color: var(--accent); margin: 0; }
.fema-legend {
  position: absolute; bottom: 26px; right: 12px; z-index: 800; background: #fff; border-radius: 8px; box-shadow: var(--shadow);
  padding: 6px 10px; font-size: 12px; display: flex; align-items: center; gap: 7px;
}
.fema-legend i { width: 16px; height: 12px; border-radius: 2px; background: rgba(0, 120, 255, .35); border: 1px solid rgba(0,90,200,.6); }

/* Leaflet bits */
.leaflet-interactive:focus, .leaflet-container path:focus { outline: none; }
.leaflet-container { font-family: inherit; }
.leaflet-tooltip.reach-tip { font-size: 12.5px; font-weight: 600; border-radius: 6px; box-shadow: var(--shadow); }
.gage-icon {
  width: 14px; height: 14px; border-radius: 3px; background: #fff; border: 2.5px solid var(--ink);
  transform: rotate(45deg); box-shadow: 0 1px 3px rgba(0,0,0,.35);
}
.popup h4 { margin: 0 0 4px; font-size: 13.5px; }
.popup .p-row { display: flex; justify-content: space-between; gap: 14px; font-size: 12.5px; }
.popup .p-row b { font-weight: 700; }
.popup .p-foot { margin-top: 6px; font-size: 11px; color: var(--muted); }
.reach-label {
  background: rgba(255,255,255,.92); border: 1px solid var(--line); border-radius: 6px; padding: 2px 7px;
  font-size: 11.5px; font-weight: 600; color: var(--ink); white-space: nowrap; box-shadow: var(--shadow);
}

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 2000; background: rgba(12, 26, 40, .55);
  display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal-card {
  background: #fff; border-radius: 14px; max-width: 620px; width: 100%; max-height: 88vh; overflow-y: auto;
  padding: 24px 26px; position: relative; box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.modal-card h2 { margin: 0 0 10px; font-size: 20px; }
.modal-card h3 { font-size: 14px; margin: 18px 0 6px; }
.modal-card ul { padding-left: 20px; margin: 6px 0; }
.modal-card li { margin-bottom: 6px; }
.modal-x { position: absolute; top: 10px; right: 12px; border: 0; background: none; font-size: 26px; color: var(--muted); line-height: 1; }
.modal-actions { display: flex; justify-content: flex-end; margin-top: 16px; }
.primary-btn { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 9px 18px; font-weight: 600; }
.primary-btn:hover { background: var(--accent-2); }
.status-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.status-table td { padding: 5px 4px; border-bottom: 1px solid var(--line); }
.status-table td:last-child { text-align: right; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  :root { --topbar-h: 54px; }
  .brand-text h1 { font-size: 14px; }
  .brand-org { display: none; }
  .search input { width: 150px; }
  .nav-btn { padding: 5px 8px; font-size: 12.5px; }
  .layout { flex-direction: column-reverse; }
  .map-wrap { flex: 1; min-height: 0; }
  .sidebar {
    width: 100%; height: 46%; border-right: 0; border-top: 1px solid var(--line);
    border-radius: 14px 14px 0 0; box-shadow: 0 -4px 16px rgba(0,0,0,.08); transition: height .2s;
  }
  .sidebar.collapsed { height: 64px; }
  .sheet-handle {
    display: flex; justify-content: center; align-items: center; border: 0; background: none; padding: 8px 0 2px; flex: none;
  }
  .sheet-handle span { width: 42px; height: 5px; border-radius: 3px; background: #c9d4dd; }
  .side-foot { display: none; }
  .map-controls { top: 8px; right: 8px; }
  .basemap-switch button { padding: 6px 8px; }
}
@media (max-width: 480px) {
  .topnav .nav-btn[data-open="aboutModal"] { display: none; }
  .search input { width: 120px; }
}
