/**
 * Geek Live Search — Apple-inspired glassmorphism UI.
 * Inspired by apple.com search + the-geek.ru aesthetics.
 *
 * @version 1.0.2
 */

/* ─────────────────────────────────────────────
 * CSS CUSTOM PROPERTIES (THEMING)
 * ───────────────────────────────────────────── */
:root {
    --gls-font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", "Segoe UI", Roboto, Arial, sans-serif;
    --gls-radius: 16px;
    --gls-radius-sm: 10px;
    --gls-radius-xs: 8px;

    /* Glass theme (default) */
    --gls-bg: rgba(255, 255, 255, 0.82);
    --gls-bg-hover: rgba(255, 255, 255, 0.95);
    --gls-backdrop-blur: 40px;
    --gls-border: rgba(0, 0, 0, 0.08);
    --gls-shadow: 0 20px 60px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.05);
    --gls-shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.08);

    --gls-text-primary: #1d1d1f;
    --gls-text-secondary: #6e6e73;
    --gls-text-tertiary: #86868b;

    --gls-accent: #0071e3;
    --gls-accent-hover: #0077ed;
    --gls-highlight-bg: rgba(0, 113, 227, 0.12);
    --gls-highlight-color: #0071e3;

    --gls-overlay-bg: rgba(0, 0, 0, 0.45);
    --gls-overlay-blur: 8px;

    --gls-divider: rgba(0, 0, 0, 0.06);
    --gls-input-bg: rgba(142, 142, 147, 0.08);
    --gls-kbd-bg: rgba(0, 0, 0, 0.06);
    --gls-kbd-border: rgba(0, 0, 0, 0.1);
    --gls-thumb-radius: 10px;
    --gls-type-bg: rgba(0, 113, 227, 0.08);
    --gls-type-color: #0071e3;

    --gls-transition: 200ms cubic-bezier(0.25, 0.1, 0.25, 1);
    --gls-transition-spring: 300ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ─── Dark Theme ─── */
.gls-theme-geek-dark,
.gls-theme-geek-dark :root,
@media (prefers-color-scheme: dark) {
    .gls-theme-geek-glass {
        --gls-bg: rgba(28, 28, 30, 0.88);
        --gls-bg-hover: rgba(44, 44, 46, 0.95);
        --gls-border: rgba(255, 255, 255, 0.1);
        --gls-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
        --gls-shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.3);
        --gls-text-primary: #f5f5f7;
        --gls-text-secondary: #a1a1a6;
        --gls-text-tertiary: #6e6e73;
        --gls-overlay-bg: rgba(0, 0, 0, 0.6);
        --gls-divider: rgba(255, 255, 255, 0.08);
        --gls-input-bg: rgba(255, 255, 255, 0.06);
        --gls-kbd-bg: rgba(255, 255, 255, 0.08);
        --gls-kbd-border: rgba(255, 255, 255, 0.12);
        --gls-highlight-bg: rgba(0, 113, 227, 0.2);
        --gls-type-bg: rgba(0, 113, 227, 0.15);
    }
}

.gls-theme-geek-dark {
    --gls-bg: rgba(28, 28, 30, 0.88);
    --gls-bg-hover: rgba(44, 44, 46, 0.95);
    --gls-border: rgba(255, 255, 255, 0.1);
    --gls-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
    --gls-shadow-hover: 0 4px 20px rgba(0, 0, 0, 0.3);
    --gls-text-primary: #f5f5f7;
    --gls-text-secondary: #a1a1a6;
    --gls-text-tertiary: #6e6e73;
    --gls-overlay-bg: rgba(0, 0, 0, 0.6);
    --gls-divider: rgba(255, 255, 255, 0.08);
    --gls-input-bg: rgba(255, 255, 255, 0.06);
    --gls-kbd-bg: rgba(255, 255, 255, 0.08);
    --gls-kbd-border: rgba(255, 255, 255, 0.12);
    --gls-highlight-bg: rgba(0, 113, 227, 0.2);
    --gls-type-bg: rgba(0, 113, 227, 0.15);
}

/* ─────────────────────────────────────────────
 * FULLSCREEN OVERLAY (Apple Spotlight-style)
 * ───────────────────────────────────────────── */
