/* ═══════════════════════════════════════════════════════════════════════════
   THEME TOKENS
   ═══════════════════════════════════════════════════════════════════════════ */
:root {
    --bg-page: #111b21;
    --bg-sidebar: #111b21;
    --bg-sidebar-header: #202c33;
    --bg-chat-area: #0b141a;
    --bg-chat-header: #202c33;
    --bg-composer: #202c33;
    --bg-sent-bubble: #005c4b;
    --bg-received-bubble: #202c33;
    --bg-search: #202c33;
    --bg-input: #2a3942;
    --bg-hover: #2a3942;
    --bg-elevated: #233138;
    --bg-account-bar: #0b141a;
    --bg-account-active: rgba(0,168,132,0.15);
    --accent-primary: #00a884;
    --accent-hover: #06cf9c;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-on-accent: #111b21;
    --text-meta: rgba(233,237,239,0.6);
    --divider: rgba(134,150,160,0.15);
    --icon-color: #aebac1;
    --tick-blue: #53bdeb;
    --chat-pattern-ink: #e9edef;
    --chat-pattern-opacity: 0.04;
    --shadow: 0 1px .5px rgba(11,20,26,.13);
    --scrollbar: rgba(255,255,255,0.16);
    --qr-panel: rgba(32,44,51,0.6);
    --modal-backdrop: rgba(11,20,26,0.8);
    --danger: #ea5455;
    --account-bar-width: 68px;
}

