/*------------------------------------------------------------------*\
    AERIAL MAP — [location_map view="aerial"] shortcode
    Static aerial photograph with x/y-positioned POI pins and a
    building marker. No Leaflet — pure CSS over a single <img>.

    Classnames are emitted by:
      - mu-plugins/site-core/templates/shortcodes/location-map-aerial.php
      - themes/apollotec-theme/assets/js/modules/location-map-aerial.js
        (filter chip state, optional pin popups)

    Conventions: ITCSS + BEM, mobile-first (base = mobile, min-width
    queries for refinement). Dark mode scoped under [data-theme="dark"]
    to mirror the rest of the theme.
\*------------------------------------------------------------------*/


/*------------------------------------------------------------------*\
    1. COMPONENT TOKENS
\*------------------------------------------------------------------*/

.c-aerial-map {
    /* Fluid marker unit — keeps every marker (icon, dot, label, building)
     * proportional to the MAP width, so they look identical from mobile to
     * widescreen while their %-based anchors keep them on the same photo point.
     *
     * `--marker-ref` is the map width (px) at which 1 design-px renders 1:1.
     * Tune it if markers look too big/small on desktop (higher = smaller).
     * `--marker-u` = one design-pixel, scaled by the map width (via cqw on the
     * stage container), floored for mobile readability and capped on ultrawide.
     * Every marker size below is `calc(<design-px> * var(--marker-u))`. */
    --marker-ref: 1440;
    --marker-u:   clamp(0.8px, calc(100cqw / var(--marker-ref)), 1.3px);

    /* Canvas / text */
    --c-aerial-map-bg:           var(--color-bg-white, #ffffff);
    --c-aerial-map-fg:           var(--color-text, #303030);

    /* Pin dot + label pill — match the dark-on-photo look of
     * rb_real_map.png. The dot inherits the category color via the
     * inline `--pin-color` custom property set by the template. */
    --c-aerial-map-label-bg:     var(--neutral-900, #0e0e0e);
    --c-aerial-map-label-fg:     var(--neutral-0, #ffffff);
    --c-aerial-map-label-shadow: 0 2px 8px rgba(0, 0, 0, .35);

    /* Filter chip bar — same visual language as the Leaflet view */
    --c-aerial-map-ctrl-bg:      var(--color-bg-white, #ffffff);
    --c-aerial-map-ctrl-fg:      var(--color-text, #303030);
    --c-aerial-map-accent:       var(--color-primary, #303030);
    --c-aerial-map-ctrl-shadow:  0 2px 8px rgba(0, 0, 0, .18);

    /* Photo treatment — light B&W-leaning aesthetic to match the
     * cinematic look of the reference image. */
    --c-aerial-map-bg-filter:    saturate(.85) contrast(1.02);
}


/*------------------------------------------------------------------*\
    2. WRAPPER + STAGE
    `--c-aerial-map-aspect` is set per-instance on the wrapper by the
    template (e.g. "2400 / 1260"). Drives the stage's aspect-ratio so
    pin positions stay anchored to the photo as it scales.
\*------------------------------------------------------------------*/

.c-aerial-map {
    position: relative;
    width: 100%;
    color: var(--c-aerial-map-fg);

    /* Mobile (base): a fixed 50vh-tall map. The stage keeps the photo's aspect
     * ratio (height-driven, below), so it overflows horizontally and is clipped
     * here — the POIs stay anchored to the exact same photo points, only the
     * visible window narrows. `min-width: 1024px` restores the natural
     * full-width, aspect-driven map. */
    height: 50vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.c-aerial-map__stage {
    position: relative;
    /* Mobile (base): height-driven so the stage fills the 50vh parent while
     * keeping the photo's aspect-ratio (→ pins anchored). Width = height × ratio
     * and overflows the parent, which clips it. `min-width: 1024px` switches
     * back to width-led (width: 100%, height from aspect-ratio). */
    height: 100%;
    width: auto;
    flex: 0 0 auto;
    /* The stage MUST take the photo's own aspect ratio (set per-instance via
     * --c-aerial-map-aspect from the image dimensions). Box ratio == image
     * ratio, so `object-fit: cover` never crops and the pins' percentage
     * anchors (left/top: var(--x)/var(--y)) map to the exact same photo point.
     *
     * The trick: NEVER let width AND height both be fixed (that would force a
     * box ratio that tracks the viewport, cover would crop, and pins would
     * drift). Exactly one dimension is free so aspect-ratio derives the other:
     *   - mobile: height fixed (= 50vh parent), width auto → derived;
     *   - desktop (min-width: 1024px): width fixed (100%), height auto → derived.
     * Either way the ratio stays the photo's, keeping the pins resolution-
     * independent. */
    aspect-ratio: var(--c-aerial-map-aspect, 16 / 9);
    /* Overflow visible: the section (.c-aerial-map) clips the horizontally
     * overflowing stage on mobile, and popups (anchored to the stage) can rise
     * above the top pins without being cropped. Pins never leave 0–100%, so
     * nothing else escapes the stage box. */
    overflow: visible;
    background: var(--c-aerial-map-bg);
    /* Contain the absolutely-positioned pins inside the rounded stage. */
    isolation: isolate;
    /* Container for the marker `cqw` unit — `1cqw` = 1% of the stage width,
     * so markers scale with the map (not the viewport). Inline-size keeps the
     * aspect-ratio height intact. */
    container-type: inline-size;
}

.c-aerial-map__bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    filter: var(--c-aerial-map-bg-filter);
    /* Sit behind every overlay (pins, marker, future scrim). */
    z-index: 0;
}

/* Colour overlay (section 19) — the full-colour version of the same photo,
 * sitting just above the B&W __bg (z 0) and below the pins (z 2). Mobile:
 * shown first (opacity 1), then the JS fades it out on scroll, revealing the
 * B&W beneath. Inherits __bg's absolute/cover layout via the shared class; only
 * the filter (full colour), z-index and opacity differ. */
.c-aerial-map__bg--color {
    filter: none;          /* full colour (override the inherited B&W filter) */
    z-index: 1;
    opacity: 1;            /* colour shown first */
    transition: opacity 0.8s ease;
}

/* Once the section has been in view long enough, the JS adds `.is-colorfaded`
   to the wrapper (~3s) → smooth fade to the B&W photo beneath. */
.c-aerial-map.is-colorfaded .c-aerial-map__bg--color {
    opacity: 0;
}

/* Desktop: hover-driven colour ↔ B&W (replaces the mobile scroll/time fade).
   The section rests in FULL COLOUR; hovering it fades the colour overlay out
   to reveal the B&W photo beneath, and leaving fades it back to colour. The
   JS time-based `.is-colorfaded` is mobile-only, so it's neutralised here —
   only :hover drives the desktop effect. The 0.8s opacity transition is
   inherited from the base `.c-aerial-map__bg--color` rule. */
@media (min-width: 1024px) {
    .c-aerial-map__bg--color {
        display: block;
        opacity: 1;
    }
    .c-aerial-map.is-colorfaded .c-aerial-map__bg--color {
        opacity: 1;   /* ignore the mobile scroll/time fade on desktop */
    }
    .c-aerial-map:hover .c-aerial-map__bg--color {
        opacity: 0;   /* hover → reveal the B&W photo */
    }
}

/* Reduced motion: skip the effect — B&W straight away, no fade. */
@media (prefers-reduced-motion: reduce) {
    .c-aerial-map__bg--color {
        opacity: 0;
        transition: none;
    }
}


/*------------------------------------------------------------------*\
    3. BUILDING MARKER
    Just the project logo (no colored box), positioned by the `--x` /
    `--y` percentages set inline by the template. Small on mobile, grows
    on larger viewports — clamp keeps it legible without dominating the
    photo. A drop-shadow keeps it readable over the image.
\*------------------------------------------------------------------*/

.c-aerial-map__building {
    position: absolute;
    left: var(--x, 50%);
    top: var(--y, 50%);
    /* Centre the marker on its (x, y) anchor — same anchoring as the POI pins,
     * so it stays fixed on the same photo point across resolutions. */
    transform: translate(-50%, -50%);
    z-index: 3;
    /* Larger than the POI icon (40u) so the building reads as the hero anchor. */
    width: calc(65 * var(--marker-u));
    aspect-ratio: 1;
    display: grid;
    place-items: center;
    pointer-events: none;
}

/* Clickable variant — the marker becomes a <button> when a title is set.
   Re-enable interaction (the base rule disables it) and strip native chrome. */
.c-aerial-map__building--button {
    appearance: none;
    border: 0;
    background: transparent;
    font: inherit;
    color: inherit;
    pointer-events: auto;
    cursor: pointer;
}

.c-aerial-map__building-logo {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, .45));
}

/* Subtle affordance that the building marker is interactive. */
.c-aerial-map__building--button:hover .c-aerial-map__building-logo,
.c-aerial-map__building--button:focus-visible .c-aerial-map__building-logo {
    transform: scale(1.06);
    transition: transform .2s ease;
}


/*------------------------------------------------------------------*\
    4. POI PIN (icon or dot + label)
    The POI's uploaded icon — or a small dark dot fallback when no icon —
    with a white label box attached to the right. Every size uses
    `--marker-u`, so the whole marker scales with the map across devices
    while the %-based anchor keeps it on the same photo point.
\*------------------------------------------------------------------*/

.c-aerial-map__pin {
    /* Reset the native <button> chrome — we only want the click target. */
    appearance: none;
    border: 0;
    background: transparent;
    padding: 0;
    margin: 0;
    font: inherit;
    color: inherit;
    cursor: pointer;

    /* Anchor on the (x, y) coordinate; the inner layout flows from there. */
    position: absolute;
    left: var(--x, 50%);
    top: var(--y, 50%);
    transform: translate(-50%, -50%);
    z-index: 2;

    display: inline-flex;
    align-items: center;
    gap: calc(6 * var(--marker-u));
    /* The label visually attaches to the dot; the click hit area covers both. */
}

.c-aerial-map__pin-dot {
    width: calc(12 * var(--marker-u));
    height: calc(12 * var(--marker-u));
    border-radius: 50%;
    background: var(--pin-color, var(--c-aerial-map-label-bg));
    /* Subtle outer ring so the dot reads against any photo color. */
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .9), 0 2px 6px rgba(0, 0, 0, .25);
    flex-shrink: 0;
    transition: transform .2s ease;
}

/* Icon badge — a coloured circle (the POI / category colour, set inline via
 * --pin-color) behind the symbol. Light mode: dark backoffice colour + white
 * symbol. Dark mode: white badge + #303030 symbol (see DARK MODE section).
 *
 * Phase 1: applied to the aerial-view POIs only. The same badge treatment is
 * planned for every POI once validated (see IMPLEMENTATION-PLAN §17). */
.c-aerial-map__pin-icon {
    width: calc(40 * var(--marker-u));
    height: calc(40 * var(--marker-u));
    border-radius: 50%;
    background: var(--pin-color, var(--c-aerial-map-label-bg));
    display: grid;
    place-items: center;
    flex-shrink: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .25);
    transition: transform .2s ease, background .2s ease;
}

/* The uploaded SVG is used as a CSS mask, so the symbol's colour is driven by
 * `background-color` (theme-controlled) instead of the file's own colour. The
 * mask URL comes from the inline --pin-icon custom property (template). */
.c-aerial-map__pin-symbol {
    /* Fixed, uniform square so every POI icon renders at the same size, no
     * matter the source SVG's own width/height. `contain` keeps each icon's
     * aspect ratio inside that square. (For pixel-identical sizing the source
     * SVGs should share a viewBox / consistent internal padding.) */
    width: calc(22 * var(--marker-u));
    height: calc(22 * var(--marker-u));
    background-color: var(--pin-symbol, #FFFFFF);   /* light mode: white symbol */
    -webkit-mask: var(--pin-icon) center / contain no-repeat;
            mask: var(--pin-icon) center / contain no-repeat;
    transition: background-color .2s ease;
}

.c-aerial-map__pin-label {
    /* Fixed (but map-scaled) width so the title wraps to ~2 lines (the pin is
     * inline-flex, so a percentage width has no fixed reference and the text
     * would stay on one line). box-sizing keeps the width inclusive of padding.
     * All sizes use --marker-u so the label scales with the map. */
    box-sizing: border-box;
    width: calc(127 * var(--marker-u));
    padding: calc(21 * var(--marker-u)) calc(10 * var(--marker-u));
    background: #ffffff;
    color: var(--color-text, #303030);
    font-family: var(--font-secondary);
    font-weight: 500;
    font-size: calc(11.8 * var(--marker-u));
    letter-spacing: calc(1.65 * var(--marker-u));
    line-height: calc(17 * var(--marker-u));
    text-transform: uppercase;
    text-align: center;
    box-shadow: var(--c-aerial-map-label-shadow);
    flex-shrink: 0;
    /* Lift the label slightly above the POI icon/anchor. */
    transform: translateY(calc(-12 * var(--marker-u)));
}


.c-aerial-map__pin:hover .c-aerial-map__pin-dot,
.c-aerial-map__pin:hover .c-aerial-map__pin-icon,
.c-aerial-map__pin:focus-visible .c-aerial-map__pin-dot,
.c-aerial-map__pin:focus-visible .c-aerial-map__pin-icon {
    transform: scale(1.1);
}

/* Hover/focus inverts the badge — light mode: white circle + #303030 symbol. */
.c-aerial-map__pin:hover .c-aerial-map__pin-icon,
.c-aerial-map__pin:focus-visible .c-aerial-map__pin-icon {
    background: var(--neutral-0, #FFFFFF);
}
.c-aerial-map__pin:hover .c-aerial-map__pin-symbol,
.c-aerial-map__pin:focus-visible .c-aerial-map__pin-symbol {
    background-color: #303030;
}

/* Dark mode: the inverse — circle back to the POI colour + white symbol. */
[data-theme="dark"] .c-aerial-map__pin:hover .c-aerial-map__pin-icon,
[data-theme="dark"] .c-aerial-map__pin:focus-visible .c-aerial-map__pin-icon {
    background: var(--pin-color, var(--c-aerial-map-label-bg));
}
[data-theme="dark"] .c-aerial-map__pin:hover .c-aerial-map__pin-symbol,
[data-theme="dark"] .c-aerial-map__pin:focus-visible .c-aerial-map__pin-symbol {
    background-color: var(--neutral-0, #FFFFFF);
}

.c-aerial-map__pin:focus-visible {
    outline: none;
}

.c-aerial-map__pin:focus-visible .c-aerial-map__pin-label {
    outline: 2px solid var(--c-aerial-map-accent);
    outline-offset: 2px;
}

/* Category filter hide — JS toggles `.is-hidden` on the pin. */
.c-aerial-map__pin.is-hidden {
    opacity: 0;
    transform: translate(-50%, -50%) scale(.5);
    pointer-events: none;
    transition: opacity .2s ease, transform .2s ease;
}


/*------------------------------------------------------------------*\
    5. POPUP (optional — shown on pin click when POI has description)
    Built lazily by the JS module. Positions itself just above the
    pin via inline top/left + a translate to centre on the X anchor.
\*------------------------------------------------------------------*/

.c-aerial-map__popup {
    /* Anchored at the pin's (x, y) centre by the JS (inline left/top). The
     * transform lifts the whole card above the pin: -100% of its own height
     * plus a gap that clears the POI icon (which is `40 * --marker-u` tall and
     * centred on the anchor, so its top sits `20 * --marker-u` above it). The
     * down-pointing tail then bridges the remaining space down to the pin. */
    --popup-gap: calc(20 * var(--marker-u) + 12px);

    position: absolute;
    z-index: 5;
    transform: translate(-50%, calc(-100% - var(--popup-gap)));
    min-width: 11rem;
    max-width: 18rem;
    width: max-content;
    padding: .7rem 1.25rem;
    background: var(--c-aerial-map-bg);
    color: var(--c-aerial-map-fg);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
    pointer-events: auto;
}

/* Down-pointing tail centred under the card — mirrors the Leaflet popup tip,
 * so the card clearly reads as belonging to the pin below it. */
.c-aerial-map__popup::after {
    content: "";
    position: absolute;
    left: 50%;
    bottom: -7px;
    transform: translateX(-50%);
    width: 0;
    height: 0;
    border: 7px solid transparent;
    border-bottom: 0;
    border-top-color: var(--c-aerial-map-bg);
}

.c-aerial-map__popup-title {
    display: block;
    font-family: var(--font-primary);
    font-weight: var(--font-bold, 700);
    font-size: .8rem;
    line-height: var(--line-height-140, 1.4);
    text-align: center;
    /* Room for the absolute close button so a long title never runs under it. */
    padding: 0 .5rem;
    margin: 0;
}

.c-aerial-map__popup-desc {
    margin: .25rem 0 0;
    font-size: .8125rem;
    line-height: var(--line-height-140, 1.4);
    color: var(--color-text-soft, #A2A2A2);
    text-align: center;
}

.c-aerial-map__popup-close {
    position: absolute;
    top: 6px;
    right: 8px;
    appearance: none;
    border: 0;
    background: transparent;
    width: 18px;
    height: 18px;
    padding: 0;
    color: inherit;
    opacity: .5;
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
    transition: opacity .15s ease;
}

.c-aerial-map__popup-close:hover {
    opacity: 1;
}


/*------------------------------------------------------------------*\
    6. FILTER CHIPS (bottom-centered)
    Same visual language as the Leaflet view's filter bar — kept as
    a separate set of classes so each component can evolve without
    coupling.
\*------------------------------------------------------------------*/

.c-aerial-map__filters {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    /* Hidden on mobile (base); shown from `min-width: 1024px`. */
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    max-width: calc(100% - 32px);
    justify-content: center;
}

.c-aerial-map__filter-chip {
    appearance: none;
    border: 1px solid rgba(0, 0, 0, .12);
    background: var(--c-aerial-map-ctrl-bg);
    color: var(--c-aerial-map-ctrl-fg);
    font-family: var(--font-secondary, 'Inter', sans-serif);
    font-size: .6875rem;
    font-weight: var(--font-semibold, 600);
    letter-spacing: .06em;
    text-transform: uppercase;
    padding: .375rem .75rem;
    border-radius: 999px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: .375rem;
    box-shadow: var(--c-aerial-map-ctrl-shadow);
    /* Keep the site button language's lift, but the visibility on hover comes
     * from a solid brand-green fill (white text): over the B&W aerial photo a
     * colourless hover (`.c-button`'s lift-only) is invisible against both the
     * light and dark areas. Green matches the category dots and the site accent
     * (--color-primary). The old `rgba(0,0,0,.04)` just muddied the pill. */
    transition: transform .15s ease, box-shadow .15s ease,
                background .15s ease, color .15s ease, opacity .15s ease;
}

/* reset.css forces `button:focus { background: transparent; color: inherit }`
 * (specificity 0,1,1), which beats the chip's base background (0,1,0) — so a
 * focused (just-clicked) chip would vanish. Re-assert the chip's own colours at
 * 0,2,0 to win. Hover (below, also 0,2,0 and later in source) still takes over. */
.c-aerial-map__filter-chip:focus {
    background: var(--c-aerial-map-ctrl-bg);
    color: var(--c-aerial-map-ctrl-fg);
}

.c-aerial-map__filter-chip:hover {
    transform: translateY(-1px);
    background: var(--c-aerial-map-accent);
    color: var(--neutral-0, #ffffff);
    box-shadow: 0 6px 16px rgba(0, 0, 0, .28);
}

/* Keep the category dot legible once the pill turns green. */
.c-aerial-map__filter-chip:hover .c-aerial-map__filter-dot {
    box-shadow: 0 0 0 1.5px rgba(255, 255, 255, .9);
}

.c-aerial-map__filter-chip:active {
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .c-aerial-map__filter-chip:hover,
    .c-aerial-map__filter-chip:active {
        transform: none;
    }
}

.c-aerial-map__filter-chip[aria-pressed="false"],
.c-aerial-map__filter-chip.is-inactive {
    opacity: .4;
}

.c-aerial-map__filter-chip:focus-visible {
    outline: 2px solid var(--c-aerial-map-accent);
    outline-offset: 2px;
}

.c-aerial-map__filter-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.c-aerial-map__filter-label {
    font-weight: var(--font-medium, 500);
}


/*------------------------------------------------------------------*\
    7. RESPONSIVE
    Markers scale with the map via `--marker-u` (a container-query unit
    on the stage), so there are no per-breakpoint marker overrides: labels
    stay visible and proportional from mobile to widescreen.

    The only breakpoint: mobile (base) renders a fixed 50vh map with the
    filter chips hidden and the stage height-driven (clipped horizontally
    by the section). From `min-width: 1024px` the map returns to its
    natural full-width, aspect-ratio-driven height with the chips visible.
    Mobile-first by construction (no max-width queries).
\*------------------------------------------------------------------*/

@media (min-width: 1024px) {
    /* Natural full-width map: no fixed height, the stage's aspect-ratio drives
     * the height again, and the section no longer needs to clip/centre. */
    .c-aerial-map {
        height: auto;
        overflow: visible;
        display: block;
    }

    .c-aerial-map__stage {
        width: 100%;
        height: auto;
    }

    /* Filter chips return on desktop. */
    .c-aerial-map__filters {
        display: inline-flex;
    }
}


/*------------------------------------------------------------------*\
    8. DARK MODE
\*------------------------------------------------------------------*/

[data-theme="dark"] .c-aerial-map {
    --c-aerial-map-bg:           var(--color-bg-surface, #141414);
    --c-aerial-map-fg:           var(--color-text, #D0D0D0);
    --c-aerial-map-label-bg:     var(--neutral-0, #ffffff);
    --c-aerial-map-label-fg:     var(--neutral-900, #0e0e0e);
    --c-aerial-map-ctrl-bg:      var(--neutral-850, #141414);
    --c-aerial-map-ctrl-fg:      var(--neutral-50, #FAFAFA);
    /* Slightly dim the photo so the inverted pins keep their contrast. */
    --c-aerial-map-bg-filter:    saturate(.8) brightness(.85) contrast(1.05);
}

[data-theme="dark"] .c-aerial-map__pin-dot {
    box-shadow: 0 0 0 2px rgba(0, 0, 0, .8), 0 2px 6px rgba(0, 0, 0, .45);
}

/* POI icon badge — invert in dark mode: white badge, dark (#303030) symbol.
 * Overrides the inline --pin-color background so the badge reads on the dark
 * photo. Phase 1: aerial view only (see IMPLEMENTATION-PLAN §17). */
[data-theme="dark"] .c-aerial-map__pin-icon {
    background: var(--neutral-0, #FFFFFF);
}
[data-theme="dark"] .c-aerial-map__pin-symbol {
    background-color: #303030;
}

[data-theme="dark"] .c-aerial-map__filter-chip {
    border-color: rgba(255, 255, 255, .12);
}
