/**
 * ai-search-widget.css
 * Path: public_html/css/ai-search-widget.css
 * Version: 1.5.0
 * 
 * Styles for the AI Search floating chat widget.
 * Desktop: floating bubble bottom-right, 400x500 chat window
 * Mobile: full-screen chat overlay
 * 
 * Changelog v1.4.0:
 * - Added email capture prompt styles
 * - Added email success state styles
 * - Added email error state styles
 * - Added fade-out animation for email capture
 * 
 * Changelog v1.3.0:
 * - Version bump to match JS v1.3.0 Phase 9 features
 * - No CSS changes needed (styles already existed)
 * 
 * Changelog v1.2.1:
 * - Tool card subtitle now wraps (max 2 lines) instead of truncating
 * 
 * Changelog v1.2.0:
 * - Phase 9: Polish & Optimization
 * - Added error state styling with icons
 * - Added retry indicator text
 * - Added suggestion chips for empty state
 * - Added offline indicator styling
 * - Added bullet point styling for formatted responses
 * - Improved accessibility with focus states
 * 
 * Changelog v1.1.6:
 * - Larger close button on mobile (44x44px touch target)
 * - Improved tap feedback with active state
 */

/* ===========================================
   FLOATING CHAT BUBBLE - BASE
   =========================================== */
.ai-search-bubble {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    cursor: pointer;
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease, opacity 0.3s ease;
}

.ai-search-bubble:hover {
    transform: scale(1.1);
}

.ai-search-bubble:focus {
    outline: 3px solid rgba(102, 126, 234, 0.5);
    outline-offset: 2px;
}

.ai-search-bubble.hidden {
    display: none;
}

.ai-search-bubble svg {
    width: 28px;
    height: 28px;
    fill: white;
}

/* Bubble tooltip label - visible initially, fades with JS class after 10s, shows on hover */
.ai-search-bubble .bubble-label {
    position: absolute;
    bottom: 70px;
    right: 0;
    background: white;
    padding: 8px 12px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    color: #333;
    box-shadow: 0 2px 12px rgba(0,0,0,0.15);
    white-space: nowrap;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.5s ease, transform 0.3s ease;
    pointer-events: none;
}

.ai-search-bubble .bubble-label::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 20px;
    width: 12px;
    height: 12px;
    background: white;
    transform: rotate(45deg);
    box-shadow: 2px 2px 4px rgba(0,0,0,0.05);
}

/* After 10 seconds, JS adds this class to fade out */
.ai-search-bubble.label-faded .bubble-label {
    opacity: 0;
    transform: translateY(10px);
}

/* On hover, always show label (even if faded) */
.ai-search-bubble:hover .bubble-label {
    opacity: 1;
    transform: translateY(0);
}

/* ===========================================
   DESIGN A: SEARCH + SPARKLES (Purple)
   =========================================== */
.ai-search-bubble.search-sparkles {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    animation: floatBubble 3s ease-in-out infinite;
}

.ai-search-bubble.search-sparkles:hover {
    box-shadow: 0 6px 25px rgba(99, 102, 241, 0.5);
}

.ai-search-bubble.search-sparkles::before {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    animation: pulse 2s ease-out infinite;
    z-index: -1;
}

/* Sparkles */
.ai-search-bubble .sparkle {
    position: absolute;
    width: 8px;
    height: 8px;
    background: #fbbf24;
    border-radius: 50%;
    animation: sparkle 1.5s ease-in-out infinite;
}

.ai-search-bubble .sparkle:nth-child(1) { top: 5px; right: 8px; animation-delay: 0s; }
.ai-search-bubble .sparkle:nth-child(2) { top: 12px; right: -2px; animation-delay: 0.3s; width: 6px; height: 6px; }
.ai-search-bubble .sparkle:nth-child(3) { top: -3px; right: 15px; animation-delay: 0.6s; width: 5px; height: 5px; }

@keyframes sparkle {
    0%, 100% { opacity: 0; transform: scale(0); }
    50% { opacity: 1; transform: scale(1); }
}

