:root {
  --bg: #0f1115;
  --bg-alt: #161923;
  --bg-elevated: #1e2230;
  --border: #2a2f3f;
  --text: #e8eaf0;
  --text-dim: #9297a8;
  --accent: #6c8cff;
  --accent-hover: #83a0ff;
  --danger: #ff5c72;
  --success: #4ade80;
  --warn: #fbbf24;
  --radius: 12px;
  --radius-lg: 20px;
  --radius-pill: 999px;
  --shadow: 0 8px 24px rgba(0,0,0,0.35);
  /* ---------- z-index scale (round 5 revamp) ----------
     Kept as named steps so overlapping-UI bugs (a banner covering the composer, a menu hiding
     under a modal, etc.) can't creep back in one rule at a time. Higher = closer to the user. */
  --z-content: 1;
  --z-header: 10;
  --z-jump: 15;
  --z-dropdown: 30;
  --z-notif-panel: 35;
  --z-mobile-scrim: 55;
  --z-mobile-panel: 60;
  --z-banner: 90;
  --z-modal-backdrop: 100;
  --z-modal: 101;
  --z-toast: 200;
  --z-call: 300;
}
html[data-theme="light"] {
  --bg: #f5f6fa;
  --bg-alt: #ffffff;
  --bg-elevated: #ffffff;
  --border: #e1e4ec;
  --text: #1b1e27;
  --text-dim: #666c7d;
  --accent: #4361ee;
  --accent-hover: #3550d6;
  --shadow: 0 8px 24px rgba(0,0,0,0.08);
}
html[data-theme="midnight"] {
  --bg: #05070d;
  --bg-alt: #0b0e17;
  --bg-elevated: #131726;
  --border: #1e2436;
  --text: #e4e7f5;
  --text-dim: #7a80a0;
  --accent: #7c5cff;
  --accent-hover: #9478ff;
  --danger: #ff5c72;
  --success: #4ade80;
  --warn: #fbbf24;
  --shadow: 0 8px 24px rgba(0,0,0,0.5);
}
html[data-theme="ocean"] {
  --bg: #071b25;
  --bg-alt: #0c2530;
  --bg-elevated: #123240;
  --border: #1e4a58;
  --text: #e3f4f6;
  --text-dim: #7fa8b0;
  --accent: #17b8c4;
  --accent-hover: #35cbd6;
  --danger: #ff6b6b;
  --success: #4ade80;
  --warn: #fbbf24;
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
}
html[data-theme="sunset"] {
  --bg: #1c1017;
  --bg-alt: #241620;
  --bg-elevated: #2f1d2c;
  --border: #452a3c;
  --text: #fbe9f0;
  --text-dim: #b78aa0;
  --accent: #ff6f61;
  --accent-hover: #ff8b7f;
  --danger: #ff5c72;
  --success: #4ade80;
  --warn: #ffb454;
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
}
html[data-theme="forest"] {
  --bg: #0d1710;
  --bg-alt: #131f16;
  --bg-elevated: #1a2b1e;
  --border: #2a3f2e;
  --text: #e6f3e6;
  --text-dim: #85a68a;
  --accent: #4caf6e;
  --accent-hover: #62c383;
  --danger: #ff5c72;
  --success: #7ee08a;
  --warn: #e0c455;
  --shadow: 0 8px 24px rgba(0,0,0,0.4);
}
* { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.2s, color 0.2s;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: white;
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  transition: filter 0.15s ease, transform 0.08s ease, box-shadow 0.15s ease;
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
button:hover { filter: brightness(1.08); box-shadow: 0 4px 14px -4px var(--accent); }
button:active { transform: scale(0.97); }
button.secondary { background: var(--bg-elevated); color: var(--text); border: 1px solid var(--border); box-shadow: none; }
button.secondary:hover { filter: none; border-color: var(--accent); box-shadow: none; }
button.danger { background: linear-gradient(135deg, var(--danger), #ff8095); }
button.ghost { background: transparent; color: var(--text-dim); padding: 6px 10px; box-shadow: none; }
button.ghost:hover { color: var(--text); background: var(--bg-elevated); filter: none; box-shadow: none; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button:disabled:hover { filter: none; box-shadow: 0 1px 2px rgba(0,0,0,0.15); }
input, textarea, select {
  font-family: inherit;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
/* Theme the native file-picker button so it doesn't render as a jarring light-mode control
   inside an otherwise dark UI (affects avatar/banner uploads, DB restore, attachments, etc). */
input[type="file"] { padding: 6px 10px; font-size: 13px; color: var(--text-dim); }
input[type="file"]::file-selector-button {
  font-family: inherit; cursor: pointer; border: none; border-radius: var(--radius-pill);
  background: var(--bg); color: var(--text); padding: 6px 12px; font-size: 12.5px; font-weight: 600;
  margin-right: 10px; border: 1px solid var(--border); transition: border-color 0.15s ease, color 0.15s ease;
}
input[type="file"]::file-selector-button:hover { border-color: var(--accent); color: var(--accent); }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 20px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); background-clip: padding-box; }
::-webkit-scrollbar-track { background: transparent; }
html { scrollbar-color: var(--border) transparent; scrollbar-width: thin; }
.messages, .sidebar-list, .right-panel, .admin-nav, .admin-main, .modal { -webkit-overflow-scrolling: touch; }

/* ---------- Auth page ---------- */
.auth-wrap {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(650px circle at 12% 8%, color-mix(in srgb, var(--accent) 20%, transparent), transparent 60%),
    radial-gradient(550px circle at 88% 92%, color-mix(in srgb, var(--accent) 14%, transparent), transparent 60%),
    var(--bg);
}
.auth-card {
  background: color-mix(in srgb, var(--bg-alt) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px -12px rgba(0,0,0,0.45), 0 0 0 1px rgba(255,255,255,0.03) inset;
  position: relative;
  z-index: 1;
  animation: authCardIn 0.45s cubic-bezier(0.16,1,0.3,1);
}
@keyframes authCardIn { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.auth-card h1 {
  margin: 0 0 4px; font-size: 24px; font-weight: 800; letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text), var(--accent));
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.auth-card p.sub { color: var(--text-dim); margin: 0 0 24px; font-size: 14px; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; }
.auth-card label { font-size: 13px; color: var(--text-dim); margin-bottom: -6px; }
.auth-tabs { display: flex; gap: 6px; margin-bottom: 20px; background: var(--bg-elevated); padding: 4px; border-radius: var(--radius); }
.auth-tabs button { flex: 1; background: transparent; color: var(--text-dim); box-shadow: none; }
.auth-tabs button.active { background: linear-gradient(135deg, var(--accent), var(--accent-hover)); color: white; box-shadow: 0 2px 8px -2px var(--accent); }
.error-box { background: rgba(255,92,114,0.12); color: var(--danger); border: 1px solid rgba(255,92,114,0.3); padding: 10px 12px; border-radius: var(--radius); font-size: 13px; }
.success-box { background: rgba(74,222,128,0.12); color: var(--success); border: 1px solid rgba(74,222,128,0.3); padding: 10px 12px; border-radius: var(--radius); font-size: 13px; }
.strength-meter { height: 5px; border-radius: 3px; background: var(--border); overflow: hidden; margin-top: -6px; }
.strength-meter div { height: 100%; transition: width 0.2s, background 0.2s; }
.hint { font-size: 12px; color: var(--text-dim); }
.link-btn { background: none; border: none; color: var(--accent); font-size: 13px; padding: 0; text-align: left; font-weight: 500; box-shadow: none; }
.link-btn:hover { filter: none; box-shadow: none; text-decoration: underline; }

/* ---------- App layout ---------- */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 280px; background: var(--bg-alt); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar-header {
  padding: 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px;
  background: linear-gradient(180deg, color-mix(in srgb, var(--accent) 7%, transparent), transparent 70%);
}
.sidebar-tabs { display: flex; border-bottom: 1px solid var(--border); gap: 2px; padding: 6px 6px 0; }
.sidebar-tabs button {
  flex: 1; background: none; color: var(--text-dim); border-radius: 8px 8px 0 0; padding: 9px 2px; font-size: 11.5px;
  font-weight: 600; letter-spacing: 0.2px; transition: color 0.15s, background 0.15s; box-shadow: none;
}
.sidebar-tabs button.active { color: var(--accent); background: var(--bg-elevated); }
.sidebar-tabs button:hover:not(.active) { color: var(--text); filter: none; box-shadow: none; }
.sidebar-list { flex: 1; overflow-y: auto; padding: 8px; }
.list-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius); cursor: pointer;
  position: relative; border-left: 3px solid transparent; transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
}
.list-item:hover { background: var(--bg-elevated); transform: translateX(1px); }
.list-item.active { background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 16%, var(--bg-elevated)), var(--bg-elevated)); border-left-color: var(--accent); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 25%, transparent), 0 2px 10px -6px var(--accent); }
.list-item.pinned-chat { background: color-mix(in srgb, var(--accent) 6%, transparent); }
.list-item.mark-all-read-row { cursor: pointer; justify-content: center; padding: 7px 10px; margin-bottom: 4px; border: 1px dashed var(--border); border-left: 3px solid transparent; }
.list-item.mark-all-read-row:hover { background: var(--bg-elevated); border-color: var(--accent); }
.list-item-pin-btn { background: transparent !important; color: var(--text-dim) !important; padding: 4px 6px !important; font-size: 13px !important; opacity: 0; flex-shrink: 0; margin-left: 2px; box-shadow: none !important; }
.list-item:hover .list-item-pin-btn { opacity: 1; }
.list-item-pin-btn:hover { color: var(--accent) !important; background: var(--bg) !important; }
.pin-marker { font-size: 11px; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  display: flex; align-items: center; justify-content: center; font-weight: 700; color: white; flex-shrink: 0;
  object-fit: cover; font-size: 14px; position: relative; box-shadow: 0 2px 6px -2px rgba(0,0,0,0.4);
}
.avatar-sm { width: 28px; height: 28px; font-size: 12px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; position: absolute; bottom: -1px; right: -1px; border: 2px solid var(--bg-alt); }
.status-dot.online { background: var(--success); box-shadow: 0 0 6px var(--success); }
.status-dot.away { background: var(--warn); }
.status-dot.busy { background: var(--danger); }
.status-dot.offline, .status-dot.invisible { background: #6b7280; }
.list-item-name { font-size: 14px; font-weight: 600; }
.list-item-sub { font-size: 12px; color: var(--text-dim); }
.badge { background: linear-gradient(135deg, var(--accent), var(--accent-hover)); color: white; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 20px; margin-left: auto; }
.streak-pill { font-size: 11px; color: var(--warn); margin-left: auto; }

.main-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.chat-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px;
  background: var(--bg-alt); position: relative; z-index: var(--z-header);
}
.chat-header .title { font-weight: 700; font-size: 15px; }
.chat-header .subtitle { font-size: 12px; color: var(--text-dim); }
.pinned-bar { background: var(--bg-elevated); border-bottom: 1px solid var(--border); padding: 8px 20px; font-size: 12px; color: var(--text-dim); display: flex; align-items: center; gap: 8px; }

.messages { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 10px; background-position: center; }
/* ---------- chat bubbles (round 5 revamp) ----------
   Each row is a full-width flex line; the bubble itself (.msg-content-wrap) is capped to 74% of
   that line and pushed to one side. Rich content (images/video/files/polls/voice notes) keeps its
   own card styling via the :has() escape hatches below instead of getting double-boxed. */
.msg-row { display: flex; gap: 8px; padding: 2px 8px; border-radius: var(--radius); position: relative; transition: background 0.12s ease; animation: msgIn 0.18s ease; align-items: flex-end; }
@keyframes msgIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
.msg-row:hover { background: color-mix(in srgb, var(--bg-elevated) 45%, transparent); }
.msg-row:hover .msg-actions { opacity: 1; }
.msg-row .avatar-sm { margin-bottom: 2px; }
.msg-content-wrap {
  flex: 0 1 auto; min-width: 0; max-width: 74%; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 8px 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.msg-row.mine { flex-direction: row-reverse; justify-content: flex-start; }
.msg-row.mine .msg-content-wrap {
  background: linear-gradient(135deg, var(--accent), var(--accent-hover)); border-color: transparent; color: white;
}
.msg-row.mine .msg-content-wrap .msg-time,
.msg-row.mine .msg-content-wrap .text-dim,
.msg-row.mine .msg-content-wrap .edited-tag { color: rgba(255,255,255,0.78); }
.msg-row.mine .msg-content-wrap .msg-sender { color: rgba(255,255,255,0.95); }
.msg-row.mine .msg-content-wrap code { background: rgba(0,0,0,0.18); border-color: rgba(255,255,255,0.2); color: inherit; }
/* rich content (media/files/polls/voice) already has its own card chrome — don't double-box it */
.msg-content-wrap:has(> .msg-image),
.msg-content-wrap:has(> .msg-video),
.msg-content-wrap:has(> .file-card),
.msg-content-wrap:has(> .poll-card),
.msg-content-wrap:has(> .voice-note-row) {
  background: transparent; border: none; padding: 0; box-shadow: none;
}
.msg-row.mine .msg-content-wrap:has(> .msg-image) .msg-time,
.msg-row.mine .msg-content-wrap:has(> .msg-video) .msg-time,
.msg-row.mine .msg-content-wrap:has(> .file-card) .msg-time,
.msg-row.mine .msg-content-wrap:has(> .poll-card) .msg-time,
.msg-row.mine .msg-content-wrap:has(> .voice-note-row) .msg-time { color: var(--text-dim); }
.msg-row.mine .msg-content-wrap:has(> .msg-image) .msg-sender,
.msg-row.mine .msg-content-wrap:has(> .msg-video) .msg-sender,
.msg-row.mine .msg-content-wrap:has(> .file-card) .msg-sender,
.msg-row.mine .msg-content-wrap:has(> .poll-card) .msg-sender,
.msg-row.mine .msg-content-wrap:has(> .voice-note-row) .msg-sender { color: var(--text); }
.msg-meta { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-row.mine .msg-meta { flex-direction: row-reverse; }
.msg-sender { font-weight: 700; font-size: 13.5px; }
.msg-time { font-size: 11px; color: var(--text-dim); }
.msg-text { font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.msg-image { max-width: 320px; max-height: 320px; border-radius: var(--radius); margin-top: 4px; display: block; }
.msg-video { max-width: 320px; max-height: 320px; border-radius: var(--radius); margin-top: 4px; display: block; }
.msg-audio { margin-top: 4px; max-width: 320px; width: 100%; }
.voice-note-row { display: flex; align-items: center; gap: 8px; }
.speed-btn { padding: 1px 8px; font-size: 11px; font-weight: 700; background: var(--bg-elevated); color: var(--text-dim); border: 1px solid var(--border); box-shadow: none; }
.speed-btn:hover { color: var(--text); border-color: var(--accent); filter: none; box-shadow: none; }
.file-card { display: flex; align-items: center; gap: 10px; margin-top: 4px; padding: 10px 12px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); max-width: 320px; text-decoration: none; color: var(--text); }
.file-card:hover { border-color: var(--accent); text-decoration: none; }
.file-card .file-icon { font-size: 22px; flex-shrink: 0; }
.file-card .file-meta { min-width: 0; }
.file-card .file-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .file-size { font-size: 11px; color: var(--text-dim); }

/* ---------- link previews (feature: round 4) ---------- */
.link-preview-card {
  display: block; margin-top: 6px; max-width: 360px; background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; text-decoration: none; color: var(--text);
  transition: border-color 0.15s ease, transform 0.1s ease;
}
.link-preview-card:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.link-preview-image { height: 140px; background-size: cover; background-position: center; background-color: var(--bg); }
.link-preview-body { padding: 10px 12px; }
.link-preview-site { font-size: 10.5px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.3px; margin-bottom: 2px; }
.link-preview-title { font-size: 13px; font-weight: 700; line-height: 1.3; }
.link-preview-desc { font-size: 12px; color: var(--text-dim); margin-top: 3px; line-height: 1.4; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

.msg-reply { border-left: 2px solid var(--accent); padding: 3px 8px; margin-bottom: 3px; font-size: 12px; color: var(--text-dim); background: var(--bg); border-radius: 4px; }
.msg-deleted { font-size: 13px; color: var(--text-dim); font-style: italic; }
.msg-row.mine .msg-content-wrap .msg-reply { background: rgba(255,255,255,0.16); border-left-color: rgba(255,255,255,0.7); color: rgba(255,255,255,0.92); }
.msg-row.mine .msg-content-wrap .msg-deleted { color: rgba(255,255,255,0.85); }
.msg-actions { position: absolute; top: -14px; left: 40px; opacity: 0; display: flex; gap: 2px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 2px; transition: opacity 0.1s; z-index: var(--z-content); box-shadow: var(--shadow); }
.msg-row.mine .msg-actions { left: auto; right: 40px; }
.msg-actions button { padding: 4px 7px; font-size: 12px; background: transparent; color: var(--text-dim); }
.msg-actions button:hover { background: var(--bg); color: var(--text); }
.msg-reactions { display: flex; gap: 4px; margin-top: 4px; flex-wrap: wrap; }
.msg-row.mine .msg-content-wrap .reaction-pill { background: rgba(255,255,255,0.18); border-color: rgba(255,255,255,0.4); color: white; }
.msg-row.mine .msg-content-wrap .reaction-pill.mine { background: rgba(255,255,255,0.4); border-color: white; }

/* ---------- polls ---------- */
.poll-card { margin-top: 4px; max-width: 340px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px; padding: 12px; box-shadow: 0 2px 10px -6px rgba(0,0,0,0.3); }
.poll-question { font-weight: 700; font-size: 13.5px; margin-bottom: 8px; }
.poll-option { position: relative; margin-bottom: 6px; padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); cursor: pointer; overflow: hidden; font-size: 13px; background: var(--bg); transition: border-color 0.15s ease; }
.poll-option:hover { border-color: var(--accent); }
.poll-option.voted { border-color: var(--accent); }
.poll-option-fill { position: absolute; inset: 0; background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 26%, transparent), color-mix(in srgb, var(--accent) 12%, transparent)); z-index: 0; transition: width 0.3s ease; }
.poll-option-label { position: relative; z-index: 1; display: flex; justify-content: space-between; gap: 8px; }
.poll-meta { font-size: 11px; color: var(--text-dim); margin-top: 4px; }

