/* ==========================================================================
   Search Enhancements — suggestions dropdown, keyboard nav, highlight
   Loaded by header.js on every page so styles are ready before first keystroke
   ========================================================================== */

/* ── Suggestion dropdown container ── */
#suggestions {
    position: absolute;
    top: calc(100% + 2px);
    left: 0;
    right: 0;
    z-index: 99999;
    background: #fff;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0,0,0,0.13);
    max-height: 420px;
    overflow-y: auto;
    overflow-x: hidden;
    min-width: 320px;
    max-width: 100%;
}

#suggestions:empty { display: none; }

#suggestions::-webkit-scrollbar { width: 4px; }
#suggestions::-webkit-scrollbar-thumb { background: #009999; border-radius: 4px; }

/* ── Group label ── */
#suggestions .sg-group-label {
    padding: 7px 14px 5px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #94a3b8;
    background: #f8fafc;
    border-bottom: 1px solid #e9ecef;
    display: flex;
    align-items: center;
    gap: 6px;
}

#suggestions .sg-group-label .fa { color: #009999; }

/* ── Divider ── */
#suggestions .sg-divider {
    height: 1px;
    background: #e9ecef;
    margin: 2px 0;
}

/* ── Suggestion item ── */
#suggestions .sg-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 14px;
    text-decoration: none !important;
    color: #1e293b !important;
    border-bottom: 1px solid #f1f5f9;
    transition: background 0.15s;
    cursor: pointer;
    outline: none;
}

#suggestions .sg-item:hover,
#suggestions .sg-item:focus,
#suggestions .sg-item.sg-focused {
    background: #f0fafa;
}

#suggestions .sg-item:last-of-type { border-bottom: none; }

/* ── Category icon bubble ── */
#suggestions .sg-cat-icon {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    flex-shrink: 0;
}

/* ── Product thumbnail ── */
#suggestions .sg-product-img-wrap {
    width: 36px;
    height: 36px;
    border-radius: 4px;
    border: 1px solid #e9ecef;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #f8fafc;
}

#suggestions .sg-product-img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* ── Text block ── */
#suggestions .sg-text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1px;
}

#suggestions .sg-name {
    font-size: 13px;
    font-weight: 500;
    color: #1e293b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Highlighted matched text */
#suggestions .sg-name mark,
#suggestions .sg-highlight {
    background: #fef9c3;
    color: #92400e;
    font-weight: 700;
    border-radius: 2px;
    padding: 0 1px;
}

#suggestions .sg-sub {
    font-size: 11px;
    color: #94a3b8;
}

#suggestions .sg-price {
    font-size: 11.5px;
    font-weight: 700;
    color: #009999;
}

/* ── Chevron ── */
#suggestions .sg-arrow {
    font-size: 9px;
    color: #cbd5e1;
    flex-shrink: 0;
    transition: color 0.15s, transform 0.15s;
}

#suggestions .sg-item:hover .sg-arrow,
#suggestions .sg-item.sg-focused .sg-arrow {
    color: #009999;
    transform: translateX(2px);
}

/* ── Empty state ── */
#suggestions .sg-empty {
    padding: 16px 14px;
    font-size: 13px;
    color: #94a3b8;
    text-align: center;
    font-style: italic;
}

/* ── View all ── */
#suggestions .sg-viewall {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    font-size: 12.5px;
    font-weight: 600;
    color: #009999 !important;
    text-decoration: none !important;
    background: #f0fafa;
    border-top: 1px solid #e0f5f5;
    transition: background 0.15s;
    border-radius: 0 0 10px 10px;
}

#suggestions .sg-viewall:hover { background: #e0f5f5; }
#suggestions .sg-viewall .fa { font-size: 11px; }

/* ── Recent searches ── */
#suggestions .sg-recent-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 14px 5px;
    font-size: 10px;
    font-weight: 800;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    color: #94a3b8;
    background: #f8fafc;
    border-bottom: 1px solid #e9ecef;
}

#suggestions .sg-clear-recent {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 2px 6px;
    font-size: 10px;
    border-radius: 4px;
    transition: all 0.15s;
}

#suggestions .sg-clear-recent:hover {
    background: #fee2e2;
    color: #ef4444;
}

#suggestions .sg-item-recent { background: #fafbfc; }
#suggestions .sg-item-recent:hover,
#suggestions .sg-item-recent.sg-focused { background: #f0f9ff; }

#suggestions .sg-recent-icon {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    background: #e0f2fe;
    color: #0284c7;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    flex-shrink: 0;
}

/* ── Loading spinner ── */
#suggestions .sg-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px 14px;
    font-size: 12px;
    color: #64748b;
}

#suggestions .sg-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid #e2e8f0;
    border-top-color: #009999;
    border-radius: 50%;
    animation: sgSpin 0.65s linear infinite;
    flex-shrink: 0;
}

@keyframes sgSpin { to { transform: rotate(360deg); } }

/* ── Mobile: keep dropdown within viewport ── */
@media (max-width: 600px) {
    #suggestions {
        min-width: 0;
        left: 0;
        right: 0;
        border-radius: 0 0 10px 10px;
        max-height: 60vh;
    }
}
