/* ==========================================================================
   Search modal (centered dialog with blurred backdrop)
   Scoped to #header-search-drawer so it overrides the older drawer styles.
   ========================================================================== */

#header-search-drawer.search-modal {
    --smodal-bg: var(--smodal-bg-light, #ffffff);
    --smodal-text: var(--smodal-text-light, #333333);
    --smodal-muted: rgba(51, 51, 51, 0.6);
    --smodal-line: rgba(51, 51, 51, 0.12);
    --smodal-soft: rgba(0, 0, 0, 0.048);
    --smodal-soft-2: rgba(0, 0, 0, 0.064);
    --smodal-hover: rgba(0, 0, 0, 0.1);

    display: none;
    position: fixed;
    inset: 0;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 1060;
    padding: 16vh 28px 32px;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    overflow-y: auto;
    background: transparent;
    color: var(--smodal-text);
    box-shadow: none;
    transform: none;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transition: none;
}

#header-search-drawer.search-modal.show {
    display: flex;
}

body.dark #header-search-drawer.search-modal {
    --smodal-bg: var(--smodal-bg-dark, var(--dark-body-bg, #1a1a1a));
    --smodal-text: var(--smodal-text-dark, var(--dark-body-text, #e0e0e0));
    --smodal-muted: rgba(255, 255, 255, 0.6);
    --smodal-line: rgba(255, 255, 255, 0.12);
    --smodal-soft: rgba(255, 255, 255, 0.07);
    --smodal-soft-2: rgba(255, 255, 255, 0.09);
    --smodal-hover: rgba(255, 255, 255, 0.14);
}

body.search-drawer-open {
    overflow: hidden;
}

/* Backdrop */
#header-search-drawer .smodal__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(14, 14, 18, 0.52);
    -webkit-backdrop-filter: saturate(1.3) blur(5px);
    backdrop-filter: saturate(1.3) blur(5px);
}

/* Dialog */
#header-search-drawer .smodal__dialog {
    position: relative;
    z-index: 1;
    width: min(820px, 100%);
    max-height: 78vh;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--smodal-bg);
    color: var(--smodal-text);
    border-radius: 10px;
    box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28), 0 0 0 1px rgba(0, 0, 0, 0.06);
}

#header-search-drawer.show .smodal__backdrop {
    animation: smodal-backdrop-in 0.28s ease both;
}

#header-search-drawer.show .smodal__dialog {
    animation: smodal-dialog-in 0.34s cubic-bezier(0.22, 1, 0.36, 1) both;
}

@keyframes smodal-backdrop-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes smodal-dialog-in {
    from { opacity: 0; transform: scale(0.94) translateY(-28px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    #header-search-drawer.show .smodal__backdrop,
    #header-search-drawer.show .smodal__dialog {
        animation: none;
    }
}

/* Sections */
#header-search-drawer .smodal__section {
    padding: 0 28px;
}

#header-search-drawer .smodal__section + .smodal__section {
    border-top: 1px solid var(--smodal-line);
}

#header-search-drawer .smodal__top {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding-top: 18px;
    padding-bottom: 10px;
}

#header-search-drawer .smodal__search-col {
    flex: 1 1 0%;
    min-width: 0;
    position: relative;
}

/* Search field */
#header-search-drawer .smodal__field {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 44px;
    margin: 0;
    padding: 0 14px;
    background: var(--smodal-soft);
    border: 1px solid var(--smodal-line);
    border-radius: 6px;
    transition: border-color 0.2s ease, background-color 0.2s ease;
}

#header-search-drawer .smodal__field:focus-within {
    border-color: var(--primary-color, #222222);
}

#header-search-drawer .smodal__submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    opacity: 0.88;
    cursor: pointer;
}

#header-search-drawer .smodal__input {
    flex: 1 1 0%;
    min-width: 0;
    height: 40px;
    padding: 0;
    margin: 0;
    font-size: 15px;
    line-height: 1.35;
    color: var(--smodal-text);
    background: transparent;
    border: 0;
    border-radius: 0;
    outline: none;
    box-shadow: none;
}

#header-search-drawer .smodal__input::placeholder {
    color: var(--smodal-muted);
}

/* Close button */
#header-search-drawer .smodal__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: var(--smodal-soft-2);
    color: var(--smodal-text);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

/* Quick suggestions */
#header-search-drawer .smodal__suggestions {
    padding-top: 16px;
    padding-bottom: 16px;
}

#header-search-drawer .smodal__title {
    margin: 0 0 12px;
    font-size: 18px;
    font-weight: 700;
    line-height: 1.25;
    color: var(--smodal-text);
}

#header-search-drawer .smodal__chips-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

#header-search-drawer .smodal__trend-icon {
    flex-shrink: 0;
    opacity: 0.8;
}

#header-search-drawer .smodal__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-width: 0;
}

#header-search-drawer .search-trending-chip {
    display: inline-block;
    margin: 0;
    padding: 6px 12px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    color: var(--smodal-text);
    background: var(--smodal-soft-2);
    border: 0;
    border-radius: 4px;
    text-decoration: none;
    transition: background-color 0.2s ease, color 0.2s ease;
}

