/* Variables */
:root {
    --sideline-green: #19b563; /* Màu xanh lá cây chuẩn của Sideline */
    --background-light: #ffffff;
    --border-color: #e0e0e0;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --hover-bg: #f5f5f5;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

/* Reset cơ bản */
* { box-sizing: border-box; margin: 0; padding: 0; }

body, html {
    font-family: 'Montserrat', sans-serif; /* Thay đổi ở đây */
    background-color: var(--background-light);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

/* Header chính */
.main-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #00b645;
    height: 60px;
    padding: 0 24px;
    color: white;
    flex-shrink: 0;
}
.header-left, .header-right { display: flex; align-items: center; }
.logo { height: 32px; vertical-align: middle; }
.by-pinger { margin-left: 8px; font-size: 14px; opacity: 0.9; }
.phone-dropdown { gap: 6px; cursor: pointer; }
.phone-number { font-weight: 700; font-size: 16px; }

/* Bố cục chính */
.app-layout {
    display: flex;
    height: calc(100vh - 60px);
    position: relative; /* Thêm thuộc tính này */
}

/* Panel Inbox (bên trái) */
.inbox-panel {
    width: 360px;
    min-width: 320px;
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}
/* Tìm và đảm bảo class này trong style.css có các thuộc tính sau */
.inbox-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}
.inbox-header h1 { font-size: 24px; font-weight: bold; margin: 0; }
/* Tìm và thay thế class này trong style.css */
.compose-button {
    height: 40px;
    background-color: var(--sideline-green);
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    /* Đã xóa các thuộc tính float, top, left bị thừa */
}
.conversations-list { flex-grow: 1; overflow-y: auto; }
.empty-message { text-align: center; padding: 30px 15px; color: var(--text-secondary); }

/* Panel Chat (bên phải) */
.chat-panel {
    flex: 1;
    display: flex;
    flex-direction: column; /* Quan trọng: Sắp xếp các mục theo chiều dọc */
    background-color: #fff;
    /* Đảm bảo chiều cao không vượt quá màn hình */
    height: 100%; 
    position: relative; 
}

.chat-header {
    /* Xóa display: flex và justify-content nếu có */
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    min-height: 69px;
}
.messages-container {
    flex-grow: 1;       /* Quan trọng: Cho phép nó lấp đầy mọi không gian trống */
    overflow-y: auto;   /* Quan trọng: Tự động thêm thanh cuộn khi cần */
    padding: 24px;
    display: flex;
    flex-direction: column;
}
#composer-view {
    padding: 24px 0; /* Khoảng cách trên dưới cho ô nhập liệu */
}
#recipient-input {
    width: 100%;
    border: none;
    outline: none;
    font-size: 16px;
    font-family: var(--font-family);
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px; /* Khoảng cách từ chữ đến đường kẻ */
}

/* Form gửi tin nhắn (cố định ở dưới) */
.send-message-form {
    flex-shrink: 0; /* Quan trọng: Ngăn không cho nó bị đẩy hoặc co lại */
    display: flex;
    align-items: center;
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    gap: 12px;
}
.message-input-wrapper {
    flex-grow: 1;
    background-color: #f0f0f0; /* Nền xám nhạt cho ô input */
    border: 1px solid #f0f0f0;
    border-radius: 20px;
    padding: 8px 15px;
    display: flex;
}
#message-input {
    width: 100%;
    border: none;
    outline: none;
    background-color: transparent;
    font-size: 15px;
}
.control-btn {
    border: none;
    background: none;
    cursor: pointer;
    font-size: 20px;
    color: var(--text-secondary);
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.send-btn { font-size: 18px; }
/* Thêm vào cuối file style.css */
.message-wrapper {
    display: flex;
    max-width: 70%;
    margin-bottom: 12px;
}
.message-wrapper.outbound {
    align-self: flex-end;
}
.message-wrapper.inbound {
    align-self: flex-start;
}
.message-wrapper.error {
    align-self: center;
}

.message-bubble {
    padding: 10px 16px;
    border-radius: 18px;
    line-height: 1.4;
}
.message-bubble.outbound {
    background-color: #19b563; /* Màu xanh lá */
    color: white;
    border-bottom-right-radius: 4px;
}
.message-bubble.inbound {
    background-color: #f0f0f0; /* Màu xám nhạt */
    color: #212529;
    border-bottom-left-radius: 4px;
}
.message-bubble.error {
    background-color: #f8d7da;
    color: #842029;
    font-size: 14px;
}
/* --- CSS CHO DANH SÁCH HỘI THOẠI --- */

.conversation-item {
    display: flex;
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid #f0f0f0;
    gap: 12px;
    align-items: center;
}
.conversation-item:hover {
    background-color: #f5f5f5;
}
.conversation-item.active {
    background-color: #e8f5e9;
}

.convo-avatar {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: #a0a0a0;
}

.convo-details {
    overflow: hidden;
    width: 100%;
}

.convo-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2px;
}

.convo-number {
    font-weight: 600;
}

.convo-timestamp {
    font-size: 12px;
    color: #6c757d;
}

.convo-preview {
    font-size: 14px;
    color: #6c757d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
}

/* --- CSS CHO CÁC TIN NHẮN TRONG KHUNG CHAT --- */

.message-wrapper {
    display: flex;
    max-width: 70%;
    margin-bottom: 12px;
}
.message-wrapper.outbound {
    align-self: flex-end;
}
.message-wrapper.inbound {
    align-self: flex-start;
}
.message-wrapper.error {
    align-self: center;
}

.message-bubble {
    padding: 10px 16px;
    border-radius: 18px;
    line-height: 1.4;
}
.message-bubble.outbound {
    background-color: #19b563;
    color: white;
    border-bottom-right-radius: 4px;
}
.message-bubble.inbound {
    background-color: #f0f0f0;
    color: #212529;
    border-bottom-left-radius: 4px;
}
.message-bubble.error {
    background-color: #f8d7da;
    color: #842029;
    font-size: 14px;
}
/* Thêm vào cuối file style.css */

.date-separator {
    text-align: center;
    margin: 20px 0;
    font-size: 13px;
    font-weight: 500;
    color: #6c757d;
}
/* --- CSS CHO KHUNG HIỂN THỊ TIN NHẮN --- */

/* Container chính chứa các tin nhắn */
.messages-container {
    display: flex;
    flex-direction: column; /* Sắp xếp tin nhắn theo chiều dọc */
    padding: 24px;
    overflow-y: auto;
    flex-grow: 0.8;
    height: 0; /* QUAN TRỌNG: Thêm dòng này */
}

/* Thẻ bao bọc mỗi tin nhắn */
.message-wrapper {
    display: flex;
    max-width: 70%;
    margin-bottom: 4px; /* Giảm khoảng cách giữa các tin nhắn */
}

/* Căn chỉnh tin nhắn GỬI ĐI sang phải */
.message-wrapper.outbound {
    align-self: flex-end;
}

/* Căn chỉnh tin nhắn NHẬN ĐẾN sang trái */
.message-wrapper.inbound {
    align-self: flex-start;
}

/* Bong bóng chat */
.message-bubble {
    padding: 10px 16px;
    border-radius: 18px;
    line-height: 1.4;
    word-wrap: break-word;
}

/* Màu cho bong bóng GỬI ĐI */
.message-bubble.outbound {
    background-color: var(--sideline-green);
    color: white;
    border-bottom-right-radius: 4px; /* Tạo hiệu ứng "đuôi" cho bong bóng */
}

/* Màu cho bong bóng NHẬN ĐẾN */
.message-bubble.inbound {
    background-color: #f0f0f0;
    color: var(--text-primary);
    border-bottom-left-radius: 4px; /* Tạo hiệu ứng "đuôi" cho bong bóng */
}
/* --- CSS CHO DẤU PHÂN CÁCH NGÀY --- */

.date-separator {
    text-align: center; /* Căn giữa */
    margin: 20px 0;     /* Tạo khoảng cách trên dưới */
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary); /* Dùng màu chữ phụ */
}
/* Thêm vào cuối file style.css */

.message-bubble.image-bubble {
    padding: 5px; /* Giảm padding cho tin nhắn chỉ chứa ảnh */
    background-color: transparent; /* Bỏ màu nền xanh/xám */
}
/* --- CSS CHO THỜI GIAN DƯỚI MỖI TIN NHẮN --- */

/* Cập nhật lại message-wrapper để sắp xếp theo chiều dọc */
.message-wrapper {
    display: flex;
    flex-direction: column; /* Quan trọng: xếp bong bóng và thời gian trên dưới */
    max-width: 70%;
    margin-bottom: 12px;
}

/* Căn chỉnh lại cho đúng hướng */
.message-wrapper.outbound {
    align-items: flex-end;
}
.message-wrapper.inbound {
    align-items: flex-start;
}

/* Style cho dòng thời gian */
.message-timestamp {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;      /* Khoảng cách với bong bóng chat ở trên */
    padding: 0 8px;       /* Căn lề cho đẹp */
}
/* Thêm vào cuối file style.css */

/* Bỏ padding và màu nền cho bong bóng chỉ chứa ảnh */
.message-bubble.image-bubble {
    padding: 5px;
    background-color: transparent;
}

