/* -------------------------------------------------------------------------
 * Shared by the Organisations Map and the Events Map: filter bar, postcode
 * search, results count, pager, pin groups, pop-ups, loading state, mobile
 * layout. Loaded after organisations-map.css / events-map.css.
 *
 * Each map sets its own colours in its :root, taken from its pin:
 *   --map-accent     pager, pin groups, pop-up icons and main button
 *   --map-on-accent  text on top of the accent
 *   --map-ink        the accent for text and outlines on white
 *   --map-tint       light accent, for hover backgrounds
 * Without them the organisations pink is used.
 * ---------------------------------------------------------------------- */

/* Filter bar: keyword, category and "More filters". The other filters and the
   postcode search open below it. */
.map-filters {
    margin-bottom: 20px;
    padding: 16px 20px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius-md);
}

.map-filters__bar,
.map-filters__extra {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

/* The buttons have no label above them: line everything up at the bottom */
.map-filters__bar {
    align-items: flex-end;
}

.map-filters__extra {
    align-items: flex-start;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color);
}

.map-filters__extra[hidden] {
    display: none;
}

/* Chips of the filters in use: same left edge as the fields above them */
.map-filters .facetwp-selections ul {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0;
    padding: 0;
}

.map-filters .facetwp-selections li {
    margin: 12px 0 0;
}

.map-filters__field {
    flex: 1 1 220px;
    min-width: 0;
}

.map-filters__field--postcode {
    flex: 2.2 1 440px;
}

/* Events Map: two date boxes side by side need more room than one dropdown */
.map-filters__field--dates {
    flex: 1.5 1 300px;
}

/* The start and end date boxes sit side by side with a gap, not touching */
.map-filters .facetwp-type-date_range {
    display: flex;
    gap: 12px;
}

.map-filters .facetwp-type-date_range input {
    flex: 1 1 0;
    min-width: 0;
    width: auto !important;
}

.map-filters__label,
.map-postcode-label {
    display: block;
    margin: 0 0 6px;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
    color: #343a40;
}

/* FacetWP gives every filter a 40px bottom margin */
.map-filters .facetwp-facet {
    margin-bottom: 0;
}

/* One height for every control, so the row lines up */
.map-filters .facetwp-facet-keyword input,
.map-filters .facetwp-type-dropdown select,
.map-filters .facetwp-type-date_range input,
.map-filters .map-postcode-input,
.map-filters .map-postcode-submit,
.map-filters__search {
    height: 50px;
}

/* Same text as "Search by distance" on both maps (each map's own CSS sizes .btn differently) */
.map-filters__search {
    min-width: 120px;
    margin-left: auto;
    font-size: 1rem !important;
    font-weight: 700;
}

.map-filters .facetwp-type-fselect .fs-wrap {
    padding: 7px 10px;
}

/* The list of categories may be wider than its field, and long names wrap
   instead of being cut off. */
.map-filters .fs-dropdown {
    width: 380px;
    min-width: 100%;
    max-width: calc(100vw - 40px);
}

.map-filters .fs-option .fs-option-label {
    white-space: normal;
}

.map-filters__more {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    height: 50px;
    padding: 0 6px;
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--purple-dark);
    text-decoration: underline;
    white-space: nowrap;
    background: none;
    border: 0;
    border-radius: 6px;
    cursor: pointer;
}

/* Chevron: points down when closed, up when open */
.map-filters__more::after {
    content: "";
    width: 9px;
    height: 9px;
    margin-top: -4px;
    border-right: 3px solid currentColor;
    border-bottom: 3px solid currentColor;
    transform: rotate(45deg);
    transition: transform 0.2s ease;
}

.map-filters__more[aria-expanded="true"]::after {
    margin-top: 4px;
    transform: rotate(-135deg);
}

.map-filters__more:hover {
    color: var(--primary-color);
}

/* Links to the events map and the list view, side by side under the filters */
.map-links {
    display: flex;
    flex-wrap: wrap;
    align-items: stretch;
    gap: 12px;
}

.map-links .map-links__list {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 24px;
    font-size: 1.125rem !important;
    font-weight: 700;
    white-space: nowrap;
}

/* Postcode search (FacetWP Proximity facet with our own markup): labels on the
   first row, postcode, distance and the button on the second. */