.gls-overlay {
    position: fixed;
    inset: 0;
    z-index: 999999;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: clamp(80px, 15vh, 200px);
    font-family: var(--gls-font);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--gls-transition), visibility var(--gls-transition);
}

.gls-overlay[hidden] {
    display: none;
}

.gls-overlay--active {
    opacity: 1;
    visibility: visible;
}

/* Blurred backdrop */
.gls-overlay__backdrop {
    position: absolute;
    inset: 0;
    background: var(--gls-overlay-bg);
    -webkit-backdrop-filter: blur(var(--gls-overlay-blur));
    backdrop-filter: blur(var(--gls-overlay-blur));
}

/* Main container */
.gls-overlay__container {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 680px;
    margin: 0 20px;
    background: var(--gls-bg);
    -webkit-backdrop-filter: blur(var(--gls-backdrop-blur)) saturate(180%);
    backdrop-filter: blur(var(--gls-backdrop-blur)) saturate(180%);
    border-radius: var(--gls-radius);
    border: 1px solid var(--gls-border);
    box-shadow: var(--gls-shadow);
    overflow: hidden;
    transform: translateY(-12px) scale(0.98);
    transition: transform var(--gls-transition-spring), opacity var(--gls-transition);
}

.gls-overlay--active .gls-overlay__container {
    transform: translateY(0) scale(1);
}

/* Search box */
.gls-overlay__search-box {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--gls-divider);
}

.gls-overlay__icon {
    flex-shrink: 0;
    color: var(--gls-text-tertiary);
}

.gls-overlay__input {
    flex: 1;
    border: none;
    background: none;
    outline: none;
    font-size: 18px;
    font-family: var(--gls-font);
    font-weight: 400;
    color: var(--gls-text-primary);
    letter-spacing: -0.01em;
    line-height: 1.4;
}

.gls-overlay__input::placeholder {
    color: var(--gls-text-tertiary);
}

.gls-overlay__input::-webkit-search-cancel-button {
    -webkit-appearance: none;
    appearance: none;
}

.gls-overlay__kbd {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 24px;
    padding: 0 6px;
    border-radius: 6px;
    background: var(--gls-kbd-bg);
    border: 1px solid var(--gls-kbd-border);
    font-family: var(--gls-font);
    font-size: 11px;
    font-weight: 500;
    color: var(--gls-text-tertiary);
    line-height: 1;
    user-select: none;
}

/* Results area */
.gls-overlay__results {
    max-height: 420px;
    overflow-y: auto;
    overscroll-behavior: contain;
    scroll-behavior: smooth;
    padding: 8px;
}

.gls-overlay__results::-webkit-scrollbar {
    width: 6px;
}

.gls-overlay__results::-webkit-scrollbar-track {
    background: transparent;
}

.gls-overlay__results::-webkit-scrollbar-thumb {
    background: var(--gls-divider);
    border-radius: 3px;
}

/* Footer */
.gls-overlay__footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    border-top: 1px solid var(--gls-divider);
    font-size: 12px;
    color: var(--gls-text-tertiary);
}

.gls-overlay__hint {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
}

.gls-overlay__hint kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 20px;
    padding: 0 5px;
    border-radius: 5px;
    background: var(--gls-kbd-bg);
    border: 1px solid var(--gls-kbd-border);
    font-family: var(--gls-font);
    font-size: 10px;
    font-weight: 500;
    color: var(--gls-text-tertiary);
    line-height: 1;
    margin: 0 2px;
}

.gls-overlay__branding {
    font-weight: 500;
    opacity: 0.5;
}

/* ─────────────────────────────────────────────
 * RESULT ITEMS
 * ───────────────────────────────────────────── */
.gls-result-item {
    opacity: 0;
    transform: translateY(6px);
    border-radius: var(--gls-radius-sm);
    transition: background var(--gls-transition);
}

.gls-result-item--enter {
    animation: glsSlideIn var(--gls-transition-spring) forwards;
}

@keyframes glsSlideIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.gls-result-item + .gls-result-item {
    margin-top: 2px;
}

.gls-result-item__link {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border-radius: var(--gls-radius-sm);
    text-decoration: none;
    color: inherit;
    transition: background var(--gls-transition);
}