/* Giới hạn kích thước của ảnh bên trong bong bóng chat */
.message-bubble img {
    max-width: 250px; /* Chiều rộng tối đa của ảnh */
    height: auto;     /* Chiều cao tự động điều chỉnh */
    border-radius: 12px; /* Bo góc cho đẹp */
    display: block;      /* Đảm bảo ảnh không có khoảng trống thừa bên dưới */
}
/* --- CSS CHO MENU ĐÍNH KÈM --- */

/* Lớp vỏ bọc menu */
.attachment-menu {
    position: absolute; /* Định vị tuyệt đối so với thẻ cha */
    bottom: 75px;       /* Vị trí phía trên thanh nhập liệu */
    left: 20px;
    background-color: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    padding: 10px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    z-index: 100;
    
    /* Mặc định ẩn đi */
    visibility: hidden;
    opacity: 0;
    transform: translateY(10px);
    transition: all 0.2s ease-in-out;
}

/* Trạng thái hiển thị của menu */
.attachment-menu.visible {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
}

/* Các mục trong menu */
.menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 15px;
    border: none;
    background-color: transparent;
    cursor: pointer;
    text-align: left;
    border-radius: 6px;
    width: 200px;
}

.menu-item:hover {
    background-color: #f5f5f5;
}

.menu-item i {
    font-size: 18px;
    color: #555;
    width: 20px; /* Cố định chiều rộng icon cho đều */
}
/* Thêm vào cuối file style.css */

/* Lớp phủ cho trạng thái đang gửi */
.sending-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    border-radius: 12px;
}

.message-bubble.image-bubble {
    position: relative; /* Cần thiết cho lớp phủ */
}

/* Style cho trạng thái gửi lỗi */
.message-wrapper.failed .message-timestamp {
    color: #dc3545; /* Màu đỏ */
    font-weight: bold;
}
/* --- CSS CHO MODAL TẠO TEMPLATE MỚI --- */

/* Tùy chỉnh kích thước cho modal tạo mới */
.modal-content.create-modal {
    max-width: 420px;
}

.create-modal .modal-header {
    padding: 20px;
}

.create-modal .modal-header h2 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

#create-template-form {
    padding: 0 20px 20px 20px;
}

#create-template-form .form-group {
    margin-bottom: 15px;
}

/* Style cho ô input và textarea */
#create-template-form input[type="text"],
#create-template-form textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 15px;
    font-family: var(--font-family);
}

#create-template-form input[type="text"]:focus,
#create-template-form textarea:focus {
    outline: none;
    border-color: var(--sideline-green);
    box-shadow: 0 0 0 2px rgba(25, 181, 99, 0.2);
}

/* Dòng chữ "Need ideas?" */
.form-info {
    font-size: 13px;
    text-align: left;
    margin-top: 8px;
    color: var(--text-secondary);
}
.form-info a {
    color: var(--sideline-green);
    text-decoration: none;
    font-weight: 500;
}

/* Thông báo lỗi */
.error-message {
    color: #d93025;
    font-size: 12px;
    text-align: left;
    margin-top: 4px;
    display: block;
    min-height: 15px;
}

/* Khu vực "Add Image" */
.add-image-placeholder {
    border: 2px dashed #e0e0e0;
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    color: var(--sideline-green);
    font-weight: 500;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.add-image-placeholder i {
    font-size: 24px;
}

/* Bộ đếm ký tự */
#create-template-form textarea {
    min-height: 100px;
    resize: vertical;
}
.char-counter {
    text-align: right;
    font-size: 12px;
    color: #888;
    margin-top: 5px;
}

/* Các nút bấm */
.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
    border-top: 1px solid #eee;
    padding-top: 20px;
}
.btn-secondary {
    background: #f0f0f0;
    color: var(--text-primary);
    padding: 10px 20px;
    border-radius: 6px;
    border: 1px solid #ccc;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
}
.btn-primary {
    background: var(--sideline-green);
    color: white;
    padding: 10px 20px;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-weight: 500;
    font-size: 14px;
}
/* --- CSS CHO MODAL VÀ TEMPLATES --- */

/* Lớp phủ nền mờ cho modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 1;
    transition: opacity 0.3s ease;
}

/* Ẩn modal */
.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Nội dung chính của modal */
.modal-content {
    background: white;
    padding: 0;
    border-radius: 8px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    width: 90%;
    max-width: 500px;
    transform: scale(1);
    transition: transform 0.3s ease;
}

.modal-overlay.hidden .modal-content {
    transform: scale(0.9);
}

/* Header của modal */
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}

.modal-tabs {
    display: flex;
    gap: 10px;
}

.tab-btn {
    padding: 8px 16px;
    border: none;
    background: transparent;
    cursor: pointer;
    font-size: 15px;
    font-weight: 500;
    color: #888;
    border-bottom: 2px solid transparent;
}

