:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #f0ece4;
  --text: #1f2a30;
  --muted: #5d6b72;
  --border: #ded7cb;
  --accent: #0e7c86;
  --accent-ink: #ffffff;
  --accent-soft: #d8eff0;
  --sand: #c9822b;
  --trail: #3f7d3a;
  --walk: #3567a8;
  --pool: #8a3f9e;
  --good: #2e7d32;
  --warn: #b26a00;
  --bad: #b3261e;
  --star: #e0a100;
  --shadow: 0 2px 10px rgba(30, 40, 45, .10);
  --radius: 12px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12181b; --surface: #1b2327; --surface-2: #232d32; --text: #e7ecee; --muted: #9db0b7;
    --border: #2f3b41; --accent: #3fb6c0; --accent-ink: #062226; --accent-soft: #163a3e;
    --sand: #e3a253; --trail: #7cc174; --walk: #7aa7e6; --pool: #c98ad9;
    --good: #7cc174; --warn: #f0b04f; --bad: #f08a80; --shadow: 0 2px 12px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #12181b; --surface: #1b2327; --surface-2: #232d32; --text: #e7ecee; --muted: #9db0b7;
  --border: #2f3b41; --accent: #3fb6c0; --accent-ink: #062226; --accent-soft: #163a3e;
  --sand: #e3a253; --trail: #7cc174; --walk: #7aa7e6; --pool: #c98ad9;
  --good: #7cc174; --warn: #f0b04f; --bad: #f08a80; --shadow: 0 2px 12px rgba(0,0,0,.4);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
h1, h2, h3, h4 { margin: 0; line-height: 1.2; }

/* ───── App shell ───── */
.app { display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); height: 100dvh; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); z-index: 1000;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; white-space: nowrap; }
.brand .logo { font-size: 22px; }
.topbar .spacer { flex: 1; }
.mode-pill { font-size: 12px; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.mode-pill.cloud { background: var(--accent-soft); color: var(--accent); }

.main { display: grid; grid-template-columns: 400px minmax(0, 1fr); min-height: 0; }
.sidebar, .detail-body, .section, .list, .card { min-width: 0; }
.card h3, .section, .visit { overflow-wrap: anywhere; }
.sidebar { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--bg); position: relative; }
#map { min-height: 0; height: 100%; }

/* ───── Buttons & chips ───── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; text-decoration: none; color: var(--text);
  min-height: 40px;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); }
.icon-btn { border: 0; background: transparent; cursor: pointer; font-size: 20px; padding: 6px; border-radius: 8px; color: var(--text); }
.icon-btn:hover { background: var(--surface-2); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); border-radius: 999px;
  padding: 5px 11px; font-size: 13px; cursor: pointer; user-select: none; white-space: nowrap;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tag { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.tag.paid { background: #fde9cf; color: #7a4a00; }
.tag.free { background: #dcefd9; color: #23561f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .tag.paid { background: #4a3413; color: #f6cf93; } :root:not([data-theme="light"]) .tag.free { background: #1f3a1d; color: #a8dca1; } }
:root[data-theme="dark"] .tag.paid { background: #4a3413; color: #f6cf93; }
:root[data-theme="dark"] .tag.free { background: #1f3a1d; color: #a8dca1; }

/* ───── Filters ───── */
.filters { padding: 12px 16px; display: grid; gap: 8px; border-bottom: 1px solid var(--border); background: var(--surface); }
.filters .row { display: flex; gap: 8px; align-items: center; }
.search { flex: 1; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); min-height: 40px; }
.filters select { padding: 8px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); min-height: 40px; }
.more-filters summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.more-filters .chips { margin-top: 8px; }