#header-search-drawer .search-chip-skeleton {
    width: 64px;
    height: 30px;
    border-radius: 4px;
    background: var(--smodal-soft-2);
}

/* Banners / trending products */
#header-search-drawer .smodal__tiles {
    padding-top: 22px;
    padding-bottom: 24px;
}

#header-search-drawer .smodal__banners {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

#header-search-drawer .smodal__banners--single {
    grid-template-columns: 1fr;
}

#header-search-drawer .smodal__banner {
    position: relative;
    display: block;
    overflow: hidden;
    aspect-ratio: 2 / 1;
    border-radius: 6px;
    background: var(--smodal-soft);
}

#header-search-drawer .smodal__banners--single .smodal__banner {
    aspect-ratio: 4 / 1;
}

#header-search-drawer .smodal__banner img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.6s cubic-bezier(0.22, 1, 0.36, 1);
}

#header-search-drawer .smodal__banner::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.28) 50%, transparent 65%);
    transform: translateX(-130%) skewX(-12deg);
    pointer-events: none;
}

#header-search-drawer .smodal__products {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

/* Live results */
#header-search-drawer .smodal__results {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    width: 100%;
    max-height: 360px;
    margin-top: 8px;
    padding: 0;
    overflow-y: auto;
    background: var(--smodal-bg);
    border: 1px solid var(--smodal-line);
    border-radius: 6px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.08);
    z-index: auto;
}

#header-search-drawer .smodal__results .autocomplete-product-link {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 10px 12px;
    margin: 0;
    color: var(--smodal-text);
    background: transparent;
    border: 0;
    border-bottom: 1px solid var(--smodal-line);
    border-radius: 0;
    box-shadow: none;
    text-decoration: none;
    transition: background-color 0.2s ease;
}

#header-search-drawer .smodal__results .autocomplete-product-link:last-child {
    border-bottom: 0;
}

#header-search-drawer .smodal__results .autocomplete-product-image-wrapper {
    flex: 0 0 56px;
    width: 56px;
    height: 72px;
    margin: 0;
    overflow: hidden;
    border-radius: 4px;
    background: var(--smodal-soft);
    aspect-ratio: auto;
}

#header-search-drawer .smodal__results .autocomplete-product-image {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#header-search-drawer .smodal__results .autocomplete-product-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 0;
    padding: 0;
    text-align: start;
}

#header-search-drawer .smodal__results .autocomplete-product-name {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.35;
    color: inherit;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    white-space: normal;
    transition: color 0.2s ease;
}

#header-search-drawer .smodal__results .autocomplete-product-price {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

#header-search-drawer .smodal__results .autocomplete-price-current {
    font-weight: 600;
    color: var(--smodal-text);
}

#header-search-drawer .smodal__results .autocomplete-price-old {
    font-weight: 400;
    color: var(--smodal-muted);
    text-decoration: line-through;
}

#header-search-drawer .smodal__results .autocomplete-empty,
#header-search-drawer .smodal__results .autocomplete-loading {
    padding: 24px 12px;
    text-align: center;
    color: var(--smodal-muted);
}

/* Hover (pointer devices only) */
@media (hover: hover) and (pointer: fine) {
    #header-search-drawer .smodal__close:hover,
    #header-search-drawer .search-trending-chip:hover {
        background: var(--smodal-hover);
    }

    #header-search-drawer .search-trending-chip:hover {
        color: var(--primary-color, inherit);
    }

    #header-search-drawer .smodal__results .autocomplete-product-link:hover {
        background: var(--smodal-soft);
    }

    #header-search-drawer .smodal__results .autocomplete-product-link:hover .autocomplete-product-name {
        color: var(--primary-color, inherit);
    }

    #header-search-drawer .smodal__banner:hover img {
        transform: scale(1.04);
    }

    #header-search-drawer .smodal__banner:hover::after {
        transform: translateX(130%) skewX(-12deg);
        transition: transform 0.9s ease;
    }
}

/* Mobile: full-screen sheet */
@media (max-width: 767.98px) {
    #header-search-drawer.search-modal {
        padding: 0;
    }

    #header-search-drawer .smodal__dialog {
        width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    #header-search-drawer .smodal__section {
        padding-left: 16px;
        padding-right: 16px;
    }

    #header-search-drawer .smodal__title {
        font-size: 16px;
    }

    #header-search-drawer .smodal__banners {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    #header-search-drawer .smodal__products {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    #header-search-drawer .smodal__results {
        max-height: none;
    }
}

/* Suggestion chips follow the theme's primary color */
#header-search-drawer .search-trending-chip {
    color: var(--primary-color, #222);
    background: color-mix(in srgb, var(--primary-color, #222) 10%, transparent);
}

#header-search-drawer .smodal__trend-icon {
    color: var(--primary-color, currentColor);
    opacity: 1;
}

@media (hover: hover) and (pointer: fine) {
    #header-search-drawer .search-trending-chip:hover {
        background: var(--primary-color, #222);
        color: var(--text-color-primary-bg, #fff);
    }
}

body.dark #header-search-drawer .search-trending-chip {
    color: #f2f2f2;
    background: color-mix(in srgb, var(--primary-color, #222) 35%, transparent);
}
