/* ============================================================
   MAP UI LAYOUT PRINCIPLES — foundational rules
   ============================================================

   The map has two classes of floating UI; they coexist by
   following a few fixed rules. If you're adding a new panel,
   button, or viewer that floats over the map, pick the class
   it belongs to and follow the rules for that class.

   1. CONTEXT surfaces — persistent, represent user state.
          * #details-sidebar (selection panel, right edge)
          * #mapillary-container.floating-viewer (Street View)
      These own their space. Users open them deliberately and
      expect them to stay put. They do NOT shift or collapse
      when transient UI appears.

   2. CONTROL surfaces — transient, user opens → picks → closes.
          * #filter-panel
          * #layers-panel
          * #boundaries-popover
      These anchor to the top-right. They:
        (a) auto-close each other (one at a time), via the
            'floating-panel-open' CustomEvent.
        (b) dismiss on outside click and Escape.
        (c) never occlude a context surface — they shift left
            by --sidebar-width when body.sidebar-visible, so
            the selection panel is always visible beneath them.

   3. CONTEXT surfaces yield to CONTROL surfaces on the same
      edge. The Street View PiP sits bottom-right; if a control
      panel opens, SV shifts further left by --control-panel-
      offset so the user's current pick remains visible. When
      the control panel closes, SV slides back.

   The CSS variables that implement these rules:
        --sidebar-width          width of the selection sidebar
        --control-panel-offset   width + gap of the currently-
                                 open control panel (0px when
                                 no panel is open)

   Transitions on 'right' are deliberate: a sudden snap looks
   like a bug, a smooth slide reads as intentional reflow.
   ============================================================ */

/* ============================================================
   DESIGN TOKENS — foundational primitives
   ============================================================
   Rules:
   * Components reference tokens, not raw values. If you're
     about to type '4px' or '#fff' in a panel style, look for
     a token first. Adding a new one is cheap; drifting is
     expensive.
   * Tokens are grouped by axis: spacing, radius, shadow,
     motion, z-index, color. Adding a new axis = new group.
   * Dark-mode tokens override semantic colors under
     body.theme-dark. Never theme individual components
     directly — always theme via token.
   * Layout primitives (--sidebar-width, --control-panel-
     offset) are set dynamically by JS; they live here for
     documentation even though their values change at runtime.
   ============================================================ */
body {
    /* Layout primitives — set/overridden at runtime by JS.
       Keep in sync with the literal 380px in index.html
       #details-sidebar { width } — the variable here drives
       every offset that anchors against the sidebar's left
       edge (icon rail, top-right popovers, floating header). */
    --sidebar-width: 380px;
    --control-panel-offset: 0px;
    /* Horizontal space the right-edge icon rail occupies,
       including the gap between it and anything to its left.
       Panels anchored top-right use this so they don't cover
       the rail. Rail itself is 36px + 4px padding on each
       side = 44px, plus a 20px gap = 64px. */
    --rail-gutter: 64px;

    /* Spacing scale (4px base grid) */
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;

    /* Radius */
    --radius-sm: 3px;
    --radius-md: 4px;
    --radius-lg: 8px;
    --radius-pill: 999px;

    /* Shadow */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --shadow-lg: 0 6px 18px rgba(0, 0, 0, 0.22);

    /* Motion */
    --motion-fast: 0.15s;
    --motion-base: 0.25s;

    /* Z-index layers */
    --z-map: 1;
    --z-floating: 950;
    --z-panel: 1000;
    --z-header: 1001;
    --z-modal: 2000;

    /* Semantic colors — light theme.
       Values chosen to match the most common hex already in
       use so the tokens pass is visually invisible. */
    --color-bg-elevated: #fff;
    --color-bg-muted: #f8f9fa;
    --color-bg-hover: #f5f5f5;
    --color-border: #eee;
    --color-border-strong: #dee2e6;
    --color-fg-primary: #333;
    --color-fg-secondary: #495057;
    --color-fg-muted: #6c757d;
    --color-accent: #0080ff;
    --color-accent-strong: #0066cc;
}

/* Dark-theme overrides. Only semantic colors change; spacing,
   radius, motion, and z-index are theme-agnostic. */
body.theme-dark {
    --color-bg-elevated: #1e1e1e;
    --color-bg-muted: #2a2a2a;
    --color-bg-hover: #2a2a2a;
    --color-border: #333;
    --color-border-strong: #444;
    --color-fg-primary: #e8eaed;
    --color-fg-secondary: #c9ccd1;
    --color-fg-muted: #9aa0a6;
    --color-accent: #4dabf7;
    --color-accent-strong: #339af0;
}

/* Base typography improvements */
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    line-height: 1.5;
    color: #333;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
    margin-top: 0;
    margin-bottom: 0.5rem;
    font-weight: 600;
    line-height: 1.2;
}

/* Header improvements */
#floating-header {
    padding: 5px 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 4px;
    z-index: 1001;
}

#home-button {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: #0080ff;
}

/* Search improvements */
#search-container {
    flex-grow: 1;
    max-width: 500px;
    margin: 0 20px;
}

#search-input {
    height: 38px;
    border-radius: 4px 0 0 4px;
    border: 1px solid #ddd;
    padding: 0 12px;
    font-size: 14px;
    width: 100%;
    transition: border-color 0.2s;
}

#search-input:focus {
    outline: none;
    border-color: #0080ff;
}

#search-button {
    height: 38px;
    background-color: #0080ff;
    border-radius: 0 4px 4px 0;
    transition: background-color 0.2s;
}

#search-button:hover {
    background-color: #0066cc;
}

/* Button improvements */
.header-button {
    padding: 8px 12px;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    font-weight: 500;
}

.header-button:hover {
    background-color: rgba(0, 128, 255, 0.1);
}

.header-button.active {
    background-color: rgba(0, 128, 255, 0.15);
    color: var(--color-accent);
}

/* ---- Icon rail --------------------------------------------------
   The right-edge floating menu that hosts Filters / Layers /
   Boundaries / Settings. A vertical stack of icon-only buttons
   in a rounded card, same visual family as the panels it
   opens. See the layout-principles block at the top of this
   stylesheet — the rail is a CONTROL cluster, so it shifts
   left along with its panels when the selection sidebar is
   visible. */
#icon-rail {
    position: absolute;
    top: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-1);
    background: var(--color-bg-elevated);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    z-index: var(--z-panel);
    transition: right var(--motion-base) ease;
}
/* Shift the rail left when the selection sidebar is visible
   so it stays 10px off the sidebar's inner edge. Note this is
   sidebar + 10px, NOT sidebar + rail-gutter: the rail's whole
   job is to live INSIDE the rail-gutter area (64px wide).
   Panels anchor at sidebar + rail-gutter, so the rail needs to
   be at the smaller offset (sidebar + 10) to sit between the
   panel and the sidebar. If we used rail-gutter here, the rail
   would overlap the panel. */
body.sidebar-visible #icon-rail {
    right: calc(var(--sidebar-width, 300px) + 10px);
}
/* On mobile the sidebar slides up from the bottom, not in from
   the right, so the rail stays pinned to the right edge. */
@media (max-width: 768px) {
    body.sidebar-visible #icon-rail {
        right: 10px;
    }
}

/* Icon-only button used by the rail. 36x36 with centered icon;
   no text. Tooltip via the title attribute, accessible name
   via the aria-label attribute. */
.icon-rail-button {
    position: relative;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--color-fg-secondary);
    cursor: pointer;
    padding: 0;
    transition: background-color var(--motion-fast), color var(--motion-fast);
}
.icon-rail-button:hover {
    background-color: var(--color-bg-hover);
    color: var(--color-fg-primary);
}
.icon-rail-button:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}
.icon-rail-button.active {
    background-color: rgba(0, 128, 255, 0.12);
    color: var(--color-accent);
}
/* Active-state indicator for boundaries (the only rail button
   with an external "is anything selected?" signal). A tiny dot
   in the top-right corner of the icon. */
.icon-rail-button.has-active::after {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-accent);
    box-shadow: 0 0 0 2px var(--color-bg-elevated);
}
/* Filter badge sits inside the button. It used to float to the
   right of the "Filters" label; in icon-only mode it overlays
   the top-right of the funnel icon. */
#filter-button .filter-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    min-width: 14px;
    padding: 0;
    font-size: 9px;
    line-height: 14px;
    margin: 0;
    border-radius: var(--radius-pill);
    box-shadow: 0 0 0 2px var(--color-bg-elevated);
}

/* ---- Settings popover ------------------------------------------
   Anchored top-right like the other rail popovers, offset so it
   doesn't cover the rail itself. Same visual language as
   #layers-panel / #boundaries-popover. */
