/* ── Palette ─────────────────────────────────────────────── */
:root {
  /* Riverknowing typography (Brand Spec v1.2): Lora titles, IBM Plex Sans UI */
  --font-ui:    "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-title: "Lora", Georgia, "Times New Roman", serif;

  /* Riverknowing brand palette (Visual Brand Master Spec v1.2). All text pairs
     below are WCAG-AA verified. */
  --bg:            #F3EFE7;  /* Warm Paper */
  --ink:           #252829;  /* Near-black — body text */
  --muted:         #526B7A;  /* Slate Blue — 4.9:1 on Warm Paper */
  --river:         #17324D;  /* River Ink — links, primary */
  --veg:           #66725A;  /* Living Moss — ecological accent */
  --veg-light:     #8A9580;
  --accent:        #A45F48;  /* River Clay — sparing highlight */
  --accent-hover:  #B5715A;
  --accent-active: #8C4E3B;
  --panel:         #F8F5EF;  /* Warm Paper, a touch lighter */
  --border:        #E2DBCC;

  --sb-bg:         #17324D;  /* River Ink */
  --sb-bg2:        #1E4063;
  --sb-border:     #2C4C69;
  --sb-text:       #F3EFE7;  /* Warm Paper — 11.5:1 on River Ink */
  --sb-muted:      #9FB4C5;  /* 6.1:1 on River Ink */
  --sb-label:      #93A9BC;  /* 5.4:1 on River Ink */
  --sb-green:      #66725A;  /* Living Moss accent (white text on it) */
  --sb-green-dim:  #566149;
  --sb-tog-off:    #2C4C69;

  --sb-width:      280px;
  --detail-width:  320px;
  --transition:    0.22s ease;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

/* Visible keyboard focus for all interactive elements (accessibility) */
:focus-visible { outline: 2px solid var(--river); outline-offset: 2px; border-radius: 2px; }

/* Lora on titles; IBM Plex Sans (via body) everywhere else */
#sidebar-brand h1,
#welcome-inner h2,
#submit-dialog-inner h2,
#detail-content h3,
.popup-title {
  font-family: var(--font-title);
  font-weight: 600;
  letter-spacing: 0;
}

/* Respect users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

html, body {
  height: 100%;
  font-family: var(--font-ui);
  background: var(--sb-bg);
  color: var(--sb-text);
  overflow: hidden;
}

/* ── Desktop layout: sidebar | map | detail ──────────────── */
#layout {
  display: flex;
  height: 100vh;
  height: 100dvh; /* dynamic viewport: adjusts as mobile browser chrome shows/hides */
  width: 100vw;
  overflow: hidden;
}

/* ── Left sidebar ────────────────────────────────────────── */
#sidebar {
  width: var(--sb-width);
  flex-shrink: 0;
  background: var(--sb-bg);
  border-right: 1px solid var(--sb-border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition);
  position: relative;
  z-index: 10;
}
#sidebar.collapsed { width: 0; }

/* Scrollable body of sidebar */
#sidebar > .sec,
#sidebar > #sidebar-footer {
  flex-shrink: 0;
}
#sidebar {
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--sb-border) transparent;
}

/* Brand block */
#sidebar-brand {
  padding: 1rem 1rem 0.9rem 1.1rem;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
  position: relative;
  min-width: var(--sb-width); /* prevent text wrapping during collapse */
}
#sidebar-brand h1 {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--sb-text);
  margin: 0 2rem 3px 0;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
#sidebar-subtitle {
  font-size: 0.73rem;
  color: var(--sb-muted);
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#sidebar-collapse {
  position: absolute;
  top: 0.8rem;
  right: 0.6rem;
  width: 24px;
  height: 24px;
  background: var(--sb-bg2);
  border: 1px solid var(--sb-border);
  border-radius: 4px;
  color: var(--sb-muted);
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
}
#sidebar-collapse:hover { color: var(--sb-text); }

