:root {
    --primary: #2ecc71;
    --sidebar-bg: #ffffff;
    --chat-bg: #f0f2f5;
    --border: #e4e6eb;
    --border-soft: #e8e8e8;
    --text-main: #050505;
    --text-muted: #65676b;
    --text-dim: #8a8d91;
    --text-strong: #1c1e21;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --surface-3: #f7f8fa;
    --hover: #f5f6f7;
    --active: #e7f3ff;
    --overlay-06: rgba(0,0,0,0.06);
    --overlay-12: rgba(0,0,0,0.12);
    --sent-bg: #ffffff;
    --sent-text: #050505;
    --received-bg: #ffffff;
    --received-text: #050505;
    --accent-green: #00a859;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --sidebar-bg: #181c22;
        --chat-bg: #0f1216;
        --border: #2a2f36;
        --border-soft: #2a2f36;
        --text-main: #e7e9ea;
        --text-muted: #9a9ea3;
        --text-dim: #82868b;
        --text-strong: #f2f3f5;
        --surface: #1b1f25;
        --surface-2: #22262c;
        --surface-3: #1e2227;
        --hover: #262b31;
        --active: #1d3a52;
        --overlay-06: rgba(255,255,255,0.06);
        --overlay-12: rgba(255,255,255,0.12);
        --sent-bg: #1f4d3a;
        --sent-text: #eafbf1;
        --received-bg: #262b31;
        --received-text: #e7e9ea;
        --accent-green: #2ecc71;
    }
}
:root[data-theme="dark"] {
    --sidebar-bg: #181c22;
    --chat-bg: #0f1216;
    --border: #2a2f36;
    --border-soft: #2a2f36;
    --text-main: #e7e9ea;
    --text-muted: #9a9ea3;
    --text-dim: #82868b;
    --text-strong: #f2f3f5;
    --surface: #1b1f25;
    --surface-2: #22262c;
    --surface-3: #1e2227;
    --hover: #262b31;
    --active: #1d3a52;
    --overlay-06: rgba(255,255,255,0.06);
    --overlay-12: rgba(255,255,255,0.12);
    --sent-bg: #1f4d3a;
    --sent-text: #eafbf1;
    --received-bg: #262b31;
    --received-text: #e7e9ea;
    --accent-green: #2ecc71;
}

body { margin: 0; font-family: 'Inter', sans-serif; height: 100vh; height: 100dvh; overflow: hidden; background: var(--chat-bg); color: var(--text-main); }
.app-container { display: flex; height: 100vh; height: 100dvh; width: 100vw; }

/* Sidebar */
.sidebar { width: 400px; min-width: 220px; max-width: 700px; background: var(--sidebar-bg); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }

.sidebar-resizer { width: 5px; cursor: col-resize; background: transparent; flex-shrink: 0; transition: background 0.15s; z-index: 10; }
.sidebar-resizer:hover, .sidebar-resizer.dragging { background: #1565c0; }
.sidebar-header { padding: 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.sidebar-header h2 { margin: 0; font-size: 1.25rem; font-weight: 600; color: var(--text-main); }
.nav-buttons a { text-decoration: none; font-size: 0.8rem; color: var(--text-muted); margin-left: 10px; background: var(--surface-2); padding: 6px 12px; border-radius: 6px; font-weight: 500; }
.nav-buttons a:hover { color: #00a859; background: var(--hover); }

.contact-list { flex: 1; overflow-y: auto; }
.contact-item { display: flex; padding: 15px 15px; cursor: pointer; transition: background 0.2s; border-bottom: 1px solid var(--border); align-items: flex-start; }
.contact-item:hover { background: var(--hover); }
.contact-item.active { background: var(--active); }

.contact-avatar { width: 46px; height: 46px; border-radius: 50%; margin-right: 10px; flex-shrink: 0; }
.contact-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; border: 1px solid var(--border-soft); }

.contact-info { flex: 1; min-width: 0; }
.contact-name-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 2px; }
.contact-name-group { display: flex; align-items: center; gap: 6px; min-width: 0; overflow: hidden; }
.contact-name { font-weight: 500; font-size: 1rem; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex-shrink: 1; }
.contact-time { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }

.contact-last-msg-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2px; }
.contact-last-msg { font-size: 0.9rem; font-weight: 400; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 10px; }
.contact-last-msg.has-unread { font-weight: 700; color: var(--text-strong); }
.unread-badge { min-width: 20px; height: 20px; background: #e74c3c; border-radius: 10px; padding: 0 6px; display: flex; align-items: center; justify-content: center; font-size: 0.72rem; font-weight: 700; color: white; flex-shrink: 0; }

/* Bot Pill Badge */
.bot-pill { display: inline-flex; align-items: center; background: var(--surface-2); border-radius: 20px; border: 1px solid var(--border); padding-right: 5px; }
.bot-pill img { width: 20px; height: 20px; border-radius: 50%; margin-right: 4px; border: 1px solid var(--border-soft); }
.bot-pill span { font-size: 0.85rem; color: var(--text-main); font-weight: 500; }
.bot-pill.bot-pill-internal { background: #e3f2fd; border-color: #bbdefb; padding: 0px 4px; flex-shrink: 0; white-space: nowrap; }
.bot-pill.bot-pill-internal span { color: #1565c0; font-weight: 600; white-space: nowrap; }
.bot-pill-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.mute-icon { font-size: 0.75rem; opacity: 0.7; }
.category-pill { display: inline-flex; align-items: center; padding: 0px 6px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; background: var(--surface-2); border: 1px solid var(--border); }
.order-pill { display: inline-flex; align-items: center; padding: 0px 6px; border-radius: 20px; font-size: 0.8rem; font-weight: 600; background: var(--surface-2); border: 1.5px solid; white-space: nowrap; }
.category-select { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 3px 8px; border-radius: 14px; border: 1px solid #0068ff; background: var(--surface); color: #0068ff; cursor: pointer; white-space: nowrap; }
.category-select:hover { background: #f0f4ff; }
.category-select svg { flex-shrink: 0; }
.category-menu { position: fixed; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 4px 16px rgba(0,0,0,0.15); z-index: 9999; min-width: 150px; padding: 4px; max-height: 260px; overflow-y: auto; }
.category-menu-item { padding: 7px 10px; border-radius: 6px; font-size: 0.85rem; font-weight: 500; cursor: pointer; white-space: nowrap; }
.category-menu-item:hover { background: var(--hover); }
.sidebar-toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.sidebar-toolbar input { flex: 1; min-width: 0; border: 1px solid var(--border); border-radius: 20px; padding: 6px 12px; font-size: 0.85rem; outline: none; background: var(--surface-2); color: var(--text-main); }
.sidebar-toolbar input:focus { border-color: #1877f2; background: var(--surface); }
.sidebar-toolbar select { flex-shrink: 0; font-size: 0.82rem; padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); color: var(--text-main); cursor: pointer; }

/* Chat Area */
.chat-area { flex: 1; display: flex; flex-direction: column; background: var(--surface); position: relative; }
.chat-header { padding: 15px 25px; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; }
.chat-header-info h3 { margin: 0; font-size: 1.05rem; color: var(--text-main); }
.chat-header-info p { margin: 4px 0 0; font-size: 0.8rem; color: var(--text-muted); }
.conv-summary-bar { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px 16px; background: var(--surface-3); border-bottom: 1px solid var(--border); font-size: 0.78rem; color: var(--text-muted); }
.summary-tag { background: var(--surface-2); border-radius: 12px; padding: 2px 10px; }
.summary-tag.pending { background: #fff3cd; color: #856404; }

.messages-wrap { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.messages-container { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 20px 25px; display: flex; flex-direction: column; background: var(--chat-bg); }
.scroll-bottom-btn {
    position: absolute; right: 24px; bottom: 16px; width: 40px; height: 40px; border-radius: 50%;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-main);
    display: none; align-items: center; justify-content: center; cursor: pointer;
    box-shadow: 0 2px 10px rgba(0,0,0,0.18); z-index: 5;
}
.scroll-bottom-btn.show { display: flex; }
.scroll-bottom-btn:hover { background: var(--surface-2); }
.message-row { display: flex; margin-bottom: 10px; max-width: 80%; align-items: center; }
.message-row.msg-highlight { animation: msg-highlight-fade 2s ease forwards; }
@keyframes msg-highlight-fade { 0%,30% { outline: 2px solid #1877f2; border-radius: 12px; } 100% { outline: 2px solid transparent; } }
.message-row.sent { align-self: flex-end; flex-direction: row-reverse; }
.message-row.received { align-self: flex-start; }

.msg-bubble { padding: 10px 15px 3px 15px; border-radius: 18px; font-size: 0.95rem; line-height: 1.4; position: relative; min-width: 0; word-break: break-word; overflow-wrap: break-word; }
.sent .msg-bubble { background: var(--sent-bg); color: var(--sent-text); border-bottom-right-radius: 4px; border: 1px solid var(--border); }
.received .msg-bubble { background: var(--received-bg); color: var(--received-text); border-bottom-left-radius: 4px; border: 1px solid var(--border); }

.msg-footer { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.msg-time { font-size: 0.7rem; color: var(--text-dim); display: block; margin-left: auto; flex-shrink: 0; }
.sent .msg-time { color: var(--text-muted); }
.msg-recalled-label { text-decoration: line-through; color: var(--text-dim); font-style: italic; font-size: 0.85em; margin-top: 2px; }

.chat-input-area { padding: 12px 20px; background: var(--surface); border-top: 1px solid var(--border); display: flex; align-items: center; gap: 4px; }
.chat-input { flex: 1; background: var(--surface-2); border: none; padding: 10px 16px; border-radius: 20px; outline: none; font-size: 1rem; color: var(--text-main); resize: none; overflow-y: auto; max-height: 160px; line-height: 1.4; font-family: inherit; display: block; }
.send-btn { background: none; border: none; color: var(--text-strong); cursor: pointer; padding: 0 15px; font-size: 1.6rem; transition: transform 0.2s; }
.send-btn:hover { transform: scale(1.1); }
.img-btn, .file-btn { background: none; border: none; cursor: pointer; font-size: 1.4rem; padding: 0 8px; transition: transform 0.2s; }
.img-btn:hover, .file-btn:hover { transform: scale(1.1); }
.msg-image { max-width: 240px; max-height: 240px; border-radius: 10px; cursor: pointer; display: block; }
.sent .msg-bubble .msg-image { border-radius: 10px 10px 2px 10px; }
.received .msg-bubble .msg-image { border-radius: 10px 10px 10px 2px; }
.msg-image-title { font-size: 0.82rem; color: var(--text-muted); margin-top: 5px; max-width: 240px; word-break: break-word; white-space: pre-wrap; }
.msg-video-wrap { position: relative; display: inline-block; cursor: pointer; line-height: 0; }
.msg-video { max-width: 280px; max-height: 200px; border-radius: 10px; display: block; background: #000; pointer-events: none; }
.msg-video-play { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); width: 44px; height: 44px; background: rgba(0,0,0,0.55); border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 1.2rem; padding-left: 3px; pointer-events: none; }
.msg-sticker { width: 130px; height: 130px; object-fit: contain; display: block; }
.msg-file { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; background: var(--overlay-06); border-radius: 8px; color: inherit; text-decoration: none; font-size: 0.9rem; max-width: 260px; word-break: break-all; }
.msg-file:hover { background: var(--overlay-12); }
.msg-link-preview { display: flex; flex-direction: column; text-decoration: none; color: inherit; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); max-width: 260px; background: var(--surface); }
.msg-link-preview:hover { background: var(--surface-3); }
.msg-link-preview .link-preview-thumb { width: 100%; object-fit: cover; display: block; }
.msg-link-preview .link-preview-info { padding: 8px 10px; }
.msg-link-preview .link-preview-title { font-size: 0.85rem; font-weight: 600; color: var(--text-main); line-height: 1.3; margin-bottom: 3px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.msg-link-preview .link-preview-src { font-size: 0.75rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-preview-msg { margin-bottom: 6px; white-space: pre-wrap; word-break: break-word; }
.sent .msg-bubble .msg-video { border-radius: 10px 10px 2px 10px; }
.received .msg-bubble .msg-video { border-radius: 10px 10px 10px 2px; }
.sent .msg-bubble .msg-video-wrap .msg-video { border-radius: 10px 10px 2px 10px; }
.received .msg-bubble .msg-video-wrap .msg-video { border-radius: 10px 10px 10px 2px; }

/* Image grid (multi-photo bubble) */
.msg-image-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; width: 260px; }
.img-grid-cell { position: relative; overflow: hidden; border-radius: 8px; cursor: pointer; aspect-ratio: 1; background: var(--border); }
.img-grid-cell.span-full { grid-column: 1 / -1; aspect-ratio: 2 / 1; }
.img-grid-cell img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity 0.15s; }
.img-grid-cell:hover img { opacity: 0.88; }
.sent .msg-bubble .msg-image-grid { border-radius: 10px 10px 2px 10px; }
.received .msg-bubble .msg-image-grid { border-radius: 10px 10px 10px 2px; }
.msg-bubble:has(.msg-image-grid) { padding: 4px; }

.no-chat-selected { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-muted); background: var(--surface); }
.no-chat-selected i { font-size: 4rem; margin-bottom: 15px; opacity: 0.1; }
.group-avatar { position: relative; width: 46px; height: 46px; flex-shrink: 0; margin-right: 10px; }
.group-avatar img { position: absolute; width: 28px; height: 28px; border-radius: 50%; object-fit: cover; border: 2px solid var(--sidebar-bg); }
.group-avatar img:nth-child(1) { top: 0; left: 0; }
.group-avatar img:nth-child(2) { bottom: 0; right: 0; }
.group-avatar img:nth-child(3) { top: 0; right: 0; width: 22px; height: 22px; }
.group-avatar-1 img { width: 40px; height: 40px; position: static; border: none; }
.group-avatar-placeholder { width: 46px; height: 46px; border-radius: 50%; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 1.2rem; flex-shrink: 0; margin-right: 10px; }
.contact-avatar-order { width: 46px; height: 46px; border-radius: 50%; background: var(--surface-2); display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; margin-right: 10px; }
.contact-item-order { cursor: pointer; }
.msg-body { display: flex; flex-direction: column; min-width: 0; }
.sender-row { display: flex; align-items: center; gap: 6px; margin-bottom: 4px; padding-top:15px; }
.sender-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.sender-avatar-placeholder { width: 32px; height: 32px; border-radius: 50%; background: #b0b3b8; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; color: white; font-weight: 600; flex-shrink: 0; }
.sender-name { font-size: 0.78rem; color: var(--text-muted); font-weight: 600; }
.internal-badge { font-size: 0.65rem; background: #e3f2fd; color: #1565c0; padding: 1px 6px; border-radius: 8px; font-weight: 600; margin-left: 5px; vertical-align: middle; }
.members-link { cursor: pointer; color: #1877f2; }
.members-link:hover { text-decoration: underline; }
.mention-item:hover, .mention-item.active { background: var(--surface-2); }
.contact-name-link { cursor: pointer; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; }
.contact-name-link:hover { text-decoration: underline; }
.friend-badge { font-size: 0.7rem; padding: 1px 7px; border-radius: 8px; font-weight: 500; }
.friend-badge.friend { background: #e8f5e9; color: #2e7d32; }
.friend-badge.stranger { background: #fff3e0; color: #e65100; }
.internal-avatar { width: 46px; height: 46px; border-radius: 50%; background: #1565c0; display: flex; align-items: center; justify-content: center; font-size: 1.3rem; flex-shrink: 0; color: white; }
.btn-sm { font-size: 12px; padding: 3px 8px; border-radius: 14px; border: 1px solid; background: var(--surface); color: var(--text-main); cursor: pointer; white-space: nowrap; }

/* Reaction picker */
.reaction-picker {
    display: none;
    position: absolute;
    top: 100%;
    padding: 8px 10px 5px;  /* padding-top lấp khoảng hở để hover liền mạch */
    background: var(--surface);
    border-radius: 24px;
    box-shadow: 0 2px 14px rgba(0,0,0,0.15);
    gap: 2px;
    z-index: 100;
    white-space: nowrap;
    border: 1px solid var(--border);
    left: 0;
}
.reaction-picker.picker-above { top: auto; bottom: 100%; padding: 5px 10px 8px; }
.message-row:hover .reaction-picker { display: flex; }
.message-row.sent .msg-bubble .reaction-picker { left: auto; right: 0; }
.reaction-emoji { font-size: 1.25rem; cursor: pointer; padding: 3px 5px; border-radius: 50%; transition: transform 0.15s; user-select: none; }
.reaction-emoji:hover { transform: scale(1.5) translateY(-4px); }
.picker-divider { width: 1px; background: var(--border); margin: 4px 4px; align-self: stretch; }
.picker-action { display: inline-flex; align-items: center; justify-content: center; }

.reactions-display { display: flex; flex-wrap: wrap; gap: 3px; }
.reaction-badge { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2px 5px; font-size: 0.7rem; display: flex; align-items: center; gap: 3px; box-shadow: 0 1px 3px rgba(0,0,0,0.08); }
.sent .reaction-badge { background: rgba(255,255,255,0.2); border-color: rgba(255,255,255,0.3); color: white; }

/* Tim rỗng thả nhanh trên tin nhắn khách gửi gần nhất — đúng vị trí badge reaction
   thật (❤️), không cần hover mở reaction-picker. Bấm vào tự thay bằng badge thật. */
.quick-heart-badge { cursor: pointer; color: var(--text-dim); }
.quick-heart-badge:hover { color: #ff3040; }

/* Reply banner */
.reply-banner { display: none; padding: 8px 15px; background: var(--surface-2); border-top: 1px solid var(--border); align-items: center; justify-content: space-between; font-size: 0.85rem; gap: 8px; }
.reply-banner.show { display: flex; }
.reply-banner-inner { overflow: hidden; flex: 1; }
.reply-banner-name { font-weight: 600; color: var(--text-strong); font-size: 0.8rem; margin-bottom: 2px; }
.reply-banner-content { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-muted); font-size: 0.82rem; }
.reply-cancel { background: none; border: none; font-size: 1.1rem; cursor: pointer; color: var(--text-muted); padding: 2px 6px; flex-shrink: 0; }

/* Link preview banner (khi gõ/dán link vào ô chat) */
.link-preview-banner { display: none; padding: 8px 15px; background: var(--surface-2); border-top: 1px solid var(--border); align-items: center; justify-content: space-between; font-size: 0.85rem; gap: 8px; }
.link-preview-banner.show { display: flex; }
.link-preview-banner-thumb { width: 44px; height: 44px; border-radius: 6px; object-fit: cover; flex-shrink: 0; }
.link-preview-banner-info { overflow: hidden; flex: 1; }
.link-preview-banner-title { font-weight: 600; color: var(--text-strong); font-size: 0.82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.link-preview-banner-src { color: var(--text-muted); font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Attachment preview banner (khi paste ảnh vào ô chat) */
.attachment-preview-banner { display: none; padding: 8px 15px; background: var(--surface-2); border-top: 1px solid var(--border); align-items: center; justify-content: space-between; gap: 8px; }
.attachment-preview-banner.show { display: flex; }
.attachment-preview-list { display: flex; gap: 8px; overflow-x: auto; flex: 1; }
.attachment-preview-item { position: relative; flex-shrink: 0; }
.attachment-preview-thumb { height: 64px; width: 64px; border-radius: 6px; object-fit: cover; display: block; }
.attachment-preview-remove { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface); border: 1px solid var(--border); color: var(--text-muted); font-size: 0.7rem; line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center; padding: 0; }

/* Quote inside bubble */
.msg-quote { background: var(--overlay-06); padding: 6px 10px; border-left: 3px solid var(--text-muted); border-radius: 4px; margin-bottom: 6px; font-size: 0.82rem; max-width: 100%; }
.sent .msg-quote { background: rgba(255,255,255,0.2); border-left-color: rgba(255,255,255,0.7); }
.msg-quote-name { font-weight: 600; margin-bottom: 2px; }
.msg-quote-content { opacity: 0.85; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }

.btn-secondary { border-color: var(--border); color: var(--text-muted); }
.btn-secondary:hover { background: var(--hover); }
.btn-blue { border-color: #1565c0; color: #1565c0; }
.btn-blue:hover { background: #f0f4ff; }
.btn-green { border-color: #00a859; color: #00a859; }
.btn-green:hover { background: #f0fdf6; }
.btn-danger { border-color: #e53935; color: #e53935; }
.btn-danger:hover { background: #fff5f5; }
.only-desktop-inline { display: contents; }
.only-mobile-inline { display: none; }

/* Modal */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 9500; justify-content: center; align-items: center; }
.modal-overlay.open { display: flex; }
.modal-box { background: var(--surface); color: var(--text-main); border-radius: 12px; padding: 24px; width: 400px; max-height: 80vh; display: flex; flex-direction: column; overflow-y: auto; box-shadow: 0 8px 32px rgba(0,0,0,0.2); }
.modal-box h3 { margin: 0 0 16px; font-size: 1.1rem; }
.modal-box input[type=text] { width: 100%; box-sizing: border-box; padding: 8px 12px; border: 1px solid var(--border-soft); border-radius: 6px; font-size: 0.95rem; margin-bottom: 12px; background: var(--surface); color: var(--text-main); }
.user-pick-list { flex: 1; overflow-y: auto; border: 1px solid var(--border-soft); border-radius: 8px; max-height: 240px; }
.user-pick-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; }
.user-pick-item:hover { background: var(--hover); }
.user-initial { width: 36px; height: 36px; border-radius: 50%; background: #1565c0; color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.95rem; flex-shrink: 0; }
.modal-actions { margin-top: 14px; display: flex; gap: 8px; justify-content: flex-end; }

/* Forward modal */
.forward-msg-preview { background: var(--surface-2); border-radius: 8px; padding: 10px 12px; margin-bottom: 12px; border-left: 3px solid #1565c0; }
.forward-preview-from { font-size: 0.75rem; color: var(--text-dim); font-weight: 600; margin-bottom: 3px; }
.forward-preview-content { font-size: 0.88rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.forward-contact-list { flex: 1; overflow-y: auto; border: 1px solid var(--border-soft); border-radius: 8px; max-height: 280px; }
.forward-section-title { padding: 7px 14px 4px; font-size: 0.72rem; font-weight: 700; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.5px; background: var(--surface-3); border-bottom: 1px solid var(--border-soft); }
.forward-contact-item { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; transition: background 0.1s; }
.forward-contact-item:hover { background: var(--hover); }
.forward-contact-item.selected { background: var(--active); }
.forward-avatar { width: 36px; height: 36px; border-radius: 50%; background: #1565c0; color: white; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.95rem; flex-shrink: 0; overflow: hidden; }
.forward-avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.forward-name-wrap { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.forward-name { font-size: 0.92rem; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.forward-session-name { font-size: 0.75rem; color: var(--text-dim); margin-top: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.forward-check { font-size: 1rem; color: #1565c0; font-weight: 700; }

/* Call / bubble message card */
.msg-call-card { display: flex; align-items: center; gap: 10px; padding: 6px 2px; min-width: 160px; text-decoration: none; color: inherit; }
.call-card-icon { font-size: 1.5rem; flex-shrink: 0; line-height: 1; }
.call-card-icon-img { width: 28px; height: 28px; object-fit: contain; flex-shrink: 0; }
.call-card-info { display: flex; flex-direction: column; min-width: 0; }
.call-card-label { font-size: 0.9rem; font-weight: 600; }
.call-card-duration { font-size: 0.78rem; color: var(--text-dim); margin-top: 2px; }
.msg-call-card.missed .call-card-label { color: #e53935; }
.msg-location:hover { opacity: 0.8; }
.msg-location .call-card-duration { color: #1565c0; }
.msg-group-action { opacity: 0.85; }
.msg-group-action .call-card-label { font-weight: 500; font-size: 0.85rem; }
.msg-rtf { white-space: pre-wrap; font-size: 0.92rem; line-height: 1.5; }

/* Clickable links inside messages */
.msg-link { text-decoration: underline; word-break: break-all; }

/* Date separator */
.date-separator {
    display: flex;
    align-items: center;
    text-align: center;
    margin: 12px 0;
    gap: 10px;
}
.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--border);
}
.date-separator span {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: var(--surface-2);
    padding: 2px 10px;
    border-radius: 10px;
    white-space: nowrap;
}

/* RAG suggestion chips */
.suggestion-chip {
    background: var(--surface-2);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    padding: 4px 12px;
    cursor: pointer;
    font-size: 13px;
    white-space: normal;
    word-break: break-word;
    color: var(--text-main);
}
.suggestion-chip:hover { background: var(--hover); }

/* Mobile back button — ẩn trên desktop */
.mobile-back-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    cursor: pointer;
    color: var(--text-main);
    padding: 0 10px 0 0;
    line-height: 1;
}
/* Chuyển theme mượt, không giật */
body, .sidebar, .chat-area, .chat-header, .chat-input-area, .msg-bubble,
.modal-box, .contact-item, .reaction-picker, .reaction-badge, .msg-link-preview {
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

/* Nút chọn theme (sáng / tối / hệ thống) */
.theme-switch { display: inline-flex; align-items: center; flex-shrink: 0; background: var(--surface-2); border: 1px solid var(--border); border-radius: 20px; padding: 3px; gap: 2px; }
.theme-switch button { display: inline-flex; align-items: center; flex-shrink: 0; width: auto; white-space: nowrap; background: none; border: none; border-radius: 16px; padding: 5px 11px; font-size: 0.85rem; line-height: 1; cursor: pointer; color: var(--text-muted); margin: 0; }
.theme-switch button.active { background: var(--surface); color: var(--text-main); box-shadow: 0 1px 2px rgba(0,0,0,0.08); font-weight: 600; }
.theme-switch .ts-label { margin-left: 5px; }

/* Block "File/Ảnh" trong modal thông tin */
.media-preview-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 8px; }
.media-tile { position: relative; overflow: hidden; border-radius: 8px; cursor: pointer; aspect-ratio: 1; background: var(--surface-2); }
.media-tile img, .media-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-tile-more { position: absolute; inset: 0; background: rgba(0,0,0,0.55); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 1.05rem; font-weight: 600; }
.media-tile-file { display: flex; flex-direction: column; align-items: center; justify-content: center; text-decoration: none; color: inherit; padding: 4px; gap: 4px; text-align: center; }
.media-tile-file-icon { font-size: 1.6rem; }
.media-tile-file-name { font-size: 0.65rem; color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* Modal danh sách toàn bộ File/Ảnh (cuộn tải thêm) */
.media-list-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; padding-right: 2px; }
.media-list-loading { grid-column: 1 / -1; text-align: center; padding: 10px; color: var(--text-dim); font-size: 0.85rem; }

@media (max-width: 768px) {
    /* Ngăn overflow ngang, dùng dvh để trừ keyboard iOS */
    html, body { overflow-x: hidden; height: 100dvh; }
    .app-container { overflow: hidden; width: 100vw; height: 100dvh; }
    .chat-area { height: 100dvh; }

    /* Ghim input area ở dưới khi keyboard hiện */
    .chat-input-area { position: sticky; bottom: 0; z-index: 10; background: var(--surface); }
    .reply-banner { position: sticky; bottom: 0; z-index: 9; }
    .link-preview-banner { position: sticky; bottom: 0; z-index: 9; }
    .attachment-preview-banner { position: sticky; bottom: 0; z-index: 9; }
    #suggestions-bar { position: sticky; bottom: 0; z-index: 8; background: var(--surface); }

    /* Layout: sidebar full-width, chat-area đè lên trên dạng drawer trượt ngang */
    .sidebar { width: 100vw !important; max-width: 100vw !important; min-width: 0 !important; }
    .sidebar-resizer { display: none; }
    .chat-area {
        display: flex !important;
        position: fixed !important;
        top: 0; left: 0;
        width: 100vw !important; max-width: 100vw !important;
        height: 100dvh;
        transform: translateX(100%);
        transition: transform 0.25s ease;
        z-index: 20;
        will-change: transform;
    }

    /* Khi đang xem chat: trượt chat-area vào che sidebar */
    body.chat-active .chat-area { transform: translateX(0); }

    /* Hiện nút back */
    .mobile-back-btn { display: block; flex-shrink: 0; }

    /* Header: 2 dòng — dòng 1: back+avatar+tên, dòng 2: action-bar */
    .chat-header { padding: 10px 12px; flex-wrap: wrap; gap: 4px; align-items: center; }
    .chat-header-info { flex: 1; min-width: 0; }
    .chat-header-info h3 { font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .chat-header-info p { font-size: 0.72rem; }
    .header-action-bar { flex-basis: 100%; margin-left: 0; justify-content: flex-start; }
    .category-select { font-size: 0.75rem; padding: 3px 5px; max-width: 120px; }
    .btn-sm { font-size: 0.75rem; padding: 4px 10px; }

    /* Đổi đơn/Unlink: bar header quá chật trên mobile, chuyển vào modal-contact-info */
    .only-desktop-inline { display: none; }
    .only-mobile-inline { display: contents; }

    /* Messages */
    .messages-container { padding: 10px 8px; }
    .message-row { max-width: 88%; }

    /* Input area */
    .chat-input-area { padding: 8px 8px; gap: 2px; }
    .chat-input { font-size: 0.95rem; padding: 8px 12px; }

    /* Sidebar */
    .sidebar-header { padding: 14px 16px; }
    .contact-item { padding: 10px 15px; }

    /* Modal full-width */
    .modal-box { width: 94vw !important; max-width: 94vw !important; padding: 16px; box-sizing: border-box; }

    /* Suggestion chips */
    .suggestion-chip { font-size: 12px; padding: 4px 10px; }

    /* Theme switch: icon trên, label dưới để nút gọn theo chiều ngang, không tràn/xuống dòng giữa chừng */
    .theme-switch button { flex-direction: column; gap: 2px; padding: 5px 7px; border-radius: 10px; }
    .theme-switch .ts-icon { font-size: 1rem; }
    .theme-switch .ts-label { margin-left: 0; font-size: 0.6rem; }
}
