/* ============================================================================
 * map3d-terrain.css — styles for the optional 3D terrain view
 * ----------------------------------------------------------------------------
 * Scope rule: every selector in this file is namespaced (#map3d-*) or hangs off
 * a body class (.is-3d) so the existing 2D map, its controls and the layer
 * panel are never restyled. The 3D surface is an overlay on top of
 * #detectlab-map, inside .map-wrapper, so PWA/fullscreen sizing comes for free.
 * ========================================================================== */

/* ── the surface itself ─────────────────────────────────────────────────── */
#map3d-surface {
    position: absolute;
    inset: 0;
    /* Leaflet panes (401–660), the Josephine transition (950), the layer panel
     * (1001/1002) and the search bar (≥1000) all compete in this same stacking
     * context — see css/styles.css. 700 puts the 3D canvas above every Leaflet
     * pane and below every piece of DetectLab chrome, so the layer panel, the
     * search bar and the dock stay usable while 3D is on. */
    z-index: 700;
    border-radius: 12px;
    overflow: hidden;
    background: #060E1E;
    display: none;
}

/* While 3D is on, the Leaflet panes keep their state but stop painting: the
 * MapLibre canvas is the only map the user sees, and the browser is not asked
 * to rasterise two full maps at once. Everything comes back instantly when 3D
 * is closed — this is a paint-side switch, not a teardown. */
body.is-3d #detectlab-map .leaflet-pane { visibility: hidden; }

/* Leaflet's own controls (zoom, locate, measure) drive the *2D* map, and
 * Leaflet pins them at z-index 1000 — above this canvas. Hidden while 3D is
 * on, so nobody clicks a button that moves a map they cannot see; MapLibre
 * contributes a compact source-credit control and the scale, both bottom-left
 * (no navigation or terrain toggle). The 3D bar keeps the shared basemap
 * picker, the reset/north/flat shortcuts and the LiDAR row: pitch, bearing and
 * terrain exaggeration are gesture-only / fixed on the web layout. The live location
 * control that the PWA appends to its own stack is hidden for the same reason
 * (it moves the 2D camera). */
body.is-3d #detectlab-map .leaflet-control-container,
body.is-3d #pwa-br-stack .leaflet-control { visibility: hidden; }

/* …with ONE exception: the base-layer button (#arcgisBasemapCtrl). Switching
 * the base map must stay possible without leaving 3D — it is the same control
 * the 2D view uses (and the 3D bar's basemap picker reads/writes the same
 * state), so it keeps its bottom-left slot in the 3D view instead of leaving
 * the user to find the picker in the bar. Everything else in that corner still
 * drives the invisible 2D map and stays hidden; the compass is display:none so
 * it does not reserve the switch's slot in the column either. */
body.is-3d #detectlab-map .leaflet-bottom.leaflet-left > .leaflet-control:not(#arcgisBasemapCtrl) {
    display: none !important;
}
body.is-3d #detectlab-map #arcgisBasemapCtrl {
    visibility: visible;
    /* MapLibre puts its own widgets in the same corner — the compact
     * source-credit button (the ⓘ) and the scale bar. The base-layer button
     * rides ABOVE them: the viewer measures that stack and publishes its height
     * (+ the usual 8px gap) as --m3d-basemap-lift on .map-wrapper; the 58px
     * fallback is the documented MapLibre stack (credit row + scale + margins). */
    margin-bottom: var(--m3d-basemap-lift, 58px) !important;
}

body.is-3d #map3d-surface { display: block; }

body.is-3d .map-wrapper.is-fullscreen #map3d-surface,
body.is-pwa.is-3d #map3d-surface {
    border-radius: 0;
}

#map3d-surface canvas { outline: none; }

/* ── loading / error veil ──────────────────────────────────────────────── */
#map3d-veil {
    position: absolute;
    inset: 0;
    z-index: 3;
    display: none;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
    text-align: center;
    padding: 24px;
    background: rgba(6, 14, 30, 0.82);
    color: rgba(245, 240, 235, 0.9);
    font-family: 'Outfit', sans-serif;
    font-size: 0.86rem;
    line-height: 1.5;
    backdrop-filter: blur(2px);
}

#map3d-surface.is-busy #map3d-veil,
#map3d-surface.is-error #map3d-veil { display: flex; }

#map3d-veil .m3d-ring {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 2px solid rgba(184, 216, 240, 0.25);
    border-top-color: #c8a96e;
    animation: map3d-spin 0.9s linear infinite;
}

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

#map3d-veil .m3d-veil-title { font-weight: 600; letter-spacing: 0.02em; }
#map3d-veil .m3d-veil-detail {
    font-size: 0.78rem;
    color: rgba(245, 240, 235, 0.65);
    max-width: 30rem;
    /* A long error message (the exact WebGL reason is appended) must never
     * push the buttons off the bottom of a phone screen. */
    max-height: 40vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* The two ways out of an error: retry the 3D view, or give up and go back to
 * the 2D map. They live inside the surface, which is the only place an error
 * CAN be shown — #map3d-surface is display:none without body.is-3d, so an
 * error that removed the class hid its own message (the mobile “flashes and
 * snaps back to 2D” bug). */
#map3d-veil .m3d-veil-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

#map3d-veil .m3d-veil-action,
#map3d-veil .m3d-veil-back {
    margin-top: 4px;
    padding: 7px 14px;
    border-radius: 6px;
    border: 1px solid rgba(200, 169, 110, 0.45);
    background: rgba(200, 169, 110, 0.14);
    color: #f5f0eb;
    font: inherit;
    cursor: pointer;
}
/* Secondary: “back to 2D” must not out-shout “try again”. */
#map3d-veil .m3d-veil-back {
    border-color: rgba(184, 216, 240, 0.3);
    background: rgba(184, 216, 240, 0.08);
}
#map3d-veil .m3d-veil-action:hover,
#map3d-veil .m3d-veil-back:hover { background: rgba(200, 169, 110, 0.26); }
#map3d-veil .m3d-veil-back:hover { background: rgba(184, 216, 240, 0.18); }

/* ── the 2D/3D switch and nearby tile refresh action ─────────────────── */
.m3d-toggle-group {
    /* Box model only. The 2D/3D switch's position is environment-specific:
     * bottom-left above the base-layer button in the installed PWA
     * (body.is-pwa .m3d-toggle-group, measured by js/map3d-terrain.js), and
     * bottom-centre on the website (body:not(.is-pwa) .m3d-toggle-group),
     * clear of the country “Exit view” pill and the analysis dock that share
     * the bottom-centre slot. */
    z-index: 960;               /* above the 3D surface, below the app chrome */
    display: flex;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

/* Installed PWA: the switch heads the bottom-left control column, directly
 * above the base-layer button (#arcgisBasemapCtrl). The offset is measured
 * and published by js/map3d-terrain.js (--m3d-anchor-*); the fallback is the
 * documented PWA column (146px + home-indicator inset: compass + Detect, the
 * base-layer button and Leaflet's own corner margins). */
body.is-pwa .m3d-toggle-group {
    position: absolute;
    bottom: var(--m3d-anchor-bottom, calc(146px + var(--map3d-safe-area-bottom, env(safe-area-inset-bottom, 0px))));
    left: var(--m3d-anchor-left, 10px);
}

/* Website: the switch floats bottom-centre (66 px on desktop, 58 px on
 * phones), clear of the country “Exit view” pill and the analysis dock. */
body:not(.is-pwa) .m3d-toggle-group {
    position: absolute;
    bottom: 66px;
    left: 50%;
    transform: translateX(-50%);
}

/* Installed PWA, 3D on: the 2D switch and the tile-refresh action leave the
 * bottom-left control column and centre on the lower edge, directly under the
 * centred 3D bar — the website keeps this group centred all the time, and the
 * PWA now matches it once the second button (refresh) joins the group. The
 * offset leaves room for the LiDAR pill and the phone navigation area.
 * While the country “Exit view” pill is showing, js/country-dock.js publishes
 * --country-exit-lift (46px, PWA only) and the group steps above that pill,
 * exactly as the centred switch did before it moved into the column. In 2D
 * the group stays in the column: the base body.is-pwa rule below keeps the
 * measured anchor because this selector only matches with .is-3d. */
body.is-pwa.is-3d .m3d-toggle-group {
    bottom: calc(96px + var(--map3d-safe-area-bottom, env(safe-area-inset-bottom, 0px)) + var(--country-exit-lift, 0px));
    left: calc(50% - 22px);
    transform: translateX(-50%);
}

/* The analysis dock lives outside the map wrapper. Its bottom offset is
 * measured against its own containing block and clears the entire 3D button
 * stack. The fallback works before the first measurement. Specificity and
 * !important also beat the PWA's inline bottom/bleed override. */
body.is-3d .layer-action-dock,
body.is-pwa.is-3d .layer-action-dock {
    bottom: var(--m3d-analysis-dock-bottom, calc(192px + var(--map3d-safe-area-bottom, env(safe-area-inset-bottom, 0px)) + var(--country-exit-lift, 0px))) !important;
}

/* In the installed 3D view the basemap control joins the 2D/refresh row.
 * Keep it in Leaflet's corner (and its existing event handlers), but position
 * the corner across the map so it shares the row's safe-area offset. */
body.is-pwa.is-3d #detectlab-map .leaflet-bottom.leaflet-left {
    width: 100%;
    /* The regular PWA corner already adds the safe-area inset and bleed.
       The row below is positioned relative to the wrapper and includes its
       own inset; reset the corner or the basemap button is lifted twice. */
    bottom: 0 !important;
    pointer-events: none;
}
body.is-pwa.is-3d #detectlab-map #arcgisBasemapCtrl {
    position: absolute;
    left: calc(50% + 25px);
    bottom: calc(98px + var(--map3d-safe-area-bottom, env(safe-area-inset-bottom, 0px)) + var(--country-exit-lift, 0px));
    margin: 0 !important;
    pointer-events: auto;
    display: flex;
    flex-direction: column-reverse;
}
/* Keep the icon beside refresh when the list opens upwards. */
body.is-pwa.is-3d #arcgisBasemapCtrl .arcgis-basemap-header {
    width: 38px;
    align-self: flex-start;
}
body.is-pwa.is-3d #arcgisBasemapCtrl .arcgis-basemap-list {
    border-top: 0;
    border-bottom: 1px solid rgba(184, 216, 240, 0.14);
}

/* The 2D/3D switch rides the same glass material as the map icons
   (tokens in css/styles.css :root), so the bottom-centre pill never reads as
   a second, warmer design language. */
#map3d-toggle,
#map3d-refresh {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 36px;
    padding: 6px 11px;
    border-radius: var(--ctl-radius, 12px);
    border: 1px solid var(--ctl-border, rgba(198, 180, 255, 0.20));
    background: var(--ctl-bg, rgba(24, 19, 40, 0.45));
    color: var(--ctl-icon, #BBA9F2);
    font-family: 'Outfit', sans-serif;
    font-size: 0.74rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    cursor: pointer;
    pointer-events: auto;
    -webkit-backdrop-filter: var(--ctl-blur, blur(18px) saturate(150%));
    backdrop-filter: var(--ctl-blur, blur(18px) saturate(150%));
    box-shadow: var(--ctl-shadow, 0 6px 18px rgba(4, 6, 18, 0.32));
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}

#map3d-toggle:hover,
#map3d-refresh:hover {
    background: var(--ctl-bg-hover, rgba(45, 33, 74, 0.60));
    border-color: var(--ctl-border-hover, rgba(198, 180, 255, 0.38));
    color: var(--ctl-icon-hover, #DCD2FB);
}
#map3d-toggle:focus-visible,
#map3d-refresh:focus-visible { outline: 2px solid var(--ctl-border-engaged, rgba(206, 190, 255, 0.55)); outline-offset: 2px; }
#map3d-toggle .m3d-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: rgba(198, 180, 255, 0.45);
}
body.is-3d #map3d-toggle .m3d-dot { background: #C6B4FA; box-shadow: 0 0 6px rgba(198, 180, 255, 0.65); }
#map3d-toggle[disabled] { opacity: 0.6; cursor: progress; }
#map3d-refresh { display: none; min-width: 44px; }
body.is-3d #map3d-refresh { display: inline-flex; }
#map3d-refresh .m3d-refresh-icon { display: inline-block; font-size: 1.1rem; line-height: 1; }
#map3d-refresh .m3d-refresh-count { font-size: 0.62rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
#map3d-refresh.is-busy .m3d-refresh-icon { animation: map3d-spin 1s linear infinite; }
#map3d-refresh.is-stopping .m3d-refresh-icon { animation: none; }
#map3d-refresh.is-error { border-color: rgba(255, 125, 125, 0.6); }
#map3d-refresh:disabled { opacity: 0.65; cursor: progress; }

/* Installed PWA only: the switch and the refresh action are 38×38 icon-sized
   squares, exactly like the compass, Detect and base-layer buttons they share
   the bottom-left control column with (css/styles.css, index.html). The
   website keeps the roomier text pill above — it has the whole bottom-centre
   slot. The id + body-class specificity here (1,1,1) beats both the shared
   pill rule and the 720px phone media query's 44px touch bump, so the column
   stays uniformly 38px on every PWA screen instead of growing on phones. */
body.is-pwa #map3d-toggle,
body.is-pwa #map3d-refresh {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    gap: 3px;
}
/* A 38px square has no room for the “done/total” count beside the glyph. The
   count is aria-hidden anyway: the role=status .m3d-refresh-status span and
   the button's title carry the same progress for assistive technology. */
body.is-pwa #map3d-refresh .m3d-refresh-count { display: none; }
.m3d-refresh-status {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ── the 3D control bar (only while 3D is on) ───────────────────────────── */
#map3d-bar {
    /* Bottom-left, one slot above the 2D/3D switch: the right edge belongs to
     * the layer panel (1001, full height) and the opacity mirror, the top
     * centre to the search bar, and the bottom centre to the country “Exit
     * view” pill / the folded LiDAR window — the left edge is the only strip
     * that stays free once 3D is on (Leaflet's own zoom/locate controls are
     * hidden in 3D, and MapLibre's scale control sits below this offset). The
     * switch stays visible in 3D — it is the way back to 2D — so the bar rides
     * on the same measured anchor, --m3d-stack-top, instead of a constant. */
    position: absolute;
    z-index: 960;               /* above the 3D surface, below the app chrome */
    display: none;
    flex-direction: column;
    gap: 8px;
    width: 208px;
    max-width: calc(100% - 20px);
    padding: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    color: rgba(245, 240, 235, 0.92);
    font-family: 'Outfit', sans-serif;
    font-size: 0.72rem;
    /* No shared backdrop: only the individual slider strips are tinted.
     * Gaps between them remain transparent and let map gestures through. */
    pointer-events: none;
    overflow-y: auto;
}

