:root {
  --app-bg: #d1d7db;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --hover: #f5f6f6;
  --active: #f0f2f5;
  --border: #e9edef;
  --text: #111b21;
  --text-2: #3b4a54;
  --muted: #667781;
  --accent: #00a884;
  --accent-strong: #008069;
  --chat-bg: #efeae2;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --quote-bg: rgba(11, 20, 26, 0.05);
  --tick-read: #53bdeb;
  --danger: #ea0038;
  --shadow: 0 2px 5px rgba(11, 20, 26, 0.16), 0 2px 10px rgba(11, 20, 26, 0.12);
  --system-bg: #ffffff;
  --input-bg: #ffffff;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --app-bg: #0c1317;
    --panel: #111b21;
    --panel-2: #202c33;
    --hover: #202c33;
    --active: #2a3942;
    --border: #222d34;
    --text: #e9edef;
    --text-2: #d1d7db;
    --muted: #8696a0;
    --accent: #00a884;
    --accent-strong: #06cf9c;
    --chat-bg: #0b141a;
    --bubble-in: #202c33;
    --bubble-out: #005c4b;
    --quote-bg: rgba(0, 0, 0, 0.2);
    --danger: #f15c6d;
    --shadow: 0 2px 5px rgba(0, 0, 0, 0.4), 0 2px 10px rgba(0, 0, 0, 0.3);
    --system-bg: #182229;
    --input-bg: #2a3942;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  background: var(--app-bg);
  color: var(--text);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
a { color: #027eb5; }
@media (prefers-color-scheme: dark) { a { color: #53bdeb; } }
svg { display: block; flex-shrink: 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.pad { padding: 16px; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- buttons & inputs ---------- */
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--muted); flex-shrink: 0; transition: background .15s;
}
.icon-btn:hover { background: var(--quote-bg); }
.btn {
  padding: 10px 22px; border-radius: 24px; font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.primary:disabled { opacity: .6; cursor: default; }
.btn.round { width: 48px; height: 48px; padding: 0; border-radius: 50%; flex-shrink: 0; }
.btn.wide { width: 100%; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.ghost { border: 1px solid var(--border); color: var(--danger); }
.btn.danger-text { color: var(--danger); }
.btn.danger-text:hover { background: var(--quote-bg); }
.input {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--input-bg); outline: none;
}
.input:focus { border-color: var(--accent); }
.field { display: block; margin: 14px 0; }
.field > span { display: block; font-size: 13px; color: var(--accent-strong); margin-bottom: 6px; }
.field input {
  width: 100%; padding: 10px 2px; border: 0; border-bottom: 2px solid var(--border);
  background: transparent; outline: none;
}
.field input:focus { border-bottom-color: var(--accent); }

/* ---------- auth ---------- */
/* auto margins on the card centre it, but unlike align-items:center they keep it scrollable when taller than the screen */
.auth {
  min-height: 100vh; min-height: 100dvh; display: flex; align-items: flex-start; justify-content: center;
  padding: 16px; overflow-y: auto; height: 100%;
  background: linear-gradient(var(--accent) 0 220px, var(--app-bg) 220px);
}
.auth-card {
  width: 100%; max-width: 400px; margin: auto 0; background: var(--panel); border-radius: 12px;
  padding: 32px 28px; box-shadow: var(--shadow); text-align: center;
}
.auth-logo { width: 64px; height: 64px; }
.auth-card h1 { margin: 12px 0 4px; font-weight: 500; font-size: 26px; }
.auth-card form { text-align: left; }
.tabs { display: flex; margin: 20px 0 6px; border-bottom: 1px solid var(--border); }
.tab { flex: 1; padding: 10px; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 500; }
.tab.active { color: var(--accent-strong); border-bottom-color: var(--accent); }
.register-only { display: none; }
.auth.register .register-only { display: block; }
.android-link { display: inline-block; margin-top: 18px; color: var(--accent-strong); font-weight: 500; text-decoration: none; }
.form-error { color: var(--danger); min-height: 20px; font-size: 14px; margin-bottom: 10px; }

/* ---------- layout ---------- */
.app {
  display: flex; height: 100vh; height: 100dvh; max-width: 1600px; margin: 0 auto;
  background: var(--panel); box-shadow: var(--shadow); overflow: hidden;
}
@media (min-width: 1440px) {
  .app { height: calc(100vh - 38px); height: calc(100dvh - 38px); margin-top: 19px; }
}
.sidebar {
  width: 30%; min-width: 320px; max-width: 440px; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--border);
}
.chat-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--chat-bg); }
.back-btn { display: none; }

@media (max-width: 800px) {
  .sidebar { width: 100%; max-width: none; min-width: 0; border-right: 0; }
  .chat-pane { display: none; }
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .chat-pane { display: flex; }
  .back-btn { display: inline-flex; margin-left: -8px; }
  .messages { padding: 8px 4% 12px !important; }
  .bubble { max-width: 85% !important; }
}

/* ---------- sidebar ---------- */
.side-header, .chat-header {
  height: 60px; flex-shrink: 0; display: flex; align-items: center; gap: 8px;
  padding: 0 12px 0 16px; background: var(--panel-2);
}
.side-header { justify-content: space-between; }
.header-actions { display: flex; align-items: center; gap: 4px; }
.avatar-btn { border-radius: 50%; }
.search-box { position: relative; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.search-icon { position: absolute; left: 24px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.search-icon svg { width: 18px; height: 18px; }
.search-box input {
  width: 100%; padding: 8px 12px 8px 52px; border-radius: 8px; border: 0;
  background: var(--panel-2); outline: none;
}
.connection-banner { background: #ffd279; color: #3b2f00; padding: 8px 16px; font-size: 13px; }
.chat-list { flex: 1; overflow-y: auto; }
.chat-item {
  display: flex; align-items: center; gap: 13px; width: 100%; padding: 0 0 0 13px;
  cursor: pointer; text-align: left; outline: none;
}
.chat-item:hover, .chat-item:focus-visible { background: var(--hover); }
.chat-item.active { background: var(--active); }
.chat-item-body { flex: 1; min-width: 0; padding: 12px 15px 12px 0; border-bottom: 1px solid var(--border); height: 72px; display: flex; flex-direction: column; justify-content: center; gap: 3px; }
.chat-item-row { display: flex; align-items: center; gap: 6px; }
.chat-item-name { flex: 1; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item-time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.chat-item-time.unread { color: var(--accent); font-weight: 500; }
.preview {
  flex: 1; min-width: 0; font-size: 14px; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 3px;
}
.preview.typing { color: var(--accent); }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; flex-shrink: 0;
  background: var(--accent); color: #fff; font-size: 12px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.list-empty { padding: 40px 24px; text-align: center; color: var(--muted); }

/* ---------- avatars ---------- */
.avatar {
  border-radius: 50%; flex-shrink: 0; overflow: hidden; color: #fff; font-weight: 500;
  display: flex; align-items: center; justify-content: center; background: #6b7c85; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- empty state ---------- */
.empty-state {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px; background: var(--panel-2); border-bottom: 6px solid var(--accent); color: var(--muted);
}
.empty-state h2 { font-weight: 300; font-size: 32px; color: var(--text); margin: 24px 0 8px; }
.empty-state .small { display: inline-flex; align-items: center; gap: 4px; margin-top: 40px; }
.empty-state .small svg { width: 14px; height: 14px; }

/* ---------- chat view ---------- */
.chat-view { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.chat-header { border-left: 1px solid var(--border); padding-left: 16px; }
.chat-head-info { flex: 1; min-width: 0; display: flex; align-items: center; gap: 14px; text-align: left; height: 100%; }
.head-text { min-width: 0; }
.head-name { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-status { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.head-status.typing { color: var(--accent); }

.messages {
  flex: 1; overflow-y: auto; padding: 12px 7% 16px; display: flex; flex-direction: column;
  background-color: var(--chat-bg);
  background-image: radial-gradient(rgba(128, 128, 128, .07) 1px, transparent 1px);
  background-size: 18px 18px;
  outline: none;
}
.loading, .loading-more { text-align: center; color: var(--muted); padding: 16px; font-size: 13px; }
.chat-start {
  align-self: center; margin: 8px 0 12px; padding: 6px 12px; border-radius: 8px; font-size: 12.5px;
  background: #ffeecd; color: #54656f; display: flex; align-items: center; gap: 4px; text-align: center;
}
@media (prefers-color-scheme: dark) { .chat-start { background: #182229; color: #ffd279; } }
.day-sep { align-self: center; margin: 12px 0 8px; position: sticky; top: 4px; z-index: 2; }
.day-sep span, .system-msg span {
  display: inline-block; padding: 5px 12px; border-radius: 8px; font-size: 12.5px;
  background: var(--system-bg); color: var(--muted); box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
}
.system-msg { align-self: center; margin: 6px 0; text-align: center; max-width: 85%; }

.msg-row { display: flex; margin-top: 2px; transition: background .4s; }
.msg-row.first { margin-top: 10px; }
.msg-row.out { justify-content: flex-end; }
.msg-row.flash { background: rgba(0, 168, 132, .18); border-radius: 8px; }
.bubble {
  position: relative; max-width: min(65%, 560px); min-width: 80px; padding: 6px 7px 8px 9px; border-radius: 8px;
  background: var(--bubble-in); box-shadow: 0 1px .5px rgba(11, 20, 26, .13); overflow-wrap: anywhere;
}
.out .bubble { background: var(--bubble-out); }
.msg-row.first.in .bubble { border-top-left-radius: 0; }
.msg-row.first.out .bubble { border-top-right-radius: 0; }
.msg-row.first.in .bubble::before, .msg-row.first.out .bubble::before {
  content: ""; position: absolute; top: 0; width: 8px; height: 13px;
}
.msg-row.first.in .bubble::before { left: -8px; background: var(--bubble-in); clip-path: polygon(0 0, 100% 0, 100% 100%); }
.msg-row.first.out .bubble::before { right: -8px; background: var(--bubble-out); clip-path: polygon(0 0, 100% 0, 0 100%); }
.sender { font-size: 12.8px; font-weight: 500; margin-bottom: 2px; }
.text { white-space: pre-wrap; font-size: 14.2px; line-height: 19px; }
.text.jumbo { font-size: 40px; line-height: 48px; }
.text.deleted { font-style: italic; color: var(--muted); }
.meta-spacer { display: inline-block; width: 52px; height: 1px; }
.meta-spacer.mine { width: 72px; }
.meta {
  position: absolute; right: 7px; bottom: 3px; display: inline-flex; align-items: center; gap: 3px;
  font-size: 11px; color: var(--muted); white-space: nowrap;
}
.tick-wrap { display: inline-flex; color: var(--muted); }
.tick-read { color: var(--tick-read); }
.with-meta { padding-bottom: 14px; }

.msg-menu-btn {
  position: absolute; top: 2px; right: 2px; width: 26px; height: 24px; border-radius: 0 6px 0 12px;
  display: flex; align-items: center; justify-content: center; color: var(--muted);
  background: inherit; opacity: 0; transition: opacity .15s;
}
.bubble:hover .msg-menu-btn, .msg-menu-btn:focus-visible { opacity: 1; }
@media (hover: none) { .msg-menu-btn { display: none; } }

.quote {
  border-left: 4px solid var(--accent); background: var(--quote-bg); border-radius: 6px;
  padding: 5px 8px; margin: 0 0 5px; cursor: pointer; min-width: 0; flex: 1;
}
.quote-name { font-size: 12.8px; font-weight: 500; }
.quote-text { font-size: 13px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }

/* media */
.bubble.media { padding: 3px; }
.bubble.media .text { padding: 4px 6px 2px; }
.bubble.media .sender, .bubble.media .quote { margin: 3px 3px 5px; }
.media-wrap { position: relative; border-radius: 6px; overflow: hidden; background: rgba(0, 0, 0, .08); }
.media-wrap img, .media-wrap video {
  display: block; max-width: min(330px, 100%); max-height: 360px; min-width: 120px; min-height: 80px; object-fit: cover; cursor: pointer;
}
.bubble.no-caption .meta {
  color: #fff; right: 8px; bottom: 7px; padding: 0 4px; border-radius: 4px;
  background: linear-gradient(transparent, rgba(0, 0, 0, .35)); text-shadow: 0 1px 1px rgba(0, 0, 0, .4);
}
.bubble.no-caption .tick-wrap, .bubble.no-caption .tick-read { color: #fff; }
.bubble.media video + .progress, .bubble.media img + .progress { pointer-events: none; }
.progress {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .35); color: #fff; font-weight: 600;
}
.with-meta .progress { position: static; background: none; color: var(--muted); font-size: 12px; font-weight: 400; padding-top: 4px; }

/* files */
.file-card {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 6px;
  background: var(--quote-bg); color: inherit; text-decoration: none; min-width: 240px; max-width: 320px;
}
.file-icon {
  width: 38px; height: 46px; border-radius: 4px; background: #f15c6d; color: #fff; font-size: 10px; font-weight: 700;
  display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; flex-shrink: 0;
}
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-size { font-size: 12px; color: var(--muted); }
.file-dl { color: var(--muted); border: 1px solid var(--muted); border-radius: 50%; padding: 5px; }
.audio-name { font-size: 13px; margin-bottom: 4px; }
.bubble audio { width: 260px; max-width: 100%; height: 40px; }

/* voice */
.voice { display: flex; align-items: center; gap: 8px; width: 290px; max-width: 100%; }
.voice-avatar { position: relative; }
.voice-mic { position: absolute; bottom: -3px; right: -4px; color: var(--accent); }
.out .voice-avatar { order: 3; }
.out .voice-mic { right: auto; left: -4px; }
.with-meta:has(.voice) { padding-bottom: 16px; }
.vp-btn { color: var(--muted); width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; }
.vp-track { flex: 1; min-width: 0; position: relative; padding-bottom: 6px; }
.vp-bar { width: 100%; accent-color: var(--accent); margin: 8px 0 0; height: 4px; }
.vp-time { position: absolute; left: 0; top: 22px; font-size: 11px; color: var(--muted); }

/* call log */
.call-msg { display: flex; align-items: center; gap: 10px; padding: 4px 2px; text-align: left; min-width: 200px; }
.call-msg-icon {
  width: 38px; height: 38px; border-radius: 50%; background: var(--quote-bg); color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
}
.call-msg-icon.missed { color: var(--danger); }
.call-msg-text { display: flex; flex-direction: column; flex: 1; }
.call-msg-title { font-size: 14.5px; }
.call-msg-sub { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 3px; }
.call-msg-sub.missed svg { color: var(--danger); }

.scroll-down {
  position: absolute; right: 20px; bottom: 80px; width: 42px; height: 42px; border-radius: 50%; z-index: 5;
  background: var(--panel); color: var(--muted); box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center;
}
.drop-hint {
  position: absolute; inset: 60px 0 0; z-index: 20; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 168, 132, .15); border: 3px dashed var(--accent); font-size: 20px; color: var(--accent-strong);
  pointer-events: none;
}

/* ---------- composer ---------- */
.reply-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px 0 16px; background: var(--panel-2);
}
.reply-bar .quote { margin: 0; }
.composer {
  display: flex; align-items: flex-end; gap: 4px; padding: 8px 12px; background: var(--panel-2); flex-shrink: 0;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}
.composer .icon-btn { width: 42px; height: 42px; }
#msg-input {
  flex: 1; resize: none; border: 0; outline: none; border-radius: 8px; padding: 10px 12px; margin: 0 4px;
  background: var(--input-bg); line-height: 21px; max-height: 140px; min-height: 42px;
}
.send-btn { color: var(--muted); }
.send-btn[data-mode="send"], #rec-send { background: var(--accent); color: #fff; }
.send-btn[data-mode="send"]:hover, #rec-send:hover { background: var(--accent-strong); }
.recorder { align-items: center; gap: 12px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse 1s infinite; }
.rec-time { font-variant-numeric: tabular-nums; font-size: 16px; }
.rec-label { flex: 1; color: var(--muted); }
@keyframes pulse { 50% { opacity: .2; } }

.emoji-panel {
  position: absolute; bottom: 62px; left: 8px; z-index: 10; width: min(360px, calc(100% - 16px));
  max-height: 260px; overflow-y: auto; padding: 8px; border-radius: 12px; background: var(--panel); box-shadow: var(--shadow);
  display: grid; grid-template-columns: repeat(auto-fill, minmax(38px, 1fr));
}
.emoji { font-size: 24px; height: 40px; border-radius: 8px; }
.emoji:hover { background: var(--panel-2); }
.attach-menu {
  position: absolute; bottom: 62px; left: 52px; z-index: 10; padding: 8px 0; border-radius: 12px;
  background: var(--panel); box-shadow: var(--shadow); min-width: 200px;
}
.attach-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 18px; text-align: left; }
.attach-item:hover { background: var(--hover); }
.attach-icon { width: 36px; height: 36px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: #fff; }
.attach-icon svg { width: 20px; height: 20px; }
.attach-icon.media { background: #bf59cf; }
.attach-icon.doc { background: #7f66ff; }

/* ---------- popups ---------- */
.context-menu {
  position: fixed; z-index: 300; min-width: 190px; padding: 6px 0; border-radius: 10px;
  background: var(--panel); box-shadow: var(--shadow);
}
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 18px; text-align: left; }
.menu-item:hover { background: var(--hover); }
.menu-item span { color: var(--muted); }
.menu-item.danger, .menu-item.danger span { color: var(--danger); }

.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 20px); z-index: 400; max-width: calc(100% - 32px);
  padding: 12px 20px; border-radius: 8px; background: #323739; color: #fff; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200; background: rgba(11, 20, 26, .55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  width: 100%; max-width: 440px; max-height: 88vh; max-height: 88dvh; display: flex; flex-direction: column;
  background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); overflow: hidden;
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 10px 22px; background: var(--panel-2); }
.modal-header h3 { margin: 0; font-weight: 500; font-size: 18px; }
.modal-body { padding: 16px 22px 20px; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.profile-avatar { display: flex; justify-content: center; margin: 8px auto 12px; position: relative; width: 150px; border-radius: 50%; }
.profile-avatar.editable { cursor: pointer; }
.avatar-overlay {
  position: absolute; inset: 0; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .4); color: #fff; opacity: 0; transition: opacity .15s;
}
.profile-avatar.editable:hover .avatar-overlay, .profile-avatar.editable:focus-visible .avatar-overlay { opacity: 1; }
@media (hover: none) { .avatar-overlay { opacity: .7; } }
.info-name { text-align: center; font-size: 22px; margin-top: 4px; }
.info-actions { display: flex; justify-content: center; gap: 12px; margin: 16px 0; }
.info-action {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 22px; border-radius: 10px;
  border: 1px solid var(--border); color: var(--accent-strong); font-size: 13px;
}
.info-action:hover { background: var(--hover); }
.info-section { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 4px; }
.section-title { color: var(--accent-strong); font-size: 14px; margin: 16px 0 6px; }
.caption-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; }

.new-group-row { display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 4px; margin-bottom: 8px; text-align: left; border-radius: 8px; }
.new-group-row:hover { background: var(--hover); }
.round-icon { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }

.picker .input { margin-bottom: 4px; }
.picker-results { min-height: 120px; }
.user-row { display: flex; align-items: center; gap: 12px; padding: 8px 4px; border-radius: 8px; }
.user-row.clickable { cursor: pointer; }
.user-row.clickable:hover { background: var(--hover); }
.user-row-text { flex: 1; min-width: 0; }
.user-row-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.check {
  width: 22px; height: 22px; border-radius: 4px; border: 2px solid var(--muted); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; color: #fff;
}
.check.on { background: var(--accent); border-color: var(--accent); }
.tag { font-size: 11.5px; color: var(--accent-strong); background: rgba(0, 168, 132, .12); padding: 2px 8px; border-radius: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 2px; border-radius: 16px; background: var(--panel-2); font-size: 13px; }
.chip-x { width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.member-list { margin-top: 4px; }

.preview-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; }
.preview-grid.single { grid-template-columns: 1fr; }
.preview-item { border-radius: 8px; overflow: hidden; background: var(--panel-2); min-height: 120px; display: flex; align-items: center; justify-content: center; }
.preview-item img, .preview-item video { width: 100%; height: 100%; max-height: 50vh; object-fit: contain; display: block; }
.preview-grid:not(.single) .preview-item img, .preview-grid:not(.single) .preview-item video { height: 120px; object-fit: cover; }
.preview-item.file { flex-direction: column; gap: 6px; padding: 16px; color: var(--muted); text-align: center; }
.preview-item.file .file-name { color: var(--text); max-width: 100%; }

/* ---------- lightbox ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 250; background: rgba(11, 20, 26, .95); color: #e9edef;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.lightbox-bar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.lightbox-bar .icon-btn { color: #e9edef; }
.lightbox-title { flex: 1; }
.lightbox img { max-width: 92vw; max-height: calc(100vh - 140px); object-fit: contain; }
.lightbox-caption { margin-top: 14px; max-width: 80vw; text-align: center; white-space: pre-wrap; }

/* ---------- call screen ---------- */
.call-screen {
  position: fixed; inset: 0; z-index: 500; background: #0b141a; color: #fff; overflow: hidden;
  display: flex; flex-direction: column; align-items: center; justify-content: space-between;
}
.remote-video, .local-video { position: absolute; object-fit: cover; background: #000; display: none; }
.remote-video { inset: 0; width: 100%; height: 100%; }
.local-video {
  right: 16px; bottom: 120px; width: 120px; height: 170px; border-radius: 10px; z-index: 2;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .5);
}
.local-video.mirror { transform: scaleX(-1); }
@media (min-width: 800px) { .local-video { width: 220px; height: 150px; } }
/* video call: show my camera full screen until the other side's video arrives */
.call-screen.video .local-video { display: block; }
.call-screen.video:not(.has-remote) .local-video { inset: 0; width: 100%; height: 100%; border-radius: 0; z-index: 0; }
.call-screen.video.has-remote .remote-video { display: block; }
.call-screen.video.has-remote:not(.peer-camera-off) .call-avatar { display: none; }
.call-screen.peer-camera-off .remote-video { visibility: hidden; }
.call-screen.my-camera-off .local-video { visibility: hidden; }

.call-info {
  position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 10px;
  padding: 56px 16px 0; text-shadow: 0 1px 3px rgba(0, 0, 0, .6); text-align: center;
}
.call-kind { display: flex; align-items: center; gap: 6px; font-size: 13px; opacity: .8; }
.call-avatar { margin: 24px 0 8px; }
.call-name { font-size: 26px; }
.call-status { font-size: 15px; opacity: .85; font-variant-numeric: tabular-nums; }
.call-screen.video.has-remote .call-info { padding-top: 20px; }
.call-screen.video.has-remote .call-kind { display: none; }

.call-controls {
  position: relative; z-index: 3; display: flex; gap: 20px; justify-content: center; align-items: center;
  padding: 24px 16px max(32px, env(safe-area-inset-bottom));
}
.call-btn {
  width: 58px; height: 58px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: rgba(255, 255, 255, .15); color: #fff; transition: background .15s;
}
.call-btn:hover { background: rgba(255, 255, 255, .25); }
.call-btn.off { background: #fff; color: #111b21; }
.call-btn.end { background: #f15c6d; }
.call-btn.end:hover { background: #e0384c; }
.call-btn.accept { background: #00a884; animation: ring 1.2s infinite; }
.call-btn-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; font-size: 13px; }
.incoming-controls { gap: 80px; }
.call-screen .incoming-controls { display: none; }
.call-screen.incoming .incoming-controls { display: flex; }
.call-screen.incoming .active-controls { display: none; }
.call-screen:not(.video) .cam-only { display: none; }
.call-screen.ended .call-controls { visibility: hidden; }
@keyframes ring { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }
