/* TrendTalk v2 — themes, compact layout, Spark-style contacts, chat, calls */

/* ───────── themes (set on <html data-theme="…">) ───────── */
:root, :root[data-theme="light"] {
  --brand: #0e2a47;          /* deep navy */
  --accent: #f07c1e;         /* orange */
  --accent-ink: #fff;
  --accent-soft: rgba(240, 124, 30, .14);
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #17212e;
  --muted: #66758a;
  --line: #e2e7ee;
  --bubble-me: #0e4a80;
  --bubble-me-ink: #ffffff;
  --bubble-them: #ffffff;
  --hover: #eef2f7;
  --active: #e3ecf7;
  --group-ink: #1f5fa8;
  --danger: #c62828;
  --ok: #22a85a;
  --away: #f5a623;
  --busy: #e53935;
  --off: #c5ccd6;
  --tick-read: #1e88e5;
  --shadow: 0 10px 30px rgba(14, 42, 71, .16);
  --login-bg: radial-gradient(1200px 600px at 10% -10%, #1d4b7a 0, transparent 60%), #0e2a47;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --brand: #0b1622; --accent: #ff8a2b; --accent-soft: rgba(255, 138, 43, .16);
  --bg: #0d141d; --panel: #141e2a; --panel-2: #111a25; --ink: #e6ecf3; --muted: #8fa0b5; --line: #243244;
  --bubble-me: #1f6fb8; --bubble-them: #1c2836; --hover: #1a2533; --active: #1f3048; --group-ink: #7fb4ff;
  --off: #4a5869; --tick-read: #64b5f6; --shadow: 0 10px 30px rgba(0, 0, 0, .5);
  --login-bg: radial-gradient(1200px 600px at 10% -10%, #1b2c44 0, transparent 60%), #070d15;
  color-scheme: dark;
}
:root[data-theme="purple"] {
  --brand: #3b1a6b; --accent: #8b5cf6; --accent-soft: rgba(139, 92, 246, .15);
  --bg: #f5f3fb; --panel-2: #faf8ff; --line: #e6e1f3; --bubble-me: #6d28d9; --hover: #f0ebfb; --active: #e7defa;
  --group-ink: #6d28d9; --tick-read: #a78bfa;
  --login-bg: radial-gradient(1200px 600px at 10% -10%, #6d3fc0 0, transparent 60%), #2a1250;
}
:root[data-theme="green"] {
  --brand: #1f3d12; --accent: #6aa526; --accent-soft: rgba(106, 165, 38, .16);
  --bg: #f3f7f0; --panel-2: #f9fcf6; --line: #dfe9d6; --bubble-me: #3f7d20; --hover: #ecf4e5; --active: #dfeed2;
  --group-ink: #3f7d20; --tick-read: #8bc34a;
  --login-bg: radial-gradient(1200px 600px at 10% -10%, #4c8a2a 0, transparent 60%), #1c3810;
}
:root[data-theme="red"] {
  --brand: #5a1016; --accent: #d32f2f; --accent-soft: rgba(211, 47, 47, .13);
  --bg: #faf4f4; --panel-2: #fffafa; --line: #f0dfdf; --bubble-me: #b71c1c; --hover: #f8ecec; --active: #f5dddd;
  --group-ink: #b71c1c; --tick-read: #ef9a9a;
  --login-bg: radial-gradient(1200px 600px at 10% -10%, #a52a2a 0, transparent 60%), #3d0b0f;
}
:root[data-theme="ocean"] {
  --brand: #063c4c; --accent: #00a3bf; --accent-soft: rgba(0, 163, 191, .15);
  --bg: #eff7f9; --panel-2: #f7fcfd; --line: #d7e8ee; --bubble-me: #00708a; --hover: #e5f2f6; --active: #d4ebf2;
  --group-ink: #00708a; --tick-read: #4dd0e1;
  --login-bg: radial-gradient(1200px 600px at 10% -10%, #0b7891 0, transparent 60%), #052f3c;
}

/* ───────── base ───────── */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { font-size: calc(13.5px * var(--font-scale, 1)); }
body { font: 1rem/1.4 "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--group-ink); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .9rem; }
.error { color: var(--danger); min-height: 1.2em; margin: 4px 0; font-size: .95rem; }
svg { width: 20px; height: 20px; fill: currentColor; flex: none; }
::selection { background: var(--accent-soft); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 10px; border: 2px solid var(--panel); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line);
  background: var(--panel); border-radius: 9px; padding: 7px 13px; font-weight: 600; text-decoration: none; color: var(--ink); }
.btn:hover { background: var(--hover); }
.btn svg { width: 17px; height: 17px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); }
.btn.red { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.green { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.block { width: 100%; padding: 10px; }
.btn.sm { padding: 4px 9px; font-size: .88rem; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 9px; border: 0; background: transparent; color: inherit; position: relative; }
.icon-btn:hover { background: var(--hover); }
.icon-btn svg { width: 19px; height: 19px; }
.pill { display: inline-grid; place-items: center; min-width: 19px; height: 19px; padding: 0 6px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: .8rem; font-weight: 700; }
.pill.muted-pill { background: var(--off); }
label { display: block; font-size: .92rem; font-weight: 600; color: var(--muted); margin-bottom: 11px; }
input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=range]), textarea, select {
  display: block; width: 100%; margin-top: 4px; padding: 8px 11px; border: 1px solid var(--line); border-radius: 9px;
  background: var(--panel); outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; }
kbd { font: .8rem ui-monospace, Consolas, monospace; background: var(--hover); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

/* ───────── sign in ───────── */
.login { height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--login-bg); overflow: auto; }
.login-card { width: 100%; max-width: 360px; background: var(--panel); border-radius: 18px; padding: 26px 24px; box-shadow: var(--shadow); }
.login-logo { width: 220px; max-width: 100%; height: auto; display: block; margin: 0 auto 6px; }
.login-card h1 { display: flex; align-items: center; justify-content: center; gap: 8px; font-size: 1.55rem; margin: 8px 0 0; }
.login-card p.muted { text-align: center; margin: 0 0 16px; }

/* ───────── layout ───────── */
.app { display: grid; grid-template-columns: 300px 1fr; height: 100vh; height: 100dvh; }
.sidebar { display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-right: 1px solid var(--line); }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; background: #fff; border-bottom: 1px solid var(--line); }
.brand-logo { height: 24px; width: auto; display: block; }
.brand-tag { display: inline-flex; align-items: center; gap: 5px; font-size: .85rem; font-weight: 700; color: #0e2a47; }
.me-btn { display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 12px; border: 0; border-bottom: 1px solid var(--line);
  background: var(--panel); text-align: left; color: var(--ink); }
.me-btn:hover { background: var(--hover); }
.me-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
.me-text b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-status { font-size: .85rem; color: var(--muted); display: inline-flex; align-items: center; gap: 5px; }
.sdot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; background: var(--off); flex: none; }
.sdot.online { background: var(--ok); } .sdot.away { background: var(--away); } .sdot.busy { background: var(--busy); }
.me-btn .caret { width: 16px; height: 16px; color: var(--muted); }
.side-tools { display: flex; gap: 6px; padding: 8px 10px 4px; align-items: center; }
.search { flex: 1; display: flex; align-items: center; gap: 6px; background: var(--hover); border-radius: 9px; padding: 0 9px; }
.search svg { width: 17px; height: 17px; color: var(--muted); }
.search input { border: 0 !important; background: transparent !important; box-shadow: none !important; margin: 0 !important; padding: 6px 0 !important; }
.tabs { display: flex; gap: 4px; padding: 2px 10px 6px; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: transparent; padding: 5px; border-radius: 8px; font-weight: 600; color: var(--muted); display: inline-flex; gap: 6px; justify-content: center; align-items: center; }
.tabs button.active { background: var(--active); color: var(--ink); }
.list { flex: 1; overflow-y: auto; padding: 6px; }
.conn { padding: 7px; text-align: center; font-size: .9rem; background: #fff4e5; color: #8a4b00; }
.list-section { padding: 9px 9px 3px; font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }

.item { display: flex; align-items: center; gap: 9px; padding: 6px 8px; border-radius: 10px; cursor: pointer; border: 0; width: 100%; background: transparent; text-align: left; }
.item:hover { background: var(--hover); }
.item.active { background: var(--active); }
.item .meta { flex: 1; min-width: 0; }
.item .row { display: flex; align-items: baseline; gap: 6px; }
.item .name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .time { font-size: .82rem; color: var(--muted); flex: none; }
.item .preview { font-size: .92rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; }
.item.unread .name, .item.unread .preview { color: var(--ink); font-weight: 700; }
.item .icons { display: inline-flex; gap: 3px; color: var(--muted); }
.item .icons svg { width: 14px; height: 14px; }
.item mark, .search-hit mark { background: var(--accent-soft); color: inherit; border-radius: 3px; padding: 0 1px; }

/* avatar */
.av { position: relative; flex: none; width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: .95rem; letter-spacing: .3px; }
.av img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; background: var(--panel); }
.av .emo { font-size: 1.35em; line-height: 1; }
.av.lg { width: 84px; height: 84px; font-size: 1.9rem; }
.av.md { width: 48px; height: 48px; font-size: 1.15rem; }
.av.sm { width: 28px; height: 28px; font-size: .8rem; }
.av.xs { width: 22px; height: 22px; font-size: .68rem; }
.av svg { width: 18px; height: 18px; }
.av .dot { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; border-radius: 50%; border: 2px solid var(--panel); background: var(--off); }
.av.lg .dot { width: 18px; height: 18px; border-width: 3px; right: 2px; bottom: 2px; }
.av .dot.online { background: var(--ok); } .av .dot.away { background: var(--away); } .av .dot.busy { background: var(--busy); }

/* ───────── chat pane ───────── */
.chat { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.empty .welcome-logo { width: 220px; max-width: 70%; height: auto; }
.empty h2 { color: var(--ink); margin: 14px 0 6px; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 12px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 52px; }
.chat-head .title { flex: 1; min-width: 0; cursor: pointer; }
.chat-head .title b { display: block; font-size: 1.07rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .title span { font-size: .88rem; color: var(--muted); }
.chat-head .actions { display: flex; gap: 2px; }
.back-btn { display: none; }
.pinbar, .callbar { display: flex; align-items: center; gap: 8px; padding: 6px 12px; background: var(--panel-2); border-bottom: 1px solid var(--line); font-size: .92rem; }
.pinbar { cursor: pointer; }
.pinbar .ptext { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinbar b { color: var(--group-ink); }
.callbar { background: var(--accent-soft); }
.callbar .ctext { flex: 1; font-weight: 600; }

.messages { flex: 1; overflow-y: auto; padding: 10px 14px 6px; display: flex; flex-direction: column; gap: 2px; }
.day { align-self: center; margin: 12px 0 6px; font-size: .82rem; font-weight: 600; color: var(--muted); background: var(--panel); padding: 2px 11px; border-radius: 999px; border: 1px solid var(--line); }
.sysline { align-self: center; margin: 6px 0; font-size: .85rem; color: var(--muted); text-align: center; max-width: 80%; }
.callline { align-self: center; display: inline-flex; align-items: center; gap: 8px; margin: 6px 0; padding: 5px 12px; border-radius: 999px;
  background: var(--panel); border: 1px solid var(--line); font-size: .9rem; }
.callline svg { width: 16px; height: 16px; color: var(--ok); }
.callline.missed svg { color: var(--danger); }
.callline .btn { padding: 2px 9px; font-size: .82rem; }
.buzzline { align-self: center; margin: 6px 0; padding: 4px 12px; border-radius: 999px; background: #fff3cd; color: #7a5a00; font-weight: 700; font-size: .9rem; }

.msg { display: flex; gap: 7px; align-items: flex-end; max-width: 78%; position: relative; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.first { margin-top: 7px; }
.msg .av-slot { width: 28px; flex: none; }
.msg .stack { display: flex; flex-direction: column; min-width: 0; }
.msg.me .stack { align-items: flex-end; }
.bubble { position: relative; background: var(--bubble-them); border: 1px solid var(--line); padding: 5px 10px 4px; border-radius: 14px; min-width: 64px; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--bubble-me); color: var(--bubble-me-ink); border-color: transparent; }
.msg.me .bubble a { color: #cfe6ff; }
.msg.flash .bubble { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.bubble .who { font-size: .88rem; font-weight: 700; color: var(--accent); margin-bottom: 1px; }
.bubble .who em { font-style: normal; font-weight: 500; color: var(--muted); }
.bubble .text { white-space: pre-wrap; }
.bubble .text.big { font-size: 2.2rem; line-height: 1.2; }
.bubble .foot { display: flex; justify-content: flex-end; align-items: center; gap: 5px; font-size: .78rem; opacity: .75; margin-top: 1px; }
.bubble .foot svg { width: 14px; height: 14px; }
.tick { display: inline-flex; }
.tick svg { width: 16px; height: 16px; }
.tick.read { color: var(--tick-read); opacity: 1; }
.msg.me .tick.read { color: #8fd3ff; }
.bubble.deleted .text { font-style: italic; opacity: .7; }
.bubble.announce { border-left: 4px solid var(--accent); }
.tagline { display: inline-flex; align-items: center; gap: 4px; font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.msg.me .tagline { color: rgba(255, 255, 255, .8); }
.aud { display: inline-block; font-size: .78rem; font-weight: 700; background: var(--accent-soft); color: var(--accent); padding: 1px 8px; border-radius: 999px; margin-bottom: 3px; }
.msg.me .aud { background: rgba(255, 255, 255, .18); color: #fff; }
.quote { display: block; border-left: 3px solid var(--accent); background: rgba(127, 127, 127, .12); border-radius: 6px; padding: 3px 8px; margin: 2px 0 4px; font-size: .9rem; cursor: pointer; max-width: 360px; }
.quote b { display: block; font-size: .82rem; color: var(--accent); }
.msg.me .quote { border-color: #fff; } .msg.me .quote b { color: #fff; }
.quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; }
.react-chip { display: inline-flex; align-items: center; gap: 3px; border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 0 7px; font-size: .9rem; line-height: 1.6; }
.react-chip.mine { border-color: var(--accent); background: var(--accent-soft); }
.react-chip b { font-size: .8rem; color: var(--muted); }
.msg-actions { position: absolute; top: -14px; display: flex; gap: 1px; padding: 2px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 9px; box-shadow: 0 2px 8px rgba(0, 0, 0, .12); opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 3; }
.msg:not(.me) .msg-actions { right: -8px; transform: translateX(100%); top: 0; }
.msg.me .msg-actions { left: -8px; transform: translateX(-100%); top: 0; }
.msg:hover .msg-actions, .msg:focus-within .msg-actions { opacity: 1; pointer-events: auto; }
.msg-actions button { border: 0; background: transparent; color: var(--muted); padding: 3px 5px; border-radius: 6px; font-size: 1rem; line-height: 1; }
.msg-actions button:hover { background: var(--hover); color: var(--ink); }
.msg-actions svg { width: 16px; height: 16px; }
.seen { align-self: flex-end; font-size: .82rem; color: var(--muted); margin: 1px 6px 0; }

.att-img { display: block; max-width: min(320px, 100%); max-height: 300px; border-radius: 10px; margin: 2px 0 4px; cursor: zoom-in; background: var(--hover); }
.att-video { display: block; max-width: min(360px, 100%); max-height: 280px; border-radius: 10px; margin: 2px 0 4px; background: #000; }
.att-file { display: flex; align-items: center; gap: 10px; padding: 7px 9px; border-radius: 10px; background: rgba(127, 127, 127, .1); text-decoration: none; color: inherit; margin: 2px 0 4px; min-width: 200px; }
.att-file:hover { background: rgba(127, 127, 127, .18); }
.ext { width: 36px; height: 42px; border-radius: 6px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: .72rem; font-weight: 800; text-transform: uppercase; flex: none; }
.att-file .fn { font-weight: 600; font-size: .95rem; word-break: break-all; }
.att-file .fs { font-size: .82rem; opacity: .75; }

.typing { min-height: 20px; padding: 0 18px; font-size: .88rem; color: var(--muted); font-style: italic; }
.composer { display: flex; flex-direction: column; gap: 5px; padding: 6px 10px 8px; background: var(--panel); border-top: 1px solid var(--line); padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.composer-row { display: flex; align-items: flex-end; gap: 4px; }
.composer textarea { flex: 1; resize: none; max-height: 160px; min-height: 36px; margin: 0; border-radius: 11px; line-height: 1.4; padding: 7px 10px; }
.send-btn { width: 36px; height: 36px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; }
.send-btn svg { width: 18px; height: 18px; }
.send-btn:disabled { opacity: .5; }
.chip { display: flex; align-items: center; gap: 8px; background: var(--hover); border-radius: 9px; padding: 5px 9px; font-size: .92rem; }
.chip .bar { flex: 1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.chip .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.chip .name { max-width: 55%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.chip .ctx { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip .ctx b { color: var(--accent); }
.readonly-note { text-align: center; padding: 12px; color: var(--muted); font-size: .95rem; background: var(--panel); border-top: 1px solid var(--line); }
.target-btn { align-self: flex-start; border: 1px dashed var(--accent); color: var(--accent); background: transparent; border-radius: 999px; padding: 2px 11px; font-size: .88rem; font-weight: 700; }
.drop-hint { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(14, 42, 71, .65); color: #fff; font-size: 1.4rem; font-weight: 700; z-index: 5; pointer-events: none; }

/* emoji picker */
.emoji-pop { position: fixed; z-index: 65; width: 330px; max-width: calc(100vw - 16px); height: 330px; display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden; }
.emoji-tabs { display: flex; border-bottom: 1px solid var(--line); padding: 3px; gap: 1px; }
.emoji-tabs button { flex: 1; border: 0; background: transparent; border-radius: 7px; padding: 4px 0; font-size: 1.1rem; }
.emoji-tabs button.active { background: var(--active); }
.emoji-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(8, 1fr); padding: 6px; gap: 2px; align-content: start; }
.emoji-grid button { border: 0; background: transparent; font-size: 1.45rem; line-height: 1.3; border-radius: 7px; padding: 2px 0; }
.emoji-grid button:hover { background: var(--hover); }
.emoji-grid .ecat { grid-column: 1 / -1; font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; padding: 4px 2px 0; }
.react-pop { position: fixed; z-index: 66; display: flex; gap: 2px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 999px; box-shadow: var(--shadow); }
.react-pop button { border: 0; background: transparent; font-size: 1.45rem; line-height: 1; padding: 4px 5px; border-radius: 50%; transition: transform .1s; }
.react-pop button:hover { transform: scale(1.25); background: var(--hover); }

/* ───────── Spark-style contacts ───────── */
.bc-all { display: flex; align-items: center; gap: 8px; width: 100%; margin: 2px 0 6px; padding: 7px 10px; border: 1px dashed var(--accent);
  border-radius: 10px; background: var(--accent-soft); color: var(--ink); font-weight: 600; text-align: left; }
.bc-all svg { width: 18px; height: 18px; color: var(--accent); }
.bc-all span:first-of-type { flex: 1; }
.grp { position: relative; }
.grp-head { display: flex; align-items: center; gap: 4px; width: 100%; border: 0; background: transparent; padding: 5px 30px 5px 4px;
  text-align: left; border-radius: 8px; color: var(--group-ink); font-weight: 700; font-size: .92rem; text-transform: uppercase; letter-spacing: .2px; }
.grp-head:hover { background: var(--hover); }
.grp-head .chev { width: 16px; height: 16px; color: var(--muted); transition: transform .15s; }
.grp.open > .grp-head .chev { transform: rotate(90deg); }
.grp-head .gname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.grp-head .gcount { flex: none; font-weight: 600; color: var(--muted); text-transform: none; }
.grp-menu { position: absolute; right: 2px; top: 2px; width: 26px; height: 24px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-weight: 900; opacity: 0; }
.grp:hover > .grp-menu, .grp-menu:focus { opacity: 1; }
.grp-menu:hover { background: var(--active); color: var(--ink); }
.grp-body { padding: 0 0 4px; }
.contact { display: flex; align-items: center; gap: 8px; width: 100%; border: 0; background: transparent; padding: 3px 8px 3px 26px; border-radius: 6px; text-align: left; color: var(--muted); }
.contact.on { color: var(--ink); }
.contact:hover { background: var(--hover); }
.contact .cname { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact .cstat { font-size: .82rem; font-style: italic; color: var(--muted); white-space: nowrap; }
.contact .you { font-size: .75rem; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 4px; }

/* ───────── modals, menus, popups ───────── */
.modal-back { position: fixed; inset: 0; background: rgba(8, 18, 30, .55); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 460px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--panel); border-radius: 15px; box-shadow: var(--shadow); }
.modal.wide { max-width: 900px; }
.modal.mid { max-width: 620px; }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--line); gap: 10px; }
.modal header h3 { margin: 0; font-size: 1.15rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal .body { padding: 14px 16px; overflow-y: auto; }
.modal footer { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 10px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-tabs { display: flex; gap: 4px; padding: 8px 16px 0; border-bottom: 1px solid var(--line); overflow-x: auto; }
.modal-tabs button { border: 0; background: transparent; padding: 7px 10px; font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.modal-tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
.pick-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 10px; margin-top: 8px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 7px 10px; cursor: pointer; font-weight: 500; color: var(--ink); margin: 0; font-size: 1rem; }
.pick:hover { background: var(--hover); }
.pick .sub { font-size: .85rem; color: var(--muted); }
.members .member { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.members .member .meta { flex: 1; min-width: 0; }
.tag { font-size: .78rem; font-weight: 700; padding: 1px 7px; border-radius: 6px; background: var(--active); color: var(--ink); margin-left: 4px; }
.tag.off { background: #fde4e4; color: var(--danger); }
.tag.orange { background: var(--accent-soft); color: var(--accent); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.stats { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--hover); border-radius: 11px; padding: 9px 11px; }
.stat b { display: block; font-size: 1.5rem; }
.stat span { font-size: .82rem; color: var(--muted); }
table.users { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.users th { text-align: left; font-size: .82rem; color: var(--muted); font-weight: 700; padding: 7px 6px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); }
table.users td { padding: 7px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.admin-tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.admin-tabs button.active { background: var(--active); }
.copybox { font-family: ui-monospace, Consolas, monospace; background: var(--hover); padding: 10px 12px; border-radius: 10px; font-size: 1.05rem; user-select: all; }
.menu { position: fixed; z-index: 60; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); padding: 5px; min-width: 220px; max-height: calc(100vh - 16px); overflow-y: auto; }
.menu .who { padding: 7px 10px 9px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.menu button { display: flex; width: 100%; gap: 10px; align-items: center; border: 0; background: transparent; padding: 7px 10px; border-radius: 8px; text-align: left; font-size: .97rem; }
.menu button:hover { background: var(--hover); }
.menu button.on { font-weight: 700; }
.menu button.danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
.menu .mlabel { padding: 4px 10px 2px; font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0, 0, 0, .88); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 20px; }
.lightbox img { max-width: 100%; max-height: calc(100dvh - 100px); border-radius: 8px; }
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(20px); opacity: 0; background: #1b2633; color: #fff; padding: 9px 15px; border-radius: 10px; transition: .2s; z-index: 90; pointer-events: none; max-width: calc(100% - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%); }

/* broadcast popup (like Spark's broadcast window) */
.attention { position: fixed; top: 16px; right: 16px; z-index: 85; width: 360px; max-width: calc(100vw - 32px); display: flex; flex-direction: column; gap: 10px; }
.att-card { background: var(--panel); border: 1px solid var(--line); border-left: 5px solid var(--accent); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; animation: slidein .25s ease; }
.att-card .hd { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-weight: 700; }
.att-card .hd svg { color: var(--accent); }
.att-card .bd { white-space: pre-wrap; overflow-wrap: anywhere; max-height: 180px; overflow: auto; margin-bottom: 8px; }
.att-card .ft { display: flex; justify-content: flex-end; gap: 6px; }
@keyframes slidein { from { transform: translateX(30px); opacity: 0; } to { transform: none; opacity: 1; } }

/* buzz shake */
.shake { animation: shake .5s cubic-bezier(.36, .07, .19, .97) both 2; }
@keyframes shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-8px); } 40%, 60% { transform: translateX(8px); } }

/* settings & profile */
.swatches { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 14px; }
.swatch { width: 78px; border: 2px solid var(--line); border-radius: 10px; padding: 5px; background: var(--panel); text-align: center; font-size: .82rem; font-weight: 600; }
.swatch.active { border-color: var(--accent); }
.swatch i { display: flex; height: 30px; border-radius: 6px; overflow: hidden; margin-bottom: 4px; }
.swatch i { border: 1px solid var(--line); }
.swatch i b { flex: 1; }
.setrow { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); }
.setrow:last-child { border-bottom: 0; }
.setrow .lbl { flex: 1; }
.setrow .lbl small { display: block; color: var(--muted); }
.setrow select { width: auto; min-width: 150px; margin: 0; }
.sec-title { font-size: .82rem; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 12px 0 4px; }
.avatar-grid { display: grid; grid-template-columns: repeat(8, 1fr); gap: 6px; margin-top: 8px; }
.avatar-grid button { border: 2px solid transparent; border-radius: 50%; padding: 0; background: transparent; aspect-ratio: 1; display: grid; place-items: center; font-size: 1.4rem; }
.avatar-grid button.sel { border-color: var(--accent); }
.colors { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.colors button { width: 24px; height: 24px; border-radius: 50%; border: 2px solid transparent; }
.colors button.sel { border-color: var(--ink); }
.profile-top { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 6px 10px; font-size: .97rem; }
.kv span:nth-child(odd) { color: var(--muted); }
.shared-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 6px; }
.shared-grid img, .shared-grid video { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; cursor: pointer; background: var(--hover); }
.shared-row { display: flex; align-items: center; gap: 10px; padding: 7px 4px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.shared-row:hover { background: var(--hover); }
.shared-row .m { flex: 1; min-width: 0; }
.shared-row .m b, .shared-row .m span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shared-row .m span { color: var(--muted); font-size: .85rem; }
.search-hit { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 6px 8px; border-radius: 9px; }
.search-hit:hover { background: var(--hover); }
.search-hit .sh-top { display: flex; gap: 6px; font-size: .85rem; color: var(--muted); }
.search-hit .sh-top b { color: var(--ink); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.search-hit .sh-body { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ───────── calls ───────── */
.call { position: fixed; inset: 0; z-index: 75; display: flex; flex-direction: column; background: #0b1119; color: #fff; }
.call-head { display: flex; align-items: center; gap: 10px; padding: 10px 14px; }
.call-head .t { flex: 1; min-width: 0; }
.call-head .t b { display: block; font-size: 1.1rem; }
.call-head .t span { font-size: .9rem; color: #9fb0c4; }
.call-head .icon-btn:hover { background: rgba(255, 255, 255, .1); }
.call-grid { flex: 1; min-height: 0; display: grid; gap: 8px; padding: 8px 14px; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); grid-auto-rows: 1fr; }
.call-grid.n1 { grid-template-columns: 1fr; }
.tile { position: relative; background: #17202c; border-radius: 14px; overflow: hidden; display: grid; place-items: center; min-height: 160px; }
.tile video { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; background: #000; }
.tile video.screen { object-fit: contain; }
.tile .ph { display: flex; flex-direction: column; align-items: center; gap: 10px; color: #c9d4e0; z-index: 1; }
.tile.has-video .ph { display: none; }
.tile .label { position: absolute; left: 8px; bottom: 8px; z-index: 2; background: rgba(0, 0, 0, .55); padding: 2px 9px; border-radius: 999px; font-size: .88rem; display: flex; align-items: center; gap: 5px; }
.tile .label svg { width: 14px; height: 14px; color: #ff6b6b; }
.tile.speaking { box-shadow: 0 0 0 3px var(--ok) inset; }
.tile.local { position: absolute; right: 22px; bottom: 96px; width: 220px; height: 140px; min-height: 0; z-index: 4; box-shadow: 0 6px 20px rgba(0, 0, 0, .5); }
.tile.local video { transform: scaleX(-1); }
.tile.local video.screen { transform: none; }
.call-grid.group .tile.local { position: relative; right: auto; bottom: auto; width: auto; height: auto; min-height: 160px; box-shadow: none; }
.call-ctl { display: flex; justify-content: center; gap: 14px; padding: 14px 14px 22px; }
.call-ctl button { width: 52px; height: 52px; border-radius: 50%; border: 0; background: #2a3646; color: #fff; display: grid; place-items: center; }
.call-ctl button:hover { background: #36465a; }
.call-ctl button.off { background: #fff; color: #17202c; }
.call-ctl button.on { background: var(--accent); }
.call-ctl button.hang { background: #e53935; width: 64px; }
.call-ctl button svg { width: 24px; height: 24px; }
.call-mini { position: fixed; right: 16px; bottom: 16px; z-index: 75; display: flex; align-items: center; gap: 8px; padding: 8px 10px 8px 14px;
  background: #0b1119; color: #fff; border-radius: 999px; box-shadow: var(--shadow); cursor: pointer; }
.call-mini .t { font-weight: 600; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-mini button { width: 34px; height: 34px; border-radius: 50%; border: 0; display: grid; place-items: center; background: #2a3646; color: #fff; }
.call-mini button.hang { background: #e53935; }
.call-mini svg { width: 18px; height: 18px; }
.incoming { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); z-index: 95; width: 340px; max-width: calc(100vw - 24px);
  background: #0b1119; color: #fff; border-radius: 18px; box-shadow: 0 16px 40px rgba(0, 0, 0, .45); padding: 18px; text-align: center; animation: slidedown .25s ease; }
@keyframes slidedown { from { transform: translate(-50%, -20px); opacity: 0; } to { transform: translateX(-50%); opacity: 1; } }
.incoming .av { margin: 0 auto 8px; animation: pulse 1.4s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(34, 168, 90, .6); } 70% { box-shadow: 0 0 0 16px rgba(34, 168, 90, 0); } 100% { box-shadow: 0 0 0 0 rgba(34, 168, 90, 0); } }
.incoming b { display: block; font-size: 1.15rem; }
.incoming span { color: #9fb0c4; font-size: .92rem; }
.incoming .btns { display: flex; justify-content: center; gap: 14px; margin-top: 14px; }
.incoming .btns button { width: 52px; height: 52px; border-radius: 50%; border: 0; display: grid; place-items: center; color: #fff; }
.incoming .btns button svg { width: 24px; height: 24px; }
.incoming .decline { background: #e53935; } .incoming .accept { background: var(--ok); }
.picker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.picker-grid button { border: 2px solid var(--line); border-radius: 10px; background: var(--panel); padding: 6px; text-align: left; }
.picker-grid button:hover { border-color: var(--accent); }
.picker-grid img { width: 100%; aspect-ratio: 16 / 10; object-fit: contain; background: #000; border-radius: 6px; display: block; margin-bottom: 4px; }
.picker-grid span { font-size: .85rem; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ───────── responsive ───────── */
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .app .chat { display: none; }
  .app.show-chat .sidebar { display: none; }
  .app.show-chat .chat { display: flex; }
  .back-btn { display: inline-grid; }
  .msg { max-width: 90%; }
  .messages { padding: 10px 8px 6px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid2 { grid-template-columns: 1fr; }
  table.users .hide-sm { display: none; }
  .tile.local { width: 120px; height: 160px; right: 12px; bottom: 90px; }
  .msg-actions { display: none; position: static; transform: none !important; opacity: 1; pointer-events: auto; align-self: center; box-shadow: none; }
  .msg.show-actions .msg-actions { display: flex; }
  .msg:hover .msg-actions { opacity: 1; }
}
@media (min-width: 641px) and (max-width: 860px) {
  .app { grid-template-columns: 260px 1fr; }
}

/* ───────── v2.1: message pop-ups, install & notification banners ───────── */
.msgpop { border-left-color: var(--group-ink); cursor: pointer; padding: 10px 12px; }
.msgpop .hd { margin-bottom: 4px; font-weight: 600; }
.msgpop .hd .av { margin-right: 2px; }
.msgpop .hd .nm { flex: 1; min-width: 0; line-height: 1.2; }
.msgpop .hd .nm b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msgpop .hd .nm span { font-size: .82rem; color: var(--muted); font-weight: 500; }
.msgpop .bd { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; max-height: none; margin-bottom: 6px; }
.msgpop .x { border: 0; background: transparent; color: var(--muted); font-size: 1.1rem; line-height: 1; padding: 2px 4px; border-radius: 6px; }
.msgpop .x:hover { background: var(--hover); }
.banner { display: flex; align-items: center; gap: 8px; margin: 6px 8px 0; padding: 8px 10px; border-radius: 10px; background: var(--accent-soft); font-size: .9rem; }
.banner span { flex: 1; }
.banner .x { border: 0; background: transparent; color: var(--muted); font-size: 1rem; padding: 2px 4px; }
.ios-steps { margin: 0; padding-left: 20px; line-height: 1.9; }
.ios-steps b { white-space: nowrap; }
@media (max-width: 640px) {
  .attention { top: auto; bottom: 12px; right: 8px; left: 8px; width: auto; }
}

/* never wider than the phone screen */
.app { grid-template-columns: 300px minmax(0, 1fr); }
.sidebar, .chat, .side-tools, .search, .search input, .tabs, .list, .banner { min-width: 0; }
.search input { width: 100%; }
@media (max-width: 640px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  html, body { overflow-x: hidden; }
  .side-head { padding: 6px 12px; }
  .brand-logo { height: 22px; }
}
@media (min-width: 641px) and (max-width: 860px) {
  .app { grid-template-columns: 260px minmax(0, 1fr); }
}
.setrow.my-sound { padding-left: 14px; }
.setrow.my-sound .lbl { font-size: .95em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) { .setrow select { min-width: 0; max-width: 46vw; } }