.tab-btn.active {
    color: var(--sideline-green);
    border-bottom-color: var(--sideline-green);
}

.create-btn {
    background-color: var(--sideline-green);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

/* Nút đóng modal chung */
.close-modal-btn {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: #888;
}

/* Body của modal */
.modal-body {
    padding: 20px;
    max-height: 400px;
    overflow-y: auto;
}

/* Các tab nội dung */
.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

/* --- Style cho từng mục template --- */
.template-item {
    padding: 12px 10px;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.template-item:hover {
    background-color: #f5f5f5;
}

.template-item:last-child {
    border-bottom: none;
}

.template-item h4 {
    margin: 0 0 4px 0;
    font-size: 15px;
    font-weight: 600;
    color: #333;
}

.template-item p {
    margin: 0;
    font-size: 14px;
    color: #666;
}
/* --- CSS CHO MENU DROPDOWN CỦA USER --- */

.user-menu {
    position: absolute;
    top: 55px; /* Vị trí ngay dưới header */
    right: 20px;
    background-color: white;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    width: 260px;
    z-index: 1001;
    border: 1px solid #e0e0e0;
    padding: 8px 0;
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.user-menu.hidden {
    opacity: 0;
    transform: translateY(-10px);
    pointer-events: none; /* Không cho phép click khi đang ẩn */
}

.user-menu-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    font-size: 14px;
    color: var(--text-primary);
    cursor: pointer;
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    text-decoration: none;
}

.user-menu-item:hover {
    background-color: var(--hover-bg);
}

.menu-separator {
    height: 1px;
    background-color: var(--border-color);
    margin: 8px 0;
}

/* --- CSS cho nút gạt (toggle switch) --- */
.switch {
    position: relative;
    display: inline-block;
    width: 34px;
    height: 20px;
}

.switch input { 
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: #ccc;
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
}

input:checked + .slider {
    background-color: var(--sideline-green);
}

input:checked + .slider:before {
    transform: translateX(14px);
}

.slider.round {
    border-radius: 20px;
}

.slider.round:before {
    border-radius: 50%;
}
/* --- CSS CHO KHUNG CHỌN EMOJI --- */
.emoji-picker-container {
    position: absolute;
    bottom: 70px; /* Vị trí phía trên thanh nhập liệu */
    right: 15px;
    z-index: 100;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    border-radius: 8px;
    overflow: hidden; /* Giúp bo góc cho emoji-picker bên trong */
}

.emoji-picker-container.hidden {
    display: none;
}
/* --- CSS CHO TIN NHẮN CHƯA ĐỌC --- */


/* In đậm SĐT và tin nhắn preview */
.conversation-item.unread .convo-number,
.conversation-item.unread .convo-preview {
    font-weight: bold;
    color: var(--text-primary);
}

/* Thêm position: relative vào item chính để làm mốc */
/* (Lưu ý: có thể bạn đã có rule .conversation-item, hãy đảm bảo nó có position: relative) */
.conversation-item {
    position: relative;
}

/* Dấu chấm màu xanh báo có tin nhắn mới */
.conversation-item.unread::before {
    content: '';
    position: absolute;
    /* Đặt dấu chấm vào bên trong padding trái của item */
    left: 8px; 
    top: 50%;
    transform: translateY(-50%);
    width: 8px;
    height: 8px;
    background-color: var(--sideline-green, green); 
    border-radius: 50%;
}
/* --- CSS CHO KHU VỰC NHẬP LIỆU NGƯỜI NHẬN (TAGS) --- */

/* Container chính bao bọc các thẻ và ô input */
.recipient-container {
    display: flex;
    flex-wrap: wrap; /* Cho phép các thẻ xuống dòng nếu không đủ chỗ */
    align-items: center;
    gap: 6px;
    padding: 5px;
    border-bottom: 1px solid var(--border-color);
}

/* Thẻ "pill" hiển thị SĐT đã nhập */
.recipient-pill {
    display: flex;
    align-items: center;
    background-color: #e9ecef;
    border: 1px solid #dee2e6;
    border-radius: 16px;
    padding: 4px 8px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap; /* Ngăn SĐT bị xuống dòng */
}

/* Nút 'x' để xóa thẻ */
.recipient-pill .remove-btn {
    margin-left: 8px;
    border: none;
    background: #adb5bd;
    color: white;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
}

/* Ô input để nhập SĐT tiếp theo */
#recipient-input-live {
    border: none;
    outline: none;
    flex-grow: 1; /* Lấp đầy không gian còn lại */
    padding: 6px;
    font-size: 15px;
     font-weight: bold;
}