:root {
  --ink: #14181d;
  --ink-2: #454e59;
  --ink-3: #79838f;
  --line: #e4e8ed;
  --line-2: #eef1f4;
  --surface: #ffffff;
  --canvas: #f6f8fa;

  --sadd: #d5202c;          /* the red from the SADD wordmark */
  --risk: #d5202c;
  --safe: #1f8a3b;
  --gap: #96131d;
  --computed: #e08a12;
  --crash: #55131a;

  --r-sm: 8px;
  --r: 12px;
  --r-lg: 16px;
  --shadow: 0 1px 2px rgba(20, 24, 29, 0.05), 0 4px 14px rgba(20, 24, 29, 0.06);
  --shadow-lg: 0 8px 34px rgba(20, 24, 29, 0.16);
  --head-h: 62px;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  display: flex;
  flex-direction: column;
  font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--canvas);
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

/* ============================================================ top bar */
.topbar {
  flex: 0 0 auto;
  height: var(--head-h);
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 30;
}

.brand { display: flex; align-items: center; text-decoration: none; flex: 0 0 auto; }
.brand-logo { height: 34px; width: auto; display: block; }

/* Shown only if assets/sadd-logo.png is missing. */
.brand-fallback { display: block; line-height: 1; color: var(--ink); }
.brand-fallback b { font-size: 20px; font-weight: 900; letter-spacing: -0.02em; }
.brand-fallback i { color: var(--sadd); font-style: normal; }
.brand-fallback small {
  display: block;
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: 0.055em;
  text-transform: uppercase;
  margin-top: 3px;
  color: var(--ink-2);
}

.titles {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  border-left: 1px solid var(--line);
  padding-left: 18px;
}

.titles h1 {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0;
  white-space: nowrap;
  line-height: 1.15;
}

.credit {
  margin: 0;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-3);
  letter-spacing: 0.01em;
  white-space: nowrap;
  line-height: 1.15;
}