/* ---------- starred / forward list modals ---------- */
.starred-item { display: flex; flex-direction: column; gap: 2px; padding: 10px; border-bottom: 1px solid var(--border); cursor: pointer; }
.starred-item:hover { background: var(--bg-elevated); }
.starred-item:last-child { border-bottom: none; }
.starred-room { font-size: 11px; color: var(--accent); font-weight: 700; text-transform: uppercase; }
.starred-preview { font-size: 13px; }
.starred-time { font-size: 11px; color: var(--text-dim); }
.forward-target { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: var(--radius); cursor: pointer; }
.forward-target:hover { background: var(--bg-elevated); }
.seen-by-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; }

/* ---------- attachment menu (composer "+") ---------- */
.attach-menu { display: none; position: absolute; bottom: 52px; left: 0; flex-direction: column; gap: 2px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 6px; min-width: 180px; z-index: var(--z-dropdown); }
.attach-menu.open { display: flex; }
.attach-menu button { background: transparent; color: var(--text); justify-content: flex-start; text-align: left; padding: 8px 10px; font-size: 13px; font-weight: 500; }
.attach-menu button:hover { background: var(--bg); }

/* ---------- voice note recorder ---------- */
.recording-bar { display: flex; align-items: center; gap: 10px; padding: 8px 4px; }
.recording-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: pulse-dot 1s infinite; flex-shrink: 0; }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
.recording-time { font-variant-numeric: tabular-nums; font-size: 13px; font-weight: 600; }
.recording-hint { flex: 1; color: var(--text-dim); font-size: 12px; }
.reaction-pill { font-size: 12px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 12px; padding: 1px 8px; cursor: pointer; }
.reaction-pill.mine { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 15%, transparent); }
.edited-tag { font-size: 10px; color: var(--text-dim); }
.typing-indicator { font-size: 12px; color: var(--text-dim); padding: 4px 20px; height: 20px; }