@keyframes floatBubble {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* ===========================================
   DESIGN B: FRIENDLY ROBOT (Green)
   =========================================== */
.ai-search-bubble.friendly-robot {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
    border-radius: 16px;
    animation: wiggle 3s ease-in-out infinite;
}

.ai-search-bubble.friendly-robot:hover {
    box-shadow: 0 6px 25px rgba(16, 185, 129, 0.5);
}

.ai-search-bubble.friendly-robot::before {
    display: none;
}

/* Robot face */
.robot-face {
    width: 32px;
    height: 32px;
    position: relative;
}

.robot-antenna {
    position: absolute;
    top: -8px;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 8px;
    background: white;
}

.robot-antenna::after {
    content: '';
    position: absolute;
    top: -4px;
    left: -3px;
    width: 8px;
    height: 8px;
    background: #fbbf24;
    border-radius: 50%;
    animation: glow 1s ease-in-out infinite alternate;
}

.robot-eyes {
    display: flex;
    justify-content: space-between;
    padding: 0 4px;
    margin-top: 4px;
}

.robot-eye {
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 2px;
    animation: blink 3s ease-in-out infinite;
}

.robot-mouth {
    width: 16px;
    height: 4px;
    background: white;
    border-radius: 2px;
    margin: 6px auto 0;
}

@keyframes blink {
    0%, 90%, 100% { transform: scaleY(1); }
    95% { transform: scaleY(0.1); }
}

@keyframes wiggle {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(3deg); }
    75% { transform: rotate(-3deg); }
}

@keyframes glow {
    from { box-shadow: 0 0 5px #fbbf24; }
    to { box-shadow: 0 0 15px #fbbf24, 0 0 20px #fbbf24; }
}

/* ===========================================
   CHAT WIDGET CONTAINER
   =========================================== */
.ai-search-widget {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 400px;
    height: 550px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
}

.ai-search-widget.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ===========================================
   WIDGET HEADER
   =========================================== */
.ai-search-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.ai-search-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-search-header-title svg {
    width: 24px;
    height: 24px;
    fill: white;
}

.ai-search-header-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
}

.ai-search-close {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.ai-search-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.ai-search-close:active {
    background: rgba(255, 255, 255, 0.4);
}

.ai-search-close:focus {
    outline: 2px solid white;
    outline-offset: 2px;
}

/* ===========================================
   CHAT MESSAGES AREA
   =========================================== */
.ai-search-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #f8f9fa;
}

/* Message bubbles */
.ai-search-message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.5;
    font-size: 14px;
    animation: fadeIn 0.3s ease;
}

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

.ai-search-message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border-bottom-right-radius: 4px;
}

.ai-search-message.assistant {
    align-self: flex-start;
    background: white;
    color: #333;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.ai-search-message.assistant strong {
    color: #667eea;
}

/* Bullet point styling */
.ai-search-message .ai-search-bullet {
    display: block;
    padding-left: 8px;
    margin: 4px 0;
}

/* ===========================================
   ERROR STATES
   =========================================== */
.ai-search-message.ai-search-error {
    background: #fff5f5;
    border: 1px solid #fed7d7;
    color: #c53030;
}

.ai-search-message.ai-search-error .ai-search-error-icon {
    margin-right: 8px;
    font-size: 16px;
}

.ai-search-message.ai-search-offline {
    background: #fffbeb;
    border: 1px solid #fcd34d;
    color: #92400e;
}

/* ===========================================
   SUGGESTION CHIPS
   =========================================== */
.ai-search-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.ai-search-suggestion-chip {
    background: #e9ecef;
    border: 1px solid #dee2e6;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12px;
    color: #495057;
    cursor: pointer;
    transition: all 0.2s ease;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-search-suggestion-chip:hover {
    background: #667eea;
    border-color: #667eea;
    color: white;
}

.ai-search-suggestion-chip:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

/* Welcome message */
.ai-search-welcome {
    text-align: center;
    padding: 20px;
    color: #666;
}

.ai-search-welcome h4 {
    margin: 0 0 8px;
    color: #333;
    font-size: 16px;
}

.ai-search-welcome p {
    margin: 0 0 16px;
    font-size: 14px;
}

/* Tool cards in responses */
.ai-search-tools {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 12px;
}

.ai-search-tool-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: #f8f9fa;
    border-radius: 10px;
    text-decoration: none;
    color: #333;
    transition: background 0.2s ease, transform 0.2s ease;
}

.ai-search-tool-card:hover {
    background: #e9ecef;
    transform: translateX(4px);
}

.ai-search-tool-card:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.ai-search-tool-logo {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    object-fit: cover;
    background: #fff;
}

.ai-search-tool-info {
    flex: 1;
    min-width: 0;
}

.ai-search-tool-name {
    font-weight: 600;
    font-size: 13px;
    color: #333;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.ai-search-tool-subtitle {
    font-size: 11px;
    color: #666;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.3;
}

