/**
 * Fullscreen overlay for the native WooCommerce Product Search block
 * (core/search block, buttonPosition = "button-only", used in the header
 * template part). The block already ships an accessible expand/collapse
 * behaviour driven by the WordPress Interactivity API: it toggles the
 * "wp-block-search__searchfield-hidden" class on the form and reflects the
 * open state through the button's aria-expanded attribute.
 *
 * IMPORTANT: the fullscreen overlay styles below are intentionally keyed to
 * "html.has-search-overlay-open", a class the JS enhancement adds/removes -
 * NOT to the form's own "wp-block-search__searchfield-hidden" class. If we
 * keyed off the form's own class directly, the overlay would vanish the
 * instant WordPress toggles that class, and the block's own default
 * (non-overlay) transition would then play at full viewport size before
 * shrinking into the header - a visible glitch. Routing through a class the
 * JS owns lets the JS also kill transitions for one frame on close (see
 * ".has-search-overlay-no-transition" below), so nothing animates at all
 * when the overlay is dismissed.
 *
 * Closed state : html without .has-search-overlay-open
 * Open state   : html.has-search-overlay-open
 */

/* Trigger icon button (closed state) - align with header, editorial style. */
.wp-block-search__button-only .wp-block-search__button {
    border: 1px solid transparent;
    background: transparent;
    color: currentColor;
    padding: .5rem;
    transition: opacity 150ms ease;
}

.wp-block-search__button-only .wp-block-search__button:hover,
.wp-block-search__button-only .wp-block-search__button:focus-visible {
    opacity: 0.7;
}

/* -------------------------------------------------------------------- */
/* Fullscreen overlay - open state                                     */
/* -------------------------------------------------------------------- */
html.has-search-overlay-open .wp-block-search__button-only {
    position: fixed !important;
    inset: 0 !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    z-index: 999999;
    display: flex !important;
    flex-direction: column;
    background: var(--wp--preset--color--secondary);
    color: var(--wp--preset--color--primary);
    overflow-y: auto;
    animation: fixandgo-search-overlay-in 180ms ease;
}

@supports (height: 100dvh) {
    html.has-search-overlay-open .wp-block-search__button-only {
        height: 100dvh !important;
    }
}

@keyframes fixandgo-search-overlay-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__inside-wrapper {
    display: flex;
    flex: 0;
    flex-direction: column;
    justify-content: flex-start;
    align-items: stretch;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 96px 32px 32px;
    box-sizing: border-box;
    position: relative;
}

html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__label {
    position: static;
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--wp--preset--color--muted);
    margin-bottom: 16px;
    clip: auto;
    width: auto;
    height: auto;
}

html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__input {
    width: 100% !important;
    min-width: 0 !important;
    flex: 1 1 auto;
    order: 1;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--wp--preset--color--hairline);
    border-radius: 0;
    padding: 12px 0 !important;
    margin: 0 !important;
    font-size: 25px;
    line-height: 1.2;
    color: var(--wp--preset--color--primary);
    transition: border-color 200ms ease;
    -webkit-appearance: none;
    appearance: none;
}

html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__input::placeholder {
    color: var(--wp--preset--color--muted);
}

html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__input:focus {
    outline: none;
    border-color: var(--wp--preset--color--primary);
}

html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__button {
    order: 2;
    align-self: flex-end;
    margin-top: 16px;
    border: 1px solid var(--wp--preset--color--primary);
    background: var(--wp--preset--color--primary);
    color: var(--wp--preset--color--secondary);
    padding: 12px 24px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 12px;
    transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}

/*
 * Explicit close (X) control and ESC hint, injected once by the JS
 * enhancement. Both controls only ever make sense while the overlay is
 * open, so they are hidden by default and only revealed by the scoped
 * rules below.
 */
.fixandgo-search-overlay-close,
.fixandgo-search-overlay-hint {
    display: none;
}

html.has-search-overlay-open .wp-block-search__button-only .fixandgo-search-overlay-close {
    position: absolute;
    top: 24px;
    right: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid var(--wp--preset--color--hairline);
    background: transparent;
    color: var(--wp--preset--color--primary);
    cursor: pointer;
    transition: border-color 150ms ease, opacity 150ms ease;
}

html.has-search-overlay-open .wp-block-search__button-only .fixandgo-search-overlay-close:hover,
html.has-search-overlay-open .wp-block-search__button-only .fixandgo-search-overlay-close:focus-visible {
    border-color: var(--wp--preset--color--primary);
    opacity: 0.7;
}

.fixandgo-search-overlay-close svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.5;
}

html.has-search-overlay-open .wp-block-search__button-only .fixandgo-search-overlay-hint {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--wp--preset--color--muted);
    margin-top: 24px;
}

.wp-block-search__button svg {
    fill: currentColor;
    height: 30px;
    min-height: 30px;
    min-width: 30px;
    vertical-align: text-bottom;
    width: 30px;
}

/*
 * Hard kill-switch for close: the JS adds this class for exactly one frame
 * right before it removes "has-search-overlay-open", so that neither our
 * own entrance keyframe nor WordPress' own default (non-overlay) transition
 * on the block gets a chance to animate. Without this, the instant the
 * overlay class is removed the element falls back to the block's native
 * collapsed-state CSS, which has its own transition and would otherwise
 * visibly play out in the header.
 */
html.has-search-overlay-no-transition .wp-block-search__button-only,
html.has-search-overlay-no-transition .wp-block-search__button-only * {
    transition: none !important;
    animation: none !important;
}

/* Desktop: show the keyboard hint, give the field more breathing room. */
@media (min-width: 768px) {
    html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__inside-wrapper {
        padding: 140px 64px 64px;
    }

    html.has-search-overlay-open .wp-block-search__button-only .fixandgo-search-overlay-hint {
        display: block;
    }
}

/* Mobile: dedicated layout, not just a shrunk desktop version. */
@media (max-width: 767.98px) {
    html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__inside-wrapper {
        padding: 72px 20px 24px;
    }

    html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__label {
        margin-bottom: 12px;
    }

    html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__input {
        font-size: 22px;
        padding: 10px 0 !important;
    }

    html.has-search-overlay-open .wp-block-search__button-only .wp-block-search__button {
        width: 100%;
        align-self: stretch;
        margin-top: 24px;
        padding: 14px 24px;
    }

    html.has-search-overlay-open .wp-block-search__button-only .fixandgo-search-overlay-close {
        top: 16px;
        right: 16px;
        width: 44px;
        height: 44px;
    }
}

@media (prefers-reduced-motion: reduce) {
    html.has-search-overlay-open .wp-block-search__button-only {
        animation: none;
    }
}
