/* ============================================================
   AEX Smart Search — Styles
   ============================================================ */

/* ── Search bar wrap ──────────────────────────────────────── */
.aex-search-wrap {
    position: relative;
    display: inline-flex;
    align-items: center;
}

/* ── Desktop search bar ───────────────────────────────────── */
.aex-search-bar {
    position: relative;
    display: flex;
    align-items: center;
    width: 340px;
    max-width: 100%;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
    overflow: hidden;
}
.aex-search-bar:focus-within {
    border-color: #c9a84c;
    box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.15);
}

.aex-search-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    pointer-events: none;
    color: #888;
}

.aex-search-input {
    flex: 1;
    padding: 12px 40px 12px 40px;
    border: none !important;
    outline: none !important;
    background: transparent !important;
    font-size: 14px;
    color: #1a1a1a;
    font-family: inherit;
    width: 100%;
    -webkit-appearance: none;
    appearance: none;
}
.aex-search-input::placeholder { color: #aaa; }
/* Remove browser's native clear button */
.aex-search-input::-webkit-search-cancel-button { display: none; }
.aex-search-input[type="search"]::-ms-clear { display: none; }

.aex-search-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: none;
    background: none;
    cursor: pointer;
    color: #aaa;
    padding: 0;
    transition: color 0.15s;
    border-radius: 4px;
    -webkit-tap-highlight-color: transparent;
}
.aex-search-clear:hover { color: #333; }

/* ── Mobile trigger (icon only) ───────────────────────────── */
.aex-search-trigger {
    display: none; /* shown via media query */
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    cursor: pointer;
    color: #fff;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
    border-radius: 6px;
    transition: background 0.15s;
}
.aex-search-trigger:hover { background: rgba(255,255,255,0.1); }

/* ── Results panel (fixed, appended to body) ──────────────── */
.aex-ss-panel {
    position: fixed;
    left: 0;
    right: 0;
    /* top is set by JS to match header bottom */
    top: 80px;
    z-index: 99999;
    background: #fff;
    border: 1px solid #e8e8e8;
    border-top: none;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    max-height: 520px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    /* Animation */
    opacity: 0;
    transform: translateY(-8px);
    transition: opacity 0.18s ease, transform 0.18s ease;
    pointer-events: none;
}
.aex-ss-panel.aex-ss-open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: all;
}
.aex-ss-panel-inner {
    max-width: 1160px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ── Section label ────────────────────────────────────────── */
.aex-ss-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #999;
    padding: 16px 0 10px;
    font-family: inherit;
}

/* ── Category chips ───────────────────────────────────────── */
.aex-ss-cats-section {
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 16px;
}
.aex-ss-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}
.aex-ss-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 16px;
    background: #f5f5f5;
    color: #1a1a1a;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    font-family: inherit;
    border: 1px solid transparent;
}
.aex-ss-chip:hover {
    background: #1a1a1a;
    color: #fff;
}
.aex-ss-chip-count {
    font-size: 11px;
    font-weight: 400;
    opacity: 0.6;
}

/* ── Product rows ─────────────────────────────────────────── */
.aex-ss-products-section { padding-bottom: 8px; }
.aex-ss-products { }