.map-postcode {
    display: grid;
    /* The distance column is never narrower than its label: a label on two lines
       pushed the postcode box and the button below the other filters of the row */
    grid-template-columns: minmax(0, 1.4fr) minmax(max-content, 1fr) auto;
    column-gap: 16px;
    align-items: center;
}

.map-postcode-label {
    grid-row: 1;
    grid-column: 1;
}

.map-postcode-label--distance {
    grid-column: 2;
    white-space: nowrap;
}

.map-postcode-input {
    grid-row: 2;
    grid-column: 1;
}

.map-postcode-radius {
    grid-row: 2;
    grid-column: 2;
    display: block;
    width: 100%;
}

.map-postcode-submit {
    grid-row: 2;
    grid-column: 3;
    padding: 0 18px;
    font-size: 1rem !important;
    font-weight: 700;
    white-space: nowrap;
}

.map-postcode-message {
    grid-row: 3;
    grid-column: 1 / -1;
}

.map-postcode-message {
    margin: 0.75rem 0 0;
    font-weight: 700;
    color: #b00020;
}

.map-postcode-message:empty {
    display: none;
}

.map-postcode-input:focus-visible,
.map-postcode-radius:focus-visible,
.map-postcode-submit:focus-visible,
.map-filters__more:focus-visible,
.map-more .btn:focus-visible,
.map-count__info:focus-visible,
.facetwp-selection-value:focus-visible,
.facetwp-page:focus-visible,
.map-skip-to-list:focus-visible {
    outline: 3px solid #1a1a1a;
    outline-offset: 2px;
}

/* Results count and empty state */
.map-count {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 0.75rem;
}

.map-results-count {
    font-weight: 700;
}

/* "i" button beside the count, and the note it opens */
.map-count__info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    font-size: 1.375rem;
    line-height: 1;
    color: #502481;
    background: none;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
}

.map-count__info:hover,
.map-count__info[aria-expanded="true"] {
    color: var(--primary-color);
}

.map-count__info[hidden],
.map-count__help[hidden] {
    display: none;
}