#settings-popover {
    position: absolute;
    top: 70px;
    right: var(--rail-gutter);
    width: 280px;
    max-height: calc(100vh - 90px);
    background: var(--color-bg-elevated);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: var(--z-panel);
    display: none;
    overflow: hidden;
    flex-direction: column;
    transition: right var(--motion-base) ease;
}
#settings-popover[style*="display: block"] {
    display: flex !important;
}
body.sidebar-visible #settings-popover {
    right: calc(var(--sidebar-width, 300px) + var(--rail-gutter));
}
.settings-popover-header {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.settings-popover-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}
.settings-popover-content {
    padding: var(--space-2) 0;
    overflow-y: auto;
}
.settings-section {
    padding: var(--space-2) var(--space-4) var(--space-3);
}
.settings-section + .settings-section {
    border-top: 1px solid var(--color-border);
}
.settings-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-fg-muted);
    margin: var(--space-1) 0 var(--space-2);
}
.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px var(--space-1);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--motion-fast);
}
.settings-row:hover {
    background-color: var(--color-bg-hover);
}
.settings-row-label {
    font-size: 13.5px;
    color: var(--color-fg-primary);
}
.settings-row input[type="checkbox"] {
    margin: 0;
    cursor: pointer;
}
.settings-action-btn {
    width: 100%;
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border-strong);
    background: var(--color-bg-muted);
    color: var(--color-fg-primary);
    font-size: 13px;
    font-family: inherit;
    cursor: pointer;
    transition: background-color var(--motion-fast);
}
.settings-action-btn:hover {
    background: var(--color-bg-hover);
}
.settings-copy-status {
    margin-top: 6px;
    font-size: 12px;
    color: var(--color-fg-muted);
    min-height: 16px;
}
.settings-copy-status--error {
    color: #b42318;
}
/* Dark-mode: rail + settings inherit from semantic tokens; only
   the shadow needs an opacity bump for visibility on dark bg. */
body.theme-dark #icon-rail,
body.theme-dark #settings-popover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
/* Mobile sheet — full-width bottom sheet for settings too. */
@media (max-width: 767px) {
    #settings-popover {
        top: auto !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        max-height: 60vh !important;
        border-radius: 8px 8px 0 0;
    }
}

/* Panel improvements */
#details-sidebar, #filter-panel {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-radius: 4px;
}

.filter-header {
    padding: 12px 16px;
    border-bottom: 1px solid #eee;
}

.filter-header h3 {
    font-size: 16px;
    font-weight: 600;
    margin: 0;
}

.filter-content {
    padding: 16px;
}

.filter-section-title {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 12px;
    color: #333;
}

.filter-option {
    margin-bottom: 12px;
}

.filter-button {
    padding: 8px 16px;
    border-radius: 4px;
    font-weight: 500;
    transition: all 0.2s;
}

.filter-apply {
    background-color: #0080ff;
    color: white;
}

.filter-apply:hover {
    background-color: #0066cc;
}

.filter-close, .filter-reset {
    background-color: #f5f5f5;
    color: #333;
}

.filter-close:hover, .filter-reset:hover {
    background-color: #e0e0e0;
}

/* ---- Layers panel (floating, anchored to the layers button) --- */
/* Shares the visual language of #filter-panel but is narrower —
   the panel is a compact legend + checkbox list, not a form, so
   it doesn't need the filter panel's width. Positioned against
   the map container so it follows the map when the sidebar
   opens and pushes the map edge inward. */
#layers-panel {
    position: absolute;
    top: 70px;
    right: var(--rail-gutter);
    width: 320px;
    max-height: calc(100vh - 90px);
    background: var(--color-bg-elevated);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: var(--z-panel);
    display: none;
    overflow: hidden;
    flex-direction: column;
    transition: right var(--motion-base) ease;
}
#layers-panel[style*="display: block"] {
    display: flex !important;
}
/* CONTROL surface — shift left when the selection sidebar is
   open so it never occludes the user's current selection.
   See the layout-principles block at the top of this file. */
body.sidebar-visible #layers-panel {
    right: calc(var(--sidebar-width, 300px) + var(--rail-gutter));
}

.layers-panel-header {
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.layers-panel-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.layers-panel-content {
    padding: var(--space-2) 0;
    overflow-y: auto;
    flex: 1 1 auto;
}

.layers-section {
    padding: var(--space-2) var(--space-4) var(--space-3);
}
.layers-section + .layers-section {
    border-top: 1px solid var(--color-border);
}
.layers-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-fg-muted);
    margin: var(--space-1) 0 10px 0;
}

/* Row: [swatch | label-group | checkbox] (the main <label>) plus a
   small "Show in Legend" eye-toggle button on the right. The main
   target stays a <label for=…> so clicking anywhere in it flips the
   visibility checkbox; the legend-toggle is a separate <button> so
   its clicks don't also toggle visibility. */
.layer-row {
    display: flex;
    align-items: center;
    gap: 4px;
    border-radius: var(--radius-md);
}
.layer-row-main {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px var(--space-1);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--motion-fast);
    min-width: 0;
}
.layer-row-main:hover {
    background-color: var(--color-bg-hover);
}
.layer-row-main input[type="checkbox"] {
    margin: 0;
    flex-shrink: 0;
    cursor: pointer;
}
.layer-legend-toggle {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-fg-muted);
    transition: background-color var(--motion-fast), color var(--motion-fast);
    padding: 0;
}
.layer-legend-toggle:hover {
    background-color: var(--color-bg-hover);
    color: var(--color-fg-primary);
}
/* When the layer is included in the Legend, the eye reads as
   "active" — slightly stronger color to distinguish from the
   slashed-eye (excluded) state. */
.layer-legend-toggle[aria-pressed="true"] {
    color: var(--color-fg-primary);
}
.layer-legend-toggle[aria-pressed="false"] {
    color: var(--color-fg-muted);
    opacity: 0.6;
}
.layer-label-group {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.layer-label {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--color-fg-primary);
}
/* Lifetime (∞) badge — inline chip that signals "this layer
   ignores the master date-range picker." Appears next to the
   label in the Layers panel when datePeriod !== 'lifetime'. */
.layer-lifetime-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 0 5px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.4;
    color: var(--color-fg-muted);
    background: var(--color-bg-subtle, rgba(0,0,0,0.05));
    border: 1px solid var(--color-border);
    border-radius: 8px;
    cursor: help;
    vertical-align: middle;
}
body.theme-dark .layer-lifetime-badge {
    background: rgba(255,255,255,0.06);
    color: #999;
}
.layer-description {
    font-size: 11.5px;
    color: var(--color-fg-muted);
    line-height: 1.3;
}

/* Swatches come in three shapes matching legend.shape values. */
.layer-swatch {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border: 1px solid rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
}
.layer-swatch--fill {
    border-radius: var(--radius-sm);
}
.layer-swatch--line {
    height: 3px;
    border-radius: 2px;
    margin: 0 0 0 0;
    align-self: center;
}
.layer-swatch--dot {
    border-radius: 50%;
}

.layers-empty {
    padding: var(--space-5) var(--space-4);
    color: var(--color-fg-muted);
    font-size: 13px;
    text-align: center;
}

/* ---- Legend (read-only summary) ------------------------------- */
/* Desktop: floats bottom-left of the map as a card. Starts
   expanded; collapse shrinks it to an icon-only puck in the
   same corner. The collapsed button and the expanded body
   share the same #legend element — we toggle visibility of the
   two via .legend--expanded / .legend--collapsed classes.
   Mobile: the card is CSS-hidden and a rail button (created in
   js/ui/legend.js) opens the same DOM as a full-width sheet. */
.legend {
    position: absolute;
    left: 20px;
    bottom: 20px;
    z-index: var(--z-control);
    font-family: inherit;
    color: var(--color-fg-primary);
}
.legend .legend-expanded-body {
    display: none;
    width: 280px;
    max-height: calc(50vh);
    background: var(--color-bg-elevated);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    flex-direction: column;
}
.legend .legend-collapsed-button {
    display: none;
    width: 40px;
    height: 40px;
    align-items: center;
    justify-content: center;
    background: var(--color-bg-elevated);
    color: var(--color-fg-primary);
    border: none;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    cursor: pointer;
    padding: 0;
    transition: background-color var(--motion-fast);
}
.legend .legend-collapsed-button:hover {
    background-color: var(--color-bg-hover);
}
.legend.legend--expanded .legend-expanded-body {
    display: flex;
}
.legend.legend--collapsed .legend-collapsed-button {
    display: inline-flex;
}

.legend-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px var(--space-3) 8px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.legend-title {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-fg-muted);
}
.legend-collapse-button {
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--color-fg-muted);
    font-size: 18px;
    line-height: 1;
    padding: 0;
    transition: background-color var(--motion-fast);
}
.legend-collapse-button:hover {
    background-color: var(--color-bg-hover);
    color: var(--color-fg-primary);
}

.legend-content {
    overflow-y: auto;
    padding: 6px 0 10px;
    flex: 1 1 auto;
}
.legend-section {
    padding: 8px var(--space-3) 4px;
}
.legend-section + .legend-section {
    border-top: 1px solid var(--color-border);
}
.legend-section-title {
    font-size: 10.5px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--color-fg-muted);
    margin: 0 0 6px 0;
}

.legend-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 2px;
}
.legend-swatch {
    flex-shrink: 0;
    width: 12px;
    height: 12px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
}
.legend-row-label {
    font-size: 13px;
    color: var(--color-fg-primary);
    line-height: 1.3;
}

