/* ============================================================
 * Sydney Dive Conditions, dark ocean theme
 * Tokens validated against WCAG/CVD (see README → design notes)
 * ============================================================ */

:root {
  --page: #0a0f16;
  --surface: #121a24;
  --raised: #1a2431;
  --border: rgba(255, 255, 255, 0.10);
  --ink: #f2f6fa;
  --ink-2: #b8c4d0;
  --muted: #8394a5;
  --grid: #223041;
  --axis: #2c3b4e;
  --accent: #3987e5;
  --good: #34c163;
  --fair: #ffc233;
  --poor: #ff9166;
  --nogo: #e85c5c;
  --score-ink: #12242f;
  color-scheme: dark;
  --banner-bg: #3a2a12;
  --banner-ink: #ffd9a0;
  --banner-border: rgba(250, 178, 25, 0.35);
  --warn-tint: rgba(250, 178, 25, 0.16);
  --warn-ink: #ffd27a;
  --wreck-tint: rgba(57, 135, 229, 0.18);
  --wreck-ink: #9ec5f4;
  --danger-tint: rgba(208, 59, 59, 0.12);
  --danger-border: rgba(208, 59, 59, 0.35);
  --danger-ink: #ffb9b9;
  --legend-bg: rgba(10, 15, 22, 0.88);
  --rain-ink: #86b6ef;
  --radius: 10px;
  --sans: system-ui, -apple-system, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --score-ink: rgba(15, 26, 36, 0.78);
  --page: #f2f5f8;
  --surface: #ffffff;
  --raised: #e7edf3;
  --border: rgba(16, 32, 46, 0.13);
  --ink: #12222f;
  --ink-2: #3e5468;
  --muted: #5d7386;
  --grid: #dde5ec;
  --axis: #c3cfda;
  --accent: #2a78d6;
  --banner-bg: #fdf1dc;
  --banner-ink: #7a5200;
  --banner-border: rgba(160, 110, 0, 0.3);
  --warn-tint: rgba(250, 178, 25, 0.22);
  --warn-ink: #7a5200;
  --wreck-tint: rgba(42, 120, 214, 0.13);
  --wreck-ink: #1c5cab;
  --danger-tint: rgba(208, 59, 59, 0.08);
  --danger-border: rgba(208, 59, 59, 0.3);
  --danger-ink: #a02222;
  --legend-bg: rgba(255, 255, 255, 0.92);
  --rain-ink: #1c5cab;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--page);
  display: flex;
  flex-direction: column;
  /* identical glyph weight in both themes, macOS subpixel smoothing otherwise
     renders light-on-dark heavier, which reads as a tiny layout shift on toggle */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* identical scrollbar geometry in both themes (kills theme-toggle reflow) */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--grid);
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover { background-color: var(--muted); background-clip: padding-box; }
* { scrollbar-width: thin; scrollbar-color: var(--grid) transparent; }

/* ---------------- header ---------------- */

header.app-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--page);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 9px; }
.brand .logo { width: 27px; height: 27px; flex: none; }
.brand h1 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: 0.2px; }
.brand .tagline { align-self: baseline; padding-top: 4px; }
.brand .tagline { color: var(--muted); font-size: 12.5px; }
.head-spacer { flex: 1; }
.head-stat { color: var(--ink-2); font-size: 13px; }
#updated { color: var(--muted); font-size: 12.5px; }