/* Installed PWA: keep the bar above the centred controls, including the
 * extra lift when the country exit pill is visible. */
body.is-pwa.is-3d #map3d-bar {
    top: auto;
    right: auto;
    left: 50%;
    transform: translateX(-50%);
    bottom: calc(142px + var(--map3d-safe-area-bottom, env(safe-area-inset-bottom, 0px)) + var(--country-exit-lift, 0px));
    width: 280px;
    max-width: calc(100% - 100px);
    max-height: calc(100% - 214px - var(--map3d-safe-area-bottom, env(safe-area-inset-bottom, 0px)) - var(--country-exit-lift, 0px));
    overflow-y: auto;
    scrollbar-width: thin;
}

/* Website: bar above the bottom-centre switch. */
body:not(.is-pwa).is-3d #map3d-bar {
    left: 50%;
    transform: translateX(-50%);
    bottom: 34px;
    width: 208px;
    max-width: calc(100% - 20px);
    max-height: calc(100% - 72px);
}

body.is-3d #map3d-bar { display: flex; }

#map3d-bar > * { pointer-events: auto; flex-shrink: 0; }
#map3d-bar.collapsed .m3d-row,
#map3d-bar.collapsed .m3d-actions { display: none; }

.m3d-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 6px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    font-size: 0.66rem;
    color: rgba(200, 169, 110, 0.95);
}

.m3d-head button {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    font: inherit;
    padding: 2px 4px;
}

#map3d-bar .m3d-row {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid rgba(184, 216, 240, 0.24);
    background: rgba(6, 14, 30, 0.48);
    backdrop-filter: blur(4px);
}
#map3d-bar .m3d-row > label { display: flex; justify-content: space-between; gap: 6px; }
/* The bar's only row is the basemap picker: the exaggeration / pitch /
 * bearing sliders (and their `input[type="range"]` skin) are gone — the 3D
 * camera is moved by gestures, and the DEM exaggeration is a fixed constant. */
#map3d-bar .m3d-basemap-select {
    display: block;
    width: 100%;
    min-height: 36px;
    margin: 0;
    padding: 6px 8px;
    border: 1px solid rgba(184, 216, 240, 0.24);
    border-radius: 6px;
    background: rgba(6, 14, 30, 0.86);
    color: rgba(245, 240, 235, 0.94);
    font: inherit;
    cursor: pointer;
}
#map3d-bar .m3d-basemap-select:focus-visible {
    outline: 2px solid #c8a96e;
    outline-offset: 1px;
}
#map3d-bar .m3d-basemap-select option { background: #0a1526; color: #f5f0eb; }
#map3d-bar .m3d-row:focus-within { border-color: #c8a96e; }
#map3d-bar .m3d-head { text-shadow: 0 1px 3px #060e1e; }

.m3d-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.m3d-actions button {
    flex: 1 1 auto;
    padding: 5px 8px;
    border-radius: 6px;
    border: 1px solid rgba(184, 216, 240, 0.24);
    background: rgba(184, 216, 240, 0.08);
    color: inherit;
    font: inherit;
    cursor: pointer;
}

.m3d-actions button:hover { background: rgba(184, 216, 240, 0.18); }

/* MapLibre's own controls inside the surface */
/* Everything MapLibre adds is at bottom-left: the compact source-credit
 * button and the scale. The top-right corner belongs to the app's own help
 * button alone — the terrain toggle that used to be parked under it (a
 * `.maplibregl-ctrl-group` button group) is gone from the viewer, and with it
 * the row reservation, the phone `display: none` and the group/icon skin that
 * only that button needed. */

#map3d-surface .maplibregl-ctrl-attrib {
    background: rgba(6, 14, 30, 0.72);
    color: rgba(245, 240, 235, 0.8);
    font-size: 0.62rem;
}
#map3d-surface .maplibregl-ctrl-attrib a { color: rgba(200, 169, 110, 0.95); }
#map3d-surface .maplibregl-ctrl-attrib-button {
    background-color: rgba(245, 240, 235, 0.92);
    border-radius: 50%;
}
#map3d-surface .maplibregl-ctrl-scale {
    background: rgba(6, 14, 30, 0.6);
    color: rgba(245, 240, 235, 0.85);
    border-color: rgba(184, 216, 240, 0.4);
}

