/* retailermaps — embeddable retailer maps (MapLibre GL). Prefix: rm- */

.rm {
    --rm-h-mobile: 320px;
    --rm-h-tablet: 420px;
    --rm-h-desktop: 520px;
    --rm-frame: #1c4c9a;
    --rm-frame-width: 2px;
    --rm-frame-radius: .5rem;
    --rm-pin-w: 32px;
    --rm-pin-h: 37px;
    position: relative;
}

/* ---- map frame ---------------------------------------------------------------------- */
.rm__frame {
    position: relative;
    border: var(--rm-frame-width) solid var(--rm-frame);
    border-radius: var(--rm-frame-radius);
    overflow: hidden;
    background: #eeeeee;
}
.rm__map {
    width: 100%;
    height: var(--rm-h-mobile);
}
@media (min-width: 768px) {
    .rm__map { height: var(--rm-h-tablet); }
}
@media (min-width: 992px) {
    .rm__map { height: var(--rm-h-desktop); }
    .rm--results-left .rm__results-wrap,
    .rm--results-right .rm__results-wrap {
        display: flex;
        flex-direction: column;
        max-height: calc(var(--rm-h-desktop) + 4px);
    }
    .rm--results-left .rm__results,
    .rm--results-right .rm__results {
        flex: 1 1 auto;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
        margin-right: 0;
    }
}

/* ---- overlays ----------------------------------------------------------------------- */
.rm__loading {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, .7);
    z-index: 5;
}
.rm--loading .rm__loading { display: flex; }
.rm__spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: .3rem solid rgba(0, 0, 0, .12);
    border-top-color: var(--rm-frame);
    border-radius: 50%;
    animation: rm-spin .8s linear infinite;
}
@keyframes rm-spin { to { transform: rotate(360deg); } }
/* viewport refetch: a small corner spinner, no overlay, so panning never blanks the map */
.rm__frame::after {
    content: "";
    position: absolute;
    right: 12px; top: 12px;
    width: 1.1rem; height: 1.1rem;
    border: .2rem solid rgba(255, 255, 255, .5);
    border-top-color: var(--rm-frame);
    border-radius: 50%;
    animation: rm-spin .8s linear infinite;
    opacity: 0;
    transition: opacity .15s;
    pointer-events: none;
    z-index: 5;
}
.rm--refreshing .rm__frame::after { opacity: 1; }
.rm .maplibregl-ctrl-top-right { margin-top: 36px; }   /* keep zoom buttons clear of the corner spinner */

.rm__message {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    padding: .5rem .75rem;
    background: #fff3cd;
    color: #664d03;
    font-size: .875rem;
    z-index: 6;
}
.rm__message[hidden] { display: none; }

/* list-only fallback (no WebGL) */
.rm--list-only .rm__map-col { display: none; }
.rm--list-only .rm__results-col { flex: 0 0 100%; max-width: 100%; }
.rm--list-only .rm__results-col[hidden] { display: block; }
.rm--list-only .rm__locate { display: none; }

/* ---- lock badge + count badge (MapLibre controls, stacked top-left) ------------------ */
.rm {
    --rm-badge-bg: rgba(255, 255, 255, .92);
    --rm-badge-fg: var(--rm-frame);
    --rm-count-bg: var(--rm-frame);
    --rm-count-fg: #ffffff;
}
.rm__badge.maplibregl-ctrl,
.rm__count.maplibregl-ctrl {
    border-radius: 999px;
    padding: 2px 10px;
    font-size: .75rem;
    font-weight: 600;
    line-height: 1.4;
    pointer-events: none;
    box-shadow: 0 1px 2px rgba(0, 0, 0, .15);
    white-space: nowrap;
}
.rm__badge.maplibregl-ctrl {
    background: var(--rm-badge-bg);
    color: var(--rm-badge-fg);
    border: 1px solid var(--rm-frame);
}
.rm__count.maplibregl-ctrl {
    background: var(--rm-count-bg);
    color: var(--rm-count-fg);
    border: 1px solid var(--rm-count-bg);
    font-weight: 500;
}
.rm__count.maplibregl-ctrl[hidden] { display: none; }
@media (max-width: 575.98px) {
    /* phone: "Showing 200 of 267 retailers…" must wrap short of the zoom buttons */
    .rm__count.maplibregl-ctrl { white-space: normal; max-width: calc(100vw - 120px); line-height: 1.3; }
}
/* tighten the stack so the count reads as a second line of the label */
.rm .maplibregl-ctrl-top-left .rm__badge.maplibregl-ctrl + .rm__count.maplibregl-ctrl { margin-top: 4px; }

