/*------------------------------------------------------------------*\
    BUILDING MAP — [building_map] shortcode
    SVG polygon overlay over a background image. Step 8.1: static render.
    Click handlers + tooltip live in assets/js/modules/building-map.js
    (steps 8.2 / 8.3).
\*------------------------------------------------------------------*/

.bm-viewer {
    position: relative;
    display: block;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    overflow: hidden;
    border-radius: 8px;
    /* Only block browser scroll when zoom/pan is actually enabled — otherwise
       the viewer swallows wheel/touch and the page feels "stuck". */
    touch-action: auto;
}
.bm-viewer:not(.is-zoom-disabled) {
    touch-action: none; /* pinch/drag pan without browser scroll interference */
}
.bm-viewer.is-zoomed {
    cursor: grab;
}
.bm-viewer.is-panning {
    cursor: grabbing;
}

/* Transform target — Panzoom manages the transform/origin on this element. */
.bm-zoom {
    position: relative;
    width: 100%;
    will-change: transform;
    /* Cria um stacking context isolado contendo a imagem + SVG. Necessario
     * para o `mix-blend-mode` dos poligonos blendar com `.bm-image` mas nao
     * com o resto da pagina. */
    isolation: isolate;
}

.bm-image {
    display: block;
    width: 100%;
    height: auto;
    user-select: none;
    -webkit-user-drag: none;
    pointer-events: none; /* let polygon clicks pass through when not zoomed */
}

.bm-overlay {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: visible;
}

/* ── Zoom controls (top-right of the viewer) ── */
.bm-viewer .bm-controls {
    position: absolute;
    top: 16px;
    right: 0px;
    z-index: 20;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin: 0;
    padding: 0;
    pointer-events: auto;
}