.icon-btn {
  background: var(--raised);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.icon-btn:hover { background: var(--grid); }

/* ---------------- toolbar (the one filter row) ---------------- */

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: thin;
}
.chip-row { display: flex; gap: 6px; }
.day-chip, .type-chip {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.day-chip { display: inline-flex; align-items: center; gap: 7px; }
.day-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.day-chip.active, .type-chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
.day-chip:hover:not(.active), .type-chip:hover:not(.active) { background: var(--raised); }
/* fixed box: the ◐/☀/☾ glyphs have different font metrics and would
   otherwise change the button height and shift the whole header */
#theme-toggle {
  width: 38px;
  height: 30px;
  padding: 0;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.day-star { margin-left: 2px; font-size: 10px; opacity: 0.9; }
.toolbar-sep { width: 1px; align-self: stretch; background: var(--border); flex: none; }

/* ---------------- layout ---------------- */

.app-main {
  flex: 1;
  display: grid;
  grid-template-columns: 370px 1fr;
  min-height: 0;
  position: relative;
  transition: opacity 0.25s;
}
body.refreshing .app-main { opacity: 0.6; }

/* loading spinner: pill over the map + spinning refresh glyph */
.loader-pill {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1300;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 15px;
  font-size: 12.5px;
  color: var(--ink-2);
  align-items: center;
  gap: 7px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}
body.refreshing .loader-pill { display: inline-flex; }
.rfx { display: inline-block; }
body.refreshing .rfx { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { body.refreshing .rfx { animation: none; } }

#banner {
  background: var(--banner-bg);
  color: var(--banner-ink);
  border-bottom: 1px solid var(--banner-border);
  padding: 7px 16px;
  font-size: 13px;
}

/* ---------------- sidebar ---------------- */

.sidebar {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--page);
}
.sidebar-controls {
  padding: 10px 12px 8px;
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border);
}
#search {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  min-width: 0;
}
#search::placeholder { color: var(--muted); }
#sort, #area {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--ink-2);
  border-radius: 8px;
  padding: 7px 22px 7px 8px;
  font-size: 13px;
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 13px) 55%, calc(100% - 9px) 55%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
/* the area picker leads the toolbar: same control language, a touch bolder */
#area {
  flex: none;
  color: var(--ink);
  font-weight: 600;
  border-radius: 999px;
  padding: 5px 24px 5px 12px;
  cursor: pointer;
  max-width: 220px;
}
#search { appearance: none; -webkit-appearance: none; }
#sort-dir { width: 34px; padding: 7px 0; text-align: center; flex: none; }
#summary { padding: 8px 14px 0; color: var(--muted); font-size: 12.5px; }
#daybrief {
  padding: 4px 14px 7px;
  color: var(--ink-2);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
#daybrief:empty { display: none; }
.bf-row { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; }
.bf-group { display: inline-flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; }
.bf-group + .bf-group { border-left: 1px solid var(--border); padding-left: 10px; }
.bf-item { display: inline-flex; align-items: baseline; gap: 5px; white-space: nowrap; }
.bf-ico { color: var(--muted); font-size: 10px; }

.bw-box { margin-top: 12px; padding-top: 9px; border-top: 1px solid var(--border); }
.bw-cap { font-size: 11px; color: var(--muted); }

#site-list {
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: 6px 10px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}
.site-card {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  cursor: pointer;
  color: var(--ink);
  display: block;
  width: 100%;
}
.site-card:hover { background: var(--raised); }
.site-card.selected { border-color: var(--accent); }
.site-card.dim { opacity: 0.72; }
.site-card.dim:hover, .site-card.dim.selected { opacity: 1; }
.sc-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sc-name { font-weight: 600; font-size: 13.5px; }
.sc-meta { color: var(--muted); font-size: 12px; margin-top: 3px; }
.lvl-badge {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  font-size: 9.5px;
  letter-spacing: 0.4px;
  color: var(--muted);
  vertical-align: 1px;
}
.sc-stats { color: var(--ink-2); font-size: 12px; margin-top: 5px; }
.empty { color: var(--muted); padding: 18px; text-align: center; }

/* rating chip */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--score-ink);
  border-radius: 999px;
  padding: 3px 9px;
  font-size: 12px;
  flex: none;
}
.chip strong { font-weight: 700; }
.chip-sm { font-size: 11.5px; padding: 2px 8px; }
.chip-empty { background: var(--raised); color: var(--muted); }

/* ---------------- map ---------------- */

#map { min-height: 0; background: var(--page); }

.mk-wrap { background: none; border: none; }
.mk {
  width: 30px; height: 30px;
  color: var(--score-ink);
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.92);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.mk-boat { border-radius: 8px; }
.mk-wreck { border-radius: 7px; transform: rotate(45deg); }
.mk-wreck .mk-num { transform: rotate(-45deg); display: block; }

/* hovered-in-list marker: faint accent ring */
.mk-hover {
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 50%, transparent), 0 1px 4px rgba(0, 0, 0, 0.45);
}

