/**
 * Global Search Styles
 * Modern, responsive styles for the global search component
 * IMPORTANT: All search results have white background for better readability
 */

/* ==== FORCE WHITE BACKGROUND OVERRIDE ==== */
.global-search-results,
.global-search-results *,
.search-result-item,
.search-header,
.search-footer,
.no-results,
.search-error,
.search-loading {
    background-color: #ffffff !important;
}

/* ==== SEARCH INPUT CONTAINER ==== */
.global-search-container {
    position: relative;
    display: flex;
    align-items: center;
}

.global-search-input {
    background-color: rgba(255, 255, 255, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.3);
    color: #fff;
    transition: all 0.3s ease;
}

.global-search-input:focus {
    background-color: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 0 0 0.2rem rgba(255, 255, 255, 0.25);
    color: #fff;
}

.global-search-input::placeholder {
    color: rgba(255, 255, 255, 0.7);
}

/* Search button styling */
.global-search-container .btn-outline-light {
    border-left: 0;
    background-color: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.9);
    transition: all 0.3s ease;
}

.global-search-container .btn-outline-light:hover {
    background-color: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.5);
    color: #fff;
}

/* ==== RESULTS DROPDOWN ==== */
.global-search-results {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    z-index: 1050;
    margin-top: 2px;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    background-color: #ffffff !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    min-width: 500px;
    max-width: 800px;
    width: max-content;
    /* Ensure it's not affected by Bootstrap dropdown styles */
    transform: none !important;
    opacity: 1 !important;
    text-align: left !important;
}

.global-search-results.show {
    display: block;
    animation: searchResultsSlideIn 0.2s ease-out;
}

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

/* ==== SEARCH HEADER ==== */
.search-header {
    background: #ffffff !important;
    border-bottom: 1px solid #e9ecef;
    text-align: left !important;
}

.search-header * {
    text-align: left !important;
}

.search-header .text-muted {
    font-size: 0.8rem;
}

/* ==== RESULT ITEMS ==== */
.search-result-item {
    cursor: pointer;
    transition: all 0.2s ease;
    border-left: 3px solid transparent;
    text-decoration: none;
    color: inherit;
    background-color: #ffffff !important;
    text-align: left !important;
}