/* Panzoom desativado: esconde a toolbar (markup mantem-se p/ reactivacao). */
.bm-viewer.is-zoom-disabled .bm-controls {
    display: none;
}
.bm-viewer .bm-ctrl {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    margin: 0;
    padding: 0;
    background: rgba(20, 20, 20, 0.88);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 6px;
    font-family: inherit;
    font-size: 20px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    user-select: none;
}
.bm-viewer .bm-ctrl:hover,
.bm-viewer .bm-ctrl:focus-visible {
    background: var(--color-primary, #2C3D31);
    border-color: var(--color-primary, #2C3D31);
    outline: none;
    transform: translateY(-1px);
}
.bm-viewer .bm-ctrl:active {
    transform: translateY(0);
}
.bm-viewer .bm-ctrl--reset {
    font-size: 18px;
}

/* ── Intro animation: image first, then the zones (JS-gated) ──
 * `.bm-anim` is added by building-map.js only when GSAP is available;
 * without JS/GSAP nothing is hidden. Reduced-motion → no fade. */
.bm-viewer.bm-anim .bm-image,
.bm-viewer.bm-anim .bm-polygon {
    opacity: 0;
}
@media (prefers-reduced-motion: reduce) {
    .bm-viewer.bm-anim .bm-image,
    .bm-viewer.bm-anim .bm-polygon {
        opacity: 1;
    }
}

/* ── Polygons ──
 * Camada base com tint suave em `multiply` para o utilizador perceber que
 * cada poligono e um apartamento (sem tapar a textura do edificio). Hover
 * preenche com a cor primary #2C3D31. Sem pulse, sem spotlight. */
.bm-polygon {
    pointer-events: all;
    cursor: pointer;
    transition: fill 0.2s ease, fill-opacity 0.2s ease;
    outline: none;
}

/* Multiply tinta o edificio em vez de tapar — so nas fracoes atribuidas. */
.bm-polygon[data-status] {
    mix-blend-mode: multiply;
    stroke: #ffffff !important;
    stroke-opacity: 0.2;
    /* Pixel-locked stroke: without `vector-effect`, Firefox over-thickens
     * the stroke when combined with `mix-blend-mode` + `paint-order` because
     * it computes the stroke in viewBox user units (7840 wide) before
     * scaling. Chrome happens to compensate; FF does not. Locking to screen
     * pixels makes both browsers render the same line weight. */
    vector-effect: non-scaling-stroke;
    stroke-width: 2 !important;
    stroke-linejoin: round;
    paint-order: stroke fill;
}

/* Tint base por estado — `fill` em CSS sobrepoe-se ao inline do SVG. */
/* Status tints — distinct hues so available / reserved / sold are
   clearly told apart on the model. */
.bm-polygon[data-status="available"] { fill: #303030; fill-opacity: 0.55; }
.bm-polygon[data-status="reserved"]  { fill: #DFBB61; fill-opacity: 0.65; }
.bm-polygon[data-status="sold"]      { fill: #A49869; fill-opacity: 0.7; }

/* Hover/focus/row-active: keep the apartment's status colour, just
   intensify it (stronger opacity) so the highlight matches the state. */
.bm-polygon.is-assigned[data-status="available"]:hover,
.bm-polygon.is-assigned[data-status="available"]:focus-visible,
.bm-polygon.is-assigned[data-status="available"].is-active {
    fill: #303030 !important;
    fill-opacity: 0.75 !important;
}
.bm-polygon.is-assigned[data-status="reserved"]:hover,
.bm-polygon.is-assigned[data-status="reserved"]:focus-visible,
.bm-polygon.is-assigned[data-status="reserved"].is-active {
    fill: #DFBB61 !important;
    fill-opacity: 0.85 !important;
}
.bm-polygon.is-assigned[data-status="sold"]:hover,
.bm-polygon.is-assigned[data-status="sold"]:focus-visible,
.bm-polygon.is-assigned[data-status="sold"].is-active {
    fill: #A49869 !important;
    fill-opacity: 0.60 !important;
}

.bm-polygon:focus-visible {
    stroke-width: 3 !important;
}

/* Unassigned: invisivel em repouso, mas com hover apelativo (cinza-azulado)
 * para sinalizar que existe uma area clicavel mesmo sem fraccao associada. */
.bm-polygon.is-unassigned {
    cursor: help;
    fill: transparent;
    stroke: transparent;
    transition: fill 0.2s ease, fill-opacity 0.2s ease, stroke 0.2s ease, stroke-opacity 0.2s ease;
}
.bm-polygon.is-unassigned:hover,
.bm-polygon.is-unassigned:focus-visible {
    fill: #8B9AA3;
    fill-opacity: 0.4;
    stroke: #ffffff;
    stroke-opacity: 0.55;
    vector-effect: non-scaling-stroke;
    stroke-width: 2;
    stroke-linejoin: round;
    paint-order: stroke fill;
    mix-blend-mode: multiply;
}

/* ── Labels ── */
.bm-label {
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}
.bm-viewer.show-labels .bm-label,
.bm-polygon:hover + .bm-label {
    opacity: 1;
}

/* ── Tooltip ── */
.bm-tooltip {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9999;
    min-width: 220px;
    max-width: 320px;
    padding: 0.875rem 1rem;
    background: #1a1a1a;
    color: #f5f5f5;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-left: 3px solid var(--color-primary, #2C3D31);
    border-radius: 8px;
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
    font-family: var(--font-secondary, "DM Sans", sans-serif);
    font-size: 0.8125rem;
    line-height: 1.5;
    pointer-events: none;
    opacity: 0;
    visibility: hidden;
    transform: translateY(4px);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s linear 0.15s;
}
.bm-tooltip.is-visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
    transition: opacity 0.15s ease, transform 0.15s ease, visibility 0s;
}

/* Touch devices: a tap would pin this tooltip over the map (there is no hover
   to dismiss it). Hide it on touch — the tap still scrolls to the apartment
   row. Desktop / mouse keeps the hover tooltip. */
@media (hover: none) and (pointer: coarse) {
    .bm-tooltip {
        display: none;
    }
}

.bm-tooltip__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.625rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.bm-tooltip__unit {
    font-family: var(--font-primary, 'Syne', sans-serif);
    font-weight: 700;
    font-size: 1.125rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: #ffffff;
}

.bm-tooltip__pill {
    display: inline-block;
    padding: 0.25rem 0.625rem;
    border-radius: 999px;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    line-height: 1.2;
    color: #ffffff;
    white-space: nowrap;
}
.bm-tooltip__pill--available {
    background: #D9D9D9;
    color: #303030;          /* light pill → dark text for contrast */
}
.bm-tooltip__pill--reserved {
    background: #DFBB61;
}
.bm-tooltip__pill--sold {
    background: #A49869;
}

.bm-tooltip__list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.25rem 0.875rem;
    margin: 0;
}
.bm-tooltip__list dt {
    color: rgba(255, 255, 255, 0.55);
    font-size: 0.6875rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
    align-self: center;
}
.bm-tooltip__list dd {
    margin: 0;
    color: #f5f5f5;
    font-size: 0.8125rem;
}
.bm-tooltip__list dd strong {
    font-weight: 600;
    color: #ffffff;
}

.bm-tooltip__empty {
    color: rgba(255, 255, 255, 0.6);
    font-style: italic;
    text-align: center;
}

/* ── Dark mode: invert tooltip to a light card ──
 * In dark mode the page background is already dark, so a dark tooltip
 * blends into it. Flipping to a light card keeps it floating above the
 * page. Status pill backgrounds are client-chosen colours (kept intact);
 * only their text colour switches to dark so they read on the light card. */
:where([data-theme="dark"]) .bm-tooltip {
    background: #f5f5f5;
    color: #1a1a1a;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-left: 3px solid var(--color-primary, #2C3D31);
    box-shadow: 0 20px 48px rgba(0, 0, 0, 0.65);
}
:where([data-theme="dark"]) .bm-tooltip__head {
    border-bottom-color: rgba(0, 0, 0, 0.10);
}
:where([data-theme="dark"]) .bm-tooltip__unit         { color: #1a1a1a; }
:where([data-theme="dark"]) .bm-tooltip__list dt      { color: rgba(0, 0, 0, 0.55); }
:where([data-theme="dark"]) .bm-tooltip__list dd      { color: #1a1a1a; }
:where([data-theme="dark"]) .bm-tooltip__list dd strong { color: #000000; }
:where([data-theme="dark"]) .bm-tooltip__empty        { color: rgba(0, 0, 0, 0.6); }
/* Pills: bg stays (client colour), text flips for contrast on light card.
 * `--available` already uses dark text in light mode — no change needed. */
:where([data-theme="dark"]) .bm-tooltip__pill--reserved { color: #2a2207; }
:where([data-theme="dark"]) .bm-tooltip__pill--sold     { color: #2f2a1c; }

/* Legend */
.bm-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    justify-content: center;
    margin: 1.25rem 0 0;
    padding: 0;
    list-style: none;
    font-family: var(--font-secondary, "DM Sans", sans-serif);
    font-size: 0.8125rem;
    color: var(--color-text, #d0d0d0);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}
.bm-legend__item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}
.bm-legend__dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

/* ── Empty state ── */
.bm-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted, rgba(255, 255, 255, 0.5));
    font-family: var(--font-secondary, "DM Sans", sans-serif);
}

/* ── Mobile: larger stroke for tap targets ── */
@media (max-width: 768px) {
    .bm-polygon {
        vector-effect: non-scaling-stroke;
        stroke-width: 2;
    }
    .bm-polygon:hover,
    .bm-polygon:focus-visible {
        stroke-width: 3.5 !important;
    }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .bm-polygon,
    .bm-label {
        transition: none;
    }
}
