/**
 * Search Widget Styles
 * Professional instant search dropdown
 *
 * @version 1.0.0
 * @date November 15, 2025
 */

/* Search Widget Container */
.search-widget {
    position: relative;
    max-width: 500px;
    width: 100%;
}

/* Search Input */
.search-input-container {
    position: relative;
    display: flex;
    align-items: center;
    background: white;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    transition: all 0.3s ease;
    overflow: hidden;
}

.search-input-container:focus-within {
    border-color: var(--theme-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.search-icon {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
    font-size: 1.2rem;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

#search-input {
    flex: 1;
    padding: 12px 50px 12px 45px;
    border: none;
    font-size: 0.95rem;
    outline: none;
    background: transparent;
}

#search-input::placeholder {
    color: #9ca3af;
}

/* Voice Search Button */
#voice-search-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    font-size: 1.2rem;
    color: #6b7280;
    transition: all 0.3s;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#voice-search-btn:hover {
    background: #f3f4f6;
    color: var(--theme-primary, #2563eb);
}

#voice-search-btn.listening {
    color: #ef4444;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Search Dropdown */
#search-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    left: 0;
    right: 0;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    max-height: 500px;
    overflow-y: auto;
    z-index: 1000;
    display: none;
}

/* Suggestions Container */
.search-suggestions {
    padding: 10px;
}

/* Individual Suggestion Item */
.search-suggestion-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: all 0.2s;
    cursor: pointer;
}

.search-suggestion-item:hover,
.search-suggestion-item.selected {
    background: #f3f4f6;
}

.suggestion-image {
    flex-shrink: 0;
    width: 50px;
    height: 50px;
    border-radius: 6px;
    overflow: hidden;
    background: #f9fafb;
    display: flex;
    align-items: center;
    justify-content: center;
}

.suggestion-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.suggestion-icon {
    font-size: 1.8rem;
}

.suggestion-content {
    flex: 1;
    min-width: 0;
}

.suggestion-title {
    font-weight: 600;
    color: #1f2937;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.suggestion-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: #6b7280;
}

.suggestion-type {
    display: inline-block;
    padding: 2px 8px;
    background: #e0e7ff;
    color: #4338ca;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    text-transform: uppercase;
}

.suggestion-desc {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* View All Results Link */
.search-view-all {
    display: block;
    padding: 12px 15px;
    text-align: center;
    color: var(--theme-primary, #2563eb);
    font-weight: 600;
    text-decoration: none;
    border-top: 1px solid #e5e7eb;
    transition: all 0.2s;
}

.search-view-all:hover {
    background: #f9fafb;
}

/* Loading State */
.search-loading {
    padding: 30px;
    text-align: center;
    color: #6b7280;
}

.loading-spinner {
    width: 30px;
    height: 30px;
    border: 3px solid #e5e7eb;
    border-top-color: var(--theme-primary, #2563eb);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin: 0 auto 10px;
}

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

/* No Results State */
.search-no-results {
    padding: 40px 20px;
    text-align: center;
    color: #6b7280;
}

/* Mobile Responsive */
@media (max-width: 768px) {
    /* Hide header search on mobile to show mobile menu toggle */
    .header-search {
        display: none !important;
    }

    .search-widget {
        max-width: 100%;
    }

    #search-dropdown {
        max-height: 400px;
    }

    .suggestion-desc {
        display: none;
    }
}

/* Scrollbar Styling */
#search-dropdown::-webkit-scrollbar {
    width: 8px;
}

#search-dropdown::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 10px;
}

#search-dropdown::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

#search-dropdown::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Header Integration Specific Styles */
.header-search {
    display: flex;
    align-items: center;
    gap: 20px;
}

.header-search .search-widget {
    max-width: 400px;
}

/* Dark Header Variant */
.header-dark .search-input-container {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.2);
}

.header-dark #search-input {
    color: white;
}

.header-dark #search-input::placeholder {
    color: rgba(255, 255, 255, 0.6);
}

.header-dark .search-icon {
    color: rgba(255, 255, 255, 0.6);
}

.header-dark #voice-search-btn {
    color: rgba(255, 255, 255, 0.7);
}

.header-dark #voice-search-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
}

/* Accessibility */
.search-suggestion-item:focus {
    outline: 2px solid var(--theme-primary, #2563eb);
    outline-offset: 2px;
}

/* Print Styles */
@media print {
    .search-widget,
    #search-dropdown {
        display: none !important;
    }
}

/* ==============================================
   Icon Only Search Widget Styles
   ============================================== */

/* Search Icon Button (when widget_style = icon_only) */
.header-search-icon {
    display: flex;
    align-items: center;
}

#search-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    background: transparent;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.3s ease;
}

/* Ensure SVG displays correctly in Safari */
#search-toggle-btn svg {
    display: block;
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
}

#search-close-btn svg {
    display: block;
    width: 20px;
    height: 20px;
    stroke: currentColor;
    fill: none;
}

#search-toggle-btn:hover {
    border-color: var(--theme-primary, #2563eb);
    color: var(--theme-primary, #2563eb);
    background: rgba(37, 99, 235, 0.05);
}

#search-toggle-btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

/* Search Overlay Container */
.search-overlay {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: auto;
    display: flex;
    align-items: center;
    background: var(--theme-background, #ffffff);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transform: translateX(20px);
    transition: all 0.3s ease;
    padding: 0 15px;
    border-radius: 0;
}

.search-overlay.is-active {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.search-overlay-content {
    display: flex;
    align-items: center;
    width: 100%;
    max-width: none; /* Allow full width */
}

/* Full-width search input in overlay */
.search-widget-overlay {
    width: 100%;
}

/* Search widget inside overlay */
.search-widget-overlay {
    flex: 1;
    max-width: none;
}

.search-widget-overlay .search-input-container {
    background: var(--theme-background, #ffffff);
    border-color: var(--theme-primary, #2563eb);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

/* Close Button */
#search-close-btn {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: #6b7280;
    transition: all 0.3s;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: 5px;
}

#search-close-btn:hover {
    background: #f3f4f6;
    color: #1f2937;
}

/* Adjust input padding when close button is present */
.search-widget-overlay #search-input {
    padding-right: 80px;
}

.search-widget-overlay #voice-search-btn {
    right: 45px;
}

/* Dark Header Variant for Icon Button */
.header-dark #search-toggle-btn {
    border-color: rgba(255, 255, 255, 0.3);
    color: rgba(255, 255, 255, 0.8);
}

.header-dark #search-toggle-btn:hover {
    border-color: rgba(255, 255, 255, 0.6);
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

/* Transparent Header Variant */
.header-transparent #search-toggle-btn {
    border-color: rgba(255, 255, 255, 0.4);
    color: rgba(255, 255, 255, 0.9);
}

.header-transparent #search-toggle-btn:hover {
    border-color: white;
    color: white;
    background: rgba(255, 255, 255, 0.15);
}

.header-transparent .search-overlay {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
}

/* Scrolled header state */
.site-header.scrolled .search-overlay {
    background: var(--theme-background, #ffffff);
}

/* Position the overlay correctly in header */
.header-content {
    position: relative;
}

/* Hide icon button on mobile */
@media (max-width: 768px) {
    .header-search-icon {
        display: none !important;
    }

    .search-overlay {
        display: none !important;
    }
}

/* Ensure overlay doesn't cover logo */
@media (min-width: 769px) {
    .search-overlay {
        /* Width calculated by JS to extend from logo to right edge */
        left: auto;
        right: 0;
        /* Width will be set dynamically by JavaScript */
    }
}