/* Single sidebar tab — rides the sidebar's outer edge, fixed to the viewport */
#sidebar-tab {
  position: fixed;
  top: 50%;
  left: var(--sb-width);
  transform: translateY(-50%);
  z-index: 900;
  width: 22px;
  height: 48px;
  background: var(--sb-bg);
  border: 1px solid var(--sb-border);
  border-left: none;
  border-radius: 0 6px 6px 0;
  color: var(--sb-muted);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: left var(--transition);
}
#sidebar-tab:hover { color: var(--sb-text); }
#sidebar.collapsed ~ #sidebar-tab { left: 0; }

/* ── Section blocks ─────────────────────────────────────── */
.sec { border-bottom: 1px solid var(--sb-border); min-width: var(--sb-width); }
.sec-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  background: none;
  border: none;
  color: var(--sb-label);
  font-size: 0.73rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: left;
  transition: color 0.15s;
  white-space: nowrap;
}
.sec-head:hover { color: var(--sb-text); }
.sec-icon  { font-size: 0.82rem; flex-shrink: 0; }
.sec-label { flex: 1; }
.sec-caret { font-size: 0.65rem; transition: transform 0.2s; display: inline-block; }
.sec.collapsed .sec-caret { transform: rotate(-90deg); }
.sec-body  { padding: 0.3rem 1rem 0.7rem; }
.sec.collapsed .sec-body { display: none; }

/* ── Layer rows ─────────────────────────────────────────── */
.layer-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.38rem 0;
}
.layer-name   { flex: 1; font-size: 0.8rem; color: var(--sb-text); white-space: nowrap; }
.layer-count  {
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--sb-bg2);
  color: var(--sb-green);
  border-radius: 999px;
  padding: 1px 6px;
  min-width: 22px;
  text-align: center;
}
.layer-count:empty { display: none; }

/* Toggle switch */
.toggle { cursor: pointer; flex-shrink: 0; }
/* Visually hidden but still keyboard-focusable (display:none would drop it from
   tab order); focus ring is drawn on the track. */
.toggle input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}
.toggle input:focus-visible + .tog-track { outline: 2px solid var(--river); outline-offset: 2px; }
.tog-track {
  display: block;
  width: 32px; height: 17px;
  background: var(--sb-tog-off);
  border-radius: 9px;
  position: relative;
  transition: background 0.2s;
}
.tog-track::after {
  content: '';
  position: absolute;
  width: 11px; height: 11px;
  background: #fff;
  border-radius: 50%;
  top: 3px; left: 3px;
  transition: transform 0.2s;
}
.toggle input:checked + .tog-track { background: var(--sb-green); }
.toggle input:checked + .tog-track::after { transform: translateX(15px); }

/* ── Chip filters ───────────────────────────────────────── */
.chip-filters { display: flex; flex-wrap: wrap; gap: 4px; padding-top: 2px; }
.chip-filters button {
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--sb-border);
  background: var(--sb-bg2);
  color: var(--sb-muted);
  font-size: 0.73rem;
  cursor: pointer;
  /* Chips show the full canonical term, so long labels must be allowed to wrap
     onto a second line rather than forcing one very wide pill in a fixed-width
     sidebar. "Nature Guardian / Nature on the board" is the case that needs it. */
  white-space: normal;
  text-align: left;
  max-width: 100%;
  line-height: 1.25;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.chip-filters button:hover { border-color: var(--sb-green); color: var(--sb-text); }
.chip-filters button.active {
  background: var(--sb-green);
  color: #fff;
  border-color: var(--sb-green);
  font-weight: 600;
}

/* ── Selected-case label ────────────────────────────────────
   A permanent Leaflet tooltip pinned to the last selected case. Added to the
   map rather than the cluster, so a filter re-render does not remove it. */
.leaflet-tooltip.case-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 230px;
  padding: 5px 6px 5px 9px;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--river);
  border-radius: 4px;
  box-shadow: 0 2px 8px rgba(23, 50, 77, 0.22);
  font-family: var(--font-ui);
  font-size: 0.76rem;
  font-weight: 500;
  line-height: 1.3;
  white-space: normal;
}
.leaflet-tooltip.case-label::before { border-top-color: var(--river); }
.case-label-text { flex: 1; }
.case-label-x {
  flex-shrink: 0;
  align-self: flex-start;
  width: 17px;
  height: 17px;
  padding: 0;
  border: none;
  border-radius: 3px;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  line-height: 15px;
  cursor: pointer;
}
.case-label-x:hover { background: var(--border); color: var(--ink); }

