/* style.css */
@import url('https://fonts.googleapis.com/css2?family=Roboto:wght@400;500;700&display=swap');

/* === Color Variables === */
:root {
    --primary-color: #006A6A; /* Teal from JINYU logo */
    --secondary-color: #FFC107; /* Yellow from elephant, adjusted for better UI use */
    --toggle-on-color: #2196F3; /* Blue for toggle switch when ON */
    --toggle-off-color: #ccc; /* Gray for toggle switch when OFF */
    --text-color-dark: #212529;
    --text-color-light: #ffffff;
    --background-light: #f8f9fa;
    --background-elements: #ffffff;
    --border-color: #dee2e6;
    --message-bot-bg: #e9ecef;
    --shadow-color: rgba(0, 0, 0, 0.1);
}

/* === Base Styles === */
body {
    font-family: 'Roboto', Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: var(--background-light);
    color: var(--text-color-dark);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    font-size: 16px; /* Base font size */
}

/* === Chat Container === */
.chat-container {
    width: 95%;
    max-width: 700px; /* Max width for desktop */
    background-color: var(--background-elements);
    border-radius: 12px;
    box-shadow: 0 5px 20px var(--shadow-color);
    display: flex;
    flex-direction: column;
    height: 90vh; /* Responsive height */
    max-height: 800px; /* Max height */
    overflow: hidden; /* Prevents content from spilling out before border-radius applies */
}

/* === Chat Header === */
.chat-header {
    background-color: var(--primary-color);
    color: var(--text-color-light);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between; /* For logo and clear button */
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}

.header-content {
    display: flex;
    align-items: center;
    flex-grow: 1;
}

.logo {
    height: 40px; /* Adjust as needed */
    width: auto;
    margin-right: 15px;
    border-radius: 4px; /* Optional: if logo has sharp edges */
}

.chat-header h1 {
    font-size: 1.4em;
    margin: 0;
    font-weight: 500;
}

.clear-chat-btn {
    color: var(--text-color-light);
    text-decoration: none;
    font-size: 0.9em;
    padding: 5px 10px;
    border-radius: 5px;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
}

.clear-chat-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.clear-chat-btn svg {
    margin-right: 5px; /* Space between icon and text */
}

/* === Mode Toggle Switch (in Header) === */
.mode-toggle {
    display: flex;
    align-items: center;
    margin-right: 15px;
    font-size: 0.9em;
}

.mode-label {
    margin-right: 8px;
    color: var(--text-color-light);
    font-size: 0.9em;
    font-weight: 500;
}

/* === Chat Box === */
.chat-box {
    flex-grow: 1;
    padding: 20px;
    overflow-y: auto;
    background-color: var(--background-light); /* Slightly different from body for depth */
    scrollbar-width: thin; /* Firefox */
    scrollbar-color: var(--primary-color) var(--background-elements); /* Firefox */
}

/* Webkit (Chrome, Safari, Edge) scrollbar styling */
.chat-box::-webkit-scrollbar {
    width: 8px;
}
.chat-box::-webkit-scrollbar-track {
    background: var(--background-elements);
    border-radius: 4px;
}
.chat-box::-webkit-scrollbar-thumb {
    background-color: var(--primary-color);
    border-radius: 4px;
    border: 2px solid var(--background-elements);
}

/* === Messages === */
.message {
    margin-bottom: 15px;
    padding: 12px 18px;
    border-radius: 20px; /* More rounded messages */
    line-height: 1.5;
    max-width: 85%; /* Slightly wider messages allowed */
    word-wrap: break-word;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    position: relative; /* For potential future pseudo-elements like tails */
}

.user-message {
    background-color: var(--primary-color);
    color: var(--text-color-light);
    margin-left: auto;
    border-bottom-right-radius: 5px; /* Tail effect */
}

.bot-message {
    background-color: var(--message-bot-bg);
    color: var(--text-color-dark);
    margin-right: auto;
    border-bottom-left-radius: 5px; /* Tail effect */
    white-space: pre-wrap;
}

/* === Input Area === */
.input-area {
    display: flex;
    align-items: flex-end; /* Align items to bottom for multi-line textarea */
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    background-color: var(--background-elements);
    flex-wrap: nowrap; /* Đảm bảo các phần tử nằm trên cùng một dòng */
}

.input-area textarea {
    flex-grow: 1;
    padding: 12px 15px;
    border: 1px solid var(--border-color);
    border-radius: 25px; /* Pill shape */
    resize: none;
    margin-right: 10px;
    font-size: 1em;
    line-height: 1.4;
    min-height: 24px; /* Based on line-height and padding */
    max-height: 120px;
    overflow-y: auto;
    background-color: var(--background-light);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input-area textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(0, 106, 106, 0.25);
}

.input-area button {
    padding: 12px;
    background-color: var(--primary-color);
    color: var(--text-color-light);
    border: none;
    border-radius: 50%; /* Circular button */
    cursor: pointer;
    font-size: 1.2em; /* Icon size */
    width: 48px; /* Fixed width */
    height: 48px; /* Fixed height */
    display: flex;
    justify-content: center;
    align-items: center;
    transition: background-color 0.2s ease;
}

.input-area button:hover {
    background-color: #005050; /* Darker shade of primary */
}

.input-area button:disabled {
    background-color: #a0a0a0;
    cursor: not-allowed;
}

