/* =====================================================================
 * components/country-map.css — Leaflet map, custom pin, popup, and the
 * branches-section bridge note, shared by the country pages
 * (/programs/indonesia, /programs/malaysia).
 *
 * Consolidated from the byte-identical (modulo namespace) blocks that
 * lived in pages/indonesia.css (.indonesia-map / .branch-pin /
 * .branch-popup*) and pages/malaysia.css (.malaysia-map / .malaysia-pin
 * / .malaysia-popup*).
 *
 * LOAD-ORDER NOTE (important):
 * ---------------------------
 * Component CSS loads in the layout's "components" block, which is
 * BEFORE the per-page vendor sheet (vendor/leaflet.css loads via
 * $page_vendor_css, after components). That is the opposite of where
 * these overrides used to live (page CSS, which loads AFTER leaflet).
 * So any rule here that overrides one of Leaflet's OWN classes
 * (.leaflet-container, .leaflet-popup-content*) cannot rely on source
 * order to win — it must win on specificity instead. Those overrides
 * are therefore scoped under .country-map (the map element; popups
 * render inside it), giving (0,2,0) which beats Leaflet's bare (0,1,0)
 * regardless of load order. Rules targeting OUR OWN classes
 * (.country-pin, .country-popup*) need no such scoping — Leaflet never
 * styles them.
 *
 * Page-specific residue (Malaysia's popup min-width floor and tighter
 * region line-height) stays in pages/malaysia.css, which still loads
 * last and so keeps winning for those two declarations.
 *
 * No hex literals — tokens + color-mix only (vendor/leaflet.css keeps
 * its own hex literals, an accepted audit exception).
 * ===================================================================== */

/* ---------------------------------------------------------------
 * 1. Map container. Responsive height via --country-map-h.
 * --------------------------------------------------------------- */
.country-map {
    --country-map-h: 21.25rem;          /* 340px — mobile */
    width: 100%;
    height: var(--country-map-h);
    border-radius: var(--radius-md);
    border: 1px solid var(--color-border);
    /* Leaflet pans are tile-based; clip overflow so the rounded corners
     * aren't blown out by tiles overlapping the radius. */
    overflow: hidden;
    /* Own stacking context: traps Leaflet's internal z-indexes (panes
     * 400–700, zoom control up to 1000) inside the map box so they can
     * never paint over the sticky navbar as the map scrolls up beneath
     * it. overflow:hidden clips but does not isolate; this does. */
    isolation: isolate;
    /* Pre-init reservation so the page doesn't reflow when Leaflet
     * sizes itself. */
    min-height: var(--country-map-h);
}

@media (min-width: 768px) {
    .country-map { --country-map-h: 25rem; }     /* 400px tablet */
}
@media (min-width: 1024px) {
    .country-map { --country-map-h: 31.25rem; }  /* 500px desktop */
}

/* Pre-tile background. Leaflet paints `.leaflet-container` a light grey
 * by default; the map element carries BOTH .country-map and (after
 * init) .leaflet-container, so .country-map.leaflet-container (0,2,0)
 * beats Leaflet's bare (0,1,0) without depending on load order. */
.country-map.leaflet-container {
    background-color: var(--color-surface);
}

/* ---------------------------------------------------------------
 * 2. Custom pin (L.divIcon). JS injects:
 *      <span class="country-pin">…inline svg…</span>
 *    The container claims its anchor box; the SVG fills it. Colour
 *    flows through currentColor → color: var(--color-accent), so the
 *    teardrop fill picks up the brand turquoise without a hex literal.
 *    position: relative is harmless on the single-variant pin and
 *    leaves room for a future ::after ring if an HQ variant returns.
 * --------------------------------------------------------------- */
.country-pin {
    display: block;
    position: relative;
    width: 2rem;             /* 32px — matches the divIcon size baseline */
    height: 2.5rem;          /* 40px — pin tip ends here */
    color: var(--color-accent);
    transform-origin: 50% 100%;   /* scale from the pin tip */
    transition: transform var(--transition-fast);
    filter: drop-shadow(0 1px 2px color-mix(in srgb, var(--color-ink) 35%, transparent));
}

.country-pin svg {
    width: 100%;
    height: 100%;
    display: block;
}

.country-pin:hover {
    transform: scale(1.08);
}

@media (prefers-reduced-motion: reduce) {
    .country-pin { transition: none; }
    .country-pin:hover { transform: none; }
}

/* ---------------------------------------------------------------
 * 3. Leaflet popup chrome overrides. Scoped under .country-map so they
 *    beat Leaflet's bare popup rules on specificity (see load-order
 *    note above).
 * --------------------------------------------------------------- */
.country-map .leaflet-popup-content-wrapper {
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
}

.country-map .leaflet-popup-content {
    margin: 0;                     /* we own padding inside .country-popup */
    width: auto !important;        /* override Leaflet's inline width calc */
}

/* ---------------------------------------------------------------
 * 4. Popup body (our own classes — no Leaflet specificity contest).
 * --------------------------------------------------------------- */
.country-popup {
    display: flex;
    flex-direction: column;
    gap: var(--space-1);
    padding: var(--space-4) var(--space-5);
    /* Three short lines (name, region, gmaps link) — narrow cap keeps
     * popups from running past the map container edges at the default
     * zoom. */
    max-width: 13rem;
    font-size: var(--fs-sm);
    line-height: var(--lh-normal);
    color: var(--color-text);
}

.country-popup__name {
    font-size: var(--fs-md);
    font-weight: var(--fw-semibold);
    color: var(--color-text);
    line-height: var(--lh-tight);
}

.country-popup__region {
    font-size: var(--fs-sm);
    color: var(--color-text-muted);
}

.country-popup__link {
    margin-top: var(--space-2);
    color: var(--color-primary);
    font-weight: var(--fw-semibold);
    text-decoration: none;
    border-bottom: 1px solid color-mix(in srgb, var(--color-primary) 30%, transparent);
    align-self: flex-start;
}
.country-popup__link:hover {
    color: var(--color-primary-hover);
    border-bottom-color: var(--color-primary-hover);
}

/* ---------------------------------------------------------------
 * 5. Branches-section bridge note — the quiet single line under the
 *    photo-card grid. Not map-related, but it's the country branches
 *    section's last shared piece, and the card grid itself lives in the
 *    off-limits branch-card.css, so it sits here with the section's
 *    other shared styling. Consolidated from the byte-identical
 *    .indonesia-branches__bridge-note / .malaysia-branches__bridge-note.
 * --------------------------------------------------------------- */
.country-branches__bridge-note {
    max-width: 60ch;
    margin-inline: auto;
    text-align: center;
    font-size: var(--fs-sm);
    color: var(--color-text-muted);
    line-height: var(--lh-relaxed);
}