/* ── Export buttons ─────────────────────────────────────── */
.export-note { font-size: 0.72rem; color: var(--sb-muted); margin: 0 0 0.5rem; line-height: 1.4; }
.export-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  background: var(--sb-bg2);
  color: var(--sb-text);
  border: 1px solid var(--sb-border);
  border-radius: 7px;
  padding: 0.45rem 0.6rem;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.export-btn:hover { background: var(--sb-border); border-color: var(--sb-muted); }
.export-btn-wide { width: 100%; flex: none; }
/* Request export is an <a> carrying a mailto:, so strip the link underline and
   keep the button's own colour rather than the visited/link colours. */
a.export-btn { text-decoration: none; color: var(--sb-text); }

/* Shown under the request link for anyone whose mail app does not open. */
.export-fallback { font-size: 0.7rem; color: var(--sb-muted); margin: 0.4rem 0 0; line-height: 1.4; }
.export-link {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--sb-text);
  text-decoration: underline;
  cursor: pointer;
}
.export-link:hover { color: #fff; }
.export-fallback-text {
  width: 100%;
  margin-top: 0.4rem;
  min-height: 6.5rem;
  padding: 0.4rem 0.5rem;
  background: var(--sb-bg2);
  color: var(--sb-text);
  border: 1px solid var(--sb-border);
  border-radius: 6px;
  font: inherit;
  font-size: 0.7rem;
  line-height: 1.4;
  resize: vertical;
}
.export-fallback-text[hidden] { display: none; }

/* Per-case export footer (light detail panel) */
#detail-export {
  margin: 1rem 0 0;
  padding: 0.85rem 0 0;
  border-top: 1px solid var(--border);
}
#detail-export[hidden] { display: none; }
.detail-export-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 6px;
}
.detail-export-buttons { display: flex; gap: 0.5rem; }
.case-btn {
  flex: 1;
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 0.45rem 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.case-btn:hover { border-color: var(--river); color: var(--river); }

/* ── Sidebar footer ─────────────────────────────────────── */
#sidebar-footer {
  margin-top: auto;
  padding: 0.9rem 1rem 1.1rem;
  border-top: 1px solid var(--sb-border);
  flex-shrink: 0;
  min-width: var(--sb-width);
}
#submit-btn {
  width: 100%;
  background: var(--sb-green);
  color: #fff;
  border: none;
  padding: 0.6rem 1rem;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
}
#submit-btn:hover   { background: var(--sb-green-dim); }
#submit-btn.picking { background: var(--accent-active); color: #fff; }
.footer-note { font-size: 0.72rem; color: var(--sb-muted); margin: 0.4rem 0 0; text-align: center; }

/* Partner logos — the pale "sand" EJM mark sits directly on the dark sidebar;
   the Riverknowing logo becomes a round cream badge. */
#sidebar-logos {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  margin-top: 0.95rem;
}
#sidebar-logos a { display: inline-flex; align-items: center; }
.logo-ejm img { height: 54px; width: auto; display: block; }
.logo-rk img {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  object-fit: cover;
  background: #F5F2E4;
  display: block;
}

/* ── Map ────────────────────────────────────────────────── */
#map {
  flex: 1;
  background: var(--bg);
  position: relative;
  min-width: 0;
}

/* ── Right detail panel ─────────────────────────────────── */
#detail-panel {
  width: var(--detail-width);
  flex-shrink: 0;
  background: var(--panel);
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 1.25rem 1rem 1.5rem;
  position: relative;
  transition: width var(--transition);
  z-index: 10;
}
#detail-panel[hidden] {
  display: none;
}
/* One tab, vertically centred on the panel's left edge, fixed while the panel
   scrolls (replaces the old top-right close button). */
