/*------------------------------------------------------------------*\
    LOCATION MAP — [location_map] shortcode
    Interactive Leaflet map with custom POI markers, style toggle
    (Mapa / Aerea) and category legend filters.

    Classnames are emitted by:
      - mu-plugins/site-core/templates/shortcodes/location-map.php
      - themes/apollotec-theme/assets/js/modules/location-map.js
        (divIcon markers, popups, state classes)

    Conventions: ITCSS + BEM, mobile-first (base = mobile, min-width
    queries for desktop refinement). Dark mode scoped under
    [data-theme="dark"] to mirror dark-mode.css.

    Leaflet emits its own classes (.leaflet-*) in the DOM. We scope
    every override under `.c-location-map .leaflet-*` so other Leaflet
    instances on the site (should any appear) stay untouched.
\*------------------------------------------------------------------*/


/*------------------------------------------------------------------*\
    1. COMPONENT TOKENS
    Local custom properties — kept on the wrapper so dark mode only
    needs to override these four-or-so values, never individual rules.
\*------------------------------------------------------------------*/

.c-location-map {
    /* Canvas / text */
    --c-location-map-bg:        var(--color-bg-white, #ffffff);
    --c-location-map-fg:        var(--color-text, #303030);

    /* Building home pin — strongly contrasting accent */
    --c-location-map-pin-bg:    var(--neutral-900, #0e0e0e);
    --c-location-map-pin-fg:    var(--neutral-0, #ffffff);

    /* POI markers — the per-category color now arrives via inline
     * `style="background-color:..."` from the JS divIcon and paints the
     * circle itself (the icon image rides on top). These tokens stay as
     * fallback for legacy markers / dark-mode tweaks. */
    --c-location-map-poi-bg:    var(--neutral-800, #1c1c1c);
    --c-location-map-poi-fg:    var(--neutral-0, #ffffff);

    /* Controls (toggle + legend) */
    --c-location-map-ctrl-bg:   var(--color-bg-white, #ffffff);
    --c-location-map-ctrl-fg:   var(--color-text, #303030);
    --c-location-map-accent:    var(--color-primary, #303030);

    /* Shadows / elevation */
    --c-location-map-shadow-sm: 0 2px 8px rgba(0, 0, 0, .18);
    --c-location-map-shadow-md: 0 4px 16px rgba(0, 0, 0, .20);
    --c-location-map-shadow-lg: 0 8px 24px rgba(0, 0, 0, .22);
}


/*------------------------------------------------------------------*\
    2. WRAPPER + CANVAS
\*------------------------------------------------------------------*/

.c-location-map {
    position: relative;
    width: 100%;
    /* Mobile (base): render the map as a landscape window so it reads
     * horizontal on phones instead of a full-height portrait. The height is a
     * fixed, DEFINITE value (465px) — `aspect-ratio` + `height:auto` collapses
     * to 0 here because the wrapper is
     * a flex item inside Elementor's (flex) container with only absolutely-
     * positioned children — that hid the map whenever no explicit height was
     * set in Elementor. Desktop (min-width: 1024px, section 11) restores the
     * per-instance height from the inline `--c-location-map-height` custom
     * property emitted by the shortcode (`style="--c-location-map-height: 100vh;"`).
     * That custom property is CRITICAL on desktop — without a height the
     * wrapper collapses to 0px and the map is invisible (the "mapa nao
     * aparece" bug from steps 12.5 / 12.7). */
    height: 465px;
    border-radius: 12px;
    overflow: hidden;
    /* Contain z-indices / blend modes inside the component so Leaflet's
     * internal stacking can never bleed into the surrounding page. */
    isolation: isolate;
    background: var(--c-location-map-bg);
    color: var(--c-location-map-fg);
}

.c-location-map__canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: var(--c-location-map-bg);
    cursor: grab;
}

.c-location-map__canvas:active {
    cursor: grabbing;
}

/* Keyboard focus ring on the canvas (it has tabindex="0"). */
.c-location-map__canvas:focus-visible {
    outline: 2px solid var(--c-location-map-accent);
    outline-offset: -2px;
}


/*------------------------------------------------------------------*\
    3. POI MARKERS
    Rendered by Leaflet's L.divIcon — the JS sets `iconSize: [36, 36]`
    so the wrapper size matches exactly.
\*------------------------------------------------------------------*/

.c-location-map__poi {
    width: 36px;
    height: 36px;
}

.c-location-map__poi-inner {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    border-radius: 50%;
    /* The POI/category colour paints the circle via the inline `--pin-color`
     * custom property from the JS divIcon (a custom property, not `background`
     * directly, so dark-mode CSS can flip it to white). The token is the
     * fallback when no inline value is present. */
    background: var(--pin-color, var(--c-location-map-poi-bg));
    color: var(--c-location-map-poi-fg);
    box-shadow: var(--c-location-map-shadow-sm);
    transition: transform .2s ease, box-shadow .2s ease, background .2s ease;
    cursor: pointer;
}

/* Hover/focus inverts the badge — light mode: white circle + #303030 symbol. */
.c-location-map__poi-inner:hover,
.c-location-map__poi:focus-within .c-location-map__poi-inner {
    transform: scale(1.12);
    box-shadow: var(--c-location-map-shadow-md);
    background: var(--neutral-0, #FFFFFF);
}
.c-location-map__poi-inner:hover .c-location-map__poi-symbol,
.c-location-map__poi:focus-within .c-location-map__poi-symbol {
    background-color: #303030;
}

/* POI icon symbol — the uploaded SVG used as a CSS mask so its colour is
 * theme-driven (light = white symbol; dark = #303030, see DARK MODE). Fixed
 * 22px so every POI icon renders at the same size inside the 36px circle. */
.c-location-map__poi-symbol {
    width: 22px;
    height: 22px;
    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;
    pointer-events: none;
    transition: background-color .2s ease;
}

/* Category filter hide — JS toggles `.is-hidden` on the marker DOM. */
.c-location-map__poi.is-hidden .c-location-map__poi-inner {
    opacity: 0;
    transform: scale(.5);
    pointer-events: none;
}


/*------------------------------------------------------------------*\
    4. HOME PIN (building)
    Larger and visually distinct so it always reads as "this is the
    building", never as just another POI. JS sets iconSize [44, 44].
\*------------------------------------------------------------------*/

.c-location-map__home {
    width: 44px;
    height: 44px;
}

.c-location-map__home-inner {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    border-radius: 50%;
    background: var(--c-location-map-pin-bg);
    color: var(--c-location-map-pin-fg);
    box-shadow: var(--c-location-map-shadow-md);
    /* Halo ring for contrast against any tile color. */
    border: 2px solid var(--c-location-map-bg);
}

.c-location-map__home-inner svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

/* Home icon image (Media Library upload). Same physical footprint as the
 * inline SVG fallback so the marker geometry never shifts based on whether
 * the editor uploaded a custom icon. */
.c-location-map__home-img {
    width: 24px;
    height: 24px;
    object-fit: contain;
    display: block;
    pointer-events: none;
}


/*------------------------------------------------------------------*\
    5. CATEGORY FILTER BAR
    Bottom-centered chip group. Each chip is a toggle button — JS flips
    aria-pressed + `.is-active` / `.is-inactive`. Replaces the legacy
    `__legend` floating card with a more discreet, single-row layout.
\*------------------------------------------------------------------*/

.c-location-map__filters {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    /* Above Leaflet's tile/marker panes (max ~700) but below its popups
     * (700+). 401 stays out of the way of zoom controls (1000). */
    z-index: 401;
    /* Hidden on mobile (base); shown from `min-width: 1024px` (mirrors the
     * aerial view — the chip bar is cramped over a small map). */
    display: none;
    flex-wrap: wrap;
    gap: 6px;
    max-width: calc(100% - 32px);
    justify-content: center;
}

.c-location-map__filter-chip {
    appearance: none;
    border: 1px solid rgba(0, 0, 0, .12);
    background: var(--c-location-map-ctrl-bg);
    color: var(--c-location-map-ctrl-fg);
    font: inherit;
    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-location-map-shadow-sm);
    /* Match the site-wide button language: a "presence" hover (lift + a
     * stronger shadow), never a colour/background change. See `.c-button`
     * in components/button.css ("hover de presenca (sem cor)"). */
    transition: transform .15s ease, box-shadow .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. */
.c-location-map__filter-chip:focus {
    background: var(--c-location-map-ctrl-bg);
    color: var(--c-location-map-ctrl-fg);
}

.c-location-map__filter-chip:hover {
    transform: translateY(-1px);
    box-shadow: var(--c-location-map-shadow-md);
}

.c-location-map__filter-chip:active {
    transform: translateY(0);
}

@media (prefers-reduced-motion: reduce) {
    .c-location-map__filter-chip:hover,
    .c-location-map__filter-chip:active {
        transform: none;
    }
}

/* Disabled-by-filter state — JS sets aria-pressed="false" + adds
 * .is-inactive when the user toggles the category off. */
.c-location-map__filter-chip[aria-pressed="false"],
.c-location-map__filter-chip.is-inactive {
    opacity: .4;
}

.c-location-map__filter-chip:focus-visible {
    outline: 2px solid var(--c-location-map-accent);
    outline-offset: 2px;
}

.c-location-map__filter-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
    display: inline-block;
}

.c-location-map__filter-label {
    font-weight: var(--font-medium, 500);
}


/*------------------------------------------------------------------*\
    6. CUSTOM POPUP (Leaflet override)
    The JS binds popups with className="c-location-map__popup", which
    Leaflet appends to its own `.leaflet-popup` wrapper. We mostly
    re-skin the inner wrapper + tip + close button.
\*------------------------------------------------------------------*/

.c-location-map .leaflet-popup-content-wrapper {
    background: var(--c-location-map-bg);
    color: var(--c-location-map-fg);
    border-radius: 10px;
    box-shadow: var(--c-location-map-shadow-lg);
    padding: 5px 0;
}

.c-location-map .leaflet-popup-content {
    margin: 14px 16px;
    line-height: var(--line-height-140, 1.4);
}

.c-location-map .leaflet-popup-tip {
    background: var(--c-location-map-bg);
    box-shadow: var(--c-location-map-shadow-sm);
}

/* `!important` here because Leaflet sets `color: #c3c3c3` inline on
 * the close button to match its default light skin; we need a token-
 * driven color to follow dark mode. */
.c-location-map .leaflet-popup-close-button {
    color: var(--c-location-map-fg) !important;
    opacity: .5;
    transition: opacity .15s ease;
}

.c-location-map .leaflet-popup-close-button:hover {
    opacity: 1;
}

.c-location-map__popup-body {
    /* Slot wrapper for our title + description. Leaflet centers the
     * popup horizontally; left-align our copy for readability. */
    text-align: left;
}

.c-location-map__popup-title {
    display: block;
    font-family: var(--font-primary);
    font-weight: var(--font-bold, 700);
    font-size: 0.8rem;
    margin-bottom: .25rem;
    text-align: center;
}

.c-location-map__popup-desc {
    font-size: .8125rem;
    margin: 0;
    color: var(--color-text-soft, #A2A2A2);
}

.leaflet-popup {
    margin-bottom: 39px;
}


/*------------------------------------------------------------------*\
    7. LEAFLET CONTROLS (zoom + attribution)
    Re-skinned to match the rest of the component instead of Leaflet's
    default blue-tinted controls.
\*------------------------------------------------------------------*/

.c-location-map .leaflet-control-zoom {
    border: 0;
    border-radius: 10px;
    box-shadow: var(--c-location-map-shadow-md);
    overflow: hidden;
}

.c-location-map .leaflet-control-zoom a {
    background: var(--c-location-map-ctrl-bg);
    color: var(--c-location-map-ctrl-fg);
    border: 0;
    transition: background .15s ease;
}

.c-location-map .leaflet-control-zoom a:hover {
    background: rgba(0, 0, 0, .06);
}

.c-location-map .leaflet-control-attribution {
    font-size: .625rem;
    background: rgba(255, 255, 255, .8);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}


/*------------------------------------------------------------------*\
    8. NOSCRIPT FALLBACK
\*------------------------------------------------------------------*/

.c-location-map__noscript {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 1rem;
    margin: 0;
    text-align: center;
    background: var(--c-location-map-bg);
    color: var(--c-location-map-fg);
    font-family: var(--font-secondary, 'Inter', sans-serif);
}


/*------------------------------------------------------------------*\
    9. DARK MODE OVERRIDES
    Scoped under [data-theme="dark"] to mirror the convention already
    used in dark-mode.css (e.g. `[data-theme="dark"] .rb-table-apts`).
\*------------------------------------------------------------------*/

[data-theme="dark"] .c-location-map {
    --c-location-map-bg:        var(--color-bg-surface, #141414);
    --c-location-map-fg:        var(--color-text, #D0D0D0);
    --c-location-map-pin-bg:    var(--neutral-0, #ffffff);
    --c-location-map-pin-fg:    var(--neutral-900, #0e0e0e);
    --c-location-map-poi-bg:    var(--neutral-50, #FAFAFA);
    --c-location-map-poi-fg:    var(--neutral-900, #0e0e0e);
    --c-location-map-ctrl-bg:   var(--neutral-850, #141414);
    --c-location-map-ctrl-fg:   var(--neutral-50, #FAFAFA);
}

/* POI badge — invert in dark mode: white circle, dark (#303030) symbol.
 * Overrides the inline --pin-color background so the marker reads on the dark
 * map tiles. Matches the aerial view treatment. */
[data-theme="dark"] .c-location-map__poi-inner {
    background: var(--neutral-0, #FFFFFF);
}
[data-theme="dark"] .c-location-map__poi-symbol {
    background-color: #303030;
}
/* Dark-mode hover: the inverse — circle back to the POI colour + white symbol. */
[data-theme="dark"] .c-location-map__poi-inner:hover,
[data-theme="dark"] .c-location-map__poi:focus-within .c-location-map__poi-inner {
    background: var(--pin-color, var(--c-location-map-poi-bg));
}
[data-theme="dark"] .c-location-map__poi-inner:hover .c-location-map__poi-symbol,
[data-theme="dark"] .c-location-map__poi:focus-within .c-location-map__poi-symbol {
    background-color: var(--neutral-0, #FFFFFF);
}

/* Popup stays light in dark mode — a white card reads clearly against the dark
 * map tiles (the token-driven dark popup would otherwise blend in). */
[data-theme="dark"] .c-location-map .leaflet-popup-content-wrapper,
[data-theme="dark"] .c-location-map .leaflet-popup-tip {
    background: var(--neutral-0, #FFFFFF);
    color: var(--neutral-900, #0E0E0E);
}
[data-theme="dark"] .c-location-map .leaflet-popup-close-button {
    color: var(--neutral-900, #0E0E0E) !important;
}

[data-theme="dark"] .c-location-map .leaflet-control-attribution {
    background: rgba(0, 0, 0, .55);
    color: rgba(255, 255, 255, .85);
}

[data-theme="dark"] .c-location-map .leaflet-control-attribution a {
    color: rgba(255, 255, 255, .85);
}

[data-theme="dark"] .c-location-map__filter-chip {
    border-color: rgba(255, 255, 255, .12);
}

[data-theme="dark"] .c-location-map .leaflet-control-zoom a:hover {
    background: rgba(255, 255, 255, .08);
}


/*------------------------------------------------------------------*\
    10. MOBILE-ONLY ADJUSTMENTS
    Base styles above already target mobile. The override below tweaks
    the floating controls on very narrow viewports: tighter inset so
    the filter bar doesn't crowd the edge, larger tap targets for the
    chips (Fitts's law on touch).
\*------------------------------------------------------------------*/

@media (max-width: 640px) {
    .c-location-map__filters {
        bottom: 8px;
        gap: 4px;
        max-width: calc(100% - 16px);
    }
    .c-location-map__filter-chip {
        font-size: .625rem;
        padding: .3125rem .625rem;
    }
}


/*------------------------------------------------------------------*\
    11. ERROR OVERLAY
    Shown when tile delivery fails (missing tilesUrl config, CORS
    rejection, 4xx/5xx from the tile origin). The overlay sits above
    the Leaflet canvas so the user sees a clear message instead of a
    blank pane. role="alert" is set in JS for assistive tech.
\*------------------------------------------------------------------*/

.c-location-map__error {
    position: absolute;
    inset: 0;
    z-index: 500; /* Above Leaflet panes (which max out at 400). */
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    background: var(--c-location-map-bg);
    color: var(--c-location-map-fg);
    text-align: center;
    pointer-events: auto;
}

.c-location-map__error-inner {
    max-width: 32rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.c-location-map__error-title {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: .01em;
}

.c-location-map__error-body {
    margin: 0;
    font-size: .875rem;
    line-height: 1.5;
    opacity: .85;
}

@media (min-width: 1024px) {
    /* Desktop: drop the mobile landscape window and restore the per-instance
       height from the shortcode's --c-location-map-height custom property. */
    .c-location-map {
        height: var(--c-location-map-height, 100vh);
        min-height: 360px;
    }

    .c-location-map__error-title { font-size: 1.125rem; }
    .c-location-map__error-body  { font-size: .9375rem; }

    /* Filter chips return on desktop (hidden on mobile in the base rule),
       forced onto a single row (no wrap, no width cap, chips keep their size). */
    .c-location-map__filters {
        display: inline-flex;
        flex-wrap: nowrap;
        max-width: none;
    }
    .c-location-map__filter-chip { flex-shrink: 0; }
}
