/* css/ai-chat.css */

/* Floating Pill Launcher */
.ai-chat-launcher {
    height: 46px;
    padding: 0 16px 0 13px;
    border-radius: 999px;
    background: #7236ff;
    color: #ffffff;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(26, 115, 232, 0.35), 0 2px 6px rgba(0, 0, 0, 0.12);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 99998;
    transition: transform 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
    user-select: none;
}

.ai-chat-launcher:hover {
    transform: translateY(-2px);
    background: #1557b0;
    box-shadow: 0 6px 20px rgba(26, 115, 232, 0.45), 0 3px 8px rgba(0, 0, 0, 0.15);
}

.ai-chat-launcher-text {
    font-size: 14px;
    font-weight: 600;
    letter-spacing: 0.2px;
    color: #ffffff;
    white-space: nowrap;
}

.ai-chat-launcher svg {
    width: 28px;
    height: 28px;
    fill: currentColor;
}

/* Chat Widget Container */
.ai-chat-widget {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.16);
    display: flex;
    flex-direction: column;
    z-index: 99999;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.25s ease, transform 0.25s ease, visibility 0.25s;
}

.ai-chat-widget.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Chat Header */
.ai-chat-header {
    background: #7236ff;
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-header-info h4 {
    margin: 0;
    font-size: 15px;
    font-weight: 600;
    color: #ffffff;
}

.ai-chat-header-badge {
    font-size: 11px;
    background: rgba(255, 255, 255, 0.22);
    padding: 2px 7px;
    border-radius: 10px;
}

.ai-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ai-chat-btn-icon {
    background: transparent;
    border: none;
    color: #ffffff;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.85;
    transition: opacity 0.2s ease, background 0.2s ease;
}

.ai-chat-btn-icon:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.15);
}

.ai-chat-btn-icon svg {
    width: 18px;
    height: 18px;
    fill: currentColor;
}

/* Chat Body (Message List) */
.ai-chat-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f8f9fa;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Message Bubbles */
.ai-chat-message {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    word-break: break-word;
    font-size: 13.5px;
    line-height: 1.45;
}

.ai-chat-message.user {
    align-self: flex-end;
}

.ai-chat-message.model {
    align-self: flex-start;
}

.ai-chat-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    white-space: pre-wrap;
}

.ai-chat-message.user .ai-chat-bubble {
    background: #7236ff;
    color: #ffffff;
    border-bottom-right-radius: 3px;
}

.ai-chat-message.model .ai-chat-bubble {
    background: #ffffff;
    color: #202124;
    border: 1px solid #e1e3e6;
    border-bottom-left-radius: 3px;
}

/* Loading Dots */
.ai-chat-loading {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: #ffffff;
    border: 1px solid #e1e3e6;
    border-radius: 14px;
    border-bottom-left-radius: 3px;
}

.ai-chat-loading.active {
    display: flex;
    align-items: center;
    gap: 4px;
}

.ai-chat-dot {
    width: 6px;
    height: 6px;
    background: #9aa0a6;
    border-radius: 50%;
    animation: aiChatPulse 1.4s infinite ease-in-out both;
}

.ai-chat-dot:nth-child(1) { animation-delay: -0.32s; }
.ai-chat-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes aiChatPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Chat Footer / Input */
.ai-chat-footer {
    padding: 12px;
    background: #ffffff;
    border-top: 1px solid #e8eaed;
}

.ai-chat-counter {
    font-size: 11px;
    color: #5f6368;
    margin-bottom: 6px;
    display: flex;
    justify-content: space-between;
}

.ai-chat-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.ai-chat-textarea {
    flex: 1;
    resize: none;
    border: 1px solid #dadce0;
    border-radius: 10px;
    padding: 9px 12px;
    font-size: 13px;
    font-family: inherit;
    max-height: 80px;
    min-height: 38px;
    outline: none;
    transition: border-color 0.2s ease;
}

.ai-chat-textarea:focus {
    border-color: #7236ff;
}

/* Send Button with Embedded SVG Background */
.ai-chat-send-btn {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    min-height: 38px !important;
    border-radius: 10px !important;
    border: none !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
    transition: background-color 0.2s ease, opacity 0.2s ease !important;
    
    /* Blue background + Pure White Paper Plane SVG */
    background-color: #7236ff !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Cpath d='M2.01 21L23 12 2.01 3 2 10l15 2-15 2z'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
    background-size: 18px 18px !important;
}

.ai-chat-send-btn:hover {
    background-color: #5e24e0 !important;
}

.ai-chat-send-btn:disabled {
    background-color: #9aa0a6 !important;
    opacity: 0.6 !important;
    cursor: not-allowed !important;
}

