:root {
  --green: #1b7a3d;
  --green-dark: #135c2d;
  --green-bright: #3ca62c; /* TeeHunter wordmark "Tee" */
  --ink-green: #16321f; /* TeeHunter wordmark "Hunter" / mark */
  --green-soft: #e7f3ec;
  --ink: #16241b;
  --muted: #6b7c70;
  --line: #dfe7e1;
  --bg: #f5f8f6;
  --card: #ffffff;
  --warn: #b8761f;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.05);
}

* { box-sizing: border-box; }
/* Ensure the hidden attribute wins over class display rules (e.g. .results). */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 22px; background: #fff; color: var(--ink);
  border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark { width: 42px; height: 42px; flex: none; }
.brand h1 { margin: 0; font-size: 23px; font-weight: 800; letter-spacing: -0.6px; font-style: italic; }
.brand h1 .tee { color: var(--green-bright); }
.brand h1 .hunter { color: var(--ink-green); }
.brand .sub { margin: 1px 0 0; font-size: 9px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--muted); }
.status { display: flex; align-items: center; gap: 14px; }
.meta { font-size: 12px; color: var(--muted); }
.btn-refresh {
  background: var(--green); color: #fff; border: 1px solid var(--green);
  padding: 7px 12px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.btn-refresh:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn-refresh:disabled { opacity: 0.5; cursor: default; }

/* Layout */
.layout { display: grid; grid-template-columns: 280px 1fr; gap: 18px; padding: 18px; align-items: start; }

/* Filters */
.filters {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); position: sticky; top: 84px;
  /* Always independently scrollable on desktop: budget = viewport minus the
     sticky top offset (84px = topbar ~66px + .layout 18px top padding) minus
     an 18px bottom gap so "Clear filters" isn't flush to the screen edge.
     NOTE: overflow-y:auto makes overflow-x compute to auto too, which would
     clip an in-panel dropdown — the search dropdown (item: search) is rendered
     position:fixed (anchored to #query via getBoundingClientRect) OUTSIDE this
     overflow box so it is never clipped. */
  max-height: calc(100vh - 102px);
  overflow-y: auto;
}
.filters::-webkit-scrollbar { width: 8px; }
.filters::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.filters::-webkit-scrollbar-thumb:hover { background: var(--muted); }
/* Mobile: stack to one column and let the filter panel flow naturally.
   Placed AFTER the base .filters rule so these overrides win the cascade —
   media queries add no specificity, so source order decides at <=820px. */
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .filters { position: static; max-height: none; overflow: visible; }
}
.filter-block { margin-bottom: 18px; }
.filter-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.hint { font-size: 11px; color: var(--muted); margin: 6px 0 0; }

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1; padding: 8px 0; border: 1px solid var(--line); background: #fff;
  border-radius: 8px; cursor: pointer; font-size: 14px; color: var(--ink);
}
.seg button.active { background: var(--green); color: #fff; border-color: var(--green); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  padding: 6px 10px; border: 1px solid var(--line); background: #fff;
  border-radius: 999px; cursor: pointer; font-size: 12px; color: var(--ink);
}
.chips button.active { background: var(--green); color: #fff; border-color: var(--green); }

input[type="range"] { width: 100%; accent-color: var(--green); }

/* Scale tick labels under a slider */
.scale { display: flex; justify-content: space-between; margin-top: 7px; font-size: 10px; color: var(--muted); }
.scale span { position: relative; padding-top: 7px; }
.scale span::before { content: ''; position: absolute; top: 0; left: 50%; width: 1px; height: 4px; background: var(--line); }
.scale span:first-child::before { left: 0; }
.scale span:last-child::before { left: auto; right: 0; }

/* Dual-knob range slider (one track, two thumbs, filled middle) */
.range-dual { position: relative; height: 28px; }
.range-track, .range-fill {
  position: absolute; top: 50%; transform: translateY(-50%); height: 4px; border-radius: 2px;
}
.range-track { left: 0; right: 0; background: var(--line); }
.range-fill { background: var(--green); }
.range-dual input[type="range"] {
  position: absolute; top: 0; left: 0; width: 100%; height: 28px; margin: 0;
  background: none; pointer-events: none; -webkit-appearance: none; appearance: none;
}
.range-dual input[type="range"]::-webkit-slider-runnable-track { background: none; border: none; }
.range-dual input[type="range"]::-moz-range-track { background: none; border: none; }
.range-dual input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; pointer-events: auto;
  width: 18px; height: 18px; border-radius: 50%; background: var(--green);
  border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); cursor: pointer; margin-top: -7px;
}
.range-dual input[type="range"]::-moz-range-thumb {
  pointer-events: auto; width: 18px; height: 18px; border-radius: 50%; background: var(--green);
  border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3); cursor: pointer;
}
#query {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}