.composer { border-top: 1px solid var(--border); padding: 12px 20px; background: var(--bg-alt); }
.reply-preview { background: var(--bg-elevated); border-radius: var(--radius); padding: 6px 10px; margin-bottom: 8px; font-size: 12px; display: flex; justify-content: space-between; align-items: center; }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1; resize: none; max-height: 120px; min-height: 42px; background: var(--bg-elevated);
  border-radius: var(--radius-lg); padding: 11px 16px;
}
.icon-btn {
  background: var(--bg-elevated); color: var(--text-dim); border: 1px solid var(--border); width: 40px; height: 40px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 16px;
  flex-shrink: 0; box-shadow: none; transition: color 0.15s ease, border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--accent); filter: none; box-shadow: none; }
.icon-btn:active { transform: scale(0.94); }
/* the send button is the one primary (non-.icon-btn) button in the composer row — give it a
   circular, gradient-filled look so it's unmistakably the "go" action next to the pill input */
.composer-row > button:not(.icon-btn) {
  width: 42px; height: 42px; border-radius: 50%; padding: 0; flex-shrink: 0; font-size: 0;
  display: flex; align-items: center; justify-content: center;
}
.composer-row > button:not(.icon-btn)::after { content: '➤'; font-size: 16px; transform: translateX(-1px); }

