/* The "Where to recycle" block: the search panel, the map, the popup.
 *
 * Everything here is scoped under .cms-code, the wrapper the CMS puts
 * around a custom-code block, so none of it can reach the rest of a
 * programme page.
 *
 * This is the small, load-bearing part of what the legacy pages carried.
 * The rest of that CSS — .btn-dark, .col-with-margin,
 * .inner-div-with-margin, .bottom-left-text, .is-section-75,
 * #program-choice — styled furniture that lived elsewhere on those pages
 * and is not part of the map. It is deliberately not carried over, along
 * with `#where-to-recycle { width: 100vh }`, which applied a height unit
 * to a width.
 */

/* Full-bleed, whatever section the block is dropped into.
 *
 * The negative margins on .map-container below are the standard escape
 * from a centred column — and even a full-width section keeps a little
 * horizontal padding, so the map has to escape that too or it sits in
 * gutters.
 *
 * What must NOT go here is overflow-x. It is the obvious place for it,
 * because 100vw counts the scrollbar and can overflow the page by its
 * width — but a clip on this element clips the child that is escaping
 * it, which put the map right back inside the padding it had just
 * climbed out of. The clip belongs on an ancestor that is already the
 * full width; see the rule below. */
.cms-code .rnb-map-wrap {
    position: relative;
    width: 100%;
}

/* Where the clip does belong.
 *
 * The section is full-viewport-width already, so clipping here costs the
 * map nothing and still stops 100vw from adding a horizontal scrollbar
 * to the whole page on a platform with classic (space-taking)
 * scrollbars. `clip` rather than `hidden` so this does not quietly
 * become a scroll container.
 *
 * Unscoped, because it selects an ancestor of the block — :has is what
 * makes that possible, and it keeps the rule to sections that actually
 * contain a map. A browser without :has simply does not apply it, and
 * the worst case there is a horizontal scrollbar, not a broken map. */
section:has(.rnb-map-wrap) {
    overflow-x: clip;
}

.cms-code .map-container {
    position: relative;
    width: 100vw;
    margin-left: calc(-50vw + 50%);
    margin-right: calc(-50vw + 50%);
    height: 90vh;
    overflow: hidden;
}

.cms-code #js-map {
    width: 100%;
    height: 100%;
}

/* The search panel. Recycle NB's deep green, square corners — the same
 * treatment the rest of the site gives a control on a dark ground. */
.cms-code .search-form-container {
    background-color: #2e765c;
    padding: 1.5rem;
    border-radius: 0.25rem;
    width: 350px;
    max-width: 500px;
    z-index: 10;
}

/* Measured against the live site rather than guessed: 32px on a 38.4px
 * line, with 16px of air under it. The legacy markup wrote 4px on the
 * heading and 16px on the wrapper around it, and the 4px collapsed —
 * the panel it produces is 154px tall, which is what this reproduces. */
.cms-code .search-form-heading {
    color: #fff;
    margin: 0 0 1rem;
    font-size: 2rem;
    line-height: 1.2;
}

.cms-code .search-row {
    display: flex;
    flex-direction: row;
}

/* background-color is the one that matters, and it is easy to miss why
 * it has to be said. An <input> is white by the browser's own stylesheet,
 * which is why the legacy page never set it — but Tailwind's Preflight
 * resets form controls to `background-color: transparent`, so on this
 * site the field vanished into the green panel and the placeholder
 * floated on it with nothing behind.
 *
 * 1.0833rem is 17.33px, which is what the live site renders: Bootstrap's
 * 1.0833rem, arrived at from its own root size. Matching it keeps the
 * field the same height (52px) without pinning one. */
.cms-code .search-row input[type="text"] {
    /* Takes whatever the button leaves, rather than claiming a share of
     * its own. A 3:1 grow on the pair — which is how the legacy markup
     * wrote it — does not reproduce the legacy widths here: it comes out
     * 227/68 against the live site's 221/74, because there the flex item
     * was a wrapper div and the input merely filled it, while here the
     * input is the item and brings an intrinsic size with it. Sizing the
     * button and letting the field take the remainder gives the same
     * result at any panel width. */
    flex: 1 1 auto;
    width: 100%;
    margin-right: 0.5rem;
    padding: 0.75rem;
    border: 0;
    border-radius: 0;
    background-color: #fff;
    color: #555;
    font-size: 1.0833rem;
    font-weight: 700;
    min-width: 0;
}

.cms-code .search-row input[type="text"]::placeholder {
    color: #c5c5c5;
    font-weight: 400;
}

