/* === Chat Widget === */

.chat-widget {
    --chat-green: #047857;
    --chat-green-deep: #065f46;
    --chat-green-glow: rgba(4, 120, 87, 0.12);
    --chat-ink: #0c1220;
    --chat-charcoal: #1a2335;
    --chat-warm: #faf8f5;
    --chat-mist: #8b95a7;
    --chat-cloud: #e2e8f0;
}

/* Trigger button */
.chat-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 88;
    width: 56px;
    height: 56px;
    border-radius: var(--radius-full);
    border: none;
    background: linear-gradient(135deg, var(--chat-green), var(--chat-green-deep));
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(4, 120, 87, 0.3);
    transition: all var(--ease-short);
}
.chat-trigger:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(4, 120, 87, 0.4);
}
.chat-trigger-close {
    display: none;
}
.chat-trigger.open .chat-trigger-icon {
    display: none;
}
.chat-trigger.open .chat-trigger-close {
    display: block;
}

/* Pulse animation for nudge */
.chat-trigger.pulse {
    animation: chatTriggerPulse 2s ease-in-out infinite;
}
@keyframes chatTriggerPulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(4, 120, 87, 0.3); }
    50% { box-shadow: 0 4px 20px rgba(4, 120, 87, 0.3), 0 0 0 8px rgba(4, 120, 87, 0.15); }
}

/* Nudge tooltip */
.chat-nudge {
    position: fixed;
    bottom: 88px;
    right: 24px;
    z-index: 88;
    background: white;
    color: var(--chat-ink);
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-lg);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    display: none;
    align-items: center;
    gap: var(--space-xs);
    max-width: 260px;
    animation: chatNudgeIn 0.3s ease;
}
.chat-nudge.visible {
    display: flex;
}
.chat-nudge::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: 22px;
    width: 12px;
    height: 12px;
    background: white;
    transform: rotate(45deg);
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.05);
}
.chat-nudge-close {
    background: none;
    border: none;
    color: var(--chat-mist);
    font-size: 18px;
    cursor: pointer;
    padding: 0 0 0 4px;
    line-height: 1;
    flex-shrink: 0;
    transition: color var(--ease-short);
}
.chat-nudge-close:hover { color: var(--chat-ink); }
@keyframes chatNudgeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Chat panel */
.chat-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    z-index: 89;
    width: 380px;
    max-height: 560px;
    background: white;
    border-radius: var(--radius-xl);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0,0,0,0.04);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--font-body);
}
.chat-panel.open {
    display: flex;
    animation: chatPanelIn 0.2s ease;
}
@keyframes chatPanelIn {
    from { opacity: 0; transform: scale(0.95) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Header */
.chat-header {
    background: linear-gradient(135deg, var(--chat-charcoal), var(--chat-ink));
    color: white;
    padding: var(--space-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    flex-shrink: 0;
}
.chat-header-info {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}
.chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-full);
    overflow: hidden;
    flex-shrink: 0;
}
.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}
.chat-header-title {
    font-weight: 600;
    font-size: var(--text-ui);
}
.chat-header-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.5);
    display: flex;
    align-items: center;
    gap: 5px;
}
.chat-status-dot {
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: #22c55e;
    display: inline-block;
}
.chat-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}
.chat-new-convo,
.chat-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: all var(--ease-short);
    font-size: 22px;
    line-height: 1;
}
.chat-new-convo {
    font-size: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
}
.chat-new-convo:hover,
.chat-close:hover {
    color: white;
    background: rgba(255, 255, 255, 0.1);
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    background: var(--chat-warm);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    min-height: 200px;
    max-height: 360px;
}

/* Message bubbles */
.chat-msg {
    max-width: 85%;
    padding: var(--space-xs) var(--space-sm);
    font-size: var(--text-sm);
    line-height: 1.5;
    animation: chatMsgIn 0.15s ease;
    word-wrap: break-word;
}
.chat-msg.user {
    align-self: flex-end;
    background: var(--chat-green);
    color: white;
    border-radius: 16px 16px 4px 16px;
}
.chat-msg.assistant {
    align-self: flex-start;
    background: white;
    color: var(--chat-ink);
    border-radius: 16px 16px 16px 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
@keyframes chatMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Typing indicator */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
    background: white;
    border-radius: 16px 16px 16px 4px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}