.legend-filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}
.legend-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--color-bg-hover);
    font-size: 11.5px;
    line-height: 1.4;
}
.legend-filter-chip-category {
    font-weight: 600;
    color: var(--color-fg-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 10px;
}
.legend-filter-chip-label {
    color: var(--color-fg-primary);
}

.legend-empty {
    padding: var(--space-4) var(--space-3);
    font-size: 12px;
    color: var(--color-fg-muted);
    text-align: center;
    line-height: 1.4;
}

/* Rail button is only an entry point on mobile. Desktop hides
   it because the Legend is already visible bottom-left. */
.legend-rail-button { display: inline-flex; }
@media (min-width: 769px) {
    .legend-rail-button { display: none; }
}

/* Mobile layout: the bottom-left card is hidden; the rail
   button opens the same body as a bottom sheet. */
@media (max-width: 768px) {
    /* Hide the desktop card outright. The body becomes a
       fixed bottom sheet when .legend--mobile-open is set. */
    .legend {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: var(--z-panel);
    }
    .legend .legend-collapsed-button {
        display: none !important;
    }
    .legend .legend-expanded-body {
        display: none !important;
        width: 100%;
        max-width: 100%;
        max-height: 60vh;
        border-radius: var(--radius-md) var(--radius-md) 0 0;
    }
    .legend.legend--mobile-open .legend-expanded-body {
        display: flex !important;
    }
}

/* ---- Boundaries popover (radio-style lens picker) ------------- */
/* Smaller than the layers panel — a boundaries popover is a
   short list of radio rows, not a groupable legend. Anchored
   against the map container same as the layers panel so it
   tracks the visible map edge when the sidebar opens. */
#boundaries-popover {
    position: absolute;
    top: 70px;
    right: var(--rail-gutter);
    width: 300px;
    max-height: calc(100vh - 90px);
    background: var(--color-bg-elevated);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    z-index: var(--z-panel);
    display: none;
    overflow: hidden;
    flex-direction: column;
    transition: right var(--motion-base) ease;
}
#boundaries-popover[style*="display: block"] {
    display: flex !important;
}
/* CONTROL surface — shifts left when the selection sidebar
   is open. See layout-principles block at the top of file. */
body.sidebar-visible #boundaries-popover {
    right: calc(var(--sidebar-width, 300px) + var(--rail-gutter));
}

.boundaries-popover-header {
    padding: var(--space-3) var(--space-4) 10px;
    border-bottom: 1px solid var(--color-border);
    flex-shrink: 0;
}
.boundaries-popover-header h3 {
    margin: 0 0 2px 0;
    font-size: 16px;
    font-weight: 600;
}
.boundaries-popover-hint {
    font-size: 11.5px;
    color: var(--color-fg-muted);
    line-height: 1.3;
}

.boundaries-popover-content {
    padding: var(--space-2) 0;
    overflow-y: auto;
    flex: 1 1 auto;
}

.boundaries-options {
    padding: 0 var(--space-2);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Row: swatch | label-group | radio. Whole row is a <label>
   so clicking the text also selects the radio. Disabled rows
   don't react to hover and show "coming soon" next to their
   label. */
.boundary-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: var(--space-2);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--motion-fast);
}
.boundary-row:hover {
    background-color: var(--color-bg-hover);
}
.boundary-row input[type="radio"] {
    margin: 0;
    flex-shrink: 0;
    cursor: pointer;
}
.boundary-row--active {
    background-color: #e7f5ff;
}
.boundary-row--active:hover {
    background-color: #d0ebff;
}
.boundary-row--disabled {
    cursor: not-allowed;
    opacity: 0.5;
}
.boundary-row--disabled:hover {
    background-color: transparent;
}
.boundary-row--disabled input[type="radio"] {
    cursor: not-allowed;
}