.cms-code .search-button {
    /* A quarter of the row, less the gap — the share legacy's 3:1 split
     * produced (73.5px in a 302px row). */
    flex: 0 0 calc((100% - 0.5rem) / 4);
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #2e554d;
    color: #fff;
    border-radius: 0;
    text-decoration: none;
}

.cms-code .search-button:hover { background-color: #24443e; }
.cms-code .search-button svg { width: 1.0833rem; height: 1.0833rem; }

/* The marker popup. Positioned by OpenLayers, so only its look is here. */
.cms-code #popup {
    position: absolute;
    bottom: 12px;
    left: -50px;
    min-width: 200px;
    display: none;
    z-index: 10000;
    padding: 15px;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 10px;
    color: #1f2937;
}

.cms-code #popup-closer {
    position: absolute;
    top: 2px;
    right: 8px;
    color: #c3c3c3;
    text-decoration: none;
}

/* The lock/unlock control, which only appears on touch layouts: a map
 * that swallows a one-finger scroll traps the page. */
.cms-code .map-toggle-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
    display: none;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Desktop: the panel floats over the map. */
@media (min-width: 768px) {
    .cms-code .search-form-container {
        position: absolute;
        top: 8%;
        left: 5%;
    }

    /* Only here: below this the panel goes edge to edge, and a width
     * would beat the rule that does it. */
    .cms-code .search-form-container.is-chooser {
        width: 500px;
        max-width: 500px;
    }
}

/* Below that it stacks above a shorter map, full width and square, and
 * the lock control appears. */
@media (max-width: 767px) {
    /* Edge to edge, like the map under it.
     *
     * width:100% is 100% of the wrapper, and the wrapper sits inside the
     * section's horizontal padding — so the panel stopped short of both
     * edges while the map beneath it did not, and the two disagreed by
     * 16px a side. The panel has to escape the padding the same way the
     * map does; square corners, because a full-bleed band with rounded
     * ones reads as a mistake. */
    .cms-code .search-form-container {
        position: relative;
        left: 0;
        width: 100vw;
        max-width: none;
        margin-left: calc(-50vw + 50%);
        margin-right: calc(-50vw + 50%);
        margin-bottom: 0;
        border-radius: 0;
    }

    .cms-code .map-container { height: 70vh; }
    .cms-code .map-toggle-btn { display: block; }
}

/* The search button's busy state.
 *
 * The legacy script swapped the button's innerHTML for a FontAwesome
 * spinner and then for a FontAwesome magnifier, which on this site would
 * replace the inline SVG with an <i> that renders as nothing — the button
 * went blank after the first search and stayed that way. It toggles this
 * class instead, so the icon is never touched. */
.cms-code .search-button.is-searching {
    opacity: 0.6;
    pointer-events: none;
}

.cms-code .search-button.is-searching svg {
    animation: rnb-map-spin 0.9s linear infinite;
}

@keyframes rnb-map-spin {
    to { transform: rotate(360deg); }
}

/* A failed search says so here, rather than through SweetAlert2 — see
 * fireError in map-proxy.js. */
.cms-code .search-error {
    margin: 0.75rem 0 0;
    color: #fff;
    font-size: 0.875rem;
    line-height: 1.4;
}

@media (prefers-reduced-motion: reduce) {
    .cms-code .search-button.is-searching svg { animation: none; }
}

/* --- The chooser -----------------------------------------------------
 *
 * The home page asks which programme rather than knowing, so its panel
 * carries a <select> above the location row and is wider to fit the
 * longest label ("Pharmaceutical Products & Medical Sharps"). Measured
 * off the live site: 500px panel, 54px select, 24px between it and the
 * row below. */

.cms-code .search-choose {
    margin-bottom: 1.5rem;
}

.cms-code .search-choose select {
    display: block;
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 0.75rem;
    border: 0;
    border-bottom: 2px solid #fff;
    border-radius: 0;
    background-color: transparent;
    /* The arrow the platform would draw is hidden by appearance:none, so
     * it is drawn here instead — white, to read against the green. */
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 10'%3e%3cpath fill='%23fff' d='M2.5 4 L5 6.5 L7.5 4 Z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    color: #fff;
    font-size: 1.0833rem;
    font-weight: 400;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

/* The dropdown itself is drawn by the platform on its own background,
 * which is usually white — white-on-white without this. */
.cms-code .search-choose select option {
    color: #1f2937;
    background-color: #fff;
}
