/**
 * AI Site Search Widget Styles
 * =============================
 * 
 * TABLE OF CONTENTS:
 * 1. CSS Variables & Configuration
 * 2. Base Widget Styles
 * 3. Default Search Input (Light Theme)
 * 4. Glass Effect Search Input (Dark Theme)
 * 5. Search Button Styles
 * 6. Modal Overlay
 * 7. Modal Content & Header
 * 8. Modal Search Input
 * 9. Suggestions Panel
 * 10. Results Display
 * 11. Loading & Error States
 * 12. Animations
 * 13. Responsive Styles
 */


/* ==========================================================================
   1. CSS VARIABLES & CONFIGURATION
   ========================================================================== */

.ai-site-search-widget {
    /* Primary brand color - change this to match your theme */
    --ai-search-primary: #ff6b00;
    
    /* Text colors */
    --ai-search-text-dark: #081428;
    --ai-search-text-light: #ffffff;
    --ai-search-text-muted: #6b7280;
    
    /* Background colors */
    --ai-search-bg-light: #ffffff;
    --ai-search-bg-hover: rgba(245, 236, 255, 0.8);
    --ai-search-bg-subtle: #f9fafb;
    
    /* Border colors */
    --ai-search-border-light: rgba(194, 196, 202, 0.4);
    --ai-search-border-default: #c2c4ca;
    --ai-search-border-input: #e5e7eb;
    
    /* Shadows */
    --ai-search-shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.08);
    --ai-search-shadow-modal: 0 0 14px rgba(0, 0, 0, 0.25);
    
    /* Border radius */
    --ai-search-radius-sm: 8px;
    --ai-search-radius-md: 10px;
    --ai-search-radius-full: 20px;
    
    /* Font family */
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    max-width: 800px;
    margin: 0 auto;
}


/* ==========================================================================
   2. BASE WIDGET STYLES
   ========================================================================== */

.ai-search-container {
    position: relative;
}


/* ==========================================================================
   3. DEFAULT SEARCH INPUT (Light Theme)
   ========================================================================== */

.ai-search-input-wrapper {
    display: flex;
    align-items: center;
    height: 65px;
    background: var(--ai-search-bg-light);
    border-radius: var(--ai-search-radius-md);
    box-shadow: var(--ai-search-shadow-soft);
    overflow: hidden;
    border: 1px solid var(--ai-search-border-light);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-search-input-wrapper:hover {
    border-color: var(--ai-search-border-default);
}

.ai-search-input-wrapper:focus-within {
    background: var(--ai-search-bg-hover);
    box-shadow: 0 0 0 2px rgba(255, 107, 0, 0.2);
}

.ai-search-input-section {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 20px;
    background: linear-gradient(91deg, rgba(255, 255, 255, 0.1) 2%, rgba(255, 255, 255, 0.2) 79%);
}

.ai-search-icon {
    width: 16px;
    height: 16px;
    color: var(--ai-search-text-dark);
    flex-shrink: 0;
}

.ai-search-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 18px 0;
    font-size: 16px;
    font-family: inherit;
    background: transparent;
    color: var(--ai-search-text-dark);
    cursor: pointer;
}

.ai-search-input::placeholder {
    color: var(--ai-search-text-dark);
}

.ai-sparkle-icon {
    width: 31px;
    height: 26px;
    flex-shrink: 0;
}


/* ==========================================================================
   4. GLASS EFFECT SEARCH INPUT (Dark Theme / Transparent)
   Use with: .ai-search-glass class on widget
   Best used on dark backgrounds (hero sections, banners, etc.)
   ========================================================================== */