.aex-ss-product {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 11px 0;
    border-bottom: 1px solid #f0f0f0;
    text-decoration: none;
    color: inherit;
    transition: background 0.12s;
    border-radius: 6px;
    margin: 0 -8px;
    padding-left: 8px;
    padding-right: 8px;
}
.aex-ss-product:last-of-type { border-bottom: none; }
.aex-ss-product:hover { background: #fffbeb; }

/* Product is keyboard-focused */
.aex-ss-product.aex-ss-active { background: #fffbeb; outline: 2px solid #c9a84c; }

.aex-ss-product-img {
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid #eee;
    background: #f8f8f8;
    display: flex;
    align-items: center;
    justify-content: center;
}
.aex-ss-product-img img {
    width: 52px;
    height: 52px;
    object-fit: cover;
    display: block;
}

.aex-ss-product-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.aex-ss-product-name {
    font-size: 14px;
    font-weight: 600;
    color: #1a1a1a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}
.aex-ss-product-cat {
    font-size: 11px;
    color: #aaa;
    font-weight: 500;
}
.aex-ss-product-price {
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 700;
    color: #1a1a1a;
    text-align: right;
    white-space: nowrap;
}
.aex-ss-product-price .woocommerce-Price-amount { font-size: inherit; font-weight: inherit; color: inherit; }
.aex-ss-product-price del { color: #bbb; font-weight: 400; font-size: 12px; display: block; }

/* ── View all link ────────────────────────────────────────── */
.aex-ss-view-all {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px;
    margin: 4px -24px 0;
    background: #fffbeb;
    color: #c9a84c;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    border-top: 1px solid #f0f0f0;
    transition: color 0.15s, background 0.15s;
    font-family: inherit;
}
.aex-ss-view-all:hover { color: #b8943e; background: #fff8e1; }
.aex-ss-view-all svg { flex-shrink: 0; }

/* ── No results ───────────────────────────────────────────── */
.aex-ss-no-results {
    padding: 32px 0;
    text-align: center;
    color: #aaa;
    font-size: 14px;
    line-height: 1.6;
}

/* ── Loading state ────────────────────────────────────────── */
.aex-ss-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 32px 0;
    gap: 8px;
    color: #ccc;
    font-size: 14px;
}
.aex-ss-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #e8e8e8;
    border-top-color: #c9a84c;
    border-radius: 50%;
    animation: aex-spin 0.7s linear infinite;
}
@keyframes aex-spin { to { transform: rotate(360deg); } }

/* ============================================================
   MOBILE OVERLAY  (full-screen, <768px)
   ============================================================ */

/* Overlay backdrop */
.aex-ss-overlay {
    position: fixed;
    inset: 0;
    z-index: 999998;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
}
.aex-ss-overlay.aex-ss-open {
    opacity: 1;
    pointer-events: all;
}

/* Overlay panel slides down from top */
.aex-ss-overlay-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    background: #fff;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    transform: translateY(-100%);
    transition: transform 0.25s cubic-bezier(0.32, 0.72, 0, 1);
    display: flex;
    flex-direction: column;
}
.aex-ss-overlay.aex-ss-open .aex-ss-overlay-panel {
    transform: translateY(0);
}

.aex-ss-overlay-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-bottom: 1px solid #f0f0f0;
    background: #fff;
    position: sticky;
    top: 0;
    z-index: 1;
}
.aex-ss-overlay-bar {
    flex: 1;
    display: flex;
    align-items: center;
    background: #f8f8f8;
    border: 1px solid #e8e8e8;
    border-radius: 8px;
    overflow: hidden;
}
.aex-ss-overlay-bar .aex-search-icon {
    position: static;
    transform: none;
    padding: 0 10px;
    color: #888;
}
.aex-ss-overlay-input {
    flex: 1;
    padding: 12px 12px 12px 0;
    border: none !important;
    outline: none !important;
    background: transparent !important;
    font-size: 16px; /* 16px prevents iOS zoom */
    color: #1a1a1a;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}
.aex-ss-overlay-input::placeholder { color: #aaa; }
.aex-ss-overlay-input::-webkit-search-cancel-button { display: none; }

.aex-ss-overlay-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    background: #f5f5f5;
    border-radius: 8px;
    cursor: pointer;
    color: #555;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
}
.aex-ss-overlay-results {
    padding: 0 16px;
}
/* Reuse panel styles inside overlay */
.aex-ss-overlay-results .aex-ss-view-all {
    margin: 4px -16px 0;
}
/* On mobile chips wrap freely */
.aex-ss-overlay-results .aex-ss-chips {
    flex-wrap: wrap;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 767px) {
    /* Hide desktop bar, show trigger icon */
    .aex-search-bar    { display: none; }
    .aex-search-trigger { display: flex; }

    /* Hide the fixed desktop panel — mobile uses overlay */
    .aex-ss-panel { display: none !important; }
}

@media (min-width: 768px) {
    /* Hide mobile trigger, show desktop bar */
    .aex-search-trigger  { display: none; }
    .aex-search-bar      { display: flex; }

    /* Hide mobile overlay on desktop (keyboard Escape still works) */
    .aex-ss-overlay { display: none !important; }
}

/* Panel inner constrained width on large screens */
@media (min-width: 1200px) {
    .aex-ss-panel-inner { padding: 0 40px; }
    .aex-ss-view-all    { margin-left: -40px; margin-right: -40px; }
}
