/* Layout: full-bleed map, floating side panel (desktop) / top sheet (mobile). */
:root {
  --bg: #ffffff;
  --surface: #f5f6f7;
  --fg: #17212b;
  --muted: #5d6974;
  --line: #dde1e5;
  --accent: #1f5fa8;
  --accent-fg: #ffffff;
  --good: #2e7d4f;
  --danger: #b4302a;
  --consensus: #5d6974;
  --font: "Public Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 8px;
  --shadow: 0 2px 12px rgba(16, 24, 32, .14);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161b21;
    --surface: #1f262d;
    --fg: #e8ecef;
    --muted: #9ba7b2;
    --line: #2f3841;
    --accent: #6ea8ec;
    --accent-fg: #0d1520;
    --good: #6cc391;
    --danger: #ef7a72;
    --shadow: 0 2px 14px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 var(--font); color: var(--fg); background: var(--bg); }
#map { position: fixed; inset: 0; }
button, input { font: inherit; color: inherit; }
h1 { font-size: 17px; font-weight: 700; margin: 0; letter-spacing: -.01em; user-select: none; }
h2 { font-size: 15px; font-weight: 700; margin: 0; }
p { margin: 0; }

/* Panel */
.panel {
  position: fixed; z-index: 1000;
  top: calc(16px + env(safe-area-inset-top, 0px)); left: 16px; bottom: 16px;
  width: 340px;
  display: flex; flex-direction: column;
  background: var(--bg); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 16px 16px 12px; border-bottom: 1px solid var(--line);
}
.panel-body { flex: 1; min-height: 0; overflow-y: auto; padding: 14px 16px 16px; }
.view { display: flex; flex-direction: column; gap: 14px; }
.view-head { display: flex; align-items: center; justify-content: space-between; }
.meta { margin-top: 2px; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.intro { color: var(--fg); font-size: 14px; }
.hint, .empty { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); font-size: 13px; }
.only-mobile { display: none; }

.field { display: flex; flex-direction: column; gap: 6px; }
label, .field > label { font-size: 12px; font-weight: 600; color: var(--muted); }
input[type="search"], input[type="text"], input[type="password"] {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 6px; background: var(--surface);
}
input:focus-visible, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.inline-form { display: flex; gap: 8px; }
.inline-form input { flex: 1; min-width: 0; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--bg); font-weight: 500; font-size: 14px; cursor: pointer;
}
.btn:hover { background: var(--surface); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.approve { background: var(--good); border-color: var(--good); color: var(--bg); }
.btn.reject { color: var(--danger); }
.btn.block { width: 100%; }
.row { display: flex; gap: 8px; }
.row > .btn { flex: 1; }
.link-btn { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; font-size: 13px; text-align: left; }
.icon-btn { border: 1px solid var(--line); border-radius: 6px; background: var(--bg); padding: 4px 10px; font-size: 13px; cursor: pointer; }
kbd { font: 600 11px/1 var(--font); padding: 2px 4px; border: 1px solid currentColor; border-radius: 3px; opacity: .7; }

/* Legend */
.legend { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.legend-bar { height: 8px; border-radius: 2px; background: linear-gradient(to right, transparent, var(--consensus)); border: 1px solid var(--line); }
.legend-scale { display: flex; justify-content: space-between; }

/* Lists */
.nbhd-list, .results-list, .review-list, .mine ul { list-style: none; margin: 0; padding: 0; }
.nbhd-list li button, .results-list li button, .review-list li button {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 7px 6px; border: 0; border-radius: 6px; background: none; text-align: left; cursor: pointer;
}
.nbhd-list li button:hover, .results-list li button:hover, .review-list li button:hover { background: var(--surface); }
.nbhd-list li button[aria-current="true"], .review-list li button[aria-current="true"] { background: var(--surface); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.grow { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.num { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tag { font-size: 11px; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }
.results-list li button { font-size: 13px; }
.mine { display: flex; flex-direction: column; gap: 6px; padding-top: 12px; border-top: 1px solid var(--line); }
.mine li { display: flex; justify-content: space-between; gap: 8px; font-size: 14px; padding: 3px 0; }

/* Painting: desktop gets tools and drag-to-paint; touch screens tap one block at a time */
body.touch .desktop-only { display: none !important; }
body:not(.touch) .touch-only { display: none !important; }
.steps { font-size: 14px; }
.toolbar { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.tool { flex: 1; border: 0; background: var(--bg); padding: 7px 4px; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 5px; }
.tool + .tool { border-left: 1px solid var(--line); }
.tool[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); font-weight: 600; }
.paint-status { display: flex; justify-content: space-between; align-items: center; font-size: 14px; font-variant-numeric: tabular-nums; }
.paint-actions { display: flex; gap: 12px; }
.link-btn:disabled { color: var(--muted); opacity: .6; cursor: default; }

/* Review */
.badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); }
.signin, .admin-tools { display: flex; flex-direction: column; gap: 12px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); }
.tab {
  border: 0; background: none; padding: 6px 8px 8px; cursor: pointer; font-size: 14px; color: var(--muted);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab[aria-selected="true"] { color: var(--fg); font-weight: 600; border-bottom-color: var(--accent); }
.count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.review-card { display: flex; flex-direction: column; gap: 8px; padding: 12px; border: 1px solid var(--line); border-radius: 6px; }
.admin-foot { display: flex; flex-direction: column; gap: 8px; padding-top: 12px; border-top: 1px solid var(--line); }

/* Map popup */
.maplibregl-map { font-family: var(--font); }
.maplibregl-popup-content { padding: 10px 12px; border-radius: 6px; box-shadow: var(--shadow); color: #17212b; }
.pop h3 { font-size: 13px; margin: 0 0 6px; }
.pop ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.pop li { display: grid; grid-template-columns: 1fr auto; column-gap: 10px; row-gap: 3px; font-size: 13px; align-items: center; }
.pop .bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: #e6e9ec; overflow: hidden; }
.pop .bar i { display: block; height: 100%; }
.pop .note { font-size: 12px; color: #5d6974; margin-top: 6px; }

/* Map style editor */
.pane { display: flex; flex-direction: column; gap: 12px; }
.style-rows { display: flex; flex-direction: column; }
.style-row { display: grid; grid-template-columns: auto 1fr auto 72px; align-items: center; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.style-row .name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.style-row .name small { color: var(--muted); }
.style-row input[type="color"] { width: 28px; height: 22px; padding: 0; border: 1px solid var(--line); border-radius: 4px; background: none; cursor: pointer; }
.style-row input[type="color"]:disabled { opacity: .3; cursor: default; }
.style-row input[type="range"] { width: 72px; }
.style-row.off .name { color: var(--muted); }
.style-all summary { cursor: pointer; font-size: 13px; color: var(--accent); padding: 4px 0; }

/* Hover tooltip: follows the cursor and never blocks it */
.hover-pop { pointer-events: none; }
.hover-pop .maplibregl-popup-tip { display: none; }

/* Toast */
.toast {
  position: fixed; z-index: 1100; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%); padding: 8px 14px; border-radius: 6px;
  background: var(--fg); color: var(--bg); font-size: 14px; box-shadow: var(--shadow);
}

/* Mobile: panel becomes a top sheet */
@media (max-width: 640px) {
  .panel {
    left: 12px; right: 12px; width: auto; bottom: auto;
    top: calc(12px + env(safe-area-inset-top, 0px));
    max-height: calc(100% - 24px - env(safe-area-inset-top, 0px) - env(safe-area-inset-bottom, 0px));
  }
  .only-mobile { display: inline-block; }
  .panel:not(.open) .panel-body { display: none; }
  .panel:not(.open) .panel-head { border-bottom: 0; }
  /* While painting on a phone, keep the panel compact so most of the map is free to tap. */
  body.drawing .panel { max-height: 45%; }
  body.drawing .panel-head { display: none; }
  body.drawing .panel-body { padding-block: 10px 12px; }
  body.drawing .view { gap: 10px; }
  body.drawing .steps { font-size: 13px; color: var(--muted); }
  body.drawing #view-draw > .hint:last-of-type { display: none; }
}

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