/* Mobile Responsiveness & Viewport Fix */
@media (max-width: 480px) {
    .ai-chat-widget {
        top: 0 !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100vw !important;
        max-width: 100vw !important;
        /* dvh accounts for dynamic mobile browser address bars */
        height: 100dvh !important;
        max-height: 100dvh !important;
        border-radius: 0 !important;
    }

    /* Keep header below phone notches and status bars */
    .ai-chat-header {
        padding-top: max(12px, env(safe-area-inset-top)) !important;
        padding-bottom: 12px !important;
    }

    /* Larger touch targets for mobile thumbs */
    .ai-chat-btn-icon {
        padding: 8px !important;
        min-width: 36px;
        min-height: 36px;
    }

    .ai-chat-btn-icon svg {
        width: 22px !important;
        height: 22px !important;
    }

    /* Ensure bottom input stays above iPhone home indicator bar */
    .ai-chat-footer {
        padding-bottom: max(12px, env(safe-area-inset-bottom)) !important;
    }
}


/* Launcher Container & Dismiss Button */
.ai-chat-launcher-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat-launcher-container.dismissed {
    display: none !important;
}

.ai-chat-launcher-container .ai-chat-launcher {
    position: static;
}

.ai-chat-dismiss-btn {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #5f6368;
    color: #ffffff;
    border: 2px solid #ffffff;
    font-size: 13px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    transition: background 0.2s ease, transform 0.2s ease;
    padding: 0;
}

.ai-chat-dismiss-btn:hover {
    background: #202124;
    transform: scale(1.1);
}


/* Ensure Send Button SVG is always visible */
.ai-chat-send-btn svg {
    display: block !important;
    margin: auto;
}

/* Native In-Widget Confirmation Dialog */
.ai-chat-modal {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
    animation: aiModalFadeIn 0.18s ease;
}

.ai-chat-modal[hidden] {
    display: none !important;
}

.ai-chat-modal-card {
    background: #ffffff;
    border-radius: 12px;
    padding: 20px;
    width: 100%;
    max-width: 290px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
    text-align: center;
    transform: scale(0.96);
    animation: aiModalPop 0.18s ease forwards;
}

.ai-chat-modal-text {
    margin: 0 0 16px 0;
    font-size: 14px;
    line-height: 1.45;
    color: #1f2937;
    font-weight: 500;
}

.ai-chat-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.ai-chat-modal-btn {
    flex: 1;
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: background 0.15s ease, transform 0.1s ease;
}

.ai-chat-modal-btn.cancel {
    background: #f3f4f6;
    color: #4b5563;
}

.ai-chat-modal-btn.cancel:hover {
    background: #e5e7eb;
}

.ai-chat-modal-btn.confirm {
    background: #ef4444;
    color: #ffffff;
}

.ai-chat-modal-btn.confirm:hover {
    background: #dc2626;
}

@keyframes aiModalFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes aiModalPop {
    to { transform: scale(1); }
}


/* Guest Teaser CTA Box */
.ai-guest-cta-box {
    margin-top: 16px;
    background: #ffffff;
    border: 1px solid #e1e3e6;
    border-radius: 12px;
    padding: 16px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
}

.ai-guest-btn-primary {
    display: block;
    background: #7236ff;
    color: #ffffff !important;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 14px;
    padding: 11px 16px;
    border-radius: 8px;
    transition: background 0.2s ease, transform 0.15s ease;
}

.ai-guest-btn-primary:hover {
    background: #5e24e0;
    transform: translateY(-1px);
}

.ai-guest-btn-secondary {
    display: inline-block;
    margin-top: 10px;
    color: #5f6368 !important;
    text-decoration: none !important;
    font-size: 12.5px;
    font-weight: 500;
    transition: color 0.2s ease;
}

.ai-guest-btn-secondary:hover {
    color: #7236ff !important;
    text-decoration: underline !important;
}

/* Guest Mock Input Box */
.ai-guest-mock-input {
    background: #f1f3f4;
    border: 1px solid #dadce0;
    border-radius: 10px;
    padding: 8px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 13px;
    color: #70757a;
    cursor: pointer;
    transition: border-color 0.2s ease;
    user-select: none;
}

.ai-guest-mock-input:hover {
    border-color: #7236ff;
}

.ai-guest-mock-btn {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    background-color: #7236ff;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='%23ffffff'%3E%3Cpath d='M2.01 21L23 12 2.01 3 2 10l15 2-15 2z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 13px 13px;
    opacity: 0.8;
}


/* --- AI chat greeting nudge --- */
.ai-nudge-bubble {
    position: absolute;
    bottom: calc(100% + 10px);
    right: 0;
    width: max-content;
    max-width: 260px;
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 12px 14px;
    background: #ffffff;
    color: #1f2937;
    font-size: 14px;
    line-height: 1.45;
    border-radius: 14px 14px 4px 14px;
    box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .25s ease, transform .25s ease;
    pointer-events: none;
    z-index: 9998;
}
.ai-nudge-bubble.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}
.ai-nudge-text { cursor: pointer; }
.ai-nudge-close {
    background: none;
    border: 0;
    padding: 0;
    margin-left: 2px;
    font-size: 18px;
    line-height: 1;
    color: #9ca3af;
    cursor: pointer;
}
.ai-nudge-close:hover { color: #4b5563; }

@media (max-width: 768px) {
    .ai-nudge-bubble {
        max-width: calc(100vw - 40px);
        font-size: 13px;
        padding: 10px 12px;
    }
}