/* ============================================================
   SecureDev Messenger — Premium Design System
   Inspiré de Teams · WhatsApp · Telegram · Signal
   ============================================================ */

/* ── Variables ──────────────────────────────────────────────── */
:root {
  color-scheme: dark;

  /* Backgrounds */
  --bg:          #0b0d16;
  --panel:       #10131f;
  --panel-2:     #161929;
  --panel-3:     #1c2035;
  --card:        #1e2236;

  /* Borders */
  --line:        rgba(255,255,255,.065);
  --line-strong: rgba(255,255,255,.11);

  /* Text */
  --text:        #e8eaed;
  --text-2:      #aab0bf;
  --muted:       #6b7489;

  /* Accents */
  --accent:      #5b8dee;
  --accent-h:    #4a7de8;
  --accent-soft: rgba(91,141,238,.13);
  --accent-2:    #22c55e;
  --accent-2-soft: rgba(34,197,94,.1);

  /* Message bubbles */
  --msg-out:     #17306b;
  --msg-out-b:   rgba(91,141,238,.28);
  --msg-in:      #1a1d2e;
  --msg-in-b:    rgba(255,255,255,.06);

  /* Status colors */
  --online:      #22c55e;
  --danger:      #ef4444;
  --warning:     #f59e0b;

  /* Shadows */
  --shadow-sm:   0 2px 8px rgba(0,0,0,.25);
  --shadow-md:   0 8px 28px rgba(0,0,0,.38);
  --shadow-lg:   0 24px 64px rgba(0,0,0,.55);

  /* Radius */
  --r-sm:  6px;
  --r-md:  10px;
  --r-lg:  16px;
  --r-xl:  22px;
  --r-pill:999px;

  /* Misc */
  --touch: 44px;
  --sidebar: 300px;
  --code-bg: #07091a;

  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ── Light mode ─────────────────────────────────────────────── */
:root.light {
  color-scheme: light;
  --bg:          #f0f2f8;
  --panel:       #ffffff;
  --panel-2:     #eef1f8;
  --panel-3:     #e4e8f2;
  --card:        #ffffff;
  --line:        rgba(0,0,0,.08);
  --line-strong: rgba(0,0,0,.13);
  --text:        #111827;
  --text-2:      #4b5563;
  --muted:       #9ca3af;
  --accent-soft: rgba(91,141,238,.1);
  --msg-out:     #dbeafe;
  --msg-out-b:   rgba(91,141,238,.25);
  --msg-in:      #f9fafb;
  --msg-in-b:    rgba(0,0,0,.07);
  --code-bg:     #1e2235;
  --shadow-sm:   0 2px 8px rgba(0,0,0,.08);
  --shadow-md:   0 8px 24px rgba(0,0,0,.12);
  --shadow-lg:   0 20px 50px rgba(0,0,0,.15);
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  line-height: 1.5;
}
h1,h2,h3,p { margin: 0; }
button, input, textarea, select { font: inherit; }
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  border-radius: var(--r-md);
  min-height: var(--touch);
  padding: 0 14px;
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
button:hover:not(:disabled) {
  background: var(--panel-3);
  border-color: var(--line-strong);
}
button:active:not(:disabled) { transform: scale(.97); }
button:disabled { opacity: .45; cursor: not-allowed; }
input, textarea, select {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--r-md);
  min-height: var(--touch);
  padding: 10px 13px;
  outline: none;
  transition: border-color .15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.hidden { display: none !important; }

/* ── App shell ──────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  height: 100dvh;
  overflow: hidden;
}
.app.logged-out {
  grid-template-columns: minmax(300px, 420px);
  justify-content: center;
  align-content: center;
  padding: 24px;
  background: radial-gradient(ellipse 80% 60% at 50% 0%, rgba(91,141,238,.08) 0%, transparent 70%);
}
.app.logged-out .sidebar {
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-lg);
  background: var(--panel);
}
.app.logged-out .chat { display: none; }

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  padding: 0;
}
.sidebar > * { flex-shrink: 0; }

/* Brand */
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(18px, env(safe-area-inset-top)) 18px 14px;
  border-bottom: 1px solid var(--line);
}
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--accent), #7c5fe6);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(91,141,238,.35);
}
.brand-info { min-width: 0; }
.brand-info strong { display: block; font-size: 14px; font-weight: 700; }
.brand-info span, .brand span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}
#presence { display: flex; align-items: center; gap: 5px; }
#presence::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  transition: background .3s;
}
#presence.online::before { background: var(--online); }

/* Auth panel */
.auth-panel { padding: 24px; }

/* Main nav */
#mainNav { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.userline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px 10px;
  border-bottom: 1px solid var(--line);
}
.userline #userName { font-size: 13px; color: var(--text-2); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.userline button, .quick-row button {
  border-radius: var(--r-md);
  min-height: 34px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
}
.quick-row {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
}
.quick-row > * { flex: 1; }
#newConversationBtn {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
#newConversationBtn:hover:not(:disabled) {
  background: var(--accent-h);
  border-color: var(--accent-h);
}
.search-wrap { padding: 10px 14px; border-bottom: 1px solid var(--line); }
.search-wrap input {
  border-radius: var(--r-pill);
  padding: 8px 14px;
  font-size: 13px;
  background: var(--panel-2);
  min-height: 36px;
}

/* Section labels */
h2 {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 14px 16px 6px;
}

/* Lists */
.list { display: flex; flex-direction: column; }
.compact { gap: 2px; }

.sidebar-section { border-bottom: 1px solid var(--line); padding-bottom: 8px; }

