/* KSA Typesense Search — Overlay styles
   No external dependencies, no framework.
   All colours use CSS custom properties so they inherit from the theme. */

/* ── Trigger (nav menu item) ─────────────────────────────────────────────── */

.ksa-search-trigger {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    background: none;
    border: none;
    padding: 0;
}

.ksa-search-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.ksa-search-icon svg {
    display: block;
}

.ksa-search-label {
    font-size: inherit;
    font-family: inherit;
}

/* ── Overlay backdrop ────────────────────────────────────────────────────── */

#ksa-search-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(0, 0, 0, 0.85);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

#ksa-search-overlay.ksa-overlay-open {
    display: block;
}

/* ── Close button (top-right of backdrop) ────────────────────────────────── */

.ksa-overlay-close {
    position: fixed;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    color: #fff;
    font-size: 32px;
    line-height: 1;
    cursor: pointer;
    padding: 8px;
    z-index: 100000;
    opacity: 0.8;
    transition: opacity 0.15s;
}

.ksa-overlay-close:hover,
.ksa-overlay-close:focus {
    opacity: 1;
    outline: 2px solid rgba(255, 255, 255, 0.5);
    border-radius: 3px;
}

/* ── Panel ───────────────────────────────────────────────────────────────── */

.ksa-overlay-panel {
    background: #fff;
    max-width: 680px;
    width: calc(100% - 32px);
    margin: 60px auto 40px;
    border-radius: 4px;
    overflow: hidden;
}

/* ── Input area ──────────────────────────────────────────────────────────── */

.ksa-overlay-input-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 24px;
    border-bottom: 1px solid #eee;
}

.ksa-overlay-input-wrap .ksa-search-icon {
    color: #888;
    flex-shrink: 0;
}

.ksa-overlay-input-wrap .ksa-search-icon svg {
    width: 22px;
    height: 22px;
}

#ksa-overlay-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 18px;
    font-family: inherit;
    color: #1a1a1a;
    background: transparent;
    min-width: 0;
}

#ksa-overlay-input::placeholder {
    color: #aaa;
}

.ksa-overlay-clear {
    background: none;
    border: none;
    color: #aaa;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 4px 6px;
    flex-shrink: 0;
    display: none;
    opacity: 0.7;
    transition: opacity 0.15s;
}

.ksa-overlay-clear.ksa-visible {
    display: block;
}

.ksa-overlay-clear:hover {
    opacity: 1;
    color: #555;
}

/* Submit button (icon, after input) */
.ksa-overlay-submit {
    background: none;
    border: none;
    color: #888;
    cursor: pointer;
    padding: 6px 8px;
    flex-shrink: 0;
    line-height: 0;
    border-radius: 3px;
    transition: color 0.15s, background 0.15s;
}

.ksa-overlay-submit:hover,
.ksa-overlay-submit:focus {
    color: #1a1a1a;
    background: #f0f0f0;
    outline: none;
}

.ksa-overlay-submit svg {
    display: block;
    width: 20px;
    height: 20px;
}

/* ── Results list ────────────────────────────────────────────────────────── */

.ksa-results-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ksa-result-item {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    border-bottom: 1px solid #f0f0f0;
    text-decoration: none;
    color: inherit;
    cursor: pointer;
    transition: background 0.1s;
}

.ksa-result-item:last-child {
    border-bottom: none;
}

.ksa-result-item:hover,
.ksa-result-item.ksa-highlighted {
    background: var(--primary-color-light, #f5f5f5);
}

.ksa-result-item:focus {
    outline: 2px solid var(--primary-color, #333);
    outline-offset: -2px;
}

/* Product image */
.ksa-result-image {
    width: 80px;
    height: 80px;
    object-fit: cover;
    flex-shrink: 0;
    border-radius: 3px;
    background: #f5f5f5;
}

/* Product info */
.ksa-result-info {
    flex: 1;
    min-width: 0;
}

.ksa-result-name {
    font-size: 15px;
    font-weight: 500;
    color: #1a1a1a;
    line-height: 1.4;
    margin: 0 0 6px;
    /* Full text, no truncation — antique names can be long */
    white-space: normal;
}

.ksa-result-price {
    font-size: 14px;
    color: #555;
    margin: 0;
}

/* ── Loading state ───────────────────────────────────────────────────────── */

.ksa-overlay-results.ksa-loading .ksa-results-list {
    opacity: 0.3;
    pointer-events: none;
}

.ksa-overlay-results::after {
    content: '';
    display: none;
    width: 28px;
    height: 28px;
    border: 3px solid #eee;
    border-top-color: var(--primary-color, #333);
    border-radius: 50%;
    animation: ksa-spin 0.7s linear infinite;
    margin: 24px auto;
}

.ksa-overlay-results.ksa-loading::after {
    display: block;
}

@keyframes ksa-spin {
    to { transform: rotate(360deg); }
}


/* ── Footer — "View all N results" ──────────────────────────────────────── */

.ksa-results-footer {
    padding: 14px 24px;
    border-top: 1px solid #eee;
    display: none;
}

.ksa-results-footer.ksa-visible {
    display: block;
}

.ksa-view-all {
    font-size: 14px;
    color: var(--primary-color, #333);
    text-decoration: none;
    font-weight: 500;
}

.ksa-view-all:hover {
    text-decoration: underline;
}

/* ── No results message ──────────────────────────────────────────────────── */

.ksa-no-results {
    padding: 24px;
    color: #888;
    font-size: 15px;
    text-align: center;
}

/* ── Mobile ──────────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
    .ksa-overlay-panel {
        width: 100%;
        margin: 0;
        border-radius: 0;
        min-height: 100vh;
    }

    .ksa-overlay-close {
        position: absolute;
    }

    .ksa-overlay-input-wrap {
        padding: 16px;
    }

    .ksa-result-item {
        padding: 12px 16px;
        gap: 12px;
    }

    .ksa-result-image {
        width: 64px;
        height: 64px;
    }

    .ksa-result-name {
        font-size: 14px;
    }

    .ksa-results-footer {
        padding: 12px 16px;
    }
}

/* ── Body scroll lock ────────────────────────────────────────────────────── */

body.ksa-overlay-active {
    overflow: hidden;
}