:root[data-theme="light"] {
    --bg-page: #f0f2f5;
    --bg-sidebar: #ffffff;
    --bg-sidebar-header: #f0f2f5;
    --bg-chat-area: #efeae2;
    --bg-chat-header: #f0f2f5;
    --bg-composer: #f0f2f5;
    --bg-sent-bubble: #d9fdd3;
    --bg-received-bubble: #ffffff;
    --bg-search: #f0f2f5;
    --bg-input: #ffffff;
    --bg-hover: #f5f6f6;
    --bg-elevated: #ffffff;
    --bg-account-bar: #e9edef;
    --bg-account-active: rgba(0,168,132,0.18);
    --accent-primary: #00a884;
    --accent-hover: #008f6f;
    --text-primary: #111b21;
    --text-secondary: #667781;
    --text-on-accent: #ffffff;
    --text-meta: rgba(17,27,33,0.5);
    --divider: #e9edef;
    --icon-color: #54656f;
    --tick-blue: #53bdeb;
    --chat-pattern-ink: #111b21;
    --chat-pattern-opacity: 0.05;
    --shadow: 0 1px .5px rgba(11,20,26,.13);
    --scrollbar: rgba(0,0,0,0.2);
    --qr-panel: #ffffff;
    --modal-backdrop: rgba(17,27,33,0.55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; }

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-page);
    color: var(--text-primary);
    overflow: hidden;
    height: 100dvh;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 3px; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(6px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@keyframes pulseBorder { 0% { box-shadow: 0 0 0 0 rgba(0,168,132,0.4); } 70% { box-shadow: 0 0 0 15px rgba(0,168,132,0); } 100% { box-shadow: 0 0 0 0 rgba(0,168,132,0); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes scaleIn { from { transform: scale(0.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes statusPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* Shared */
button { background: none; border: none; cursor: pointer; color: var(--icon-color); font-family: inherit; }
.icon-btn { padding: 8px; border-radius: 50%; display: flex; align-items: center; justify-content: center; transition: background-color 0.2s; flex-shrink: 0; }
.icon-btn:hover { background-color: var(--bg-hover); }
.profile-pic { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background-color: var(--bg-input); flex-shrink: 0; }
.placeholder-avatar {
    background-color: #dfe5e7;
    background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 24 24" fill="%238696a0" xmlns="http://www.w3.org/2000/svg"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 4c1.93 0 3.5 1.57 3.5 3.5S13.93 13 12 13s-3.5-1.57-3.5-3.5S10.07 6 12 6zm0 14c-2.03 0-4.43-.82-6.14-2.88C7.55 15.8 9.68 15 12 15s4.45.8 6.14 2.12C16.43 19.18 14.03 20 12 20z"/></svg>');
    background-size: cover;
}
.placeholder-avatar.group {
    background-image: url('data:image/svg+xml;utf8,<svg viewBox="0 0 24 24" fill="%238696a0" xmlns="http://www.w3.org/2000/svg"><path d="M16 11c1.66 0 2.99-1.34 2.99-3S17.66 5 16 5c-1.66 0-3 1.34-3 3s1.34 3 3 3zm-8 0c1.66 0 2.99-1.34 2.99-3S9.66 5 8 5C6.34 5 5 6.34 5 8s1.34 3 3 3zm0 2c-2.33 0-7 1.17-7 3.5V19h14v-2.5c0-2.33-4.67-3.5-7-3.5zm8 0c-.29 0-.62.02-.97.05 1.16.84 1.97 1.97 1.97 3.45V19h6v-2.5c0-2.33-4.67-3.5-7-3.5z"/></svg>');
    background-size: 70%;
    background-position: center;
    background-repeat: no-repeat;
}
.loading-overlay { position: fixed; inset: 0; background-color: var(--bg-page); display: flex; align-items: center; justify-content: center; z-index: 9999; opacity: 0; pointer-events: none; transition: opacity 0.3s; }
.loading-overlay.active { opacity: 1; pointer-events: auto; }
.spinner { width: 40px; height: 40px; border: 3px solid rgba(0,168,132,0.2); border-top-color: var(--accent-primary); border-radius: 50%; animation: spin 1s linear infinite; }

#app { width: 100%; height: 100%; display: flex; position: relative; }

/* ═══════════════════════════════════════════════════════════════════════════
   ACCOUNT BAR
   ═══════════════════════════════════════════════════════════════════════════ */
.account-bar {
    width: var(--account-bar-width);
    flex-shrink: 0;
    background-color: var(--bg-account-bar);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 0;
    border-right: 1px solid var(--divider);
    height: 100%;
    gap: 4px;
    z-index: 20;
}
.add-account-btn { width: 44px; height: 44px; border-radius: 50%; display: flex; align-items: center; justify-content: center; background-color: var(--accent-primary); color: var(--text-on-accent); transition: transform 0.2s, background-color 0.2s; margin-bottom: 8px; flex-shrink: 0; }
.add-account-btn:hover { background-color: var(--accent-hover); transform: scale(1.08); }
.account-list { display: flex; flex-direction: column; align-items: center; gap: 8px; overflow-y: auto; flex: 1; width: 100%; padding: 4px 0; }
.account-item { position: relative; width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; cursor: pointer; transition: background-color 0.2s; flex-shrink: 0; }
.account-item:hover { background-color: var(--bg-account-active); }
.account-item.active { background-color: var(--bg-account-active); box-shadow: 0 0 0 2px var(--accent-primary); }
.account-avatar { width: 42px; height: 42px; border-radius: 50%; background-color: var(--bg-sidebar-header); color: var(--text-primary); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 15px; }
.account-status-dot { position: absolute; bottom: 2px; right: 2px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--bg-account-bar); }
.account-status-dot.open { background-color: var(--accent-primary); }
.account-status-dot.connecting { background-color: #f59e0b; animation: statusPulse 1.5s infinite; }
.account-status-dot.close { background-color: var(--danger); }
.account-unread { position: absolute; top: -2px; right: -4px; background-color: var(--accent-primary); color: var(--text-on-accent); font-size: 10px; font-weight: 600; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: flex; align-items: center; justify-content: center; border: 2px solid var(--bg-account-bar); }

/* ═══════════════════════════════════════════════════════════════════════════
   QR
   ═══════════════════════════════════════════════════════════════════════════ */
.qr-modal { position: fixed; inset: 0; z-index: 5000; display: none; align-items: center; justify-content: center; }
.qr-modal.active { display: flex; animation: fadeIn 0.2s ease; }
.qr-modal-backdrop { position: absolute; inset: 0; background: var(--modal-backdrop); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.qr-modal-content { position: relative; background: var(--bg-elevated); border-radius: 16px; padding: 40px; box-shadow: 0 25px 60px rgba(0,0,0,0.4); animation: scaleIn 0.3s ease; display: flex; flex-direction: column; align-items: center; max-width: 400px; width: 90%; }
.qr-modal-close { position: absolute; top: 12px; right: 12px; padding: 8px; border-radius: 50%; }
.qr-modal-close:hover { background-color: var(--bg-hover); }
.qr-modal-header { text-align: center; margin-bottom: 24px; }
.qr-modal-header h2 { font-size: 20px; font-weight: 500; margin-bottom: 8px; }
.qr-modal-header p { color: var(--text-secondary); font-size: 14px; }

.qr-screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; background-color: var(--bg-page); z-index: 1000; overflow-y: auto; padding: 16px; }
.qr-screen.active { display: flex; animation: fadeIn 0.5s ease; }
.qr-container { display: flex; max-width: 1000px; width: 100%; background: var(--qr-panel); border-radius: 12px; padding: 64px; box-shadow: 0 17px 50px 0 rgba(11,20,26,.19), 0 12px 15px 0 rgba(11,20,26,.24); gap: 60px; align-items: flex-start; }
.qr-header h2 { font-size: 28px; font-weight: 300; margin-bottom: 32px; }
.qr-header p { font-size: 18px; margin-bottom: 24px; color: var(--text-secondary); }
.qr-header ol { padding-left: 20px; color: var(--text-secondary); line-height: 2.2; font-size: 16px; }
.qr-header li strong { color: var(--text-primary); font-weight: 500; }
.qr-header svg { vertical-align: middle; color: var(--text-secondary); }
.qr-card { position: relative; padding: 16px; background: white; border-radius: 8px; display: flex; flex-direction: column; align-items: center; flex-shrink: 0; }
.qr-border-animated { position: absolute; inset: 0; border: 2px solid var(--accent-primary); border-radius: 8px; animation: pulseBorder 2s infinite; }
.qr-card img { width: 264px; height: 264px; display: block; position: relative; z-index: 1; }
.qr-status { margin-top: 16px; color: #111b21; font-weight: 500; font-size: 14px; text-align: center; }

/* ═══════════════════════════════════════════════════════════════════════════
   CHAT SCREEN
   ═══════════════════════════════════════════════════════════════════════════ */
.chat-screen { display: none; width: 100%; height: 100%; }
.chat-screen.active { display: flex; animation: fadeIn 0.3s ease; }

/* Sidebar */
.sidebar { width: 400px; min-width: 300px; flex-shrink: 0; display: flex; flex-direction: column; background-color: var(--bg-sidebar); border-right: 1px solid var(--divider); height: 100%; z-index: 10; }
.sidebar-header { height: 59px; padding: 10px 16px; background-color: var(--bg-sidebar-header); display: flex; align-items: center; justify-content: space-between; flex-shrink: 0; }
.sidebar-header-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.sidebar-phone { font-size: 13px; color: var(--text-secondary); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-actions { display: flex; gap: 4px; }
:root[data-theme="light"] .icon-moon, :root:not([data-theme="light"]) .icon-sun { display: none; }

.search-container { padding: 8px 12px; border-bottom: 1px solid var(--divider); flex-shrink: 0; }
.search-bar { display: flex; align-items: center; background-color: var(--bg-search); border-radius: 8px; height: 36px; padding: 0 8px; }
.search-bar input { background: transparent; border: none; color: var(--text-primary); width: 100%; padding-left: 8px; font-size: 15px; outline: none; font-family: inherit; }
.search-bar input::placeholder { color: var(--text-secondary); }

.chat-list { flex: 1; overflow-y: auto; }
.chat-list-empty { padding: 40px 24px; text-align: center; color: var(--text-secondary); font-size: 14px; line-height: 1.5; }
.chat-item { display: flex; align-items: center; padding: 0 12px; height: 72px; cursor: pointer; transition: background-color 0.15s; }
.chat-item:hover { background-color: var(--bg-hover); }
.chat-item.active { background-color: var(--bg-sidebar-header); }
.chat-item-avatar { margin-right: 14px; }
.chat-item-avatar .profile-pic { width: 49px; height: 49px; }
.chat-item-content { flex: 1; display: flex; flex-direction: column; justify-content: center; height: 100%; border-bottom: 1px solid var(--divider); padding-right: 4px; min-width: 0; }
.chat-item:last-child .chat-item-content { border-bottom: none; }
.chat-item-top { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 3px; gap: 8px; }
.chat-item-name { font-size: 16px; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 12px; color: var(--text-secondary); flex-shrink: 0; }
.chat-item-time.unread { color: var(--accent-primary); }
.chat-item-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.chat-item-message { font-size: 14px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.unread-badge { background-color: var(--accent-primary); color: var(--text-on-accent); border-radius: 10px; padding: 0 6px; min-width: 20px; height: 20px; font-size: 12px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
.start-chat-item .chat-item-name { color: var(--accent-primary); }

/* Main chat */
.main-chat { flex: 1; min-width: 0; position: relative; display: flex; flex-direction: column; background-color: var(--bg-chat-area); height: 100%; }
.no-chat-placeholder { display: none; flex-direction: column; align-items: center; justify-content: center; height: 100%; text-align: center; padding: 20px; background-color: var(--bg-sidebar-header); border-bottom: 6px solid var(--accent-primary); }
.no-chat-placeholder.active { display: flex; }
.placeholder-content h2 { font-size: 32px; font-weight: 300; margin: 28px 0 16px; }
.placeholder-content p { color: var(--text-secondary); margin-bottom: 10px; font-size: 14px; max-width: 400px; line-height: 1.4; }
.end-to-end { margin-top: 32px; display: flex; align-items: center; justify-content: center; gap: 4px; color: var(--text-secondary); font-size: 12px; }

.active-chat { display: none; flex-direction: column; height: 100%; width: 100%; position: relative; }
.active-chat.active { display: flex; }
.chat-header { height: 59px; padding: 8px 16px 8px 8px; background-color: var(--bg-chat-header); display: flex; align-items: center; z-index: 10; flex-shrink: 0; gap: 4px; }
.back-btn { display: none; }
.chat-header-info { flex: 1; display: flex; align-items: center; gap: 12px; min-width: 0; padding: 4px 8px; border-radius: 8px; text-align: left; color: inherit; }
.chat-header-info:hover { background-color: var(--bg-hover); }
.chat-info { flex: 1; display: flex; flex-direction: column; justify-content: center; min-width: 0; }
.chat-name { font-size: 16px; font-weight: 500; margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 8% 8px;
    background-color: var(--bg-chat-area);
    background-image: url('data:image/svg+xml;utf8,<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg"><path d="M10 10l80 80M90 10L10 90" stroke="%23888" stroke-width="2" opacity="0.08"/></svg>');
    display: flex;
    flex-direction: column;
}
.messages-empty { display: flex; align-items: center; justify-content: center; padding: 40px; color: var(--text-secondary); font-size: 14px; }
.date-divider { align-self: center; background-color: var(--bg-elevated); color: var(--text-secondary); font-size: 12px; padding: 6px 12px; border-radius: 8px; margin: 12px 0; box-shadow: var(--shadow); }
.load-more-btn { align-self: center; margin: 8px auto 12px; padding: 6px 14px; border-radius: 16px; background-color: var(--bg-elevated); color: var(--text-secondary); font-size: 12.5px; cursor: pointer; border: none; box-shadow: var(--shadow); }
.load-more-btn:hover { color: var(--text-primary); }
.load-more-btn:disabled { opacity: 0.6; cursor: default; }

.message-row { display: flex; margin-bottom: 4px; width: 100%; }
.message-row.first { margin-top: 8px; }
.message-row.sent { justify-content: flex-end; }
.message-row.received { justify-content: flex-start; }
.message-bubble { max-width: min(65%, 560px); min-width: 80px; padding: 6px 8px 7px 9px; border-radius: 8px; position: relative; font-size: 14.2px; line-height: 19px; box-shadow: var(--shadow); animation: slideUp 0.15s ease; display: flex; flex-direction: column; word-break: break-word; }
.message-row.sent .message-bubble { background-color: var(--bg-sent-bubble); }
.message-row.received .message-bubble { background-color: var(--bg-received-bubble); }
.message-row.first.sent .message-bubble { border-top-right-radius: 0; }
.message-row.first.received .message-bubble { border-top-left-radius: 0; }
.message-row.first .message-bubble::before { content: ''; position: absolute; top: 0; width: 8px; height: 13px; }
.message-row.first.sent .message-bubble::before { right: -8px; background: radial-gradient(circle at 100% 100%, transparent 8px, var(--bg-sent-bubble) 8px); }
.message-row.first.received .message-bubble::before { left: -8px; background: radial-gradient(circle at 0 100%, transparent 8px, var(--bg-received-bubble) 8px); }
.message-text { white-space: pre-wrap; }
.message-text a { color: var(--accent-primary); }
.message-meta { display: flex; align-items: center; justify-content: flex-end; gap: 3px; margin-top: 2px; margin-bottom: -3px; float: right; margin-left: 12px; line-height: 1; }
.message-time { font-size: 11px; color: var(--text-meta); }
.message-status { color: var(--text-meta); display: flex; }
.message-status.read { color: var(--tick-blue); }
.message-status.failed { color: var(--danger); }
.message-pushname { font-size: 12.8px; font-weight: 500; margin-bottom: 3px; }

/* Media inside bubbles */
.message-bubble.has-media { padding: 4px; }
.message-bubble.has-media .message-text { padding: 4px 6px 0; }
.message-bubble.has-media .message-meta { padding-right: 4px; padding-bottom: 2px; }
.media-image, .media-sticker { display: block; border-radius: 6px; cursor: pointer; background-color: rgba(0,0,0,0.1); }
.media-image { max-width: 100%; width: 330px; max-height: 400px; object-fit: cover; }
.media-sticker { width: 160px; height: 160px; object-fit: contain; background: transparent; cursor: default; }
.media-video { display: block; max-width: 100%; width: 330px; max-height: 400px; border-radius: 6px; background: #000; }
.media-audio { width: 280px; max-width: 100%; height: 40px; margin: 6px 4px; display: block; }
.media-doc { display: flex; align-items: center; gap: 10px; padding: 10px 8px; min-width: 240px; border-radius: 6px; background-color: rgba(0,0,0,0.08); color: inherit; text-decoration: none; }
.media-doc:hover { background-color: rgba(0,0,0,0.14); }
.media-doc-icon { width: 34px; height: 34px; flex-shrink: 0; color: var(--text-secondary); }
.media-doc-info { min-width: 0; flex: 1; }
.media-doc-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.media-doc-size { font-size: 11px; color: var(--text-secondary); }
.media-doc-dl { color: var(--text-secondary); flex-shrink: 0; }
.media-broken { padding: 14px; font-size: 13px; color: var(--text-secondary); font-style: italic; }
.media-placeholder { font-size: 14px; color: var(--text-secondary); font-style: italic; }

/* Composer */
.attach-preview { display: none; gap: 8px; padding: 8px 16px; background-color: var(--bg-composer); border-top: 1px solid var(--divider); overflow-x: auto; flex-shrink: 0; }
.attach-preview.active { display: flex; }
.attach-item { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; background-color: var(--bg-input); flex-shrink: 0; display: flex; align-items: center; justify-content: center; }
.attach-item img { width: 100%; height: 100%; object-fit: cover; }
.attach-item .attach-file { font-size: 10px; color: var(--text-secondary); text-align: center; padding: 4px; word-break: break-all; line-height: 1.2; }
.attach-item .attach-remove { position: absolute; top: 2px; right: 2px; width: 18px; height: 18px; border-radius: 50%; background: rgba(0,0,0,0.6); color: #fff; font-size: 12px; display: flex; align-items: center; justify-content: center; }
.attach-item.uploading::after { content: ''; position: absolute; inset: 0; background: rgba(0,0,0,0.45) url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%23fff" stroke-width="2"><circle cx="12" cy="12" r="9" opacity=".3"/><path d="M21 12a9 9 0 0 0-9-9"/></svg>') center/24px no-repeat; animation: spin 1s linear infinite; }
.drop-hint { display: none; position: absolute; inset: 0; z-index: 30; align-items: center; justify-content: center; font-size: 22px; font-weight: 500; color: var(--accent-primary); background: var(--modal-backdrop); border: 3px dashed var(--accent-primary); pointer-events: none; }
.active-chat.dragging .drop-hint { display: flex; }

.chat-footer { min-height: 62px; padding: 8px 12px; background-color: var(--bg-composer); display: flex; align-items: flex-end; gap: 4px; z-index: 10; flex-shrink: 0; }
.chat-footer .icon-btn { margin-bottom: 3px; }
.message-input-container { flex: 1; background-color: var(--bg-input); border-radius: 8px; padding: 9px 12px; display: flex; min-width: 0; }
#message-input { width: 100%; background: transparent; border: none; color: var(--text-primary); font-size: 15px; outline: none; resize: none; font-family: inherit; line-height: 20px; max-height: 120px; }
#message-input::placeholder { color: var(--text-secondary); }
.send-btn { color: var(--text-secondary); transition: color 0.2s; }
.send-btn.active { color: var(--accent-primary); }

/* Info panel (group participants / contact) */
.info-panel { position: fixed; inset: 0; z-index: 4000; display: none; }
.info-panel.active { display: block; }
.info-panel-backdrop { position: absolute; inset: 0; background: var(--modal-backdrop); }
.info-panel-content { position: absolute; top: 0; right: 0; bottom: 0; width: 400px; max-width: 100%; background-color: var(--bg-sidebar); display: flex; flex-direction: column; box-shadow: -4px 0 24px rgba(0,0,0,0.3); animation: fadeIn 0.2s ease; }
.info-panel-header { height: 59px; display: flex; align-items: center; gap: 12px; padding: 0 12px; background-color: var(--bg-sidebar-header); font-size: 16px; font-weight: 500; flex-shrink: 0; }
.info-panel-body { flex: 1; overflow-y: auto; }
.info-hero { display: flex; flex-direction: column; align-items: center; padding: 28px 16px 20px; gap: 12px; border-bottom: 8px solid var(--bg-page); }
.info-hero .profile-pic { width: 120px; height: 120px; }
.info-hero h3 { font-size: 22px; font-weight: 400; text-align: center; }
.info-hero p { color: var(--text-secondary); font-size: 14px; text-align: center; white-space: pre-wrap; }
.info-section-title { padding: 14px 20px 6px; font-size: 14px; color: var(--text-secondary); }
.info-participant { display: flex; align-items: center; gap: 12px; padding: 8px 20px; }
.info-participant-name { flex: 1; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.info-participant-admin { font-size: 11px; color: var(--accent-primary); border: 1px solid var(--accent-primary); border-radius: 4px; padding: 1px 5px; }
.info-participant-sub { font-size: 12px; color: var(--text-secondary); }

/* Lightbox */
.lightbox { position: fixed; inset: 0; z-index: 6000; background: rgba(0,0,0,0.92); display: none; align-items: center; justify-content: center; }
.lightbox.active { display: flex; animation: fadeIn 0.15s ease; }
.lightbox img { max-width: 95vw; max-height: 90vh; object-fit: contain; }
.lightbox-close { position: absolute; top: 12px; right: 16px; color: #fff; }
.lightbox-close:hover { background: rgba(255,255,255,0.15); }
.lightbox-download { position: absolute; top: 20px; left: 20px; color: #fff; font-size: 14px; text-decoration: none; background: rgba(255,255,255,0.15); padding: 6px 12px; border-radius: 6px; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background-color: var(--bg-elevated); color: var(--text-primary); padding: 10px 18px; border-radius: 8px; font-size: 14px; box-shadow: 0 4px 16px rgba(0,0,0,0.4); opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s; z-index: 10000; max-width: 90vw; text-align: center; }
.toast.active { opacity: 1; transform: translate(-50%, 0); }

/* ═══════════════════════════════════════════════════════════════════════════
   RESPONSIVE
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 1100px) {
    .sidebar { width: 340px; }
    .messages-container { padding-left: 5%; padding-right: 5%; }
}

@media (max-width: 768px) {
    :root { --account-bar-width: 56px; }
    .qr-screen { align-items: flex-start; }
    .qr-container { flex-direction: column; padding: 28px 20px; align-items: center; text-align: center; gap: 28px; }
    .qr-header h2 { font-size: 22px; margin-bottom: 16px; }
    .qr-header p { font-size: 15px; margin-bottom: 12px; }
    .qr-header ol { text-align: left; font-size: 14px; line-height: 1.8; }
    .qr-card img { width: 220px; height: 220px; }

    .account-avatar { width: 38px; height: 38px; font-size: 13px; }
    .account-item { width: 42px; height: 42px; }
    .add-account-btn { width: 38px; height: 38px; }

    /* sidebar and chat stack on top of each other, to the right of the account bar */
    .chat-screen { position: relative; }
    .sidebar { width: auto; min-width: 0; position: absolute; top: 0; left: var(--account-bar-width); right: 0; bottom: 0; transition: transform 0.25s ease; border-right: none; }
    .main-chat { position: absolute; top: 0; left: var(--account-bar-width); right: 0; bottom: 0; transform: translateX(105%); transition: transform 0.25s ease; }
    .chat-screen.show-chat .sidebar { transform: translateX(-30%); }
    .chat-screen.show-chat .main-chat { transform: translateX(0); }
    .chat-screen.show-chat .account-bar { display: none; }
    .chat-screen.show-chat .main-chat { left: 0; }

    .back-btn { display: flex; }
    .no-chat-placeholder { display: none !important; }
    .chat-header { padding: 6px 8px 6px 4px; }
    .chat-header-info { gap: 10px; }
    .messages-container { padding: 8px 12px 6px; }
    .message-bubble { max-width: 85%; }
    .media-image, .media-video { width: 260px; }
    .media-audio { width: 220px; }
    .media-doc { min-width: 200px; }
    .chat-footer { padding: 6px 6px; }
    .info-panel-content { width: 100%; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   REPLIES, REACTIONS, EMOJI, MENUS, MODALS
   ═══════════════════════════════════════════════════════════════════════════ */

/* Quoted message inside a bubble */
.quoted { display: flex; flex-direction: column; gap: 1px; padding: 5px 8px; margin-bottom: 4px; border-left: 4px solid var(--accent-primary); border-radius: 5px; background: rgba(0,0,0,0.12); cursor: pointer; }
:root[data-theme="light"] .quoted { background: rgba(0,0,0,0.05); }
.quoted-name { font-size: 12.5px; font-weight: 500; color: var(--accent-primary); }
.quoted-text { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.message-row.highlight .message-bubble { animation: flashBubble 1.2s ease; }
@keyframes flashBubble { 0%, 60% { box-shadow: 0 0 0 3px var(--accent-primary); } 100% { box-shadow: var(--shadow); } }

/* Deleted placeholder */
.message-deleted { font-style: italic; color: var(--text-secondary); display: flex; align-items: center; gap: 5px; }

/* Reactions */
.reactions { position: absolute; bottom: -12px; display: flex; gap: 2px; background: var(--bg-elevated); border-radius: 12px; padding: 1px 5px; box-shadow: var(--shadow); font-size: 12px; line-height: 16px; white-space: nowrap; cursor: pointer; }
.message-row.sent .reactions { right: 8px; }
.message-row.received .reactions { left: 8px; }
.reactions .count { font-size: 11px; color: var(--text-secondary); margin-left: 1px; }
.message-row:has(.reactions) { margin-bottom: 16px; }

/* Hover actions on a bubble */
.bubble-actions { position: absolute; top: 2px; right: 2px; display: flex; gap: 2px; opacity: 0.45; transition: opacity 0.15s; }
.message-bubble:hover .bubble-actions { opacity: 1; }
.bubble-actions button { width: 24px; height: 24px; border-radius: 50%; background: var(--bg-elevated); color: var(--text-secondary); display: flex; align-items: center; justify-content: center; font-size: 14px; line-height: 1; box-shadow: var(--shadow); }
.bubble-actions button:hover { color: var(--text-primary); }
.message-bubble { padding-right: 30px; }
.message-bubble.has-media { padding-right: 4px; }

/* Context menu */
.msg-menu { position: fixed; z-index: 7000; display: none; flex-direction: column; min-width: 190px; background: var(--bg-elevated); border-radius: 8px; padding: 6px 0; box-shadow: 0 8px 28px rgba(0,0,0,0.35); }
.msg-menu.active { display: flex; }
.msg-menu button { padding: 10px 18px; text-align: left; font-size: 14.5px; color: var(--text-primary); width: 100%; }
.msg-menu button:hover { background: var(--bg-hover); }
.msg-menu button.danger { color: var(--danger); }
.msg-menu .menu-reactions { display: flex; gap: 4px; padding: 6px 10px 8px; border-bottom: 1px solid var(--divider); margin-bottom: 4px; }
.msg-menu .menu-reactions button { width: 34px; height: 34px; padding: 0; border-radius: 50%; font-size: 19px; display: flex; align-items: center; justify-content: center; }

/* Emoji picker */
.emoji-picker { display: none; flex-direction: column; height: 260px; background: var(--bg-composer); border-top: 1px solid var(--divider); flex-shrink: 0; }
.emoji-picker.active { display: flex; }
.emoji-tabs { display: flex; gap: 2px; padding: 6px 10px; border-bottom: 1px solid var(--divider); overflow-x: auto; }
.emoji-tabs button { padding: 4px 8px; border-radius: 6px; font-size: 17px; opacity: 0.6; }
.emoji-tabs button.active { opacity: 1; background: var(--bg-hover); }
.emoji-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr)); gap: 2px; padding: 8px 10px; }
.emoji-grid button { height: 36px; border-radius: 6px; font-size: 22px; line-height: 1; }
.emoji-grid button:hover { background: var(--bg-hover); }

/* Reply bar above the composer */
.reply-bar { display: none; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg-composer); border-top: 1px solid var(--divider); flex-shrink: 0; }
.reply-bar.active { display: flex; }
.reply-bar-body { flex: 1; min-width: 0; border-left: 4px solid var(--accent-primary); padding: 2px 8px; background: rgba(0,0,0,0.12); border-radius: 5px; }
:root[data-theme="light"] .reply-bar-body { background: rgba(0,0,0,0.04); }
.reply-bar-name { font-size: 13px; font-weight: 500; color: var(--accent-primary); }
.reply-bar-text { font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Generic modal (new group, add participants, join) */
.modal { position: fixed; inset: 0; z-index: 5500; display: none; align-items: center; justify-content: center; }
.modal.active { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: var(--modal-backdrop); }
.modal-content { position: relative; width: 460px; max-width: 94vw; max-height: 86vh; background: var(--bg-sidebar); border-radius: 12px; display: flex; flex-direction: column; box-shadow: 0 25px 60px rgba(0,0,0,0.4); animation: scaleIn 0.2s ease; overflow: hidden; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; background: var(--bg-sidebar-header); }
.modal-header h2 { font-size: 17px; font-weight: 500; }
.modal-body { flex: 1; overflow-y: auto; padding: 12px 0; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--divider); }
.modal-input { width: calc(100% - 32px); margin: 4px 16px 12px; padding: 10px 12px; border-radius: 8px; border: 1px solid var(--divider); background: var(--bg-input); color: var(--text-primary); font-size: 15px; font-family: inherit; outline: none; }
.modal-input:focus { border-color: var(--accent-primary); }
.modal-hint { padding: 0 16px 10px; font-size: 13px; color: var(--text-secondary); }
.btn { padding: 9px 18px; border-radius: 8px; font-size: 14.5px; font-weight: 500; }
.btn-primary { background: var(--accent-primary); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: default; }
.btn-ghost { color: var(--text-secondary); }
.btn-ghost:hover { background: var(--bg-hover); }
.picker-row { display: flex; align-items: center; gap: 12px; padding: 8px 16px; cursor: pointer; }
.picker-row:hover { background: var(--bg-hover); }
.picker-row input { width: 18px; height: 18px; accent-color: var(--accent-primary); }
.picker-name { flex: 1; min-width: 0; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-sub { font-size: 12px; color: var(--text-secondary); }
.picker-empty { padding: 24px 16px; text-align: center; color: var(--text-secondary); font-size: 14px; }

/* Info panel extras */
.info-actions { display: flex; flex-direction: column; border-top: 8px solid var(--bg-page); }
.info-action { padding: 13px 20px; text-align: left; font-size: 15px; color: var(--text-primary); width: 100%; }
.info-action:hover { background: var(--bg-hover); }
.info-action.danger { color: var(--danger); }
.info-invite { margin: 8px 20px 14px; padding: 10px; border-radius: 8px; background: var(--bg-input); font-size: 12.5px; word-break: break-all; color: var(--text-secondary); }
.info-participant { cursor: pointer; }
.info-participant:hover { background: var(--bg-hover); }

@media (max-width: 768px) {
    .emoji-picker { height: 220px; }
    .quoted-text { max-width: 180px; }
    .modal-content { width: 100%; max-height: 92vh; border-radius: 12px 12px 0 0; align-self: flex-end; }
    .modal { align-items: flex-end; }
    .bubble-actions { display: flex; }
}
.system-notice { max-width: 80%; text-align: center; line-height: 1.4; }

/* ═══════════════════════════════════════════════════════════════════════════
   SETTINGS
   ═══════════════════════════════════════════════════════════════════════════ */
.settings-section { border-bottom: 8px solid var(--bg-page); padding-bottom: 6px; }
.settings-section:last-child { border-bottom: none; }
.settings-title { padding: 16px 20px 8px; font-size: 14px; color: var(--accent-primary); font-weight: 500; }
.settings-empty, .settings-note { padding: 4px 20px 14px; font-size: 13px; color: var(--text-secondary); line-height: 1.5; }
.settings-value { color: var(--text-secondary); font-size: 13px; margin-left: 6px; }
.settings-account { display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 20px; }
.settings-account.active { background: var(--bg-hover); }
.account-avatar.small { width: 38px; height: 38px; font-size: 13px; }
.settings-account-info { flex: 1; min-width: 0; }
.settings-account-name { font-size: 15px; display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.settings-account-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.settings-account-name .tag { font-size: 10.5px; text-transform: uppercase; letter-spacing: .04em; color: var(--accent-primary); border: 1px solid var(--accent-primary); border-radius: 4px; padding: 0 4px; }
.settings-account-sub { font-size: 12.5px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.account-status-dot.inline { position: static; width: 8px; height: 8px; border: none; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn.danger { color: var(--danger); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.08); }
.settings-confirm { margin: 0 20px 14px; padding: 14px; border-radius: 10px; background: var(--bg-input); border: 1px solid var(--danger); }
.settings-confirm p { font-size: 13.5px; line-height: 1.5; color: var(--text-secondary); margin-bottom: 8px; }
.settings-confirm p strong { color: var(--text-primary); font-size: 15px; }
.settings-confirm-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ═══════════════════════════════════════════════════════════════════════════
   SIGN IN / SETUP
   ═══════════════════════════════════════════════════════════════════════════ */
.auth-screen { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; background: var(--bg-page); }
.auth-card { width: 100%; max-width: 380px; background: var(--bg-sidebar); border-radius: 14px; padding: 32px 28px; box-shadow: 0 18px 50px rgba(0,0,0,.28); display: flex; flex-direction: column; }
.auth-card h1 { font-size: 23px; font-weight: 500; margin-bottom: 4px; }
.auth-sub { color: var(--text-secondary); font-size: 14px; margin-bottom: 22px; }
.auth-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--text-secondary); margin-bottom: 14px; }
.auth-card input { padding: 11px 12px; border-radius: 8px; border: 1px solid var(--divider); background: var(--bg-input); color: var(--text-primary); font-size: 15px; font-family: inherit; outline: none; }
.auth-card input:focus { border-color: var(--accent-primary); }
.auth-submit { width: 100%; margin-top: 6px; padding: 12px; }
.auth-error { background: rgba(234,84,85,.12); border: 1px solid var(--danger); color: var(--danger); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; margin-bottom: 12px; }
.auth-note { color: var(--text-secondary); font-size: 12.5px; margin-top: 14px; text-align: center; }