.ai-search-glass .ai-search-glass-input {
    /* Glass effect background - semi-transparent gradient */
    background: linear-gradient(98deg, rgba(255, 255, 255, 0.08) 2%, rgba(255, 255, 255, 0.24) 74%);
    
    /* White border for contrast on dark backgrounds */
    border: 2px solid rgba(255, 255, 255, 1);
    
    /* Compact height matching Figma design */
    height: 50px;
    
    /* Reset shadow for cleaner glass look */
    box-shadow: none;
    
    /* Backdrop blur for frosted glass effect (modern browsers) */
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.ai-search-glass .ai-search-glass-input:focus-within {
    /* Slightly more visible on focus */
    background: linear-gradient(98deg, rgba(255, 255, 255, 0.12) 2%, rgba(255, 255, 255, 0.32) 74%);
    border-color: rgba(255, 255, 255, 1);
}

.ai-search-glass .ai-search-input-section {
    /* Remove default gradient, keep transparent */
    background: transparent;
    padding: 0 20px;
}

/* White text and icons for dark backgrounds */
.ai-search-glass .ai-search-icon {
    color: var(--ai-search-text-light);
}

.ai-search-glass .ai-search-input {
    color: var(--ai-search-text-light);
    /* Reduced padding for compact 50px height */
    padding: 10px 0;
}

.ai-search-glass .ai-search-input::placeholder {
    color: var(--ai-search-text-light);
    opacity: 0.9;
}

/* Compact button for glass variant - matches Figma 154px width */
.ai-search-glass .ai-search-submit {
    width: 154px;
    height: 46px;
    border-radius: 0 var(--ai-search-radius-sm) var(--ai-search-radius-sm) 0;
    margin: 2px;
    margin-left: 0;
}


/* ==========================================================================
   5. SEARCH BUTTON STYLES
   ========================================================================== */

.ai-search-submit {
    width: 156px;
    height: 65px;
    border-radius: 0 var(--ai-search-radius-md) var(--ai-search-radius-md) 0;
    background: var(--ai-search-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--ai-search-text-light);
    font-family: inherit;
    font-weight: 700;
    font-size: 16px;
    transition: opacity 0.2s;
    flex-shrink: 0;
}

.ai-search-submit:hover {
    opacity: 0.9;
}

.ai-search-submit:active {
    transform: scale(0.98);
}

.ai-search-submit svg {
    width: 16px;
    height: 16px;
}


/* ==========================================================================
   6. MODAL OVERLAY
   ========================================================================== */

body .ai-search-modal,
.ai-site-search-widget .ai-search-modal {
    /* Duplicate CSS variables for when modal is portaled to body */
    --ai-search-primary: #ff6b00;
    --ai-search-text-dark: #081428;
    --ai-search-text-light: #ffffff;
    --ai-search-text-muted: #6b7280;
    --ai-search-bg-light: #ffffff;
    --ai-search-bg-hover: rgba(245, 236, 255, 0.8);
    --ai-search-bg-subtle: #f9fafb;
    --ai-search-border-light: rgba(194, 196, 202, 0.4);
    --ai-search-border-default: #c2c4ca;
    --ai-search-border-input: #e5e7eb;
    --ai-search-shadow-soft: 0 4px 20px rgba(0, 0, 0, 0.08);
    --ai-search-shadow-modal: 0 0 14px rgba(0, 0, 0, 0.25);
    --ai-search-radius-sm: 8px;
    --ai-search-radius-md: 10px;
    --ai-search-radius-full: 20px;
    font-family: 'Space Grotesk', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    /* Maximum z-index to ensure modal appears above any parent popups */
    z-index: 2147483647;
    align-items: center;
    justify-content: center;
    padding: 20px 16px;
    /* No scroll on overlay - scroll happens in modal-content */
    overflow: hidden;
    transition: align-items 0.3s ease;
}

/* When results are shown, align modal to top */
body .ai-search-modal.has-results,
.ai-site-search-widget .ai-search-modal.has-results {
    align-items: flex-start;
}

body .ai-search-modal.active,
.ai-site-search-widget .ai-search-modal.active {
    display: flex;
}


/* ==========================================================================
   7. MODAL CONTENT & HEADER
   ========================================================================== */

body .ai-search-modal-content,
.ai-site-search-widget .ai-search-modal-content {
    background: var(--ai-search-bg-light);
    border-radius: var(--ai-search-radius-md);
    width: 100%;
    max-width: 1000px;
    box-shadow: var(--ai-search-shadow-modal);
    /* Single scroll container for all modal content */
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    position: relative;
    z-index: 2147483647;
    /* Ensure modal uses maximum available height */
    max-height: calc(100vh - 40px);
    /* Prevent shrinking when content is small */
    flex-shrink: 0;
}

.ai-search-modal-header {
    padding: 25px 40px;
    border-bottom: 1px solid var(--ai-search-border-light);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    background: var(--ai-search-bg-light);
    position: sticky;
    top: 0;
    z-index: 10;
}

.ai-search-modal-title {
    font-weight: 600;
    font-size: 16px;
    text-transform: uppercase;
    color: var(--ai-search-text-dark);
    margin: 0 0 4px;
    letter-spacing: 0.02em;
}

.ai-search-modal-subtitle {
    font-weight: 300;
    font-size: 18px;
    color: var(--ai-search-text-dark);
    margin: 0;
}

.ai-search-close-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f5f5f5;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ai-search-close-btn:hover {
    background: #e5e5e5;
}


/* ==========================================================================
   8. MODAL SEARCH INPUT
   ========================================================================== */

body .ai-search-modal-body,
.ai-site-search-widget .ai-search-modal-body {
    padding: 30px 40px;
}

.ai-search-modal-input-wrapper {
    display: flex;
    align-items: center;
    height: 55px;
    background: var(--ai-search-bg-hover);
    border: 1px solid var(--ai-search-border-default);
    border-radius: var(--ai-search-radius-md);
    overflow: hidden;
    margin-bottom: 20px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-search-modal-input-wrapper:focus-within {
    box-shadow: 0 0 0 2px rgba(255, 107, 0, 0.2);
}

.ai-search-modal-input-section {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 20px;
}

.ai-search-modal-input {
    flex: 1;
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    padding: 15px 0;
    font-size: 16px;
    font-family: inherit;
    background: transparent;
    color: var(--ai-search-text-dark);
}

.ai-search-modal-input:focus,
.ai-search-modal-input:focus-visible,
.ai-search-modal-input:focus-within {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
}

.ai-search-modal-input::placeholder {
    color: var(--ai-search-text-dark);
}

.ai-search-modal-submit {
    width: 156px;
    height: 55px;
    border-radius: var(--ai-search-radius-md);
    background: var(--ai-search-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    color: var(--ai-search-text-light);
    font-family: inherit;
    font-weight: 700;
    font-size: 16px;
    margin-right: -1px;
}

.ai-search-modal-submit:hover {
    opacity: 0.9;
}


/* ==========================================================================
   9. SUGGESTIONS PANEL
   ========================================================================== */

body .ai-search-suggestions,
.ai-site-search-widget .ai-search-suggestions {
    margin-top: 15px;
    display: flex;
    flex-direction: column;
    flex-wrap: nowrap;
    gap: 0;
    width: 100%;
}

body .ai-search-suggestion-item,
.ai-site-search-widget .ai-search-suggestion-item {
    display: block;
    float: none;
    clear: both;
    padding: 12px 16px;
    margin: 0;
    border: none;
    border-bottom: 1px solid var(--ai-search-border-light);
    border-radius: 0;
    font-size: 14px;
    color: var(--ai-search-text-dark);
    cursor: pointer;
    transition: background-color 0.2s, color 0.2s;
    background: transparent;
    text-align: left;
    width: 100%;
    box-sizing: border-box;
    white-space: normal;
    line-height: 1.5;
}

body .ai-search-suggestion-item:hover,
.ai-site-search-widget .ai-search-suggestion-item:hover {
    color: var(--ai-search-primary);
    background: var(--ai-search-bg-hover);
}

body .ai-search-suggestion-item:last-child,
.ai-site-search-widget .ai-search-suggestion-item:last-child {
    border-bottom: none;
}

body .ai-search-suggestion-label,
.ai-site-search-widget .ai-search-suggestion-label {
    color: var(--ai-search-text-muted);
    margin-right: 4px;
}


/* ==========================================================================
   10. RESULTS DISPLAY
   ========================================================================== */

body .ai-search-results,
.ai-site-search-widget .ai-search-results {
    padding: 30px 40px;
    border-top: 1px solid var(--ai-search-border-light);
}

.ai-search-answer {
    display: none;
}

.answer-text {
    font-size: 16px;
    line-height: 1.7;
    color: #374151;
    margin-bottom: 20px;
}

.related-pages h4,
.related-questions h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--ai-search-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin: 20px 0 12px;
}

.pages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pages-section-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--ai-search-text-muted);
    margin-top: 16px;
    margin-bottom: 8px;
}

