/* =============================================================================
   search.css  —  Herb & House Search Module
   -----------------------------------------------------------------------------
   Component: live search dropdown + mobile search modal + results page
   Single responsibility: search-related styles only. Nothing else.

   Anatomy:
     .hh-search              — wrapper around the search input + dropdown
     .hh-search__input       — the input element (desktop)
     .hh-search__btn         — submit button (search icon)
     .hh-search__dropdown    — live suggestions panel (desktop, below input)
     .hh-search__group       — section label inside dropdown ("PRODUCTS")
     .hh-search__item        — one suggestion row (product or category)
     .hh-search__viewall     — "Press Enter to view all" footer
     .hh-search__skeleton    — loading shimmer placeholder
     .hh-search__empty       — "no matches" state
     .hh-search__recent      — recent searches list (mobile)
     #hhSearchModal          — mobile full-screen modal

   States:
     idle, focused-empty, loading, results, no-results, error, mobile-open

   Design tokens come from variables.css — no hex codes here.
============================================================================= */

/* ─── 1. Desktop search wrapper ─────────────────────────────────────────── */

.hh-search {
    position: relative;
    width: 100%;
    max-width: 560px;
}

.hh-search__form {
    display: flex;
    width: 100%;
}

.hh-search__input {
    flex: 1;
    height: 44px;
    padding: 0 16px;
    border: 1px solid var(--border-md, rgba(13, 74, 49, 0.20));
    border-right: none;
    border-radius: var(--radius-sm, 6px) 0 0 var(--radius-sm, 6px);
    background: var(--cream, #FDFCF4);
    color: var(--text-body, #1C2B1E);
    font-family: var(--font-body);
    font-size: var(--fs-body, 16px);
    line-height: 1.4;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.hh-search__input::placeholder {
    color: var(--text-faint, #7A8C7D);
}

.hh-search__input:hover {
    border-color: var(--forest-200, #A8C5B5);
}

.hh-search__input:focus {
    border-color: var(--forest, #0D4A31);
    box-shadow: 0 0 0 3px rgba(13, 74, 49, 0.10);
}

.hh-search__btn {
    width: 48px;
    height: 44px;
    border: 1px solid var(--forest, #0D4A31);
    border-radius: 0 var(--radius-sm, 6px) var(--radius-sm, 6px) 0;
    background: var(--forest, #0D4A31);
    color: var(--cream, #FDFCF4);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.hh-search__btn:hover { background: var(--forest-90, #11613E); }
.hh-search__btn:active { background: var(--forest-800, #0A3D27); }

/* Search icon inside input (loading spinner replaces it during fetch) */
.hh-search__input-icon {
    position: absolute;
    right: 60px;  /* clear the submit button */
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-faint, #7A8C7D);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.hh-search.is-loading .hh-search__input-icon {
    opacity: 1;
    animation: hh-spin 0.7s linear infinite;
}

@keyframes hh-spin {
    to { transform: translateY(-50%) rotate(360deg); }
}


/* ─── 2. Dropdown panel ─────────────────────────────────────────────────── */

.hh-search__dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--cream, #FDFCF4);
    border: 1px solid var(--border-md, rgba(13, 74, 49, 0.20));
    border-radius: var(--radius-md, 10px);
    box-shadow: 0 12px 32px rgba(13, 74, 49, 0.18);
    max-height: 480px;
    overflow-y: auto;
    z-index: 1050;
    opacity: 0;
    transform: translateY(-4px);
    pointer-events: none;
    transition: opacity 0.18s ease, transform 0.18s ease;
}

/* Visible state — toggled by JS adding .is-open to .hh-search */
.hh-search.is-open .hh-search__dropdown {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Custom scrollbar for the dropdown (subtle) */
.hh-search__dropdown::-webkit-scrollbar { width: 6px; }
.hh-search__dropdown::-webkit-scrollbar-thumb {
    background: var(--forest-200, #A8C5B5);
    border-radius: 3px;
}


/* ─── 3. Dropdown sections + items ──────────────────────────────────────── */

.hh-search__group {
    padding: 8px 16px 4px;
    font-size: var(--fs-caption, 12px);
    font-weight: var(--fw-semibold, 600);
    color: var(--text-faint, #7A8C7D);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    background: var(--offwhite, #F2EFE0);
    border-bottom: 1px solid var(--border, rgba(13, 74, 49, 0.12));
    position: sticky;
    top: 0;
    z-index: 1;
}

.hh-search__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--text-body, #1C2B1E);
    text-decoration: none;
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: background-color 0.12s ease, border-color 0.12s ease;
}

.hh-search__item:hover,
.hh-search__item.is-active {
    background: var(--forest-50, #EBF2EE);
    border-left-color: var(--forest, #0D4A31);
}

.hh-search__item-img {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: var(--radius-xs, 4px);
    object-fit: cover;
    background: var(--offwhite, #F2EFE0);
}

.hh-search__item-icon {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--forest-50, #EBF2EE);
    color: var(--forest, #0D4A31);
    border-radius: var(--radius-xs, 4px);
    font-size: 18px;
}

.hh-search__item-body {
    flex: 1;
    min-width: 0;
}

.hh-search__item-title {
    font-size: var(--fs-body, 16px);
    font-weight: var(--fw-medium, 500);
    color: var(--text-body, #1C2B1E);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.hh-search__item-meta {
    font-size: var(--fs-caption, 12px);
    color: var(--text-faint, #7A8C7D);
    margin-top: 2px;
}

.hh-search__item-price {
    font-weight: var(--fw-semibold, 600);
    color: var(--forest, #0D4A31);
    font-size: var(--fs-label, 13px);
    flex-shrink: 0;
}


/* ─── 4. Footer (view all / press enter) ────────────────────────────────── */

.hh-search__viewall {
    padding: 12px 16px;
    border-top: 1px solid var(--border, rgba(13, 74, 49, 0.12));
    background: var(--offwhite, #F2EFE0);
    font-size: var(--fs-caption, 12px);
    color: var(--text-muted, #4A5E4D);
    text-align: center;
}

.hh-search__viewall kbd {
    display: inline-block;
    padding: 1px 6px;
    background: var(--cream, #FDFCF4);
    border: 1px solid var(--border-md, rgba(13, 74, 49, 0.20));
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 11px;
    color: var(--text-body, #1C2B1E);
}


/* ─── 5. Empty / error / loading states ─────────────────────────────────── */

.hh-search__empty,
.hh-search__error {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted, #4A5E4D);
    font-size: var(--fs-label, 13px);
}

.hh-search__empty-title {
    font-family: var(--font-display);
    font-size: 18px;
    color: var(--forest, #0D4A31);
    margin-bottom: 4px;
}

.hh-search__skeleton {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
}

.hh-search__skeleton-img,
.hh-search__skeleton-line {
    background: linear-gradient(
        90deg,
        var(--offwhite, #F2EFE0) 25%,
        var(--linen, #EAE6CC) 50%,
        var(--offwhite, #F2EFE0) 75%
    );
    background-size: 200% 100%;
    animation: hh-shimmer 1.4s ease-in-out infinite;
    border-radius: var(--radius-xs, 4px);
}

.hh-search__skeleton-img {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.hh-search__skeleton-line {
    height: 12px;
    flex: 1;
}

.hh-search__skeleton-line--short { max-width: 60%; }

@keyframes hh-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}


/* ─── 6. Recent searches ────────────────────────────────────────────────── */

.hh-search__recent {
    list-style: none;
    margin: 0;
    padding: 0;
}

.hh-search__recent-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    color: var(--text-body, #1C2B1E);
    text-decoration: none;
    cursor: pointer;
    border-left: 2px solid transparent;
    transition: background-color 0.12s ease;
}

.hh-search__recent-item:hover,
.hh-search__recent-item.is-active {
    background: var(--forest-50, #EBF2EE);
    border-left-color: var(--forest, #0D4A31);
}

.hh-search__recent-icon {
    color: var(--text-faint, #7A8C7D);
    font-size: 12px;
}

.hh-search__recent-clear {
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-faint, #7A8C7D);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 14px;
    line-height: 1;
    border-radius: 3px;
}

.hh-search__recent-clear:hover { background: var(--error-bg, #fee2e2); color: var(--error, #C0392B); }


/* ─── 7. Mobile modal ───────────────────────────────────────────────────── */

#hhSearchModal {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: var(--cream, #FDFCF4);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.24s cubic-bezier(0.4, 0, 0.2, 1);
    visibility: hidden;
}

#hhSearchModal.is-open {
    transform: translateY(0);
    visibility: visible;
}

.hh-search-modal__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--forest, #0D4A31);
    color: var(--cream, #FDFCF4);
    flex-shrink: 0;
}

.hh-search-modal__close {
    background: none;
    border: none;
    color: var(--cream, #FDFCF4);
    font-size: 22px;
    cursor: pointer;
    padding: 4px 8px;
    line-height: 1;
    border-radius: 3px;
}

.hh-search-modal__close:hover { background: rgba(255,255,255,0.12); }

.hh-search-modal__title {
    font-family: var(--font-display);
    font-size: 18px;
    font-weight: var(--fw-bold, 700);
}

.hh-search-modal__body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
}

.hh-search-modal__input-wrap {
    display: flex;
    margin-bottom: 16px;
}

.hh-search-modal__input-wrap .hh-search__input {
    height: 52px;
    font-size: 17px;  /* ≥16px to avoid iOS auto-zoom */
    border-radius: var(--radius-sm, 6px) 0 0 var(--radius-sm, 6px);
}

.hh-search-modal__input-wrap .hh-search__btn {
    height: 52px;
    width: 56px;
}

/* Inside the modal, the dropdown is part of the body flow — no absolute positioning */
#hhSearchModal .hh-search__dropdown {
    position: static;
    opacity: 1;
    transform: none;
    pointer-events: auto;
    box-shadow: none;
    border: none;
    max-height: none;
    margin: 0 -16px;  /* bleed to modal edges */
}

#hhSearchModal .hh-search__group {
    position: static;
}


/* ─── 8. Mobile trigger icon (replaces inline search form on mobile) ───── */

.hh-search-trigger {
    display: none;  /* shown via media query below */
    background: none;
    border: none;
    color: var(--text-body, #1C2B1E);
    font-size: 18px;
    padding: 8px 10px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.hh-search-trigger:hover { color: var(--forest, #0D4A31); }


/* ─── 9. Results page (searchfilter.blade.php) ─────────────────────────── */

.search-results__header {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border, rgba(13, 74, 49, 0.12));
}

.search-results__title {
    font-family: var(--font-display);
    font-size: var(--fs-h2, 28px);
    font-weight: var(--fw-bold, 700);
    color: var(--forest, #0D4A31);
    margin: 0;
}

.search-results__meta {
    font-size: var(--fs-label, 13px);
    color: var(--text-muted, #4A5E4D);
}

.search-results__meta strong {
    color: var(--forest, #0D4A31);
    font-weight: var(--fw-semibold, 600);
}

/* "Did you mean?" pill */
.search-results__suggestion {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    background: var(--forest-50, #EBF2EE);
    border: 1px solid var(--forest-100, #D0E2D8);
    border-radius: var(--radius-pill, 50px);
    font-size: var(--fs-label, 13px);
    color: var(--text-body, #1C2B1E);
    margin-top: 8px;
}

.search-results__suggestion a {
    color: var(--forest, #0D4A31);
    font-weight: var(--fw-semibold, 600);
    text-decoration: underline;
}

/* Zero-results state */
.search-empty {
    text-align: center;
    padding: 48px 16px;
    min-width: 60vw;
}

.search-empty__title {
    font-family: var(--font-display);
    font-size: var(--fs-h3, 22px);
    color: var(--forest, #0D4A31);
    margin: 0 0 8px;
}

.search-empty__text {
    color: var(--text-muted, #4A5E4D);
    font-size: var(--fs-label, 13px);
    margin-bottom: 32px;
}

.search-empty__section-title {
    font-family: var(--font-display);
    font-size: var(--fs-h3, 22px);
    color: var(--forest, #0D4A31);
    margin: 32px 0 16px;
}

/* Price-range filter (sidebar) */
.search-filter__price-range {
    padding: 16px 0;
    border-top: 1px solid var(--border, rgba(13, 74, 49, 0.12));
}

.search-filter__price-range-title {
    font-size: var(--fs-label, 13px);
    font-weight: var(--fw-semibold, 600);
    color: var(--text-body, #1C2B1E);
    margin-bottom: 12px;
}

.search-filter__price-inputs {
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-filter__price-inputs input {
    width: 100%;
    padding: 6px 10px;
    border: 1px solid var(--border-md, rgba(13, 74, 49, 0.20));
    border-radius: var(--radius-xs, 4px);
    background: var(--cream, #FDFCF4);
    font-size: var(--fs-label, 13px);
    font-family: var(--font-body);
    color: var(--text-body, #1C2B1E);
}

.search-filter__price-inputs input:focus {
    outline: none;
    border-color: var(--forest, #0D4A31);
    box-shadow: 0 0 0 2px rgba(13, 74, 49, 0.10);
}


/* ─── 10. Responsive ────────────────────────────────────────────────────── */

/* Mobile: hide inline search form, show trigger icon */
@media (max-width: 991.98px) {
    .hh-search--inline { display: none !important; }
    .hh-search-trigger { display: inline-flex; }
}

/* Desktop: hide mobile trigger, show inline form */
@media (min-width: 992px) {
    .hh-search-trigger { display: none !important; }
}

/* Mobile modal: full bleed items */
@media (max-width: 575.98px) {
    .hh-search__item {
        padding: 12px 16px;
    }

    .hh-search__item-img,
    .hh-search__item-icon {
        width: 48px;
        height: 48px;
    }

    .hh-search__item-title {
        font-size: 17px;  /* iOS no-zoom threshold */
    }

    .hh-search-modal__title {
        font-size: 16px;
    }
}

/* Reduced-motion: disable all transitions/animations */
@media (prefers-reduced-motion: reduce) {
    .hh-search__dropdown,
    #hhSearchModal,
    .hh-search__skeleton-img,
    .hh-search__skeleton-line,
    .hh-search__input-icon {
        transition: none !important;
        animation: none !important;
    }
}
