:root {
  --bg: #f7f5f0;
  --ink: #1e2a24;
  --ink-muted: #5b6a62;
  --line: #d8d4c8;
  --accent: #2f6b4f;
  --accent-dark: #20503a;
  --accent-soft: #e4efe8;
  --card: #ffffff;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 12px rgba(0, 0, 0, 0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
}

a { color: var(--accent-dark); }

.hero {
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-dark) 100%);
  background-image: url("trout-patterns3.jpg");
  background-size: cover;
  /*background-size: 100% 100%;*/
  color: #fff;
  padding: 2.5rem 1.25rem 1.5rem;
}
.hero-inner { max-width: 1100px; margin: 0 auto; }
.hero h1 { margin: 0 0 0.25rem; font-size: 1.9rem; letter-spacing: -0.01em; }
.hero .tagline { margin: 0 0 1.25rem; opacity: 0.9; }

.summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 0.5rem;
}
.summary-cell {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 0.75rem 1rem;
}
.summary-cell span {
  display: block;
  font-size: 1.4rem;
  font-weight: 600;
}
.summary-cell label {
  display: block;
  font-size: 0.8rem;
  opacity: 0.85;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tabs {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 1.25rem;
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--line);
  margin-top: 1.25rem;
}
.tab {
  background: transparent;
  border: none;
  padding: 0.75rem 1rem;
  font: inherit;
  color: var(--ink-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.active {
  color: var(--accent-dark);
  border-bottom-color: var(--accent);
  font-weight: 600;
}

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.view { display: none; }
.view.active { display: block; }

.view-header { margin-bottom: 1rem; }
.view-header h2 { margin: 0 0 0.25rem; }
.view-header .muted { color: var(--ink-muted); margin: 0 0 0.75rem; }

#waters-search {
  width: 100%;
  max-width: 360px;
  padding: 0.55rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}
#waters-search:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
th, td {
  padding: 0.7rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
}
th {
  background: #faf8f3;
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fbfaf6; }

/* Footer row that lives below the table: sentinel during loading,
   end-marker when we've reached the end, or an inline retry when
   loading failed. The three variants share layout; only the content
   and accents differ. */
.list-footer {
  padding: 0.75rem 1rem;
  background: #faf8f3;
  border-top: 1px solid var(--line);
  font-size: 0.88rem;
  text-align: center;
}
.list-footer.sentinel::before {
  content: '⟳ ';
  display: inline-block;
  animation: list-spin 1.2s linear infinite;
}
@keyframes list-spin {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}
.list-footer.end-marker { letter-spacing: 0.02em; }
.list-footer.error-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  background: #fbefe6;
  color: #7a3e14;
}

/* Reused by inline retry, and previously by the pager (now gone). */
.pager-btn {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.4rem 0.85rem;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}
.pager-btn:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); }
.pager-btn:disabled { opacity: 0.4; cursor: default; }

/* Floating back-to-top button, appears once the user scrolls past a
   threshold (logic in app.js). Sits above most content but below the
   drawer (z-index 1000). */
.back-to-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 900;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 0.55rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
  transition: transform 120ms ease, background 120ms ease;
}
.back-to-top:hover {
  background: var(--accent-dark);
  transform: translateY(-2px);
}
.back-to-top[hidden] { display: none; }

.waters-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.water-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.9rem 1.1rem;
  box-shadow: var(--shadow);
}
.water-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.4rem;
  flex-wrap: wrap;
}
.water-title {
  font-size: 1.05rem;
  font-weight: 600;
}
.water-county {
  color: var(--ink-muted);
  font-size: 0.88rem;
  margin-left: 0.4rem;
  font-weight: 400;
}
.water-meta {
  font-size: 0.85rem;
  color: var(--ink-muted);
}
.water-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.4rem;
}
.date-chip {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 6px;
  font-size: 0.82rem;
  background: #f2efe7;
  color: var(--ink);
  border: 1px solid var(--line);
  font-variant-numeric: tabular-nums;
}
.date-chip.recent {
  background: var(--accent-soft);
  color: var(--accent-dark);
  border-color: #bcd6c6;
  font-weight: 600;
}

.loading, .empty {
  padding: 2rem;
  text-align: center;
  color: var(--ink-muted);
}

footer {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.25rem 2rem;
  color: var(--ink-muted);
  font-size: 0.85rem;
  border-top: 1px solid var(--line);
}

@media (max-width: 640px) {
  .summary { grid-template-columns: repeat(2, 1fr); }
  .hero h1 { font-size: 1.5rem; }
  th, td { padding: 0.55rem 0.7rem; font-size: 0.88rem; }
}

/* ------- Detail drawer (waterbody info) ----------------------------- */

.water-card { cursor: pointer; transition: transform 80ms ease, box-shadow 80ms ease; }
.water-card:hover { transform: translateY(-1px); box-shadow: 0 2px 4px rgba(0,0,0,.05), 0 6px 18px rgba(0,0,0,.06); }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable td:nth-child(2) { color: var(--accent-dark); font-weight: 500; }

