/* ============================================
   Clinical Search - Enhanced Styles
   Fuse.js fuzzy search component
   ============================================ */

/* Search Container */
.search-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: stretch;
}

.search-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 12px;
    pointer-events: none;
    color: rgba(255, 255, 255, 0.7);
    z-index: 2;
}

#condition-search {
    width: 220px;
    padding: 8px 36px 8px 40px;
    font-size: 15px;
    line-height: 1.4;
    color: white;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 24px;
    transition: all 0.2s ease;
}

#condition-search::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

#condition-search:focus {
    outline: none;
    width: 280px;
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.8);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.1);
}

/* Clear button */
.search-clear {
    position: absolute;
    right: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    border-radius: 50%;
    transition: all 0.15s ease;
}

.search-clear:hover {
    color: white;
    background: rgba(255, 255, 255, 0.2);
}

.search-clear:focus {
    outline: 2px solid white;
    outline-offset: 1px;
}

/* Results Dropdown */
.search-results {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 350px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--bg-primary, white);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    overscroll-behavior: contain;
}

.search-results[hidden] {
    display: none;
}

/* Result Items */
.search-result-item {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    text-decoration: none;
    color: var(--text-primary, #111827);
    border-bottom: 1px solid var(--border-color, #e5e7eb);
    transition: background 0.15s ease;
    cursor: pointer;
}

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

.search-result-item:hover,
.search-result-item:focus,
.search-result-item.selected {
    background-color: var(--bg-highlight, #eff6ff);
    outline: none;
}

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

.search-result-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.search-result-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary, #111827);
    line-height: 1.4;
}

.search-result-title mark {
    background-color: #fef3c7;
    color: #92400e;
    padding: 1px 3px;
    border-radius: 2px;
    font-weight: 700;
}

.search-result-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted, #6b7280);
}

.search-result-path {
    font-family: ui-monospace, monospace;
}

.search-result-score {
    flex-shrink: 0;
    padding: 3px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--secondary-color, #059669);
    background-color: rgba(5, 150, 105, 0.1);
    border-radius: 4px;
}

/* No Results / Error States */
.search-no-results,
.search-error {
    padding: 20px 16px;
    text-align: center;
}

.search-no-results p:first-child {
    font-weight: 600;
    color: var(--text-primary, #111827);
    margin-bottom: 8px;
}

.search-hint {
    font-size: 14px;
    color: var(--text-secondary, #4b5563);
}

.search-hint a {
    color: var(--primary-color, #1e40af);
    text-decoration: underline;
}

.search-error {
    color: #dc2626;
}

/* Loading State */
.search-loading {
    padding: 16px;
    text-align: center;
    color: var(--text-muted, #6b7280);
}

.search-loading::after {
    content: '';
    display: inline-block;
    width: 14px;
    height: 14px;
    margin-left: 8px;
    border: 2px solid var(--border-color, #e5e7eb);
    border-top-color: var(--primary-color, #1e40af);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Screen Reader Only */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    .search-container {
        width: 100%;
        margin-top: 1rem;
    }

    #condition-search {
        width: 100%;
    }

    #condition-search:focus {
        width: 100%;
    }

    .search-results {
        position: fixed;
        top: 60px;
        left: 16px;
        right: 16px;
        width: auto;
        max-height: calc(100vh - 80px);
    }
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
    .search-result-item,
    #condition-search,
    .search-clear {
        transition: none;
    }

    .search-loading::after {
        animation: none;
    }
}

/* High Contrast Mode */
@media (prefers-contrast: high) {
    .search-result-item:focus {
        outline-width: 3px;
    }

    .search-result-title mark {
        background-color: #fef08a;
        color: #000;
    }
}
