/* --- TỐI ƯU TOÀN MÀN HÌNH & KHÔNG BỊ KHUẤT FOOTER TRÊN MOBILE --- */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    width: 100%;
    overflow: hidden; /* Tránh tình trạng cuộn toàn bộ trang web */
    background: #0e1621;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Thẻ chứa chính ôm trọn toàn màn hình (Hỗ trợ iOS Safari & Chrome Mobile) */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Giúp khớp chính xác khung hình khi thanh địa chỉ mobile ẩn/hiện */
    height: calc(var(--vh, 1vh) * 100); /* Fallback bằng Javascript */
    width: 100%;
    position: relative;
}

/* --- HEADER --- */
.chat-header {
    background: #242f3d;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid #0e1621;
    z-index: 10;
    flex-shrink: 0; /* Không cho phép header bị co lại */
}

.back-btn {
    background: none;
    border: none;
    cursor: pointer;
    margin-right: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.back-btn svg {
    width: 24px;
    height: 24px;
    fill: #7d8b99;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #2b5278;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    color: #fff;
    margin-right: 12px;
    flex-shrink: 0;
}

.chat-info h3 {
    font-size: 16px;
    color: #fff;
    margin: 0;
}

.chat-info span {
    font-size: 12px;
    color: #7d8b99;
}

/* --- MESSAGES AREA --- */
.chat-messages {
    flex: 1; /* Tự động dãn rộng tối đa khoảng trống giữa Header và Footer */
    padding: 15px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Cuộn mượt trên thiết bị iOS */
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" opacity="0.03"><rect width="100" height="100" fill="%23fff"/></svg>');
}

/* --- BONG BÓNG TIN NHẮN --- */
.message {
    max-width: 80%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.4;
    position: relative;
    word-wrap: break-word;
    color: #ffffff;
}

.message.incoming {
    background: #182533;
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.message.outgoing {
    background: #2b5278;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.message .time {
    font-size: 10px;
    color: #7d8b99;
    float: right;
    margin-left: 8px;
    margin-top: 4px;
}

/* --- INPUT FOOTER CỐ ĐỊNH --- */
.chat-input-area {
    background: #242f3d;
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0; /* Giữ nguyên kích thước khung nhập không bị đè ép */
    position: relative;
    z-index: 10;
}

.chat-input-area input {
    flex: 1;
    background: #17212b;
    border: none;
    padding: 10px 15px;
    border-radius: 20px;
    color: #fff;
    font-size: 14px;
    outline: none;
}

.chat-input-area input::placeholder {
    color: #7d8b99;
}

.send-btn {
    background: #5288c1;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 0.2s;
    flex-shrink: 0;
}

.send-btn:hover {
    background: #4075a6;
}

.send-btn svg {
    width: 18px;
    height: 18px;
    fill: #fff;
    transform: translateX(1px);
}
/* Context Menu & Overlay */
.ctx-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    display: none;
    justify-content: center;
    align-items: flex-end;
    z-index: 9999;
    animation: fadeIn 0.15s ease-out;
}
.ctx-overlay.active { display: flex; }

.ctx-menu {
    background: #fff;
    width: 100%;
    max-width: 450px;
    border-radius: 16px 16px 0 0;
    padding: 10px 0;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.15);
    animation: slideUp 0.2s ease-out;
}

.ctx-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    font-size: 15px;
    color: #222;
    cursor: pointer;
    transition: background 0.15s;
}
.ctx-item:active { background: #f0f0f0; }
.ctx-item svg { width: 20px; height: 20px; fill: #555; margin-right: 15px; }

/* Selection Mode Layout */
.selection-header {
    background: #3390ec !important;
    color: #fff !important;
}
.selection-header h3 { color: #fff !important; }
.selection-header svg { fill: #fff !important; }
.selection-actions { display: flex; gap: 15px; margin-left: auto; }
.selection-actions button { background: none; border: none; cursor: pointer; color: #fff; }

/* Item Selected state */
.message {
    position: relative;
    transition: background 0.2s;
}
.message.selected {
    background-color: rgba(51, 144, 236, 0.18) !important;
}
.message.selected::before {
    content: "✓";
    position: absolute;
    left: -25px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    background: #3390ec;
    color: white;
    border-radius: 50%;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Modal Forward */
.forward-modal {
    position: fixed;
    top:0; left:0; right:0; bottom:0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}
.forward-modal.active { display: flex; }
.forward-content {
    background: #fff;
    width: 90%;
    max-width: 400px;
    border-radius: 12px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    color: #004991;
}
.forward-header {
    padding: 15px;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.forward-header h3 { font-size: 16px; margin:0; }
.forward-header button { background:none; border:none; font-size:22px; cursor:pointer; }
.forward-list { overflow-y: auto; flex: 1; }
.forward-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    border-bottom: 1px solid #f5f5f5;
    cursor: pointer;
}
.forward-item:active { background: #f0f0f0; }
.leave-group-trigger-btn {
    background: none;
    border: none;
    font-size: 20px;
    font-weight: bold;
    color: #8e8e93;
    cursor: pointer;
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}
.leave-group-trigger-btn:hover {
    color: #ff3b30; /* Đổi sang màu đỏ khi hover */
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }