/* Final header overrides: the search icon always occupies the top action row.
   The input expands beside its button when the row has room, otherwise below. */
.header .container.header-top-row {
    position: relative !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) auto auto !important;
    grid-template-rows: auto !important;
    grid-template-areas: "primary search actions" !important;
    align-items: center !important;
    gap: 10px !important;
}
.header .header-primary { grid-area: primary !important; min-width: 0; }
.header .actions { grid-area: actions !important; }
.header #headerSearch {
    grid-area: search !important;
    display: block !important;
    position: static !important;
    inset: auto !important;
    transform: none !important;
    width: 40px !important;
    min-width: 40px !important;
    max-width: 40px !important;
    height: 40px !important;
    z-index: 5 !important;
}
.header #headerSearch .search-form,
.header #headerSearch.is-open .search-form {
    display: block !important;
    position: static !important;
    inset: auto !important;
    transform: none !important;
    width: 40px !important;
    min-width: 0 !important;
    height: 40px !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: auto !important;
    overflow: visible !important;
}
.header #headerSearch .search-toggle {
    display: grid !important;
    place-items: center;
    position: static !important;
    width: 40px !important;
    min-width: 40px !important;
    height: 40px !important;
    padding: 0 !important;
    color: var(--ts-text, var(--text-primary)) !important;
    background: transparent !important;
    border: 1px solid var(--ts-border, var(--border-color)) !important;
    border-radius: 12px !important;
    cursor: pointer;
}
.header #headerSearch .search-toggle:hover,
.header #headerSearch.is-open .search-toggle {
    background: color-mix(in srgb, var(--accent, #22d3ee) 12%, transparent) !important;
}
.header .header-search-panel {
    position: absolute;
    left: var(--search-fallback-left, 0px);
    right: auto;
    top: calc(100% + 8px);
    width: min(380px, 100%, var(--search-fallback-width, 380px));
    padding: 10px;
    border: 1px solid var(--ts-border, var(--border-color, #526174));
    border-radius: 14px;
    background: var(--ts-surface, var(--card-bg, #fff));
    box-shadow: var(--ts-shadow-soft, 0 12px 32px rgba(0, 0, 0, .12));
    transform: translateY(-8px) scaleY(.9);
    transform-origin: var(--search-origin-x, 20px) top;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: transform .28s ease, clip-path .28s ease, opacity .2s ease, visibility .28s;
}
.header #headerSearch.is-open .header-search-panel {
    transform: translateX(0) scaleX(1);
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}
.header #headerSearchPanel #headerSearchInput {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    height: 42px !important;
    min-height: 42px !important;
    padding: 0 12px !important;
    border: 1px solid var(--ts-border, var(--border-color, #526174)) !important;
    border-radius: 9px !important;
    background: var(--ts-surface-soft, var(--card-bg, #fff)) !important;
    color: var(--ts-text, var(--text-primary)) !important;
    font-size: 16px !important;
}
.header .header-search-panel input:focus-visible,
.header #headerSearch .search-toggle:focus-visible {
    outline: 2px solid var(--accent, #22d3ee);
    outline-offset: 3px;
}
/* Reserve the input's space; it must never cover navigation or account actions. */
.header #headerSearch.is-inline {
    position: relative !important;
    max-width: none !important;
    transition: width .28s ease;
}
.header #headerSearch.is-inline.is-open { width: calc(48px + var(--search-panel-width)) !important; }
.header #headerSearch.is-inline .search-form { width: 100% !important; position: relative !important; }
.header #headerSearch.is-inline .search-toggle { position: absolute !important; left: 0; top: 0; }
.header #headerSearch.is-inline .header-search-panel {
    left: 48px;
    right: auto;
    top: 0;
    width: var(--search-panel-width);
    height: 40px;
    padding: 0;
    border: 0;
    box-shadow: none;
    transform: translateX(-12px);
    transform-origin: left center;
    clip-path: inset(0 100% 0 0);
}
.header #headerSearch.is-inline.is-open .header-search-panel { transform: none; clip-path: inset(0); }
.header #headerSearch.is-inline #headerSearchPanel #headerSearchInput { height: 40px !important; min-height: 40px !important; }
/* Legacy theme rules for the form must not paint a dark box in the light header. */
.header #headerSearch .search-form { background: transparent !important; box-shadow: none !important; }
.header #headerSearchPanel #headerSearchInput::placeholder { color: var(--ts-muted) !important; opacity: 1 !important; }
@media (max-width: 900px) {
    .header .container.header-top-row {
        grid-template-columns: 36px minmax(0, 1fr) auto auto !important;
        grid-template-areas: "toggle logo search actions" !important;
        grid-template-rows: auto !important;
        gap: 4px !important;
    }
    .header .header-primary { display: contents !important; }
    .header .logo { grid-area: logo !important; overflow: hidden; }
    .header .nav-toggle { grid-area: toggle !important; min-width: 36px !important; width: 36px !important; }
    .header .actions { gap: 2px !important; }
}
@media (max-width: 390px) {
    .header .actions > a,
    .header .actions > button,
    .header .actions .cart-action,
    .header .actions .theme-toggle,
    .header .actions .bell-btn {
        min-width: 29px !important;
        width: 29px !important;
        height: 36px !important;
    }
    .header .logo-img { max-width: 100% !important; }
    .header .logo-site-name { max-width: 100%; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
    .header .header-search-panel, .header #headerSearch.is-inline { transition: none; }
    .header .header-search-panel { transform: none; }
}
