/*
 * "Advanced search" drawer for the filter menus (Conference Navigator and
 * Professional Circles). Phones only: the filter menus fold away under one
 * button and roll down when it is tapped (js/advanced-search-toggle.js).
 * Beside it, a Map button pops the map open where it sits ([data-refine-map]);
 * otherwise the map stays folded away.
 * Larger screens never see either button; the wrappers step out of the layout
 * (display: contents) so the filter grid and the map sit exactly where they always did.
 */

.refine-search,
.refine-bar,
.refine-drawer,
.refine-drawer-inner {
    display: contents;
}

.refine-toggle,
.refine-map-toggle {
    display: none;
}

@media (max-width: 768px) {
    .refine-search {
        display: block;
    }

    /* Advanced search and Map side by side */
    .refine-bar {
        display: flex;
        align-items: stretch;
        gap: 0.55rem;
    }

    .refine-bar > .refine-toggle {
        flex: 1 1 auto;
        min-width: 0;
    }

    /* The button */
    .refine-toggle {
        position: relative;
        width: 100%;
        min-height: 56px;
        display: flex;
        align-items: center;
        gap: 0.75rem;
        padding: 0.55rem 0.7rem 0.55rem 0.6rem;
        border: 1px solid rgba(13, 109, 108, 0.16);
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.82);
        box-shadow:
            0 1px 2px rgba(15, 40, 38, 0.05),
            0 6px 16px -8px rgba(13, 109, 108, 0.28);
        color: #16302d;
        font: inherit;
        text-align: left;
        cursor: pointer;
        box-sizing: border-box;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition:
            border-color 0.25s ease,
            background-color 0.25s ease,
            box-shadow 0.25s ease,
            transform 0.16s ease;
    }

    .refine-toggle:active {
        transform: scale(0.985);
    }

    .refine-toggle:focus-visible {
        outline: none;
        border-color: #3eb3a5;
        box-shadow:
            0 0 0 3px rgba(62, 179, 165, 0.28),
            0 6px 16px -8px rgba(13, 109, 108, 0.28);
    }

    .refine-search.is-open .refine-toggle {
        border-color: rgba(62, 179, 165, 0.55);
        background: #fff;
        box-shadow:
            0 1px 2px rgba(15, 40, 38, 0.05),
            0 10px 24px -12px rgba(13, 109, 108, 0.4);
    }

    /* Teal tile with a sliders glyph; its knobs slide when the drawer opens */
    .refine-toggle-icon {
        flex: none;
        width: 38px;
        height: 38px;
        display: grid;
        place-items: center;
        border-radius: 11px;
        background: linear-gradient(140deg, #4cc2b3 0%, #1f9488 55%, #0d6d6c 100%);
        color: #fff;
        box-shadow:
            0 5px 12px -4px rgba(13, 109, 108, 0.5),
            inset 0 1px 0 rgba(255, 255, 255, 0.28);
    }

    .refine-toggle-icon svg {
        width: 20px;
        height: 20px;
        overflow: visible;
    }

    .refine-toggle-icon .refine-knob {
        transition: transform 0.5s cubic-bezier(0.34, 1.4, 0.64, 1);
    }

    .refine-search.is-open .refine-knob--1 { transform: translateX(6px); }
    .refine-search.is-open .refine-knob--2 { transform: translateX(-7px); }
    .refine-search.is-open .refine-knob--3 { transform: translateX(5px); }

    .refine-toggle-text {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 2px;
    }

    .refine-toggle-title {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        font-size: 0.98rem;
        font-weight: 600;
        line-height: 1.2;
        letter-spacing: -0.005em;
        color: #16302d;
    }

    .refine-toggle-hint {
        font-size: 0.76rem;
        line-height: 1.25;
        color: #74827f;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        transition: color 0.25s ease;
    }

    .refine-search.has-filters .refine-toggle-hint {
        color: #0d6d6c;
        font-weight: 500;
    }

    .refine-toggle-count {
        flex: none;
        min-width: 22px;
        height: 22px;
        padding: 0 7px;
        border-radius: 999px;
        background: #3eb3a5;
        color: #fff;
        font-size: 0.74rem;
        font-weight: 700;
        line-height: 22px;
        text-align: center;
        box-sizing: border-box;
        box-shadow: 0 0 0 3px rgba(62, 179, 165, 0.16);
    }

    .refine-toggle-count[hidden] {
        display: none;
    }

    .refine-toggle-count.is-popping {
        animation: refineCountPop 0.42s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    .refine-toggle-chevron {
        flex: none;
        width: 30px;
        height: 30px;
        display: grid;
        place-items: center;
        border-radius: 50%;
        background: rgba(13, 109, 108, 0.07);
        color: #0d6d6c;
        transition:
            transform 0.45s cubic-bezier(0.22, 1, 0.36, 1),
            background-color 0.25s ease;
    }

    .refine-toggle-chevron svg {
        width: 15px;
        height: 15px;
    }

    .refine-search.is-open .refine-toggle-chevron {
        transform: rotate(180deg);
        background: rgba(62, 179, 165, 0.16);
    }

    /* The Map button: a square card to the right; teal when the map is showing */
    .refine-map-toggle {
        position: relative;
        flex: none;
        width: 62px;
        min-height: 56px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        padding: 0;
        border: 1px solid rgba(13, 109, 108, 0.16);
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.82);
        box-shadow:
            0 1px 2px rgba(15, 40, 38, 0.05),
            0 6px 16px -8px rgba(13, 109, 108, 0.28);
        color: #0d6d6c;
        font: inherit;
        cursor: pointer;
        box-sizing: border-box;
        overflow: hidden;
        isolation: isolate;
        -webkit-tap-highlight-color: transparent;
        touch-action: manipulation;
        transition:
            border-color 0.3s ease,
            box-shadow 0.3s ease,
            color 0.3s ease,
            transform 0.16s ease;
    }

    /* The teal fill fades in underneath rather than snapping on */
    .refine-map-toggle::before {
        content: '';
        position: absolute;
        inset: 0;
        z-index: -1;
        background: linear-gradient(140deg, #4cc2b3 0%, #1f9488 55%, #0d6d6c 100%);
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .refine-map-toggle:active {
        transform: scale(0.95);
    }

    .refine-map-toggle:focus-visible {
        outline: none;
        border-color: #3eb3a5;
        box-shadow:
            0 0 0 3px rgba(62, 179, 165, 0.28),
            0 6px 16px -8px rgba(13, 109, 108, 0.28);
    }

    .refine-map-toggle[aria-pressed="true"] {
        border-color: transparent;
        color: #fff;
        box-shadow:
            0 1px 2px rgba(15, 40, 38, 0.08),
            0 10px 22px -10px rgba(13, 109, 108, 0.75),
            inset 0 1px 0 rgba(255, 255, 255, 0.25);
    }

    .refine-map-toggle[aria-pressed="true"]::before {
        opacity: 1;
    }

    .refine-map-icon {
        width: 23px;
        height: 23px;
        overflow: visible;
    }

    .refine-map-icon .refine-pin {
        fill: #fff;
        transition: fill 0.3s ease;
    }

    .refine-map-icon .refine-pin circle {
        fill: currentColor;
        stroke: none;
    }

    .refine-map-toggle[aria-pressed="true"] .refine-pin {
        fill: #0d6d6c;
    }

    .refine-map-toggle[aria-pressed="true"] .refine-pin circle {
        fill: #fff;
    }

    /* The pin drops onto the map as it opens */
    .refine-map-toggle.is-dropping .refine-pin {
        animation: refinePinDrop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
    }

    .refine-map-label {
        font-size: 0.7rem;
        font-weight: 600;
        line-height: 1;
        letter-spacing: 0.02em;
    }

    /* The map: folded away until the Map button is on, then it pops open in place.
       Only its frame folds; the map inside keeps its full size the whole time, so it
       never has to lay its tiles out again. */
    [data-refine-map] {
        overflow: hidden;
        transform-origin: 50% 0;
        transition:
            height 0.5s cubic-bezier(0.22, 1, 0.36, 1),
            margin 0.5s cubic-bezier(0.22, 1, 0.36, 1),
            opacity 0.3s ease,
            transform 0.55s cubic-bezier(0.34, 1.3, 0.64, 1),
            visibility 0s linear 0s;
    }

    html:not(.refine-map-open) [data-refine-map] {
        opacity: 0;
        transform: translateY(-6px) scale(0.96);
        visibility: hidden;
        transition:
            height 0.42s cubic-bezier(0.22, 1, 0.36, 1),
            margin 0.42s cubic-bezier(0.22, 1, 0.36, 1),
            opacity 0.25s ease,
            transform 0.42s cubic-bezier(0.22, 1, 0.36, 1),
            visibility 0s linear 0.42s;
    }

    /* Conference Navigator: the map card above the results */
    .map-section[data-refine-map] #advanced-world-map {
        height: 250px;
        /* Round the corners for the map's tile and pin layers too, which a plain
           border-radius doesn't always clip */
        clip-path: inset(0 round 16px);
    }

    html:not(.refine-map-open) .map-section[data-refine-map] {
        height: 0 !important;
        margin-bottom: -1rem; /* takes back the gap to the results */
    }

    /* Professional Circles: the mini map under the filters */
    .search-controls-right[data-refine-map] {
        min-height: 0;
        height: 200px;
    }

    .search-controls-right[data-refine-map] #people-mini-map {
        inset: 0 0 auto 0;
        height: 200px;
        clip-path: inset(0 round 10px);
    }

    html:not(.refine-map-open) .search-controls-right[data-refine-map] {
        height: 0;
        margin-top: -0.85rem; /* takes back the gap under the filters */
    }

    html.refine-map-no-motion [data-refine-map] {
        transition: none;
    }

    /* The drawer: rolls open to the height of the filters inside it */
    .refine-drawer {
        display: grid;
        grid-template-rows: 0fr;
        transition: grid-template-rows 0.45s cubic-bezier(0.22, 1, 0.36, 1);
    }

    .refine-search.is-open .refine-drawer {
        grid-template-rows: 1fr;
    }

    /* A little side room so the menus' focus rings aren't clipped */
    .refine-drawer-inner {
        display: block;
        min-height: 0;
        overflow: hidden;
        margin: 0 -4px;
        padding: 0 4px;
        visibility: hidden;
        transition: visibility 0s linear 0.45s;
    }

    .refine-search.is-open .refine-drawer-inner {
        visibility: visible;
        transition-delay: 0s;
    }

    .refine-drawer-inner > .filters-grid {
        padding: 0.65rem 0 4px;
    }

    /* Folded away: the quick switches go with the menus, and the selected-filters line
       only stays when something is selected, so the chosen filters are always in view */
    .search-controls:not(.refine-open) .quick-filters {
        display: none;
    }

    .search-controls:not(.refine-open):not(.refine-has-badges) .filter-controls {
        display: none;
    }

    /* While it opens (js adds .refine-opening for a moment) the menus drift in one after
       another. Only the buttons move, never the menus around them, so the sheets they
       open stay pinned to the screen. */
    .search-controls.refine-opening .filter-menu-trigger {
        animation: refineItemIn 0.45s cubic-bezier(0.22, 1, 0.36, 1) backwards;
    }

    .search-controls.refine-opening .filter-menu:nth-child(1) .filter-menu-trigger { animation-delay: 0.05s; }
    .search-controls.refine-opening .filter-menu:nth-child(2) .filter-menu-trigger { animation-delay: 0.09s; }
    .search-controls.refine-opening .filter-menu:nth-child(3) .filter-menu-trigger { animation-delay: 0.13s; }
    .search-controls.refine-opening .filter-menu:nth-child(4) .filter-menu-trigger { animation-delay: 0.17s; }
    .search-controls.refine-opening .filter-menu:nth-child(5) .filter-menu-trigger { animation-delay: 0.21s; }
    .search-controls.refine-opening .filter-menu:nth-child(6) .filter-menu-trigger { animation-delay: 0.25s; }

    .search-controls.refine-opening .quick-filters {
        animation: refineItemIn 0.45s cubic-bezier(0.22, 1, 0.36, 1) 0.27s backwards;
    }

    .search-controls.refine-opening:not(.refine-has-badges) .filter-controls {
        animation: refineFadeIn 0.4s ease 0.2s backwards;
    }

    /* First paint with the drawer already open (coming back to the page): no roll-down */
    .refine-search.no-motion .refine-drawer,
    .refine-search.no-motion .refine-drawer-inner,
    .refine-search.no-motion .refine-toggle-chevron,
    .refine-search.no-motion .refine-knob {
        transition: none;
    }

    /* The narrowest phones: a slightly tighter button so the hint still fits */
    @media (max-width: 360px) {
        .refine-toggle {
            gap: 0.6rem;
            padding-left: 0.5rem;
            padding-right: 0.55rem;
        }

        /* The sliders tile steps aside so the title and hint keep one line each */
        .refine-toggle-icon {
            display: none;
        }

        .refine-toggle-text {
            padding-left: 0.35rem;
        }

        .refine-toggle-hint {
            font-size: 0.7rem;
        }

        /* No room for the bubble; the hint already says how many filters are on */
        .refine-toggle-count {
            display: none;
        }

        .refine-toggle-chevron {
            width: 26px;
            height: 26px;
        }

        .refine-bar {
            gap: 0.4rem;
        }

        .refine-map-toggle {
            width: 50px;
        }
    }

    @keyframes refineItemIn {
        from {
            opacity: 0;
            transform: translateY(-8px);
        }
        to {
            opacity: 1;
            transform: none;
        }
    }

    @keyframes refineFadeIn {
        from { opacity: 0; }
        to { opacity: 1; }
    }

    @keyframes refinePinDrop {
        0% { transform: translateY(-7px); opacity: 0; }
        45% { opacity: 1; }
        100% { transform: none; }
    }

    @keyframes refineCountPop {
        0% { transform: scale(0.6); }
        60% { transform: scale(1.15); }
        100% { transform: scale(1); }
    }

    @media (prefers-reduced-motion: reduce) {
        .refine-toggle,
        .refine-drawer,
        .refine-drawer-inner,
        .refine-toggle-chevron,
        .refine-knob,
        .refine-map-toggle,
        .refine-map-toggle::before,
        [data-refine-map],
        html:not(.refine-map-open) [data-refine-map] {
            transition: none;
        }

        .search-controls.refine-opening .filter-menu-trigger,
        .search-controls.refine-opening .quick-filters,
        .search-controls.refine-opening .filter-controls,
        .refine-toggle-count.is-popping,
        .refine-map-toggle.is-dropping .refine-pin {
            animation: none;
        }
    }
}
