/* ==========================================================================
   Melbourne Move — mobile-first, works offline-ish, readable on a phone in
   sunlight and on a laptop at night.
   ========================================================================== */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #10151c;
  --text-2: #5b6672;
  --text-3: #8a94a0;

  --accent: #1b5e8c;
  --accent-soft: #e7f0f7;

  /* Verdict / rating scale. Colour-blind safe: blue→amber→red, never red/green. */
  --good: #1a7f5a;
  --good-soft: #e3f4ed;
  --ok: #9a6b12;
  --ok-soft: #fbf1dc;
  --poor: #a8402f;
  --poor-soft: #fbe9e5;

  --shadow: 0 1px 2px rgba(16, 21, 28, 0.06), 0 4px 12px rgba(16, 21, 28, 0.06);
  --shadow-lg: 0 -2px 12px rgba(16, 21, 28, 0.1);

  --radius: 12px;
  --radius-sm: 8px;

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, monospace;

  --header-h: 52px;
  --tabs-h: 46px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116;
    --surface: #161b22;
    --surface-2: #1e242d;
    --border: #2b323c;
    --text: #e8ecf1;
    --text-2: #9aa4b0;
    --text-3: #6b7580;

    --accent: #5ba3d0;
    --accent-soft: #14293a;

    --good: #4cc38a;
    --good-soft: #10261d;
    --ok: #d9a441;
    --ok-soft: #2a2113;
    --poor: #e5715c;
    --poor-soft: #2d1714;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 -2px 16px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior-y: none;
}

/* While the map view is active the page itself must not scroll — otherwise a
   drag on the map bubbles into a page scroll and the map "sticks". */
body.map-active {
  overflow: hidden;
  position: fixed;
  width: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; }
p { margin: 0 0 0.75em; }
a { color: var(--accent); }

/* ---------- Header ---------- */

.header {
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--header-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
  height: calc(var(--header-h) + env(safe-area-inset-top));
}

.header h1 {
  font-size: 15px;
  font-weight: 650;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header .route {
  font-size: 11px;
  color: var(--text-3);
  font-weight: 500;
  white-space: nowrap;
}

/* ---------- Tabs ---------- */

.tabs {
  position: sticky;
  top: calc(var(--header-h) + env(safe-area-inset-top));
  z-index: 39;
  display: flex;
  gap: 2px;
  padding: 0 8px;
  height: var(--tabs-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: 0 0 auto;
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  color: var(--text-2);
  padding: 0 12px;
  height: var(--tabs-h);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab[aria-selected='true'] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* ---------- Views ---------- */

.view { display: none; }
.view.active { display: block; }
.view-pad { padding: 14px; padding-bottom: 40px; }

/* ---------- Map ---------- */

#map {
  width: 100%;
  /* vh first as a fallback, dvh where supported: on iOS Safari 100vh ignores
     the address bar and the map ends up taller than the viewport. */
  height: calc(100vh - var(--header-h) - var(--tabs-h) - env(safe-area-inset-top));
  height: calc(100dvh - var(--header-h) - var(--tabs-h) - env(safe-area-inset-top));
  background: var(--surface-2);
  z-index: 1;
  /* Let the map own all touch gestures in its box. */
  touch-action: none;
}

.leaflet-container { font: inherit; background: var(--surface-2); }
.leaflet-popup-content-wrapper,
.leaflet-popup-tip { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 10px 12px; font-size: 13px; }
.leaflet-bar a {
  background: var(--surface);
  color: var(--text);
  border-bottom-color: var(--border);
}
.leaflet-bar a:hover { background: var(--surface-2); }
.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.75) !important;
  font-size: 10px !important;
}
@media (prefers-color-scheme: dark) {
  .leaflet-control-attribution { background: rgba(0, 0, 0, 0.6) !important; }
  .leaflet-control-attribution a { color: var(--accent) !important; }
  /* No filter hack here: the map swaps to CARTO's real dark basemap instead. */
}

.map-legend {
  background: var(--surface);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  font-size: 11px;
  line-height: 1.55;
  border: 1px solid var(--border);
  max-width: 190px;
}
.map-legend summary {
  cursor: pointer;
  padding: 6px 10px;
  font-size: 10px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-2);
  list-style: none;
}
.map-legend summary::-webkit-details-marker { display: none; }
.map-legend summary::after { content: ' ▾'; color: var(--text-3); }
.map-legend details[open] summary { border-bottom: 1px solid var(--border); margin-bottom: 5px; }
.map-legend details[open] summary::after { content: ' ▴'; }
.map-legend details > div { padding: 0 10px; }
.map-legend details > div:last-child { padding-bottom: 7px; }
.map-legend b {
  display: block;
  margin: 6px 0 3px;
  padding: 0 10px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
}
.map-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: -1px;
}

