/* ========================================
   Elements Chat Widget - Ana Silva
   ======================================== */

/* FAB Button */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: #5223DE;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(82, 35, 222, 0.35);
    z-index: 1000;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.chat-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px rgba(82, 35, 222, 0.45);
}

.chat-fab svg {
    width: 28px;
    height: 28px;
    fill: #fff;
}

/* Badge notification */
.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #F26F21;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    font-family: 'Nunito Sans', sans-serif;
}

.chat-fab-badge.visible {
    display: flex;
}

/* FAB pulse animation */
@keyframes chatPulse {
    0% { box-shadow: 0 4px 16px rgba(82, 35, 222, 0.35); }
    50% { box-shadow: 0 4px 24px rgba(82, 35, 222, 0.55); }
    100% { box-shadow: 0 4px 16px rgba(82, 35, 222, 0.35); }
}

.chat-fab.pulse {
    animation: chatPulse 1.5s ease infinite;
}

/* Adjust FAB when sticky product bar is visible */
.prod-sticky.visible ~ #chatWidget .chat-fab {
    bottom: 104px;
}

/* ========================================
   Chat Window
   ======================================== */

.chat-window {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 380px;
    height: 520px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 1001;
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Adjust chat window when sticky product bar is visible */
.prod-sticky.visible ~ #chatWidget .chat-window {
    bottom: 172px;
}

/* ========================================
   Chat Header
   ======================================== */

.chat-header {
    background: #5223DE;
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.3);
    flex-shrink: 0;
}

.chat-avatar-initials {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    flex-shrink: 0;
    font-family: 'Nunito Sans', sans-serif;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-name {
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    font-family: 'Nunito Sans', sans-serif;
    line-height: 1.2;
}

.chat-header-status {
    color: rgba(255, 255, 255, 0.8);
    font-size: 12px;
    font-family: 'Nunito Sans', sans-serif;
    display: flex;
    align-items: center;
    gap: 5px;
}

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

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

.chat-header-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

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

.chat-header-btn svg {
    width: 16px;
    height: 16px;
    stroke: #fff;
    fill: none;
}

/* ========================================
   Chat Messages
   ======================================== */

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: #fff;
}

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

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

.chat-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 2px;
}

/* Message row */
.chat-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: chatMsgIn 0.25s ease;
}

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

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

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

.chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.45;
    font-family: 'Nunito Sans', sans-serif;
    word-break: break-word;
}

.chat-msg.assistant .chat-msg-bubble {
    background: #F5F5F5;
    color: #1A1A1A;
    border-bottom-left-radius: 4px;
}

.chat-msg.user .chat-msg-bubble {
    background: #5223DE;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-msg-time {
    font-size: 10px;
    color: #999;
    margin-top: 4px;
    font-family: 'Nunito Sans', sans-serif;
}

.chat-msg.user .chat-msg-time {
    text-align: right;
}

/* ========================================
   Quick Replies
   ======================================== */

.chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 0 16px 12px;
}

.chat-quick-btn {
    padding: 8px 14px;
    border: 1.5px solid #5223DE;
    border-radius: 20px;
    background: #fff;
    color: #5223DE;
    font-size: 13px;
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.chat-quick-btn:hover {
    background: #5223DE;
    color: #fff;
}

/* ========================================
   Typing Indicator
   ======================================== */

.chat-typing {
    display: none;
    align-self: flex-start;
    gap: 8px;
    max-width: 85%;
    padding: 0 16px 4px;
}

.chat-typing.visible {
    display: flex;
}

.chat-typing-bubble {
    background: #F5F5F5;
    padding: 12px 18px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.chat-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #999;
    animation: chatTypingBounce 1.2s ease infinite;
}

.chat-typing-dot:nth-child(2) {
    animation-delay: 0.15s;
}

.chat-typing-dot:nth-child(3) {
    animation-delay: 0.3s;
}

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

.chat-typing-text {
    font-size: 12px;
    color: #999;
    font-family: 'Nunito Sans', sans-serif;
    margin-left: 4px;
}

/* ========================================
   Chat Input
   ======================================== */

.chat-input-area {
    padding: 12px 16px;
    border-top: 1px solid #ECECEC;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: #fff;
}

.chat-input {
    flex: 1;
    border: 1.5px solid #E5E5E5;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: 'Nunito Sans', sans-serif;
    outline: none;
    resize: none;
    max-height: 80px;
    line-height: 1.4;
    transition: border-color 0.15s;
}

.chat-input:focus {
    border-color: #5223DE;
}

.chat-input::placeholder {
    color: #aaa;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: #5223DE;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s, opacity 0.15s;
}

.chat-send-btn:hover {
    background: #4119B5;
}

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

.chat-send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
}

/* ========================================
   Mobile Fullscreen
   ======================================== */

@media (max-width: 767px) {
    .chat-fab {
        bottom: 16px;
        right: 16px;
    }

    .prod-sticky.visible ~ #chatWidget .chat-fab {
        bottom: 96px;
    }

    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
        transform: translateY(100%);
        opacity: 1;
    }

    .chat-window.open {
        transform: translateY(0);
    }

    .prod-sticky.visible ~ #chatWidget .chat-window {
        bottom: 0;
    }

    .chat-header {
        padding: 16px;
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .chat-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* Desktop adjustments */
@media (min-width: 768px) {
    .chat-fab {
        bottom: 32px;
        right: 32px;
    }

    .chat-window {
        bottom: 100px;
        right: 32px;
    }

    .prod-sticky.visible ~ #chatWidget .chat-window {
        bottom: 180px;
    }
}
