/**
 * DAVINCI Smart CTA — Chat Widget Stylesheet
 *
 * Inline chat widget for professional tax advisory websites.
 * Uses CSS custom properties set via JS from davinciCTA config.
 *
 * @version 2.0.0
 */

/* =========================================================================
   BASE / CONTAINER
   ========================================================================= */

.dv-chat {
    --dv-chat-primary: #1e3a5f;
    --dv-chat-accent: #2877A6;
    --dv-chat-bg: #f4f5f7;
    --dv-chat-white: #ffffff;
    --dv-chat-text: #333333;
    --dv-chat-text-muted: #8a929a;
    --dv-chat-border: #e0e4e8;
    --dv-chat-agent-bubble: #eceef1;
    --dv-chat-radius: 12px;
    --dv-chat-success: #22c55e;

    position: relative;
    margin: 32px 0;
    border-radius: var(--dv-chat-radius);
    background: var(--dv-chat-bg);
    border: 1px solid var(--dv-chat-border);
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--dv-chat-text);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06), 0 8px 24px rgba(0, 0, 0, 0.04);
    max-width: 100%;

    /* Initial hidden state */
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.dv-chat--visible {
    opacity: 1;
    transform: translateY(0);
}

.dv-chat--dismissing {
    opacity: 0;
    transform: translateY(-12px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.dv-chat--dismissed {
    display: none;
}

.dv-chat--minimal {
    opacity: 0.4;
    transform: scale(0.98);
    transition: opacity 1.5s ease, transform 1.5s ease;
    pointer-events: none;
}

/* =========================================================================
   HEADER
   ========================================================================= */

.dv-chat__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 18px;
    background: var(--dv-chat-primary);
    color: var(--dv-chat-white);
}

.dv-chat__avatar {
    position: relative;
    width: 40px;
    height: 40px;
    flex-shrink: 0;
}

.dv-chat__avatar img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.dv-chat__avatar-fallback {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--dv-chat-accent);
    color: var(--dv-chat-white);
    font-size: 18px;
    font-weight: 700;
}

.dv-chat__status-dot {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--dv-chat-success);
    border: 2px solid var(--dv-chat-primary);
    animation: dvChatPulse 2s ease-in-out infinite;
}

@keyframes dvChatPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5); }
    50%      { box-shadow: 0 0 0 4px rgba(34, 197, 94, 0); }
}

.dv-chat__agent-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

.dv-chat__agent-name {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.dv-chat__agent-status {
    font-size: 12px;
    opacity: 0.8;
    line-height: 1.3;
}

.dv-chat__close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: var(--dv-chat-white);
    border-radius: 50%;
    cursor: pointer;
    font-size: 20px;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
    transition: background 0.2s;
}

.dv-chat__close:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* =========================================================================
   MESSAGES AREA
   ========================================================================= */

.dv-chat__messages {
    padding: 18px 18px 8px;
    max-height: 360px;
    min-height: 80px;
    overflow-y: auto;
    background: var(--dv-chat-white);
    scroll-behavior: smooth;
}

/* Thin scrollbar */
.dv-chat__messages::-webkit-scrollbar {
    width: 5px;
}
.dv-chat__messages::-webkit-scrollbar-track {
    background: transparent;
}
.dv-chat__messages::-webkit-scrollbar-thumb {
    background: var(--dv-chat-border);
    border-radius: 3px;
}

/* =========================================================================
   MESSAGE BUBBLES
   ========================================================================= */

.dv-chat__msg {
    display: flex;
    flex-direction: column;
    margin-bottom: 14px;
    animation: dvChatMsgIn 0.3s ease forwards;
}

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

/* Agent messages — left aligned */
.dv-chat__msg--agent {
    align-items: flex-start;
}

.dv-chat__msg--agent .dv-chat__bubble {
    background: var(--dv-chat-agent-bubble);
    color: var(--dv-chat-text);
    border-radius: 2px 14px 14px 14px;
    max-width: 85%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

/* User messages — right aligned */
.dv-chat__msg--user {
    align-items: flex-end;
}

.dv-chat__msg--user .dv-chat__bubble {
    background: var(--dv-chat-primary);
    color: var(--dv-chat-white);
    border-radius: 14px 14px 2px 14px;
    max-width: 85%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

/* Timestamp */
.dv-chat__time {
    font-size: 11px;
    color: var(--dv-chat-text-muted);
    margin-top: 4px;
    padding-left: 4px;
}

/* =========================================================================
   TYPING INDICATOR
   ========================================================================= */

.dv-chat__typing .dv-chat__bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 18px;
    min-height: 20px;
}

.dv-chat__dot {
    display: inline-block;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--dv-chat-text-muted);
    animation: dvChatBounce 1.4s ease-in-out infinite;
}

.dv-chat__dot:nth-child(2) {
    animation-delay: 0.2s;
}

.dv-chat__dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes dvChatBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* =========================================================================
   INPUT AREA
   ========================================================================= */

.dv-chat__input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: var(--dv-chat-white);
    border-top: 1px solid var(--dv-chat-border);
}

.dv-chat__input {
    flex: 1;
    padding: 10px 14px;
    border: 1.5px solid var(--dv-chat-border);
    border-radius: 24px;
    font-size: 14px;
    color: var(--dv-chat-text);
    background: var(--dv-chat-bg);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: inherit;
    min-width: 0;
}

.dv-chat__input:focus {
    border-color: var(--dv-chat-accent);
    box-shadow: 0 0 0 3px rgba(40, 119, 166, 0.1);
    background: var(--dv-chat-white);
}

.dv-chat__input::placeholder {
    color: #adb5bd;
}

.dv-chat__input--error {
    border-color: #dc3545;
    animation: dvChatShake 0.4s ease;
}

@keyframes dvChatShake {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-4px); }
    75%      { transform: translateX(4px); }
}

.dv-chat__send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--dv-chat-accent);
    color: var(--dv-chat-white);
    cursor: pointer;
    font-size: 18px;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
    padding: 0;
}

.dv-chat__send:hover {
    background: var(--dv-chat-primary);
    transform: scale(1.05);
}

.dv-chat__send:active {
    transform: scale(0.95);
}

/* =========================================================================
   RESPONSIVE
   ========================================================================= */

@media (max-width: 480px) {
    .dv-chat {
        margin: 20px 0;
        border-radius: 8px;
    }

    .dv-chat__header {
        padding: 12px 14px;
        gap: 10px;
    }

    .dv-chat__avatar,
    .dv-chat__avatar img,
    .dv-chat__avatar-fallback {
        width: 34px;
        height: 34px;
    }

    .dv-chat__avatar-fallback {
        font-size: 15px;
    }

    .dv-chat__agent-name {
        font-size: 14px;
    }

    .dv-chat__messages {
        padding: 14px 12px 6px;
        max-height: 300px;
    }

    .dv-chat__msg--agent .dv-chat__bubble,
    .dv-chat__msg--user .dv-chat__bubble {
        max-width: 90%;
        font-size: 13px;
        padding: 9px 12px;
    }

    .dv-chat__input-area {
        padding: 10px 10px;
        gap: 6px;
    }

    .dv-chat__input {
        padding: 9px 12px;
        font-size: 14px;
    }

    .dv-chat__send {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
}

@media (max-width: 360px) {
    .dv-chat__msg--agent .dv-chat__bubble,
    .dv-chat__msg--user .dv-chat__bubble {
        max-width: 95%;
    }
}