#detail-tab {
  position: fixed;
  top: 50%;
  right: var(--detail-width);
  transform: translateY(-50%);
  z-index: 950;
  width: 22px;
  height: 48px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-right: none;
  border-radius: 6px 0 0 6px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: -2px 0 6px rgba(0,0,0,0.06);
}
#detail-tab:hover { color: var(--river); }
#detail-tab[hidden] { display: none; }

/* Propose addition/adjustment — centred in the panel */
.propose-edit-btn { display: block; margin: 0.9rem auto 0; }

/* ── Search ─────────────────────────────────────────────── */
#search-btn {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 600;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.42rem 0.9rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.12);
}
#search-btn:hover { border-color: var(--river); color: var(--river); }
#search-panel {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  width: min(460px, calc(100% - 28px));
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(0,0,0,0.22);
  padding: 0.6rem;
}
#search-panel[hidden] { display: none; }
#search-input {
  width: calc(100% - 34px);
  padding: 0.5rem 0.7rem;
  font-size: 0.9rem;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 7px;
}
#search-close {
  position: absolute;
  top: 0.72rem;
  right: 0.7rem;
  width: 26px; height: 26px;
  background: none; border: none;
  font-size: 1.15rem; line-height: 1;
  color: var(--muted); cursor: pointer;
}
#search-results { list-style: none; margin: 0.4rem 0 0; padding: 0; max-height: 46vh; overflow-y: auto; }
#search-results li { margin: 0; }
#search-results button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; border-radius: 6px;
  padding: 0.45rem 0.55rem; cursor: pointer; font-family: inherit;
}
#search-results button:hover { background: #ECE5D6; }
.sr-title { display: block; font-size: 0.86rem; font-weight: 600; color: var(--ink); }
.sr-meta  { display: block; font-size: 0.75rem; color: var(--muted); }
.search-empty { padding: 0.5rem 0.55rem; font-size: 0.85rem; color: var(--muted); }
#detail-content img {
  width: 100%;
  border-radius: 8px;
  margin-bottom: 0.75rem;
  display: block;
}
#detail-content h3          { font-size: 1.05rem; margin: 0 0 4px; padding-right: 1.5rem; color: var(--ink); }
#detail-content .popup-meta { margin-bottom: 8px; color: var(--muted); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.02em; }
#detail-content .popup-tags { margin-bottom: 8px; }
#detail-content .popup-synopsis { font-size: 0.95rem; line-height: 1.55; color: var(--ink); margin: 4px 0; }
#detail-content .popup-link { display: inline-block; margin-top: 0.5rem; font-size: 0.8rem; font-weight: 600; color: var(--river); }

/* Totals — reflects filters + toggles */
#total-count {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--sb-muted);
  margin-top: 3px;
  white-space: nowrap;
}

/* Source provenance (always shown, even for single-source cases) */
.source-single, .source-switch-wrap { margin-bottom: 0.85rem; }
.source-single-label {
  display: block;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  margin-bottom: 4px;
}
.source-badge {
  display: inline-block;
  padding: 3px 11px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  color: #fff;
  background: var(--river);
}
.source-badge.src-researched { background: var(--veg); }
.source-badge.src-submission { background: var(--muted); }

/* Form tools (resize + pop-out) */
#form-tools { display: flex; gap: 0.4rem; align-items: center; margin-bottom: 0.5rem; }
#form-tools button {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 6px;
  padding: 3px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
#form-tools button:hover { border-color: var(--river); color: var(--river); }
#form-popout { margin-left: auto; }

/* ── Colour key ─────────────────────────────────────────── */
.key-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  padding: 0.34rem 0.25rem;
  font-size: 0.78rem;
  color: var(--sb-text);
  background: none;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
  transition: background 0.15s, opacity 0.15s;
}
.key-row:hover { background: var(--sb-bg2); }
.key-label { flex: 1; }
.key-tog {
  width: 30px; height: 16px; border-radius: 9px; flex-shrink: 0;
  background: var(--sb-tog-off); position: relative; transition: background 0.2s;
}
.key-tog::after {
  content: ""; position: absolute; width: 11px; height: 11px; border-radius: 50%;
  background: #fff; top: 2.5px; left: 3px; transition: transform 0.2s;
}
.key-row[aria-pressed="true"] .key-tog { background: var(--veg); }
.key-row[aria-pressed="true"] .key-tog::after { transform: translateX(13px); }
.key-row[aria-pressed="false"] .key-dot { opacity: 0.45; }
.key-dot {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(0,0,0,0.28);
}