/* selected marker: crisp accent ring, same language as the selected card */
.mk-sel {
  border-color: #fff;
  box-shadow: 0 0 0 2.5px var(--accent), 0 1px 6px rgba(0, 0, 0, 0.5);
}

.basemap-toggle { display: flex; overflow: hidden; border-radius: 6px; }
.bm-btn {
  background: var(--surface);
  color: var(--ink-2);
  border: none;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.bm-btn.active { background: var(--accent); color: #fff; font-weight: 600; }

.map-legend {
  background: var(--legend-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 11.5px;
  color: var(--ink-2);
}
.lg-row { display: flex; align-items: center; gap: 7px; margin: 2px 0; }
.lg-dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.lg-div { height: 1px; background: var(--border); margin: 5px 0; }
.lg-shape {
  width: 10px; height: 10px; flex: none;
  background: var(--muted);
  border: 1.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25);
}
.lg-shore { border-radius: 50%; }
.lg-boat { border-radius: 3px; }
.lg-wreck { border-radius: 2px; transform: rotate(45deg); }
.lg-note { color: var(--muted); margin-top: 5px; font-size: 10.5px; }

/* leaflet chrome on dark */
.leaflet-bar a {
  background: var(--surface);
  color: var(--ink);
  border-bottom-color: var(--border);
}
.leaflet-bar a:hover { background: var(--raised); }
.leaflet-container .leaflet-control-attribution {
  background: var(--legend-bg);
  color: var(--muted);
  font-size: 10px;
}
.leaflet-control-attribution a { color: var(--ink-2); }
.leaflet-tooltip {
  background: var(--raised);
  color: var(--ink);
  border: 1px solid var(--border);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.leaflet-tooltip-top:before { border-top-color: var(--raised); }

/* ---------------- detail drawer ---------------- */

#drawer {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 440px;
  max-width: 100%;
  background: var(--page);
  border-left: 1px solid var(--border);
  transform: translateX(102%);
  transition: transform 0.22s ease;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  box-shadow: -12px 0 32px rgba(0, 0, 0, 0.45);
}
#drawer.open { transform: translateX(0); }
.drawer-bar {
  display: flex;
  justify-content: flex-end;
  padding: 8px 10px 0;
}
#drawer-body {
  overflow-y: auto;
  scrollbar-gutter: stable;
  padding: 0 18px 26px;
  min-height: 0;
}

.dd-head { margin-bottom: 4px; }
.dd-name { font-size: 19px; margin: 2px 0 4px; }
.dd-meta { color: var(--muted); font-size: 12.5px; }
.dd-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.tag {
  background: var(--raised);
  color: var(--ink-2);
  border-radius: 999px;
  padding: 2.5px 9px;
  font-size: 11.5px;
}
.tag-warn { background: var(--warn-tint); color: var(--warn-ink); }
.tag-wreck { background: var(--wreck-tint); color: var(--wreck-ink); }
.tag-season { background: rgba(52, 193, 99, 0.15); color: var(--good); }
:root[data-theme="light"] .tag-season { color: #1e8a44; }

.dd-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 14px;
}
.hero-score { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.hero-num { font-size: 46px; font-weight: 650; line-height: 1; }
.hero-level { font-size: 16px; font-weight: 700; }
.hero-when { color: var(--ink-2); font-size: 12.5px; margin-top: 2px; }
.hero-now { color: var(--muted); font-size: 12px; margin-top: 2px; }

.meter-row { margin: 9px 0; }
.meter-head { display: flex; justify-content: space-between; font-size: 12px; margin-bottom: 4px; }
.meter-label { color: var(--ink-2); }
.meter-val { color: var(--muted); }
.meter-track {
  height: 6px;
  background: var(--raised);
  border-radius: 4px;
  overflow: hidden;
}
.meter-fill { height: 100%; border-radius: 4px; }

.dd-section { margin-top: 20px; }
.dd-h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
  margin: 0 0 9px;
  font-weight: 600;
}

.day-strip {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 5px;
}
.ds-cell {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 3px 6px;
  text-align: center;
  cursor: pointer;
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}
.ds-cell:hover { background: var(--raised); }
.ds-cell.active { border-color: var(--accent); }
.ds-day { font-size: 11px; color: var(--ink-2); font-weight: 600; }
.ds-cell .chip-sm { padding: 1px 6px; font-size: 10.5px; gap: 3px; }
.ds-cell .chip-sm span { display: none; }         /* number + colour + word is too much at this size; word lives in the big chip */
.ds-stat { font-size: 10px; color: var(--muted); font-variant-numeric: tabular-nums; }
.ds-rain { color: var(--rain-ink); }

.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.tile-label { color: var(--muted); font-size: 11.5px; display: flex; align-items: baseline; gap: 7px; }
.tile-ico { font-size: 14.5px; opacity: 0.9; color: var(--ink-2); }
.tile-value { font-size: 19px; font-weight: 650; margin-top: 2px; }
.tile-sub { color: var(--muted); font-size: 11.5px; margin-top: 1px; }

.chart-box { position: relative; }
.chart-wrap { position: relative; outline-offset: 4px; }
.chart-panel { margin-bottom: 8px; }
.chart-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 2px; }
.chart-title { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.chart-sub { font-size: 11px; color: var(--muted); }
.chart-svg { display: block; width: 100%; height: auto; }
.chart-svg text { font-family: var(--sans); }
.tnum { font-variant-numeric: tabular-nums; }

.chart-tip {
  position: absolute;
  top: 8px;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  pointer-events: none;
  z-index: 5;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.5);
  min-width: 110px;
}
.tip-time { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.tip-row { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 2px 0; }
.tip-row strong { color: var(--ink); font-weight: 700; }
.tip-lab { color: var(--muted); font-size: 11px; }
.tip-key { width: 14px; height: 3px; border-radius: 2px; flex: none; }

.tide-note {
  background: var(--warn-tint);
  border: 1px solid var(--banner-border);
  color: var(--warn-ink);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 12.5px;
  margin: 0 0 8px;
}
.tide-events { color: var(--ink-2); font-size: 12px; margin-top: 2px; }

.dd-blurb { color: var(--ink-2); font-size: 13.5px; margin: 0 0 10px; }
.dd-dl { display: grid; grid-template-columns: 84px 1fr; gap: 6px 10px; margin: 0; font-size: 12.5px; }
.dd-dl dt { color: var(--muted); }
.dd-dl dd { margin: 0; color: var(--ink-2); }
.dd-links { margin-top: 16px; display: flex; flex-direction: column; gap: 8px; }
.link-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--raised);
  border: 1px solid var(--border);
  color: var(--ink);
  text-decoration: none;
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 13px;
}
.link-ico { color: var(--muted); font-size: 15px; line-height: 1; }
.link-btn:hover { background: var(--grid); }