.tagline {
  margin: 0 auto 0 0;
  font-size: 13.5px;
  color: var(--ink-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  align-self: center;
}

.sheet-btn { display: none; }

/* ============================================================ layout */
.layout {
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 322px 1fr;
  min-height: 0;
}

.layout:has(.detail:not([hidden])) { grid-template-columns: 322px 1fr 400px; }

/* ============================================================ sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
}

.sidebar-head {
  padding: 16px 16px 14px;
  border-bottom: 1px solid var(--line-2);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.count-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.count-row h2 { font-size: 14px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.count { font-size: 12px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.filters { display: flex; flex-wrap: wrap; gap: 5px; margin: 12px 0; }

.chip {
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  padding: 5px 11px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.chip:hover { border-color: #c4ccd5; background: var(--canvas); }
.chip.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

.layer-toggles { display: flex; flex-direction: column; gap: 7px; }

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: var(--ink-2);
  cursor: pointer;
  user-select: none;
}

.toggle input { margin: 0; cursor: pointer; accent-color: var(--ink); }
.toggle b { color: var(--ink-3); font-weight: 600; }

.swatch { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.sw-computed { background: var(--computed); }
.sw-crash { background: var(--crash); }

.submit-open {
  width: 100%;
  margin-top: 13px;
  padding: 9px;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  color: var(--sadd);
  background: #fdf3f4;
  border: 1px solid #f3d4d7;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.12s;
}

.submit-open span { font-weight: 800; margin-right: 2px; }
.submit-open:hover { background: #fbe9eb; }

/* ---- spot list ---- */
.spot-list { list-style: none; margin: 0; padding: 12px 12px 4px; flex: 1 1 auto; }

.spot {
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: var(--r);
  margin-bottom: 7px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 5px;
  background: var(--surface);
  transition: border-color 0.12s, box-shadow 0.14s, transform 0.14s;
}

.spot:hover { border-color: #c8d0d9; box-shadow: var(--shadow); transform: translateY(-1px); }
.spot.is-active { border-color: var(--ink); box-shadow: var(--shadow); }
.spot.is-computed { border-style: dashed; background: #fffdfa; }

.spot-name { font-size: 13.5px; font-weight: 650; line-height: 1.32; letter-spacing: -0.005em; }

.spot-meta {
  font-size: 11.5px;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px;
}

.pill {
  font-size: 9.5px;
  text-transform: uppercase;
  letter-spacing: 0.045em;
  padding: 2.5px 7px;
  border-radius: 999px;
  font-weight: 800;
  white-space: nowrap;
}

.pill-verified { background: #e7f6ec; color: #16702f; }
.pill-candidate { background: #fdf2e4; color: #96590f; }
.pill-gap { background: #fceaec; color: var(--gap); }
.pill-computed { background: #fdf2e4; color: #96590f; }

.legend {
  padding: 14px 16px 20px;
  border-top: 1px solid var(--line-2);
  margin-top: 6px;
}

.legend p { margin: 0 0 8px; font-size: 11.5px; line-height: 1.55; color: var(--ink-3); }
.legend p:last-child { margin-bottom: 0; }

/* ============================================================ map */
.map-wrap { position: relative; min-height: 0; }
.map { position: absolute; inset: 0; }

/* MapLibre forces square 29px buttons on control groups. */
.basemap-switch { display: flex; white-space: nowrap; }

.basemap-switch button {
  width: auto !important;
  height: auto !important;
  min-width: 0 !important;
  padding: 7px 13px !important;
  font: inherit;
  font-size: 12px;
  font-weight: 650;
  border: 0;
  border-right: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
  background-image: none !important;
}

.basemap-switch button:last-child { border-right: 0; }
.basemap-switch button:hover { background: var(--canvas); }
.basemap-switch button.is-active { background: var(--ink); color: #fff; }

.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-group { border-radius: var(--r-sm); overflow: hidden; box-shadow: var(--shadow); }

/* ---- markers ---- */
.pin {
  width: 17px;
  height: 17px;
  border-radius: 50%;
  border: 2.5px solid #fff;
  box-shadow: 0 1px 5px rgba(0, 0, 0, 0.45);
  cursor: pointer;
  transition: transform 0.12s;
}

.pin:hover { transform: scale(1.18); }
.pin-risk { background: var(--risk); }
.pin-gap { background: var(--gap); width: 19px; height: 19px; }
.pin-safe { background: var(--safe); }
.pin-target { background: #1668b8; }
.pin-computed { background: var(--computed); width: 12px; height: 12px; border-width: 2px; }

/* Sober by design. These are people, not decoration. */
.crash {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: rgba(85, 19, 26, 0.55);
  border: 1.5px solid rgba(255, 255, 255, 0.85);
  cursor: pointer;
}

.crash-fatal { width: 15px; height: 15px; background: var(--crash); border-width: 2px; }

/* ============================================================ detail */
.detail {
  background: var(--surface);
  border-left: 1px solid var(--line);
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 20px 20px 34px;
  position: relative;
}

.close {
  position: absolute;
  top: 12px;
  right: 14px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: var(--canvas);
  font-size: 20px;
  line-height: 1;
  color: var(--ink-2);
  cursor: pointer;
  transition: background 0.12s;
}

.close:hover { background: #e9edf1; }

.detail h2 {
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin: 0 36px 3px 0;
}

.suburb { margin: 0 0 16px; color: var(--ink-3); font-size: 12.5px; font-weight: 500; }

.detail h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 800;
  color: var(--ink-3);
  margin: 20px 0 7px;
}

.detail h3.is-gap { color: var(--gap); }
.detail p { font-size: 14px; line-height: 1.6; margin: 0; color: var(--ink-2); }

.sv-links { display: flex; flex-direction: column; gap: 7px; margin-bottom: 14px; }

.sv-btn {
  display: block;
  padding: 10px 13px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  border: 1px solid var(--line);
  transition: filter 0.12s;
}

.sv-btn::after { content: " \2197"; opacity: 0.5; }
.sv-risky { border-color: #f2d2d5; color: var(--risk); background: #fdf5f6; }
.sv-safe { border-color: #c9e6d2; color: var(--safe); background: #f3faf5; }
.sv-btn:hover { filter: brightness(0.975); }

.approx {
  margin-top: 12px !important;
  padding: 10px 12px;
  background: #fdf7ed;
  border: 1px solid #f1dfc0;
  border-radius: var(--r-sm);
  font-size: 12.5px !important;
  line-height: 1.55 !important;
  color: #86571a !important;
}

.approx a { color: #86571a; }

.metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 4px; }

.metrics > div {
  background: var(--canvas);
  border-radius: var(--r-sm);
  padding: 9px 5px;
  text-align: center;
}

.metrics span { display: block; font-size: 14px; font-weight: 750; font-variant-numeric: tabular-nums; }
.metrics small { display: block; font-size: 9px; color: var(--ink-3); line-height: 1.3; margin-top: 3px; }

.extra { margin-top: 9px !important; font-size: 12.5px !important; color: var(--ink-3) !important; }

.evidence {
  font-size: 13px !important;
  color: var(--ink-3) !important;
  border-left: 3px solid var(--line);
  padding-left: 12px;
}

.sources ul { margin: 0; padding-left: 17px; }
.sources li { font-size: 12.5px; line-height: 1.5; margin-bottom: 5px; color: var(--ink-3); }
.sources a { color: var(--ink); text-decoration-color: var(--line); }

code { background: #eef1f4; padding: 1.5px 5px; border-radius: 4px; font-size: 12.5px; }

/* ============================================================ submit modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(20, 24, 29, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  width: min(520px, 100%);
  padding: 26px 26px 22px;
  position: relative;
  max-height: 92vh;
  overflow-y: auto;
}

.modal-card h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; margin: 0 36px 8px 0; }
.modal-lede { font-size: 13.5px; line-height: 1.6; color: var(--ink-3); margin: 0 0 20px; }

#submitForm label {
  display: block;
  font-size: 12.5px;
  font-weight: 650;
  color: var(--ink-2);
  margin-bottom: 13px;
}

#submitForm .hint { display: block; font-weight: 400; color: var(--ink-3); margin: 2px 0 5px; font-size: 11.5px; }
#submitForm .hint a { color: var(--ink-2); }

#submitForm input, #submitForm textarea {
  display: block;
  width: 100%;
  margin-top: 5px;
  padding: 9px 11px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 400;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--canvas);
  resize: vertical;
}

#submitForm input:focus, #submitForm textarea:focus {
  outline: none;
  border-color: var(--ink-3);
  background: var(--surface);
}

.modal-actions { display: flex; gap: 8px; margin-top: 4px; }

.btn-primary, .btn-ghost {
  flex: 1;
  padding: 10px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 650;
  border-radius: var(--r-sm);
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: #000; }
.btn-ghost { background: var(--surface); border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { background: var(--canvas); }

.modal-note {
  margin: 12px 0 0;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink-3);
  background: var(--canvas);
  padding: 10px 12px;
  border-radius: var(--r-sm);
}

/* ============================================================ editor */
.editor {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 5;
  width: 300px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r);
  box-shadow: var(--shadow-lg);
  padding: 15px;
}

.editor h3 {
  margin: 0 0 7px;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  font-weight: 800;
  color: var(--ink-3);
}

.ed-step { margin: 0 0 11px; font-size: 13px; line-height: 1.5; color: var(--ink-2); }
.ed-nums { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 11px; }
.ed-nums > div { background: var(--canvas); border-radius: var(--r-sm); padding: 8px 5px; text-align: center; }
.ed-nums span { display: block; font-size: 15px; font-weight: 750; font-variant-numeric: tabular-nums; }
.ed-nums small { display: block; font-size: 9.5px; color: var(--ink-3); line-height: 1.25; margin-top: 2px; }

.editor textarea {
  width: 100%;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 9px;
  resize: vertical;
  margin-bottom: 8px;
  background: var(--canvas);
  color: var(--ink-2);
}

.ed-btns { display: flex; gap: 6px; }

.ed-btns button {
  flex: 1;
  padding: 8px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  border-radius: var(--r-sm);
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink-2);
  cursor: pointer;
}

.ed-btns button:hover { background: var(--canvas); }

/* ============================================================ mobile */
@media (max-width: 860px) {
  :root { --head-h: 54px; }

  .topbar { gap: 10px; padding: 0 12px; }
  .brand-logo { height: 26px; }
  .titles { border-left: 0; padding-left: 0; gap: 1px; align-items: flex-start; }
  .titles h1 { font-size: 14.5px; }
  .credit { font-size: 10px; }
  .tagline { display: none; }

  .sheet-btn {
    display: block;
    margin-left: auto;
    padding: 7px 14px;
    font: inherit;
    font-size: 13px;
    font-weight: 650;
    color: #fff;
    background: var(--ink);
    border: 0;
    border-radius: 999px;
    cursor: pointer;
  }

  .layout, .layout:has(.detail:not([hidden])) {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    position: relative;
  }

  .map-wrap { grid-row: 1; }

  /* Sidebar becomes a bottom sheet. */
  .sidebar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    top: 28%;
    z-index: 20;
    border-right: 0;
    border-top: 1px solid var(--line);
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    box-shadow: var(--shadow-lg);
    transform: translateY(100%);
    transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  }

  .sidebar::before {
    content: "";
    position: absolute;
    top: 7px;
    left: 50%;
    transform: translateX(-50%);
    width: 38px;
    height: 4px;
    border-radius: 999px;
    background: var(--line);
  }

  body.sheet-open .sidebar { transform: translateY(0); }
  .sidebar-head { padding-top: 20px; }

  /* Detail takes the whole screen so the text is actually readable. */
  .detail {
    position: absolute;
    inset: 0;
    z-index: 40;
    border-left: 0;
    padding: 18px 16px 40px;
  }

  .editor { left: 10px; right: 10px; bottom: 10px; width: auto; }
  .modal { padding: 12px; align-items: flex-end; }
  .modal-card { padding: 22px 18px 18px; border-radius: var(--r-lg); max-height: 88vh; }
  .basemap-switch button { padding: 7px 10px !important; font-size: 11.5px; }
}

@media (max-width: 400px) {
  .titles h1 { font-size: 13.5px; }
  .brand-logo { height: 22px; }
}
