/* ========================================
   SEARCH BAR & RESULTS
   Documentation search functionality
   ======================================== */

/* Search Container */
.search-container {
    flex: 1;
    max-width: 500px;
    margin: 0 2rem;
    position: relative;
    z-index: 1200;
}

.search-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
    border: 1px solid var(--border-color);
    border-radius: 12px;
    transition: all 0.25s ease;
    height: 38px;
    overflow: hidden;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}

.search-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow:
        0 0 0 3px rgba(0, 229, 208, 0.16),
        0 10px 28px rgba(0, 0, 0, 0.3);
    background: var(--background-color);
    transform: translateY(-1px);
}

/* Search Icon */
.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-secondary, #9aa5a8);
    pointer-events: none;
    transition: color 0.2s ease;
}

.search-wrapper:focus-within .search-icon {
    color: var(--primary-color);
}

/* Search Input */
.search-input {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    padding: 0 12px 0 40px;
    color: var(--text-color);
    font-size: 14px;
    font-family: inherit;
    height: 100%;
}

.search-input::placeholder {
    color: var(--text-secondary, #9aa5a8);
}

.search-mobile-close {
    display: none;
    border: none;
    background: transparent;
    color: var(--text-secondary, #9aa5a8);
    height: 100%;
    width: 42px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    border-left: 1px solid var(--border-color);
    transition: all 0.2s ease;
}

.search-mobile-close:hover {
    color: var(--text-color);
    background: rgba(255, 255, 255, 0.05);
}

.search-mobile-trigger {
    display: none;
    background: none;
    border: 2px solid var(--border-color);
    color: var(--text-color);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    transition: all 0.3s ease;
    margin-right: 0.5rem;
}

.search-mobile-trigger:hover {
    border-color: var(--accent-color);
    background: var(--surface-color);
    transform: scale(1.05);
}

.search-backdrop {
    display: none;
}

/* Search Shortcut Badge */
.search-shortcut {
    position: absolute;
    right: 8px;
    padding: 3px 8px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 11px;
    font-family: monospace;
    color: var(--text-secondary, #9aa5a8);
    pointer-events: none;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.search-wrapper:focus-within .search-shortcut {
    display: none;
}

/* Search Results Dropdown */
.search-results {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 
        0 12px 32px rgba(0, 0, 0, 0.4),
        0 4px 12px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(0, 229, 208, 0.1);
    max-height: 500px;
    overflow-y: auto;
    z-index: 1000;
    animation: searchResultsAppear 0.2s ease;
}

@keyframes searchResultsAppear {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

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

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

.search-results::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Search Results Content */
.search-results-content {
    padding: 8px;
}

/* Search Result Item */
.search-result-item {
    display: flex;
    flex-direction: column;
    padding: 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    color: inherit;
    border: 1px solid transparent;
    gap: 6px;
}

.search-result-item:hover,
.search-result-item.active {
    background: linear-gradient(135deg, var(--background-color), rgba(255, 255, 255, 0.02));
    border-color: var(--primary-color);
    transform: translateY(-1px);
}

.search-result-item[data-title-match="true"] {
    border-left: 3px solid var(--primary-color);
    background: linear-gradient(90deg, rgba(79, 224, 210, 0.08), transparent);
}

.search-result-item[data-title-match="true"]:hover,
.search-result-item[data-title-match="true"].active {
    background: linear-gradient(90deg, rgba(79, 224, 210, 0.15), rgba(255, 255, 255, 0.02));
}

.search-result-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-color);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.search-result-title svg {
    width: 16px;
    height: 16px;
    color: var(--primary-color);
    flex-shrink: 0;
}

.search-result-context {
    font-size: 13px;
    color: var(--text-secondary, #9aa5a8);
    line-height: 1.5;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    line-clamp: 2;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.search-result-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.search-result-path {
    font-size: 11px;
    letter-spacing: 0.2px;
    text-transform: uppercase;
    color: var(--text-secondary, #9aa5a8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-chips {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
}

.search-result-chip {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.2px;
    text-transform: uppercase;
    border-radius: 999px;
    padding: 2px 7px;
    border: 1px solid var(--border-color);
    color: var(--text-secondary, #9aa5a8);
    background: rgba(255, 255, 255, 0.04);
}

.search-result-chip-tag {
    color: #b0fff9;
    border-color: rgba(79, 224, 210, 0.45);
    background: rgba(79, 224, 210, 0.12);
}

.search-result-chip-difficulty {
    color: #ffdda6;
    border-color: rgba(245, 158, 11, 0.45);
    background: rgba(245, 158, 11, 0.14);
}

.search-result-chip-owner {
    color: #c8d6ff;
    border-color: rgba(99, 102, 241, 0.45);
    background: rgba(99, 102, 241, 0.14);
}

.search-result-chip-writer {
    color: #dccdff;
    border-color: rgba(147, 51, 234, 0.45);
    background: rgba(147, 51, 234, 0.14);
}

.search-result-chip-match {
    color: #052d2f;
    border-color: rgba(79, 224, 210, 0.55);
    background: linear-gradient(120deg, #4fe0d2, #97efe9);
}

.search-result-badge {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: #052d2f;
    background: linear-gradient(120deg, #4fe0d2, #97efe9);
    border-radius: 999px;
    padding: 3px 8px;
    flex-shrink: 0;
}

/* Highlight matched text */
.search-highlight {
    background: var(--primary-color);
    color: var(--background-color);
    padding: 2px 4px;
    border-radius: 3px;
    font-weight: 600;
}

/* No Results Message */
.search-no-results {
    padding: 24px;
    text-align: center;
    color: var(--text-secondary, #9aa5a8);
}

.search-no-results svg {
    width: 48px;
    height: 48px;
    margin-bottom: 12px;
    opacity: 0.3;
}

.search-no-results p {
    margin: 0;
    font-size: 14px;
}

/* Loading State */
.search-loading {
    padding: 24px;
    text-align: center;
    color: var(--text-secondary, #9aa5a8);
}

.search-loading-spinner {
    display: inline-block;
    width: 24px;
    height: 24px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: searchSpinner 0.8s linear infinite;
    margin-bottom: 8px;
}

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

/* Search Info Footer */
.search-info {
    padding: 8px 12px;
    border-top: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-secondary, #9aa5a8);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.search-filters-active {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 6px;
}

.search-filter-chip {
    display: inline-flex;
    align-items: center;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.04);
    padding: 2px 8px;
}

.search-info-shortcuts {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-left: auto;
}

.search-info-shortcuts kbd {
    padding: 2px 6px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 3px;
    font-size: 10px;
    font-family: monospace;
}

[data-theme="light"] .search-wrapper {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(15, 118, 110, 0.23);
    box-shadow: 0 10px 22px rgba(15, 118, 110, 0.11);
}

[data-theme="light"] .search-wrapper:focus-within {
    border-color: rgba(15, 118, 110, 0.5);
    box-shadow:
        0 0 0 3px rgba(15, 118, 110, 0.14),
        0 14px 26px rgba(15, 118, 110, 0.14);
    background: #ffffff;
}

[data-theme="light"] .search-shortcut {
    background: rgba(15, 118, 110, 0.08);
    border-color: rgba(15, 118, 110, 0.24);
    color: #3f606a;
}

[data-theme="light"] .search-results {
    background: #ffffff;
    border-color: rgba(15, 118, 110, 0.26);
    box-shadow:
        0 14px 30px rgba(15, 118, 110, 0.14),
        0 4px 12px rgba(8, 145, 178, 0.1),
        0 0 0 1px rgba(15, 118, 110, 0.08);
}

[data-theme="light"] .search-result-item:hover,
[data-theme="light"] .search-result-item.active {
    background: linear-gradient(135deg, #f2fbfa, #eaf8f7);
}

[data-theme="light"] .search-result-chip {
    color: #4a6570;
    background: rgba(15, 118, 110, 0.07);
    border-color: rgba(15, 118, 110, 0.23);
}

[data-theme="light"] .search-result-chip-tag {
    color: #0f5f63;
    border-color: rgba(15, 118, 110, 0.33);
    background: rgba(15, 118, 110, 0.12);
}

[data-theme="light"] .search-result-chip-difficulty {
    color: #8b5a08;
    border-color: rgba(217, 119, 6, 0.33);
    background: rgba(217, 119, 6, 0.12);
}

[data-theme="light"] .search-result-chip-owner {
    color: #245d87;
    border-color: rgba(14, 116, 144, 0.32);
    background: rgba(14, 116, 144, 0.12);
}

[data-theme="light"] .search-result-chip-writer {
    color: #32568b;
    border-color: rgba(37, 99, 235, 0.32);
    background: rgba(37, 99, 235, 0.11);
}

[data-theme="light"] .search-filter-chip {
    background: rgba(15, 118, 110, 0.07);
    border-color: rgba(15, 118, 110, 0.22);
}

[data-theme="light"] .search-backdrop {
    background: rgba(15, 118, 110, 0.2);
}

/* Responsive Design */
@media (max-width: 900px) {
    .search-container {
        position: fixed;
        top: 70px;
        left: 12px;
        right: 12px;
        margin: 0;
        max-width: none;
        opacity: 0;
        transform: translateY(-8px);
        pointer-events: none;
        transition: opacity 0.2s ease, transform 0.2s ease;
    }

    .search-container.mobile-open {
        opacity: 1;
        transform: translateY(0);
        pointer-events: auto;
    }
    
    .search-wrapper {
        height: 44px;
        border-radius: 12px;
        box-shadow:
            0 20px 40px rgba(0, 0, 0, 0.5),
            0 0 0 1px rgba(0, 229, 208, 0.1);
    }
    
    .search-results {
        max-height: min(62vh, 460px);
    }
    
    .search-shortcut {
        display: none;
    }

    .search-mobile-close {
        display: flex;
    }

    .search-mobile-trigger {
        display: inline-flex;
    }

    .search-backdrop {
        position: fixed;
        inset: 60px 0 0 0;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(3px);
        z-index: 1100;
    }

    .search-backdrop.active {
        display: block;
    }
}

@media (min-width: 901px) {
    .search-mobile-trigger,
    .search-mobile-close,
    .search-backdrop {
        display: none !important;
    }
}

/* Medium screens - reduce search bar width */
@media (max-width: 1024px) {
    .search-container {
        max-width: 300px;
        margin: 0 1rem;
    }
}