.boundary-label-group {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.boundary-label {
    font-size: 13.5px;
    font-weight: 500;
    color: var(--color-fg-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}
.boundary-description {
    font-size: 11.5px;
    color: var(--color-fg-muted);
    line-height: 1.3;
}
.boundary-coming-soon {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #868e96;
    background: #f1f3f5;
    padding: 2px 6px;
    border-radius: 10px;
}

/* Boundary swatches are always fill-style squares — boundaries
   are polygon regions, no need for line/dot variants. */
.boundary-swatch {
    flex-shrink: 0;
    width: 14px;
    height: 14px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
}

.boundaries-empty {
    padding: var(--space-5) var(--space-4);
    color: var(--color-fg-muted);
    font-size: 13px;
    text-align: center;
}

/* ---- New selection panel (chip row + body + close) ------------ */
/* --sidebar-width lives in the tokens block at the top of this
   stylesheet. */

#panel-close {
    background: #e9ecef;
    color: #495057;
}
#panel-close:hover { background: #dee2e6; color: #212529; }

#panel-chip-row:empty { display: none; }

/* Chip row */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    height: 26px;
    border-radius: 13px;
    font-size: 12.5px;
    font-weight: 500;
    line-height: 1;
    border: 1px solid transparent;
    background: #f1f3f5;
    color: #495057;
    cursor: default;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
    max-width: 100%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.chip--current {
    background: #0080ff;
    color: #fff;
    border-color: #0080ff;
    cursor: default;
    font-weight: 600;
}
.chip--current[disabled] { opacity: 1; }
.chip--neighborhood { background: #e7f5ff; color: #1971c2; border-color: #c5e0fa; }
.chip--ward         { background: #fff4e6; color: #d9480f; border-color: #ffd8a8; }
.chip--council      { background: #f3f0ff; color: #5f3dc4; border-color: #d0bfff; }
/* Census tract — palette matches the lens fill in census-boundaries.js (#1c7ed6) */
.chip--tract        { background: #e7f5ff; color: #1c7ed6; border-color: #a5d8ff; }
.chip--block        { background: #f4fce3; color: #5c940d; border-color: #d8f5a2; }
/* Phase-5b breadcrumb chips */
.chip--block_group  { background: #f4fce3; color: #5c940d; border-color: #d8f5a2; }
/* DFD battalion (red) and CVI area (green) — match the lens fills
   in administrative-boundaries.js so chip color = polygon color. */
.chip--dfd_battalion { background: #ffe3e3; color: #c92a2a; border-color: #ffc9c9; }
.chip--cvi_area      { background: #ebfbee; color: #2f9e44; border-color: #b2f2bb; }
.chip--nez_district  { background: #fff4e6; color: #e67700; border-color: #ffd8a8; }
/* Zoning chip — neutral tan to match the styled-fill layer's
   default residential-yellow palette. */
.chip--zoning       { background: #f8f9fa; color: #5c4a30; border-color: #ced4da; }
.chip--clickable { cursor: pointer; }
.chip--clickable:hover {
    background: #0080ff;
    color: #fff;
    border-color: #0080ff;
}
.chip--info { cursor: default; opacity: 0.95; }

/* Selection heading + sections in panel body */
.selection-heading {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 14px;
}
.selection-heading-text { flex: 1; min-width: 0; }
.selection-heading-text h3 {
    margin: 0 0 4px 0;
    font-size: 17px;
    font-weight: 600;
}
.parcel-address {
    font-size: 13px;
    color: #555;
    line-height: 1.35;
}
/* Caption row under the H1 in selection headings — holds the
   parcel id (when the address is the title) and the zoning tag
   inline. Light, low-contrast typography so it reads as
   secondary metadata rather than competing with the title. */
.parcel-caption {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 2px;
    font-size: 12px;
    color: #6c757d;
    line-height: 1.4;
}
.parcel-caption-sep {
    color: #adb5bd;
}
/* Zoning tag — inline in the caption row, next to the parcel
   id. Margin-left removed since the caption row uses gap. */
.parcel-zoning-tag {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    color: #3e2723;
    background: #efebe9;
    border: 1px solid #d7ccc8;
    border-radius: 10px;
    vertical-align: middle;
    white-space: nowrap;
}
.selection-section {
    margin-top: 16px;
}
.selection-section h4 {
    margin: 0 0 8px 0;
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: #6c757d;
}

/* ---- Panel group headers ---------------------------------------- */
/* Groups wrap related enrichment sections (Affordable Housing, Sales
   History, Compliance & Enforcement, Fire & Safety) under a slim
   label that reads as a structural divider, not a navigation element.
   The label sits above the first section's own h4, so both levels
   of hierarchy are visible simultaneously when collapsed. */
.panel-group {
    margin-bottom: 24px;
}
.panel-group-header {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-fg-muted, #6c757d);
    padding-bottom: 6px;
    margin-bottom: 12px;
    border-bottom: 2px solid var(--color-border, #e0e0e0);
}
body.theme-dark .panel-group-header {
    border-bottom-color: #333;
    color: #9aa0a6;
}

/* ---- Scorecard row ---------------------------------------------- */
/* Compact chip strip between the share button and Parcel Data.
   Each chip is a key-fact pill — SEV, year built, open violations,
   HUD / FIE flags, tax status. Wraps gracefully on narrow panels. */
.scorecard-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 10px 0 14px;
}
.scorecard-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-radius: 4px;
    padding: 3px 7px;
    font-size: 11px;
    font-weight: 500;
    line-height: 1.4;
    white-space: nowrap;
}
.scorecard-label {
    opacity: 0.7;
    font-weight: 600;
}
.scorecard-chip--neutral {
    background: #f5f5f5;
    color: #424242;
}
.scorecard-chip--warning {
    background: #fff3e0;
    color: #e65100;
}
.scorecard-chip--alert {
    background: #fce8e8;
    color: #c62828;
}
.scorecard-chip--info {
    background: #e8f0fe;
    color: #1a73e8;
}
.scorecard-chip--hud {
    background: #ede7f6;
    color: #5e35b1;
}
.scorecard-chip--fie {
    background: #efebe9;
    color: #4e342e;
}
body.theme-dark .scorecard-chip--neutral {
    background: #2a2a2a;
    color: #e0e0e0;
}
body.theme-dark .scorecard-chip--warning {
    background: #3e2700;
    color: #ffb74d;
}
body.theme-dark .scorecard-chip--alert {
    background: #3e0000;
    color: #ef9a9a;
}
body.theme-dark .scorecard-chip--info {
    background: #0d2240;
    color: #82b1ff;
}
body.theme-dark .scorecard-chip--hud {
    background: #1e1040;
    color: #b39ddb;
}
body.theme-dark .scorecard-chip--fie {
    background: #1e1410;
    color: #bcaaa4;
}

/* ---- Debug / Map Properties <details> --------------------------- */
/* Collapsed by default; power-users can expand. Visually separated
   from the main content with a dashed border so it reads as
   "not for regular users". */
.debug-section {
    margin-top: 16px;
    border: 1px dashed var(--color-border, #e0e0e0);
    border-radius: 4px;
}
.debug-section > summary {
    padding: 6px 10px;
    font-size: 11px;
    color: var(--color-fg-muted, #6c757d);
    cursor: pointer;
    list-style: none;
    user-select: none;
}
.debug-section > summary::-webkit-details-marker {
    display: none;
}
.debug-section > summary::before {
    content: '▶ ';
    font-size: 9px;
}
.debug-section[open] > summary::before {
    content: '▼ ';
}
.debug-section > *:not(summary) {
    padding: 0 10px 10px;
}
body.theme-dark .debug-section {
    border-color: #333;
}

/* ---- Source attribution footer ---------------------------------- */
.section-source {
    font-size: 11px;
    color: var(--color-fg-muted, #6c757d);
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--color-border, #e0e0e0);
}
.section-source a {
    color: inherit;
    text-decoration: underline;
}
body.theme-dark .section-source {
    border-top-color: #333;
}

/* ⓘ icon on parcel data section headers — links to pipelines glossary */
.section-info-link {
    margin-left: auto;
    display: flex;
    align-items: center;
    color: var(--color-fg-muted, #6c757d);
    text-decoration: none;
    opacity: 0.5;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.section-info-link:hover {
    opacity: 1;
}

.ambient-banner {
    font-size: 12px;
    margin-bottom: 12px;
}

/* ---- Floating Mapillary viewer (picture-in-picture) ----------- */
/* Pinned bottom-right of the map. No drag, no resize — the frame
   is entirely CSS-positioned so it can never drift out of sync
   with the map underneath (the map-PiP chrome had that problem
   when drag was allowed). "Minimize" collapses it back into the
   pegman; "Swap" flips primary vs. floating frames. */
#mapillary-container.floating-viewer {
    position: absolute;
    left: auto;
    /* SV is a CONTEXT surface — it yields to the selection
       sidebar (when visible) and to whatever CONTROL panel
       the user has open. See the layout-principles block at
       the top of this stylesheet. Both offsets are 0 when
       nothing is open, so the default collapses to 20px. */
    right: calc(var(--control-panel-offset, 0px) + 20px);
    bottom: 20px;
    top: auto;
    width: min(480px, 34vw);
    height: min(320px, 36vh);
    min-width: 280px;
    min-height: 180px;
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border-strong);
    border-radius: 6px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    z-index: var(--z-floating);
    display: none;
    transition: right var(--motion-base) ease;
}
/* When sidebar is visible, slide the viewer clear of its edge. */
body.sidebar-visible #mapillary-container.floating-viewer {
    right: calc(var(--sidebar-width, 300px) + var(--control-panel-offset, 0px) + 20px);
}

.floating-viewer-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 32px;
    background: var(--color-bg-muted);
    border-bottom: 1px solid var(--color-border-strong);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-2) 0 var(--space-3);
    z-index: 5;
}
.floating-viewer-title-group {
    display: flex;
    align-items: baseline;
    gap: var(--space-2);
    min-width: 0;
    overflow: hidden;
}
.floating-viewer-title {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--color-fg-secondary);
    letter-spacing: 0.02em;
    white-space: nowrap;
    /* Title shrinks/ellipsizes before the pill row does — the
       pills carry information, the title is branding. */
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    flex-shrink: 1;
}
/* Time pill — single button in the chrome header. Label shows
   the currently-viewed image's month+year; click opens the
   archive drill-down (.time-menu) below it. Separator "•"
   from the title rendered via ::before, matching the prior
   subtitle look so the chrome visually reads the same. */
.time-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    line-height: 1;
    padding: 3px 8px;
    border-radius: 10px;
    border: 1px solid #c5e0fa;
    background: #e7f5ff;
    color: #1971c2;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background-color 0.12s, color 0.12s, border-color 0.12s;
    font-family: inherit;
}
.time-pill::before {
    content: '•';
    margin-right: 4px;
    color: #ced4da;
    font-weight: 400;
}
.time-pill:hover:not(:disabled) {
    background: #d0ebff;
    border-color: #9ac8ec;
}
.time-pill--open,
.time-pill--open:hover:not(:disabled) {
    background: #1971c2;
    color: #fff;
    border-color: #1971c2;
}
.time-pill--open::before {
    color: rgba(255, 255, 255, 0.5);
}
.time-pill:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    background: #f1f3f5;
    color: #868e96;
    border-color: #dee2e6;
}
.time-pill-chevron {
    flex-shrink: 0;
    transition: transform 0.12s;
}
.time-pill--open .time-pill-chevron {
    transform: rotate(180deg);
}
/* Time menu — drill-down popover anchored beneath the pill. */
.time-menu {
    position: absolute;
    z-index: 1000;
    min-width: 180px;
    max-width: 260px;
    max-height: 320px;
    overflow-y: auto;
    background: #ffffff;
    border: 1px solid #dee2e6;
    border-radius: 8px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.14);
    padding: 4px;
    font-size: 12px;
    color: #343a40;
}
.time-menu-year-wrap,
.time-menu-month-wrap {
    display: block;
}
.time-menu-row {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 6px 8px;
    background: transparent;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
    color: inherit;
    text-align: left;
    line-height: 1.25;
}
.time-menu-row:hover {
    background: #f1f3f5;
}
.time-menu-row--active {
    background: #e7f5ff;
    color: #1971c2;
    font-weight: 600;
}
.time-menu-row--active:hover {
    background: #d0ebff;
}
.time-menu-row--year { font-weight: 600; }
.time-menu-row--month { padding-left: 20px; }
.time-menu-row--day { padding-left: 36px; color: #6c757d; }
.time-menu-row--day.time-menu-row--active { color: #1971c2; }
.time-menu-caret {
    flex-shrink: 0;
    transition: transform 0.12s;
    color: #868e96;
}
.time-menu-row--expanded .time-menu-caret {
    transform: rotate(90deg);
}
.time-menu-label {
    flex: 1 1 auto;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.time-menu-count {
    flex-shrink: 0;
    color: #868e96;
    font-variant-numeric: tabular-nums;
    font-size: 11px;
    font-weight: 500;
}
.time-menu-row--active .time-menu-count {
    color: #1971c2;
}
.time-menu-children {
    display: block;
}
.time-menu-children--day {
    display: none;
}
.time-menu-month-wrap--expanded > .time-menu-children--day {
    display: block;
}
.floating-viewer-chrome-buttons {
    display: flex;
    gap: var(--space-1);
    flex-shrink: 0;
}
.floating-viewer-minimize-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    width: 26px;
    height: 26px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-fg-secondary);
    transition: background-color var(--motion-fast);
    padding: 0;
}
.floating-viewer-minimize-btn:hover {
    background: var(--color-bg-hover);
}

/* Push the Mapillary canvas below the chrome header */
#mapillary-container.floating-viewer #mapillary-viewer {
    position: absolute;
    top: 32px;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: calc(100% - 32px);
}
#mapillary-container.floating-viewer #mapillary-spinner {
    top: calc(50% + 16px);
}

/* Detail row improvements */
.detail-row {
    padding: 8px 0;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
}

.detail-row strong {
    font-weight: 600;
}

/* Search results dropdown (dynamically created, appended to body) */
#search-results-dropdown {
    position: fixed;
    z-index: 9999;
    background-color: #fff;
    border: 2px solid #0080ff;
    border-radius: 4px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    max-height: 300px;
    overflow-y: auto;
    display: none;
    width: 400px;
}
body.theme-dark #search-results-dropdown {
    background-color: #1e1e1e;
    border-color: #0099ff;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.5);
    color: #eee;
}
body.theme-dark #search-results-dropdown .search-result {
    border-bottom-color: #333;
    color: #eee;
}
body.theme-dark #search-results-dropdown .search-result:hover {
    background-color: #2a2a2a;
}

/* Geocode marker pin */
.geocode-marker {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background-color: #0080ff;
    border: 2px solid #fff;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}
body.theme-dark .geocode-marker {
    background-color: #0099ff;
    border-color: #1e1e1e;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.6);
}

/* Share button (sidebar copy-link) */
.share-button {
    background-color: #0080ff;
    color: #fff;
    border: none;
    border-radius: 4px;
    padding: 8px 12px;
    margin-top: 8px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.share-button:hover {
    background-color: #0066cc;
}
body.theme-dark .share-button {
    background-color: #1a6fd1;
}
body.theme-dark .share-button:hover {
    background-color: #2a80e0;
}

/* Detail-row status variants (light mode) */
.detail-row.detail-info {
    background: #e8f4ff;
    padding: 8px;
    margin-bottom: 16px;
}
.detail-row.detail-warning {
    background: #fff3e0;
    padding: 8px;
    margin-bottom: 16px;
}
.detail-row.detail-error {
    background: #ffebee;
    padding: 8px;
}

/* Tooltip styles */
.tooltip {
    position: relative;
    display: inline-block;
}

.tooltip .tooltip-text {
    visibility: hidden;
    width: 120px;
    background-color: rgba(0, 0, 0, 0.8);
    color: #fff;
    text-align: center;
    border-radius: 4px;
    padding: 5px;
    position: absolute;
    z-index: 1002;
    bottom: 125%;
    left: 50%;
    transform: translateX(-50%);
    opacity: 0;
    transition: opacity 0.2s;
    font-size: 12px;
    pointer-events: none;
}

.tooltip .tooltip-text::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: rgba(0, 0, 0, 0.8) transparent transparent transparent;
}

.tooltip:hover .tooltip-text {
    visibility: visible;
    opacity: 1;
}

/* Focus styles for accessibility */
button:focus, input:focus, select:focus, a:focus {
    outline: 2px solid #0080ff;
    outline-offset: 2px;
}

/* Loading indicator improvements */
#loading {
    background-color: rgba(255, 255, 255, 0.9);
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    padding: 20px 30px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
}

#loading::before {
    content: '';
    width: 20px;
    height: 20px;
    margin-right: 10px;
    border: 2px solid #0080ff;
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Hide debug panel toggle button and zoom level display by default */
#debug-toggle-btn, #zoom-level-display {
    display: none !important;
}