/* ── Bulleted rights list (researched cases) ────────────── */
.rights-intro { margin-bottom: 2px !important; font-weight: 600; }
.rights-list {
  margin: 4px 0 10px 1.1rem;
  padding: 0;
}
.rights-list li {
  font-size: 0.94rem;
  line-height: 1.5;
  color: var(--ink);
  margin-bottom: 4px;
}

/* Source switch (shown on entries that exist in more than one dataset) */
.source-switch {
  display: inline-flex;
  margin: 0 0 0.85rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.src-btn {
  background: #fff;
  border: none;
  border-right: 1px solid var(--border);
  padding: 4px 13px;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.src-btn:last-child { border-right: none; }
.src-btn.active { background: var(--veg); color: #fff; }
.src-btn:not(.active):hover { background: #F2E8D4; color: var(--ink); }

.source-links { margin-top: 0.7rem; font-size: 0.8rem; color: var(--muted); }
.source-links-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 3px;
}
.source-link-list { list-style: none; margin: 0; padding: 0; }
.source-link-list li { margin: 2px 0; }
.source-link-list a {
  color: var(--river);
  text-decoration: none;
  font-weight: 600;
  word-break: break-word;
}
.source-link-list a:hover { text-decoration: underline; }

/* ── Map state overlays ─────────────────────────────────── */
#empty-state {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 500;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  color: var(--ink);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  text-align: center;
  max-width: 280px;
}
#loading-state {
  position: absolute;
  bottom: 16px; left: 16px;
  z-index: 500;
  background: rgba(23,50,77,0.9);
  border: 1px solid var(--sb-border);
  border-radius: 20px;
  padding: 0.35rem 0.9rem;
  font-size: 0.8rem;
  color: var(--sb-text);
}

/* Mobile filter toggle (hidden on desktop) */
#mobile-filters-btn { display: none; }

/* ── Cluster icons ──────────────────────────────────────── */
/* Override markercluster's default green/yellow/orange size tiers with one
   neutral slate, so cluster colour never reads as a category (green/blue). */
.marker-cluster-small,
.marker-cluster-medium,
.marker-cluster-large { background-color: rgba(82, 107, 122, 0.35); }
.marker-cluster-small div,
.marker-cluster-medium div,
.marker-cluster-large div { background-color: #526B7A; }  /* Slate Blue — neutral aggregate */
.marker-cluster span { color: #fff; font-weight: 700; }

/* ── Leaflet popup tweaks ───────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.popup-preview-img { width: 100%; max-width: 220px; border-radius: 6px; margin-bottom: 6px; display: block; }
.learn-more-btn {
  display: block;
  margin-top: 6px;
  background: var(--sb-green);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
}
.learn-more-btn:hover { background: var(--sb-green-dim); }
.popup-title  { font-weight: 700; font-size: 0.98rem; margin: 0 0 4px; color: var(--ink); }
.popup-tags   { margin-bottom: 6px; }
.popup-tags span {
  display: inline-block;
  background: #ECE5D6;
  color: var(--river);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.72rem;
  font-weight: 600;
  margin: 0 4px 4px 0;
}
.popup-synopsis { font-size: 0.87rem; line-height: 1.4; margin: 6px 0; color: var(--ink); }
.popup-link     { font-size: 0.8rem; font-weight: 600; }

/* Propose edit button */
.propose-edit-btn {
  display: inline-block;
  margin-top: 0.75rem;
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 4px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}
.propose-edit-btn:hover { border-color: var(--accent); color: var(--accent-active); }

/* ── Welcome dialog ─────────────────────────────────────── */
dialog#welcome-dialog {
  border: none;
  border-radius: 12px;
  padding: 0;
  width: min(580px, 94vw);
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}
dialog#welcome-dialog::backdrop { background: rgba(10,20,30,0.6); }
/* Must scroll: the welcome text is long enough to exceed a phone viewport, and
   without this the "Explore the map" button becomes unreachable. */
dialog#welcome-dialog { max-height: 90vh; max-height: 90dvh; overflow-y: auto; }
#welcome-inner { padding: 2rem 2rem 1.5rem; background: var(--panel); border-radius: 12px; }
#welcome-inner h2 { margin: 0 0 0.75rem; font-size: 1.25rem; color: var(--veg); }
#welcome-inner h3 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin: 1.1rem 0 0.3rem; }
#welcome-inner p  { font-size: 0.92rem; line-height: 1.55; margin: 0 0 0.4rem; color: var(--ink); }
#welcome-inner a  { color: var(--river); }
.welcome-sources { margin: 0.3rem 0 0.5rem 1.1rem; }
.welcome-sources li { font-size: 0.9rem; line-height: 1.5; color: var(--ink); margin-bottom: 3px; }
.welcome-actions  { display: flex; align-items: center; justify-content: space-between; margin-top: 1.25rem; gap: 0.75rem; flex-wrap: wrap; }
.welcome-skip     { font-size: 0.82rem; color: var(--muted); display: flex; align-items: center; gap: 0.4rem; cursor: pointer; }
.welcome-btn-primary {
  background: var(--sb-green);
  color: #fff;
  border: none;
  padding: 0.55rem 1.4rem;
  border-radius: 6px;
  font-size: 0.95rem;
  cursor: pointer;
  font-weight: 700;
}
.welcome-btn-primary:hover { background: var(--sb-green-dim); }

/* ── Submit dialog ──────────────────────────────────────── */
/* Freely resizable by dragging the bottom-right corner; the iframe fills
   whatever size the user chooses (the +/- buttons nudge the same value). */
dialog#submit-dialog {
  border: none;
  border-radius: 10px;
  padding: 0;
  width: min(560px, 92vw);
  min-width: 320px;
  min-height: 320px;
  max-width: 98vw;
  max-height: 96vh;
  resize: both;
  overflow: auto;
}
dialog#submit-dialog::-webkit-resizer { background: var(--border); }
dialog#submit-dialog::backdrop { background: rgba(0,0,0,0.4); }
#submit-dialog-inner { padding: 1.25rem 1.5rem; display: flex; flex-direction: column; gap: 0.4rem; background: var(--panel); border-radius: 10px; min-height: 100%; }
/* The iframe grows to fill whatever height the dialog is resized to */
#submit-dialog-inner #tally-frame { flex: 1 1 auto; min-height: 240px; }
#submit-dialog-inner h2 { margin: 0 0 0.25rem; color: var(--ink); }
.dialog-note  { font-size: 0.8rem; color: var(--muted); margin: 0 0 0.5rem; }
.link-btn     { background: none; border: none; padding: 0; color: var(--river); text-decoration: underline; cursor: pointer; font-size: inherit; }
#tally-frame  { width: 100%; height: 60vh; border: 1px solid var(--border); border-radius: 6px; }
#turnstile-gate { padding: 1.5rem 0; text-align: center; }
#turnstile-widget { display: inline-block; min-height: 65px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.75rem; }
.dialog-actions button { padding: 0.5rem 1rem; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; background: var(--panel); color: var(--ink); }

/* Correction reference */
#correction-reference { background: #F2E8D4; border: 1px solid var(--border); border-radius: 6px; padding: 0.6rem 0.85rem 0.5rem; margin-bottom: 0.5rem; }
.correction-intro     { margin: 0 0 0.5rem; font-style: italic; }
#correction-fields    { margin: 0; }
.corr-row { display: flex; gap: 0.5rem; font-size: 0.8rem; padding: 2px 0; border-bottom: 1px solid var(--border); color: var(--ink); }
.corr-row:last-child  { border-bottom: none; }
.corr-row dt { width: 90px; flex-shrink: 0; font-weight: 600; color: var(--muted); }
.corr-row dd { margin: 0; flex: 1; overflow-wrap: anywhere; }

/* ── Mobile ─────────────────────────────────────────────── */
@media (max-width: 720px) {
  #layout {
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }

  /* Map fills screen */
  #map {
    flex: 1;
    min-height: 0;
    order: 1;
  }

  /* Sidebar becomes a slide-up bottom drawer */
  #sidebar {
    order: 2;
    width: 100% !important;   /* override desktop collapsed width:0 */
    height: 50vh;
    max-height: 50vh;
    min-width: unset;
    display: block;           /* simpler than flex for the drawer */
    overflow-y: auto;
    overflow-x: hidden;
    border-right: none;
    border-top: 1px solid var(--sb-border);
    flex-shrink: 0;
    transition: height var(--transition), max-height var(--transition);
  }
  #sidebar.collapsed {
    height: 0;
    max-height: 0;
    overflow: hidden;
  }
  #sidebar-brand {
    min-width: unset;
    padding: 0.65rem 1rem 0.6rem;
  }
  #sidebar-brand h1   { font-size: 0.85rem; white-space: normal; margin-right: 1.8rem; }
  #sidebar-subtitle   { display: none; }
  .sec, .sec-body, #sidebar-footer { min-width: unset; }
  #sidebar-footer { margin-top: 0; }

  /* Desktop sidebar tab not used on mobile (the drawer button replaces it) */
  #sidebar-tab { display: none !important; }
  #search-btn  { top: auto; bottom: 16px; right: 14px; }

  /* Mobile filter toggle button floats over map */
  #mobile-filters-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    background: var(--sb-bg);
    color: var(--sb-text);
    border: 1px solid var(--sb-border);
    border-radius: 999px;
    padding: 0.5rem 1.1rem;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(0,0,0,0.3);
    white-space: nowrap;
  }

  /* Bottom sheet on mobile: the tab sits centred on its top edge */
  #detail-tab {
    top: auto;
    bottom: 65vh;
    right: 50%;
    transform: translateX(50%);
    width: 48px;
    height: 22px;
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    box-shadow: 0 -2px 6px rgba(0,0,0,0.06);
  }

  /* Detail panel: full-width bottom sheet */
  #detail-panel {
    position: fixed;
    bottom: 0; left: 0; right: 0;
    width: 100%;
    height: 65vh;
    border-left: none;
    border-top: 2px solid var(--border);
    border-radius: 14px 14px 0 0;
    z-index: 2000;
    box-shadow: 0 -4px 24px rgba(0,0,0,0.18);
  }

  /* Dialogs full-width on mobile */
  dialog#submit-dialog, dialog#welcome-dialog { width: 96vw; }
  #tally-frame { height: 50vh; }

  /* ── Mobile accessibility ──────────────────────────────
     Touch targets sized for fingers (WCAG 2.5.8 wants ≥24px; 44px is the
     comfortable target), and 16px inputs so iOS Safari doesn't auto-zoom. */
  .chip-filters button {
    min-height: 34px;
    padding: 7px 13px;
    font-size: 0.8rem;
  }
  .key-row { min-height: 44px; padding: 0.5rem 0.35rem; }
  .src-btn { min-height: 40px; padding: 8px 15px; }
  .case-btn, .export-btn, .propose-edit-btn { min-height: 44px; }
  .propose-edit-btn { width: 100%; }
  #form-tools button { min-height: 40px; padding: 8px 13px; }
  #search-close { width: 40px; height: 40px; font-size: 1.3rem; }
  #search-btn { min-height: 40px; padding: 0.5rem 1rem; }
  #search-input { font-size: 16px; padding: 0.6rem 0.7rem; }
  #search-results button { min-height: 46px; }
  #search-results { max-height: 40vh; }

  /* Bottom-sheet grab tab: tall enough to hit reliably */
  #detail-tab { height: 30px; width: 64px; font-size: 1rem; }

  /* Selected-case label: 230px is nearly two thirds of a phone screen, so a
     label on a marker near the edge ran off it, and a long title stacked into a
     column tall enough to leave the top of the map. Cap both. */
  .leaflet-tooltip.case-label { max-width: min(230px, 62vw); }
  .case-label-text {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Keep the two floating map buttons clear of each other */
  #search-btn { bottom: 66px; }
}