.pages-section-label:first-child {
    margin-top: 0;
}

.page-link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: var(--ai-search-bg-subtle);
    border: 1px solid var(--ai-search-border-input);
    border-radius: var(--ai-search-radius-sm);
    text-decoration: none;
    color: #374151;
    font-size: 14px;
    transition: all 0.2s;
}

.page-link:hover {
    background: #fff7ed;
    border-color: var(--ai-search-primary);
    color: var(--ai-search-primary);
}

.page-link svg {
    flex-shrink: 0;
    opacity: 0.5;
}

.questions-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.question-pill {
    padding: 10px 16px;
    background: #f3f4f6;
    border: 1px solid var(--ai-search-border-input);
    border-radius: var(--ai-search-radius-full);
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    color: #374151;
    transition: all 0.2s;
}

.question-pill:hover {
    background: var(--ai-search-primary);
    border-color: var(--ai-search-primary);
    color: var(--ai-search-text-light);
}

.ai-search-new-query {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 0;
    margin-top: 20px;
    background: transparent;
    color: var(--ai-search-text-muted);
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-family: inherit;
    font-weight: 600;
    transition: opacity 0.2s;
    display: none;
}

.ai-search-new-query:hover {
    color: var(--ai-search-primary);
}

.ai-search-new-query::after {
    content: '→';
    font-size: 16px;
}


/* ==========================================================================
   11. LOADING & ERROR STATES
   ========================================================================== */