/* Responsive improvements */
@media (max-width: 768px) {
    #floating-header {
        padding: 0 12px;
    }
    
    #search-container {
        max-width: 60%;
        margin: 0 10px;
    }
    
    .header-button span {
        display: none;
    }
    
    .header-button svg {
        margin-right: 0;
    }

    /* Layers panel becomes a full-width sheet on mobile,
       matching the filter panel's typical mobile treatment. */
    #layers-panel {
        top: auto !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        max-height: 60vh !important;
        border-radius: 8px 8px 0 0;
    }

    /* Boundaries popover: same full-width sheet treatment. */
    #boundaries-popover {
        top: auto !important;
        bottom: 0 !important;
        right: 0 !important;
        left: 0 !important;
        width: 100% !important;
        max-height: 60vh !important;
        border-radius: 8px 8px 0 0;
    }
}

/* Dark mode enhancements */
body.theme-dark {
    color: #eee;
    background-color: #121212;
}

body.theme-dark #floating-header {
    background-color: #1e1e1e;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

body.theme-dark #home-button {
    color: #0099ff;
}

body.theme-dark #search-input {
    background-color: #333;
    border-color: #444;
    color: #eee;
}

body.theme-dark #search-input:focus {
    border-color: #0099ff;
}

/* The geocoder close button (×) and the collapsed-state
   magnifying-glass button use hardcoded light palette colors in
   index.html. In dark mode the near-white background collides
   with the dark header — override with dark-palette surfaces so
   they blend with the rest of the header chrome. */
body.theme-dark .search-close-button {
    background-color: #333;
    border-color: #444;
    color: #bbb;
}
body.theme-dark .search-close-button:hover {
    background-color: #404040;
    color: #eee;
}
body.theme-dark .search-icon-button {
    background-color: #333;
    border-color: #444;
    color: #bbb;
}
body.theme-dark .search-icon-button:hover {
    background-color: #404040;
    border-color: #0099ff;
    color: #0099ff;
}

body.theme-dark .header-button:hover {
    background-color: rgba(0, 153, 255, 0.2);
}

body.theme-dark .header-button.active {
    background-color: rgba(0, 153, 255, 0.25);
    color: #0099ff;
}

/* #details-sidebar hasn't been token-swept yet — its base
   background comes from inline style or legacy CSS, so we
   still need an explicit override here. #filter-panel was
   removed from this rule because its base now uses
   var(--color-bg-elevated) which auto-flips. Shadow override
   for the filter panel lives in enhanced-filter-panel.js. */
body.theme-dark #details-sidebar {
    background-color: #1e1e1e;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

body.theme-dark .filter-header {
    border-bottom-color: #333;
}

body.theme-dark .filter-section-title {
    color: #eee;
}

body.theme-dark .filter-close,
body.theme-dark .filter-reset {
    background-color: #333;
    color: #eee;
}

body.theme-dark .filter-close:hover,
body.theme-dark .filter-reset:hover {
    background-color: #444;
}

/* ---- Dark mode: layers panel ---------------------------------
   Most panel-chrome overrides are gone — the base rules use
   semantic tokens (--color-bg-elevated, --color-border,
   --color-fg-muted, --color-bg-hover) which flip automatically
   under body.theme-dark via the tokens block at the top.

   What stays: (a) shadow needs more opacity on dark bg to be
   visible; (b) swatch border inverts from black to white
   because a dark border is invisible against a dark card. */
body.theme-dark #layers-panel {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
body.theme-dark .layer-swatch {
    border-color: rgba(255, 255, 255, 0.18);
}

/* ---- Dark mode: Legend ---------------------------------------
   Semantic tokens carry most of the weight; only the swatch
   border + card shadow need explicit dark-mode values. */
body.theme-dark .legend .legend-expanded-body {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}
body.theme-dark .legend .legend-collapsed-button {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}
body.theme-dark .legend-swatch {
    border-color: rgba(255, 255, 255, 0.18);
}

/* ---- Dark mode: boundaries popover ---------------------------
   Same story as the layers panel — base uses semantic tokens
   that auto-flip. Only real overrides below are: (a) darker
   shadow; (b) white-tinted swatch border; (c) the blue
   selected-row tint (domain accent, not a semantic token);
   (d) the "coming soon" chip which has its own theme. */
body.theme-dark #boundaries-popover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
body.theme-dark .boundary-row--active {
    background-color: rgba(0, 153, 255, 0.18);
}
body.theme-dark .boundary-row--active:hover {
    background-color: rgba(0, 153, 255, 0.25);
}
body.theme-dark .boundary-row--disabled:hover {
    background-color: transparent;
}
body.theme-dark .boundary-coming-soon {
    color: #9aa0a6;
    background: #2a2a2a;
}
body.theme-dark .boundary-swatch {
    border-color: rgba(255, 255, 255, 0.18);
}

/* ---- Dark mode: selection panel chips + thumb + floating viewer -- */
body.theme-dark #panel-chip-row { border-bottom-color: #333; }
body.theme-dark #panel-close {
    background: #333;
    color: #ddd;
}
body.theme-dark #panel-close:hover { background: #444; color: #fff; }

