:root {
  --tree: #2e7d32;
  --power: #e8590c;
  --road: #d62828;
  --flood: #1c7ed6;
  --bg: #ffffff;
  --fg: #1d2330;
  --muted: #5b6475;
  --line: #d9dde5;
  --chip: #f3f5f8;
  --accent: #1f5fbf;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161a22;
    --fg: #e8ebf1;
    --muted: #9aa3b5;
    --line: #2c3240;
    --chip: #222835;
    --accent: #6ea2ff;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.35 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button {
  font: inherit;
  color: inherit;
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}
button:hover { border-color: var(--muted); }
button.danger { color: #c92a2a; }

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 20px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.title h1 { font-size: 19px; margin: 0; }
.updated { margin: 2px 0 0; color: var(--muted); font-size: 13px; }

.counts { display: flex; gap: 8px; flex-wrap: wrap; }
.count {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  column-gap: 8px;
  align-items: center;
  text-align: left;
  min-width: 120px;
  padding: 6px 12px;
}
.count .swatch { grid-row: 1 / span 2; }
.count .num { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.count .label { font-size: 12px; color: var(--muted); }
.count[aria-pressed="false"] { opacity: 0.45; }
.count[aria-pressed="false"] .num { text-decoration: line-through; }

.swatch { display: inline-block; flex: none; }
.swatch.dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.35); }
.swatch.line { width: 18px; height: 5px; border-radius: 3px; }
.swatch.tree { background: var(--tree); }
.swatch.power { background: var(--power); }
.swatch.road { background: var(--road); }
.swatch.flood { background: var(--flood); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--line);
}
.toolbar[hidden], .hint[hidden] { display: none; }
.tools { display: flex; flex-wrap: wrap; gap: 6px; }
.tool { display: inline-flex; align-items: center; gap: 6px; }
.pick-count { align-self: center; color: var(--muted); font-size: 13px; margin-right: 4px; }
button:disabled { opacity: .45; cursor: default; }
.problems { padding: 6px 16px; background: #fff4d6; color: #3d2f00; border-bottom: 1px solid #f0d78c; font-size: 13px; }
.problems[hidden] { display: none; }
.problems summary { cursor: pointer; font-weight: 600; }
.problems ul { margin: 4px 0 2px; padding-left: 20px; }
.tool.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }

.hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  width: min(560px, calc(100% - 100px));
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: #fff4d6;
  color: #3d2f00;
  border: 1px solid #f0d78c;
}
.hint button { color: #1d2330; background: #fff; }
.hint span { flex: 1 1 200px; }

.map-wrap { position: relative; flex: 1; min-height: 300px; display: flex; }
#map { flex: 1; }
.locate-btn { width: 30px; height: 30px; line-height: 30px; text-align: center; background: #fff; color: #333 !important; font-size: 18px; text-decoration: none; }
#map.picking { cursor: crosshair; }

/* Popups */
.hz-popup { min-width: 200px; }
.hz-popup h3 { margin: 0 0 4px; font-size: 15px; }
.hz-popup .meta { color: #5b6475; font-size: 12px; margin-bottom: 6px; }
.hz-popup .where { font-weight: 600; margin-bottom: 2px; }
.hz-popup input { width: 100%; font: inherit; font-size: 13px; margin-bottom: 4px; }
.hz-popup textarea { width: 100%; min-height: 54px; font: inherit; font-size: 13px; }
.hz-popup .row { display: flex; gap: 6px; margin-top: 6px; }
.hz-popup button { color: #1d2330; background: #f3f5f8; border-color: #d9dde5; padding: 4px 8px; font-size: 13px; }
.hz-popup button.danger { color: #c92a2a; }

/* Map legend (bottom left) */
.legend {
  background: rgba(255,255,255,.92);
  color: #1d2330;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.6;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.legend div { display: flex; align-items: center; gap: 6px; }

@media (max-width: 600px) {
  .topbar { padding: 8px 12px; }
  .title h1 { font-size: 17px; }
  .counts { width: 100%; }
  .count { flex: 1 1 0; min-width: 0; padding: 6px 8px; }
  .count .num { font-size: 20px; }
  .count .label { font-size: 11px; }
  .toolbar { padding: 8px 12px; }
  .hint { top: auto; bottom: 10px; width: calc(100% - 24px); }
}

/* Report a hazard */
.fab {
  position: absolute; right: 12px; bottom: 28px; z-index: 1000;
  background: #c92a2a; color: #fff; border: none; border-radius: 999px;
  padding: 12px 18px; font-weight: 600; font-size: 16px;
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
}
.fab:hover { background: #a61e1e; }
.fab[hidden], .panel[hidden], .toast[hidden] { display: none; }
.panel {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1001;
  width: min(420px, calc(100% - 24px));
  background: var(--bg); color: var(--fg);
  border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,.35);
  padding: 14px 16px;
}
.panel h2 { margin: 0 0 10px; font-size: 17px; }
.choices { display: grid; gap: 8px; }
.choices button { display: flex; align-items: center; gap: 10px; padding: 12px; font-size: 16px; text-align: left; }
.panel .link { background: none; border: none; color: var(--muted); margin-top: 8px; padding: 4px 0; }
.panel label { display: block; font-size: 14px; margin-bottom: 8px; }
.panel .opt { color: var(--muted); font-size: 12px; }
.panel input, .panel textarea {
  display: block; width: 100%; margin-top: 3px; font: inherit; font-size: 16px;
  padding: 7px 8px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); color: var(--fg);
}
.panel .row { display: flex; gap: 8px; margin-top: 4px; }
.panel .primary { background: #1f5fbf; color: #fff; border-color: #1f5fbf; font-weight: 600; }
.panel .msg { margin: 8px 0 0; font-size: 13px; color: var(--muted); min-height: 1em; }
.trap { position: absolute; left: -9999px; width: 1px; height: 1px; }
.toast {
  position: absolute; left: 50%; top: 12px; transform: translateX(-50%); z-index: 1002;
  background: #1d2330; color: #fff; padding: 10px 14px; border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,.35); font-size: 14px; max-width: calc(100% - 24px);
}

.hz-popup .note { white-space: pre-line; font-size: 13px; }
.hz-popup .update { margin-top: 8px; border-top: 1px solid #d9dde5; padding-top: 8px; }
.hz-popup .update .meta { margin: 4px 0 0; }
.hz-popup .update textarea { font-size: 16px; }

.install { margin-top: 4px; padding: 3px 10px; font-size: 13px; border-radius: 999px; background: #1f3b73; color: #fff; border-color: #1f3b73; }
.install[hidden] { display: none; }

.photo-field { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.panel .photo-btn { display: inline-flex; align-items: center; gap: 4px; margin: 0; padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--chip); cursor: pointer; }
.photo-btn input { position: absolute; width: 1px; height: 1px; opacity: 0; }
#photo-preview { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
#photo-preview[hidden] { display: none; }
.panel .photo-field .link { margin: 0; }
.hz-popup .photo { display: block; margin-top: 6px; }
.hz-popup .photo img { display: block; width: 100%; max-width: 260px; height: 150px; object-fit: cover; border-radius: 6px; }