/* Map pins: circular badge + white glyph. Inline SVG rather than emoji so they
   render identically everywhere and can take theme colours. */
.pin {
  background: var(--pin);
  border-radius: 50%;
  border: 1.5px solid #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s ease;
}
.pin svg {
  width: 62%;
  height: 62%;
  fill: #fff;
  display: block;
}
.leaflet-marker-icon:hover .pin { transform: scale(1.25); z-index: 500; }

.cbd-chip {
  background: #10151c;
  color: #fff;
  font: 600 9px/1 var(--font);
  padding: 4px 6px;
  border-radius: 4px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  text-align: center;
}

.leaflet-tooltip {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 12px;
  padding: 4px 8px;
}
.leaflet-tooltip-top::before { border-top-color: var(--border); }

/* Locator map in the suburb sheet — answers "where actually is this?" */
.sheet-map {
  flex: 0 0 auto;
  height: 150px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.sheet-map .leaflet-container { background: var(--surface-2); }

/* Layer toggles (primary / secondary / unis) */
.leaflet-control-layers {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.leaflet-control-layers-expanded { padding: 8px 10px; font-size: 12px; }
.leaflet-control-layers-toggle {
  background-color: var(--surface);
  border-radius: var(--radius-sm);
}
.leaflet-control-layers label { display: flex; align-items: center; gap: 6px; margin: 3px 0; }
.leaflet-control-layers input { accent-color: var(--accent); }

/* ---------- Bottom sheet ---------- */

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  max-height: 82dvh;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg);
  transform: translateY(101%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  display: flex;
  flex-direction: column;
  overscroll-behavior: contain;
}
.sheet.open { transform: translateY(0); }

.sheet-grab {
  flex: 0 0 auto;
  padding: 8px 0 4px;
  display: flex;
  justify-content: center;
  cursor: grab;
  touch-action: none;
}
.sheet-grab::before {
  content: '';
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}

.sheet-head {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 2px 16px 10px;
  border-bottom: 1px solid var(--border);
}
.sheet-head h2 { font-size: 19px; }
.sheet-head .sub { font-size: 12px; color: var(--text-2); margin-top: 2px; }
.sheet-close {
  margin-left: auto;
  appearance: none;
  border: 0;
  background: var(--surface-2);
  color: var(--text-2);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  flex: 0 0 auto;
}

.sheet-body {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px 16px calc(24px + env(safe-area-inset-bottom));
  overscroll-behavior: contain;
}

@media (min-width: 820px) {
  .sheet {
    left: auto;
    right: 16px;
    bottom: 16px;
    top: calc(var(--header-h) + var(--tabs-h) + 16px);
    width: 400px;
    max-height: none;
    border-radius: var(--radius);
    transform: translateX(calc(100% + 24px));
  }
  .sheet.open { transform: translateX(0); }
}

/* ---------- Metric rows (the Domain-style table) ---------- */

.metrics { border-top: 1px solid var(--border); }
.metric {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 10px 2px;
  border-bottom: 1px solid var(--border);
}
.metric dt {
  /* Fixed-ish label column. Previously flex:1 1 auto, which let a long source
     line in the value push the number off-screen entirely (SEIFA row). */
  flex: 0 1 42%;
  font-size: 13px;
  color: var(--text-2);
  margin: 0;
  overflow-wrap: break-word;
}
.metric dd {
  flex: 1 1 auto;
  min-width: 0; /* lets the source line wrap instead of forcing overflow */
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  text-align: right;
  font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
}
.metric dd small {
  display: block;
  font-weight: 400;
  font-size: 10.5px;
  line-height: 1.35;
  color: var(--text-3);
  margin-top: 1px;
  /* Source strings are long and data-driven — clamp so one verbose citation
     can't turn a table row into a paragraph. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}
.card > h3 { font-size: 15px; margin-bottom: 8px; }

.suburb-card {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
.suburb-card:active { background: var(--surface-2); }

.suburb-card-top {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 6px;
}
.suburb-card-top h3 { flex: 1; font-size: 16px; }
.suburb-card-top .price { font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 8px; }
.chip {
  font-size: 11px;
  font-weight: 550;
  padding: 3px 7px;
  border-radius: 5px;
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.poor { background: var(--poor-soft); color: var(--poor); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Filters ---------- */

.filters {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 12px 14px;
  scrollbar-width: none;
  position: sticky;
  top: calc(var(--header-h) + var(--tabs-h) + env(safe-area-inset-top));
  background: var(--bg);
  z-index: 20;
  border-bottom: 1px solid var(--border);
}
.filters::-webkit-scrollbar { display: none; }

.filter-btn {
  flex: 0 0 auto;
  appearance: none;
  font: inherit;
  font-size: 12px;
  font-weight: 550;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  white-space: nowrap;
}
.filter-btn[aria-pressed='true'] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

input.search {
  flex: 1 1 150px;
  min-width: 130px;
  font: inherit;
  font-size: 13px;
  padding: 6px 11px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  -webkit-appearance: none;
}
input.search::placeholder { color: var(--text-3); }

select.sort {
  flex: 0 0 auto;
  font: inherit;
  font-size: 12px;
  font-weight: 550;
  padding: 6px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
}

/* ---------- Inline result map ---------- */

.map-toggle {
  width: 100%;
  appearance: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 10px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--accent);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.map-toggle[aria-expanded='true'] { background: var(--accent-soft); }

.result-map {
  height: 340px;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  margin-bottom: 12px;
  background: var(--surface-2);
}
.result-map[hidden] { display: none; }

/* ---------- Sliders ---------- */

.slider { display: block; margin-bottom: 16px; }
.slider:last-child { margin-bottom: 4px; }
.slider-lab {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 7px;
}
.slider-lab b {
  font-size: 17px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 680;
}
.slider input[type='range'] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  outline: none;
}
.slider input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;   /* generous: this is a thumb-driven control on a phone */
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--surface);
  box-shadow: var(--shadow);
  cursor: pointer;
}
.slider input[type='range']::-moz-range-thumb {
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--surface);
  box-shadow: var(--shadow); cursor: pointer;
}

