/**
 * PC Kompas - Global Search Styling
 * Search popup overlay and header search bar
 *
 * Features:
 * - Responsive design (fullscreen on mobile, centered modal on desktop)
 * - Dark/light mode support via CSS variables
 * - Keyboard navigation with selected state
 * - Loading, empty, error, and initial states
 * - BEM naming convention
 */

/* =====================================
   GLOBAL SEARCH POPUP
   ===================================== */

/* Backdrop */
.search-popup__backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 1000;
}

/* Popup Container */
.search-popup {
    position: fixed;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% - 32px);
    max-width: 600px;
    max-height: calc(100vh - 120px);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 1001;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Mobile: Fullscreen */
@media (max-width: 639px) {
    .search-popup {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        transform: none;
        width: 100%;
        max-width: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
    }
}

/* Input Wrapper */
.search-popup__input-wrapper {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.search-popup__icon {
    width: 20px;
    height: 20px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.search-popup__input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.125rem;
    outline: none;
    min-width: 0;
}

.search-popup__input::placeholder {
    color: var(--text-muted);
}

.search-popup__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 150ms ease, color 150ms ease;
}

.search-popup__close:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.search-popup__close:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.search-popup__close svg {
    width: 18px;
    height: 18px;
}

/* Results Container */
.search-popup__results {
    flex: 1;
    overflow-y: auto;
    padding: 8px 0;
    min-height: 200px;
}

/* Loading State */
.search-popup__loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 16px;
    color: var(--text-secondary);
}

.search-popup__spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: search-spin 0.8s linear infinite;
}

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

/* Empty State */
.search-popup__empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 16px;
    text-align: center;
    color: var(--text-secondary);
}

.search-popup__empty svg {
    width: 48px;
    height: 48px;
    opacity: 0.5;
}

.search-popup__empty-hint {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Error State */
.search-popup__error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 48px 16px;
    text-align: center;
    color: var(--error);
}

.search-popup__error svg {
    width: 48px;
    height: 48px;
}

/* Initial State */
.search-popup__initial {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 48px 16px;
    text-align: center;
    color: var(--text-muted);
}

.search-popup__shortcuts {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    font-size: 0.8125rem;
    justify-content: center;
}

.search-popup__shortcuts kbd {
    display: inline-block;
    padding: 2px 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.75rem;
}

/* Category Section */
.search-popup__category {
    padding: 0 8px;
}

.search-popup__category-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 8px 8px;
}

.search-popup__category-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 0;
}

.search-popup__category-link {
    font-size: 0.75rem;
    color: var(--accent);
    background: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
    transition: color 150ms ease;
}

.search-popup__category-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.search-popup__category-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Product Row */
.search-popup__product {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 8px;
    margin: 0 8px;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: background-color 150ms ease;
    cursor: pointer;
}

.search-popup__product:hover,
.search-popup__product--selected {
    background: var(--bg-hover);
}

