/* Widget Wrapper */
#chat-widget {
    position: fixed;
    z-index: 9999;
    bottom: 140px;
    right: 2.6%;
    font-family: 'Outfit', 'Inter', sans-serif;
}

/* Nút mở rộng Chat */
#chat-toggle {
    width: 60px;
    height: 60px;
    background: var(--ltn__secondary-color, #08a635);
    background: linear-gradient(135deg, var(--ltn__secondary-color, #08a635) 0%, color-mix(in srgb, var(--ltn__secondary-color, #08a635) 80%, black) 100%);
    color: white;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(8, 166, 53, 0.35);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
}

#chat-toggle svg {
    transition: transform 0.4s ease;
}

#chat-toggle:hover {
    transform: scale(1.08) rotate(5deg);
    box-shadow: 0 10px 28px rgba(8, 166, 53, 0.45);
}

/* Hiệu ứng Pulse nháy vòng tròn ngoài */
#chat-toggle::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--ltn__secondary-color, #08a635);
    top: 0;
    left: 0;
    opacity: 0.8;
    animation: chat-pulse 2s infinite ease-out;
    pointer-events: none;
}

@keyframes chat-pulse {
    0% {
        transform: scale(1);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.4);
        opacity: 0;
    }
}

/* Khung Chat Chính (Glassmorphism & Symmetrical Design) */
#chat-box {
    position: fixed;
    bottom: 95px;
    right: 25px;
    width: 380px;
    height: 520px;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-radius: 20px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    z-index: 9999;
    border: 1px solid rgba(255, 255, 255, 0.4);
    transition: transform 0.3s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.3s ease;
    transform-origin: bottom right;
}

#chat-box.hidden {
    display: none !important;
    transform: scale(0.85) translateY(30px);
    opacity: 0;
}

/* Header */
#chat-header {
    background: var(--ltn__secondary-color, #08a635);
    background: linear-gradient(135deg, var(--ltn__secondary-color, #08a635) 0%, color-mix(in srgb, var(--ltn__secondary-color, #08a635) 85%, black) 100%);
    color: white;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

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

.chat-avatar-container {
    position: relative;
    width: 40px;
    height: 40px;
}

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

.chat-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #10b981;
    border: 2px solid var(--ltn__secondary-color, #08a635);
    border-radius: 50%;
}

.chat-title-wrapper {
    display: flex;
    flex-direction: column;
}

.chat-title {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.3px;
}

.chat-subtitle {
    font-size: 11px;
    opacity: 0.85;
    margin-top: 1px;
}

#chat-close {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    color: white;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

#chat-close:hover {
    background: rgba(255, 255, 255, 0.3);
    transform: rotate(90deg);
}

/* Khung tin nhắn */
#chat-messages {
    flex: 1;
    padding: 20px;
    background: #f7f9fa;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

/* Custom thanh cuộn */
#chat-messages::-webkit-scrollbar {
    width: 6px;
}

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

#chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.12);
    border-radius: 4px;
}

/* Cấu trúc tin nhắn */
.message-wrapper {
    display: flex;
    gap: 10px;
    max-width: 85%;
    opacity: 0;
    transform: translateY(15px);
    animation: messageIn 0.35s cubic-bezier(0.165, 0.84, 0.44, 1) forwards;
}

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

.message-wrapper.bot {
    align-self: flex-start;
}

.msg-avatar {
    width: 32px;
    height: 32px;
    background: #e6f7ed;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.message-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
}

/* Markdown styling inside bubble */
.message-bubble p {
    margin: 0 0 8px 0;
}
.message-bubble p:last-child {
    margin-bottom: 0;
}
.message-bubble ul, .message-bubble ol {
    margin: 6px 0;
    padding-left: 20px;
}
.message-bubble li {
    margin-bottom: 4px;
}

.message-wrapper.user .message-bubble {
    background: var(--ltn__secondary-color, #08a635);
    color: white;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 10px rgba(8, 166, 53, 0.15);
}

.message-wrapper.bot .message-bubble {
    background: white;
    color: #2D3748;
    border-top-left-radius: 4px;
    border: 1px solid rgba(0, 0, 0, 0.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
}

/* Typing Indicator */
.typing-dots {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 8px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #718096;
    border-radius: 50%;
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.3; }
    40% { transform: scale(1); opacity: 1; }
}

/* Footer (Quick Replies + Input) */
#chat-footer {
    background: white;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
    padding: 12px;
}

/* Gợi ý nhanh - Quick Replies */
#chat-quick-replies {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 10px;
    margin-bottom: 10px;
    scroll-behavior: smooth;
}

#chat-quick-replies::-webkit-scrollbar {
    height: 4px;
}

#chat-quick-replies::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 10px;
}

.quick-reply-btn {
    white-space: nowrap;
    background: #f0fdf4;
    color: var(--ltn__secondary-color, #08a635);
    border: 1px solid color-mix(in srgb, var(--ltn__secondary-color, #08a635) 20%, white);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 11.5px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-reply-btn:hover {
    background: var(--ltn__secondary-color, #08a635);
    color: white;
    border-color: var(--ltn__secondary-color, #08a635);
    transform: translateY(-1px);
}

/* Khung nhập tin nhắn */
#chat-input-container {
    display: flex;
    align-items: center;
    background: #f7f9fa;
    border-radius: 12px;
    padding: 4px 8px;
    border: 1px solid rgba(0, 0, 0, 0.06);
    transition: all 0.2s ease;
}

#chat-input-container:focus-within {
    background: white;
    border-color: var(--ltn__secondary-color, #08a635);
    box-shadow: 0 0 0 3px rgba(8, 166, 53, 0.1);
}

#message-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 8px;
    font-size: 13.5px;
    color: #2d3748;
    outline: none !important;
}

#send-btn {
    width: 36px;
    height: 36px;
    background: var(--ltn__secondary-color, #08a635);
    color: white;
    border: none;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

#send-btn:hover {
    background: color-mix(in srgb, var(--ltn__secondary-color, #08a635) 85%, black);
    transform: scale(1.05);
}

#send-btn:disabled {
    background: #cbd5e0;
    cursor: not-allowed;
    transform: none;
}

/* Animations */
@keyframes messageIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Responsive */
@media (max-width: 480px) {
    #chat-box {
        width: calc(100% - 30px);
        height: 480px;
        right: 15px;
        bottom: 85px;
    }
    #chat-widget {
        right: 15px;
    }
}