/* ── narrow screens ────────────────────────────────────────────────────── */
@media (max-width: 720px) {
    #map3d-bar {
        width: 168px;
        font-size: 0.68rem;
        padding: 0;
    }
    #map3d-toggle,
    #map3d-refresh {
        min-height: 44px;
        font-size: 0.68rem;
        padding: 5px 8px;
    }
    /* On phones the search bar owns the top of the map and the country pill the
     * bottom centre: the bar tucks under the search bar on the left (installed
     * PWA only — the column switch lives there), and its max-height stops above
     * the measured 2D/3D switch. On the website the switch stays bottom-centre
     * and the bar keeps its website placement. */
    body.is-pwa #map3d-bar {
        top: 56px;
        left: 8px;
        bottom: auto;
        max-height: calc(100% - 64px - var(--m3d-stack-top, 144px));
    }
    body:not(.is-pwa) .m3d-toggle-group {
        bottom: 58px;
    }
    /* Hide the scale widget on phones, not the compact source-credit button. */
    #map3d-surface .maplibregl-ctrl-bottom-left .maplibregl-ctrl-scale { display: none; }
    #map3d-surface .maplibregl-ctrl-bottom-left,
    #map3d-surface .maplibregl-ctrl-bottom-right { font-size: 0.6rem; }

    /* The veil is the only thing standing between a phone and a silent
     * failure, so its buttons get a real touch target (44 px is Apple's
     * minimum) and the whole panel keeps clear of the rounded corners. */
    #map3d-veil { padding: 16px; }
    #map3d-veil .m3d-veil-actions { width: 100%; }
    #map3d-veil .m3d-veil-action,
    #map3d-veil .m3d-veil-back {
        min-height: 44px;
        min-width: 44px;
        flex: 1 1 8rem;
        padding: 10px 16px;
        font-size: 0.82rem;
    }
}

/* One safe-area value keeps the PWA fallbacks and the bottom-anchored LiDAR
 * pill in step; exposing it as a custom property also lets layout tests
 * simulate the home-indicator inset. */
body.is-pwa { --map3d-safe-area-bottom: env(safe-area-inset-bottom, 0px); }

@media (max-height: 420px) {
    #map3d-bar { max-height: calc(100% - var(--m3d-stack-top, 144px) - 72px); }
}

/* ── popups opened from a 3D feature (same HTML the 2D popup shows) ────── */
#map3d-surface .maplibregl-popup.m3d-popup .maplibregl-popup-content {
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(184, 216, 240, 0.28);
    background: rgba(6, 14, 30, 0.94);
    color: rgba(245, 240, 235, 0.95);
    font-family: 'Outfit', sans-serif;
    font-size: 0.76rem;
    line-height: 1.45;
    max-height: 40vh;
    overflow: auto;
}

#map3d-surface .maplibregl-popup.m3d-popup .maplibregl-popup-tip { border-top-color: rgba(6, 14, 30, 0.94); }
#map3d-surface .maplibregl-popup.m3d-popup a { color: rgba(200, 169, 110, 0.95); }
#map3d-surface .maplibregl-popup.m3d-popup a[href*="cimec.ro"] { color: #fff !important; }
#map3d-surface .maplibregl-popup.m3d-popup .m3d-popup-body b { color: rgba(245, 240, 235, 0.9); }


/* Keep the compact 3D source-credit control clear of the PWA's bottom-right
 * action stack and above the home indicator. If opened, long credits can scroll. */
body.is-pwa.is-3d #map3d-surface .maplibregl-ctrl-bottom-left {
    bottom: env(safe-area-inset-bottom, 0px);
    max-width: 42%;
}
body.is-pwa.is-3d #map3d-surface .maplibregl-ctrl-attrib {
    max-height: 3.4em;
    overflow: auto;
    overflow-wrap: anywhere;
}

/* In the installed PWA the separate layer button already provides the
 * basemap picker. Keep only the camera shortcuts in this bar, even if it was
 * collapsed before entering the PWA. The website keeps its own picker. */
body.is-pwa.is-3d #map3d-bar .m3d-head,
body.is-pwa.is-3d #map3d-bar .m3d-basemap-row { display: none; }
body.is-pwa.is-3d #map3d-bar.collapsed .m3d-actions { display: flex; }

/* Desktop web 3D: the same compact controls as the installed PWA. The
 * existing Leaflet picker remains the single source of basemap state; only
 * its position changes, and its list opens upwards from the icon. */
body:not(.is-pwa).is-3d .m3d-toggle-group {
    left: calc(50% - 22px);
    bottom: calc(96px + var(--country-exit-lift, 0px));
}
body:not(.is-pwa).is-3d #map3d-toggle,
body:not(.is-pwa).is-3d #map3d-refresh {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    gap: 3px;
}
body:not(.is-pwa).is-3d #map3d-refresh .m3d-refresh-count { display: none; }
body:not(.is-pwa).is-3d #detectlab-map .leaflet-bottom.leaflet-left {
    position: absolute !important;
    width: 100%;
    bottom: 0 !important;
    pointer-events: none;
}
body:not(.is-pwa).is-3d #detectlab-map #arcgisBasemapCtrl {
    position: absolute;
    left: calc(50% + 25px);
    bottom: calc(98px + var(--country-exit-lift, 0px));
    margin: 0 !important;
    pointer-events: auto;
    display: flex;
    flex-direction: column-reverse;
}
body:not(.is-pwa).is-3d #arcgisBasemapCtrl .arcgis-basemap-header {
    width: 38px;
    align-self: flex-start;
}
body:not(.is-pwa).is-3d #arcgisBasemapCtrl .arcgis-basemap-list {
    border-top: 0;
    border-bottom: 1px solid rgba(184, 216, 240, 0.14);
}
body:not(.is-pwa).is-3d #map3d-bar {
    bottom: calc(142px + var(--country-exit-lift, 0px));
    width: 280px;
    max-width: calc(100% - 100px);
}
body:not(.is-pwa).is-3d #map3d-bar .m3d-head,
body:not(.is-pwa).is-3d #map3d-bar .m3d-basemap-row { display: none; }
body:not(.is-pwa).is-3d #map3d-bar.collapsed .m3d-actions { display: flex; }

/* ══════════════════════════════════════════════════════════════════════════
 * The LiDAR focus (js/lidar-3d-focus.js)
 * --------------------------------------------------------------------------
 * Shown over the 2D map — pressing 3D with a LiDAR layer switched on never
 * opens 3D straight away: it asks for a point and a fetching distance first,
 * prefetches that disc, and only then switches renderer. Colours follow the
 * 3D surface (its veil and bar) so the dialog reads as part of the same step.
 * ══════════════════════════════════════════════════════════════════════════ */

#map3d-focus {
    position: absolute;
    inset: 0;
    /* Above the layer panel (1001/1002) and the search bar: this is a modal
     * decision about what the next view may load. */
    z-index: 1400;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    /* The card takes the clicks; the map behind it keeps its gestures. */
    pointer-events: none;
    font-family: 'Outfit', sans-serif;
    color: rgba(245, 240, 235, 0.94);
}

#map3d-focus .m3d-focus-card {
    pointer-events: auto;
    box-sizing: border-box;
    width: min(400px, calc(100% - 16px));
    max-height: min(76vh, 620px);
    overflow-y: auto;
    background: rgba(6, 14, 30, 0.94);
    border: 1px solid rgba(200, 169, 110, 0.42);
    border-radius: 12px;
    padding: 11px 13px 13px;
    box-shadow: 0 18px 44px rgba(2, 6, 14, 0.6);
    font-size: 0.78rem;
    line-height: 1.3;
}

#map3d-focus .m3d-focus-card[hidden] { display: none; }

.m3d-focus-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 4px;
}

#map3d-focus h2 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: rgba(200, 169, 110, 0.98);
}

#map3d-focus .m3d-focus-x {
    background: none;
    border: none;
    color: rgba(245, 240, 235, 0.75);
    font: inherit;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
    /* A real touch target: this dialog is the one place a phone user has to be
     * able to get out of, and its header is where they look for it. */
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

#map3d-focus .m3d-focus-x:hover { background: rgba(184, 216, 240, 0.14); }

#map3d-focus .m3d-focus-lead {
    margin: 0 0 8px;
    color: rgba(245, 240, 235, 0.78);
    font-size: 0.74rem;
}

#map3d-focus .m3d-focus-block {
    border-top: 1px solid rgba(184, 216, 240, 0.14);
    padding-top: 8px;
    margin-top: 8px;
}

#map3d-focus .m3d-focus-label {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
    font-weight: 600;
    letter-spacing: 0.02em;
    margin-bottom: 4px;
}

#map3d-focus .m3d-focus-cap {
    font-style: normal;
    font-size: 0.68rem;
    opacity: 0.66;
}

#map3d-focus .m3d-focus-layers {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 112px;
    overflow-y: auto;
}

#map3d-focus .m3d-focus-layer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 9px;
    border: 1px solid rgba(184, 216, 240, 0.2);
    border-radius: 8px;
    background: rgba(184, 216, 240, 0.06);
    cursor: pointer;
    font-size: 0.76rem;
    /* Comfortable for a thumb: the whole row is the target. */
    min-height: 34px;
}

#map3d-focus .m3d-focus-layer.is-on {
    border-color: rgba(200, 169, 110, 0.75);
    background: rgba(200, 169, 110, 0.16);
}

