/**
 * Search Modal - Command Palette Style
 * Modern, accessible search with instant results
 * Inspired by Spotlight, Linear, Vercel
 */

/* ========================================
   Base & Reset
   ======================================== */

.gw-search-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 10vh 1rem 1rem;
    opacity: 0;
    visibility: hidden;
}

.gw-search-modal.is-open {
    display: flex;
    opacity: 1;
    visibility: visible;
    animation: gw-modal-fade-in 0.2s ease forwards;
}

/* Backdrop */
.gw-search-modal__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.gw-search-modal__overlay {
    display: none;
}

/* ========================================
   Modal Container
   ======================================== */

.gw-search-modal__container {
    position: relative;
    width: 100%;
    height: auto;
}

.gw-search-modal__content {
    position: relative;
    width: 100%;
    max-width: 580px;
    margin: 0 auto;
    background: #ffffff;
    border-radius: 16px;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.05),
        0 4px 16px rgba(0, 0, 0, 0.12),
        0 16px 48px rgba(0, 0, 0, 0.16);
    overflow: hidden;
    transform: scale(0.96) translateY(-8px);
    transition: transform 0.2s cubic-bezier(0.32, 0.72, 0, 1);
}

.gw-search-modal.is-open .gw-search-modal__content {
    transform: scale(1) translateY(0);
}

/* ========================================
   Search Header / Input
   ======================================== */

.gw-search-modal__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
}

.gw-search-modal__input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    background: transparent;
}

.gw-search-modal__icon {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    color: #aaa;
}

