* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; height: 100vh; overflow: hidden; background: #1a1a2e; color: #eee; }
#app { display: flex; height: 100vh; }

/* ── Column 1: Account Avatars with Names ── */
.col-accounts { width: 260px; background: #0f1a30; display: flex; flex-direction: column; border-right: 1px solid #0f3460; flex-shrink: 0; }
.col-accounts-header { padding: 12px 0; text-align: center; font-size: 11px; color: #e94560; font-weight: 700; letter-spacing: 1px; border-bottom: 1px solid #0f3460; flex-shrink: 0; cursor: default; }
.col-accounts-body { flex: 1; overflow-y: auto; padding: 8px 0; display: flex; flex-direction: column; gap: 2px; }
.col-accounts-footer { padding: 8px; border-top: 1px solid #0f3460; display: flex; flex-direction: column; align-items: center; gap: 4px; flex-shrink: 0; }
.col-accounts-footer .footer-actions { display: flex; align-items: center; justify-content: center; gap: 4px; width: 100%; }
.acc-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; transition: background 0.15s; border-left: 3px solid transparent; }
.acc-item:hover { background: rgba(255,255,255,0.04); }
.acc-item.active { background: rgba(233,69,96,0.12); border-left-color: #e94560; }
.acc-item.has-unread { border-left-color: #25D366; }
.acc-item .acc-avatar { width: 40px; height: 40px; border-radius: 50%; position: relative; flex-shrink: 0; }
.acc-item .acc-avatar .avatar-img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: #16213e; display: block; }
.acc-item .acc-avatar .avatar-init { width: 40px; height: 40px; border-radius: 50%; background: #16213e; display: flex; align-items: center; justify-content: center; font-size: 15px; color: #888; }
.acc-item .acc-avatar .online-dot { width: 10px; height: 10px; border-radius: 50%; background: #4ade80; border: 2px solid #0f1a30; position: absolute; bottom: -1px; right: -1px; }
.acc-item .acc-avatar .offline-dot { width: 10px; height: 10px; border-radius: 50%; background: #555; border: 2px solid #0f1a30; position: absolute; bottom: -1px; right: -1px; }
.acc-item .acc-name { flex: 1; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #ccc; min-width: 0; display: flex; align-items: center; gap: 4px; }
.acc-item .acc-unread-badge { background: #25D366; color: #fff; font-size: 9px; font-weight: 700; min-width: 16px; height: 16px; border-radius: 8px; display: inline-flex; align-items: center; justify-content: center; padding: 0 4px; line-height: 1; flex-shrink: 0; }
.acc-item .acc-gear { width: 24px; height: 24px; border-radius: 50%; background: transparent; color: #555; font-size: 13px; border: none; cursor: pointer; display: none; align-items: center; justify-content: center; flex-shrink: 0; }
.acc-item:hover .acc-gear { display: inline-flex; }
.acc-item .acc-gear:hover { color: #e94560; background: rgba(233,69,96,0.15); }
.acc-item.dragging { opacity: 0.3; }
.acc-item.drag-over { background: rgba(233,69,96,0.2); }
.acc-item.sending-disabled .acc-name { opacity: 0.5; }
.sending-toggle { width: 20px; height: 20px; border-radius: 50%; font-size: 11px; cursor: pointer; display: none; align-items: center; justify-content: center; flex-shrink: 0; }
.acc-item:hover .sending-toggle { display: inline-flex; }
.sending-toggle.send-on { color: #4ade80; }
.sending-toggle.send-off { color: #555; }
.acc-action-btn { width: 36px; height: 36px; border: none; border-radius: 50%; background: transparent; color: #888; font-size: 18px; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; transition: all 0.15s; flex-shrink: 0; }
.acc-action-btn:hover { background: rgba(233,69,96,0.15); color: #e94560; }
.acc-action-btn.add-btn { border: 2px dashed #e94560; color: #e94560; font-size: 20px; }
.acc-action-btn.add-btn:hover { background: #e94560; color: #fff; }

/* ── Column 2: Chat List (380px) ── */
.col-chats { width: 380px; background: #16213e; display: flex; flex-direction: column; border-right: 1px solid #0f3460; flex-shrink: 0; }
.chats-nav { display: flex; flex-wrap: wrap; gap: 3px; padding: 6px 8px; border-bottom: 1px solid #0f3460; flex-shrink: 0; }
.chats-nav button { flex: 1 0 auto; padding: 5px 6px; border: none; border-radius: 5px; cursor: pointer; font-size: 11px; background: transparent; color: #888; transition: all 0.15s; min-width: 0; }
.chats-nav button.active { background: #e94560; color: #fff; }
.chats-nav button:hover:not(.active) { background: #1a1a3e; }
.chats-search { padding: 10px 12px; border-bottom: 1px solid #0f3460; flex-shrink: 0; }
.chats-search input { width: 100%; padding: 8px 12px; border: 1px solid #0f3460; border-radius: 8px; background: #1a1a2e; color: #eee; font-size: 13px; outline: none; }
.chats-search input:focus { border-color: #e94560; }
.chats-search input::placeholder { color: #555; }
.chats-list { flex: 1; overflow-y: auto; }
.chat-item-2 { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid #0f3460; display: flex; align-items: center; gap: 12px; transition: background 0.1s; height: 64px; }
.chat-item-2:hover { background: #1a1a3e; }
.chat-item-2.active { background: #0f3460; }
.chat-item-2 .avatar { width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; position: relative; }
.chat-item-2 .avatar img { width: 44px; height: 44px; border-radius: 50%; object-fit: cover; background: #0f3460; display: block; }
.chat-item-2 .avatar .avatar-init { width: 44px; height: 44px; border-radius: 50%; background: #0f3460; display: flex; align-items: center; justify-content: center; font-size: 16px; color: #888; }
.chat-item-2 .info { flex: 1; min-width: 0; display: flex; flex-direction: column; justify-content: center; gap: 2px; }
.chat-item-2 .top-row { display: flex; justify-content: space-between; align-items: center; }
.chat-item-2 .name { font-size: 14px; font-weight: 500; color: #eee; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.chat-item-2 .time { font-size: 11px; color: #666; flex-shrink: 0; }
.chat-item-2 .top-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; margin-left: 8px; }
.chat-item-2 .pin-btn { cursor: pointer; font-size: 12px; opacity: 0; transition: opacity 0.2s; user-select: none; line-height: 1; }

.chat-item-2:hover .pin-btn,
.chat-item-2:hover .del-btn { opacity: 0.4; }

.chat-item-2 .pin-btn:hover,
.chat-item-2 .del-btn:hover { opacity: 1; }

.chat-item-2 .pin-btn.pinned { opacity: 0.7; }

.chat-item-2 .del-btn { cursor: pointer; font-size: 12px; opacity: 0; transition: opacity 0.2s; user-select: none; line-height: 1; margin-left: 4px; }
.chat-item-2 .bottom-row { display: flex; justify-content: space-between; align-items: center; margin-top: 1px; }
.chat-item-2 .preview { font-size: 12px; color: #888; flex: 1; min-width: 0; display: flex; align-items: center; gap: 4px; overflow: hidden; }
.chat-item-2 .preview .preview-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-2 .badge-area { flex-shrink: 0; margin-left: 8px; display: flex; align-items: center; }
.chat-item-2 .unread-badge { background: #25D366; color: #fff; font-size: 10px; font-weight: 700; min-width: 18px; height: 18px; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; padding: 0 4px; line-height: 1; }
.chat-item-2 .pin-icon { font-size: 13px; opacity: 0.5; margin-right: 2px; }

/* ── Column 3: Chat Panel (flex-1) ── */
.col-chat { flex: 1; display: flex; flex-direction: column; background: #1a1a2e; min-width: 0; position: relative; }
.col-chat .empty-state { flex: 1; display: flex; align-items: center; justify-content: center; color: #555; font-size: 15px; flex-direction: column; gap: 8px; }
.col-chat .empty-state .empty-icon { font-size: 48px; opacity: 0.3; }

/* Chat Header */
#chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-header { padding: 12px 20px; background: #16213e; border-bottom: 1px solid #0f3460; display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.chat-header-avatar { width: 40px; height: 40px; border-radius: 50%; background: #0f3460; display: flex; align-items: center; justify-content: center; font-size: 16px; color: #888; flex-shrink: 0; overflow: hidden; position: relative; }
.chat-header-avatar img { position: absolute; inset: 0; width: 40px; height: 40px; border-radius: 50%; object-fit: cover; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-size: 15px; font-weight: 600; }
.chat-header-status { font-size: 11px; color: #888; }

/* Chat Messages */
.chat-messages { flex: 1; overflow-y: auto; padding: 8px 16px; display: flex; flex-direction: column; align-items: center; }
.chat-messages .msg-wrap { display: flex; flex-direction: row; align-items: flex-end; gap: 6px; margin-bottom: 1px; width: 100%; max-width: 680px; }
.chat-messages .msg-wrap.group-start { margin-top: 6px; }
.chat-messages .msg-wrap.group-end { margin-bottom: 4px; }
/* Side avatar slot — always 34px wide to keep incoming bubbles aligned */
.chat-messages .msg-wrap .side-avatar { width: 34px; height: 34px; flex-shrink: 0; border-radius: 50%; overflow: hidden; align-self: flex-end; }
.chat-messages .msg-wrap .side-avatar img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; display: block; }
.chat-messages .msg-wrap .side-avatar.empty { background: transparent; }
.chat-messages .msg-wrap .side-avatar.placeholder { background: #0f3460; display: flex; align-items: center; justify-content: center; font-size: 13px; color: #aaa; }
/* Outgoing wraps: push to the right, no avatar */
.chat-messages .msg-wrap.out-wrap { justify-content: flex-end; }
.chat-messages .msg { max-width: 75%; padding: 6px 12px 3px; border-radius: 10px; font-size: 14px; line-height: 1.45; word-wrap: break-word; position: relative; }
.chat-messages .msg.outgoing { background: linear-gradient(135deg, #056162 0%, #075e54 100%); border-bottom-right-radius: 3px; }
.chat-messages .msg.incoming { background: #1f2c3e; border-bottom-left-radius: 3px; }
.chat-messages .msg.outgoing.tail { border-bottom-right-radius: 10px; }
.chat-messages .msg.incoming.tail { border-bottom-left-radius: 10px; }
.chat-messages .msg .sender { font-size: 12px; color: #e94560; font-weight: 600; margin-bottom: 2px; }
.chat-messages .msg .msg-text { margin-bottom: 2px; white-space: pre-wrap; }
.chat-messages .msg .msg-text a { color: #2AABEE !important; text-decoration: underline !important; }
.chat-messages .msg .msg-footer { display: flex; align-items: center; justify-content: flex-end; gap: 4px; margin-top: 1px; }
.chat-messages .msg .time { font-size: 10px; color: rgba(255,255,255,0.45); }
.chat-messages .msg.outgoing .time { color: rgba(255,255,255,0.6); }
.chat-messages .msg .read-receipt { font-size: 11px; color: #888; }
.chat-messages .msg.outgoing .read-receipt.read { color: #53bdeb; }
.chat-messages .msg .translated-tag { font-size: 10px; color: #e94560; font-style: italic; }
.chat-messages .typing-indicator { display: flex; align-items: center; gap: 4px; padding: 4px 0; }
.chat-messages .typing-indicator .dot { width: 6px; height: 6px; border-radius: 50%; background: #888; animation: typingBounce 1.4s infinite ease-in-out; }
.chat-messages .typing-indicator .dot:nth-child(1) { animation-delay: 0s; }
.chat-messages .typing-indicator .dot:nth-child(2) { animation-delay: 0.2s; }
.chat-messages .typing-indicator .dot:nth-child(3) { animation-delay: 0.4s; }
.chat-messages .typing-indicator .typing-text { font-size: 11px; color: #888; margin-left: 4px; }
@keyframes typingBounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }
.chat-messages .msg .media-img { max-width: 240px; max-height: 240px; border-radius: 6px; display: block; margin: 2px 0 4px; cursor: pointer; }
.chat-messages .msg .sender-avatar { display: none; }
.chat-messages .date-separator { display: flex; justify-content: center; margin: 10px 0; width: 100%; max-width: 680px; }
.chat-messages .date-separator span { background: rgba(15,20,40,0.75); color: rgba(255,255,255,0.75); font-size: 12px; font-weight: 500; padding: 5px 14px; border-radius: 14px; backdrop-filter: blur(4px); }

/* Chat Input */
.chat-input { display: flex; gap: 6px; padding: 10px 16px; background: #16213e; border-top: 1px solid #0f3460; align-items: flex-end; flex-shrink: 0; }
.chat-input textarea { flex: 1; padding: 10px; border: 1px solid #0f3460; border-radius: 8px; resize: none; background: #1a1a2e; color: #eee; font-size: 14px; outline: none; max-height: 80px; font-family: inherit; }
.chat-input textarea:focus { border-color: #e94560; }
.chat-input .action-btn { background: transparent; border: 1px solid #0f3460; border-radius: 8px; color: #888; font-size: 18px; cursor: pointer; padding: 6px 10px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; transition: all 0.15s; flex-shrink: 0; }
.chat-input .action-btn:hover { border-color: #e94560; color: #e94560; }
.chat-input .send-btn { padding: 8px 16px; background: #e94560; color: #fff; border: none; border-radius: 8px; cursor: pointer; font-size: 14px; white-space: nowrap; flex-shrink: 0; }
.chat-input .send-btn:hover { background: #d63850; }
.chat-input #attach-btn, .chat-input #emoji-btn { background: transparent; border: 1px solid #0f3460; font-size: 18px; line-height: 1; padding: 6px 10px; }

/* Emoji picker */
#emoji-picker { display: none; position: absolute; bottom: 72px; right: 16px; background: #16213e; border: 1px solid #0f3460; border-radius: 10px; padding: 8px; width: 320px; max-height: 200px; overflow-y: auto; z-index: 50; flex-wrap: wrap; gap: 2px; }
#emoji-picker.show { display: flex; }
#emoji-picker span { cursor: pointer; font-size: 22px; padding: 4px; border-radius: 4px; width: 36px; text-align: center; }
#emoji-picker span:hover { background: #0f3460; }

/* Bulk view */
#bulk-view { padding: 24px; overflow-y: auto; height: 100%; }
#bulk-view h2 { margin-bottom: 16px; color: #e94560; font-size: 16px; }
.bulk-form { display: flex; flex-direction: column; gap: 10px; max-width: 600px; }
.bulk-form label { font-size: 13px; color: #aaa; }
.bulk-form input, .bulk-form textarea { padding: 10px; border: 1px solid #0f3460; border-radius: 8px; background: #16213e; color: #eee; font-size: 14px; }
.bulk-form input:focus, .bulk-form textarea:focus { outline: none; border-color: #e94560; }
.bulk-form button { padding: 10px 24px; background: #e94560; color: #fff; border: none; border-radius: 8px; cursor: pointer; font-size: 15px; align-self: flex-start; }
.bulk-form button:hover { background: #d63850; }
#bulk-account-select { display: flex; flex-wrap: wrap; gap: 8px; }
#bulk-account-select label { display: flex; align-items: center; gap: 6px; cursor: pointer; font-size: 14px; color: #ddd; background: #16213e; padding: 6px 12px; border-radius: 8px; border: 1px solid #0f3460; }
#bulk-account-select input[type="checkbox"] { accent-color: #e94560; }
#bulk-result { margin-top: 12px; padding: 12px; background: #16213e; border-radius: 8px; white-space: pre-wrap; font-size: 13px; max-height: 300px; overflow-y: auto; }

/* Modal */
.modal { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal-content { background: #16213e; padding: 24px; border-radius: 12px; width: 420px; max-width: 90%; max-height: 85vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-content h2 { margin-bottom: 8px; color: #e94560; }
.modal-content label { font-size: 13px; color: #aaa; }
.modal-content input, .modal-content textarea, .modal-content select { padding: 10px; border: 1px solid #0f3460; border-radius: 8px; background: #1a1a2e; color: #eee; font-size: 14px; }
.modal-content button { padding: 10px; background: #e94560; color: #fff; border: none; border-radius: 8px; cursor: pointer; font-size: 15px; margin-top: 8px; }
.modal-content button:hover { background: #d63850; }
.close { float: right; font-size: 24px; cursor: pointer; color: #888; }
.close:hover { color: #e94560; }

/* Toast notifications */
.toast { position: fixed; top: 16px; right: 16px; background: #16213e; border: 1px solid #e94560; border-radius: 10px; padding: 12px 18px; max-width: 320px; z-index: 200; box-shadow: 0 4px 20px rgba(0,0,0,0.5); animation: slideIn 0.3s ease; cursor: pointer; }
.toast strong { color: #e94560; font-size: 14px; }
.toast span { color: #ccc; font-size: 13px; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* Platform badges */
.plat-badge { display: inline; }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* Settings panel (slide-in) */
#settings-panel { position: fixed; top: 0; right: 0; width: 320px; height: 100vh; background: #16213e; border-left: 1px solid #0f3460; display: flex; flex-direction: column; overflow-y: auto; z-index: 90; box-shadow: -4px 0 20px rgba(0,0,0,0.4); animation: slideInRight 0.2s ease; }
@keyframes slideInRight { from { transform: translateX(100%); } to { transform: translateX(0); } }
.settings-panel-header { display: flex; justify-content: space-between; align-items: center; padding: 16px; border-bottom: 1px solid #0f3460; flex-shrink: 0; }
.settings-panel-header h3 { color: #e94560; font-size: 16px; }
.settings-panel-header .close-btn { background: none; border: none; color: #888; font-size: 22px; cursor: pointer; }
.settings-panel-header .close-btn:hover { color: #e94560; }
.settings-section { border-bottom: 1px solid #0f3460; display: flex; flex-direction: column; width: 100%; }
.settings-section-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; cursor: pointer; color: #e94560; font-size: 14px; font-weight: 600; user-select: none; flex-shrink: 0; }
.settings-section-header:hover { background: rgba(233,69,96,0.08); }
.collapse-icon { font-size: 10px; color: #888; transition: transform 0.2s; }
.collapse-icon.collapsed { transform: rotate(-90deg); }
.settings-section-body { padding: 0 16px 16px; display: flex; flex-direction: column; width: 100%; }
.settings-section-body.collapsed { display: none; }
#settings-account-details { display: flex; flex-direction: column; width: 100%; }
#settings-account-details .detail-row { display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid #0f3460; font-size: 13px; }
#settings-account-details .detail-row .label { color: #888; }
#settings-account-details .detail-row .value { color: #eee; }
.setting-row { margin-bottom: 16px; display: flex; flex-direction: column; width: 100%; }
.setting-row label { font-size: 13px; color: #ddd; display: block; margin-bottom: 4px; }
.setting-row select { width: 100%; padding: 8px; border: 1px solid #0f3460; border-radius: 6px; background: #1a1a2e; color: #eee; font-size: 13px; cursor: pointer; }
.setting-row select:focus { outline: none; border-color: #e94560; }
.setting-hint { font-size: 11px; color: #888; margin-top: 4px; }

/* Auto-reply */
.toggle-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 13px; color: #ddd; }
.toggle-label input[type="checkbox"] { accent-color: #e94560; width: 18px; height: 18px; cursor: pointer; }
#ar-reply-text { width: 100%; padding: 8px; border: 1px solid #0f3460; border-radius: 6px; background: #1a1a2e; color: #eee; font-size: 13px; resize: vertical; font-family: inherit; }
#ar-reply-text:focus { outline: none; border-color: #e94560; }
#ar-keywords { width: 100%; padding: 8px; border: 1px solid #0f3460; border-radius: 6px; background: #1a1a2e; color: #eee; font-size: 13px; }
#ar-keywords:focus { outline: none; border-color: #e94560; }
#ar-cooldown { width: 100%; padding: 8px; border: 1px solid #0f3460; border-radius: 6px; background: #1a1a2e; color: #eee; font-size: 13px; }
#ar-cooldown:focus { outline: none; border-color: #e94560; }
.btn-connect { padding: 8px 20px; background: #e94560; color: #fff; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; }
.btn-connect:hover { background: #d63850; }
.btn-connect:disabled { opacity: 0.5; cursor: not-allowed; }

/* Chat avatars */
.chat-messages .msg .sender-avatar img { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; background: #0f3460; }
.chat-messages .msg .sender-avatar .fallback { width: 20px; height: 20px; border-radius: 50%; background: #0f3460; display: inline-flex; align-items: center; justify-content: center; font-size: 10px; color: #888; }

/* Old classes kept for backward compat */
.chat-item-title { font-size: 14px; }
.chat-item-last { font-size: 12px; color: #888; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.translate-indicator { font-size: 11px; color: #e94560; margin-left: 8px; }

/* Groups view */
#groups-view { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
#target-groups-view { flex: 1; display: flex; flex-direction: column; overflow-y: auto; }
#target-groups-view { flex: 1; display: flex; flex-direction: column; }
#groups-list-view, #group-detail-view { flex: 1; display: flex; flex-direction: column; }
.group-item:hover { border-color: #2AABEE !important; }
#group-accounts-list label { font-size: 13px; display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid #222; }
#group-accounts-list label:last-child { border-bottom: none; }
#create-group-account-select label:hover, #add-to-group-account-select label:hover { background: rgba(42,171,238,0.05); }
#create-group-account-select input[type="checkbox"], #add-to-group-account-select input[type="checkbox"] { accent-color: #2AABEE; }

/* Filter view */
#filter-view { padding: 24px; overflow-y: auto; height: 100%; }
#filter-view h2 { margin-bottom: 16px; color: #e94560; font-size: 16px; }
#filter-view .bulk-form { max-width: 600px; }
#filter-results table { width: 100%; border-collapse: collapse; font-size: 12px; }
#filter-results th { background: #0f3460; padding: 6px; text-align: left; position: sticky; top: 0; }
#filter-results td { padding: 4px 6px; border-bottom: 1px solid #0f3460; }
#filter-results tr:hover { background: rgba(255,255,255,0.03); }

/* Group Settings modal */
.gs-perm-row { display:flex; align-items:center; gap:8px; font-size:13px; color:#ccc; padding:4px 0; border-bottom:1px solid #1a1a2e; cursor:pointer; }
.gs-perm-row:hover { color:#fff; }
.gs-perm-row input { accent-color:#2AABEE; }

/* Media viewer overlay */
#media-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 1000; align-items: center; justify-content: center; cursor: zoom-out; }
#media-overlay .media-full { max-width: 95vw; max-height: 95vh; object-fit: contain; border-radius: 4px; }
#media-overlay .media-close { position: absolute; top: 16px; right: 24px; font-size: 32px; color: #fff; cursor: pointer; font-weight: 700; line-height: 1; }

.msg-avatar-img { width: 20px; height: 20px; border-radius: 50%; object-fit: cover; display: inline-block; vertical-align: middle; background: #16213e; }

/* Message actions (hover buttons) */
.msg-wrap { position: relative; }
.msg-actions { display: none; }
.msg-action-btn { display: none; }

/* Right-click context menu */
#msg-context-menu {
  position: fixed;
  z-index: 9999;
  background: #1e2235;
  border-radius: 14px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.55);
  padding: 6px 0;
  min-width: 200px;
  display: none;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
}
#msg-context-menu.visible { display: flex; }
.msg-ctx-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 11px 18px;
  cursor: pointer;
  font-size: 15px;
  color: #e8e8e8;
  transition: background 0.12s;
}
.msg-ctx-item:hover { background: rgba(255,255,255,0.07); }
.msg-ctx-item.danger { color: #e94560; }
.msg-ctx-item .ctx-icon {
  width: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: inherit;
}
.msg-ctx-item .ctx-icon svg { display: block; }
.msg-ctx-item .ctx-label { flex: 1; font-weight: 400; }
.msg-ctx-divider { height: 1px; background: rgba(255,255,255,0.07); margin: 4px 0; }
.msg-ctx-footer {
  padding: 7px 18px 8px;
  font-size: 11px;
  color: #555;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Reaction picker */
.reaction-picker { position: absolute; right: 0; top: 24px; display: flex; gap: 2px; background: #1a1a2e; border: 1px solid #0f3460; border-radius: 8px; padding: 4px 6px; z-index: 10; box-shadow: 0 4px 12px rgba(0,0,0,0.5); }
.reaction-opt { cursor: pointer; font-size: 18px; padding: 2px 4px; border-radius: 4px; transition: background 0.15s; }
.reaction-opt:hover { background: #0f3460; }

/* Reply preview inside message */
.reply-preview { display: flex; flex-direction: column; background: rgba(42,171,238,0.08); border-left: 3px solid #2AABEE; border-radius: 4px; padding: 4px 8px; margin-bottom: 4px; cursor: pointer; font-size: 12px; }
.reply-title { color: #2AABEE; font-weight: 600; font-size: 11px; }
.reply-text { color: #999; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Inline editing */
.msg-editing { background: rgba(42,171,238,0.1); outline: 2px solid #2AABEE; border-radius: 4px; padding: 2px 4px; min-width: 50px; }

/* Search highlight */
.msg-highlight { outline: 2px solid #facc15; border-radius: 6px; background: rgba(250,204,21,0.08); }

/* ── Mobile back button (hidden on desktop) ── */
#mobile-back-btn { display: none; background: transparent; border: none; color: #eee; font-size: 22px; cursor: pointer; padding: 0 6px 0 0; line-height: 1; flex-shrink: 0; }

/* ── Mobile / Phone responsive layout ── */
@media (max-width: 768px) {
  /* Slim accounts column to icon-strip */
  .col-accounts { width: 54px; }
  .col-accounts-header { font-size: 7px; padding: 8px 2px; letter-spacing: 0; }
  .acc-item { padding: 8px 5px; justify-content: center; gap: 0; }
  .acc-item .acc-name, .acc-item .acc-gear, .acc-item .sending-toggle,
  .col-accounts-footer .footer-actions .acc-action-btn:not(.add-btn) { display: none !important; }
  .col-accounts-footer { padding: 6px 4px; }
  .col-accounts-footer .footer-actions { flex-direction: column; gap: 4px; }
  .acc-action-btn { width: 30px; height: 30px; font-size: 16px; }
  .acc-action-btn.add-btn { font-size: 18px; }

  /* Chat list fills remaining width */
  .col-chats { flex: 1; width: 0; min-width: 0; }
  .chats-nav button { font-size: 10px; padding: 4px 3px; }

  /* Chat view slides in as full-screen overlay */
  .col-chat {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw;
    z-index: 300;
    transform: translateX(100%);
    transition: transform 0.22s ease;
  }
  .col-chat.mobile-open { transform: translateX(0); }

  /* Show back button */
  #mobile-back-btn { display: flex; }

  /* Hide less-essential header buttons on mobile */
  #chat-header > button:not(#mobile-back-btn):not(#search-btn):not(#mute-chat-btn) { display: none; }
  #manage-group-btn { display: none !important; }

  /* Wider message bubbles on small screens */
  .chat-messages { padding: 6px 8px; }
  .chat-messages .msg-wrap { max-width: 100%; }
  .chat-messages .msg { max-width: 85%; }

  /* Message input: ensure it stays above virtual keyboard */
  #message-input-area { position: sticky; bottom: 0; }

  /* Compact input bar — hide non-essential buttons so textarea gets space */
  .chat-input { gap: 4px; padding: 8px 8px; }
  .chat-input #mic-btn,
  .chat-input #emoji-btn { display: none; }
  .chat-input .send-btn { padding: 8px 12px; font-size: 13px; }
  .chat-input textarea { font-size: 15px; }
}
