:root {
  --accent: #0071E3;
  --ink: #1D1D1F;
  --ink-2: #6E6E73;
  --ink-3: #48484A;
  --fill: rgba(118,118,128,0.12);
  --hair: rgba(60,60,67,0.18);
  --glass: rgba(255,255,255,0.78);
  --glass-shadow: 0 0 0 0.5px rgba(0,0,0,0.08), 0 10px 36px rgba(0,0,0,0.12);
  --font: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display', Inter, system-ui, sans-serif;
  --panel-w: 320px; /* desktop sidebar; 300–340px reads best beside the map */
  --edge: 16px;     /* gap between floating chrome and the map's edges */
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: #E8ECEC; -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible { outline: 3px solid rgba(0,113,227,0.5); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.nosb { scrollbar-width: none; }
.nosb::-webkit-scrollbar { display: none; }
[hidden] { display: none !important; }

#map { position: fixed; inset: 0; }
.glass { background: var(--glass); -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%); box-shadow: var(--glass-shadow); }

/* Panel */
.panel { position: fixed; left: 16px; top: 16px; bottom: 16px; width: var(--panel-w); border-radius: 20px; display: flex; flex-direction: column; overflow: visible; z-index: 3; }
.panel.detail { background: rgba(242,242,247,0.86); }
.view { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; border-radius: 20px; }
.grabber { display: none; }
.panel-head { padding: 18px 18px 0; display: flex; flex-direction: column; gap: 14px; }
.title-row { display: flex; align-items: center; gap: 12px; }
.title-row h1 { flex: 1; margin: 0; font: 700 20px/24px var(--font); letter-spacing: -0.3px; }
/* Borough picker in the title position: reads as the panel heading. */
.title-select { flex: 1; min-width: 0; position: relative; display: flex; align-items: center; gap: 4px; color: var(--ink); }
.title-select select { appearance: none; -webkit-appearance: none; min-width: 0; max-width: 100%; border: none; background: transparent; color: var(--ink);
  font: 700 20px/28px var(--font); letter-spacing: -0.3px; padding: 0 22px 0 0; margin-right: -22px; cursor: pointer; text-overflow: ellipsis; }
.title-select svg { pointer-events: none; color: var(--ink-2); flex: none; }
.title-select:hover svg { color: var(--ink); }
.icon-btn { width: 32px; height: 32px; border-radius: 16px; border: none; background: var(--fill); display: flex; align-items: center; justify-content: center; }
.search { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 10px; background: var(--fill); color: var(--ink-2); }
.search input { flex: 1; min-width: 0; border: none; background: transparent; outline: none; font: 400 15px/20px var(--font); color: var(--ink); }
.search input::placeholder { color: var(--ink-2); }
.search input::-webkit-search-cancel-button { opacity: .6; }