#map3d-focus .m3d-focus-layer input { accent-color: #c8a96e; margin: 0; }

/* The scope switch: whole layers, or only the 1 km disc. Two buttons side by
 * side — the first thing the window asks, so it reads as a choice, not as a
 * setting buried further down. */
#map3d-focus .m3d-focus-scope {
    display: flex;
    gap: 6px;
}

#map3d-focus .m3d-focus-scope-opt {
    flex: 1 1 0;
    min-height: 36px;
    padding: 6px 8px;
    border: 1px solid rgba(184, 216, 240, 0.24);
    border-radius: 8px;
    background: rgba(184, 216, 240, 0.06);
    color: inherit;
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
}

#map3d-focus .m3d-focus-scope-opt:hover { background: rgba(184, 216, 240, 0.14); }

#map3d-focus .m3d-focus-scope-opt.is-on {
    border-color: rgba(200, 169, 110, 0.8);
    background: rgba(200, 169, 110, 0.18);
    color: rgba(255, 240, 214, 0.98);
}

#map3d-focus .m3d-focus-scope-note {
    margin: 6px 0 0;
    font-size: 0.7rem;
    line-height: 1.35;
    opacity: 0.72;
}

/* A block the current scope does not need (the area/point controls in the
 * whole-layer mode) is hidden outright — the author display above must not
 * beat the attribute. */
#map3d-focus .m3d-focus-block[hidden] { display: none; }

#map3d-focus .m3d-focus-hintline,
#map3d-focus .m3d-focus-empty {
    margin: 8px 0 0;
    font-size: 0.7rem;
    opacity: 0.7;
}

/* The area block when the radius is fixed (1 km, the default): the disc is a
 * decision of the entry rule, not a setting — so it reads as a sentence, with
 * the note about what stays outside it, instead of a slider nobody may move. */
#map3d-focus .m3d-focus-fixed {
    margin: 3px 0 0;
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid rgba(200, 169, 110, 0.28);
    background: rgba(200, 169, 110, 0.08);
    font-size: 0.72rem;
    opacity: 1;
    line-height: 1.35;
}

#map3d-bar input[type="range"],
#map3d-focus .m3d-focus-radius {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: var(--slider-track-h, 3px);
    margin: 4px 0 6px;
    padding: 0;
    border: 0;
    border-radius: 999px;
    background: linear-gradient(
        90deg,
        var(--slider-fill, rgba(242, 170, 121, 0.52)) 0%,
        var(--slider-fill, rgba(242, 170, 121, 0.52)) var(--slider-pct, 0%),
        var(--slider-track-bg, rgba(245, 240, 235, 0.14)) var(--slider-pct, 0%),
        var(--slider-track-bg, rgba(245, 240, 235, 0.14)) 100%
    );
    accent-color: rgba(244, 176, 128, 0.82);
    outline: none;
    cursor: pointer;
}

#map3d-bar input[type="range"]::-webkit-slider-thumb,
#map3d-focus .m3d-focus-radius::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: var(--slider-thumb-size, 12px);
    height: var(--slider-thumb-size, 12px);
    border-radius: 50%;
    background: var(--slider-thumb-bg, rgba(244, 176, 128, 0.74));
    border: 1px solid var(--slider-thumb-border, rgba(255, 228, 206, 0.52));
    box-shadow: var(--slider-thumb-shadow, 0 1px 4px rgba(4, 6, 18, 0.36));
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}

#map3d-bar input[type="range"]::-webkit-slider-thumb:hover,
#map3d-focus .m3d-focus-radius::-webkit-slider-thumb:hover {
    background: var(--slider-thumb-bg-hover, rgba(248, 188, 144, 0.88));
    transform: scale(1.1);
}

#map3d-bar input[type="range"]::-moz-range-thumb,
#map3d-focus .m3d-focus-radius::-moz-range-thumb {
    width: var(--slider-thumb-size, 12px);
    height: var(--slider-thumb-size, 12px);
    border-radius: 50%;
    background: var(--slider-thumb-bg, rgba(244, 176, 128, 0.74));
    border: 1px solid var(--slider-thumb-border, rgba(255, 228, 206, 0.52));
    box-shadow: var(--slider-thumb-shadow, 0 1px 4px rgba(4, 6, 18, 0.36));
    cursor: pointer;
}

#map3d-bar input[type="range"]::-moz-range-track,
#map3d-focus .m3d-focus-radius::-moz-range-track {
    height: var(--slider-track-h, 3px);
    border: 0;
    border-radius: 999px;
    background: var(--slider-track-bg, rgba(245, 240, 235, 0.14));
}

#map3d-bar input[type="range"]::-moz-range-progress,
#map3d-focus .m3d-focus-radius::-moz-range-progress {
    height: var(--slider-track-h, 3px);
    border-radius: 999px;
    background: var(--slider-fill, rgba(242, 170, 121, 0.52));
}

