/**
 * IF Header Search (Elementor widget) — product search in the site header.
 * Mockup: kit/pages/поиск_.jpg. The pill mirrors the catalog module's search
 * field (.if-products__search in products-module.css).
 *
 * Colours and sizes are custom properties so the widget's style controls and
 * the dark-header scheme can override them without fighting specificity.
 */

.if-hsearch {
    --if-hs-height: 42px;
    --if-hs-max-width: 380px;
    --if-hs-radius: 9999px;
    --if-hs-bg: transparent;
    --if-hs-border: #a6a5a1;
    --if-hs-border-focus: var(--if-color-primary, #ff0000);
    --if-hs-color: var(--if-color-dark, #111827);
    --if-hs-placeholder: #9a9a98;
    --if-hs-icon: var(--if-color-dark, #111827);
    --if-hs-icon-size: 20px;
    --if-hs-toggle-size: 40px;
    --if-hs-panel-bg: var(--if-color-bg, #f3f4f6);

    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 100%;
}

/* Dark header (homepage, «О компании»): white lines over the hero photo. */
.if-hsearch--dark {
    --if-hs-border: rgba(255, 255, 255, 0.55);
    --if-hs-color: #ffffff;
    --if-hs-placeholder: rgba(255, 255, 255, 0.6);
    --if-hs-icon: #ffffff;
    --if-hs-panel-bg: #111111;
}

/* The widget takes whatever room the header row leaves between the logo and
   the menu (flex-basis 0 + grow), down to the width of the folded icon — the
   script folds it once the room drops below the threshold. An explicit
   «Размер» set in Elementor's Advanced tab is more specific and wins. */
.e-con .elementor-widget-if_header_search,
.elementor-element.elementor-widget-if_header_search {
    --flex-grow: 1;
    --flex-shrink: 1;
    --flex-basis: 0%;
    min-width: 40px;
}

.if-hsearch__form {
    position: relative;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    max-width: var(--if-hs-max-width);
    margin: 0;
}

.if-hsearch__field {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

.if-hsearch .if-hsearch__input {
    display: block;
    width: 100%;
    height: var(--if-hs-height);
    margin: 0;
    /* Right: up to the magnifier (a 20px icon centred in the 42px button at right: 2px). */
    padding: 0 calc(var(--if-hs-height) - 4px) 0 16px;
    border: 1px solid var(--if-hs-border);
    border-radius: var(--if-hs-radius);
    background: var(--if-hs-bg);
    box-shadow: none;
    color: var(--if-hs-color);
    font-family: var(--if-font-body, Inter, sans-serif);
    font-size: 13px;
    letter-spacing: 0.04em;
    line-height: normal;
    outline: none;
    -webkit-appearance: none;
    appearance: none;
    transition: border-color 0.2s ease;
}

/* Probe for header-search.js: the placeholder's text in the placeholder's
   typography (this rule = the input's, the next one = the placeholder's; the
   widget's typography controls target it too), to tell whether it fits. */
.if-hsearch .if-hsearch__measure {
    position: absolute;
    top: 0;
    left: 0;
    visibility: hidden;
    pointer-events: none;
    white-space: nowrap;
    font-family: var(--if-font-body, Inter, sans-serif);
    font-size: 13px;
    letter-spacing: 0.04em;
}

.if-hsearch .if-hsearch__input::placeholder,
.if-hsearch .if-hsearch__measure {
    color: var(--if-hs-placeholder);
    opacity: 1;
    text-transform: uppercase;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.15em;
}

.if-hsearch .if-hsearch__input:focus {
    border-color: var(--if-hs-border-focus);
}

/* The placeholder does not fit (07.10: «ПОИСК ПО КАТАЛО» in the 200px slot of the
   header at 1366–1920px): letters closer first, then header-search.js swaps in
   the widget's short placeholder. */
.if-hsearch.is-ph-tight .if-hsearch__input::placeholder,
.if-hsearch.is-ph-tight .if-hsearch__measure {
    letter-spacing: 0;
}

/* The native «×» of type=search clashes with the pill; Esc clears it anyway. */
.if-hsearch .if-hsearch__input::-webkit-search-cancel-button,
.if-hsearch .if-hsearch__input::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
}

/* Bare icon buttons. !important defeats the parent theme's and the Elementor
   kit's global button styling (border, fill, hover colours). */
.if-hsearch .if-hsearch__btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: var(--if-hs-height);
    height: var(--if-hs-height);
    margin: 0;
    padding: 0;
    background: none !important;
    border: 0 !important;
    border-radius: 50%;
    box-shadow: none !important;
    color: var(--if-hs-icon) !important;
    cursor: pointer;
    -webkit-appearance: none;
    appearance: none;
}

.if-hsearch .if-hsearch__btn:focus-visible {
    outline: 2px solid var(--if-hs-border-focus);
    outline-offset: 2px;
}

.if-hsearch .if-hsearch__btn svg {
    display: block;
    width: var(--if-hs-icon-size);
    height: var(--if-hs-icon-size);
}

.if-hsearch .if-hsearch__submit {
    position: absolute;
    top: 0;
    right: 2px;
}

.if-hsearch .if-hsearch__toggle {
    width: var(--if-hs-toggle-size);
    height: var(--if-hs-toggle-size);
}

.if-hsearch__toggle,
.if-hsearch__close {
    display: none !important;
}

/* ── Folded: magnifier icon only ─────────────────────────────────────────
   .is-compact is set by header-search.js when the slot is narrower than the
   widget's threshold. On phones the icon is shown by CSS alone, so the field
   does not flash squeezed before the script runs. */
.if-hsearch.is-compact {
    justify-content: flex-end;
}

.if-hsearch.is-compact .if-hsearch__toggle {
    display: inline-flex !important;
}

.if-hsearch.is-compact .if-hsearch__form {
    display: none;
}

@media (max-width: 767px) {
    .if-hsearch {
        justify-content: flex-end;
    }

    .if-hsearch .if-hsearch__toggle {
        display: inline-flex !important;
    }

    .if-hsearch:not(.is-open) .if-hsearch__form {
        display: none;
    }
}

/* ── Opened from the icon: a bar across the top of the screen ────────── */
.if-hsearch.is-open .if-hsearch__form {
    display: flex;
    position: fixed;
    top: var(--wp-admin--admin-bar--height, 0px);
    left: 0;
    right: 0;
    z-index: 10000;
    max-width: none;
    padding: 12px 16px;
    background: var(--if-hs-panel-bg);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.if-hsearch.is-open .if-hsearch__close {
    display: inline-flex !important;
}
