/* --- Biến CSS để dễ dàng tùy chỉnh --- */
:root {
    --primary-color: #007AFF;
    --primary-gradient: linear-gradient(135deg, #007BFF, #0056b3);
    --secondary-color: #F1F3F6;
    --text-dark: #333;
    --text-light: #fff;
    --border-color: #E5E7EB;
    --font-family: 'Be Vietnam Pro', sans-serif;
    --border-radius: 16px;
    --chatbox-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-family);
    background-color: rgba(0,0,0,0.0);
 /* Màu nền nhẹ cho trang */
}

/* --- Nút Bật/Tắt Chat --- */
#chat-toggle {
    position: fixed;
    bottom: 25px;
    right: 25px;
    width: 60px;
    height: 60px;
    background: var(--primary-gradient);
    color: var(--text-light);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.4);
    z-index: 1000;
    transition: transform 0.3s ease, background 0.3s ease;
}

#chat-toggle:hover {
    transform: scale(1.1);
}

#chat-toggle svg {
    width: 32px;
    height: 32px;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

#chat-icon-close {
    opacity: 0;
    transform: scale(0.5);
    position: absolute;
}

#chat-toggle.active #chat-icon-open {
    opacity: 0;
    transform: scale(0.5);
}

#chat-toggle.active #chat-icon-close {
    opacity: 1;
    transform: scale(1);
}

/* --- Khung Chat --- */
#chatbox {
    position: fixed;
    bottom: 100px;
    right: 25px;
    width: 370px;
    height: 600px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    background: var(--text-light);
    border-radius: var(--border-radius);
    box-shadow: var(--chatbox-shadow);
    z-index: 999;
    overflow: hidden;
    /* Hiệu ứng ẩn/hiện */
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#chatbox.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* --- Header --- */
#chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--primary-gradient);
    color: var(--text-light);
    flex-shrink: 0;
}

#chat-header img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.header-text strong {
    font-size: 16px;
    font-weight: 700;
    display: block;
}

.header-text span {
    font-size: 13px;
    opacity: 0.8;
}

/* --- Khu vực tin nhắn --- */
#messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: #F9FAFB;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.message {
    padding: 12px 18px;
    border-radius: var(--border-radius);
    max-width: 85%;
    word-wrap: break-word;
    font-size: 15px;
    line-height: 1.5;
    animation: fadeIn 0.4s ease-in-out;
}

.user {
    background-color: var(--secondary-color);
    color: var(--text-dark);
    align-self: flex-end;
    border-bottom-right-radius: 4px; /* Tạo hình dáng tin nhắn */
}

.bot {
    background: var(--primary-gradient);
    color: var(--text-light);
    align-self: flex-start;
    border-bottom-left-radius: 4px; /* Tạo hình dáng tin nhắn */
}

/* Hiệu ứng đang gõ mới */
.typing span {
    display: inline-block;
    width: 8px;
    height: 8px;
    background-color: rgba(255, 255, 255, 0.7);
    border-radius: 50%;
    margin: 0 2px;
    animation: bounce 1.4s infinite ease-in-out both;
}
.typing span:nth-child(1) { animation-delay: -0.32s; }
.typing span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- Khu vực nhập liệu --- */
#input-area {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--text-light);
    gap: 10px;
}

#input {
    flex: 1;
    padding: 12px 18px;
    font-size: 15px;
    border-radius: 25px;
    border: 1px solid var(--border-color);
    background-color: var(--secondary-color);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    font-family: var(--font-family);
}

#input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.15);
}

#send {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 46px;
    height: 46px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s, transform 0.2s;
}

#send:hover {
    background-color: #0056b3;
    transform: scale(1.05);
}

#send svg {
    width: 22px;
    height: 22px;
    margin-left: 2px; /* Căn chỉnh icon máy bay giấy */
}

code {
    background: rgba(255, 255, 255, 0.2);
    padding: 3px 6px;
    border-radius: 6px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.9em;
}
.user code {
    background-color: rgba(0,0,0,0.08);
}