.gw-search-modal__input {
    flex: 1;
    height: 24px;
    line-height: 24px;
    font-family: var(--gw-font-sans, 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif);
    font-size: 15px;
    font-weight: 400;
    color: #1a1a1a;
    background: transparent;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    caret-color: var(--gw-primary, #5c0a2d);
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
    padding: 0;
}

.gw-search-modal__input:focus {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

.gw-search-modal__input::placeholder {
    color: #aaa;
    font-weight: 400;
}

.gw-search-modal__input::-webkit-search-cancel-button,
.gw-search-modal__input::-webkit-search-decoration {
    -webkit-appearance: none;
    appearance: none;
    display: none;
}

/* Clear Button */
.gw-search-modal__clear {
    display: none;
    align-items: center;
    justify-content: center;
    height: 24px;
    padding: 0 8px;
    background: #e8e8e8;
    border: none;
    border-radius: 5px;
    color: #666;
    cursor: pointer;
    transition: background 0.15s ease;
}

.gw-search-modal__clear:hover {
    background: #ddd;
}

.gw-search-modal__clear svg {
    width: 12px;
    height: 12px;
}

.gw-search-modal.has-value .gw-search-modal__clear {
    display: flex;
}

/* Close Button */
.gw-search-modal__close {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 24px;
    padding: 0 8px;
    font-family: var(--gw-font-sans, 'Outfit', sans-serif);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.02em;
    color: #888;
    background: #e8e8e8;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.gw-search-modal__close:hover {
    background: #ddd;
    color: #666;
}

.gw-search-modal__close svg {
    display: none;
}

.gw-search-modal__close::before {
    content: 'ESC';
}

/* ========================================
   Results Area
   ======================================== */

.gw-search-modal__results {
    max-height: 420px;
    overflow-y: auto;
    overscroll-behavior: contain;
}

/* Hide results area when empty */
.gw-search-modal__results:empty,
.gw-search-modal__results-list:empty {
    display: none;
}

/* Only show results area when modal has value or results */
.gw-search-modal:not(.has-value) .gw-search-modal__results {
    display: none;
}

/* Custom Scrollbar */
.gw-search-modal__results::-webkit-scrollbar {
    width: 6px;
}

.gw-search-modal__results::-webkit-scrollbar-track {
    background: transparent;
}

.gw-search-modal__results::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 3px;
}

.gw-search-modal__results::-webkit-scrollbar-thumb:hover {
    background: #ccc;
}

/* Results List */
.gw-search-modal__results-list {
    padding: 8px;
}

/* ========================================
   Search Result Item
   ======================================== */

.gw-search-result {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 10px 12px;
    text-decoration: none;
    color: inherit;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.1s ease;
}

.gw-search-result:hover,
.gw-search-result.is-selected {
    background: #f7f7f7;
}

.gw-search-result:active {
    background: #f0f0f0;
}

/* Product Image */
.gw-search-result__image {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    border-radius: 8px;
    overflow: hidden;
    background: #f5f5f5;
}

.gw-search-result__image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Content */
.gw-search-result__content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* Category Label */
.gw-search-result__category {
    font-family: var(--gw-font-sans, 'Outfit', sans-serif);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--gw-primary, #5c0a2d);
}

/* Title */
.gw-search-result__title {
    font-family: var(--gw-font-sans, 'Outfit', sans-serif);
    font-size: 14px;
    font-weight: 500;
    color: #1a1a1a;
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Price */
.gw-search-result__price {
    font-family: var(--gw-font-sans, 'Outfit', sans-serif);
    font-size: 13px;
    font-weight: 500;
    color: #666;
}

.gw-search-result__price del {
    color: #aaa;
    font-weight: 400;
    margin-right: 6px;
}

.gw-search-result__price ins {
    text-decoration: none;
    color: var(--gw-primary, #5c0a2d);
    font-weight: 600;
}

/* Arrow Icon */
.gw-search-result::after {
    content: '';
    flex-shrink: 0;
    width: 16px;
    height: 16px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%23ccc' stroke-width='2.5'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' d='m9 18 6-6-6-6'/%3E%3C/svg%3E");
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.gw-search-result:hover::after {
    opacity: 1;
    transform: translateX(0);
}

/* ========================================
   States: Loading, Empty, No Results
   ======================================== */

/* Loading */
.gw-search-modal__loading {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 24px;
}

.gw-search-modal__spinner {
    width: 20px;
    height: 20px;
    color: var(--gw-primary, #5c0a2d);
    animation: gw-spin 0.8s linear infinite;
}

.gw-search-modal__loading span {
    font-family: var(--gw-font-sans, 'Outfit', sans-serif);
    font-size: 14px;
    color: #999;
}

/* No Results */
.gw-search-modal__no-results {
    padding: 48px 24px;
    text-align: center;
}

.gw-search-modal__no-results p {
    font-family: var(--gw-font-sans, 'Outfit', sans-serif);
    font-size: 15px;
    font-weight: 500;
    color: #666;
    margin: 0;
}

/* ========================================
   View All Footer
   ======================================== */

.gw-search-modal__view-all {
    padding: 12px 16px;
    border-top: 1px solid #f0f0f0;
    background: #fafafa;
}

.gw-search-modal__view-all-link {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    font-family: var(--gw-font-sans, 'Outfit', sans-serif);
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    background: var(--gw-primary, #5c0a2d);
    border: none;
    border-radius: 8px;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
}

.gw-search-modal__view-all-link:hover {
    background: #4a0824;
}

.gw-search-modal__view-all-link:active {
    transform: scale(0.98);
}

.gw-search-modal__view-all-link svg {
    width: 14px;
    height: 14px;
}

/* ========================================
   Keyboard Navigation Hints
   ======================================== */

.gw-search-modal__hints {
    display: none;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 10px 16px;
    border-top: 1px solid #f0f0f0;
    background: #fafafa;
}

@media (min-width: 640px) {
    .gw-search-modal__hints {
        display: flex;
    }
}

.gw-search-modal__hint {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: var(--gw-font-sans, 'Outfit', sans-serif);
    font-size: 11px;
    color: #999;
}

.gw-search-modal__hint kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    font-family: inherit;
    font-size: 10px;
    font-weight: 600;
    color: #666;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 4px;
    box-shadow: 0 1px 0 #e0e0e0;
}

/* ========================================
   Animations
   ======================================== */

@keyframes gw-modal-fade-in {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

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

/* ========================================
   Mobile Styles
   ======================================== */

@media (max-width: 639px) {
    .gw-search-modal {
        padding: 8px;
        align-items: flex-start;
    }

    .gw-search-modal__content {
        max-width: 100%;
        max-height: calc(100vh - 16px);
        border-radius: 12px;
    }

    .gw-search-modal__header {
        padding: 14px;
        gap: 10px;
    }

    .gw-search-modal__input {
        font-size: 16px; /* Prevents zoom on iOS */
    }

    .gw-search-modal__close {
        height: 26px;
        padding: 0 8px;
        font-size: 10px;
    }

    .gw-search-modal__results {
        max-height: calc(100vh - 120px);
    }

    .gw-search-result {
        padding: 8px 10px;
        gap: 12px;
    }

    .gw-search-result__image {
        width: 48px;
        height: 48px;
    }

    .gw-search-result__title {
        font-size: 13px;
    }

    .gw-search-result__price {
        font-size: 12px;
    }

    .gw-search-modal__view-all {
        padding: 10px 12px;
    }

    .gw-search-modal__view-all-link {
        padding: 14px 16px;
        font-size: 14px;
    }
}

/* Safe Area (Notch devices) */
@supports (padding-top: env(safe-area-inset-top)) {
    .gw-search-modal {
        padding-top: max(10vh, env(safe-area-inset-top));
    }

    @media (max-width: 639px) {
        .gw-search-modal {
            padding-top: max(8px, env(safe-area-inset-top));
        }
    }
}

/* ========================================
   Body Lock
   ======================================== */

body.gw-search-modal-open {
    overflow: hidden;
}

/* Hidden Utility */
[hidden] {
    display: none !important;
}