/* Fuzzy search dropdown + include/exclude chips */
.search-wrap { position: relative; }
/* Rendered position:fixed in JS (anchored to the input) so it escapes the
   .filters overflow:auto box and never gets clipped. Base styling here. */
.search-results {
  position: fixed; z-index: 1500;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 280px; overflow-y: auto;
}
.sr-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 7px 10px; border-bottom: 1px solid var(--line); }
.sr-row:last-child { border-bottom: none; }
.sr-row:hover { background: var(--green-soft); }
.sr-label { font-size: 13px; flex: 1 1 auto; min-width: 0; } /* shrink so the +Include/−Exclude buttons never get pushed off the edge */
.sr-tag { font-size: 9px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-left: 6px; }
.sr-acts { display: flex; gap: 5px; flex: none; }
.sr-acts button { border: 1px solid var(--line); background: #fff; border-radius: 6px; font-size: 11px; padding: 3px 7px; cursor: pointer; color: var(--ink); white-space: nowrap; }
.sr-inc:hover { background: var(--green); color: #fff; border-color: var(--green); }
.sr-exc:hover { background: #fdecec; color: #a13; border-color: #e3b3b3; }
.sr-empty { padding: 10px; font-size: 12px; color: var(--muted); }
.search-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.search-chips:empty { margin-top: 0; }
.search-chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 6px 4px 9px; border-radius: 999px; font-size: 12px; border: 1px solid var(--line); }
.search-chip.chip-include { background: var(--green-soft); color: var(--green-dark); border-color: #bfe0cb; }
.search-chip.chip-exclude { background: #fdecec; color: #a13; border-color: #e8c4c4; }
.search-chip .chip-pre { font-size: 9px; text-transform: uppercase; letter-spacing: .5px; opacity: .75; }
.search-chip .chip-x { border: none; background: none; cursor: pointer; font-size: 14px; line-height: 1; color: inherit; padding: 0 2px; }

.btn-clear {
  width: 100%; padding: 9px; background: #fff; border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; color: var(--muted); font-size: 13px;
}
.btn-clear:hover { color: var(--ink); border-color: var(--muted); }

/* Content */
/* z-index:0 + isolation:isolate confine Leaflet's z-index:1000 control
   containers to the map's own stacking context, BELOW the sticky .topbar (1000). */
#map {
  height: 320px; border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow);
  position: relative; z-index: 0; isolation: isolate;
}
/* !important overrides Leaflet's inline position:relative on the container.
   z-index:2000 (higher specificity than #map) lifts the maximised map + its
   controls above the topbar; isolation keeps the controls compositing on top. */
#map.expanded {
  position: fixed !important; inset: 0; width: 100vw; height: 100vh;
  z-index: 2000; isolation: isolate; border-radius: 0; border: none;
}
body.map-locked { overflow: hidden; }
.map-maximise-btn {
  width: 34px; height: 34px; padding: 0; background: #fff; border: none; border-radius: 6px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3); cursor: pointer; font-size: 17px; line-height: 34px; color: var(--ink);
}
.map-maximise-btn:hover { background: var(--green-soft); }
.map-hint { font-size: 11px; color: var(--muted); margin: 6px 4px 0; }
.results-head { display: flex; align-items: baseline; gap: 12px; margin: 16px 2px 8px; flex-wrap: wrap; }
.count { font-size: 14px; font-weight: 600; }
.selected-course { font-size: 13px; color: var(--green-dark); }
.selected-course a { color: var(--green-dark); cursor: pointer; text-decoration: underline; }
.sort-ctrl { margin-left: auto; font-size: 12px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.sort-ctrl select {
  font-size: 13px; color: var(--ink); padding: 5px 8px; border: 1px solid var(--line);
  border-radius: 8px; background: #fff; cursor: pointer;
}
.attribution { font-size: 11px; color: var(--muted); margin: 0 2px 10px; }
.attribution::first-letter { color: #f4a51c; } /* the ★ */

.results { display: flex; flex-direction: column; gap: 12px; }
.course-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.course-card h3 { margin: 0 0 2px; font-size: 16px; }
.src-badge {
  display: inline-block; font-size: 10px; font-weight: 600; vertical-align: middle;
  padding: 2px 6px; border-radius: 5px; margin-left: 4px; white-space: nowrap;
}
.src-clubmaster { background: #e7f3ec; color: #135c2d; }
.src-digitalwedge { background: #e6eefb; color: #1f4fa3; }
.src-lastminutegolf { background: #fdeede; color: #9a5b00; }
.btn-clubview {
  flex: none; background: var(--green-soft); color: var(--green-dark); border: none; border-radius: 8px;
  padding: 6px 11px; cursor: pointer; font-size: 12px; font-weight: 600; white-space: nowrap;
}
.btn-clubview:hover { background: #d3e9da; }

/* Club view */
#clubHeader { margin-bottom: 16px; }
.btn-back {
  background: #fff; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px;
  cursor: pointer; font-size: 13px; color: var(--ink); margin-bottom: 12px;
}
.btn-back:hover { border-color: var(--green); color: var(--green-dark); }
.cv-name { margin: 0; font-size: 20px; }
.cv-where { margin: 3px 0 8px; font-size: 13px; color: var(--muted); }
.cv-where .rating { color: #b07700; font-weight: 700; }
.cv-where .via { font-size: 11px; color: var(--muted); font-weight: 400; }
.cv-summary { margin: 6px 0 0; font-size: 12px; color: var(--muted); line-height: 1.7; }
.cv-summary a { color: var(--green-dark); }

/* Club detail card (map + identity + contact) at the top of the club view */
#clubDetail {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow); margin-bottom: 14px;
}
.club-map { height: 220px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 12px; }
.cv-contact { margin: 0 0 2px; font-size: 13px; color: var(--ink); display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
.cv-contact a { color: var(--green-dark); text-decoration: none; }
.cv-contact a:hover { text-decoration: underline; }
.cv-contact .cv-addr { color: var(--muted); }
.cv-contact .sep { color: var(--line); margin: 0 2px; }
.hint-inline { font-weight: 400; color: var(--muted); font-size: 11px; }
.day-section { margin-bottom: 14px; }
.day-section:last-child { margin-bottom: 0; }
.day-head { margin: 0 0 9px; font-size: 14px; display: flex; align-items: baseline; gap: 10px; }
.day-count { font-size: 12px; color: var(--muted); font-weight: 400; }
.course-card .where { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.course-card .where .price-low { color: var(--green-dark); font-weight: 600; }
.course-card .where .rating { color: #b07700; font-weight: 700; } /* ★ Google rating */

/* Day separator in the main results when a course spans more than one day. */
.day-sep {
  display: flex; align-items: baseline; gap: 9px;
  font-size: 13px; font-weight: 700; color: var(--ink);
  margin: 16px 0 8px; padding-top: 12px; border-top: 1px solid var(--line);
}
.card-top + .day-sep { border-top: none; padding-top: 0; margin-top: 6px; } /* first day: no divider under the header */

.slot-grid { display: flex; flex-wrap: wrap; gap: 7px; }
/* Compact inline pill: time-only by default; badges/tags appear only on demand. */
.slot {
  display: inline-flex; align-items: center; gap: 5px;
  border: 1px solid var(--line); border-radius: 8px; padding: 5px 9px;
  text-decoration: none; color: var(--ink); background: #fff; line-height: 1;
}
.slot:hover { border-color: var(--green); box-shadow: 0 0 0 2px var(--green-soft); }
.slot .t { font-weight: 700; font-size: 14px; }
.slot .tag9 { font-size: 9px; background: var(--green-soft); color: var(--green-dark); padding: 1px 4px; border-radius: 4px; }
.slot .multi-src { font-size: 9px; color: var(--warn); font-weight: 700; }
.slot-badge { font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 4px; }
.slot-badge.price-b { background: var(--green-soft); color: var(--green-dark); }
.slot-badge.spots-b { background: #eef1f0; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.leaflet-popup-content { font-size: 13px; }
.leaflet-popup-content b { color: var(--green-dark); }
.leaflet-tooltip { font-size: 13px; line-height: 1.4; padding: 6px 9px; }
.leaflet-tooltip b { color: var(--green-dark); }