.ai-search-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px 24px;
    color: var(--ai-search-text-muted);
}

.loading-animation {
    display: flex;
    align-items: center;
    gap: 20px;
}

.loading-sparkle {
    width: 32px;
    height: 32px;
    color: var(--ai-search-primary);
    animation: sparkle-pulse 1.5s ease-in-out infinite;
}

.loading-dots {
    display: flex;
    gap: 6px;
}

.loading-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--ai-search-primary);
    animation: dot-bounce 1.4s ease-in-out infinite;
}

.loading-dot:nth-child(1) {
    animation-delay: 0s;
}

.loading-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.loading-dot:nth-child(3) {
    animation-delay: 0.4s;
}

.loading-message {
    font-size: 15px;
    font-weight: 500;
    color: var(--ai-search-text-dark);
    text-align: center;
    min-height: 24px;
    animation: message-fade 0.5s ease-in-out;
}

.loading-submessage {
    font-size: 13px;
    color: var(--ai-search-text-muted);
    font-weight: 400;
}

.ai-search-error {
    padding: 16px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: var(--ai-search-radius-sm);
    color: #dc2626;
    font-size: 14px;
    text-align: center;
}

/* Synthesized content indicator */
.synthesized-indicator {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 12px;
    padding: 6px 12px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    border: 1px solid #bae6fd;
    border-radius: 20px;
    font-size: 12px;
    color: #0369a1;
    font-weight: 500;
}

.synthesized-indicator svg {
    width: 14px;
    height: 14px;
}


/* ==========================================================================
   12. ANIMATIONS
   ========================================================================== */

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

@keyframes sparkle-pulse {
    0%, 100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
    50% {
        transform: scale(1.2) rotate(180deg);
        opacity: 0.7;
    }
}

@keyframes dot-bounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.4;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes message-fade {
    0% {
        opacity: 0;
        transform: translateY(-5px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}


/* ==========================================================================
   13. RESPONSIVE STYLES
   ========================================================================== */

@media (max-width: 768px) {
    .ai-search-input-wrapper {
        height: 55px;
    }
    
    .ai-search-submit {
        width: 100px;
        height: 55px;
        font-size: 14px;
    }
    
    .ai-search-submit span {
        display: none;
    }
    
    /* Modal responsive - full screen on mobile */
    .ai-search-modal {
        padding: 12px;
        align-items: flex-start;
    }
    
    .ai-search-modal-content {
        width: 100%;
        max-height: calc(100vh - 24px);
        border-radius: 12px;
    }
    
    .ai-search-modal-header {
        padding: 16px 20px;
    }
    
    .ai-search-modal-title {
        font-size: 14px;
    }
    
    .ai-search-modal-subtitle {
        font-size: 16px;
    }
    
    .ai-search-modal-body,
    .ai-search-results {
        padding: 16px 20px;
    }
    
    .ai-search-modal-input-wrapper {
        height: 48px;
    }
    
    .ai-search-modal-submit {
        width: 80px;
        height: 48px;
        font-size: 14px;
    }
    
    .ai-search-modal-submit span {
        display: none;
    }
    
    /* Glass variant responsive */
    .ai-search-glass .ai-search-glass-input {
        height: 50px;
    }
    
    .ai-search-glass .ai-search-submit {
        height: 46px;
        width: 100px;
    }
    
    .ai-search-glass .ai-search-submit span {
        display: none;
    }
}

@media (max-width: 480px) {
    .ai-search-input {
        font-size: 15px;
    }
    
    .questions-list {
        flex-direction: column;
    }
    
    .question-pill {
        text-align: center;
    }
}


/* ==========================================================================
   14. ACCESSIBILITY STYLES
   ========================================================================== */

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

/* Focus visible indicators */
.ai-search-input-wrapper:focus-visible,
.ai-search-submit:focus-visible,
.ai-search-close-btn:focus-visible,
.ai-search-modal-submit:focus-visible,
.ai-search-suggestion-item:focus-visible,
.ai-search-new-query:focus-visible,
.question-pill:focus-visible,
.page-link:focus-visible {
    outline: 2px solid var(--ai-search-primary, #ff6b00);
    outline-offset: 2px;
}

/* Remove focus from non-interactive elements */
.answer-text,
.ai-search-answer p,
.ai-search-answer div {
    outline: none !important;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    .ai-site-search-widget *,
    .ai-site-search-widget *::before,
    .ai-site-search-widget *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .loading-dot,
    .loading-sparkle {
        animation: none !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .ai-search-input-wrapper,
    .ai-search-modal-content {
        border-width: 2px;
    }
    
    .ai-search-submit,
    .ai-search-modal-submit,
    .ai-search-new-query {
        border: 2px solid currentColor;
    }
}