.map-count__help {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 10;
    width: 320px;
    max-width: 100%;
    margin-top: 6px;
    padding: 14px 16px;
    font-size: 1rem;
    line-height: 1.4;
    color: #1a1a1a;
    background: #fff;
    border: 2px solid #502481;
    border-radius: 10px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.map-count__help p {
    margin: 0 0 8px;
}

.map-count__help p:last-child {
    margin-bottom: 0;
}

/* The searched postcode: a red dot on the map. Its ring pulses three times and
   stops: anything that keeps moving for more than five seconds needs a pause
   control (WCAG 2.2.2), and three pulses are enough to find it. */
.map-search-pin {
    z-index: 1;
    width: 32px;
    height: 32px;
    cursor: pointer;
}

.map-search-pin::before,
.map-search-pin::after {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 22px;
    height: 22px;
    margin: -11px 0 0 -11px;
    border-radius: 50%;
}

.map-search-pin::before {
    background: #d0021b;
    border: 3px solid #fff;
    box-shadow: 0 0 0 5px rgba(208, 2, 27, 0.25), 0 1px 6px rgba(0, 0, 0, 0.5);
}

.map-search-pin::after {
    border: 3px solid #d0021b;
    opacity: 0;
    animation: map-search-pulse 1.6s ease-out 3;
}

@keyframes map-search-pulse {
    from {
        opacity: 0.9;
        transform: scale(1);
    }

    to {
        opacity: 0;
        transform: scale(3.2);
    }
}

@media (prefers-reduced-motion: reduce) {
    .map-search-pin::after {
        animation: none;
    }
}

.map-search-pin:focus-visible {
    outline: 3px solid #1a1a1a;
    outline-offset: 2px;
    border-radius: 50%;
}

/* Pop-ups stay above the dot (they come later in the page, so the same level is enough) */
.maplibregl-popup {
    z-index: 1;
}

.map-search-popup .maplibregl-popup-content {
    min-width: 0;
    padding: 10px 14px;
    font-size: 14px;
    white-space: nowrap;
}

.map-search-popup .maplibregl-popup-content p {
    margin: 0;
    line-height: 18px;
}

/* Whole-pixel line heights inside the pin pop-up. MapLibre places a pop-up with
   translate(-50%, -100%): one that is 370.6px tall lands between two pixels and
   all its text looks thin and blurred. Other pop-ups, by luck, looked sharp. */
.maplibregl-popup-content h6 {
    line-height: 22px;
}

.maplibregl-popup-content p {
    line-height: 16px;
}

/* Field labels in the pin pop-up: icon + name */
.map-popup-label {
    margin-bottom: 5px;
    font-weight: 900;
    color: #111;
}

.map-popup-label .fa {
    margin-right: 6px;
    color: var(--map-accent, #cc1f7e);
}

/* Buttons at the foot of the pin pop-up: same size, same text, stacked */
.map-popup-actions {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    width: max-content;
    max-width: 100%;
    margin: 0 auto;
}

.map-popup-btn,
.map-popup-btn:visited {
    display: block;
    padding: 10px 22px;
    font-size: 14px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    text-decoration: none;
    color: #fff;
    border-radius: 8px;
}

.map-popup-btn--primary {
    background: var(--map-accent, #cc1f7e);
}

.map-popup-btn--secondary {
    background: #502481;
}

.map-popup-btn:hover,
.map-popup-btn:focus {
    color: #fff;
    text-decoration: none;
    filter: brightness(0.88);
}

.map-popup-btn:focus-visible {
    outline: 3px solid #1a1a1a;
    outline-offset: 2px;
}

.map-no-results {
    padding: 1rem;
    font-size: 1.125rem;
}

/* Pagination: larger text so visitors can see there are more results */
.sidebar .facetwp-pager {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 1px;
}

/* Page buttons are true circles (same width and height). 32px keeps the longest
   pager, "< 1 ... 3 4 5 6 7 ... 10 >", on one row of the sidebar. */
.sidebar .facetwp-pager .facetwp-page {
    box-sizing: border-box;
    width: 32px;
    height: 32px;
    margin: 0;
    padding: 0;
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1;
    color: var(--map-ink, #cc1f7e);
    border: 0;
    border-radius: 50%;
    background: transparent;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.sidebar .facetwp-pager .facetwp-page:hover {
    background: var(--map-tint, #fbe6f1);
}

.sidebar .facetwp-pager .facetwp-page.active {
    color: var(--map-on-accent, #fff);
    background: var(--map-accent, #cc1f7e);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* Previous / next: an outlined circle with a thin chevron drawn in CSS.
   The JS empties the link text and names it "Previous page" / "Next page". */
.sidebar .facetwp-pager .facetwp-page.prev,
.sidebar .facetwp-pager .facetwp-page.next {
    font-size: 0;
    border: 2px solid var(--map-ink, #cc1f7e);
}

.sidebar .facetwp-pager .facetwp-page.prev {
    margin-right: 4px;
}

.sidebar .facetwp-pager .facetwp-page.next {
    margin-left: 4px;
}

.sidebar .facetwp-pager .facetwp-page.prev::before,
.sidebar .facetwp-pager .facetwp-page.next::before {
    content: "";
    width: 8px;
    height: 8px;
    border-top: 2px solid currentColor;
    border-right: 2px solid currentColor;
}

.sidebar .facetwp-pager .facetwp-page.prev::before {
    margin-left: 3px;
    transform: rotate(-135deg);
}

.sidebar .facetwp-pager .facetwp-page.next::before {
    margin-right: 3px;
    transform: rotate(45deg);
}

.sidebar .facetwp-pager .facetwp-page.prev:hover,
.sidebar .facetwp-pager .facetwp-page.next:hover {
    color: var(--map-on-accent, #fff);
    background: var(--map-accent, #cc1f7e);
}

.sidebar .facetwp-pager .facetwp-page.dots {
    width: 12px;
    color: #6c757d;
    background: transparent;
    cursor: default;
}

/* Tighter result cards, so more of them fit on screen */
.sidebar .organization-card,
.sidebar .event-card {
    margin-bottom: 12px;
}

.sidebar .organization-card .card-header,
.sidebar .event-card .card-header {
    padding: 12px 16px 0;
}

.sidebar .organization-card .card-title,
.sidebar .event-card .card-title {
    font-size: 1.25rem;
    line-height: 1.2;
}

.sidebar .organization-card .card-body,
.sidebar .event-card .card-body {
    padding: 8px 16px 12px;
}

.sidebar .organization-card .card-text,
.sidebar .event-card .card-text {
    margin-bottom: 8px;
}

.sidebar .organization-card .card-body > .mt-2 {
    margin-top: 6px !important;
}

/* The list scrolls inside its own box. A wide coloured scrollbar and a shadow
   over the bottom pager make that obvious. */
.sidebar {
    scrollbar-width: auto;
    scrollbar-color: #502481 #ede6f5;
}

.sidebar::-webkit-scrollbar {
    width: 12px;
}

.sidebar::-webkit-scrollbar-track {
    background: #ede6f5;
    border-radius: 999px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #502481;
    border: 2px solid #ede6f5;
    border-radius: 999px;
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background: #3b1a61;
}

.sidebar .facetwp-pagination-wrapper {
    margin-top: 0 !important;
    margin-bottom: 12px !important;
    border-bottom: 1px solid #e3dcee;
}

.sidebar .facetwp-template ~ .facetwp-pagination-wrapper {
    margin-bottom: 0 !important;
    border-top: 1px solid #e3dcee;
    border-bottom: 0;
    box-shadow: 0 -12px 14px -10px rgba(0, 0, 0, 0.28);
}

/* The results heading only takes focus from the "skip to list" link */
#map-results:focus {
    outline: none;
    box-shadow: none; /* the theme draws a focus ring on every :focus (style.css) */
}

@media (prefers-reduced-motion: reduce) {
    .sidebar .facetwp-pager .facetwp-page {
        transition: none;
    }
}

/* Pin groups: one round marker with the number of pins it stands for */
.map-cluster {
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.125rem;
    font-weight: 700;
    line-height: 1;
    color: var(--map-on-accent, #fff);
    background: var(--map-accent, #cc1f7e);
    border: 3px solid #fff;
    border-radius: 50%;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
    cursor: pointer;
}

.map-cluster--medium {
    width: 50px;
    height: 50px;
    font-size: 1.25rem;
}

.map-cluster--large {
    width: 60px;
    height: 60px;
    font-size: 1.375rem;
}

.map-cluster:hover {
    filter: brightness(0.9);
}

.map-cluster:focus-visible {
    outline: 3px solid #1a1a1a;
    outline-offset: 2px;
}

/* List shown for organisations that share one address */
.map-cluster-list {
    min-width: 220px;
    max-width: 300px;
    padding: 10px;
}

.map-cluster-list__title {
    margin: 0 0 8px;
    font-weight: 700;
    color: #502481;
}

.map-cluster-list ul {
    max-height: 240px;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    list-style: none;
}

.map-cluster-list__item {
    width: 100%;
    min-height: 40px;
    padding: 8px 4px;
    font: inherit;
    text-align: left;
    color: var(--map-ink, #cc1f7e);
    text-decoration: underline;
    background: none;
    border: 0;
    border-top: 1px solid #e3e3e3;
    cursor: pointer;
}

.map-cluster-list__item:hover,
.map-cluster-list__item:focus-visible {
    color: #502481;
    background: #f3eef9;
}

/* Results list: cards past the first batch wait behind "Load more" */
.organization-card[hidden],
.event-card[hidden],
.map-more[hidden] {
    display: none !important;
}

.map-more {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 16px 8px 20px;
}

.map-more__count {
    flex: 1 1 100%;
    margin: 0;
    font-weight: 700;
    text-align: center;
}

.map-more .btn {
    min-height: 44px;
    padding: 8px 20px;
    font-size: 1rem !important;
    font-weight: 700;
    border: 2px solid #502481;
    border-radius: 999px;
}

.map-more__next {
    color: #fff;
    background: #502481;
}

.map-more__next:hover,
.map-more__next:focus {
    color: #fff;
    background: #3b1a61;
}

.map-more__all {
    color: #502481;
    background: #fff;
}

.map-more__all:hover,
.map-more__all:focus {
    color: #502481;
    background: #f3eef9;
}

/* Above the list while it follows the map: how many are on screen */
.map-follow {
    margin-bottom: 16px;
    padding: 12px 16px;
    border: 2px solid #502481;
    border-radius: 12px;
    background: #f3eef9;
}

/* Cards fade in as they appear: first load, "Load more", and as the list follows the map.
   Only the opacity: a moving card would throw off the scroll to the selected card. */
.organization-card,
.event-card {
    animation: map-card-in 0.3s ease-out;
}

@keyframes map-card-in {
    from {
        opacity: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .organization-card,
    .event-card {
        animation: none;
    }
}

.map-follow[hidden],
.map-follow__empty[hidden] {
    display: none;
}

.map-follow__text {
    margin: 0;
    font-weight: 700;
}

/* The card of the pin selected on the map, in the colour of each map */
.organization-card.is-selected {
    border-color: #cd1e7d;
    box-shadow: 0 0 0 4px rgba(205, 30, 125, 0.25);
}

.event-card.is-selected {
    border-color: #ff8a00;
    box-shadow: 0 0 0 4px rgba(255, 138, 0, 0.3);
}

/* Height of the map: the screen, less 24px above and below. "dvh" follows the
   browser bars on tablets; "vh" is the fallback for older browsers. */
.map-layout {
    --map-height: calc(100vh - 48px);
}

@supports (height: 100dvh) {
    .map-layout {
        --map-height: calc(100dvh - 48px);
    }
}

/* Loading state: covers the list and the map while new results are fetched */
.map-layout {
    position: relative;
}

.map-loading {
    display: none;
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1001;
    background: rgba(255, 255, 255, 0.75);
}

.map-layout.is-loading .map-loading {
    display: block;
}

/* Sticky, so the message stays on screen however long the list is */
.map-loading__box {
    position: sticky;
    top: 40vh;
    display: flex;
    align-items: center;
    gap: 12px;
    width: max-content;
    max-width: 90%;
    margin: 60px auto;
    padding: 14px 24px;
    font-size: 1.125rem;
    font-weight: 700;
    color: #502481;
    background: #fff;
    border: 2px solid #502481;
    border-radius: 999px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

.map-loading__spinner {
    flex: 0 0 auto;
    width: 24px;
    height: 24px;
    border: 4px solid #ede6f5;
    border-top-color: #502481;
    border-radius: 50%;
    animation: map-loading-spin 0.8s linear infinite;
}

@keyframes map-loading-spin {
    to {
        transform: rotate(360deg);
    }
}

@media (prefers-reduced-motion: reduce) {
    .map-loading__spinner {
        animation: none;
    }

    .map-filters__more::after {
        transition: none;
    }
}

/* The skip link only shows on mobile, where the map sits above the list */
.map-skip-to-list {
    display: none;
}

@media (max-width: 767.98px) {
    /* Filters: one field per row, postcode and distance side by side */
    .map-filters {
        padding: 12px;
    }

    .map-filters__bar,
    .map-filters__extra {
        gap: 12px;
    }

    .map-filters__field,
    .map-filters__field--dates,
    .map-filters__field--postcode {
        flex-basis: 100%;
    }

    .map-links .map-links__list {
        flex: 1 1 100%;
        min-height: 50px;
    }

    .map-postcode {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        column-gap: 12px;
    }

    .map-postcode-label--distance {
        white-space: normal;
    }

    .map-postcode-submit {
        grid-row: 3;
        grid-column: 1 / -1;
        margin-top: 12px;
    }

    .map-postcode-message {
        grid-row: 4;
    }

    .map-layout {
        display: flex;
        flex-direction: column;
    }

    .map-layout__map {
        order: -1;
        margin-bottom: 1.5rem;
    }

    .map-skip-to-list {
        display: inline-block;
        margin-bottom: 0.75rem;
        font-size: 1.125rem;
        font-weight: 700;
        text-decoration: underline;
    }

    /* Short enough that the list below can be reached by scrolling past the map */
    .map-layout #map {
        height: 60vh !important;
        min-height: 320px !important;
    }

    /* Pop-ups never wider than the map of a narrow phone (MapLibre sets the width inline) */
    .maplibregl-popup {
        max-width: calc(100vw - 90px) !important;
    }

    .maplibregl-popup-content {
        min-width: 0;
    }

    /* The list is below the map here: it runs down the page, with no box of its own to scroll */
    .map-layout .sidebar {
        height: auto !important;
        min-height: 0;
    }
}