/* ---------- Tables ---------- */

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td {
  padding: 9px 11px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
  font-weight: 600;
  background: var(--surface-2);
  position: sticky;
  top: 0;
}
td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }

/* ---------- Stat tiles ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(148px, 1fr));
  gap: 8px;
  margin-bottom: 14px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  box-shadow: var(--shadow);
}
.stat .k {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  font-weight: 650;
  margin-bottom: 5px;
}
.stat .v {
  font-size: 21px;
  font-weight: 680;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat .s { font-size: 11px; color: var(--text-2); margin-top: 3px; line-height: 1.35; }
.stat.good .v { color: var(--good); }
.stat.poor .v { color: var(--poor); }
.stat.ok   .v { color: var(--ok); }

/* ---------- Collapsible detail ---------- */

.more {
  border-top: 1px solid var(--border);
  margin-top: 10px;
  padding-top: 8px;
}
.more > summary {
  cursor: pointer;
  list-style: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  padding: 2px 0;
}
.more > summary::-webkit-details-marker { display: none; }
.more > summary::after { content: ' ▾'; }
.more[open] > summary::after { content: ' ▴'; }
.more[open] > summary { margin-bottom: 6px; }
.more p { font-size: 13px; color: var(--text-2); }
.more p:last-child { margin-bottom: 0; }

/* ---------- Callouts ---------- */

.note {
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  padding: 10px 12px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 13px;
  margin-bottom: 12px;
}
.note.warn { border-left-color: var(--ok); background: var(--ok-soft); }
.note.stop { border-left-color: var(--poor); background: var(--poor-soft); }
.note strong { display: block; margin-bottom: 2px; }
.note :last-child { margin-bottom: 0; }

/* ---------- Source attribution ---------- */

.src {
  font-size: 11px;
  color: var(--text-3);
  margin-top: 6px;
}
.src a { color: var(--text-3); }

.unverified {
  color: var(--text-3);
  font-style: italic;
  font-weight: 400;
}

/* ---------- Misc ---------- */

.section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-3);
  font-weight: 650;
  margin: 20px 0 8px;
}
.section-title:first-child { margin-top: 0; }

.muted { color: var(--text-2); font-size: 13px; }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-3);
  font-size: 13px;
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