.ai-search-tool-arrow {
    color: #667eea;
    font-size: 18px;
}

/* Loading indicator */
.ai-search-loading {
    align-self: flex-start;
    padding: 12px 16px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-search-loading-dots {
    display: flex;
    gap: 4px;
}

.ai-search-loading-dots span {
    width: 8px;
    height: 8px;
    background: #667eea;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.ai-search-loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-search-loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

/* Retry indicator */
.ai-search-retry-text {
    font-size: 11px;
    color: #888;
    font-style: italic;
}

@keyframes bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* ===========================================
   EMAIL CAPTURE PROMPT
   =========================================== */
.ai-search-email-capture {
    align-self: flex-start;
    width: 92%;
    padding: 14px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.08) 0%, rgba(118, 75, 162, 0.08) 100%);
    border: 1px solid rgba(102, 126, 234, 0.25);
    border-radius: 12px;
    position: relative;
    animation: fadeIn 0.3s ease;
}

.ai-search-email-dismiss {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: none;
    background: rgba(0, 0, 0, 0.08);
    border-radius: 50%;
    color: #666;
    font-size: 16px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
}

.ai-search-email-dismiss:hover {
    background: rgba(0, 0, 0, 0.15);
    color: #333;
}

.ai-search-email-content {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 10px;
    padding-right: 20px;
}

.ai-search-email-icon {
    width: 28px;
    height: 28px;
    min-width: 28px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}

.ai-search-email-icon svg {
    width: 14px;
    height: 14px;
}

.ai-search-email-icon-success {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

.ai-search-email-text {
    flex: 1;
}

.ai-search-email-title {
    margin: 0 0 2px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
}

.ai-search-email-subtitle {
    margin: 0;
    font-size: 12px;
    color: #666;
}

.ai-search-email-form {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.ai-search-email-input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 13px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    min-width: 0;
}

.ai-search-email-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.15);
}

.ai-search-email-input.ai-search-email-error {
    border-color: #e53e3e;
    box-shadow: 0 0 0 2px rgba(229, 62, 62, 0.15);
}

.ai-search-email-button {
    padding: 8px 14px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.2s ease;
    white-space: nowrap;
}

.ai-search-email-button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.ai-search-email-button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.ai-search-email-disclaimer {
    margin: 0;
    font-size: 11px;
    color: #888;
}

.ai-search-email-error-msg {
    margin: 4px 0 0;
    font-size: 11px;
    color: #e53e3e;
}

/* Email capture success state */
.ai-search-email-capture.ai-search-email-success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.08) 0%, rgba(5, 150, 105, 0.08) 100%);
    border-color: rgba(16, 185, 129, 0.25);
}

.ai-search-email-capture.ai-search-email-success .ai-search-email-content {
    margin-bottom: 0;
    padding-right: 0;
}

/* Email capture fade out */
.ai-search-email-capture.ai-search-email-fade-out {
    opacity: 0;
    transform: translateY(-10px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

/* ===========================================
   INPUT AREA
   =========================================== */
.ai-search-input-area {
    padding: 12px 16px;
    background: white;
    border-top: 1px solid #e9ecef;
    flex-shrink: 0;
}

.ai-search-input-wrapper {
    display: flex;
    gap: 8px;
    align-items: center;
}

.ai-search-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    font-size: 16px; /* Prevents zoom on iOS */
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    -webkit-appearance: none; /* Remove iOS styling */
    appearance: none;
}

.ai-search-input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.ai-search-input::placeholder {
    color: #999;
}

.ai-search-input:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
    opacity: 0.7;
}

.ai-search-input:disabled::placeholder {
    color: #888;
    font-style: italic;
}

.ai-search-send {
    width: 44px;
    height: 44px;
    min-width: 44px; /* Prevent shrinking */
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
    -webkit-tap-highlight-color: transparent;
}

.ai-search-send:hover {
    transform: scale(1.05);
}

.ai-search-send:focus {
    outline: 2px solid #667eea;
    outline-offset: 2px;
}

.ai-search-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ai-search-send svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Rate limit message */
.ai-search-rate-limit {
    padding: 8px 12px;
    background: #fff3cd;
    color: #856404;
    font-size: 12px;
    text-align: center;
    border-radius: 8px;
    margin-top: 8px;
}

/* ===========================================
   MOBILE STYLES
   =========================================== */