.search-popup__product--selected {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.search-popup__product:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.search-popup__product-image {
    width: 48px;
    height: 48px;
    flex-shrink: 0;
    background: var(--bg-tertiary);
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.search-popup__product-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.search-popup__product-info {
    flex: 1;
    min-width: 0;
}

.search-popup__product-name {
    color: var(--text-primary);
    font-weight: 500;
    font-size: 0.9375rem;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: 0;
}

.search-popup__product-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.search-popup__product-price {
    color: var(--accent);
    font-weight: 600;
}

.search-popup__product-oos {
    color: var(--error);
    font-size: 0.75rem;
}

/* Footer */
.search-popup__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.search-popup__footer-link {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    padding: 0;
    transition: color 150ms ease;
}

.search-popup__footer-link:hover {
    color: var(--accent-hover);
}

.search-popup__footer-link:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.search-popup__footer-link svg {
    width: 16px;
    height: 16px;
}

.search-popup__footer-hint {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.search-popup__footer-hint kbd {
    display: inline-block;
    padding: 2px 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: inherit;
    font-size: 0.6875rem;
    margin-right: 4px;
}

/* Mobile Adjustments */
@media (max-width: 639px) {
    .search-popup__input-wrapper {
        padding: 12px 16px;
    }

    .search-popup__product-image {
        width: 40px;
        height: 40px;
    }

    .search-popup__shortcuts {
        flex-direction: column;
        gap: 8px;
    }

    .search-popup__footer {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .search-popup__footer-link {
        justify-content: center;
        padding: 12px;
        background: var(--accent);
        color: var(--bg-primary);
        border-radius: 8px;
    }

    .search-popup__footer-link:hover {
        background: var(--accent-hover);
        color: var(--bg-primary);
    }

    .search-popup__footer-hint {
        text-align: center;
    }
}

/* =====================================
   HEADER SEARCH BAR (Desktop)
   ===================================== */

.header-search {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    max-width: 260px;
    height: 36px;
    padding: 0 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 150ms ease, background-color 150ms ease;
}

.header-search:hover {
    border-color: var(--border-light);
    background: var(--bg-hover);
}

.header-search:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.header-search__icon {
    width: 16px;
    height: 16px;
    color: var(--text-muted);
    flex-shrink: 0;
}

.header-search__placeholder {
    flex: 1;
    color: var(--text-muted);
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-search__shortcut {
    display: flex;
    align-items: center;
    gap: 2px;
    color: var(--text-muted);
    font-size: 0.6875rem;
    background: var(--bg-secondary);
    padding: 3px 6px;
    border-radius: 4px;
    border: 1px solid var(--border);
    flex-shrink: 0;
}

/* Hide search bar on tablet/mobile - it is in hamburger menu */
@media (max-width: 1099px) {
    .header-search {
        display: none;
    }
}

/* Hide shortcut on smaller desktops */
@media (max-width: 1200px) {
    .header-search__shortcut {
        display: none;
    }
}

/* =====================================
   MOBILE MENU SEARCH
   ===================================== */

.mobile-nav__search {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 20px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    font-size: 1rem;
    cursor: pointer;
    text-align: left;
    transition: background-color 150ms ease;
}

.mobile-nav__search:hover,
.mobile-nav__search:active {
    background: var(--bg-hover);
}

.mobile-nav__search:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.mobile-nav__search svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.mobile-nav__search span {
    flex: 1;
}

.mobile-nav__search kbd {
    font-size: 0.75rem;
    padding: 2px 6px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 4px;
}

/* Only show mobile search in mobile nav */
@media (min-width: 1100px) {
    .mobile-nav__search {
        display: none;
    }
}

/* =====================================
   ALPINE.JS TRANSITIONS
   ===================================== */

[x-cloak] {
    display: none !important;
}

/* Transition utilities for Alpine.js */
.transition {
    transition-property: opacity, transform;
}

.ease-out {
    transition-timing-function: cubic-bezier(0, 0, 0.2, 1);
}

.ease-in {
    transition-timing-function: cubic-bezier(0.4, 0, 1, 1);
}

.duration-200 {
    transition-duration: 200ms;
}

.duration-150 {
    transition-duration: 150ms;
}

.opacity-0 {
    opacity: 0;
}

.opacity-100 {
    opacity: 1;
}

/* Transform for desktop centered popup */
.-translate-y-4 {
    transform: translateX(-50%) translateY(-1rem);
}

.translate-y-0 {
    transform: translateX(-50%) translateY(0);
}

/* Transform for mobile fullscreen popup */
@media (max-width: 639px) {
    .-translate-y-4 {
        transform: translateY(-1rem);
    }

    .translate-y-0 {
        transform: translateY(0);
    }
}

/* =====================================
   SCROLLBAR STYLING (optional enhancement)
   ===================================== */

.search-popup__results::-webkit-scrollbar {
    width: 8px;
}

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

.search-popup__results::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.search-popup__results::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* =====================================
   ACCESSIBILITY
   ===================================== */

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .search-popup__close,
    .search-popup__category-link,
    .search-popup__product,
    .search-popup__footer-link,
    .header-search,
    .mobile-nav__search,
    .search-popup__spinner {
        transition: none;
        animation: none;
    }
}

/* Focus visible outline for keyboard navigation */
.search-popup__product:focus-visible,
.search-popup__category-link:focus-visible,
.search-popup__footer-link:focus-visible,
.search-popup__close:focus-visible,
.header-search:focus-visible,
.mobile-nav__search:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

@media (max-width: 639px) {
    .search-popup__product:focus-visible,
    .search-popup__category-link:focus-visible {
        outline-offset: 2px;
    }
}