/* Conversation/contact rows */
.conversation-row,
.contact-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 10px 14px;
  min-height: auto;
  transition: background .12s;
  position: relative;
}
.conversation-row:hover, .contact-row:hover { background: var(--panel-2); }
.conversation-row.active {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  padding-left: 11px;
}
.conv-info, .contact-info { flex: 1; min-width: 0; }
.conv-info strong, .contact-info strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text);
}
.conv-info span, .contact-info span {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 1px;
}
.conv-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  border-radius: var(--r-pill);
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  padding: 0 5px;
  flex-shrink: 0;
}

/* Request rows */
.request-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 12.5px;
}
.request-row strong { flex: 1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.request-row button {
  min-height: 28px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--r-pill);
}

/* Invite form */
.invite-wrap { padding: 8px 14px; }
.inline-form { display: grid; grid-template-columns: 1fr 38px; gap: 6px; }
.inline-form input { min-height: 36px; font-size: 13px; }
.inline-form button { min-height: 36px; padding: 0; width: 38px; border-radius: var(--r-md); font-size: 18px; }

/* Empty states */
.empty-state {
  font-size: 12.5px;
  color: var(--muted);
  padding: 10px 14px;
  line-height: 1.5;
}

/* ── Avatar ─────────────────────────────────────────────────── */
.avatar {
  width: 38px;
  height: 38px;
  border-radius: var(--r-md);
  background: linear-gradient(135deg, var(--accent), #7c5fe6);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  position: relative;
  user-select: none;
}
.avatar.sm { width: 30px; height: 30px; font-size: 10px; border-radius: var(--r-sm); }
.avatar.round { border-radius: 50%; }
.avatar-status {
  position: absolute;
  bottom: -2px; right: -2px;
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--online);
  border: 2px solid var(--panel);
}