.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--text-dim); gap: 8px; }

/* right panel (members/profile) */
.right-panel { width: 260px; border-left: 1px solid var(--border); background: var(--bg-alt); flex-shrink: 0; overflow-y: auto; padding: 16px; display: none; }
.right-panel.open { display: block; }
.right-panel h3 { font-size: 13px; text-transform: uppercase; color: var(--text-dim); margin: 18px 0 8px; }
.right-panel h3:first-child { margin-top: 0; }
.member-row { display: flex; align-items: center; gap: 8px; padding: 6px 4px; font-size: 13px; }

/* modal */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(6,8,14,0.6); backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; z-index: var(--z-modal-backdrop); animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-alt); border: 1px solid var(--border); border-radius: 16px; padding: 24px; width: 100%;
  max-width: 460px; max-height: 85vh; overflow-y: auto; box-shadow: 0 24px 70px -16px rgba(0,0,0,0.5); position: relative;
  animation: modalIn 0.2s cubic-bezier(0.16,1,0.3,1);
}
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
.modal h2 { margin-top: 0; font-size: 18px; font-weight: 800; letter-spacing: -0.01em; }
.modal-close { position: absolute; top: 18px; right: 18px; }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 13px; color: var(--text-dim); }
.form-row { display: flex; gap: 8px; }
.tab-strip {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px;
  flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin;
}
.tab-strip::-webkit-scrollbar { height: 4px; }
.tab-strip::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.tab-strip button { background: none; color: var(--text-dim); border-radius: 0; padding: 8px 8px; font-size: 13px; flex-shrink: 0; white-space: nowrap; }
.tab-strip button.active { color: var(--accent); border-bottom: 2px solid var(--accent); }