/* ---- pins --------------------------------------------------------------------------- */
.rm__pin {
    display: block;
    padding: 0;
    border: 0;
    background: none;
    cursor: pointer;
    line-height: 0;
}
.rm__pin img {
    display: block;
    width: var(--rm-pin-w);
    height: var(--rm-pin-h);
    filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .35));
    transform-origin: bottom center;
    transition: transform .12s ease-out;
}
.rm__pin--active img,
.rm__pin:hover img { transform: scale(1.15); }
.rm__pin:focus-visible { outline: 2px solid var(--rm-frame); outline-offset: 2px; }

/* ---- results ------------------------------------------------------------------------ */
.rm__results-header { padding: .25rem 0 .5rem; font-size: .9rem; }
.rm__results-header:empty { display: none; }   /* count lives on the map by default: no phantom gap above card 1 */
.rm__empty { padding: .5rem 0; color: #6c757d; font-size: .9rem; }
.rm__card--active .card { box-shadow: 0 0 0 2px var(--rm-frame); }
.rm__locate { cursor: pointer; }

/* ---- popup: dark text on a light card regardless of the page theme ------------------ */
.rm-popup .maplibregl-popup-content {
    color: #212529;
    background: #ffffff;
    padding: 14px 24px 12px 14px;
    border-radius: .5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, .25);
    font-size: 14px;
    line-height: 1.35;
}
.rm-popup .maplibregl-popup-close-button {
    font-size: 18px;
    padding: 2px 8px;
    color: #6c757d;
    background: transparent;
}
.rm-popup .maplibregl-popup-close-button:hover { background: rgba(0, 0, 0, .05); }
.rm-popup .scrollFix { max-height: 220px; overflow-y: auto; }
.rm-popup.maplibregl-popup-anchor-bottom .maplibregl-popup-tip { border-top-color: #ffffff; }
.rm-popup.maplibregl-popup-anchor-top .maplibregl-popup-tip { border-bottom-color: #ffffff; }
.rm-popup.maplibregl-popup-anchor-left .maplibregl-popup-tip { border-right-color: #ffffff; }
.rm-popup.maplibregl-popup-anchor-right .maplibregl-popup-tip { border-left-color: #ffffff; }

/* ---- address search (optional; chunk tc-rm.tpl.search) ------------------------------ */
.rm {
    --rm-search-bg: #ffffff;
    --rm-search-fg: #212529;
    --rm-search-accent: var(--rm-frame);
    --rm-search-width: 320px;
}
.rm__search { position: relative; font-size: .9rem; color: var(--rm-search-fg); text-align: left; }
.rm__search-holder { display: none; }                      /* corner boxes are moved into the map's control corner */
/* in the page flow (above the map / above the cards): the dropdown overlays whatever is below */
.rm__search--flow { z-index: 20; margin-bottom: .5rem; }
/* on the map */
.rm__search--map { width: var(--rm-search-width); max-width: calc(100vw - 40px); }
/* every MapLibre control carries transform:translate(0), i.e. its own stacking context, so the
   open dropdown would paint UNDER the badges / zoom buttons that follow it in the corner -
   lift the whole control above its siblings */
.rm__search-ctrl.maplibregl-ctrl { clear: both; background: transparent; box-shadow: none; position: relative; z-index: 5; }
/* a top-corner box is the FIRST control in its corner (above the badges / zoom buttons): the
   36px top-right margin that keeps the zoom buttons clear of the corner spinner is not needed
   there - the spinner moves to the bottom-left corner instead */
.rm--search-map-top-right .maplibregl-ctrl-top-right { margin-top: 0; }
.rm--search-map-top-left .rm__frame::after,
.rm--search-map-top-right .rm__frame::after { top: auto; right: auto; bottom: 12px; left: 12px; }
.rm--search-map-top-left.rm--search-map-bottom-left .rm__frame::after { display: none; }
@media (max-width: 575.98px) {
    /* phone: the top boxes span the map. The corner container is stretched to both edges
       (it is pointer-events:none, so the map underneath still pans) and the box fills it;
       the OTHER top corner's stack starts below the box row (10px margin + ~38px box). */
    .rm--search-map-top-left .maplibregl-ctrl-top-left,
    .rm--search-map-top-right .maplibregl-ctrl-top-right { left: 0; right: 0; }
    .rm__search--map-top-left, .rm__search--map-top-right { width: calc(100% - 20px); max-width: none; }
    .rm--search-map-top-left .maplibregl-ctrl-top-right { margin-top: 48px; }
    .rm--search-map-top-right .maplibregl-ctrl-top-left { margin-top: 48px; }
}
.rm__search--center { position: absolute; left: 50%; transform: translateX(-50%); z-index: 4; }
.rm__search--map-top-center { top: 10px; }
.rm__search--map-bottom-center { bottom: 34px; }
/* the field */
.rm__search-group { position: relative; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); border-radius: .25rem; flex-wrap: nowrap; }
.rm__search-input.form-control {
    background: var(--rm-search-bg);
    color: var(--rm-search-fg);
    border-color: rgba(0, 0, 0, .15);
    padding-right: 2rem;
    font-size: .9rem;
    height: calc(1.5em + .75rem + 2px);
}
.rm__search-input.form-control:focus { border-color: var(--rm-search-accent); box-shadow: none; outline: 0; }
.rm__search-input::-webkit-search-cancel-button,
.rm__search-input::-webkit-search-decoration { -webkit-appearance: none; appearance: none; }
.rm__search-clear {
    position: absolute; right: 2.6rem; top: 0; bottom: 0; z-index: 4;
    border: 0; background: transparent; color: #6c757d;
    font-size: 1.25rem; line-height: 1; padding: 0 .4rem; cursor: pointer;
}
.rm__search-clear:hover { color: var(--rm-search-fg); }
.rm__search-clear[hidden] { display: none; }
.rm__search-btn.btn {
    display: flex; align-items: center;
    padding: 0 .6rem;
    background: var(--rm-search-accent); border-color: var(--rm-search-accent); color: #ffffff;
}
.rm__search-btn.btn:hover, .rm__search-btn.btn:focus { background: var(--rm-search-accent); border-color: var(--rm-search-accent); color: #ffffff; filter: brightness(.9); box-shadow: none; }
.rm__search-btn svg { display: block; }
.rm__search--busy .rm__search-btn svg { animation: rm-blink .8s ease-in-out infinite; }
@keyframes rm-blink { 50% { opacity: .35; } }
/* the dropdown */
.rm__search-panel {
    position: absolute; left: 0; right: 0; top: 100%; margin-top: 4px; z-index: 30;
    background: var(--rm-search-bg); color: var(--rm-search-fg);
    border: 1px solid rgba(0, 0, 0, .15); border-radius: .25rem;
    box-shadow: 0 6px 16px rgba(0, 0, 0, .2);
    max-height: min(260px, 40vh); overflow-y: auto; overscroll-behavior: contain;
}
.rm__search-panel[hidden] { display: none; }
.rm__search--up .rm__search-panel { top: auto; bottom: 100%; margin-top: 0; margin-bottom: 4px; }   /* bottom corners open upward */
.rm__search-list { margin: 0; padding: .25rem 0; }
.rm__search-list:empty { display: none; }
.rm__search-item { padding: .4rem .75rem; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rm__search-item:hover, .rm__search-item--active { background: var(--rm-search-accent); color: #ffffff; }
.rm__search-geo {
    display: flex; align-items: center; gap: .4rem; width: 100%;
    border: 0; background: transparent; color: var(--rm-search-accent);
    font-weight: 600; padding: .45rem .75rem; text-align: left; cursor: pointer;
}
.rm__search-geo:hover { background: rgba(0, 0, 0, .05); }
.rm__search-geo[hidden] { display: none; }
/* locating state: the arrow spins, the option greys out, the field shows a progress cursor */
.rm__search--locating .rm__search-geo { opacity: .75; cursor: progress; }
.rm__search--locating .rm__search-geo svg { animation: rm-spin 1s linear infinite; }
.rm__search--locating .rm__search-input { cursor: progress; }
.rm__search-geo:not([hidden]) + .rm__search-list:not(:empty) { border-top: 1px solid rgba(0, 0, 0, .08); }
.rm__search-msg { padding: .45rem .75rem; color: #6c757d; font-size: .85rem; }
.rm__search-msg[hidden] { display: none; }
/* the search-point marker */
.rm__search-pin {
    position: relative; width: 16px; height: 16px; border-radius: 50%;
    background: var(--rm-search-accent); border: 3px solid #ffffff;
    box-shadow: 0 0 0 2px var(--rm-search-accent), 0 1px 4px rgba(0, 0, 0, .4);
}
.rm__search-pin::after {
    content: ""; position: absolute; inset: -10px; border-radius: 50%;
    border: 2px solid var(--rm-search-accent); opacity: .6;
    animation: rm-ping 1.6s ease-out infinite;
}
@keyframes rm-ping { 0% { transform: scale(.5); opacity: .8; } 100% { transform: scale(1.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .rm__search-pin::after { display: none; } }
.rm--list-only .rm__search--map { display: none; }

/* attribution is REQUIRED by OpenFreeMap / OpenStreetMap — keep it small, never hide it */
.rm .maplibregl-ctrl-attrib { font-size: 10px; }
.rm .maplibregl-cooperative-gesture-screen { font-size: .9rem; }