body.theme-dark .chip {
    background: #2a2a2a;
    color: #ccc;
    border-color: #333;
}
body.theme-dark .chip--current {
    background: #0099ff;
    color: #0a0a0a;
    border-color: #0099ff;
}
body.theme-dark .chip--neighborhood { background: #0d2d4a; color: #9ac8ec; border-color: #1a3e60; }
body.theme-dark .chip--ward         { background: #3a2410; color: #ffb380; border-color: #4a3220; }
body.theme-dark .chip--council      { background: #27204a; color: #c0adff; border-color: #3a305e; }
body.theme-dark .chip--tract        { background: #3a1428; color: #ffa8c2; border-color: #4a2036; }
body.theme-dark .chip--block        { background: #1f2d10; color: #c5e58f; border-color: #2e3d20; }
body.theme-dark .chip--clickable:hover {
    background: #0099ff;
    color: #0a0a0a;
    border-color: #0099ff;
}

body.theme-dark .parcel-address { color: #bbb; }
body.theme-dark .parcel-caption { color: #9aa0a6; }
body.theme-dark .parcel-caption-sep { color: #6c757d; }
body.theme-dark .selection-section h4 { color: #9aa0a6; }
body.theme-dark .parcel-zoning-tag {
    color: #d7ccc8;
    background: #3e2723;
    border-color: #5d4037;
}

body.theme-dark #mapillary-container.floating-viewer {
    background: #1e1e1e;
    border-color: #333;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
body.theme-dark .floating-viewer-header {
    background: #252525;
    border-bottom-color: #333;
}
body.theme-dark .floating-viewer-title { color: #ddd; }
body.theme-dark .time-pill {
    background: #0d2d4a;
    color: #9ac8ec;
    border-color: #1a3e60;
}
body.theme-dark .time-pill::before { color: #4a4a4a; }
body.theme-dark .time-pill:hover:not(:disabled) {
    background: #14416b;
    border-color: #2a5682;
}
body.theme-dark .time-pill--open,
body.theme-dark .time-pill--open:hover:not(:disabled) {
    background: #9ac8ec;
    color: #0a0a0a;
    border-color: #9ac8ec;
}
body.theme-dark .time-pill:disabled {
    background: #252525;
    color: #5a5a5a;
    border-color: #333;
}
body.theme-dark .time-menu {
    background: #1e1e1e;
    border-color: #333;
    color: #ddd;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.55);
}
body.theme-dark .time-menu-row:hover { background: #2a2a2a; }
body.theme-dark .time-menu-row--active {
    background: #0d2d4a;
    color: #9ac8ec;
}
body.theme-dark .time-menu-row--active:hover { background: #14416b; }
body.theme-dark .time-menu-row--day { color: #adb5bd; }
body.theme-dark .time-menu-row--day.time-menu-row--active { color: #9ac8ec; }
body.theme-dark .time-menu-count { color: #868e96; }
body.theme-dark .time-menu-row--active .time-menu-count { color: #9ac8ec; }
body.theme-dark .floating-viewer-minimize-btn { color: #ddd; }
body.theme-dark .floating-viewer-minimize-btn:hover { background: #333; }

body.theme-dark .detail-row {
    border-bottom-color: #333;
}

body.theme-dark .detail-row.detail-info {
    background: #14304a;
    color: #cfe6ff;
}
body.theme-dark .detail-row.detail-warning {
    background: #3a2a10;
    color: #ffe0b2;
}
body.theme-dark .detail-row.detail-error {
    background: #3a1414;
    color: #ffcdd2;
}

body.theme-dark #loading {
    background-color: rgba(30, 30, 30, 0.9);
    color: #eee;
}

/* Sidebar layout + transitions (moved from sidebar.js) */
#details-sidebar {
    transition: width 0.3s, right 0.3s;
    overflow-y: auto;
}
@media (max-width: 768px) {
    #details-sidebar {
        width: 100% !important;
        height: 25% !important;
        top: 75% !important;
        right: 0 !important;
        bottom: 0 !important;
        box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.1) !important;
    }
    /* Floating viewer collapses on mobile (floating-viewer.js hides it anyway). */
    #mapillary-container.floating-viewer {
        display: none !important;
    }
    /* Pegman on mobile: smaller, anchored to the bottom-right
       corner. When the sidebar (a 25%-height bottom sheet on
       mobile) is open, push him UP to sit above it instead of
       LEFT like on desktop. The old rule hardcoded
       bottom:30% unconditionally, which untethered pegman from
       the corner even when no selection was active. */
    .pegman-button {
        width: 44px;
        height: 44px;
        right: 12px !important;
        bottom: 20px !important;
    }
    /* Override the desktop right-shift with an up-shift on mobile:
       sidebar bottom sheet is 25% tall + 20px margin. */
    .pegman-button--sidebar-open {
        right: 12px !important;
        bottom: calc(25% + 20px) !important;
    }
}
body.theme-dark .sidebar-toggle {
    background-color: #333;
    color: #eee;
}

/* Debug panel (debug-panel.js renders into #debug) */
#debug {
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
}
.debug-title {
    margin-top: 0;
    margin-bottom: 10px;
    color: #333;
}
.debug-clear-button {
    position: absolute;
    top: 10px;
    right: 10px;
    padding: 3px 8px;
    font-size: 12px;
    background-color: #f5f5f5;
    border: 1px solid #ddd;
    border-radius: 3px;
    cursor: pointer;
    color: #333;
}
.debug-message {
    padding: 8px;
    margin: 8px 0;
}
.debug-message--success { background: #e8f5e9; }
.debug-message--warning { background: #fff9c4; }
.debug-message--error   { background: #ffebee; }
.debug-message--info    { background: #e3f2fd; }
.debug-timestamp {
    color: #666;
    font-size: 0.8em;
}

body.theme-dark #debug {
    background-color: #1e1e1e;
    color: #eee;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
}
body.theme-dark .debug-title { color: #eee; }
body.theme-dark .debug-clear-button {
    background-color: #333;
    border-color: #444;
    color: #eee;
}
body.theme-dark .debug-message--success { background: #14301a; color: #c8e6c9; }
body.theme-dark .debug-message--warning { background: #3a2e10; color: #fff9c4; }
body.theme-dark .debug-message--error   { background: #3a1414; color: #ffcdd2; }
body.theme-dark .debug-message--info    { background: #14304a; color: #cfe6ff; }
body.theme-dark .debug-timestamp { color: #9aa0a6; }

/* Stat cards (chart-utils.js) */
.stat-card {
    background-color: #f8f9fa;
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
}
.stat-card-icon {
    margin-right: 16px;
    color: #0080ff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.stat-card-content { flex: 1; }
.stat-card-title {
    font-size: 14px;
    color: #6c757d;
    margin-bottom: 4px;
}
.stat-card-value {
    font-size: 24px;
    font-weight: bold;
    color: #212529;
    margin-bottom: 4px;
}
.stat-card-value--no-subtitle { margin-bottom: 0; }
.stat-card-subtitle {
    font-size: 12px;
    color: #6c757d;
}
body.theme-dark .stat-card {
    background-color: #2a2a2a;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
}
body.theme-dark .stat-card-icon { color: #0099ff; }
body.theme-dark .stat-card-title,
body.theme-dark .stat-card-subtitle { color: #9aa0a6; }
body.theme-dark .stat-card-value { color: #eee; }

/* ── Boundary Stats Panel (.bstats-*) ──────────────────────────── */

.bstats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    margin-bottom: 12px;
}
.bstats-grid--2 {
    grid-template-columns: repeat(2, 1fr);
}
.bstats-grid--3 {
    grid-template-columns: repeat(3, 1fr);
}
.bstats-tile {
    background: #f1f3f5;
    border-radius: 6px;
    padding: 8px 6px;
    text-align: center;
}
button.bstats-tile--action {
    border: 1.5px solid transparent;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}
button.bstats-tile--action:hover {
    border-color: #0080ff;
    background: #e8f0fe;
}
button.bstats-tile--active {
    background: rgba(0, 128, 255, 0.12);
    border-color: #0080ff;
}
button.bstats-tile--active .bstats-tile-value,
button.bstats-tile--active .bstats-tile-label {
    color: #0060cc;
}
.bstats-tile-value {
    font-size: 15px;
    font-weight: 700;
    color: #212529;
    line-height: 1.2;
}
.bstats-tile-label {
    font-size: 10px;
    color: #6c757d;
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    line-height: 1.3;
}
.bstats-heading {
    margin: 14px 0 6px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #6c757d;
}
/* Period qualifier appended to time-aware headings
   ("Permits · last 12 months"). Rendered in a muted, looser
   weight so it reads as context, not a separate header. */
.bstats-period-label {
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
    font-size: 10.5px;
    opacity: 0.85;
}

/* Date-range picker at the top of the boundary stats panel.
   Mirrors the master picker in the filter panel but compact so
   it doesn't dominate the layout. */
.bstats-period-picker {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 12px;
    padding: 8px 10px;
    background: rgba(37, 99, 235, 0.06);
    border: 1px solid rgba(37, 99, 235, 0.18);
    border-radius: 6px;
}
.bstats-period-picker-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #4b5563;
    flex: 0 0 auto;
}
.bstats-period-select {
    flex: 1 1 auto;
    padding: 5px 8px;
    font-size: 12.5px;
    font-family: inherit;
    color: #1f2937;
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    cursor: pointer;
}
.bstats-period-select:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.22);
}

/* Segmented horizontal bar (PRE/homestead) */
.bstats-segbar {
    display: flex;
    height: 10px;
    border-radius: 5px;
    overflow: hidden;
    background: #dee2e6;
    margin-bottom: 5px;
}
.bstats-segbar-fill { height: 100%; transition: width 0.3s; }
.bstats-segbar--pre100  { background: #2f9e44; }
.bstats-segbar--preparti { background: #f59f00; }
.bstats-segbar--pre0    { background: #e03131; }
/* Race & ethnicity segments (Census tract panel). Palette chosen for
   accessibility — distinct hues, similar luminance — and to align
   loosely with Detroit's largest race groups appearing leftmost. */
.bstats-segbar--race-black { background: #1864ab; }
.bstats-segbar--race-white { background: #f59f00; }
.bstats-segbar--race-asian { background: #2f9e44; }
.bstats-segbar--race-other { background: #868e96; }
/* Tract panel "source: …" footer — small, low-contrast, no border. */
.bstats-source-note {
    font-size: 10px;
    color: #868e96;
    margin: 4px 0 8px 0;
    font-style: italic;
}

/* HUD point click popup — used by hud-points-layer.js for both
   LIHTC + Public Housing. Tight card with a colored left border
   that matches the layer's dot color (passed in inline style). */
.hud-popup { font-size: 12px; min-width: 220px; }
.hud-popup-title {
    padding: 4px 8px;
    font-weight: 600;
    font-size: 12px;
    color: #495057;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 6px;
}
.hud-popup-body { display: grid; gap: 4px; padding: 0 4px 4px; }
.hud-popup-row {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 12px;
}
.hud-popup-label { color: #6c757d; }
.hud-popup-value { color: #212529; font-weight: 500; text-align: right; }

/* 5-column grid variant — used by Fair Market Rents (one tile
   per bedroom bucket: studio, 1BR, 2BR, 3BR, 4BR). */
.bstats-grid--5 {
    grid-template-columns: repeat(5, minmax(0, 1fr)) !important;
    gap: 4px;
}

/* Tile range — small min-max line under the main value, used by
   the Phase-4d "FMR by ZIP" card to show intra-boundary variation
   below the parcel-weighted mean. */
.bstats-tile-range {
    font-size: 10px;
    color: #6c757d;
    margin-top: 2px;
    white-space: nowrap;
}

/* Zoning click popup (Phase 5a) — code + category description. */
.zoning-popup { padding: 4px 6px; min-width: 160px; }
.zoning-popup-code {
    font-size: 14px;
    font-weight: 600;
    color: #212529;
    letter-spacing: 0.04em;
}
.zoning-popup-desc {
    font-size: 12px;
    color: #495057;
    margin-top: 2px;
}

/* Income Limits comparison table — 3 tiers × N household sizes. */
.bstats-il-table-wrap { overflow-x: auto; }
.bstats-il-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.bstats-il-table th,
.bstats-il-table td {
    padding: 4px 6px;
    text-align: right;
    border-bottom: 1px solid #f1f3f5;
}
.bstats-il-table thead th {
    font-weight: 600;
    color: #6c757d;
    border-bottom: 1px solid #dee2e6;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.bstats-il-table tbody th {
    text-align: left;
    font-weight: 500;
    color: #495057;
    white-space: nowrap;
}
.bstats-segbar-legend {
    font-size: 10px;
    color: #6c757d;
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
}
.bstats-legend-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    margin-right: 3px;
}

/* Year-built chart wrapper */
.bstats-chart-wrap {
    position: relative;
    height: 160px;
    margin-bottom: 12px;
}

/* Ranked rows (owners, classes, tax) */
.bstats-rank-list {
    margin-bottom: 8px;
}
.bstats-rank-row {
    margin-bottom: 5px;
}
.bstats-rank-meta {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 2px;
}
.bstats-rank-label {
    font-size: 11px;
    color: #343a40;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.bstats-rank-count {
    font-size: 11px;
    font-weight: 600;
    color: #495057;
    white-space: nowrap;
}
.bstats-rank-pct {
    font-weight: 400;
    color: #868e96;
}
.bstats-rank-track {
    height: 4px;
    background: #e9ecef;
    border-radius: 2px;
    overflow: hidden;
}
.bstats-rank-bar {
    height: 100%;
    background: #339af0;
    border-radius: 2px;
    transition: width 0.3s;
}
.bstats-rank-bar--tax { background: #f76707; }

/* Dark-mode overrides */
body.theme-dark .bstats-tile {
    background: #2a2f36;
}
body.theme-dark button.bstats-tile--action:hover {
    background: #1e3a5f;
    border-color: #4da3ff;
}
body.theme-dark button.bstats-tile--active {
    background: rgba(0, 128, 255, 0.2);
    border-color: #4da3ff;
}
body.theme-dark button.bstats-tile--active .bstats-tile-value,
body.theme-dark button.bstats-tile--active .bstats-tile-label {
    color: #4da3ff;
}
body.theme-dark .bstats-tile-value { color: #e9ecef; }
body.theme-dark .bstats-tile-label { color: #9aa0a6; }
body.theme-dark .bstats-heading    { color: #9aa0a6; }
body.theme-dark .bstats-segbar     { background: #373d44; }
body.theme-dark .bstats-rank-label { color: #ced4da; }
body.theme-dark .bstats-rank-count { color: #adb5bd; }
body.theme-dark .bstats-rank-track { background: #373d44; }
body.theme-dark .bstats-period-picker {
    background: rgba(77, 163, 255, 0.10);
    border-color: rgba(77, 163, 255, 0.32);
}
body.theme-dark .bstats-period-picker-label { color: #adb5bd; }
body.theme-dark .bstats-period-select {
    background: #2a2f36;
    border-color: #495057;
    color: #e9ecef;
}
body.theme-dark .bstats-period-select:focus {
    border-color: #4da3ff;
    box-shadow: 0 0 0 2px rgba(77, 163, 255, 0.28);
}

/* ---- Pegman control (persistent street-view entry) ------------- */
.pegman-button {
    position: absolute;
    right: 20px;
    bottom: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #fff;
    border: 1px solid #dadce0;
    color: #5f6368;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 940;
    transition: right 0.25s ease, background-color 0.15s, box-shadow 0.15s, color 0.15s;
}
.pegman-button:hover {
    background: #f8f9fa;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.25);
    color: #202124;
}
.pegman-button.active {
    background: #0080ff;
    color: #fff;
    border-color: #0080ff;
    box-shadow: 0 3px 12px rgba(0, 128, 255, 0.4);
}
/* Preview mode — the button morphs into a rounded thumbnail of
   the nearest Mapillary image for the selected parcel. Bumps up
   in size since there's actual imagery worth reading. */
.pegman-button--preview {
    width: 80px;
    height: 80px;
    overflow: hidden;
    padding: 0;
    border-color: #0080ff;
    box-shadow: 0 3px 14px rgba(0, 128, 255, 0.35);
    transition: width 0.2s ease, height 0.2s ease,
                right 0.25s ease, box-shadow 0.15s;
}
.pegman-button--preview:hover {
    box-shadow: 0 5px 18px rgba(0, 128, 255, 0.5);
}
.pegman-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    display: block;
    pointer-events: none; /* clicks should hit the button, not the img */
}
/* When sidebar is visible, tuck the button outside its edge. */
.pegman-button--sidebar-open {
    right: calc(var(--sidebar-width, 300px) + 20px);
}
/* Explore mode: map-wide crosshair for the click-to-drop UX */
body.pegman-exploring .maplibregl-canvas {
    cursor: crosshair !important;
}
body.theme-dark .pegman-button {
    background: #2a2a2a;
    border-color: #444;
    color: #e8eaed;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}
body.theme-dark .pegman-button:hover {
    background: #333;
    color: #fff;
}
body.theme-dark .pegman-button.active {
    background: #0099ff;
    color: #0a0a0a;
    border-color: #0099ff;
}

/* Pegman toast — lightweight, above the map, below the sidebar. */
.pegman-toast {
    position: absolute;
    left: 50%;
    bottom: 80px;
    transform: translateX(-50%);
    background: rgba(33, 33, 33, 0.92);
    color: #fff;
    font-size: 13px;
    padding: 8px 14px;
    border-radius: 999px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
    z-index: 945;
    pointer-events: none;
    opacity: 0;
    transition: opacity 200ms ease;
    white-space: nowrap;
    max-width: 90%;
}
.pegman-toast.visible { opacity: 1; }

/* ---- Swap mode: viewer becomes full-bleed, map becomes PiP ----- */
/* Map PiP chrome is a plain overlay pinned to the same
   bottom-right rect as the body.sv-swapped #map rule below.
   Because both rects are defined purely in CSS with the same
   values, they can never drift out of sync (the old drag-
   enabled version had this problem during move gestures).
   Only the top 32px "header" strip intercepts pointer events
   — the rest of the chrome passes through so the map canvas
   stays fully interactive. */
#map-pip-chrome {
    position: absolute;
    right: 20px;
    bottom: 20px;
    width: min(480px, 34vw);
    height: min(320px, 36vh);
    pointer-events: none;
    display: none;
    /* Must sit above the body.sv-swapped #map rule (z-index 952
       below), or the map canvas swallows clicks on the swap-back
       button. */
    z-index: 954;
}
#map-pip-chrome > * { pointer-events: auto; }
body.sv-swapped #map-pip-chrome { display: block; }
body.sv-swapped.sidebar-visible #map-pip-chrome {
    right: calc(var(--sidebar-width, 300px) + 20px);
}

.map-pip-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 32px;
    background: rgba(248, 249, 250, 0.96);
    border-bottom: 1px solid #dee2e6;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 8px 0 12px;
}
.map-pip-title {
    font-size: 12.5px;
    font-weight: 600;
    color: #495057;
    letter-spacing: 0.02em;
}
.map-pip-swap-btn {
    background: transparent;
    border: none;
    height: 26px;
    padding: 0 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    color: #495057;
    cursor: pointer;
    transition: background-color 0.15s;
}
.map-pip-swap-btn:hover { background: #e9ecef; }

/* In swap mode: the Mapillary container fills the main container. */
body.sv-swapped #mapillary-container.floating-viewer {
    left: 0 !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    border-radius: 0;
    border: none;
    box-shadow: none;
    z-index: 920;
}
/* In swap mode the streetview is full-bleed and its chrome
   header (32px bar with title + time pill + swap/minimize
   buttons) sits at the top edge — overlapping the search bar
   at top-left. Hide the whole header in swap mode: the map
   PiP at bottom-right has its own .map-pip-header with a
   "Swap" button so the user can still flip back. The gallery
   pill is irrelevant here too — swap mode only happens in the
   sidebar layout and the gallery is dashboard-only (CSS hides
   the pill in #floating-viewer-host context). Time-pill date
   label is a small loss but the streetview content is the
   focus in this mode. */
body.sv-swapped .floating-viewer-header {
    display: none;
}
/* …and the map shrinks to a floating PiP in the lower-right.
   Matches the viewer's default PiP footprint (and the
   #map-pip-chrome rect above) so a swap doesn't change the
   frame size, only which content fills it. */
body.sv-swapped #map {
    position: absolute !important;
    left: auto;
    top: auto;
    right: 20px;
    bottom: 20px;
    width: min(480px, 34vw);
    height: min(320px, 36vh);
    /* border-box so the 1px border is INSIDE the declared
       width/height. Without this, the map's outer rect ends
       up 2px wider + 2px taller than #map-pip-chrome (both
       share the same right/bottom anchor but chrome has no
       border), which produces a visible 1–2px sliver of the
       map's top-left corner peeking out past the chrome. */
    box-sizing: border-box;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.22);
    border: 1px solid #dee2e6;
    z-index: 952;
    overflow: hidden;
}
body.sv-swapped.sidebar-visible #map {
    right: calc(var(--sidebar-width, 300px) + 20px);
}

/* Swap button (in floating viewer chrome) */
.floating-viewer-swap-btn {
    background: transparent;
    border: none;
    height: 26px;
    padding: 0 10px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    color: #495057;
    cursor: pointer;
    transition: background-color 0.15s;
}
.floating-viewer-swap-btn:hover { background: #e9ecef; }
.floating-viewer-swap-btn.active {
    background: #d0ebff;
    color: #1971c2;
}
body.theme-dark .map-pip-header {
    background: rgba(37, 37, 37, 0.96);
    border-bottom-color: #333;
}
body.theme-dark .map-pip-title { color: #ddd; }
body.theme-dark .map-pip-swap-btn { color: #ddd; }
body.theme-dark .map-pip-swap-btn:hover { background: #333; }
body.theme-dark .floating-viewer-swap-btn { color: #ddd; }
body.theme-dark .floating-viewer-swap-btn:hover { background: #333; }
body.theme-dark .floating-viewer-swap-btn.active {
    background: #0d2d4a;
    color: #9ac8ec;
}
body.theme-dark body.sv-swapped #map {
    border-color: #333;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
body.theme-dark .pegman-toast {
    background: rgba(18, 18, 18, 0.92);
}

/* ============================================================
   HISTORIC GALLERY — "this property over time"
   ============================================================
   Triggered by the .gallery-pill button next to .time-pill in
   the floating viewer header. Only available in the expanded
   dashboard (large profile view) — the small floating PiP
   hides the button via the selector below. When open, an
   overlay covers the streetview pane with a scrollable column
   of large per-year vintage cards (goobingdetroit aesthetic). */

/* Pill button styling — mirrors .time-pill's chrome so they
   sit visually paired in the header. Icon-only (no label)
   to keep the chrome compact. */
.gallery-pill {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 24px;
    height: 22px;
    padding: 0;
    border-radius: 10px;
    border: 1px solid #c5e0fa;
    background: #e7f5ff;
    color: #1971c2;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.12s, color 0.12s, border-color 0.12s;
    font-family: inherit;
}
.gallery-pill:hover:not(:disabled) {
    background: #d0ebff;
    border-color: #9ac8ec;
}
.gallery-pill--open,
.gallery-pill--open:hover:not(:disabled) {
    background: #1971c2;
    color: #fff;
    border-color: #1971c2;
}
.gallery-pill:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
body.theme-dark .gallery-pill {
    background: rgba(25, 113, 194, 0.22);
    border-color: #2c4a66;
    color: #9ac8ec;
}
body.theme-dark .gallery-pill:hover:not(:disabled) {
    background: rgba(25, 113, 194, 0.32);
    border-color: #3d6890;
}
body.theme-dark .gallery-pill--open,
body.theme-dark .gallery-pill--open:hover:not(:disabled) {
    background: #1971c2;
    color: #fff;
    border-color: #1971c2;
}
/* Hide the gallery button when the viewer is in the floating
   PiP host — the gallery is dashboard-only. The viewer
   container (#mapillary-container) moves between hosts at
   runtime, so we key off ancestor classes. */
#floating-viewer-host .gallery-pill { display: none; }

/* Full-screen compare overlay — Mapillary-style side panel +
   draggable-divider stage. Mounted at <body> level above
   everything; the streetview viewer in the dashboard keeps
   running underneath but is fully obscured by the dark
   background while the gallery is up. */
.historic-gallery-overlay {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: flex;
    background: #1c2330;
    color: #f3f4f6;
    font-family: inherit;
    animation: historic-gallery-fadein 140ms ease-out;
}
@keyframes historic-gallery-fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* ── Side panel (left, ~320px) ── */
.hg-side-panel {
    width: 320px;
    flex-shrink: 0;
    background: #161c26;
    border-right: 1px solid #232b39;
    overflow-y: auto;
    padding: 22px 18px 22px 22px;
    display: flex;
    flex-direction: column;
    gap: 22px;
    scrollbar-width: thin;
    scrollbar-color: #3a4456 transparent;
}
.hg-side-panel-section {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.hg-side-panel-label {
    font-size: 13px;
    font-weight: 500;
    color: #cbd2dd;
    letter-spacing: 0.2px;
}
.hg-side-panel-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ── Card (vintage thumbnail) ── */
.hg-card {
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 0;
    border: 2px solid transparent;
    background: #0f141d;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 140ms ease, transform 140ms ease;
    text-align: left;
}
.hg-card:hover {
    transform: translateY(-1px);
    border-color: #3a4456;
}
.hg-card.is-selected {
    border-color: #f3f4f6;
}
.hg-card[data-role="original"] { cursor: default; }
.hg-card[data-role="original"]:hover { transform: none; }
.hg-card-image {
    width: 100%;
    aspect-ratio: 2 / 1;
    background: #0a0e15;
    background-repeat: repeat-x;
    background-position-y: center;
    background-size: cover;
}
.hg-card-meta {
    position: absolute;
    left: 10px;
    bottom: 8px;
    background: rgba(255, 255, 255, 0.92);
    color: #1f2937;
    padding: 3px 9px;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 500;
    letter-spacing: 0.1px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
}

/* ── Stage (the compare area on the right) ── */
.hg-stage-wrap {
    position: relative;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}
.hg-exit-btn {
    position: absolute;
    top: 18px;
    right: 22px;
    z-index: 2;
    background: rgba(255, 255, 255, 0.92);
    color: #1f2937;
    border: none;
    border-radius: 999px;
    padding: 6px 18px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
    transition: background-color 0.12s;
    font-family: inherit;
}
.hg-exit-btn:hover { background: #fff; }
.hg-stage {
    position: relative;
    flex: 1;
    overflow: hidden;
    user-select: none;
    cursor: grab;
    touch-action: none;
}
.hg-stage-half {
    position: absolute;
    inset: 0;
    background-color: #0a0e15;
    background-repeat: repeat-x;
    background-position-y: center;
    background-size: 400% auto; /* default — overridden inline */
}
.hg-stage-half--right {
    /* Right is on top; clip-path inset from left via JS so it
       only reveals the portion to the right of the divider. */
    clip-path: inset(0 0 0 50%);
}
.hg-stage-divider {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 2px;
    margin-left: -1px;
    background: #ffffff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.5);
    cursor: ew-resize;
    z-index: 1;
    touch-action: none;
}
.hg-stage-divider-handle {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #ffffff;
    color: #1f2937;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    pointer-events: none;
}
.hg-stage-controls {
    padding: 18px 24px 22px;
    display: flex;
    justify-content: center;
    background: #1c2330;
}
.hg-stage-slider {
    width: min(560px, 70%);
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    background: #3a4456;
    border-radius: 3px;
    outline: none;
}
.hg-stage-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #1c2330;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
.hg-stage-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ffffff;
    border: 2px solid #1c2330;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

/* Light-mode override: the gallery's dark theme is intentional
   and stays the same in light mode (it's a dedicated UI moment,
   like a video lightbox). No theme variants needed. */

/* ============================================================
   BASEMAP TOGGLE — rail thumbnail button (order:5, top of rail)
   ============================================================
   Mounts in #icon-rail at order:5, before Filter (10).
   Shows a 36×36 thumbnail of the OTHER basemap so the button
   reads as both a control and a live view-mode indicator.
   No positioning rules needed — it's just a rail button. */

.basemap-rail-btn {
    position: relative;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
    border: 2px solid rgba(255, 255, 255, 0.75);
    overflow: hidden;
    cursor: pointer;
    background: #d8e4f0; /* placeholder while tile loads */
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.28);
    transition: border-color var(--motion-fast),
                box-shadow var(--motion-fast);
    flex-shrink: 0;
}
.basemap-rail-btn:hover {
    border-color: rgba(255, 255, 255, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.38);
}
.basemap-rail-btn:focus-visible {
    outline: 2px solid var(--color-accent);
    outline-offset: 2px;
}

/* Thumbnail fills the button */
.basemap-rail-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Label strip over the bottom edge */
.basemap-rail-label {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    font-size: 7px;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    text-align: center;
    padding: 2px 0 3px;
    line-height: 1;
}

/* Stronger scrim when aerial active — road-map thumb is lighter */
.basemap-rail-btn--aerial .basemap-rail-label {
    background: rgba(0, 0, 0, 0.62);
}

body.theme-dark .basemap-rail-btn {
    border-color: rgba(255, 255, 255, 0.5);
}

/* ── Icon rail: don't scrunch in swap mode ──────────────────
   When body.sv-swapped #map shrinks to a PiP, the rail used
   to live inside that tiny box. It's now in #main-container
   so this rule is just an extra safety guard: keep the rail
   at the viewport top-right even in swap mode. */
body.sv-swapped #icon-rail {
    right: 10px;
}
body.sv-swapped.sidebar-visible #icon-rail {
    right: calc(var(--sidebar-width, 300px) + 10px);
}
@media (max-width: 768px) {
    body.sv-swapped.sidebar-visible #icon-rail {
        right: 10px;
    }
}