/* Avatar colors by initials hash */
.avatar[data-color="0"] { background: linear-gradient(135deg,#5b8dee,#7c5fe6); }
.avatar[data-color="1"] { background: linear-gradient(135deg,#22c55e,#16a34a); }
.avatar[data-color="2"] { background: linear-gradient(135deg,#f59e0b,#d97706); }
.avatar[data-color="3"] { background: linear-gradient(135deg,#ef4444,#dc2626); }
.avatar[data-color="4"] { background: linear-gradient(135deg,#ec4899,#db2777); }
.avatar[data-color="5"] { background: linear-gradient(135deg,#14b8a6,#0d9488); }

/* ── Auth forms ─────────────────────────────────────────────── */
.auth-form, .dialog-form { display: grid; gap: 14px; }
label { display: grid; gap: 5px; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.form-error {
  background: rgba(239,68,68,.1);
  border: 1px solid rgba(239,68,68,.3);
  border-radius: var(--r-md);
  color: #fca5a5;
  padding: 9px 12px;
  font-size: 13px;
}
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  background: var(--panel-2);
  border-radius: var(--r-md);
  padding: 4px;
}
.tab {
  border-radius: var(--r-sm);
  border-color: transparent;
  background: transparent;
  min-height: 36px;
  font-size: 13px;
  font-weight: 600;
  transition: background .15s;
}
.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(91,141,238,.35);
}

/* ── Panel / card ───────────────────────────────────────────── */
.panel {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 16px;
}

/* ── Chat layout ────────────────────────────────────────────── */
.chat {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  background: var(--bg);
  position: relative;
}

/* ── Chat header ────────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: max(14px, env(safe-area-inset-top)) 20px 14px;
  background: rgba(16,19,31,.82);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-bottom: 1px solid var(--line);
  z-index: 10;
}
:root.light .chat-header { background: rgba(255,255,255,.85); }
.back-btn {
  display: none;
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 22px;
  border-radius: var(--r-md);
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
.back-btn:hover { background: var(--panel-2); border-color: var(--line); color: var(--text); }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header h1 {
  font-size: 16px;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chat-header p { font-size: 12px; color: var(--muted); }
.header-actions { display: flex; gap: 6px; }
.header-actions button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: var(--r-md);
  font-size: 17px;
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
}
.header-actions button:hover { background: var(--panel-2); border-color: var(--line); color: var(--text); }
#callBtn { color: var(--accent); }

/* ── Messages area ──────────────────────────────────────────── */
.messages, .admin-view {
  overflow-y: auto;
  overflow-x: hidden;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scroll-behavior: smooth;
  min-height: 0;
}

/* Date separator */
.date-separator {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 14px 0 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .05em;
}
.date-separator::before, .date-separator::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--line);
}

/* ── Message bubbles ────────────────────────────────────────── */
.msg-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 8px;
}
.msg-group.mine { align-items: flex-end; }
.msg-group:not(.mine) { align-items: flex-start; }

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: min(72%, 660px);
}
.msg-group.mine .msg-row { flex-direction: row-reverse; }
/* Only animate genuinely new messages — not on full re-render */
.msg-row.new { animation: msgIn .22s cubic-bezier(0,0,.2,1); }

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-avatar { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; font-size: 9px; font-weight: 700; }
.msg-avatar.invisible { visibility: hidden; }

.msg-bubble {
  background: var(--msg-in);
  border: 1px solid var(--msg-in-b);
  border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 4px;
  padding: 9px 13px;
  box-shadow: var(--shadow-sm);
  cursor: default;
  position: relative;
  min-width: 60px;
}
.msg-group.mine .msg-bubble {
  background: var(--msg-out);
  border-color: var(--msg-out-b);
  border-radius: var(--r-lg) var(--r-lg) 4px var(--r-lg);
  box-shadow: var(--shadow-sm), 0 0 0 1px rgba(91,141,238,.08);
}
:root.light .msg-group:not(.mine) .msg-bubble { background: #fff; border-color: var(--line); }
:root.light .msg-group.mine .msg-bubble { background: #dbeafe; }

/* First in group: show tail */
.msg-bubble.first-in-group:not(.mine) { border-radius: var(--r-lg) var(--r-lg) var(--r-lg) 4px; }

/* Sender name above bubble */
.msg-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 3px;
  padding-left: 2px;
}
.msg-group.mine .msg-sender { color: var(--text-2); text-align: right; padding-right: 2px; }

/* Message body */
.msg-body {
  font-size: 14px;
  line-height: 1.55;
  color: var(--text);
  overflow-wrap: anywhere;
  word-break: break-word;
}
:root.light .msg-group.mine .msg-body { color: #1e3a6e; }
.msg-body.scrambled { color: var(--muted); font-family: monospace; letter-spacing: .05em; user-select: none; }
.msg-body.deleted { color: var(--muted); font-style: italic; }

/* Code block in message */
.msg-body pre {
  background: var(--code-bg);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 12px 14px;
  margin: 8px 0 0;
  overflow-x: auto;
}
.msg-body code { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12.5px; color: #7dd3fc; }
.msg-body pre code { display: block; }
.code-frame {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--code-bg);
  overflow: hidden;
  margin-top: 6px;
}
.code-frame pre {
  margin: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  font-family: "SFMono-Regular", Consolas, monospace;
}
.code-head button {
  min-height: 24px;
  padding: 0 8px;
  font-size: 11px;
  border-radius: var(--r-md);
}
.code-head button.copied,
.msg-actions button.copied {
  background: rgba(34,197,94,.14);
  border-color: rgba(34,197,94,.28);
  color: #22c55e;
}
.tok-key { color: #c084fc; font-weight: 650; }
.tok-str { color: #86efac; }
.tok-num { color: #fbbf24; }
.tok-comment { color: #94a3b8; font-style: italic; }
.tok-fn { color: #7dd3fc; }
.tok-prop { color: #93c5fd; }
.inline-logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 20px;
  padding: 0 6px;
  margin: 0 2px;
  border-radius: 6px;
  font-size: 10.5px;
  line-height: 1;
  font-weight: 800;
  letter-spacing: 0;
  vertical-align: text-bottom;
  background: #334155;
  color: #fff;
  border: 1px solid rgba(255,255,255,.12);
}
.inline-logo.js { background: #f7df1e; color: #111827; }
.inline-logo.ts { background: #3178c6; }
.inline-logo.py { background: #3776ab; }
.inline-logo.php { background: #777bb4; }
.inline-logo.html { background: #e34f26; }
.inline-logo.css { background: #1572b6; }
.inline-logo.docker { background: #2496ed; }
.inline-logo.linux { background: #111827; color: #facc15; }
.inline-logo.db { background: #0f766e; }
.inline-logo.api { background: #7c3aed; }
.inline-logo.git { background: #f05032; }
.inline-thumb {
  display: inline-block;
  max-width: min(112px, 100%);
  max-height: 84px;
  margin: 2px 4px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  vertical-align: middle;
  object-fit: cover;
  background: var(--panel-2);
}
.inline-image-wrap {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 170px;
  margin: 2px 4px;
  padding: 3px 6px 3px 3px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--panel-2);
  vertical-align: middle;
}
.inline-image-wrap .inline-thumb {
  margin: 0;
  width: 44px;
  height: 34px;
  flex-shrink: 0;
}
.inline-image-wrap span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-2);
  font-size: 11px;
}
.inline-image-missing {
  display: inline-flex;
  padding: 1px 6px;
  border-radius: var(--r-pill);
  background: rgba(239,68,68,.12);
  color: var(--danger);
  font-size: 11px;
}
.alias-ref {
  display: inline-flex;
  align-items: center;
  padding: 0 6px;
  min-height: 20px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
}
.md h1, .md h2, .md h3, .md h4, .md h5, .md h6 {
  margin: 6px 0 4px;
  line-height: 1.25;
}
.md h1 { font-size: 18px; }
.md h2 { font-size: 16px; }
.md h3, .md h4, .md h5, .md h6 { font-size: 14px; }
.md blockquote {
  margin: 6px 0;
  padding: 6px 10px;
  border-left: 3px solid var(--accent);
  background: rgba(91,141,238,.08);
  border-radius: var(--r-sm);
}
.md-li {
  position: relative;
  padding-left: 18px;
}
.md-li::before {
  content: "•";
  position: absolute;
  left: 3px;
  color: var(--accent);
}
.md-li.ordered::before { content: "•"; }

/* Message time + status */
.msg-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 5px;
  margin-top: 5px;
}
.msg-time {
  font-size: 10.5px;
  color: var(--muted);
  white-space: nowrap;
}
.msg-group.mine .msg-time { color: rgba(91,141,238,.7); }
:root.light .msg-group.mine .msg-time { color: rgba(30,58,110,.55); }
.msg-status {
  font-size: 11px;
  color: var(--accent);
  line-height: 1;
}
.msg-pinned { font-size: 10px; color: var(--warning); margin-left: 4px; }
.msg-expires { font-size: 10px; color: var(--muted); }

/* Message hover actions */
.msg-bubble { outline: none; }
.msg-actions {
  display: none;
  gap: 3px;
  position: absolute;
  top: -34px;
  right: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  padding: 4px 6px;
  box-shadow: var(--shadow-md);
  z-index: 20;
  white-space: nowrap;
}
.msg-group.mine .msg-actions { right: auto; left: 0; }
.msg-bubble:hover .msg-actions,
.msg-bubble:focus-within .msg-actions,
.msg-bubble.actions-open .msg-actions { display: flex; }
.msg-actions button {
  min-height: 26px;
  padding: 0 8px;
  font-size: 11.5px;
  border-radius: var(--r-pill);
  background: transparent;
  border-color: transparent;
  color: var(--text-2);
  font-weight: 500;
}
.msg-actions button:hover { background: var(--panel-2); color: var(--text); }
.msg-actions button.danger { color: var(--danger); }
.msg-actions button.danger:hover { background: rgba(239,68,68,.1); }

.msg-menu-btn {
  min-height: 22px;
  min-width: 24px;
  padding: 0 6px;
  border-radius: var(--r-pill);
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  line-height: 1;
}
.msg-menu-btn:hover,
.msg-bubble.actions-open .msg-menu-btn {
  background: var(--panel-2);
  color: var(--text);
}

.msg-reveal-countdown {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: fit-content;
  max-width: 100%;
  min-height: 28px;
  margin-top: 8px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.msg-reveal-countdown.hidden { display: none; }

/* Reveal overlay */
.msg-reveal-overlay {
  position: absolute;
  inset: 0;
  border-radius: inherit;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,13,22,.7);
  backdrop-filter: blur(4px);
  cursor: pointer;
  transition: opacity .2s;
}
.msg-reveal-overlay:hover { background: rgba(10,13,22,.6); }
.msg-reveal-overlay span { font-size: 12px; color: var(--text-2); }

/* ── Typing indicator ───────────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 0;
  min-height: 24px;
  font-size: 12px;
  color: var(--muted);
  transition: opacity .2s;
}
.typing-indicator.hidden { opacity: 0; pointer-events: none; }
.typing-dots { display: flex; gap: 3px; align-items: center; }
.typing-dots span {
  width: 5px; height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: .15s; }
.typing-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ── Skeleton loaders ───────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg, var(--panel-2) 25%, var(--panel-3) 50%, var(--panel-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite linear;
  border-radius: var(--r-md);
}
@keyframes shimmer {
  from { background-position: 200% 0; }
  to   { background-position: -200% 0; }
}
.skeleton-msg {
  height: 52px;
  width: 55%;
  margin-bottom: 10px;
  border-radius: var(--r-lg);
}
.skeleton-msg.mine { margin-left: auto; width: 45%; }

/* ── Markdown ───────────────────────────────────────────────── */
.md h1, .md h2, .md h3 { margin: 8px 0 4px; color: var(--text); text-transform: none; letter-spacing: 0; }
.md h1 { font-size: 18px; }
.md h2 { font-size: 15px; }
.md h3 { font-size: 13px; }
.md a { color: var(--accent); }
.md blockquote {
  border-left: 3px solid var(--accent);
  margin: 6px 0;
  padding: 4px 10px;
  color: var(--text-2);
  background: var(--accent-soft);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
}

/* ── File card ──────────────────────────────────────────────── */
.file-card { display: grid; gap: 10px; }
.file-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
}
.file-icon {
  width: 42px; height: 42px;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 800;
  color: var(--accent);
  flex-shrink: 0;
}
.file-card-header-info { flex: 1; min-width: 0; }
.file-card-header-info strong {
  display: block;
  font-size: 13px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.file-card-header-info span {
  display: block;
  font-size: 11px;
  color: var(--muted);
}
.file-preview { border-radius: var(--r-md); overflow: hidden; }
.file-preview img, .file-preview video {
  display: block;
  width: 100%;
  max-height: 56vh;
  object-fit: contain;
  border-radius: var(--r-md);
  background: #000;
}
.file-preview iframe,
.file-preview object {
  display: block;
  width: 100%;
  height: min(56vh, 600px);
  border: none;
}
.file-preview audio { width: 100%; }
.file-preview pre {
  background: var(--code-bg);
  border-radius: var(--r-md);
  padding: 12px;
  max-height: 44vh;
  overflow-y: auto;
}
.file-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.file-card-actions button {
  min-height: 32px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: var(--r-md);
}
.file-card-actions button:disabled,
.file-dl-btn:disabled {
  opacity: .65;
  cursor: wait;
}
.file-transfer {
  display: grid;
  gap: 6px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-2);
}
.file-transfer.hidden { display: none; }
.file-transfer-label {
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.35;
}
.file-transfer-bar,
.composer-progress {
  display: block;
  overflow: hidden;
  height: 6px;
  border-radius: var(--r-pill);
  background: rgba(148,163,184,.18);
}
.file-transfer-bar span,
.composer-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
  transition: width .2s ease;
}
.file-transfer.done .file-transfer-bar span { background: #22c55e; }
.file-transfer.indeterminate .file-transfer-bar span {
  width: 45% !important;
  animation: transferIndeterminate 1.1s ease-in-out infinite;
}
@keyframes transferIndeterminate {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(240%); }
}
.file-large-note {
  padding: 8px 10px;
  border-radius: var(--r-md);
  background: rgba(251,191,36,.09);
  border: 1px solid rgba(251,191,36,.18);
  color: var(--text-2);
  font-size: 12px;
  line-height: 1.35;
}
.preview-loader {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px;
  color: var(--text-2);
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
}
.preview-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.preview-toolbar a,
.preview-unavailable a {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  color: var(--accent);
  background: var(--panel-2);
  text-decoration: none;
  font-size: 12px;
}
.preview-unavailable {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 12px;
}
.preview-spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(148,163,184,.3);
  border-top-color: var(--accent);
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Paste preview ──────────────────────────────────────────── */
.paste-preview {
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 8px 12px;
  margin-bottom: 8px;
  font-size: 13px;
}
.paste-preview span { flex: 1; color: var(--text-2); }
.paste-preview button { min-height: 28px; padding: 0 10px; font-size: 11px; border-radius: var(--r-md); }

/* ── Composer ───────────────────────────────────────────────── */
.composer {
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding: 10px 14px max(12px, env(safe-area-inset-bottom));
}
.drop-zone {
  display: none;
  border: 1.5px dashed var(--accent);
  border-radius: var(--r-lg);
  padding: 14px;
  margin-bottom: 10px;
  text-align: center;
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  animation: dz-pulse 1.6s ease-in-out infinite;
}
.drop-zone.visible { display: block; }
@keyframes dz-pulse {
  0%, 100% { border-color: var(--accent); }
  50% { border-color: rgba(91,141,238,.4); }
}
.composer-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  padding: 10px 12px;
  margin-bottom: 10px;
}
.composer-tools select, .composer-tools input {
  min-height: 36px;
  font-size: 13px;
  max-width: 180px;
  flex: 1 1 140px;
}
.composer-tools button {
  min-height: 34px;
  padding: 0 12px;
  font-size: 12.5px;
  flex-shrink: 0;
}
.composer-mode-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 100%;
  min-height: 36px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: rgba(255,255,255,.03);
}
.composer-mode-panel > span {
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  min-width: 72px;
}
.composer-mode-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.mode-chip {
  min-height: 26px !important;
  padding: 0 9px !important;
  border-radius: var(--r-pill) !important;
  font-size: 11.5px !important;
  background: var(--panel) !important;
}
.mode-chip.active,
.mode-chip:hover {
  border-color: var(--accent) !important;
  color: var(--accent) !important;
  background: var(--accent-soft) !important;
}
.composer-status {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 30px;
  margin: 0 0 8px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--panel-2);
  color: var(--text-2);
  font-size: 12.5px;
}
.composer-status-label {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.composer-progress {
  width: min(160px, 28vw);
  flex-shrink: 0;
}
.composer-status::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}
.composer-status.working::before {
  animation: statusPulse 1s ease-in-out infinite;
}
.composer-status.recording {
  border-color: rgba(239,68,68,.26);
  background: rgba(239,68,68,.1);
}
.composer-status.recording::before {
  background: #ef4444;
  animation: statusPulse .75s ease-in-out infinite;
}
.composer-status.done::before { background: #22c55e; }
@keyframes statusPulse {
  0%, 100% { opacity: .45; transform: scale(.85); }
  50% { opacity: 1; transform: scale(1.25); }
}
.message-form {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
#messageInput {
  flex: 1;
  resize: none;
  max-height: 30vh;
  min-height: var(--touch);
  line-height: 1.5;
  border-radius: var(--r-xl);
  padding: 11px 16px;
  font-size: 14px;
  background: var(--panel-2);
  border-color: var(--line);
  transition: border-color .15s, box-shadow .15s;
}
#messageInput:focus { border-color: var(--line-strong); box-shadow: none; }
.composer-icon {
  width: var(--touch);
  min-height: var(--touch);
  padding: 0;
  border-radius: var(--r-pill);
  font-size: 20px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  transition: background .15s, color .15s;
  flex-shrink: 0;
}
.composer-icon:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.composer-icon.active { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.send-btn {
  width: var(--touch);
  min-height: var(--touch);
  padding: 0;
  border-radius: var(--r-pill);
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(91,141,238,.35);
  transition: background .15s, transform .1s, box-shadow .15s;
}
.send-btn:hover:not(:disabled) {
  background: var(--accent-h);
  border-color: var(--accent-h);
  box-shadow: 0 4px 18px rgba(91,141,238,.5);
}
.send-btn:disabled { background: var(--panel-3); border-color: var(--line); box-shadow: none; color: var(--muted); }
.send-btn.sending {
  opacity: .85;
  cursor: progress;
}
.file-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  width: var(--touch);
  min-height: var(--touch);
  border-radius: var(--r-pill);
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  font-size: 20px;
  transition: background .15s, color .15s;
}
.file-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.file-btn input { display: none; }

/* Voice record button */
.record-btn {
  width: var(--touch);
  min-height: var(--touch);
  padding: 0;
  border-radius: var(--r-pill);
  font-size: 18px;
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  flex-shrink: 0;
  transition: background .15s, color .15s;
}
.record-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.record-btn.recording {
  background: rgba(239,68,68,.12);
  color: var(--danger);
  border-color: rgba(239,68,68,.3);
  animation: recordPulse 1s ease-in-out infinite;
}
@keyframes recordPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.4); }
  50% { box-shadow: 0 0 0 6px rgba(239,68,68,.0); }
}

/* ── Dialogs ────────────────────────────────────────────────── */
dialog {
  width: min(700px, calc(100vw - 28px));
  max-height: min(880px, calc(100dvh - 28px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-xl);
  background: var(--panel);
  color: var(--text);
  padding: 24px;
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(0,0,0,.65); backdrop-filter: blur(4px); }
dialog h2 { font-size: 15px; font-weight: 700; margin-bottom: 4px; }
menu {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0;
  margin: 12px 0 0;
}
menu button { min-height: 38px; padding: 0 16px; font-size: 13px; font-weight: 600; }
menu button[value="default"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
menu button[value="default"]:hover { background: var(--accent-h); }
.dialog-inline { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: start; }
.dialog-inline button { min-height: 44px; }
.lookup-result {
  background: var(--accent-soft);
  border: 1px solid rgba(91,141,238,.2);
  border-radius: var(--r-md);
  padding: 10px 12px;
  font-size: 13px;
  color: var(--text-2);
}

/* Member picker */
.member-picker {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 8px;
}
.member-card {
  display: flex;
  align-items: center;
  gap: 9px;
  text-align: left;
  padding: 9px 10px;
  border-radius: var(--r-md);
  border: 1px solid var(--line);
  background: var(--panel);
  min-height: auto;
}
.member-card.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.member-card strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-card span span { display: block; font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.selected-members { display: flex; flex-wrap: wrap; gap: 6px; }
.selected-chip {
  background: var(--accent-soft);
  border: 1px solid rgba(91,141,238,.25);
  border-radius: var(--r-pill);
  padding: 4px 10px;
  font-size: 12px;
  color: var(--accent);
  font-weight: 500;
}

/* ── Call overlay — Teams/Zoom/Meet style ───────────────────── */
video { background: #000; border-radius: var(--r-md); min-height: 80px; }

#callDialog {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  margin: 0;
  background: #050810;
  border: none;
  border-radius: 0;
  position: fixed;
  inset: 0;
  overflow: hidden;
}
#callDialog::backdrop { background: rgba(0,0,0,.95); }

/* Remote video — fills screen */
.call-remote {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  z-index: 0;
}

/* No-video placeholder */
.call-no-video {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 1;
  background: radial-gradient(ellipse 80% 60% at 50% 40%, #1a1e38 0%, #050810 100%);
}
.call-no-video .avatar {
  width: 96px; height: 96px;
  border-radius: 50%;
  font-size: 36px;
  box-shadow: 0 0 0 8px rgba(91,141,238,.15), 0 0 0 2px rgba(91,141,238,.4);
}
.call-no-video-name {
  font-size: 20px;
  font-weight: 700;
  color: rgba(255,255,255,.85);
}
.call-no-video-sub {
  font-size: 13px;
  color: rgba(255,255,255,.4);
}

/* Local PiP — draggable camera tile */
.call-pip {
  position: absolute;
  width: 192px;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: var(--r-lg);
  border: 2px solid rgba(255,255,255,.12);
  box-shadow: 0 8px 40px rgba(0,0,0,.75), 0 0 0 1px rgba(255,255,255,.05);
  right: 24px;
  bottom: 110px;
  z-index: 20;
  cursor: grab;
  transition: border-color .25s, box-shadow .25s;
}
.call-pip:hover { border-color: rgba(255,255,255,.28); box-shadow: 0 12px 48px rgba(0,0,0,.8); }
.call-pip.dragging { cursor: grabbing; }

/* Top status bar */
.call-topbar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 56px;
  background: linear-gradient(to bottom, rgba(0,0,0,.72) 0%, transparent 100%);
  pointer-events: none;
  transition: opacity .35s ease;
}
.call-topbar.controls-hidden { opacity: 0; }
.call-secure-badge {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(34,197,94,.14);
  border: 1px solid rgba(34,197,94,.3);
  border-radius: var(--r-pill);
  padding: 5px 14px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(34,197,94,.9);
}
.call-timer {
  font-size: 24px;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  text-shadow: 0 2px 12px rgba(0,0,0,.6);
}
.call-minimize-btn {
  pointer-events: auto;
  width: 36px; height: 36px;
  border-radius: var(--r-md);
  background: rgba(255,255,255,.1);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.8);
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: background .15s;
}
.call-minimize-btn:hover { background: rgba(255,255,255,.2); }
.call-status-chip {
  position: absolute;
  top: 70px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(255,255,255,.55);
  white-space: nowrap;
  text-shadow: 0 1px 4px rgba(0,0,0,.6);
  pointer-events: none;
  z-index: 31;
  transition: opacity .35s;
}
.call-status-chip.controls-hidden { opacity: 0; }

/* Remote participant name at bottom-left */
.call-remote-name {
  position: absolute;
  bottom: 110px;
  left: 24px;
  z-index: 25;
  color: rgba(255,255,255,.9);
  font-size: 15px;
  font-weight: 600;
  text-shadow: 0 1px 8px rgba(0,0,0,.8);
  pointer-events: none;
  transition: opacity .35s ease;
}
.call-remote-name.controls-hidden { opacity: 0; }

/* Controls bar — bottom centered pill */
.call-controls-bar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 30;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 8px;
  padding: 56px 24px 36px;
  background: linear-gradient(to top, rgba(0,0,0,.72) 0%, transparent 100%);
  transition: opacity .35s ease;
}
.call-controls-bar.controls-hidden { opacity: 0; pointer-events: none; }

/* Call action button */
.call-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 66px;
  border: none;
  background: rgba(255,255,255,.13);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-radius: 18px;
  padding: 13px 0 10px;
  color: #fff;
  cursor: pointer;
  transition: background .15s, transform .12s;
  min-height: auto;
  position: relative;
}
.call-btn:hover { background: rgba(255,255,255,.24); transform: translateY(-3px); }
.call-btn:active { transform: translateY(0) scale(.95); }
.call-btn.btn-active { background: var(--accent); }
.call-btn.btn-muted { background: rgba(239,68,68,.7); }
.call-btn.btn-sharing { background: rgba(34,197,94,.6); }
.call-btn-icon { font-size: 22px; line-height: 1; display: block; }
.call-btn-label {
  font-size: 10px;
  font-weight: 600;
  color: rgba(255,255,255,.75);
  white-space: nowrap;
  line-height: 1;
}
.call-btn.btn-muted .call-btn-label,
.call-btn.btn-active .call-btn-label,
.call-btn.btn-sharing .call-btn-label { color: #fff; }

/* Hang up — red, larger */
.call-hangup {
  background: #ef4444 !important;
  backdrop-filter: none;
  width: 74px;
  border-radius: 20px;
}
.call-hangup:hover { background: #dc2626 !important; }
.call-hangup .call-btn-icon { font-size: 28px; }

/* More options panel */
.call-more {
  position: absolute;
  bottom: 130px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  width: min(380px, calc(100vw - 32px));
}
.call-more.hidden { display: none; }
@keyframes callMoreIn {
  from { opacity: 0; transform: translateX(-50%) translateY(14px) scale(.97); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}
.call-more:not(.hidden) { animation: callMoreIn .2s cubic-bezier(0,0,.2,1); }
.call-more-inner {
  background: rgba(14,16,28,.92);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--r-xl);
  padding: 20px;
  display: grid;
  gap: 10px;
}
.call-more-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: rgba(255,255,255,.35);
  padding-top: 4px;
}
.call-more-inner label {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: rgba(255,255,255,.7);
  font-weight: normal;
}
.call-more-inner select {
  background: rgba(255,255,255,.07);
  border-color: rgba(255,255,255,.1);
  color: rgba(255,255,255,.85);
  min-height: 34px;
  font-size: 12px;
  border-radius: var(--r-md);
}
.call-more-inner select option { background: #1a1d2e; }
.call-more-inner button {
  background: rgba(255,255,255,.09);
  border: 1px solid rgba(255,255,255,.1);
  color: rgba(255,255,255,.8);
  font-size: 13px;
  min-height: 38px;
  border-radius: var(--r-md);
}
.call-more-inner button:hover { background: rgba(255,255,255,.17); }

/* Remote control pointer */
.remote-pointer {
  position: absolute;
  width: 20px; height: 20px;
  border: 2.5px solid var(--accent-2);
  border-radius: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  box-shadow: 0 0 0 6px rgba(34,197,94,.18);
  transition: left .06s, top .06s, transform .1s;
  z-index: 50;
}

/* ── Incoming call — elegant bottom sheet ───────────────────── */
#incomingCallDialog {
  width: min(400px, calc(100vw - 24px));
  padding: 0;
  border-radius: var(--r-xl);
  background: rgba(14,16,28,.95);
  backdrop-filter: blur(28px) saturate(160%);
  -webkit-backdrop-filter: blur(28px) saturate(160%);
  border: 1px solid rgba(255,255,255,.1);
  overflow: hidden;
  box-shadow: 0 32px 80px rgba(0,0,0,.7);
}
#incomingCallDialog::backdrop { background: rgba(0,0,0,.55); backdrop-filter: blur(6px); }
.incoming-call-card { display: grid; }
.incoming-call-top {
  background: linear-gradient(160deg, #12152a 0%, #090b18 100%);
  padding: 40px 24px 28px;
  text-align: center;
  position: relative;
  overflow: hidden;
}
/* Pulsing ring animation */
.ring-pulse {
  position: absolute;
  border-radius: 50%;
  border: 2px solid rgba(91,141,238,.35);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  animation: ringExpand 2s ease-out infinite;
}
.ring-pulse:nth-child(2) { animation-delay: .65s; }
.ring-pulse:nth-child(3) { animation-delay: 1.3s; }
@keyframes ringExpand {
  0%   { width: 80px; height: 80px; opacity: .7; }
  100% { width: 220px; height: 220px; opacity: 0; }
}
.incoming-avatar {
  width: 84px; height: 84px;
  border-radius: 50%;
  font-size: 32px;
  margin: 0 auto 16px;
  position: relative;
  z-index: 1;
  box-shadow: 0 0 0 4px rgba(91,141,238,.25), 0 0 0 8px rgba(91,141,238,.08);
}
.incoming-call-label {
  font-size: 12.5px;
  font-weight: 500;
  color: rgba(255,255,255,.45);
  letter-spacing: .03em;
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}
#incomingCallTitle {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  position: relative;
  z-index: 1;
}
.incoming-call-bottom {
  display: flex;
  gap: 16px;
  padding: 20px 24px 24px;
  background: rgba(0,0,0,.2);
}
.incoming-call-bottom button {
  flex: 1;
  min-height: 54px;
  border-radius: var(--r-pill);
  font-size: 15px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition: transform .12s, background .15s;
  min-width: auto;
}
.incoming-call-bottom button:active { transform: scale(.96); }
#declineCallBtn {
  background: rgba(239,68,68,.16);
  color: #ef4444;
  border: 1px solid rgba(239,68,68,.25);
}
#declineCallBtn:hover { background: rgba(239,68,68,.28); }
#acceptCallBtn {
  background: #22c55e;
  color: #fff;
  box-shadow: 0 6px 20px rgba(34,197,94,.4);
}
#acceptCallBtn:hover { background: #16a34a; }

/* ── Toast notification ─────────────────────────────────────── */
#toast {
  position: fixed;
  right: 16px;
  bottom: 20px;
  max-width: min(380px, calc(100vw - 32px));
  padding: 12px 16px;
  background: var(--card);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  line-height: 1.4;
  transform: translateY(16px);
  opacity: 0;
  pointer-events: none;
  transition: transform .22s cubic-bezier(.34,1.56,.64,1), opacity .22s ease;
  z-index: 9999;
}
#toast.visible { transform: translateY(0); opacity: 1; pointer-events: auto; }

/* ── Admin panel ────────────────────────────────────────────── */
.admin-view { padding: 20px; }
.admin-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 16px;
  align-items: start;
}
.admin-form h2, .admin-user-list h2 { margin: 0 0 12px; padding: 0; font-size: 13px; }
.admin-user-list { display: grid; gap: 8px; }
.admin-user {
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}
.admin-user > div:first-child { flex: 1; min-width: 0; }
.admin-user strong { display: block; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.admin-user span { display: block; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.admin-user-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; flex-shrink: 0; }
.admin-user-actions button { min-height: 30px; padding: 0 10px; font-size: 11.5px; border-radius: var(--r-md); }

/* ── Responsive – tablet ────────────────────────────────────── */
@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
  }
  .app.logged-out { grid-template-columns: 1fr; padding: 16px; }
  .sidebar { height: 100dvh; border-right: none; }
  .app.chat-open .sidebar { display: none; }
  .chat { display: none; height: 100dvh; }
  .app.chat-open .chat { display: grid; }
  .back-btn { display: grid; }
  .chat-header { padding: max(10px, env(safe-area-inset-top)) 12px 10px; }
  .brand { padding: max(14px, env(safe-area-inset-top)) 14px 12px; }
  .messages { padding: 14px 10px; }
  .msg-row { max-width: 92%; }
  .admin-grid { grid-template-columns: 1fr; }
  .admin-user { flex-direction: column; align-items: flex-start; }
  .call-pip { width: 30vw; min-width: 120px; bottom: 120px; right: 12px; }
  .call-controls-bar { gap: 6px; padding: 44px 12px 28px; }
  .call-btn { width: 56px; }
  .call-hangup { width: 64px; }
  .call-timer { font-size: 20px; }
  .call-topbar { padding: 14px 16px 48px; }
  .composer { padding: 8px 10px max(10px, env(safe-area-inset-bottom)); }
  .quick-row { padding: 8px 12px; }
}

@media (max-width: 520px) {
  dialog:not(#callDialog) { width: calc(100vw - 16px); border-radius: var(--r-lg); padding: 18px; }
  menu { display: grid; grid-template-columns: 1fr 1fr; }
  .composer-tools { display: grid; grid-template-columns: 1fr; }
  .member-picker { grid-template-columns: 1fr; }
}

/* ── Scrollbar styling ──────────────────────────────────────── */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Voice recording bar ────────────────────────────────────── */
.recording-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(239, 68, 68, .12);
  border-top: 1px solid rgba(239, 68, 68, .22);
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  animation: recBarIn .18s ease-out;
}
.recording-bar.hidden { display: none; }
@keyframes recBarIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.record-timer {
  font-size: 14px;
  font-weight: 600;
  color: #ef4444;
  min-width: 36px;
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}
.record-waveform {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 3px;
  height: 32px;
  overflow: hidden;
}
.record-waveform span {
  flex: 1;
  border-radius: 2px;
  background: rgba(239, 68, 68, .5);
  animation: recWave 0.9s ease-in-out infinite alternate;
  min-height: 4px;
}
.record-waveform span:nth-child(odd)  { animation-delay: .08s; }
.record-waveform span:nth-child(3n)   { animation-delay: .2s; }
.record-waveform span:nth-child(4n)   { animation-delay: .33s; }
.record-waveform span:nth-child(5n+1) { animation-delay: .44s; }
@keyframes recWave {
  from { transform: scaleY(.3); }
  to   { transform: scaleY(1); }
}
.record-cancel-hint {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  transition: color .2s, transform .2s;
  flex-shrink: 0;
}
.record-cancel-hint.active { color: #ef4444; transform: translateX(-6px); }
.record-cancel-btn {
  background: rgba(239, 68, 68, .15);
  color: #ef4444;
  border: none;
  border-radius: 50%;
  width: 30px; height: 30px;
  padding: 0; font-size: 16px;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.record-cancel-btn:hover { background: rgba(239, 68, 68, .28); }
.record-btn.recording {
  color: #ef4444;
  animation: recordPulse 1s ease-in-out infinite;
  background: rgba(239, 68, 68, .12);
  border-color: rgba(239, 68, 68, .3);
}

/* ── Voice message player ───────────────────────────────────── */
.voice-msg {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 2px;
  min-width: 200px;
  max-width: 320px;
}
.voice-play-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background .15s, transform .12s;
}
.voice-play-btn:hover { background: var(--accent-h); transform: scale(1.07); }
.voice-play-btn:disabled { background: var(--muted); cursor: default; transform: none; }
.voice-waveform {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 2px;
  height: 34px;
}
.voice-waveform span {
  flex: 1;
  border-radius: 2px;
  background: rgba(255,255,255,.25);
  min-height: 4px;
  transition: background .08s;
}
.msg-bubble.mine .voice-waveform span { background: rgba(255,255,255,.35); }
.voice-waveform span.played { background: var(--accent); }
.msg-bubble.mine .voice-waveform span.played { background: rgba(255,255,255,.85); }
.voice-duration {
  font-size: 12px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  min-width: 32px;
  text-align: right;
  flex-shrink: 0;
}

/* ── File image tap-to-reveal ───────────────────────────────── */
.file-img-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 18px 24px;
  border-radius: var(--r-md);
  background: rgba(255,255,255,.05);
  border: 1px dashed var(--line-strong);
  cursor: pointer;
  transition: background .15s;
  min-width: 160px;
}
.file-img-thumb:hover { background: rgba(255,255,255,.09); }
.file-img-thumb.loading { opacity: .6; pointer-events: none; }
.file-img-thumb.revealed { display: none; }
.file-img-reveal-icon { font-size: 28px; }
.file-img-reveal-name {
  font-size: 12px;
  color: var(--text-2);
  text-align: center;
  word-break: break-all;
  max-width: 180px;
}
.file-dl-btn {
  margin-top: 6px;
  font-size: 12px;
  padding: 5px 12px;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--text-2);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background .15s;
}
.file-dl-btn:hover { background: var(--accent-soft); color: var(--accent); }

/* ── File preview mobile improvements ──────────────────────── */
@media (max-width: 768px) {
  .msg-actions {
    top: auto;
    bottom: 30px;
    max-width: min(280px, 86vw);
    flex-wrap: wrap;
    white-space: normal;
    border-radius: var(--r-md);
  }
  .msg-actions button {
    min-height: 34px;
    padding: 0 10px;
  }
  .file-card { max-width: 100%; }
  .file-preview img  { width: 100%; border-radius: var(--r-md); }
  .file-preview video { width: 100%; border-radius: var(--r-md); }
  .file-preview iframe,
  .file-preview object { width: 100%; height: 50vh; }
  .voice-msg { min-width: 160px; max-width: 100%; }
  .voice-waveform span { gap: 1px; }
  .recording-bar { gap: 8px; padding: 10px; }
  .record-cancel-hint { display: none; }
}
