/* ===== CHAT WIDGET CSS ===== */
/* Brand gradient: #667eea → #764ba2 */

/* --- Chat Toggle Button --- */
.chat-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

.chat-toggle-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.4);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.chat-toggle-btn:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 28px rgba(102, 126, 234, 0.5);
}

.chat-toggle-btn:active {
    transform: scale(0.95);
}

.chat-toggle-icon {
    display: block;
    transition: transform 0.3s, opacity 0.3s;
}

.chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    animation: badgePulse 2s infinite;
}

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

/* --- Chat Window --- */
.chat-window {
    position: absolute;
    bottom: 72px;
    right: 0;
    width: 380px;
    height: 500px;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: chatSlideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

@keyframes chatSlideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* --- Chat Header --- */
.chat-header {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.chat-header-text h4 {
    font-size: 0.95rem;
    font-weight: 600;
    margin: 0;
    line-height: 1.3;
}

.chat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    opacity: 0.85;
    margin-top: 1px;
}

.chat-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
}

.chat-status-dot.typing {
    background: #fbbf24;
    animation: statusBlink 1.5s infinite;
}

@keyframes statusBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.chat-header-actions {
    display: flex;
    gap: 4px;
}

.chat-header-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.chat-header-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* --- Chat Messages --- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 3px;
}

/* --- Message Bubbles --- */
.chat-message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: messageSlide 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.chat-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-message.assistant {
    align-self: flex-start;
}

.chat-message-system {
    align-self: center;
    text-align: center;
    padding: 8px 16px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 12px;
    font-size: 0.82rem;
    color: #888;
    max-width: 90%;
    animation: messageSlide 0.25s ease;
}

.chat-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
}

.chat-message.assistant .chat-msg-avatar {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
}

.chat-message.user .chat-msg-avatar {
    background: #f0f0f0;
    color: #555;
}

.chat-msg-content {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.9rem;
    line-height: 1.6;
    word-break: break-word;
}

.chat-message.assistant .chat-msg-content {
    background: #f1f5f9;
    color: #334155;
    border-bottom-left-radius: 4px;
}

.chat-message.user .chat-msg-content {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg-time {
    font-size: 0.7rem;
    opacity: 0.5;
    margin-top: 4px;
    text-align: right;
}

/* --- Typing Indicator --- */
.chat-typing-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 14px 18px;
    align-self: flex-start;
    margin-left: 40px;
}

.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #cbd5e1;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* --- Quick Actions --- */
.chat-quick-actions {
    display: flex;
    gap: 8px;
    padding: 10px 18px;
    overflow-x: auto;
    flex-shrink: 0;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    scrollbar-width: none;
}

.chat-quick-actions::-webkit-scrollbar {
    display: none;
}

.chat-quick-btn {
    white-space: nowrap;
    padding: 7px 14px;
    border-radius: 18px;
    border: 1px solid rgba(102, 126, 234, 0.25);
    background: rgba(102, 126, 234, 0.06);
    color: #667eea;
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-quick-btn:hover {
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border-color: transparent;
}

/* --- Lead Form (inline in chat) --- */
.chat-lead-form {
    position: absolute;
    bottom: 58px;
    left: 0;
    right: 0;
    background: #fff;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    max-height: 340px;
    overflow-y: auto;
    z-index: 10;
    animation: formSlideUp 0.3s ease;
}

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

.chat-lead-form-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 18px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
}

.chat-lead-form-header h5 {
    font-size: 0.9rem;
    font-weight: 600;
    margin: 0;
    color: #1a1a2e;
}

.chat-lead-form form {
    padding: 14px 18px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.chat-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.chat-form-group label {
    font-size: 0.82rem;
    font-weight: 500;
    color: #555;
}

.chat-form-group label .required {
    color: #ef4444;
}

.chat-form-group input,
.chat-form-group select,
.chat-form-group textarea {
    padding: 10px 12px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 0.88rem;
    font-family: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #fafbfc;
}

.chat-form-group input:focus,
.chat-form-group select:focus,
.chat-form-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    background: #fff;
}

.chat-form-group input.error,
.chat-form-group select.error,
.chat-form-group textarea.error {
    border-color: #ef4444;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.chat-form-error {
    font-size: 0.78rem;
    color: #ef4444;
    min-height: 16px;
    display: block;
}

.chat-form-submit {
    margin-top: 4px;
    padding: 12px;
    font-size: 0.9rem;
}

.chat-form-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --- Chat Input Area --- */
.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    background: #fff;
    flex-shrink: 0;
}

.chat-input-form {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 11px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 24px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #f8fafc;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.chat-input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
    background: #fff;
}

.chat-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.35);
}

.chat-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: #cbd5e1;
}

/* --- Streaming message cursor --- */
.chat-msg-content.streaming::after {
    content: '\258C';
    animation: cursorBlink 0.8s infinite;
    margin-left: 2px;
    opacity: 0.7;
}

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

/* --- Success/Error states --- */
.chat-toast {
    position: absolute;
    top: 60px;
    left: 50%;
    transform: translateX(-50%);
    padding: 10px 20px;
    border-radius: 10px;
    font-size: 0.85rem;
    font-weight: 500;
    z-index: 20;
    animation: toastIn 0.3s ease;
    white-space: nowrap;
}

.chat-toast.success {
    background: #dcfce7;
    color: #166534;
}

.chat-toast.error {
    background: #fee2e2;
    color: #991b1b;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== MOBILE RESPONSIVE ===== */
@media (max-width: 480px) {
    .chat-widget {
        bottom: 12px;
        right: 12px;
    }

    .chat-toggle-btn {
        width: 50px;
        height: 50px;
        font-size: 1.2rem;
    }

    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        bottom: auto;
        right: auto;
        animation: chatSlideUpMobile 0.25s ease;
    }

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

    .chat-messages {
        padding: 14px;
    }

    .chat-lead-form {
        bottom: 56px;
        max-height: 60vh;
    }
}

/* ===== TABLET ===== */
@media (min-width: 481px) and (max-width: 768px) {
    .chat-window {
        width: 360px;
        height: 460px;
    }
}