/* ---------------- about dialog ---------------- */

dialog#about {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: 14px;
  max-width: 620px;
  width: calc(100vw - 48px);
  padding: 22px 24px;
}
dialog#about::backdrop { background: rgba(4, 8, 13, 0.7); }
.about-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
#about h2 { margin: 0; font-size: 18px; }
#about h3 { font-size: 13px; margin: 16px 0 6px; color: var(--ink-2); }
#about p, #about li { color: var(--ink-2); font-size: 13.5px; }
.model-detail { margin: 10px 0 4px; }
.model-detail summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.model-detail ul { margin-top: 8px; }
.model-detail li { margin-bottom: 6px; }
#about .disclaimer {
  background: var(--danger-tint);
  border: 1px solid var(--danger-border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--danger-ink);
}

#boot-errors { display: none; }

/* ---------------- responsive ---------------- */

@media (max-width: 920px) {
  .app-main { grid-template-columns: 1fr; grid-template-rows: 46vh 1fr; }
  .sidebar { order: 2; border-right: none; border-top: 1px solid var(--border); }
  #map { order: 1; }
  #drawer { position: fixed; width: 100%; }
  .brand .tagline { display: none; }

  .map-legend {
    display: grid;
    grid-template-columns: auto auto;
    gap: 0 12px;
    padding: 6px 9px;
    font-size: 10.5px;
  }
  .lg-note { grid-column: 1 / -1; margin-top: 3px; }
}