.segmented { display: flex; gap: 2px; padding: 2px; border-radius: 9px; background: var(--fill); width: 100%; }
.segmented button { flex: 1 1 0; height: 28px; padding: 0 12px; border: none; border-radius: 7px; font-size: 13px; font-weight: 500; background: transparent; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.segmented button[aria-pressed="true"] { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 0 0 0.5px rgba(0,0,0,0.04); font-weight: 600; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 18px 4px; flex-shrink: 0; }
.chip { flex-shrink: 0; height: 32px; padding: 0 12px; border-radius: 16px; border: none; background: var(--fill); font: 500 13px/1 var(--font); display: flex; align-items: center; gap: 6px; }
.chip .n { color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; font-weight: 600; }
.chip[aria-pressed="true"] .n { color: rgba(255,255,255,0.8); }
.dot { width: 8px; height: 8px; border-radius: 4px; flex-shrink: 0; }
.chip[aria-pressed="true"] .dot { box-shadow: 0 0 0 1.5px #fff; }

.list-head { padding: 10px 18px 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.list-head h2 { margin: 0; font: 600 17px/22px var(--font); white-space: nowrap; }
.list-filters { display: flex; gap: 6px; min-width: 0; }
.select-link { position: relative; display: flex; align-items: center; gap: 4px; color: var(--accent); font: 500 13px/1 var(--font); }
.select-link select { appearance: none; -webkit-appearance: none; border: none; background: transparent; color: var(--accent); font: 500 13px/28px var(--font); padding: 0 16px 0 8px; margin-right: -16px; max-width: 110px; text-overflow: ellipsis; cursor: pointer; }
.select-link svg { pointer-events: none; }
.select-link.active select { font-weight: 600; }

.list { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 2px 18px 0; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 0; border: none; border-bottom: 0.5px solid var(--hair); background: none; text-align: left; color: var(--ink); }
.row:last-child { border-bottom: none; }
.row:hover .row-name { color: var(--accent); }
.row-pin { width: 20px; flex-shrink: 0; display: flex; justify-content: center; }
.row-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-name { font: 600 15px/20px var(--font); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-name.ph { color: var(--ink-3); font-weight: 500; }
.row-sub { font: 400 13px/18px var(--font); color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-prov { flex-shrink: 0; font: 500 13px/18px var(--font); color: var(--ink-2); text-align: right; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 6px; background: #FFF4E5; color: #8A4B00; font: 600 11px/16px var(--font); margin-left: 6px; vertical-align: 1px; }
.empty { padding: 28px 4px; text-align: center; color: var(--ink-2); font-size: 14px; line-height: 20px; }
.empty button { margin-top: 10px; }

.panel-foot { padding: 12px 18px 18px; display: flex; gap: 10px; border-top: 0.5px solid var(--hair); }
.btn { height: 44px; padding: 0 16px; border: none; border-radius: 12px; font: 600 15px/1 var(--font); display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.btn.grow { flex: 1 1 auto; }
.btn-gray { background: var(--fill); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:disabled { opacity: .45; cursor: default; }
.btn-white { background: #fff; color: var(--accent); box-shadow: 0 0 0 0.5px rgba(0,0,0,0.06); }

.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 240px; padding: 6px; border-radius: 14px; display: flex; flex-direction: column; background: rgba(255,255,255,0.92); }
.menu-up { top: auto; bottom: calc(100% + 6px); left: 0; right: auto; }
.menu > * { display: block; text-align: left; padding: 10px 12px; border: none; border-radius: 9px; background: none; font: 400 15px/20px var(--font); color: var(--ink); text-decoration: none; }
.menu > *:hover { background: var(--fill); }
.menu hr { border: none; height: 0.5px; background: var(--hair); margin: 4px 8px; padding: 0; }
.menu-up { min-width: 260px; }

/* Sidebar toggle */
#hidePanelBtn { background: transparent; width: 36px; height: 36px; border-radius: 10px; color: var(--ink); }
#hidePanelBtn:hover { background: var(--fill); }
.show-panel { position: fixed; left: 16px; top: 16px; z-index: 3; width: 44px; height: 44px; border: none; border-radius: 12px; display: flex; align-items: center; justify-content: center; color: var(--ink); }
body { --chrome-left: calc(var(--edge) + var(--panel-w) + var(--edge)); }
body.panel-hidden { --chrome-left: 76px; }

/* Sidebar slide, modelled on macOS Maps: the panel glides out to the left while the map stays put. */
:root { --slide: 380ms; --ease-out: cubic-bezier(0.32, 0.72, 0, 1); --ease-in: cubic-bezier(0.4, 0, 0.6, 1); }
.panel { transition: transform var(--slide) var(--ease-out), box-shadow var(--slide) var(--ease-out), visibility 0s linear 0s; will-change: transform; }
body.panel-hidden .panel { transform: translateX(calc(-100% - 24px)); box-shadow: none; visibility: hidden;
  transition: transform 300ms var(--ease-in), box-shadow 300ms var(--ease-in), visibility 0s linear 300ms; }
.scope, .disclaimer, .stats { transition: left var(--slide) var(--ease-out); }
body.panel-hidden .scope, body.panel-hidden .disclaimer, body.panel-hidden .stats { transition-duration: 300ms; transition-timing-function: var(--ease-in); }
.show-panel { opacity: 0; transform: scale(0.85); pointer-events: none; transition: opacity 160ms ease, transform 160ms ease; }
body.panel-hidden .show-panel { opacity: 1; transform: none; pointer-events: auto; transition: opacity 220ms ease 180ms, transform 260ms var(--ease-out) 180ms; }
body.no-anim *, body.no-anim *::before { transition: none !important; }
@media (prefers-reduced-motion: reduce) {
  .panel, .scope, .disclaimer, .stats, .show-panel, body.panel-hidden .panel, body.panel-hidden .show-panel { transition: opacity 150ms ease, visibility 0s linear 150ms !important; transform: none !important; }
  body.panel-hidden .panel { opacity: 0; }
}

/* Detail */
.detail-head { padding: 14px 14px 0 8px; display: flex; align-items: center; justify-content: space-between; }
.back-link { display: flex; align-items: center; gap: 2px; height: 44px; padding: 0 6px; border: none; background: none; color: var(--accent); font: 400 17px/22px var(--font); }
.close-btn { width: 30px; height: 30px; border-radius: 15px; border: none; background: rgba(118,118,128,0.16); color: #3C3C43; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.detail-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 6px 18px 18px; display: flex; flex-direction: column; gap: 20px; }
.detail-body h1 { margin: 0; font: 700 28px/34px var(--font); letter-spacing: -0.4px; overflow-wrap: anywhere; }
.detail-body .sub { margin: 4px 0 0; font: 400 15px/20px var(--font); color: var(--ink-2); }
.actions { display: flex; gap: 8px; }
.actions .btn { flex: 1 1 0; }
.group { display: flex; flex-direction: column; gap: 8px; }
.group h2 { margin: 0 0 0 4px; font: 600 13px/18px var(--font); color: var(--ink-2); }
.card { border-radius: 12px; background: #fff; box-shadow: 0 0 0 0.5px rgba(0,0,0,0.06); overflow: hidden; }
.kv { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 10px 14px; border-bottom: 0.5px solid var(--hair); }
.kv:last-child { border-bottom: none; }
.kv .k { font: 400 15px/20px var(--font); color: var(--ink-2); flex-shrink: 0; }
.kv .v { font: 400 15px/20px var(--font); text-align: right; overflow-wrap: anywhere; }
.kv .v.muted { color: var(--ink-2); }
.kv.hl .v { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.status { display: flex; align-items: center; gap: 4px; font: 500 15px/20px var(--font); }
.status.ok { color: #1E7B34; }
.status.no { color: var(--ink-2); }
.status.pending { color: #8A4B00; }
.status.inferred { color: var(--ink-3); font-size: 14px; text-align: right; }
.card.list-card { padding: 0 14px; }
.note { margin: 0; font: 400 12px/16px var(--font); color: var(--ink-2); padding: 0 4px; }

/* Floating map chrome */
.scope { position: fixed; left: var(--chrome-left); top: 16px; border-radius: 11px; z-index: 2; display: flex; align-items: center; gap: 4px; }
.scope .mode { width: 300px; }
.scope > .vsep { align-self: center; height: 22px; }
.scope .segmented { height: 36px; }
.scope .segmented button { height: 32px; }

.stats { position: fixed; right: 16px; top: 16px; display: flex; align-items: center; padding: 6px 0; border-radius: 11px; z-index: 2; }
.stat { display: flex; flex-direction: column; gap: 0; padding: 0 10px; }
.stat b { font: 700 14px/18px var(--font); font-variant-numeric: tabular-nums; letter-spacing: -0.2px; }
.stat span { font: 400 10px/13px var(--font); color: var(--ink-2); white-space: nowrap; }
.vsep { width: 0.5px; align-self: stretch; background: rgba(60,60,67,0.2); }
.link-btn { display: flex; align-items: center; gap: 2px; height: 24px; margin: 0 10px; padding: 0; border: none; background: none; color: var(--accent); font: 600 11px/1 var(--font); white-space: nowrap; }
.link-btn svg { width: 11px; height: 11px; }

.map-controls { position: fixed; right: 16px; top: 50%; transform: translateY(-50%); transition: top var(--slide) var(--ease-out); display: flex; flex-direction: column; gap: 10px; align-items: flex-end; z-index: 2; }
.zoom { border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
.zoom button { width: 44px; height: 44px; border: none; background: transparent; display: flex; align-items: center; justify-content: center; }
.zoom .sep { height: 0.5px; background: rgba(60,60,67,0.2); margin: 0 8px; }

/* Provider share: a Liquid Glass capsule that opens upward into a breakdown. */
:root {
  --lg-bg: rgba(255,255,255,0.46);
  --lg-edge: rgba(255,255,255,0.75);
  --lg-rim: rgba(0,0,0,0.07);
  --lg-blur: blur(22px) saturate(190%);
}
.share { position: fixed; right: 16px; bottom: 16px; width: 288px; z-index: 3; display: flex; flex-direction: column;
  border-radius: 22px; background: var(--lg-bg); -webkit-backdrop-filter: var(--lg-blur); backdrop-filter: var(--lg-blur);
  box-shadow: inset 0 0.5px 0 var(--lg-edge), inset 0 0 0 0.5px var(--lg-edge), 0 0 0 0.5px var(--lg-rim), 0 4px 14px rgba(0,0,0,0.06);
  transition: border-radius var(--slide) var(--ease-out); }
.share.open { border-radius: 20px; }
.share-detail { display: grid; grid-template-rows: 0fr; transition: grid-template-rows var(--slide) var(--ease-out); }
.share.open .share-detail { grid-template-rows: 1fr; }
.share-detail-clip { min-height: 0; overflow: hidden; }
.share-detail-body { max-height: min(56vh, 460px); overflow-y: auto; padding: 16px 16px 4px; display: flex; flex-direction: column; gap: 12px;
  opacity: 0; transform: translateY(8px) scale(0.98); transform-origin: bottom center;
  transition: opacity 160ms ease, transform var(--slide) var(--ease-out); }
.share.open .share-detail-body { opacity: 1; transform: none; transition: opacity 220ms ease 90ms, transform var(--slide) var(--ease-out); }
.share-detail-body .legend { gap: 5px; }
.share-capsule { height: 56px; display: flex; align-items: center; gap: 8px; padding: 0 8px 0 16px; }
.share-main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.share-label { font: 600 11px/13px var(--font); color: var(--ink-2); }
.share-bar { height: 11px; display: flex; border-radius: 6px; overflow: hidden; background: var(--fill); }
.share-bar .seg { flex: none; height: 100%; min-width: 0; padding: 0; border: none; border-radius: 0; cursor: default;
  transition: width 320ms var(--ease-out), opacity 160ms ease, filter 160ms ease;
  box-shadow: inset -1px 0 0 rgba(255,255,255,0.55); }
.share-bar .seg:last-child { box-shadow: none; }
.share-bar.hovering .seg:not(.on) { opacity: 0.4; }
.share-bar .seg.on { filter: saturate(1.15) brightness(1.06); }
.share-bar .seg:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.share-toggle { flex: none; width: 32px; height: 32px; border-radius: 16px; border: none; background: transparent; color: var(--ink-2);
  display: flex; align-items: center; justify-content: center; transition: background 160ms ease, color 160ms ease; }
.share-toggle:hover { background: var(--fill); color: var(--ink); }
.share-toggle svg { transition: transform var(--slide) var(--ease-out); }
.share.open .share-toggle svg { transform: rotate(180deg); }
.share-tip { position: fixed; z-index: 6; transform: translate(-50%, calc(-100% + 4px)); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 12px; white-space: nowrap;
  background: var(--lg-bg); -webkit-backdrop-filter: var(--lg-blur); backdrop-filter: var(--lg-blur);
  box-shadow: inset 0 0 0 0.5px var(--lg-edge), 0 0 0 0.5px var(--lg-rim), 0 4px 12px rgba(0,0,0,0.08);
  font: 500 13px/16px var(--font); color: var(--ink); transition: opacity 140ms ease, transform 180ms var(--ease-out); }
.share-tip.show { opacity: 1; transform: translate(-50%, -100%); }
.share-tip b { font-weight: 700; margin-left: 2px; font-variant-numeric: tabular-nums; }
.share-tip.multi { flex-direction: column; align-items: stretch; gap: 4px; padding: 8px 12px 10px; white-space: normal; min-width: 180px; }
.share-tip .tip-head { display: flex; align-items: center; gap: 6px; }
.share-tip .tip-sub { font: 400 11px/14px var(--font); color: var(--ink-2); }
.share-tip .tip-list { display: flex; flex-direction: column; gap: 2px; margin-top: 2px; max-height: 180px; overflow: hidden; font: 400 12px/16px var(--font); }
.share-tip .tip-list div { display: flex; align-items: center; gap: 6px; }
.share-tip .tip-list .nm { flex: 1; }
.share-tip .tip-list span:last-child { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.share-tip .dot { flex: none; }
/* Vertically centred on the right; when the share breakdown is tall enough to reach it, the
   controls rise just above the panel. 45px is half the zoom control's height. */
body.share-open .map-controls { top: min(50%, calc(100vh - var(--share-h, 44px) - 28px - 45px)); }
.share-head { display: flex; align-items: baseline; justify-content: space-between; }
.share-head h2 { margin: 0; font: 600 15px/20px var(--font); }
.share-head span { font: 400 12px/16px var(--font); color: var(--ink-2); }
.bar { display: flex; gap: 2px; height: 8px; border-radius: 4px; overflow: hidden; background: var(--fill); }
.legend { display: flex; flex-direction: column; gap: 6px; }
.legend-row { display: flex; align-items: center; gap: 8px; font: 400 13px/18px var(--font); }
.legend-row .name { flex: 1; }
.legend-row .n { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.legend-row .pct { width: 40px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }

.disclaimer { position: fixed; left: var(--chrome-left); bottom: 16px; margin: 0; padding: 4px 10px; border-radius: 8px; background: rgba(255,255,255,0.7); font: 400 11px/14px var(--font); color: var(--ink-3); z-index: 2; }
.stats-mobile { display: none; }

/* Map markers */
.sel-marker { pointer-events: none; }
.sel-marker svg { display: block; filter: drop-shadow(0 1px 1.2px rgba(0,0,0,0.3)); }
.map-label { position: absolute; left: 22px; top: 8px; padding: 6px 10px; border-radius: 10px; background: rgba(255,255,255,0.86); -webkit-backdrop-filter: blur(30px) saturate(180%); backdrop-filter: blur(30px) saturate(180%); box-shadow: var(--glass-shadow); font: 600 13px/16px var(--font); color: var(--ink); white-space: nowrap; }
.maplibregl-popup.hover-pop .maplibregl-popup-content { padding: 6px 10px; border-radius: 10px; font: 600 13px/16px var(--font); box-shadow: var(--glass-shadow); }
.maplibregl-popup.hover-pop .maplibregl-popup-content small { display: block; font-weight: 400; color: var(--ink-2); }
.maplibregl-ctrl-attrib { font-family: var(--font); }
.maplibregl-ctrl-bottom-right { right: 312px; }

.toast { position: fixed; left: 50%; bottom: 28px; transform: translate(-50%, 20px); padding: 10px 16px; border-radius: 12px; background: rgba(29,29,31,0.92); color: #fff; font: 500 14px/18px var(--font); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Dialogs */
.dlg { border: none; padding: 0; border-radius: 20px; width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 48px); background: #F2F2F7; color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,0.25); }
.dlg-wide { width: min(1100px, calc(100vw - 24px)); }
.dlg::backdrop { background: rgba(0,0,0,0.25); }
.dlg-inner { display: flex; flex-direction: column; gap: 14px; padding: 18px; max-height: calc(100vh - 48px); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.dlg-head h2 { margin: 0; font: 700 22px/28px var(--font); letter-spacing: -0.3px; }
.dlg-note, .hint { margin: 0; font: 400 13px/18px var(--font); color: var(--ink-2); }
.hint.ok { color: #1E7B34; }
.hint.err { color: #C4221F; }
.field { display: flex; flex-direction: column; gap: 6px; font: 600 13px/18px var(--font); color: var(--ink-2); position: relative; }
.field input, .field select { height: 44px; padding: 0 12px; border-radius: 10px; border: none; background: #fff; box-shadow: 0 0 0 0.5px rgba(0,0,0,0.1); font: 400 15px/20px var(--font); color: var(--ink); width: 100%; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dlg-foot { display: flex; gap: 10px; margin-top: 4px; }
.ac-list { position: absolute; left: 0; right: 0; top: 74px; margin: 0; padding: 6px; list-style: none; border-radius: 12px; z-index: 5; max-height: 260px; overflow-y: auto; background: rgba(255,255,255,0.97); }
.ac-list li { padding: 9px 10px; border-radius: 8px; font: 400 14px/18px var(--font); color: var(--ink); cursor: pointer; }
.ac-list li small { color: var(--ink-2); display: block; }
.ac-list li[aria-selected="true"], .ac-list li:hover { background: var(--fill); }
.prose p { margin: 0 0 12px; font: 400 15px/22px var(--font); }
.table-wrap { overflow: auto; border-radius: 12px; background: #fff; box-shadow: 0 0 0 0.5px rgba(0,0,0,0.06); }
table { border-collapse: collapse; width: 100%; font: 400 13px/18px var(--font); }
th, td { text-align: left; padding: 8px 12px; border-bottom: 0.5px solid var(--hair); white-space: nowrap; }
th { position: sticky; top: 0; background: #fafafa; font-weight: 600; color: var(--ink-2); z-index: 1; }
tr.hl td { background: #E8F1FD; }
td.num { font-variant-numeric: tabular-nums; color: var(--ink-2); }
td.wrap { white-space: normal; min-width: 420px; color: var(--ink-2); }

/* Narrow desktop: stack the summary under the mode toggle */
@media (max-width: 1180px) and (min-width: 761px) {
  .stats { left: var(--chrome-left); right: auto; top: 60px; }
}
@media (max-height: 720px) and (min-width: 761px) {
  .share-detail-body { max-height: 46vh; }
}

/* Phone */
@media (max-width: 760px) {
  .show-panel { top: auto; left: 12px; bottom: calc(16px + env(safe-area-inset-bottom)); }
  body.panel-hidden .panel { transform: translateY(calc(100% + 24px)); }
  .map-controls { transition: bottom var(--slide) var(--ease-out); }
  body.panel-hidden .map-controls { bottom: 76px; }
  body.panel-hidden .maplibregl-ctrl-bottom-right { bottom: 0; }
}
@media (max-width: 760px) {
  :root { --panel-w: 100vw; }
  .panel { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: 46vh; border-radius: 22px 22px 0 0; transition: height .3s var(--ease-out), transform var(--slide) var(--ease-out), visibility 0s linear 0s; padding-bottom: env(safe-area-inset-bottom); }
  .panel.expanded { height: calc(100vh - 72px); height: calc(100dvh - 72px); }
  .view { border-radius: 22px 22px 0 0; }
  .grabber { display: flex; justify-content: center; align-items: center; height: 18px; border: none; background: none; padding: 0; flex-shrink: 0; }
  .grabber span { width: 36px; height: 5px; border-radius: 3px; background: rgba(60,60,67,0.3); }
  .panel-head { padding-top: 4px; gap: 10px; }
  .title-row h1, .title-select select { font-size: 22px; }
  .stats-mobile { display: flex; gap: 8px; }
  .stats-mobile div { flex: 1; display: flex; flex-direction: column; padding: 8px 10px; border-radius: 12px; background: var(--fill); }
  .stats-mobile b { font: 700 17px/22px var(--font); font-variant-numeric: tabular-nums; }
  .stats-mobile span { font: 400 12px/16px var(--font); color: var(--ink-2); }
  .scope { left: 12px; right: 12px; top: 12px; width: auto !important; }
  .stats, .disclaimer { display: none; }
  .share { right: auto; left: 12px; bottom: calc(46vh + 12px); width: min(270px, calc(100vw - 88px)); transition: border-radius var(--slide) var(--ease-out), bottom var(--slide) var(--ease-out); }
  body.panel-hidden .share { bottom: 72px; }
  .share-detail-body { max-height: 36vh; }
  body.share-open .map-controls { top: auto; bottom: calc(46vh + 12px); }
  body.share-open.panel-hidden .map-controls { bottom: 76px; }
  .map-controls { right: 12px; top: auto; transform: none; bottom: calc(46vh + 12px); transition: bottom var(--slide) var(--ease-out); }
  .maplibregl-ctrl-bottom-right { right: 0; bottom: 46vh; }
  .detail-body h1 { font-size: 24px; line-height: 30px; }
  /* Whole sheet scrolls on phones; footer stays pinned. */
  #listView { overflow-y: auto; }
  #listView .list { flex: none; overflow: visible; }
  #listView .chips { padding-top: 12px; }
  .panel-foot { position: sticky; bottom: 0; margin-top: auto; background: rgba(250,250,252,0.96); }
  .row2 { grid-template-columns: 1fr; }
}

/* Territory map: hover card */
.area-card { position: fixed; left: 0; top: 0; z-index: 4; width: 300px; padding: 14px; border-radius: 16px; pointer-events: none; display: flex; flex-direction: column; gap: 10px; font: 400 13px/18px var(--font); }
.area-card.pinned { pointer-events: auto; left: 50%; top: 64px; transform: translateX(-50%) !important; width: min(340px, calc(100vw - 24px)); }
.ac-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.ac-level { font: 600 11px/14px var(--font); color: var(--ink-2); text-transform: uppercase; letter-spacing: 0.4px; }
.ac-head h3 { margin: 2px 0 0; font: 700 16px/20px var(--font); letter-spacing: -0.2px; }
.ac-count { margin: 0; color: var(--ink-2); }
.ac-count b { color: var(--ink); font-size: 15px; }
.ac-rows { display: flex; flex-direction: column; gap: 4px; }
.ac-row { display: flex; align-items: center; gap: 8px; }
.ac-row .name { flex: 1; }
.ac-row .n { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.ac-row .pct { width: 48px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.ac-facts { margin: 0; display: flex; flex-direction: column; gap: 4px; padding-top: 8px; border-top: 0.5px solid var(--hair); }
.ac-facts div { display: flex; justify-content: space-between; gap: 12px; }
.ac-facts dt { color: var(--ink-2); }
.ac-facts dd { margin: 0; text-align: right; display: flex; align-items: center; gap: 6px; font-weight: 500; }
.ac-hint { margin: 0; font-size: 12px; color: var(--ink-2); }
.area-card .btn { height: 36px; font-size: 14px; }

/* Legend */
.key { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 0.5px solid var(--hair); }
.key-row { display: flex; align-items: center; gap: 8px; font: 400 12px/16px var(--font); color: var(--ink-2); }
.sw { width: 14px; height: 10px; border-radius: 2px; flex-shrink: 0; }
/* Legend swatches mirror the map: solid, gradient, opacity and pale tints. */
:root { --none: #D8DCE2; }
.sw-none { background: var(--none); opacity: 0.7; }
.key-lead { flex-wrap: wrap; gap: 6px 12px; color: var(--ink); }
.lead-chip { display: inline-flex; align-items: center; gap: 6px; font: 500 12px/16px var(--font); }
.lead-chip.muted { color: var(--ink-2); font-weight: 400; }
.key-note { margin: -2px 0 4px; font: 400 11px/14px var(--font); color: var(--ink-2); }
.key-ramp { height: 10px; border-radius: 3px; }
.key-scale { display: flex; justify-content: space-between; font: 400 11px/14px var(--font); color: var(--ink-2); }
.inline-link { border: none; background: none; padding: 0; color: var(--accent); font: inherit; font-weight: 500; }
.stat-lead b { display: flex; align-items: center; gap: 4px; max-width: 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat b small { font-size: 10px; font-weight: 600; color: var(--ink-2); }
/* Toolbar: Liquid Glass like the share capsule; the area name gets the extra width. */
.stats { background: var(--lg-bg); -webkit-backdrop-filter: var(--lg-blur); backdrop-filter: var(--lg-blur);
  box-shadow: inset 0 0.5px 0 var(--lg-edge), inset 0 0 0 0.5px var(--lg-edge), 0 0 0 0.5px var(--lg-rim); padding: 7px 4px; }
.stat b { font-weight: 600; }
.stat-area { min-width: 96px; max-width: 230px; }
.stat-area b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stats-mobile .m-area { flex: 1.6; min-width: 0; }
.stats-mobile .m-area b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .dot { width: 6px; height: 6px; }
.stats-mobile b.lead { display: flex; align-items: center; gap: 5px; white-space: nowrap; overflow: hidden; }

/* Filters */
.filter-btn { display: flex; align-items: center; gap: 4px; height: 28px; padding: 0 2px 0 6px; flex-shrink: 0; border: none; background: none; color: var(--accent); font: 500 13px/1 var(--font); }
.filter-btn.active { font-weight: 600; }
.filter-count:not(:empty) { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font: 600 11px/18px var(--font); text-align: center; }
.active-bar { margin: 8px 18px 0; padding: 7px 12px; border-radius: 10px; background: rgba(0,113,227,0.1); color: var(--ink); display: flex; justify-content: space-between; gap: 10px; font: 500 12px/16px var(--font); }
.field input[type="range"] { height: 28px; padding: 0; box-shadow: none; background: transparent; accent-color: var(--accent); }
.prose h3 { margin: 16px 0 6px; font: 600 15px/20px var(--font); }
.prose h3:first-child { margin-top: 0; }

@media (max-width: 1040px) and (min-width: 761px) {
  .disclaimer { display: none; }
}
@media (max-width: 760px) {
  .scope .mode { width: 100%; }
  .area-card:not(.pinned) { display: none; }
  .area-card.pinned { top: 60px; }
}

/* Dark theme, following the system setting */
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --accent: #0A84FF;
    --ink: #F5F5F7;
    --ink-2: #A1A1A6;
    --ink-3: #C7C7CC;
    --fill: rgba(118,118,128,0.24);
    --hair: rgba(84,84,88,0.65);
    --glass: rgba(30,30,32,0.8);
    --glass-shadow: 0 0 0 0.5px rgba(255,255,255,0.1), 0 10px 36px rgba(0,0,0,0.45);
  }
  body { background: #1C1C1E; }
  .segmented button[aria-pressed="true"] { background: #636366; box-shadow: none; }
  .panel.detail { background: rgba(28,28,30,0.9); }
  .card, .table-wrap, .field input, .field select, .btn-white { background: #2C2C2E; box-shadow: 0 0 0 0.5px rgba(255,255,255,0.08); }
  .dlg { background: #1C1C1E; }
  .menu { background: rgba(44,44,46,0.96); }
  th { background: #2C2C2E; }
  tr.hl td { background: #0B3A6E; }
  .close-btn { background: rgba(118,118,128,0.3); color: #EBEBF5; }
  .disclaimer { background: rgba(28,28,30,0.72); }
  .map-label { background: rgba(44,44,46,0.88); }
  .vsep, .zoom .sep { background: rgba(84,84,88,0.65); }
  .status.ok { color: #30D158; }
  .status.pending, .badge { color: #FFD08A; }
  .badge { background: #4A3000; }
  .active-bar { background: rgba(10,132,255,0.18); }
  .grabber span { background: rgba(235,235,245,0.3); }
  :root { --none: #3A3A3C; }
  :root { --lg-bg: rgba(36,36,40,0.5); --lg-edge: rgba(255,255,255,0.16); --lg-rim: rgba(0,0,0,0.35); }
  .share-bar .seg { box-shadow: inset -1px 0 0 rgba(0,0,0,0.35); }
  .maplibregl-popup.hover-pop .maplibregl-popup-content { background: #2C2C2E; color: var(--ink); }
  .maplibregl-popup.hover-pop .maplibregl-popup-tip { border-top-color: #2C2C2E; border-bottom-color: #2C2C2E; }
  .maplibregl-ctrl-attrib, .maplibregl-ctrl-attrib.maplibregl-compact { background: rgba(28,28,30,0.8); color: var(--ink-2); }
  .maplibregl-ctrl-attrib a { color: var(--ink-2); }
  .maplibregl-ctrl-attrib-button { filter: invert(1); }
}
@media (prefers-color-scheme: dark) and (max-width: 760px) {
  .panel-foot { background: rgba(28,28,30,0.96); }
}
@media (prefers-reduced-motion: reduce) {
  .share, .share-detail, .share-detail-body, .share-toggle svg, .share-tip, .map-controls { transition-duration: 1ms !important; transition-delay: 0s !important; }
  .share-detail-body, .share-tip.show { transform: none !important; }
}

/* Cluster breakdown popover: same glass as the share capsule. */
.maplibregl-popup.cluster-pop { z-index: 4; }
.maplibregl-popup.cluster-pop .maplibregl-popup-tip { display: none; }
.maplibregl-popup.cluster-pop .maplibregl-popup-content { padding: 9px 12px 10px; border-radius: 14px; min-width: 170px;
  background: var(--lg-bg); -webkit-backdrop-filter: var(--lg-blur); backdrop-filter: var(--lg-blur);
  box-shadow: inset 0 0 0 0.5px var(--lg-edge), 0 0 0 0.5px var(--lg-rim), 0 4px 12px rgba(0,0,0,0.08);
  font: 400 12px/16px var(--font); color: var(--ink); }
.cluster-pop .cp-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 5px; font: 500 12px/16px var(--font); color: var(--ink-2); }
.cluster-pop .cp-head b { font: 700 14px/18px var(--font); color: var(--ink); margin-right: 3px; }
.cluster-pop .cp-head .close-btn { width: 22px; height: 22px; }
.cluster-pop .cp-rows { display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow-y: auto; }
.cluster-pop .cp-rows div { display: flex; align-items: center; gap: 6px; }
.cluster-pop .cp-rows .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cluster-pop .cp-rows .n { color: var(--ink-2); font-variant-numeric: tabular-nums; }
.cluster-pop .cp-rows .pc { width: 38px; text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.cluster-pop .dot { width: 7px; height: 7px; border-radius: 4px; flex: none; }
.cluster-pop .cp-members { margin: 0 0 0 13px; font: 400 11px/14px var(--font); color: var(--ink-2); }
.cluster-pop .cp-zoom { width: 100%; height: 34px; margin-top: 8px; font-size: 14px; }

/* Cooperative-gesture hint (MapLibre's own overlay): a light frost over the map with the hint in
   a glass capsule. It appears only when a gesture is blocked and fades out shortly after. */
.maplibregl-cooperative-gesture-screen { padding: 16px; background: rgba(232,236,236,0.22);
  -webkit-backdrop-filter: blur(2.5px); backdrop-filter: blur(2.5px); color: var(--ink); font: 500 15px/20px var(--font);
  transition: opacity 260ms ease 1.1s; }
.maplibregl-cooperative-gesture-screen.maplibregl-show { transition: opacity 180ms ease; }
.maplibregl-cooperative-gesture-screen > div { padding: 11px 20px; border-radius: 999px; text-align: center;
  background: rgba(255,255,255,0.72); -webkit-backdrop-filter: var(--lg-blur); backdrop-filter: var(--lg-blur);
  box-shadow: inset 0 0.5px 0 var(--lg-edge), inset 0 0 0 0.5px var(--lg-edge), 0 0 0 0.5px var(--lg-rim), 0 6px 20px rgba(0,0,0,0.08); }
@media (max-width: 760px) {
  /* Centre the hint in the map area above the bottom sheet. */
  .maplibregl-cooperative-gesture-screen { padding-bottom: calc(46vh + 16px); }
  body.panel-hidden .maplibregl-cooperative-gesture-screen { padding-bottom: 16px; }
}
@media (prefers-color-scheme: dark) {
  .maplibregl-cooperative-gesture-screen { background: rgba(28,28,30,0.26); }
  .maplibregl-cooperative-gesture-screen > div { background: rgba(44,44,48,0.78); }
  }
@media (prefers-reduced-motion: reduce) {
  .maplibregl-cooperative-gesture-screen, .maplibregl-cooperative-gesture-screen.maplibregl-show { transition: opacity 1ms linear 1.2s; }
  .maplibregl-cooperative-gesture-screen.maplibregl-show { transition-delay: 0s; }
}