/* === Toggle Switch Styles === */
.switch {
    position: relative;
    display: inline-block;
    width: 60px;
    height: 34px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--toggle-off-color);
    transition: background-color 0.4s ease-in-out;
    border-radius: 34px;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.slider:before {
    position: absolute;
    content: "";
    height: 26px;
    width: 26px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55), background-color 0.4s ease-in-out;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.15);
}

input:checked + .slider {
    background-color: var(--toggle-on-color);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

input:focus + .slider {
    box-shadow: 0 0 3px 2px rgba(33, 150, 243, 0.3); /* Glow effect when focused */
    outline: none;
}

input:checked + .slider:before {
    transform: translateX(26px);
    background-color: #e3f2fd; /* Light blue shade for thumb when ON */
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.slider:hover {
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.3);
}

/* === Loading Indicator === */
.loading-indicator {
    text-align: center;
    padding: 10px 0;
    color: #777;
    font-style: italic;
    font-size: 0.9em;
    background-color: var(--background-elements); /* Match input area bg */
    display: flex;
    justify-content: center;
    align-items: center;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    border-top: 4px solid var(--primary-color);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    margin-right: 5px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* === Modal Styles === */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 1; /* Sit on top */
    left: 0;
    top: 0;
    width: 100%; /* Full width */
    height: 100%; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}

.modal-content {
    background-color: #fefefe;
    margin: 15% auto; /* 15% from the top and centered */
    padding: 20px;
    border: 1px solid #888;
    width: 80%; /* Could be more or less, depending on screen size */
    border-radius: 10px;
    position: relative;
}

.close-button {
    position: absolute;
    top: 0;
    right: 0;
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    padding: 0 10px;
    cursor: pointer;
}

.close-button:hover,
.close-button:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

/* === Chinese Text Highlight === */
.chinese-text {
    color: #D32F2F; /* Màu đỏ để nổi bật */
    font-weight: bold;
    position: relative;
    cursor: pointer;
    display: inline;
    background-color: rgba(211, 47, 47, 0.1); /* Nền mờ để tăng độ nổi bật */
    padding: 0 2px;
    border-radius: 2px;
}

.chinese-text:hover::after {
    content: "Click để copy";
    position: absolute;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 12px;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    z-index: 10;
}

.copy-feedback {
    position: absolute;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 12px;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    display: none;
    z-index: 10;
}

/* === Responsive Styles for Mobile === */
@media (max-width: 600px) {
    body {
        font-size: 14px; /* Giảm kích thước chữ trên mobile */
        align-items: flex-start; /* Đảm bảo nội dung căn đầu trang */
        padding: 0; /* Loại bỏ padding không cần thiết */
    }
    .chat-container {
        width: 100%;
        height: 100vh;
        max-height: 100vh;
        border-radius: 0; /* Loại bỏ border-radius trên mobile */
        box-shadow: none; /* Loại bỏ shadow để gọn gàng hơn */
        margin: 0; /* Đảm bảo không có margin gây lệch */
    }
    .chat-header {
        padding: 10px 15px;
        border-radius: 0; /* Không có radius trên mobile full screen */
        font-size: 0.9em; /* Giảm kích thước chữ */
        flex-wrap: wrap; /* Cho phép wrap nếu không đủ không gian */
    }
    .header-content {
        flex-grow: 1;
        margin-bottom: 5px; /* Khoảng cách nếu wrap */
    }
    .logo {
        height: 30px; /* Giảm kích thước logo */
    }
    .chat-header h1 {
        font-size: 1.1em; /* Giảm kích thước tiêu đề */
    }
    .mode-toggle {
        margin-right: 10px;
        font-size: 0.8em; /* Giảm kích thước chữ */
    }
    .mode-label {
        font-size: 0.8em; /* Giảm kích thước chữ trên mobile */
    }
    .switch {
        width: 50px; /* Giảm kích thước toggle */
        height: 28px;
    }
    .slider {
        border-radius: 28px;
    }
    .slider:before {
        height: 22px;
        width: 22px;
        left: 3px;
        bottom: 3px;
    }
    input:checked + .slider:before {
        transform: translateX(22px);
    }
    .chat-box {
        padding: 10px 15px; /* Giảm padding để tiết kiệm không gian */
        height: calc(100vh - 140px); /* Đảm bảo chiều cao phù hợp với input và header */
    }
    .message {
        padding: 8px 12px; /* Giảm padding cho tin nhắn */
        max-width: 90%; /* Tăng chiều rộng tối đa để tận dụng không gian */
        font-size: 0.9em; /* Giảm kích thước chữ */
    }
    .input-area {
        padding: 10px 15px; /* Giảm padding */
        position: sticky; /* Đảm bảo input luôn ở dưới cùng */
        bottom: 0;
        background-color: var(--background-elements);
        flex-wrap: nowrap; /* Đảm bảo không wrap trên mobile để giữ layout */
    }
    .input-area textarea {
        padding: 8px 12px; /* Giảm padding */
        font-size: 0.9em; /* Giảm kích thước chữ */
        min-height: 20px; /* Giảm chiều cao tối thiểu */
        max-height: 100px; /* Giảm chiều cao tối đa */
    }
    .input-area button {
        width: 40px; /* Giảm kích thước nút */
        height: 40px;
        font-size: 1em; /* Giảm kích thước icon */
    }
    .chinese-text:hover::after, .copy-feedback {
        font-size: 10px; /* Giảm kích thước chữ tooltip trên mobile */
        top: -20px; /* Điều chỉnh vị trí tooltip */
    }
}