.search-result-item:hover,
.search-result-item.selected {
    background-color: #f8f9fa;
    border-left-color: var(--primary-color, #007bff);
    transform: translateX(2px);
}

.search-result-item.selected {
    background-color: rgba(var(--primary-color-rgb, 0, 123, 255), 0.1);
    border-left-color: var(--primary-color, #1976d2);
}

/* Result content styling */
.result-content {
    text-align: left !important;
}

.result-content * {
    text-align: left !important;
}

.result-icon i {
    font-size: 1.1rem;
    width: 20px;
    text-align: center;
    color: var(--primary-color, #007bff);
}

.result-title {
    font-size: 0.95rem;
    line-height: 1.3;
    margin-bottom: 0.25rem;
    text-align: left !important;
}

.result-title mark {
    background-color: rgba(var(--primary-color-rgb, 0, 123, 255), 0.2);
    color: var(--primary-hover, #0056b3);
    padding: 1px 2px;
    border-radius: 2px;
    font-weight: 600;
}

.result-snippet {
    font-size: 0.85rem;
    line-height: 1.4;
    color: #6c757d;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-align: left !important;
}

.result-snippet mark {
    background-color: rgba(var(--primary-color-rgb, 0, 123, 255), 0.2);
    color: var(--primary-hover, #0056b3);
    padding: 1px 2px;
    border-radius: 2px;
}

.result-meta {
    font-size: 0.75rem;
    text-align: left !important;
}

.result-meta .badge {
    font-size: 0.7rem;
    padding: 0.25em 0.5em;
}

.result-actions {
    opacity: 0;
    transition: opacity 0.2s ease;
}

.search-result-item:hover .result-actions,
.search-result-item.selected .result-actions {
    opacity: 1;
}

/* ==== SEARCH FOOTER ==== */
.search-footer {
    background: #ffffff !important;
    border-top: 1px solid #e9ecef;
    text-align: left !important;
}

.search-footer * {
    text-align: left !important;
}

.search-footer .btn {
    font-size: 0.8rem;
    padding: 0.375rem 0.75rem;
}

/* ==== SPECIAL STATES ==== */
.no-results,
.search-error,
.search-loading {
    padding: 2rem 1.5rem;
    background-color: #ffffff !important;
    text-align: left !important;
}

.no-results i,
.search-error i {
    opacity: 0.6;
}

/* ==== UTILITY CLASSES ==== */
.hover-bg-light:hover {
    background-color: #f8f9fa;
}

.cursor-pointer {
    cursor: pointer;
}

/* ==== RESPONSIVE DESIGN ==== */
@media (max-width: 768px) {
    .global-search-container {
        min-width: 250px !important;
    }

    .global-search-results {
        min-width: 400px;
        max-width: calc(100vw - 2rem);
        left: 50%;
        transform: translateX(-50%);
    }

    .result-content {
        min-width: 0; /* Allow flex item to shrink */
    }

    .result-snippet {
        -webkit-line-clamp: 1;
    }

    .result-meta .badge:nth-child(n+3) {
        display: none; /* Hide extra badges on mobile */
    }
}

@media (max-width: 576px) {
    .global-search-container .input-group {
        min-width: 200px !important;
    }

    .global-search-input::placeholder {
        font-size: 0.9rem;
    }

    .search-footer .btn {
        font-size: 0.75rem;
        padding: 0.25rem 0.5rem;
    }

    .search-footer .d-flex {
        flex-direction: column;
        gap: 0.5rem;
    }
}

/* ==== FORCE WHITE BACKGROUND ==== */
@media (prefers-color-scheme: dark) {
    .global-search-results {
        background-color: #ffffff !important;
        border-color: #dee2e6;
        color: #212529;
    }

    .search-header,
    .search-footer {
        background: #ffffff !important;
        color: #212529;
        border-color: #e9ecef;
    }

    .search-result-item {
        background-color: #ffffff !important;
        color: #212529;
    }

    .search-result-item:hover,
    .search-result-item.selected {
        background-color: #f8f9fa !important;
    }

    .search-result-item.selected {
        background-color: rgba(var(--primary-color-rgb, 0, 123, 255), 0.1) !important;
    }

    .result-snippet {
        color: #6c757d !important;
    }

    .result-title mark,
    .result-snippet mark {
        background-color: rgba(var(--primary-color-rgb, 0, 123, 255), 0.2) !important;
        color: var(--primary-hover, #0056b3) !important;
    }

    .no-results,
    .search-error,
    .search-loading {
        background-color: #ffffff !important;
        color: #212529;
    }
}

/* ==== KEYBOARD NAVIGATION INDICATORS ==== */
.global-search-container:focus-within .global-search-input {
    background-color: rgba(255, 255, 255, 0.25);
    border-color: rgba(255, 255, 255, 0.5);
}

/* Focus indicators for accessibility */
.search-result-item:focus {
    outline: 2px solid #007bff;
    outline-offset: -2px;
}

.global-search-input:focus {
    outline: none; /* Bootstrap handles this */
}

/* ==== ANIMATION FOR LOADING STATE ==== */
@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.search-loading .spinner-border {
    animation: spin 1s linear infinite;
}

.search-loading p {
    animation: pulse 1.5s ease-in-out infinite;
}

/* ==== HIGH CONTRAST MODE SUPPORT ==== */
@media (prefers-contrast: high) {
    .global-search-input {
        border-width: 2px;
    }

    .search-result-item:hover,
    .search-result-item.selected {
        border-left-width: 4px;
    }

    .result-title mark,
    .result-snippet mark {
        outline: 1px solid currentColor;
    }
}

/* ==== REDUCED MOTION SUPPORT ==== */
@media (prefers-reduced-motion: reduce) {
    .global-search-results.show {
        animation: none;
    }

    .search-result-item {
        transition: none;
    }

    .search-result-item:hover {
        transform: none;
    }

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

/* ==== CUSTOM SCROLLBAR FOR RESULTS ==== */
.global-search-results::-webkit-scrollbar {
    width: 6px;
}

.global-search-results::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 3px;
}

.global-search-results::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 3px;
}

.global-search-results::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ==== PRINT STYLES ==== */
@media print {
    .global-search-container {
        display: none;
    }
}