/* UNIVERSAL RESET */
* {
    box-sizing: border-box; /* Quan trọng để padding/border không làm tăng kích thước */
    margin: 0;
    padding: 0;
}

/* General styles for desktop/large screens */
html, body {
    font-family: Arial, sans-serif;
    background-color: #F5DEB3; /* Nền trang màu nâu nhạt */
    width: 100vw;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; /* Ngăn cuộn trang tổng thể trên desktop */
}

/* Chat container styling for desktop/large screens */
.chat-container {
    width: 95%;
    height: 95%;
    max-width: 800px;
    max-height: 900px;
    background: white;
    border-radius: 8px;
    /* VIỀN XANH LÁ VÀ BÓNG ĐỔ */
    box-shadow: 0 0 0 3px #4CAF50, 
                0 4px 15px rgba(0, 0, 0, 0.15);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Chatbot header styling */
h1 {
    background: #4CAF50; /* Màu nền header xanh lá */
    color: white;
    padding: 15px;
    text-align: center;
    margin: 0;
    font-size: 1.8em;
    border-bottom: 1px solid #388E3C;
    flex-shrink: 0;
}

/* Chat window styling */
.chat-window {
    padding: 15px;
    flex-grow: 1; /* Cho phép nó mở rộng hết không gian còn lại */
    overflow-y: auto; /* THANH CUỘN CHỈ XUẤT HIỆN BÊN TRONG KHU VỰC TIN NHẮN */
    border-bottom: 1px solid #E8F5E9; /* Viền dưới màu xanh lá nhạt */
    display: flex;
    flex-direction: column;
    min-height: 0; /* Quan trọng cho flexbox để nó co lại đúng cách nếu cần */
}

/* Message bubble styling */
.chat-message {
    padding: 12px 18px;
    margin: 8px 0;
    border-radius: 20px;
    max-width: 80%;
    word-wrap: break-word;
    display: inline-block;
    line-height: 1.4;
}

/* Bot message styling */
.bot-message {
    background: #A5D6A7; /* Màu nền tin nhắn bot xanh lá nhạt */
    color: #333;
    align-self: flex-start;
    border-radius: 20px 20px 20px 5px;
}

/* User message styling */
.user-message {
    background: #4CAF50; /* Màu nền tin nhắn người dùng xanh lá đậm */
    color: white;
    align-self: flex-end;
    border-radius: 20px 20px 5px 20px;
}

/* Input area styling */
.chat-input {
    display: flex;
    border-top: 1px solid #E8F5E9; /* Viền trên màu xanh lá nhạt */
    padding: 10px;
    align-items: center;
    background-color: white;
    flex-shrink: 0;
}

/* Input field styling */
.chat-input input {
    flex-grow: 1;
    padding: 12px 15px;
    border: 1px solid #A5D6A7; /* Viền ô input màu xanh lá nhạt */
    border-radius: 25px;
    outline: none;
    background: #f9f9f9;
    margin-right: 10px;
    font-size: 1em;
    transition: border-color 0.3s ease;
}

.chat-input input:focus {
    border-color: #4CAF50; /* Viền sáng hơn khi focus */
}

/* Placeholder text styling */
.chat-input input::placeholder {
    color: #999;
}

/* Unified button styling for mic, speaker, and send */
.chat-input button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 10px;
    color: #4CAF50; /* Màu nút xanh lá */
    font-size: 1.4em;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s ease, transform 0.2s ease;
}

.chat-input button:hover {
    color: #388E3C;
    transform: translateY(-2px);
}

.chat-input button:focus {
    outline: none;
}

/* Specific styling for mic button */
.chat-input button#mic-button {
    margin-right: 5px;
}

/* Specific styling for speaker button */
.chat-input button#speaker-button {
    margin-right: 5px;
}

/* Style for when recording is active (mic button) */
.chat-input button#mic-button.recording {
    color: #B22222; /* Màu đỏ khi đang ghi âm */
    animation: pulse-mic 1s infinite alternate;
}

@keyframes pulse-mic {
    from {
        transform: scale(1);
        opacity: 1;
    }
    to {
        transform: scale(1.1);
        opacity: 0.7;
    }
}

/* Style for when speaking is active (speaker button) */
#speaker-button.speaking {
    color: #388E3C;
    animation: pulse-speaker 1s infinite alternate;
}

@keyframes pulse-speaker {
    from {
        transform: scale(1);
        opacity: 1;
    }
    to {
        transform: scale(1.1);
        opacity: 0.7;
    }
}

/* Optional: Add a subtle pulse for the message being spoken */
.bot-message.speaking-active {
    box-shadow: 0 0 8px rgba(76, 175, 80, 0.6);
    animation: none;
}

/* --- Media Queries for Mobile and Tablet Devices --- */
/* Áp dụng cho màn hình có chiều rộng tối đa 768px (điện thoại và tablet nhỏ) */
@media (max-width: 768px) {
    html, body {
        height: 100vh;
        min-height: 100vh;
        width: 100vw;
        overflow: hidden;
        display: block;
    }

    .chat-container {
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        width: 95vw;
        height: 75vh;
        max-width: none;
        max-height: none;
        border-radius: 8px;
        box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
        background: white;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

    h1 {
        padding: 12px;
        font-size: 1.4em;
        flex-shrink: 0;
    }

    .chat-window {
        padding: 8px;
        flex-grow: 1;
        overflow-y: auto;
        min-height: 0;
    }

    .chat-message {
        padding: 10px 14px;
        margin: 5px 0;
        max-width: 90%;
        font-size: 0.95em;
    }

    .chat-input {
        padding: 6px;
        flex-shrink: 0;
    }

    .chat-input input {
        padding: 10px 12px;
        font-size: 0.9em;
        margin-right: 5px;
    }

    .chat-input button {
        padding: 5px;
        font-size: 1em;
    }
}

/* Áp dụng cho màn hình có chiều rộng tối đa 480px (điện thoại cỡ nhỏ) */
@media (max-width: 480px) {
    h1 {
        font-size: 1.2em;
    }

    .chat-message {
        padding: 8px 12px;
        font-size: 0.9em;
    }

    .chat-input input {
        padding: 8px 10px;
        font-size: 0.85em;
    }

    .chat-input button {
        padding: 5px;
        font-size: 1em;
    }
}