.gls-result-item__link:hover,
.gls-result-item--active .gls-result-item__link {
    background: var(--gls-input-bg);
}

.gls-result-item--active .gls-result-item__link {
    background: var(--gls-accent);
    color: #fff;
}

.gls-result-item--active .gls-result-item__excerpt,
.gls-result-item--active .gls-result-item__type,
.gls-result-item--active .gls-result-item__arrow {
    color: rgba(255, 255, 255, 0.8);
}

.gls-result-item--active .gls-highlight {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.gls-result-item--active .gls-result-item__type {
    background: rgba(255, 255, 255, 0.15);
}

/* Thumbnail */
.gls-result-item__thumb {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: var(--gls-thumb-radius);
    overflow: hidden;
    background: var(--gls-input-bg);
}

.gls-result-item__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

/* Content */
.gls-result-item__content {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.gls-result-item__header {
    display: flex;
    align-items: center;
    gap: 8px;
}

.gls-result-item__title {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--gls-font);
    color: var(--gls-text-primary);
    line-height: 1.4;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.01em;
}

.gls-result-item--active .gls-result-item__title {
    color: #fff;
}

.gls-result-item__type {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 6px;
    background: var(--gls-type-bg);
    font-size: 11px;
    font-weight: 500;
    color: var(--gls-type-color);
    line-height: 1;
    letter-spacing: 0.01em;
    white-space: nowrap;
}

.gls-result-item__excerpt {
    margin: 3px 0 0;
    font-size: 13px;
    color: var(--gls-text-secondary);
    line-height: 1.45;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gls-result-item__meta {
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 14px;
}

.gls-result-item__date {
    font-size: 11px;
    font-weight: 500;
    color: var(--gls-text-tertiary);
    line-height: 1;
    text-transform: none;
}

.gls-result-item--active .gls-result-item__date {
    color: rgba(255, 255, 255, 0.78);
}

/* Arrow */
.gls-result-item__arrow {
    flex-shrink: 0;
    color: var(--gls-text-tertiary);
    opacity: 0;
    transform: translateX(-4px);
    transition: opacity var(--gls-transition), transform var(--gls-transition);
}

.gls-result-item__link:hover .gls-result-item__arrow,
.gls-result-item--active .gls-result-item__arrow {
    opacity: 1;
    transform: translateX(0);
}

/* Load more button */
.gls-load-more {
    display: flex;
    justify-content: center;
    padding: 10px 10px 6px;
}

.gls-load-more__btn {
    appearance: none;
    border: 1px solid var(--gls-border);
    background: var(--gls-input-bg);
    color: var(--gls-text-primary);
    border-radius: 999px;
    font-family: var(--gls-font);
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    padding: 9px 14px;
    cursor: pointer;
    transition: background var(--gls-transition), border-color var(--gls-transition), transform var(--gls-transition);
}

.gls-load-more__btn:hover {
    background: var(--gls-bg-hover);
    border-color: rgba(0, 113, 227, 0.22);
    transform: translateY(-1px);
}

.gls-load-more__btn:disabled {
    cursor: default;
    opacity: 0.72;
    transform: none;
}

/* ─────────────────────────────────────────────
 * HIGHLIGHT MARK
 * ───────────────────────────────────────────── */
.gls-highlight {
    background: var(--gls-highlight-bg);
    color: var(--gls-highlight-color);
    border-radius: 3px;
    padding: 0 2px;
    font-weight: 600;
}

/* ─────────────────────────────────────────────
 * STATUS MESSAGES (Loading, No Results, Error)
 * ───────────────────────────────────────────── */
.gls-status {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px 20px;
    text-align: center;
    font-family: var(--gls-font);
    color: var(--gls-text-secondary);
    animation: glsFadeIn var(--gls-transition) forwards;
}

@keyframes glsFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.gls-status p {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
}

.gls-status strong {
    color: var(--gls-text-primary);
}

/* Spinner */
.gls-spinner {
    width: 28px;
    height: 28px;
    position: relative;
}

.gls-spinner__ring {
    width: 100%;
    height: 100%;
    border: 2.5px solid var(--gls-divider);
    border-top-color: var(--gls-accent);
    border-radius: 50%;
    animation: glsSpin 0.65s linear infinite;
}

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

/* ─────────────────────────────────────────────
 * INLINE / DROPDOWN SEARCH
 * ───────────────────────────────────────────── */
.gls-inline-search,
.gls-input-wrapper {
    position: relative;
    font-family: var(--gls-font);
}

.gls-input-wrapper {
    display: inline-block;
    width: 100%;
}

.gls-search-field {
    position: relative;
    display: flex;
    align-items: center;
}

.gls-search-field__icon {
    position: absolute;
    left: 14px;
    color: var(--gls-text-tertiary);
    pointer-events: none;
    z-index: 1;
}

.gls-search-field__input {
    width: 100%;
    padding: 12px 16px 12px 44px;
    border: 1px solid var(--gls-border);
    border-radius: var(--gls-radius-sm);
    background: var(--gls-input-bg);
    font-family: var(--gls-font);
    font-size: 15px;
    font-weight: 400;
    color: var(--gls-text-primary);
    outline: none;
    transition: border-color var(--gls-transition), box-shadow var(--gls-transition), background var(--gls-transition);
    -webkit-appearance: none;
    appearance: none;
}

.gls-search-field__input:focus {
    border-color: var(--gls-accent);
    box-shadow: 0 0 0 3px rgba(0, 113, 227, 0.15);
    background: var(--gls-bg);
}

.gls-search-field__input::placeholder {
    color: var(--gls-text-tertiary);
}

/* Dropdown results */
.gls-dropdown-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 99999;
    background: var(--gls-bg);
    -webkit-backdrop-filter: blur(var(--gls-backdrop-blur)) saturate(180%);
    backdrop-filter: blur(var(--gls-backdrop-blur)) saturate(180%);
    border: 1px solid var(--gls-border);
    border-radius: var(--gls-radius);
    box-shadow: var(--gls-shadow);
    max-height: 400px;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 6px;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity var(--gls-transition), transform var(--gls-transition), visibility var(--gls-transition);
}

.gls-dropdown--visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.gls-dropdown-results::-webkit-scrollbar {
    width: 6px;
}

.gls-dropdown-results::-webkit-scrollbar-thumb {
    background: var(--gls-divider);
    border-radius: 3px;
}

/* ─────────────────────────────────────────────
 * RESPONSIVE
 * ───────────────────────────────────────────── */
@media (max-width: 640px) {
    .gls-overlay {
        padding-top: 0;
        align-items: stretch;
    }

    .gls-overlay__container {
        max-width: 100%;
        margin: 0;
        border-radius: 0;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .gls-overlay__results {
        flex: 1;
        max-height: none;
    }

    .gls-overlay__footer {
        flex-direction: column;
        gap: 6px;
    }

    .gls-overlay__hint {
        display: none;
    }

    .gls-result-item__thumb {
        width: 40px;
        height: 40px;
    }

    .gls-result-item__link {
        align-items: flex-start;
        gap: 10px;
        padding: 10px 12px;
    }

    .gls-result-item__header {
        align-items: flex-start;
        gap: 6px;
        flex-wrap: wrap;
    }

    .gls-result-item__title {
        white-space: normal;
        overflow: hidden;
        text-overflow: clip;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        line-height: 1.35;
        max-width: 100%;
    }

    .gls-result-item__type {
        font-size: 10px;
        padding: 2px 7px;
    }

    .gls-result-item__arrow {
        display: none;
    }
}

/* ─────────────────────────────────────────────
 * REDUCED MOTION
 * ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }
}

/* ─────────────────────────────────────────────
 * LIGHT THEME (explicit)
 * ───────────────────────────────────────────── */
.gls-theme-geek-light {
    --gls-bg: rgba(255, 255, 255, 0.95);
    --gls-backdrop-blur: 20px;
    --gls-shadow: 0 8px 32px rgba(0, 0, 0, 0.08), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

/* ─────────────────────────────────────────────
 * MINIMAL THEME
 * ───────────────────────────────────────────── */
.gls-theme-geek-minimal {
    --gls-bg: #ffffff;
    --gls-backdrop-blur: 0px;
    --gls-shadow: 0 4px 16px rgba(0, 0, 0, 0.06), 0 0 0 1px rgba(0, 0, 0, 0.04);
    --gls-radius: 12px;
    --gls-radius-sm: 8px;
}