.reg-badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 4px;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--accent-soft);
  color: var(--accent-dark);
  margin-left: 0.5rem;
  vertical-align: middle;
  font-weight: 600;
}
.reg-badge.delayed-harvest { background: #f3e6cf; color: #7a5314; }
.reg-badge.artificial-only,
.reg-badge.catch-and-release { background: #e0ecf5; color: #244e72; }

.drawer {
  position: fixed; inset: 0;
  /* Leaflet's internal panes use z-indexes up to 800 (for controls).
     Keep the drawer above all of them so the detail panel overlays
     the map properly when the Map tab is active. */
  z-index: 1000;
  pointer-events: none;
  visibility: hidden;
}
.drawer[aria-hidden="false"] { pointer-events: auto; visibility: visible; }
.drawer-scrim {
  position: absolute; inset: 0;
  background: rgba(18, 28, 22, 0);
  transition: background 180ms ease;
}
.drawer[aria-hidden="false"] .drawer-scrim {
  background: rgba(18, 28, 22, 0.45);
}
.drawer-panel {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: min(560px, 100%);
  background: var(--bg);
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.18);
  transform: translateX(100%);
  transition: transform 220ms ease;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.drawer[aria-hidden="false"] .drawer-panel { transform: translateX(0); }

.drawer-header {
  padding: 1rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.drawer-header h2 { margin: 0; font-size: 1.25rem; }
.drawer-header .muted { margin: 0.1rem 0 0; font-size: 0.9rem; }
.drawer-close {
  position: absolute; top: 0.5rem; right: 0.65rem;
  background: transparent; border: none;
  font-size: 1.8rem; line-height: 1;
  color: var(--ink-muted);
  cursor: pointer;
  padding: 0.2rem 0.55rem;
  border-radius: 6px;
}
.drawer-close:hover { background: rgba(0,0,0,0.05); color: var(--ink); }

.drawer-body {
  overflow-y: auto;
  padding: 1rem 1.25rem 1.5rem;
}

.detail-map {
  width: 100%;
  height: 240px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #e7ecea;
  margin-bottom: 1rem;
  display: none;
}
.detail-map.has-location { display: block; }

.detail-section { margin-bottom: 1.25rem; }
.detail-section h3 { margin: 0 0 0.5rem; font-size: 1rem; }

.detail-field { margin-bottom: 0.75rem; }
.detail-field label {
  display: block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  margin-bottom: 0.2rem;
}
.detail-value {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0.55rem 0.8rem;
  min-height: 1.2rem;
  white-space: pre-wrap;
}
.detail-value.empty { color: var(--ink-muted); font-style: italic; }

.detail-regs-text {
  margin-top: 0.35rem;
  padding: 0.5rem 0.75rem;
  background: #fbfaf6;
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  font-size: 0.88rem;
  line-height: 1.45;
}

.detail-history {
  display: flex; flex-direction: column;
  max-height: 360px; overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
}
.history-row {
  display: flex; justify-content: space-between;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.history-row:last-child { border-bottom: none; }
.history-row .src {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--ink-muted);
  letter-spacing: 0.04em;
}

/* ------- Stream map tab --------------------------------------------- */

.view-map .view-header { margin-bottom: 0.5rem; }

.map-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--card);
  box-shadow: var(--shadow);
  height: calc(100vh - 280px);
  min-height: 480px;
}

.stream-map { width: 100%; height: 100%; }

.map-legend {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 500;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.82rem;
  line-height: 1.5;
  box-shadow: 0 2px 6px rgba(0,0,0,0.08);
  max-width: 280px;
}
.legend-row { display: flex; align-items: center; gap: 0.5rem; }
.legend-row + .legend-row { margin-top: 0.15rem; }
.legend-row em { font-style: normal; font-size: 0.75rem; }
.legend-swatch {
  display: inline-block;
  width: 28px; height: 5px;
  border-radius: 3px;
  flex-shrink: 0;
}
.legend-swatch.base { background: #3b82f6; height: 3px; }
.legend-swatch.dh   { background: #ff1493; opacity: 0.75; }  /* deep pink */
.legend-swatch.sr   { background: #7c3aed; opacity: 0.55; }  /* purple */
.legend-swatch.hs   { background: #ffeb00; opacity: 0.85; }  /* bright yellow */

/* Popup bubbles on the map for stream click. */
.leaflet-popup-content { font-size: 0.92rem; margin: 0.6rem 0.8rem; }
.leaflet-popup-content strong { font-weight: 600; }
.leaflet-popup-content .pop-regs { color: var(--ink-muted); font-size: 0.85rem; display: block; margin-top: 0.25rem; }
.leaflet-popup-content .pop-link {
  display: inline-block;
  margin-top: 0.5rem;
  color: var(--accent-dark);
  cursor: pointer;
  text-decoration: underline;
}