/* ───── Tide planner banner ───── */
.planner { margin: 12px 16px 0; padding: 12px; border-radius: var(--radius); background: var(--accent-soft); border: 1px solid var(--border); }
.planner h3 { font-size: 14px; display: flex; gap: 6px; align-items: center; }
.planner .sub { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.planner ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.planner li { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.planner li b { font-variant-numeric: tabular-nums; }

/* ───── List ───── */
.list { overflow-y: auto; padding: 12px 16px 24px; display: grid; gap: 10px; align-content: start; flex: 1; }
.list-heading { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 6px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px; cursor: pointer; display: grid; gap: 6px; box-shadow: var(--shadow);
  text-align: left; width: 100%;
}
.card:hover, .card.active { border-color: var(--accent); }
.card .top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.card h3 { font-size: 15px; }
.card .drive { font-size: 13px; color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }
.card .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; font-size: 12px; color: var(--muted); }
.stars { color: var(--star); letter-spacing: 1px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; }

/* ───── Detail panel ───── */
.detail {
  position: absolute; inset: 0; background: var(--bg); overflow-y: auto; z-index: 500;
  display: none;
}
.detail.open { display: block; }
.detail-head { position: sticky; top: 0; background: var(--surface); border-bottom: 1px solid var(--border); padding: 10px 16px; display: flex; gap: 8px; align-items: center; z-index: 2; }
.detail-head h2 { font-size: 17px; flex: 1; }
.detail-body { padding: 16px; display: grid; gap: 14px; }
.section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: grid; gap: 10px; }
.section > h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.big-stat { display: flex; gap: 18px; flex-wrap: wrap; }
.big-stat div { display: grid; }
.big-stat b { font-size: 22px; font-variant-numeric: tabular-nums; }
.big-stat span { font-size: 12px; color: var(--muted); }
.parking { display: grid; gap: 8px; }
.parking .p { border-left: 3px solid var(--accent); padding-left: 10px; }
.parking .p .cost { font-size: 13px; color: var(--muted); }
.trail { border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: grid; gap: 6px; }
.trail .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.diff { font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 6px; color: #fff; }
.diff.Easy { background: var(--good); }
.diff.Moderate { background: var(--warn); }
.diff.Hard { background: var(--bad); }
.surface-tags { display: flex; gap: 4px; flex-wrap: wrap; }
.amen { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; font-size: 14px; }
ul.plain { margin: 0; padding-left: 18px; }
.subsec { border-top: 1px solid var(--border); padding-top: 10px; display: grid; gap: 4px; }
.subsec h4 { font-size: 14px; }
ul.news li { margin-bottom: 4px; }
.coastwide summary { cursor: pointer; font-size: 13px; color: var(--muted); }
.status-badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.status-badge.partial { background: #fde9cf; color: #7a4a00; }
.status-badge.closed { background: #f9d6d3; color: #8c1d16; }
.status-badge.check { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.status-banner { border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.status-banner.partial { background: #fde9cf; color: #5c3800; }
.status-banner.closed { background: #f9d6d3; color: #6e1510; }
:root[data-theme="dark"] .status-badge.partial, :root[data-theme="dark"] .status-banner.partial { background: #4a3413; color: #f6cf93; }
:root[data-theme="dark"] .status-badge.closed, :root[data-theme="dark"] .status-banner.closed { background: #4d1b17; color: #f6b3ad; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .status-badge.partial, :root:not([data-theme="light"]) .status-banner.partial { background: #4a3413; color: #f6cf93; }
  :root:not([data-theme="light"]) .status-badge.closed, :root:not([data-theme="light"]) .status-banner.closed { background: #4d1b17; color: #f6b3ad; }
}
.note { font-size: 13px; color: var(--muted); }

/* ───── Tides ───── */
.tide-windows { display: grid; gap: 6px; }
.tw { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 8px 10px; border-radius: 10px; background: var(--surface-2); cursor: pointer; border: 1px solid transparent; }
.tw:hover, .tw.sel { border-color: var(--accent); }
.tw .when { font-weight: 600; }
.tw .h { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.tw .go { font-size: 12px; color: var(--muted); grid-column: 1 / -1; }
.rating { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 6px; margin-left: 6px; }
.rating.Excellent { background: var(--good); color: #fff; }
.rating.Good { background: var(--accent); color: var(--accent-ink); }
.rating.Fair { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.tide-chart svg { width: 100%; height: auto; display: block; }
.tide-chart .controls { display: flex; gap: 8px; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.tide-chart input[type="date"] { padding: 6px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }
.hilo { display: flex; gap: 6px; flex-wrap: wrap; font-size: 13px; font-variant-numeric: tabular-nums; }
.hilo span { background: var(--surface-2); border-radius: 8px; padding: 3px 8px; }

/* ───── Visits ───── */
.visit { border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: grid; gap: 6px; }
.visit .row { display: flex; justify-content: space-between; gap: 8px; align-items: center; flex-wrap: wrap; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.media-grid img, .media-grid video { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; background: var(--surface-2); cursor: pointer; }
.revisit-yes { color: var(--good); font-weight: 600; }
.revisit-no { color: var(--bad); font-weight: 600; }

/* ───── Dialog (survey) ───── */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(640px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); background: var(--bg); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(10, 20, 25, .55); }
.dlg-head { position: sticky; top: 0; background: var(--surface); padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 8px; z-index: 1; }
.dlg-head h2 { flex: 1; font-size: 17px; }
.dlg-body { padding: 16px; display: grid; gap: 16px; }
.dlg-foot { position: sticky; bottom: 0; background: var(--surface); padding: 12px 16px; border-top: 1px solid var(--border); display: flex; gap: 8px; justify-content: flex-end; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; margin: 0; display: grid; gap: 10px; background: var(--surface); }
legend { font-weight: 700; padding: 0 6px; }
label.f { display: grid; gap: 4px; font-size: 14px; }
label.f > span { color: var(--muted); font-size: 13px; }
.f input[type="text"], .f input[type="date"], .f input[type="number"], .f textarea, .f select {
  padding: 9px 11px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); width: 100%;
}
.f textarea { min-height: 80px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.star-input { display: flex; gap: 4px; }
.star-input button { font-size: 32px; background: none; border: 0; cursor: pointer; color: var(--border); padding: 0 2px; line-height: 1; }
.star-input button.on { color: var(--star); }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: var(--surface); padding: 8px 14px; cursor: pointer; border-right: 1px solid var(--border); min-height: 38px; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.cond { display: grid; gap: 4px; }
.cond > span { font-size: 13px; color: var(--muted); }
.previews { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 6px; }
.previews .pv { position: relative; }
.previews img, .previews video { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.previews .x { position: absolute; top: 2px; right: 2px; background: rgba(0,0,0,.6); color: #fff; border: 0; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; }
.err { color: var(--bad); font-size: 13px; }

/* Lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); display: none; align-items: center; justify-content: center; z-index: 3000; padding: 16px; }
.lightbox.open { display: flex; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%; border-radius: 8px; }
.lightbox .close { position: absolute; top: 12px; right: 12px; color: #fff; font-size: 28px; background: none; border: 0; cursor: pointer; }

/* Map pins */
.pin { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); border: 2px solid #fff; box-shadow: 0 2px 6px rgba(0,0,0,.35); }
.pin > span { transform: rotate(45deg); font-size: 16px; }
.pin.tidepools { background: var(--pool); }
.pin.beach { background: var(--sand); }
.pin.trail { background: var(--trail); }
.pin.walk { background: var(--walk); }
.pin.custom { background: #555; }
.pin.daytrip { opacity: .6; }
.pin.visited::after { content: "✓"; position: absolute; top: -6px; right: -6px; transform: rotate(45deg); background: var(--good); color: #fff; border-radius: 50%; width: 16px; height: 16px; font-size: 11px; display: grid; place-items: center; border: 1px solid #fff; }
.pin.sel { outline: 3px solid var(--accent); outline-offset: 2px; }
.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(.95) contrast(.9) saturate(.6); }
.leaflet-container { background: var(--surface-2); }
.home-pin { font-size: 26px; filter: drop-shadow(0 2px 3px rgba(0,0,0,.4)); }
.leaflet-popup-content { font: 14px/1.4 system-ui, sans-serif; }
.map-legend { background: var(--surface); color: var(--text); padding: 8px 10px; border-radius: 10px; box-shadow: var(--shadow); font-size: 12px; display: grid; gap: 3px; }
.map-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.add-banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 900; background: var(--text); color: var(--bg); padding: 8px 14px; border-radius: 999px; font-size: 14px; display: none; gap: 10px; align-items: center; }
.add-banner.show { display: flex; }
.map-wrap { position: relative; min-height: 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 4000; opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

/* ───── Mobile ───── */
@media (max-width: 820px) {
  .main { grid-template-columns: minmax(0, 1fr); grid-template-rows: 40dvh minmax(0, 1fr); }
  .topbar { gap: 8px; padding: 8px 12px; }
  .mode-pill { display: none; }
  .brand { font-size: 16px; min-width: 0; overflow: hidden; }
  .filters .row { flex-wrap: wrap; }
  .filters .search { min-width: 0; }
  .map-wrap { order: 1; }
  .sidebar { order: 2; border-right: 0; border-top: 1px solid var(--border); }
  .detail { position: fixed; inset: 0; z-index: 2000; }
  .brand .full { display: none; }
  .grid2 { grid-template-columns: 1fr; }
}