@media (max-width: 480px) {
    .ai-search-bubble {
        bottom: 24px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    
    .ai-search-widget {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }
    
    .ai-search-widget.open {
        transform: none;
    }
    
    .ai-search-header {
        padding: 12px 16px;
    }
    
    /* Larger close button on mobile for better touch target (44x44px minimum) */
    .ai-search-close {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
    
    .ai-search-close svg {
        width: 22px;
        height: 22px;
    }
    
    .ai-search-messages {
        padding: 12px;
    }
    
    .ai-search-message {
        max-width: 90%;
        font-size: 15px;
    }
    
    .ai-search-input-area {
        padding: 10px 12px;
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }
    
    /* Suggestion chips on mobile */
    .ai-search-suggestion-chip {
        font-size: 13px;
        padding: 8px 14px;
    }
    
    /* Email capture on mobile */
    .ai-search-email-capture {
        width: 95%;
    }
    
    .ai-search-email-form {
        flex-direction: column;
    }
    
    .ai-search-email-button {
        width: 100%;
        padding: 10px 14px;
    }
}


/* Hide bubble when mobile menu is open */
body.mobile-menu-open .ai-search-bubble {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}


/* ===========================================
   DARK MODE SUPPORT
   =========================================== */
@media (prefers-color-scheme: dark) {
    .ai-search-widget {
        background: #1a1a2e;
    }
    
    .ai-search-messages {
        background: #16162a;
    }
    
    .ai-search-message.assistant {
        background: #252540;
        color: #e0e0e0;
    }
    
    .ai-search-message.ai-search-error {
        background: #2d1f1f;
        border-color: #5c2626;
        color: #f87171;
    }
    
    .ai-search-message.ai-search-offline {
        background: #2d2a1f;
        border-color: #a67c00;
        color: #fbbf24;
    }
    
    .ai-search-welcome {
        color: #aaa;
    }
    
    .ai-search-welcome h4 {
        color: #e0e0e0;
    }
    
    .ai-search-tool-card {
        background: #252540;
        color: #e0e0e0;
    }
    
    .ai-search-tool-card:hover {
        background: #303050;
    }
    
    .ai-search-tool-name {
        color: #e0e0e0;
    }
    
    .ai-search-tool-subtitle {
        color: #999;
    }
    
    .ai-search-input-area {
        background: #1a1a2e;
        border-top-color: #333;
    }
    
    .ai-search-input {
        background: #252540;
        border-color: #404060;
        color: #e0e0e0;
    }
    
    .ai-search-input:focus {
        border-color: #667eea;
    }
    
    .ai-search-loading {
        background: #252540;
    }
    
    .ai-search-suggestion-chip {
        background: #252540;
        border-color: #404060;
        color: #aaa;
    }
    
    .ai-search-suggestion-chip:hover {
        background: #667eea;
        border-color: #667eea;
        color: white;
    }
    
    .ai-search-bubble .bubble-label {
        background: #252540;
        color: #e0e0e0;
    }
    
    .ai-search-bubble .bubble-label::after {
        background: #252540;
    }
    
    /* Email capture dark mode */
    .ai-search-email-capture {
        background: linear-gradient(135deg, rgba(102, 126, 234, 0.12) 0%, rgba(118, 75, 162, 0.12) 100%);
        border-color: rgba(102, 126, 234, 0.3);
    }
    
    .ai-search-email-dismiss {
        background: rgba(255, 255, 255, 0.1);
        color: #aaa;
    }
    
    .ai-search-email-dismiss:hover {
        background: rgba(255, 255, 255, 0.2);
        color: #e0e0e0;
    }
    
    .ai-search-email-title {
        color: #e0e0e0;
    }
    
    .ai-search-email-subtitle {
        color: #aaa;
    }
    
    .ai-search-email-input {
        background: #252540;
        border-color: #404060;
        color: #e0e0e0;
    }
    
    .ai-search-email-input:focus {
        border-color: #667eea;
    }
    
    .ai-search-email-disclaimer {
        color: #777;
    }
    
    .ai-search-email-capture.ai-search-email-success {
        background: linear-gradient(135deg, rgba(16, 185, 129, 0.12) 0%, rgba(5, 150, 105, 0.12) 100%);
        border-color: rgba(16, 185, 129, 0.3);
    }
}

/* ===========================================
   PRINT - HIDE WIDGET
   =========================================== */
@media print {
    .ai-search-bubble,
    .ai-search-widget {
        display: none !important;
    }
}