.chat-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--chat-mist);
    animation: chatTypingBounce 0.6s ease-in-out infinite;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatTypingBounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* Input area */
.chat-input-area {
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--chat-cloud);
    display: flex;
    align-items: flex-end;
    gap: var(--space-xs);
    background: white;
}
.chat-input {
    flex: 1;
    border: 1px solid var(--chat-cloud);
    border-radius: var(--radius-md);
    padding: var(--space-xs) var(--space-sm);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--chat-ink);
    resize: none;
    min-height: 40px;
    max-height: 100px;
    line-height: 1.4;
    outline: none;
    transition: border-color var(--ease-short);
    background: var(--chat-warm);
}
.chat-input::placeholder {
    color: var(--chat-mist);
}
.chat-input:focus {
    border-color: var(--chat-green);
    box-shadow: 0 0 0 3px var(--chat-green-glow);
}
.chat-send {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-full);
    border: none;
    background: var(--chat-green);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--ease-short);
    flex-shrink: 0;
}
.chat-send:hover:not(:disabled) {
    background: var(--chat-green-deep);
}
.chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Inline lead capture card */
.chat-lead-card {
    background: var(--chat-warm);
    border: 1px solid var(--chat-cloud);
    border-radius: var(--radius-lg);
    padding: var(--space-sm);
    margin-top: 4px;
}
.chat-lead-card p {
    font-size: var(--text-fine);
    color: var(--chat-mist);
    margin-bottom: var(--space-xs);
}
.chat-lead-card input {
    display: block;
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--chat-cloud);
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    color: var(--chat-ink);
    margin-bottom: var(--space-xs);
    background: white;
    transition: border-color var(--ease-short);
}
.chat-lead-card input::placeholder {
    color: var(--chat-mist);
}
.chat-lead-card input:focus {
    outline: none;
    border-color: var(--chat-green);
    box-shadow: 0 0 0 3px var(--chat-green-glow);
}
.chat-lead-card .field-error {
    color: #dc2626;
    font-size: 12px;
    margin: -4px 0 8px;
}
.chat-lead-submit {
    width: 100%;
    padding: var(--space-xs);
    background: linear-gradient(135deg, var(--chat-green), var(--chat-green-deep));
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: var(--text-sm);
    font-weight: 600;
    cursor: pointer;
    transition: all var(--ease-short);
}
.chat-lead-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(4, 120, 87, 0.2);
}
.chat-lead-submit:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Fallback message with CTA */
.chat-fallback-btn {
    display: inline-block;
    margin-top: var(--space-xs);
    padding: var(--space-xs) var(--space-md);
    background: var(--chat-green);
    color: white;
    border: none;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: var(--text-fine);
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: background var(--ease-short);
}
.chat-fallback-btn:hover {
    background: var(--chat-green-deep);
}

/* === Mobile === */
@media (max-width: 640px) {
    .chat-trigger {
        bottom: 80px;
        right: 20px;
    }

    .chat-nudge {
        bottom: 144px;
        right: 20px;
        max-width: calc(100vw - 80px);
    }

    .chat-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        max-height: 100%;
        border-radius: 0;
        bottom: 0;
        right: 0;
        z-index: 1000;
    }
    .chat-panel.open {
        animation: chatPanelMobileIn 0.3s ease;
    }
    @keyframes chatPanelMobileIn {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    .chat-header {
        border-radius: 0;
    }

    .chat-messages {
        max-height: none;
        flex: 1;
    }

    .chat-trigger.open {
        display: none;
    }
}

/* Hide chat trigger when sidebar form is open (mobile) */
@media (max-width: 1200px) {
    .sidebar-form.open ~ .chat-widget .chat-trigger {
        display: none;
    }
}