/* toast / notification */
.toast-container { position: fixed; top: 16px; right: 16px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; box-shadow: var(--shadow); font-size: 13px; min-width: 240px; animation: slideIn 0.2s ease; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* call overlay */
.call-overlay {
  position: fixed; inset: 0; z-index: var(--z-call); color: white; gap: 20px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background:
    radial-gradient(600px circle at 50% 30%, color-mix(in srgb, var(--accent) 25%, transparent), transparent 60%),
    rgba(8,10,16,0.94);
  backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.call-avatar { width: 96px; height: 96px; border-radius: 50%; background: linear-gradient(135deg, var(--accent), var(--accent-hover)); display: flex; align-items: center; justify-content: center; font-size: 36px; font-weight: 700; box-shadow: 0 8px 30px -6px var(--accent); }
.call-actions { display: flex; gap: 16px; }
.call-actions button { width: 56px; height: 56px; border-radius: 50%; font-size: 20px; }
.pulse { animation: pulse 1.4s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 50%, transparent); }
  70% { box-shadow: 0 0 0 20px color-mix(in srgb, var(--accent) 0%, transparent); }
  100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 0%, transparent); }
}

/* misc */
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.text-dim { color: var(--text-dim); }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; }
.settings-section { margin-bottom: 24px; }
.settings-section h3 { font-size: 14px; margin-bottom: 10px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.toggle { position: relative; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider { position: absolute; inset: 0; background: var(--border); border-radius: 20px; cursor: pointer; transition: 0.2s; }
.toggle .slider:before { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: white; border-radius: 50%; transition: 0.2s; }
.toggle input:checked + .slider { background: linear-gradient(135deg, var(--accent), var(--accent-hover)); }
.toggle input:checked + .slider:before { transform: translateX(18px); }

/* admin */
.admin-shell { display: flex; height: 100vh; }
.admin-nav { width: 240px; background: var(--bg-alt); border-right: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; padding: 12px; }
.admin-nav .nav-group { font-size: 11px; text-transform: uppercase; color: var(--text-dim); margin: 16px 0 6px 10px; }
.admin-nav button { display: block; width: 100%; text-align: left; background: none; color: var(--text-dim); padding: 8px 10px; font-size: 13.5px; font-weight: 500; }
.admin-nav button.active { background: var(--accent); color: white; }
.admin-main { flex: 1; overflow-y: auto; padding: 24px 32px; }
.admin-main h1 { font-size: 20px; margin: 0 0 20px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--bg-alt); border: 1px solid var(--border); border-radius: 12px; padding: 16px; }
.stat-card .num { font-size: 26px; font-weight: 800; }
.stat-card .label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th { color: var(--text-dim); font-weight: 600; font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.pill.ok { background: rgba(74,222,128,0.15); color: var(--success); }
.pill.bad { background: rgba(255,92,114,0.15); color: var(--danger); }
.pill.neutral { background: var(--bg-elevated); color: var(--text-dim); }
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
.toolbar input, .toolbar select { flex: 0 0 auto; }
.table-actions { display: flex; gap: 6px; }
.table-actions button { padding: 5px 9px; font-size: 12px; }

/* ---------- new UI: mute, jump-to-bottom, unread divider, emoji picker, drag/drop, char counter ---------- */
.jump-to-bottom {
  position: absolute; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: linear-gradient(135deg, var(--accent), var(--accent-hover)); color: white; border-radius: var(--radius-pill); padding: 7px 16px;
  font-size: 12px; font-weight: 600; box-shadow: var(--shadow); z-index: var(--z-jump);
}
.unread-divider { display: flex; align-items: center; gap: 10px; margin: 10px 0; color: var(--accent); font-size: 11px; font-weight: 700; text-transform: uppercase; }
.unread-divider::before, .unread-divider::after { content: ''; flex: 1; height: 1px; background: var(--accent); opacity: 0.4; }

.emoji-picker { display: none; grid-template-columns: repeat(8, 1fr); gap: 2px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px; margin-bottom: 8px; max-height: 160px; overflow-y: auto; }
.emoji-btn { background: transparent; padding: 4px; font-size: 18px; border-radius: 6px; }
.emoji-btn:hover { background: var(--bg); }

.drop-overlay {
  display: none; position: absolute; inset: 0; background: color-mix(in srgb, var(--accent) 15%, transparent);
  border: 2px dashed var(--accent); border-radius: var(--radius); align-items: center; justify-content: center;
  font-weight: 700; color: var(--accent); z-index: var(--z-content); pointer-events: none;
}
.drop-overlay.active { display: flex; }
.composer { position: relative; }

.char-counter { font-size: 11px; color: var(--text-dim); text-align: right; padding: 2px 4px 0; }
.char-counter.danger { color: var(--danger); font-weight: 700; }

.show-more-btn { background: none; color: var(--accent); padding: 2px 0; font-size: 12px; font-weight: 600; }
.msg-text.collapsed { max-height: 180px; overflow: hidden; position: relative; mask-image: linear-gradient(to bottom, black 70%, transparent 100%); -webkit-mask-image: linear-gradient(to bottom, black 70%, transparent 100%); }

code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9em; }

/* ---------- mobile: hidden by default on desktop ---------- */
.mobile-only { display: none; }
.sidebar-scrim { display: none; }

/* ---------- PWA install / notification-permission banner ----------
   FIX (round 5): this used to be pinned to the bottom of the viewport, which sat directly on top
   of the composer (the text box + attach/emoji/send buttons) and made them completely unclickable
   the moment the banner appeared — this was the root cause of "photo/file/voice/poll/schedule
   message don't work". It's now anchored to the TOP of the viewport (below the safe area) as a
   slide-down bar, so it can never overlap the composer, and it sits below modals in the z-index
   scale so an open modal correctly covers it instead of floating above it. */
.install-banner {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(12px + env(safe-area-inset-top));
  z-index: var(--z-banner); width: calc(100% - 24px); max-width: 480px;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 10px; font-size: 13px;
  animation: bannerDown 0.25s cubic-bezier(0.16,1,0.3,1);
}
@keyframes bannerDown { from { opacity: 0; transform: translateX(-50%) translateY(-12px); } to { opacity: 1; transform: translateX(-50%) translateY(0); } }
.install-banner button { flex-shrink: 0; }

/* ---------- notification bell + panel ---------- */
.notif-dot { position: absolute; top: 3px; right: 3px; width: 8px; height: 8px; border-radius: 50%; background: var(--danger); border: 2px solid var(--bg-alt); }
.notif-panel {
  position: absolute; top: calc(100% + 6px); right: -8px; width: 300px; max-width: calc(100vw - 24px);
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); z-index: var(--z-notif-panel); overflow: hidden;
}
.notif-item { display: flex; align-items: center; gap: 8px; padding: 9px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.notif-item.unread::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }

/* ---------- accessibility & polish ---------- */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button, input, textarea, select, .list-item, .toggle { -webkit-tap-highlight-color: transparent; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
/* iOS safe-area padding so fixed UI clears the notch / home indicator once installed */
.toast-container { padding-top: env(safe-area-inset-top); }
.sidebar-header { padding-top: calc(16px + env(safe-area-inset-top)); }
@media (max-width: 860px) {
  .app-shell { position: relative; overflow: hidden; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: var(--z-mobile-panel); width: 84vw; max-width: 340px;
    transform: translateX(-100%); transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-scrim {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: var(--z-mobile-scrim);
    opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  .sidebar-scrim.open { opacity: 1; pointer-events: auto; }
  .main-panel { width: 100%; }
  .mobile-only { display: inline-flex; }
  .right-panel { position: fixed; inset: 0 0 0 auto; z-index: var(--z-mobile-panel); width: 86vw; max-width: 340px; transform: translateX(100%); transition: transform 0.2s ease; }
  .right-panel.open { display: block; transform: translateX(0); }
  .chat-header { padding: 10px 12px; }
  .messages { padding: 12px; }
  .composer { padding: 10px 12px; }
  .msg-image, .msg-video { max-width: 220px; max-height: 220px; }
  .msg-audio, .file-card { max-width: 100%; }
  .msg-content-wrap { max-width: 84%; }
  .install-banner { top: calc(10px + env(safe-area-inset-top)); width: calc(100% - 20px); }
  .modal { max-width: 92vw; padding: 18px; }
  .call-actions button { width: 50px; height: 50px; }
  .admin-shell { flex-direction: column; height: auto; min-height: 100vh; }
  .admin-nav { width: 100%; height: auto; max-height: 220px; display: flex; flex-wrap: wrap; gap: 4px; padding: 10px; }
  .admin-nav .nav-group { display: none; }
  .admin-nav button { width: auto; padding: 6px 10px; font-size: 12px; }
  .admin-main { padding: 16px; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}
@media (max-width: 480px) {
  .auth-card { padding: 22px; }
  .sidebar { width: 90vw; }
  .msg-actions { top: -12px; right: 4px; }
  .composer-row { gap: 4px; }
  .icon-btn { width: 36px; height: 36px; font-size: 14px; }
}

/* Kept at the end of the file so it wins over the earlier mobile .composer padding shorthand. */
@media (max-width: 860px) {
  .composer { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
}

/* ================================================================
   ROUND 3: navigation polish + 25 new features
   ================================================================ */

/* -- clearer section headers inside the sidebar list -- */
.sidebar-list > div[style*="text-transform:uppercase"] {
  position: sticky; top: 0; background: var(--bg-alt); z-index: 2; padding-top: 10px !important;
}

/* -- action / slash-command messages ("/me ...") -- */
.msg-action { font-style: italic; color: var(--text-dim); }
.msg-action b, .msg-action strong { color: var(--text); }

/* -- slash command autocomplete hint above the composer -- */
.slash-hint {
  display: flex; flex-direction: column; gap: 2px; background: var(--bg-elevated);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px;
  margin-bottom: 8px; font-size: 12.5px; color: var(--text-dim);
}
.slash-hint b { color: var(--accent); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* -- room announcement banner in the right panel -- */
.room-announcement {
  background: color-mix(in srgb, var(--accent) 10%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent); border-radius: var(--radius);
  padding: 8px 10px; font-size: 12.5px; margin-bottom: 10px; line-height: 1.4;
}

/* -- per-member role selector in the room members panel -- */
.member-role-select { font-size: 11.5px; padding: 4px 6px; margin-left: auto; }

/* -- profile banner preview in Settings -- */
.profile-banner-preview {
  width: 100%; height: 84px; border-radius: var(--radius); background: var(--bg-elevated);
  border: 1px solid var(--border); background-size: cover; background-position: center;
}

/* -- compact message density -- */
body.density-compact .messages { gap: 0; padding-top: 10px; }
body.density-compact .msg-row { padding: 2px 8px; }
body.density-compact .msg-text { font-size: 13.5px; line-height: 1.3; }
body.density-compact .msg-meta { gap: 6px; }
body.density-compact .avatar-sm { width: 22px; height: 22px; font-size: 10px; }

/* -- adjustable chat text size (feature: round 4) -- */
body.font-small .msg-text { font-size: 12.5px; }
body.font-medium .msg-text { font-size: 14px; }
body.font-large .msg-text { font-size: 17px; line-height: 1.55; }

/* -- clearer active/hover affordance for icon buttons in the chat header -- */
.chat-header { gap: 8px; }
.chat-header .icon-btn { width: 36px; height: 36px; }

/* -- room settings modal: file inputs shouldn't stretch oddly next to previews -- */
#roomIconInput, #bannerInput, #avatarInput { max-width: 100%; }

/* -- security tab spacing -- */
#stSecurity h3 { font-size: 14px; margin: 0 0 6px; }
#stSecurity p { margin: 0 0 10px; line-height: 1.45; }

/* -- 2FA / enrollment QR views on the auth page -- */
#enrollForm .hint { line-height: 1.5; }

/* -- login history rows already styled inline via .flex-between; give the section a max height -- */
#loginHistoryList { max-height: 220px; overflow-y: auto; }

/* -- friends list action buttons (favorite / nickname) reuse .list-item-pin-btn, but keep them
      visible (not hover-only) since they're a primary action on that tab -- */
#sidebarList .list-item .list-item-pin-btn { opacity: 1; }

/* -- blocked tab empty/list state already uses .list-item / .text-dim, no extra rules needed -- */

/* -- invite code + join-request rows use .flex-between; give <code> a bit more presence -- */
#inviteLinksList code { font-size: 13px; }

/* -- quick switcher: message results should scroll instead of pushing the modal too tall -- */
#quickSwitchResults, #quickSwitchMsgResults { max-height: 280px; overflow-y: auto; }

/* -- chat header "more actions" dropdown (mute/starred/scheduled/export) -- */
.chat-more-menu {
  display: none; position: absolute; top: calc(100% + 6px); right: 0; flex-direction: column; gap: 2px;
  background: var(--bg-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 6px; min-width: 200px; z-index: var(--z-dropdown);
  max-height: 70vh; overflow-y: auto;
}
.chat-more-menu.open { display: flex; }
.chat-more-menu button { background: transparent; color: var(--text); justify-content: flex-start; text-align: left; padding: 8px 10px; font-size: 13px; font-weight: 500; }
.chat-more-menu button:hover { background: var(--bg); }

/* -- general navigation polish: subtler dividers, more breathing room in modals -- */
.modal h2 { line-height: 1.3; }
/* NOTE: tab-strip intentionally scrolls horizontally instead of wrapping (see the base
   .tab-strip rule above) — wrapping made the Settings modal's 5th tab ("Sessions") render
   as an orphaned line with no border underneath it, which looked broken. Do not re-add
   flex-wrap: wrap here. */
.tab-strip button { padding: 8px 10px; }
