:root {
  --sb-w: 360px;
  --detail-w: 400px;
  --bg: #fafafa;
  --panel: #ffffff;
  --ink: #1b1f23;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #1d4ed8;
  --accent-soft: #e8eefc;
  --quiet: #2e9e5b;
  --moderate: #e0b400;
  --loud: #ef7d1a;
  --very_loud: #d63a2f;
  --nodata: #9aa0a6;
  --radius: 6px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 13px;
  line-height: 1.35;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

#app { display: flex; height: 100vh; height: 100dvh; width: 100vw; overflow: hidden; }

/* ---------- sidebar ---------- */
#sidebar {
  width: var(--sb-w); flex: 0 0 var(--sb-w);
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
  z-index: 5;
}
#sidebar.collapsed { display: none; }
.sb-head { display: flex; align-items: flex-start; justify-content: space-between; padding: 12px 14px 8px; }
.sb-head h1 { font-size: 16px; letter-spacing: -0.01em; }
.sb-head .sub { color: var(--muted); font-size: 12px; }
.icon-btn { border: 0; background: transparent; font-size: 20px; line-height: 1; cursor: pointer; color: var(--muted); padding: 2px 6px; border-radius: 4px; }
.icon-btn:hover { background: var(--line); color: var(--ink); }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; font-size: 12px; }
.link-btn:hover { text-decoration: underline; }
.banner { margin: 0 14px 6px; padding: 6px 8px; background: #fff7d6; border: 1px solid #f1dc8a; border-radius: var(--radius); font-size: 12px; }
.banner.err { background: #fde8e8; border-color: #f3b4b4; }
.count-row { display: flex; justify-content: space-between; align-items: baseline; padding: 0 14px 8px; font-weight: 600; border-bottom: 1px solid var(--line); }
.count-row span span { font-weight: 400; color: var(--muted); font-size: 12px; }
.sb-scroll { overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0; }

.filters { padding: 8px 14px 4px; display: flex; flex-direction: column; gap: 10px; }
.search { width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; }
.search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { font-weight: 600; font-size: 12px; color: #374151; margin-bottom: 4px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; padding: 0; }
legend output { color: var(--accent); font-weight: 600; margin-left: auto; }
legend .inline { font-weight: 400; color: var(--muted); display: inline-flex; gap: 4px; align-items: center; font-size: 11px; margin-left: auto; cursor: pointer; }
legend .hint { font-weight: 400; color: var(--muted); font-size: 11px; }
fieldset.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
fieldset.two legend { display: flex; }
input[type=range] { width: 100%; margin: 4px 0 2px; accent-color: var(--accent); }
input[type=number] { width: 100%; padding: 5px 7px; border: 1px solid var(--line); border-radius: var(--radius); }

.chips, .tri { display: flex; flex-wrap: wrap; gap: 4px; }
.chips button, .tri button {
  border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; cursor: pointer; font-size: 12px;
}
.chips button:hover, .tri button:hover { border-color: #c7cbd1; }
.chips button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tri button::before { content: "•"; color: #c7cbd1; margin-right: 5px; }
.tri button.yes { background: #e6f5ec; border-color: var(--quiet); color: #14532d; }
.tri button.yes::before { content: "✓"; color: var(--quiet); }
.tri button.yesunk { background: #fff7d6; border-color: #d4b106; color: #5c4a00; }
.tri button.yesunk::before { content: "✓?"; color: #a07c00; }

.checks { display: flex; flex-direction: column; gap: 3px; }
.checks label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 12px; }
.checks input { margin: 0; accent-color: var(--accent); }
.sw { width: 10px; height: 10px; border-radius: 50%; display: inline-block; border: 1px solid rgba(0,0,0,.15); }
.c-quiet { background: var(--quiet); } .c-moderate { background: var(--moderate); }
.c-loud { background: var(--loud); } .c-very_loud { background: var(--very_loud); }
.c-null { background: repeating-linear-gradient(45deg, var(--nodata) 0 2px, #fff 2px 4px); }

/* results list */
.results { border-top: 1px solid var(--line); margin-top: 6px; }
.results-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 14px 4px; font-weight: 600; font-size: 12px; color: #374151; }
.results-head label { font-weight: 400; color: var(--muted); }
.results-head select { border: 1px solid var(--line); border-radius: 4px; padding: 2px 4px; background: #fff; font-size: 12px; }
#list { list-style: none; margin: 0; padding: 0 6px 12px; }
#list li { padding: 7px 8px; border-radius: var(--radius); cursor: pointer; display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: 8px; align-items: center; }
#list li > span { min-width: 0; }
#list li:hover { background: #f3f4f6; }
#list li.sel { background: var(--accent-soft); }
#list .dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(0,0,0,.15); }
#list .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#list .meta { color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#list .right { text-align: right; font-size: 11px; color: var(--muted); white-space: nowrap; }
#list .right b { color: var(--ink); font-size: 12px; }
#list .empty { padding: 16px 8px; color: var(--muted); text-align: center; }

/* ---------- map ---------- */
#map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }
.fab { position: absolute; top: 10px; left: 10px; z-index: 4; display: none; border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; cursor: pointer; box-shadow: 0 1px 4px rgba(0,0,0,.15); font-weight: 600; }
.fab #fab-count { color: var(--muted); font-weight: 400; }
.fab.fab-right { left: auto; right: 10px; display: none; }
.sb-foot { display: none; padding: 8px 14px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
button.primary { width: 100%; padding: 11px 14px; border: 0; border-radius: var(--radius); background: var(--accent); color: #fff; font-weight: 600; font-size: 14px; cursor: pointer; }
.legend .mini { display: none; align-items: center; gap: 8px; }
.legend .mini .sw { width: 12px; height: 12px; }
.legend.min h4, .legend.min .row, .legend.min .grad, .legend.min .ends, .legend.min .note { display: none; }
.legend.min .mini { display: flex; }
.legend.min { min-width: 0; padding: 6px 10px; }
#sidebar.collapsed ~ #map-wrap .fab { display: inline-block; }
.map-controls { position: absolute; top: 10px; right: 10px; z-index: 4; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.seg { display: inline-flex; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.seg button { border: 0; background: transparent; padding: 5px 10px; cursor: pointer; font-size: 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button.on { background: var(--accent); color: #fff; }
.toggle { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 10px; font-size: 12px; box-shadow: 0 1px 4px rgba(0,0,0,.12); cursor: pointer; }
.toggle input { margin: 0; accent-color: var(--accent); }
.toggle.disabled { opacity: .55; cursor: not-allowed; }
.legend { position: absolute; left: 10px; bottom: 28px; z-index: 4; background: rgba(255,255,255,.94); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; font-size: 11.5px; box-shadow: 0 1px 4px rgba(0,0,0,.12); min-width: 150px; }
.legend h4 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.legend .row { display: flex; align-items: center; gap: 6px; padding: 1px 0; }
.legend .grad { height: 8px; border-radius: 4px; background: linear-gradient(90deg, #d63a2f, #e0b400 50%, #2e9e5b); margin: 4px 0 2px; }
.legend .ends { display: flex; justify-content: space-between; color: var(--muted); }
.legend .note { color: var(--muted); margin-top: 6px; border-top: 1px solid var(--line); padding-top: 4px; }
.legend .row .sq { width: 10px; height: 10px; border-radius: 2px; border: 1px solid rgba(0,0,0,.2); display: inline-block; }
.legend .row .ring { width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--accent); display: inline-block; }
.hover { position: absolute; z-index: 6; pointer-events: none; background: #1b1f23; color: #fff; padding: 5px 8px; border-radius: 4px; font-size: 12px; transform: translate(-50%, calc(-100% - 12px)); white-space: nowrap; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.hover b { font-weight: 600; }
.hover .r { color: #fcd34d; margin-left: 6px; }

#app.has-detail .map-controls { right: calc(var(--detail-w) + 10px); }
@media (max-width: 860px) { #app.has-detail .map-controls { display: none; } }

/* ---------- detail panel ---------- */
.detail {
  position: absolute; top: 0; right: 0; bottom: 0; width: var(--detail-w); max-width: 100vw;
  background: var(--panel); border-left: 1px solid var(--line); z-index: 7; display: flex; flex-direction: column;
  box-shadow: -4px 0 16px rgba(0,0,0,.08);
}
.d-head { display: flex; justify-content: space-between; align-items: flex-start; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); gap: 8px; }
.d-head h2 { font-size: 16px; line-height: 1.25; }
.d-scroll { overflow-y: auto; flex: 1; padding: 10px 14px 24px; }
.d-scroll section { margin-bottom: 14px; }
.d-scroll h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 5px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.stars { color: #d97706; font-weight: 600; }
.links { display: flex; flex-wrap: wrap; gap: 6px; }
.links a { border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; font-size: 12px; background: #fff; }
.links a:hover { background: var(--accent-soft); text-decoration: none; }
.units { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.units div { background: #f3f4f6; border-radius: var(--radius); padding: 6px 8px; }
.units .lbl { font-size: 11px; color: var(--muted); }
.units .val { font-weight: 600; }
.achips { display: flex; flex-wrap: wrap; gap: 5px; }
.achip { border-radius: 999px; padding: 3px 9px; font-size: 12px; border: 1px solid var(--line); background: #fff; cursor: default; }
.achip.yes { background: #e6f5ec; border-color: #9fd3b3; color: #14532d; }
.achip.no { background: #fde8e8; border-color: #f1b3b3; color: #7f1d1d; }
.achip.unk { color: var(--muted); border-style: dashed; }
.achip b { margin-right: 4px; }
.achip.conflict { border-style: dashed; }
.achip .warn { font-style: normal; margin-left: 4px; color: #b45309; }
details.ev { margin-top: 6px; }
details.ev summary { cursor: pointer; color: var(--accent); font-size: 12px; }
.ev ul, .plain { margin: 4px 0 0; padding-left: 16px; }
.ev li, .plain li { margin: 2px 0; }
.ev li .k { color: var(--muted); font-weight: 600; margin-right: 4px; }
.noise-badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; color: #fff; font-weight: 600; }
.tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.tag { background: #f3f4f6; border-radius: 4px; padding: 2px 7px; font-size: 12px; }
.hl li::marker { color: var(--quiet); } .ll li::marker { color: var(--very_loud); }
.rev { border-left: 3px solid var(--line); padding: 4px 8px; margin: 6px 0; }
.rev .rm { color: var(--muted); font-size: 11px; }
q { font-style: italic; }
.empty-note { color: var(--muted); font-style: italic; }

/* ---------- mobile ---------- */
@media (max-width: 860px) {
  #sidebar { position: absolute; inset: 0 auto 0 0; width: min(var(--sb-w), 92vw); box-shadow: 4px 0 16px rgba(0,0,0,.12); }
  .sb-foot { display: block; }
  #sidebar { z-index: 8; }   /* filters open above the detail sheet */
  /* detail = bottom sheet covering ~2/3 of the screen; the map (and the selected pin) stays visible above it */
  .detail { top: auto; bottom: 0; width: 100vw; height: 66vh; height: 66dvh; border-left: 0; border-top: 1px solid var(--line);
            border-radius: 14px 14px 0 0; box-shadow: 0 -6px 24px rgba(0,0,0,.18); }
  .detail::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 2px; background: #d1d5db; margin: 8px auto 0; }
  .d-head { padding-top: 6px; }
  #app.has-detail .legend, #app.has-detail .mapboxgl-ctrl-bottom-right, #app.has-detail .mapboxgl-ctrl-bottom-left { display: none; }
  .legend { bottom: 36px; }
  .fab.fab-right { display: inline-block; }
  .map-controls { display: none; top: 48px; right: 10px; flex-direction: column; align-items: stretch; background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
  .map-controls.open { display: flex; }
  .map-controls .seg, .map-controls .toggle { box-shadow: none; }
  .map-controls .seg button { flex: 1; padding: 8px 10px; }
  .hover { display: none; }
}
@media (max-width: 600px) {
  :root { font-size: 14px; }
  #sidebar { width: 100vw; }
  .sb-head { padding: calc(10px + env(safe-area-inset-top)) 14px 6px; }
  .filters { gap: 12px; padding: 10px 14px 6px; }
  .search { padding: 10px 11px; font-size: 15px; }
  .chips button, .tri button { padding: 7px 13px; font-size: 13px; min-height: 34px; }
  .checks label { min-height: 30px; font-size: 13px; }
  .checks input, legend .inline input { width: 18px; height: 18px; }
  input[type=range] { height: 28px; }
  input[type=number] { padding: 9px 10px; font-size: 15px; }
  .results-head select { padding: 6px 8px; }
  #list li { padding: 10px 8px; }
  .icon-btn { font-size: 24px; padding: 6px 12px; min-width: 44px; min-height: 44px; }
  .d-head { padding: 6px 14px 10px; position: sticky; top: 0; background: var(--panel); }
  .d-scroll { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
  .links a, .achip { padding: 6px 11px; font-size: 13px; }
  .units { grid-template-columns: repeat(3, 1fr); gap: 5px; }
  .legend { left: 10px; right: auto; bottom: 30px; max-width: 70vw; }
  .mapboxgl-ctrl-scale { display: none; }
  .mapboxgl-ctrl-bottom-right .mapboxgl-ctrl-group { margin-bottom: 30px; }
  .fab { padding: 9px 14px; font-size: 14px; }
}
@media (hover: none) and (pointer: coarse) {
  .hover { display: none; }
  #list li:hover { background: transparent; }
}
.mapboxgl-ctrl-bottom-left, .mapboxgl-ctrl-bottom-right { font-size: 10px; }
.mapboxgl-canvas:focus { outline: none; }
