/**
 * Modern Search Bar - Header Overlay
 * Transforms the native expandable search into a full-width pill overlay.
 */

/* 1. Elevate the header above the backdrop when search is open OR closing */
header:has(.wp-block-search__button-only:is(:not(.wp-block-search__searchfield-hidden), .is-closing)) {
    position: relative;
    z-index: 9999;
}

/* 2. Full-Screen Cinematic Backdrop */
body:has(.wp-block-search__button-only:is(:not(.wp-block-search__searchfield-hidden), .is-closing))::after {
    content: '';
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(4px);
    z-index: 9998;
    animation: vortex-backdrop-fade 0.3s ease-out forwards;
}

/* Fade backdrop out when closing */
body:has(.wp-block-search__button-only.is-closing)::after {
    animation: vortex-backdrop-fade-out 0.3s ease-out forwards;
}

/* 3. Kill Native Gutenberg Animations */
.wp-block-search__button-only,
.wp-block-search__button-only .wp-block-search__inside-wrapper,
.wp-block-search__button-only .wp-block-search__input {
    transition: none !important;
    animation: none !important;
}

/* 4. The Expanded Overlay Container (Covers the header entirely) */
.wp-block-search__button-only:is(:not(.wp-block-search__searchfield-hidden), .is-closing) {
    position: absolute;
    inset: 0;
    background-color: var(--wp--preset--color--base, #000000);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 2rem;
    transition: background-color 0.3s ease !important;
}

/* Fade out the solid header background smoothly */
.wp-block-search__button-only.is-closing {
    background-color: transparent !important;
}

/* 5. The Pill Wrapper */
.wp-block-search__button-only:is(:not(.wp-block-search__searchfield-hidden), .is-closing) .wp-block-search__inside-wrapper {
    width: 100%;
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    border: 2px solid var(--wp--preset--color--accent-3, #F0F0F0);
    border-radius: 9999px;
    padding: 0.25rem 1rem;
    background-color: transparent;
    animation: vortex-pill-entrance 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
}

/* Pill Exit Animation */
.wp-block-search__button-only.is-closing .wp-block-search__inside-wrapper {
    animation: vortex-pill-exit 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards !important;
}

/* 6. Animations */
@keyframes vortex-backdrop-fade {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes vortex-backdrop-fade-out {
    from {
        opacity: 1;
    }

    to {
        opacity: 0;
    }
}

@keyframes vortex-pill-entrance {
    from {
        opacity: 0;
        transform: translateY(-15px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes vortex-pill-exit {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    to {
        opacity: 0;
        transform: translateY(-15px) scale(0.98);
    }
}

/* 7. Search Toggle Button */
.wp-block-search__button-only .wp-block-search__button {
    border: none !important;
}

.wp-block-search__button-only:is(:not(.wp-block-search__searchfield-hidden), .is-closing) .wp-block-search__button {
    order: -1;
    color: var(--wp--preset--color--accent-3, #F0F0F0) !important;
    margin-right: 0.75rem;
}

.wp-block-search__button-only:is(:not(.wp-block-search__searchfield-hidden), .is-closing) .wp-block-search__button svg {
    fill: currentColor;
    width: 20px;
    height: 20px;
}

/* 8. Input Styling */
.wp-block-search__button-only:is(:not(.wp-block-search__searchfield-hidden), .is-closing) .wp-block-search__input {
    flex-grow: 1;
    background: transparent !important;
    border: none !important;
    color: var(--wp--preset--color--accent-3, #F0F0F0) !important;
    box-shadow: none !important;
    padding: 0 0.5rem !important;
    font-size: 1rem;
}

.wp-block-search__button-only:is(:not(.wp-block-search__searchfield-hidden), .is-closing) .wp-block-search__input:focus {
    outline: none !important;
}

.wp-block-search__button-only:is(:not(.wp-block-search__searchfield-hidden), .is-closing) .wp-block-search__input::placeholder {
    color: var(--wp--preset--color--accent-3, #F0F0F0);
    opacity: 0.6;
}

/* Stylize native clear "X" button (Inner X for clearing text) */
.wp-block-search__button-only .wp-block-search__input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
    height: 16px;
    width: 16px;
    background-color: var(--wp--preset--color--accent-3, #F0F0F0) !important;
    -webkit-mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><line x1='18' y1='6' x2='6' y2='18'></line><line x1='6' y1='6' x2='18' y2='18'></line></svg>");
    mask-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'><line x1='18' y1='6' x2='6' y2='18'></line><line x1='6' y1='6' x2='18' y2='18'></line></svg>");
    -webkit-mask-size: contain;
    mask-size: contain;
    cursor: pointer;
}

/* Ultimate Autofill Hack (Restores transition ONLY for the autofill state) */
.wp-block-search__button-only .wp-block-search__input:-webkit-autofill,
.wp-block-search__button-only .wp-block-search__input:-webkit-autofill:hover,
.wp-block-search__button-only .wp-block-search__input:-webkit-autofill:focus,
.wp-block-search__button-only .wp-block-search__input:-webkit-autofill:active {
    -webkit-text-fill-color: var(--wp--preset--color--accent-3, #F0F0F0) !important;
    transition: background-color 999999s ease-in-out 0s, color 999999s ease-in-out 0s !important;
    background-color: transparent !important;
}

/* 9. Injected Close Button (Outer X for closing the whole bar) */
.vortex-search-close {
    background: transparent;
    border: none;
    color: var(--wp--preset--color--accent-3, #F0F0F0);
    cursor: pointer;
    padding: 0;
    margin-left: 0.75rem;
    margin-right: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.2s ease;
}

.vortex-search-close:hover {
    transform: scale(1.15);

}

/* Hide the custom close button when the search bar is closed */
.wp-block-search__searchfield-hidden:not(.is-closing) .vortex-search-close {
    display: none;
}

/* 10. Align Live Search Dropdown with the Pill */
.wp-block-search__button-only:is(:not(.wp-block-search__searchfield-hidden), .is-closing) .vortex-live-search-dropdown {
    max-width: 800px;
    margin: 0 auto;
    left: 0;
    right: 0;
}