#map3d-focus .m3d-focus-chips { display: flex; flex-wrap: wrap; gap: 6px; }

#map3d-focus .m3d-focus-chips button {
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid rgba(184, 216, 240, 0.24);
    background: rgba(184, 216, 240, 0.08);
    color: inherit;
    font: inherit;
    font-size: 0.72rem;
    cursor: pointer;
}

#map3d-focus .m3d-focus-chips button.is-on {
    border-color: rgba(200, 169, 110, 0.8);
    background: rgba(200, 169, 110, 0.2);
}

#map3d-focus .m3d-focus-point-block .m3d-focus-pick {
    width: 100%;
    padding: 9px 10px;
    border-radius: 8px;
    border: 1px dashed rgba(200, 169, 110, 0.6);
    background: rgba(200, 169, 110, 0.08);
    color: inherit;
    font: inherit;
    cursor: pointer;
    min-height: 36px;
}

#map3d-focus .m3d-focus-point-block .m3d-focus-pick:hover { background: rgba(200, 169, 110, 0.18); }

#map3d-focus .m3d-focus-estimate {
    margin: 8px 0 0;
    font-size: 0.68rem;
    color: rgba(200, 169, 110, 0.9);
}

#map3d-focus .m3d-focus-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
}

#map3d-focus .m3d-focus-actions button {
    flex: 1 1 auto;
    padding: 8px 10px;
    border-radius: 8px;
    border: 1px solid rgba(184, 216, 240, 0.24);
    background: rgba(184, 216, 240, 0.08);
    color: inherit;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    min-height: 44px;
}

#map3d-focus .m3d-focus-go {
    background: rgba(200, 169, 110, 0.3);
    border-color: rgba(200, 169, 110, 0.85);
}

#map3d-focus .m3d-focus-go:disabled { opacity: 0.45; cursor: default; }

#map3d-focus .m3d-focus-progress { margin-top: 8px; }

#map3d-focus .m3d-focus-bar {
    height: 8px;
    border-radius: 999px;
    background: rgba(184, 216, 240, 0.16);
    overflow: hidden;
}

#map3d-focus .m3d-focus-bar i {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(200, 169, 110, 0.7), rgba(200, 169, 110, 1));
    transition: width 140ms linear;
}

#map3d-focus .m3d-focus-progress-text {
    margin-top: 8px;
    font-size: 0.74rem;
    color: rgba(245, 240, 235, 0.82);
}

#map3d-focus .m3d-focus-stop {
    margin-top: 8px;
    width: 100%;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid rgba(184, 216, 240, 0.24);
    background: rgba(184, 216, 240, 0.08);
    color: inherit;
    font: inherit;
    cursor: pointer;
    min-height: 44px;
}

/* ── the folded window ─────────────────────────────────────────────────────
 * Once the tiles are fetched and the decision is applied, the window folds
 * away — but its minimized form is NOT a pill on the map any more: it is one
 * entry in the shared bottom drawer of minimized windows
 * (.apm-dock / js/map-window-dock.js), alongside the APM panel and the LiDAR
 * Settings. Nothing of #map3d-focus paints while folded; only the host's
 * [hidden] beat still matters. */
#map3d-focus[hidden] { display: none; }
#map3d-focus.is-minimized { display: none; }

/* Crosshair while picking: the next tap is the centre of the LiDAR area. */
#detectlab-map.m3d-picking { cursor: crosshair; }
#detectlab-map.m3d-picking * { cursor: crosshair !important; }

@media (max-width: 720px) {
    #map3d-focus { padding: 10px 10px calc(10px + var(--map3d-safe-area-bottom, env(safe-area-inset-bottom, 0px))); }
    #map3d-focus .m3d-focus-scope-opt { min-height: 34px; font-size: 0.72rem; }

    #map3d-focus .m3d-focus-card {
        width: min(360px, calc(100% - 16px));
        max-height: min(76vh, 560px);
        padding: 10px 11px 12px;
    }
    #map3d-focus .m3d-focus-layers { max-height: 88px; }
}

/* The PWA map can extend below the visible viewport (--pwa-bleed).
 * Use the shell's navigation-bar clearance, not just the OS safe-area inset:
 * Android can report zero even while the phone's bottom bar covers the map.
 * Keep a 16px visual gap above that area for both the card and folded pill. */
body.is-pwa #map3d-focus {
    --m3d-focus-bottom-clearance: calc(16px + max(var(--pwa-bottom-controls-clearance, 44px), var(--map3d-safe-area-bottom, env(safe-area-inset-bottom, 0px))));
    padding-bottom: var(--m3d-focus-bottom-clearance);
}
body.is-pwa #map3d-focus .m3d-focus-card {
    max-height: min(76vh, 620px, calc(100% - 16px - var(--m3d-focus-bottom-clearance)));
}
