/* ---------- Theme ---------- */
:root {
  --bg-0: #060606;
  --bg-1: #0a0a0a;
  --bg-2: #0e0e0e;
  --bg-3: #141414;
  --bg-4: #1b1b1b;
  --bg-float: #111111;
  --bg-input: #141414;
  --line: rgba(255, 255, 255, 0.05);
  --line-strong: rgba(255, 255, 255, 0.08);
  --text: #cdcdcd;
  --text-2: #8c8c8c;
  --muted: #5c5c5c;
  --accent: #c8c8c8;
  --accent-hover: color-mix(in srgb, var(--accent) 84%, #000);
  --accent-soft: color-mix(in srgb, var(--accent) 18%, transparent);
  --on-accent: #0a0a0a;
  /* No hues anywhere: "green" (online, active) and "red" (alerts, hang up) are light grays; "yellow" (pending) is mid gray. */
  --green: #a8a8a8;
  --green-hover: #949494;
  --red: #c8c8c8;
  --red-hover: #b0b0b0;
  --yellow: #707070;
  --mention: rgba(255, 255, 255, 0.04);
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.5);
  --radius: 8px;
  --rail: 72px;
  --sidebar: 248px;
  --members: 248px;
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, "SF Mono", Menlo, monospace;
  color-scheme: dark;
}
[data-theme="light"] {
  --bg-0: #dcdcdc;
  --bg-1: #e8e8e8;
  --bg-2: #f2f2f2;
  --bg-3: #e3e3e3;
  --bg-4: #d5d5d5;
  --bg-float: #f2f2f2;
  --bg-input: #e3e3e3;
  --line: rgba(0, 0, 0, 0.08);
  --line-strong: rgba(0, 0, 0, 0.14);
  --text: #1c1c1c;
  --text-2: #4c4c4c;
  --muted: #6e6e6e;
  --accent: #2a2a2a;
  --on-accent: #f2f2f2;
  --green: #555555;
  --green-hover: #444444;
  --red: #2a2a2a;
  --red-hover: #1c1c1c;
  --yellow: #8a8a8a;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.14);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
#app { height: 100%; height: 100dvh; }
body {
  background: var(--bg-2);
  color: var(--text);
  font: 15px/1.375 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
a { color: inherit; text-decoration: none; }
.msg-text a, .notice a, .r-sub a { color: var(--text); text-decoration: underline; text-decoration-color: var(--muted); text-underline-offset: 2px; }
a:hover { text-decoration: underline; }
svg { flex-shrink: 0; display: block; }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.scroll { overflow-y: auto; scrollbar-width: thin; scrollbar-color: var(--bg-4) transparent; }
.scroll::-webkit-scrollbar { width: 8px; height: 8px; }
.scroll::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 8px; border: 2px solid transparent; background-clip: padding-box; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.spacer { flex: 1; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ---------- Generic controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 16px; border-radius: 6px;
  background: var(--accent); color: var(--on-accent); font-weight: 600; font-size: 14px;
  transition: background 0.15s;
  white-space: nowrap;
}
.btn:hover:not(:disabled) { background: var(--accent-hover); }
a.btn:hover { text-decoration: none; }
.btn.secondary { background: var(--bg-4); color: var(--text); }
.btn.secondary:hover:not(:disabled) { background: var(--line-strong); }
.btn.danger { background: var(--red); color: var(--on-accent); }
.btn.danger:hover:not(:disabled) { background: var(--red-hover); }
.btn.success { background: var(--green); color: var(--on-accent); }
.btn.success:hover:not(:disabled) { background: var(--green-hover); }
.btn.ghost { background: transparent; color: var(--text-2); }
.btn.ghost:hover:not(:disabled) { background: var(--bg-3); color: var(--text); }
.btn.small { height: 32px; padding: 0 12px; font-size: 13px; }
.btn.block { width: 100%; }

.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 6px;
  color: var(--text-2); transition: background 0.12s, color 0.12s;
}
.icon-btn:hover:not(:disabled) { color: var(--text); background: var(--bg-3); }
.icon-btn.active { color: var(--text); }
.icon-btn.danger:hover { color: var(--red); }

.field { display: grid; gap: 8px; margin-bottom: 16px; }
.field > span { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.02em; color: var(--text-2); }
.input, .field input, .field select, .field textarea {
  width: 100%; height: 40px; padding: 0 12px; border-radius: 6px;
  background: var(--bg-0); border: 1px solid transparent; outline: none;
  transition: border-color 0.15s;
}
[data-theme="light"] .input, [data-theme="light"] .field input, [data-theme="light"] .field select { background: var(--bg-3); }
.input:focus, .field input:focus, .field select:focus { border-color: var(--accent); }
.field > span.hint, .field .hint { font-size: 13px; font-weight: 400; text-transform: none; letter-spacing: 0; color: var(--muted); }
.form-error { color: var(--red); font-size: 14px; min-height: 20px; margin: -4px 0 12px; }

.switch { position: relative; display: inline-block; width: 40px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .track { position: absolute; inset: 0; border-radius: 12px; background: var(--bg-4); transition: background 0.15s; cursor: pointer; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform 0.15s; }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }

.tag {
  display: inline-flex; align-items: center; gap: 4px; height: 18px; padding: 0 6px; border-radius: 4px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.01em; color: var(--text-2); background: var(--bg-4);
  vertical-align: 2px;
}
.tag.accent { background: var(--accent); color: var(--on-accent); }

/* ---------- Avatars ---------- */
.avatar {
  position: relative; flex-shrink: 0; display: grid; place-items: center;
  border-radius: 50%; color: #d8d8d8; font-weight: 600; user-select: none;
  width: var(--size, 40px); height: var(--size, 40px); font-size: calc(var(--size, 40px) * 0.4);
  background: var(--color, var(--accent));
}
.avatar .status {
  position: absolute; right: -2px; bottom: -2px;
  width: calc(var(--size, 40px) * 0.34); height: calc(var(--size, 40px) * 0.34); min-width: 10px; min-height: 10px;
  border-radius: 50%; background: var(--muted); border: 3px solid var(--status-ring, var(--bg-1));
}
.avatar .status.online { background: var(--green); }

/* ---------- Auth screens ---------- */
.auth {
  height: 100%; display: grid; place-items: center; padding: 24px;
  background: var(--bg-0);
  overflow-y: auto;
}
.auth-card {
  width: min(440px, 100%); background: var(--bg-2); border-radius: 12px; padding: 32px; box-shadow: var(--shadow);
}
.auth-card .logo { display: flex; justify-content: center; margin-bottom: 16px; }
.auth-card .logo { color: var(--text-2); }
.auth-card h1 { margin: 0 0 6px; font-size: 24px; text-align: center; }
.auth-card .sub { margin: 0 0 24px; text-align: center; color: var(--text-2); }
.auth-card .foot { margin-top: 16px; font-size: 13px; color: var(--muted); text-align: center; }

/* ---------- Shell layout ---------- */
.shell {
  height: 100%; display: grid;
  grid-template-columns: var(--rail) var(--sidebar) minmax(0, 1fr);
  padding-top: env(safe-area-inset-top);
}
.rail {
  background: var(--bg-0); display: flex; flex-direction: column; align-items: center; gap: 8px;
  padding: 12px 0; overflow-y: auto; scrollbar-width: none;
}
.rail-btn {
  position: relative; width: 48px; height: 48px; border-radius: 24px; display: grid; place-items: center;
  background: transparent; color: var(--muted); transition: background 0.15s, color 0.15s;
}
.rail-btn:hover, .rail-btn.active { border-radius: 24px; background: var(--bg-3); color: var(--text); }
.rail-btn::before {
  content: ""; position: absolute; left: -12px; top: 50%; width: 4px; height: 0; border-radius: 0 4px 4px 0;
  background: var(--text); transform: translateY(-50%); transition: height 0.15s;
}
.rail-btn:hover::before { height: 20px; }
.rail-btn.active::before { height: 40px; }
.rail-btn .badge { position: absolute; right: -4px; bottom: -4px; }
.rail-sep { width: 24px; height: 1px; background: var(--line-strong); margin: 2px 0; }
.rail-list { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.rail-btn.coll { background: var(--bg-2); color: var(--text-2); font-size: 15px; font-weight: 600; letter-spacing: 0.02em; flex-shrink: 0; }
.rail-btn.coll:hover, .rail-btn.coll.active { background: var(--bg-4); color: var(--text); }
/* The left bar can be put away; the button for that sits at the start of the sidebar's top bar. */
.shell.rail-hidden { grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.shell.rail-hidden .rail { display: none; }
.rail-toggle { position: relative; width: 28px; height: 28px; flex-shrink: 0; margin-left: -4px; }
.rail-toggle.dot::after { content: ""; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--red); }
.badge {
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; display: inline-grid; place-items: center;
  background: var(--red); color: var(--on-accent); font-size: 11px; font-weight: 700; line-height: 1;
  box-shadow: 0 0 0 3px var(--bg-0);
}

.sidebar { background: var(--bg-1); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { height: 48px; padding: 0 10px; display: flex; align-items: center; border-bottom: 1px solid var(--line); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.sidebar-head { gap: 6px; }
.sidebar-head .input { height: 28px; font-size: 13px; padding: 0 8px; background: var(--bg-0); flex: 1; min-width: 0; }
.coll-head { flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; }
.coll-name { flex: 1; min-width: 0; text-align: left; font-weight: 700; font-size: 15px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.coll-head .icon-btn { width: 28px; height: 28px; flex-shrink: 0; }
.conv.chan { gap: 6px; padding: 5px 8px; }
.chan-hash { display: grid; place-items: center; width: 20px; flex-shrink: 0; color: var(--muted); }
.cat-toggle { display: inline-flex; align-items: center; gap: 4px; min-width: 0; text-transform: inherit; letter-spacing: inherit; font-weight: inherit; }
.cat-toggle span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-title .st-actions { display: inline-flex; align-items: center; gap: 2px; flex-shrink: 0; }
.link-btn { font-size: 13px; color: var(--text-2); text-decoration: underline; text-decoration-color: var(--muted); text-underline-offset: 2px; }
.link-btn:hover { color: var(--text); }
.empty-state { text-align: center; padding: 24px; }
.empty-state h3 { margin: 0 0 6px; font-size: 20px; }
.empty-state p { margin: 0 0 16px; }
.sidebar-list { flex: 1; padding: 8px; min-height: 0; }
.section-title {
  display: flex; align-items: center; justify-content: space-between; padding: 16px 8px 4px;
  font-size: 12px; font-weight: 700; letter-spacing: 0.02em; text-transform: uppercase; color: var(--muted);
}
.section-title:hover { color: var(--text-2); }
.conv {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 6px 8px; border-radius: 6px;
  color: var(--muted); text-align: left; --status-ring: var(--bg-1);
  margin-bottom: 2px;
}
.conv:hover { background: var(--bg-3); color: var(--text-2); --status-ring: var(--bg-3); }
.conv.active { background: var(--bg-4); color: var(--text); --status-ring: var(--bg-4); }
.conv.unread { color: var(--text); }
.conv.unread .conv-name { font-weight: 600; }
.conv-text { flex: 1; min-width: 0; }
.conv-name { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.conv-sub { display: block; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--muted); }
.conv .icon-avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-4); color: var(--text-2); flex-shrink: 0; }
.conv .icon-avatar.group { background: var(--bg-4); color: var(--text); }
.empty-hint { padding: 12px 8px; font-size: 13px; color: var(--muted); }

.voice-bar {
  border-top: 1px solid var(--line); padding: 8px 10px; background: var(--bg-1);
  display: flex; align-items: center; gap: 6px;
}
.voice-bar .vb-text { flex: 1; min-width: 0; cursor: pointer; }
.voice-bar .vb-state { display: flex; align-items: center; gap: 6px; font-size: 14px; font-weight: 700; color: var(--green); }
.voice-bar .vb-state.pending { color: var(--yellow); }
.voice-bar .vb-peer { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-bar .vb-text:hover .vb-peer { text-decoration: underline; }

.user-panel {
  height: 56px; padding: 0 8px; display: flex; align-items: center; gap: 8px; background: color-mix(in srgb, var(--bg-0) 60%, var(--bg-1));
  --status-ring: color-mix(in srgb, var(--bg-0) 60%, var(--bg-1));
  padding-bottom: env(safe-area-inset-bottom);
}
.user-panel .up-text { flex: 1; min-width: 0; line-height: 1.2; }
.user-panel .up-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-panel .up-device { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.main { background: var(--bg-2); min-width: 0; min-height: 0; display: flex; flex-direction: column; position: relative; }
.view { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.topbar {
  height: 48px; flex-shrink: 0; padding: 0 8px 0 16px; display: flex; align-items: center; gap: 8px;
  border-bottom: 1px solid var(--line); box-shadow: 0 1px 2px rgba(0,0,0,.1); position: relative; z-index: 2;
}
.topbar .back { display: none; margin-left: -8px; }
.topbar .tb-icon { color: var(--muted); }
.topbar .tb-title { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .tb-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-left: 12px; margin-left: 4px; border-left: 1px solid var(--line-strong); }
.topbar .tb-actions { margin-left: auto; display: flex; gap: 4px; align-items: center; }

/* ---------- Chat ---------- */
.chat-wrap { flex: 1; min-height: 0; display: flex; }
.chat-col { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
/* Holds the message list and the "Jump to present" pill, so the pill floats over the list and never over the message box. */
.messages-wrap { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.messages { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; overflow-anchor: none; }
.messages-inner { padding: 16px 0 8px; display: flex; flex-direction: column; min-height: 100%; justify-content: flex-end; }
.chat-intro { padding: 16px 16px 8px; margin-bottom: 8px; }
.chat-intro .big { width: 68px; height: 68px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--on-accent); margin-bottom: 12px; }
.chat-intro h2 { margin: 0 0 4px; font-size: 28px; }
.chat-intro p { margin: 0; color: var(--text-2); }
.loading-older { text-align: center; padding: 8px; font-size: 13px; color: var(--muted); }
.readonly-note { flex-shrink: 0; padding: 12px 16px; font-size: 13px; color: var(--muted); text-align: center; border-top: 1px solid var(--line); }

.day-divider { display: flex; align-items: center; gap: 8px; margin: 16px 16px 8px; font-size: 12px; font-weight: 600; color: var(--muted); }
.day-divider::before, .day-divider::after { content: ""; flex: 1; height: 1px; background: var(--line-strong); }
.new-divider { display: flex; align-items: center; margin: 8px 16px 4px 16px; color: var(--muted); font-size: 11px; font-weight: 700; }
.new-divider::before { content: ""; flex: 1; height: 1px; background: var(--line-strong); }
.new-divider span { color: var(--muted); padding: 0 0 0 8px; line-height: 16px; letter-spacing: 0.04em; }

.msg { position: relative; padding: 2px 48px 2px 72px; margin-top: 17px; min-height: 44px; }
.msg.grouped { margin-top: 0; min-height: 0; }
.msg:hover, .msg.menu-open { background: rgba(0, 0, 0, 0.06); }
[data-theme="light"] .msg:hover { background: rgba(0, 0, 0, 0.025); }
.msg.highlight { animation: highlight 1.6s ease-out; }
@keyframes highlight { from { background: var(--accent-soft); } to { background: transparent; } }
.msg.pending { opacity: 0.55; }
.msg > .avatar { position: absolute; left: 16px; top: 4px; cursor: default; }
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; line-height: 22px; }
.msg-name { font-weight: 600; color: var(--text); }
.msg-time { font-size: 12px; color: var(--muted); }
.msg .gutter-time {
  position: absolute; left: 0; width: 72px; top: 4px; text-align: center; font-size: 11px; color: var(--muted);
  visibility: hidden; line-height: 22px;
}
.msg.grouped:hover .gutter-time { visibility: visible; }
.msg-text { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--text); }
.msg-text.jumbo { font-size: 44px; line-height: 1.2; }
.msg-text code { font-family: var(--mono); font-size: 0.85em; background: var(--bg-0); padding: 2px 4px; border-radius: 4px; }
.msg-text .code-block {
  font-family: var(--mono); font-size: 13px; background: var(--bg-0); border: 1px solid var(--line);
  border-radius: 6px; padding: 8px 10px; margin: 4px 0; white-space: pre; overflow-x: auto; max-width: 100%;
}
.msg-text .code-block code { background: none; padding: 0; font-size: inherit; }
.msg-text .spoiler { background: var(--bg-4); color: transparent; border-radius: 4px; cursor: pointer; padding: 0 2px; }
.msg-text .spoiler.revealed { color: inherit; background: var(--bg-3); }
.edited { font-size: 11px; color: var(--muted); margin-left: 4px; }

/* ---------- Message formatting (js/format.js): headers, quotes, lists, small text, the bar over selected text ---------- */
.msg-text strong { font-weight: 700; }
.msg-text .fmt-h { font-weight: 700; line-height: 1.3; margin: 8px 0 4px; }
.msg-text .fmt-h:first-child { margin-top: 2px; }
.msg-text .fmt-h1 { font-size: 1.5em; }
.msg-text .fmt-h2 { font-size: 1.25em; }
.msg-text .fmt-h3 { font-size: 1.05em; }
.msg-text .fmt-sub { font-size: 0.8em; line-height: 1.5; color: var(--text-2); }
.msg-text .fmt-quote { margin: 2px 0; padding: 0 0 0 10px; border-left: 3px solid var(--muted); }
.msg-text .fmt-list { margin: 2px 0; padding: 0 0 0 1.5em; }
.msg-text ol.fmt-list { padding-left: calc(1em + var(--fmt-digits, 1) * 0.62em); }
.msg-text .fmt-list .fmt-list { margin: 0; }
.msg-text .fmt-list li::marker { color: var(--text-2); }
.msg-text .spoiler:not(.revealed) * { visibility: hidden; }
.msg-text .spoiler:not(.revealed):hover { background: color-mix(in srgb, var(--bg-4) 86%, var(--text)); }
.msg-text .spoiler:focus-visible { outline-width: 1px; outline-offset: 1px; }
.fmt-bar {
  position: fixed; z-index: 60; display: flex; gap: 2px; padding: 3px; border-radius: 6px; background: var(--bg-4);
  border: 1px solid var(--line-strong); box-shadow: var(--shadow); animation: fadein 0.1s;
}
.fmt-btn { display: grid; place-items: center; width: 30px; height: 28px; border-radius: 4px; color: var(--text-2); font-size: 15px; line-height: 1; }
.fmt-btn:hover { background: color-mix(in srgb, var(--bg-4) 86%, var(--text)); color: var(--text); }
.fmt-btn-bold { font-weight: 800; }
.fmt-btn-italic { font-style: italic; font-family: Georgia, "Times New Roman", serif; font-size: 16px; }
.fmt-btn-strike { text-decoration: line-through; }
@media (hover: none) { .fmt-btn { width: 40px; height: 38px; font-size: 17px; } }
/* The rest of Markdown: smaller headers, a line across, highlight, tick boxes, tables, and what comes with a note from Obsidian. */
.msg-text .fmt-h4 { font-size: 1em; }
.msg-text .fmt-h5 { font-size: 0.92em; }
.msg-text .fmt-h6 { font-size: 0.85em; color: var(--text-2); }
.msg-text .fmt-title { font-weight: 700; }
.msg-text .fmt-rule { border: 0; border-top: 1px solid var(--fmt-line); margin: 8px 0; }
.msg-text { --fmt-line: color-mix(in srgb, var(--text) 18%, transparent); }
.msg-text mark { background: color-mix(in srgb, var(--text) 22%, transparent); color: inherit; border-radius: 3px; padding: 0 2px; }
.msg-text .fmt-wiki { text-decoration: underline dotted var(--muted); text-underline-offset: 2px; }
.msg-text .fmt-meta { color: var(--text-2); font-size: 12px; }
.msg-text li.fmt-task { list-style: none; }
.msg-text .fmt-box {
  display: inline-block; position: relative; box-sizing: border-box; width: 14px; height: 14px; margin: 0 7px 0 -21px;
  vertical-align: -2px; border: 1.5px solid var(--text-2); border-radius: 3px;
}
.msg-text .fmt-box.done { background: var(--text-2); }
.msg-text .fmt-box.done::after, .fmt-send-as input:checked::after {
  content: ""; position: absolute; left: 3px; top: 0; width: 4px; height: 7px;
  border: solid var(--bg-1); border-width: 0 1.5px 1.5px 0; transform: rotate(45deg);
}
.msg-text .fmt-table-frame { max-width: 100%; overflow-x: auto; margin: 4px 0; }
.msg-text .fmt-table { border-collapse: collapse; white-space: normal; overflow-wrap: normal; }
.msg-text .fmt-table th, .msg-text .fmt-table td { border: 1px solid var(--fmt-line); padding: 4px 10px; text-align: left; vertical-align: top; }
.msg-text .fmt-table th { font-weight: 700; background: var(--bg-3); }
/* A .md file waiting in the message box: the tick box that sends its text as a message. */
.fmt-send-as { display: flex; align-items: center; gap: 6px; font-size: 12px; line-height: 1.2; color: var(--text-2); cursor: pointer; user-select: none; }
.fmt-send-as.off { color: var(--muted); cursor: default; }
.fmt-send-as input {
  appearance: none; -webkit-appearance: none; position: relative; flex-shrink: 0; width: 14px; height: 14px; margin: 0; padding: 0;
  border: 1.5px solid var(--text-2); border-radius: 3px; background: none; cursor: inherit;
}
.fmt-send-as input:checked { background: var(--text-2); }
.fmt-send-as input:disabled { border-color: var(--muted); }
.fmt-send-as input:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
/* Formatting shown while typing: the message box's own letters are see-through, a styled copy lies over them.
   Nothing here may change how wide a letter is, so bold is drawn by thickening and no font or size changes. */
.fmt-wrap { position: relative; display: flex; flex: 1; min-width: 0; }
.fmt-wrap > textarea.fmt-on { color: transparent; caret-color: var(--text); }
.fmt-wrap > textarea.fmt-on::selection { color: transparent; }
.fmt-live {
  position: absolute; inset: 0; margin: 0; overflow: hidden; pointer-events: none; box-sizing: border-box;
  border: 0 solid transparent; white-space: pre-wrap; overflow-wrap: break-word; color: var(--text);
}
.fmt-live .b { -webkit-text-stroke: 0.55px currentColor; }
.fmt-live .i { font-style: italic; }
.fmt-live .u { text-decoration: underline; }
.fmt-live .s { text-decoration: line-through; }
.fmt-live .l { text-decoration: underline; text-decoration-color: var(--muted); text-underline-offset: 2px; }
.fmt-live .u.s { text-decoration: underline line-through; }
.fmt-live .sp { background: color-mix(in srgb, var(--text) 16%, transparent); border-radius: 3px; }
.fmt-live .c { background: var(--bg-0); border-radius: 3px; }
.fmt-live .hl { background: color-mix(in srgb, var(--text) 22%, transparent); border-radius: 3px; }
.fmt-live .sm { color: var(--text-2); }
.fmt-live .m { color: var(--muted); }
/* ---------- end of message formatting ---------- */

.reply-ref {
  position: relative; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--text-2);
  margin-bottom: 2px; min-width: 0; cursor: pointer; line-height: 18px;
}
.reply-ref::before {
  content: ""; position: absolute; left: -38px; top: 9px; width: 30px; height: 12px;
  border-left: 2px solid var(--line-strong); border-top: 2px solid var(--line-strong); border-top-left-radius: 6px;
}
.reply-ref .rr-name { font-weight: 600; color: var(--text); white-space: nowrap; flex-shrink: 0; max-width: 70%; overflow: hidden; text-overflow: ellipsis; }
.reply-ref .rr-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.85; }
.reply-ref:hover .rr-text { opacity: 1; }
.msg.has-reply { margin-top: 17px; }
.msg.has-reply > .avatar { top: 24px; }

.msg-tools {
  position: absolute; right: 16px; top: -14px; display: none; background: var(--bg-2); border: 1px solid var(--line-strong);
  border-radius: 6px; box-shadow: var(--shadow); padding: 2px; z-index: 3;
}
.msg:hover .msg-tools, .msg.menu-open .msg-tools { display: flex; }
.msg-tools .icon-btn { width: 30px; height: 30px; }
/* Extra buttons that only show while Shift is held. */
.msg-tools .shift-only { display: none; }
body.shift-held .msg-tools .shift-only { display: inline-grid; }
.msg-tools .icon-btn.danger { color: var(--red); }
@media (hover: none) { .msg:hover .msg-tools { display: none; } .msg:hover { background: none; } }

.attachments { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; max-width: 560px; }
.att-media {
  position: relative; border-radius: 8px; overflow: hidden; background: var(--bg-0); cursor: zoom-in;
  max-width: min(100%, 400px); max-height: 350px; display: block;
}
.att-media img, .att-media video { display: block; max-width: 100%; max-height: 350px; width: auto; height: auto; object-fit: contain; }
.attachments.multi .att-media { width: calc(50% - 3px); max-width: 278px; aspect-ratio: 1; }
.attachments.multi .att-media img, .attachments.multi .att-media video { width: 100%; height: 100%; max-height: none; object-fit: cover; }
.att-video { cursor: default; }
.att-video video { background: #000; }
/* The video player: Chat-Monki's own controls on the video, and a download button in the corner. */
.vp { background: #000; color: #fff; }
.attachments:not(.multi) .vp { min-width: min(100%, 240px); }
.vp video { margin: 0 auto; cursor: pointer; }
.vp-btn { width: 32px; height: 32px; border-radius: 6px; display: grid; place-items: center; color: #e6e6e6; flex-shrink: 0; }
.vp-btn:hover { color: #fff; background: rgba(255, 255, 255, .14); text-decoration: none; }
.vp-dl { position: absolute; top: 8px; right: 8px; background: rgba(0, 0, 0, .6); }
.vp-dl:hover { background: rgba(0, 0, 0, .85); }
.vp-bar {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: center; gap: 2px;
  padding: 20px 6px 4px; background: linear-gradient(transparent, rgba(0, 0, 0, .8));
}
.vp-bar, .vp-dl { opacity: 0; transition: opacity .15s; }
.vp:hover .vp-bar, .vp:focus-within .vp-bar, .vp.paused .vp-bar,
.vp:hover .vp-dl, .vp:focus-within .vp-dl, .vp.paused .vp-dl { opacity: 1; }
.vp.idle:not(.paused) .vp-bar, .vp.idle:not(.paused) .vp-dl { opacity: 0; }
.vp.idle:not(.paused) video { cursor: none; }
.vp-time { font-size: 12px; font-variant-numeric: tabular-nums; color: #e6e6e6; padding: 0 8px 0 2px; white-space: nowrap; }
.vp input[type="range"] {
  appearance: none; -webkit-appearance: none; height: 16px; min-width: 0; margin: 0; padding: 0;
  background: transparent; border: 0; cursor: pointer;
}
.vp input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, #fff var(--p, 0%), rgba(255, 255, 255, .3) var(--p, 0%)); }
.vp input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(to right, #fff var(--p, 0%), rgba(255, 255, 255, .3) var(--p, 0%)); }
.vp input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4px; border-radius: 50%; background: #fff; border: 0; opacity: 0; }
.vp input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 0; opacity: 0; }
.vp input[type="range"]:hover::-webkit-slider-thumb, .vp input[type="range"]:focus-visible::-webkit-slider-thumb { opacity: 1; }
.vp input[type="range"]:hover::-moz-range-thumb, .vp input[type="range"]:focus-visible::-moz-range-thumb { opacity: 1; }
.vp-seek { flex: 1; }
.vp-sound { display: flex; align-items: center; }
.vp-vol { width: 0; opacity: 0; transition: width .15s, opacity .15s; }
.vp-sound:hover .vp-vol, .vp-sound:focus-within .vp-vol { width: 64px; opacity: 1; margin: 0 6px 0 2px; }
.vp.small .vp-time, .vp.small .vp-sound { display: none; }
@media (hover: none) { .vp-vol { display: none; } }
.vp:fullscreen { max-width: none; max-height: none; width: 100vw; height: 100vh; border-radius: 0; display: grid; place-items: center; }
.vp:fullscreen video { width: 100%; height: 100%; max-width: none; max-height: none; object-fit: contain; }
/* A video this browser cannot play keeps its place and says so. */
.vp.failed { display: grid; place-items: center; background: var(--bg-1); border: 1px solid var(--line); color: var(--text-2); }
.attachments:not(.multi) .vp.failed { width: min(100%, 400px); aspect-ratio: 16 / 9; }
.vp-failed { display: grid; justify-items: center; gap: 6px; padding: 12px 16px; max-width: 100%; min-width: 0; text-align: center; }
.vp-failed .vp-why { font-size: 14px; color: var(--text); }
.vp-failed .vp-file { max-width: 100%; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vp-failed .btn { margin-top: 4px; }
.vp-progress { width: 180px; max-width: 100%; height: 4px; margin: 4px 0 2px; border-radius: 2px; background: var(--bg-4); overflow: hidden; }
.vp-progress i { display: block; width: 0; height: 100%; border-radius: 2px; background: var(--text-2); transition: width .8s linear; }
.att-file {
  display: flex; align-items: center; gap: 12px; width: min(100%, 420px); padding: 12px;
  background: var(--bg-1); border: 1px solid var(--line); border-radius: 8px;
}
.att-file .af-icon { color: var(--accent); }
.att-file .af-text { flex: 1; min-width: 0; }
.att-file .af-name { display: block; color: var(--text); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-file .af-size { font-size: 12px; color: var(--muted); }
.att-audio { width: min(100%, 420px); padding: 10px 12px; background: var(--bg-1); border: 1px solid var(--line); border-radius: 8px; }
.att-audio .af-name { font-size: 14px; margin-bottom: 6px; display: flex; gap: 8px; align-items: center; }
.att-audio audio { width: 100%; height: 36px; }

.call-log { padding: 6px 48px 6px 72px; margin-top: 8px; display: flex; align-items: center; gap: 8px; color: var(--text-2); font-size: 14px; position: relative; flex-wrap: wrap; }
.call-log .cl-icon { position: absolute; left: 30px; color: var(--green); }
.call-log .cl-icon.missed { color: var(--red); }
.call-log b { color: var(--text); font-weight: 600; }

.jump-latest {
  position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); z-index: 4;
  display: flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 16px;
  background: var(--accent); color: var(--on-accent); font-size: 13px; font-weight: 600; box-shadow: var(--shadow);
}

.composer-wrap { padding: 0 16px calc(8px + env(safe-area-inset-bottom)); flex-shrink: 0; }
.composer-bar {
  display: flex; align-items: center; gap: 8px; padding: 6px 12px; font-size: 13px; color: var(--text-2);
  background: var(--bg-1); border-radius: 8px 8px 0 0;
}
.composer-bar b { color: var(--text); }
.composer.flat-top { border-top-left-radius: 0; border-top-right-radius: 0; }
.tray {
  display: flex; gap: 10px; padding: 12px; overflow-x: auto; background: var(--bg-input); border-radius: 8px 8px 0 0;
  border-bottom: 1px solid var(--line);
}
.tray.flat-top { border-radius: 0; }
.conv .badge { box-shadow: none; margin-left: auto; }
.call-panel.expanded:not(.hidden) ~ .chat-wrap { display: none; }
.key-box {
  font-family: var(--mono); font-size: 14px; line-height: 1.5; word-break: break-all; user-select: all;
  background: var(--bg-0); border: 1px dashed var(--line-strong); border-radius: 8px; padding: 12px 14px; color: var(--text);
}
.key-input { font-family: var(--mono) !important; font-size: 13px !important; letter-spacing: 0.02em; }

/* ---------- Invites to a collective chat ---------- */
/* The box a key turns into inside a chat. */
.invite-card { width: min(100%, 400px); margin-top: 4px; padding: 12px 14px 14px; background: var(--bg-1); border: 1px solid var(--line); border-radius: 8px; }
.invite-card .ic-title { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; text-transform: uppercase; color: var(--muted); margin-bottom: 10px; }
.invite-card .ic-row { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.invite-card .ic-icon {
  width: 44px; height: 44px; border-radius: 14px; flex-shrink: 0; display: grid; place-items: center;
  background: var(--bg-4); color: var(--text); font-size: 15px; font-weight: 600; letter-spacing: 0.02em;
}
.invite-card .ic-text { flex: 1; min-width: 0; line-height: 1.3; }
.invite-card .ic-name { color: var(--text); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.invite-card .ic-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.invite-card .btn { flex-shrink: 0; min-width: 64px; }
/* The window an admin invites people from. */
.invite-window .invite-list { margin: 10px -8px 0; max-height: min(300px, 38vh); min-height: 64px; }
.invite-window .member .btn, .invite-window .member .tag { flex-shrink: 0; }
.invite-window .member .btn { min-width: 64px; }
.invite-key { margin-top: 12px; padding-top: 14px; border-top: 1px solid var(--line-strong); }
.invite-key .ik-label { font-size: 12px; font-weight: 700; letter-spacing: 0.03em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.invite-key .ik-row { display: flex; align-items: center; gap: 8px; }
.invite-key .key-box { flex: 1; min-width: 0; padding: 8px 10px; font-size: 12px; line-height: 1.4; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; word-break: normal; }
.invite-key .ik-note { margin-top: 8px; font-size: 12px; color: var(--muted); }
.notice { display: block; padding: 10px 12px; border-radius: 6px; background: var(--bg-3); color: var(--text-2); font-size: 13px; margin: 12px 0; }
.notice.warn { box-shadow: inset 2px 0 0 var(--yellow); }
.approval-card { display: flex; gap: 12px; align-items: center; }
.approval-meta { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.role-select { height: 32px; border-radius: 6px; background: var(--bg-0); border: 1px solid var(--line); padding: 0 8px; font-size: 13px; }
.account-devices { margin-top: 10px; border-top: 1px solid var(--line); padding-top: 6px; }
.account-devices .member { padding: 4px 6px; }
.tray-item {
  position: relative; width: 140px; flex-shrink: 0; background: var(--bg-1); border-radius: 6px; padding: 8px;
  display: flex; flex-direction: column; gap: 6px;
}
.tray-item .ti-thumb { height: 84px; border-radius: 4px; background: var(--bg-0); display: grid; place-items: center; overflow: hidden; color: var(--muted); }
.tray-item .ti-thumb img { width: 100%; height: 100%; object-fit: cover; }
.tray-item .ti-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tray-item .ti-progress { height: 4px; border-radius: 2px; background: var(--bg-4); overflow: hidden; }
.tray-item .ti-progress > div { height: 100%; background: var(--accent); width: 0; transition: width 0.2s; }
.tray-item.done .ti-progress > div { background: var(--green); }
.tray-item.error .ti-progress > div { background: var(--red); width: 100% !important; }
.tray-item .ti-remove { position: absolute; top: -6px; right: -6px; width: 24px; height: 24px; border-radius: 50%; background: var(--bg-2); border: 1px solid var(--line-strong); display: grid; place-items: center; color: var(--text-2); }
.tray-item .ti-remove:hover { color: var(--red); }

.composer {
  display: flex; align-items: flex-end; gap: 4px; padding: 0 6px 0 4px; min-height: 44px;
  background: var(--bg-input); border-radius: 8px;
}
.composer .icon-btn { width: 40px; height: 44px; border-radius: 8px; }
.composer .icon-btn:hover { background: transparent; }
.composer textarea {
  flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: transparent; padding: 11px 4px;
  max-height: 40vh; line-height: 22px; font-size: 15px;
}
.composer textarea::placeholder { color: var(--muted); }
.composer .send { color: var(--accent); }
.composer .send:disabled { color: var(--muted); opacity: 1; }
.typing-line { height: 20px; font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 6px; padding-left: 4px; }
.typing-dots { display: inline-flex; gap: 3px; }
.typing-dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--text-2); animation: blink 1.2s infinite; }
.typing-dots i:nth-child(2) { animation-delay: 0.2s; }
.typing-dots i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 0%, 60%, 100% { opacity: 0.25; } 30% { opacity: 1; } }

.drop-overlay {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; pointer-events: none;
  background: rgba(0, 0, 0, 0.55);
}
.drop-overlay > div { background: var(--bg-3); color: var(--text); padding: 24px 36px; border-radius: 10px; text-align: center; box-shadow: var(--shadow); }
.drop-overlay h3 { margin: 8px 0 4px; font-size: 20px; }

/* Members / devices panel */
.members { width: var(--members); flex-shrink: 0; background: var(--bg-1); padding: 8px; --status-ring: var(--bg-1); }
.member { display: flex; align-items: center; gap: 12px; padding: 6px 8px; border-radius: 6px; color: var(--text-2); }
.member:hover { background: var(--bg-3); --status-ring: var(--bg-3); }
.member.offline { opacity: 0.45; }
.member .m-text { flex: 1; min-width: 0; line-height: 1.25; }
.member .m-name { font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.member .m-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member .m-actions { display: none; gap: 2px; }
.member:hover .m-actions { display: flex; }
.member.clickable { width: 100%; text-align: left; cursor: pointer; }
.member .m-more { display: none; color: var(--muted); }
.member.clickable:hover .m-more, .member.clickable:focus-visible .m-more { display: inline-grid; }
@media (hover: none) { .member .m-more { display: inline-grid; } }
@media (hover: none) { .member .m-actions { display: flex; } }
.device-icon { width: 32px; height: 32px; border-radius: 50%; background: var(--bg-4); color: var(--text); display: grid; place-items: center; position: relative; flex-shrink: 0; }
.device-icon .status { position: absolute; right: -2px; bottom: -2px; width: 12px; height: 12px; border-radius: 50%; background: var(--muted); border: 3px solid var(--status-ring, var(--bg-1)); }
.device-icon .status.online { background: var(--green); }
.profile-card { padding: 16px 8px; }
.profile-card .avatar { margin-bottom: 12px; }
.profile-card h3 { margin: 0; font-size: 20px; }
.profile-card .pc-user { color: var(--text-2); font-size: 14px; }

/* ---------- Call panel ---------- */
.call-panel {
  flex-shrink: 0; background: #000; position: relative; display: flex; flex-direction: column;
  height: 300px; min-height: 180px; transition: height 0.2s;
  color: #fff;
}
.call-panel.audio { height: 220px; }
.call-panel.has-video { height: 46vh; }
.call-panel.expanded { height: auto; flex: 1; }
.call-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px; padding: 10px 12px; z-index: 3; background: linear-gradient(rgba(0,0,0,.55), transparent); }
.call-top .ct-state { font-size: 14px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.call-top .ct-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
.call-top .ct-dot.pending { background: var(--yellow); animation: blink 1.2s infinite; }
.call-top .icon-btn { color: #ddd; }
.call-top .icon-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.call-stage { flex: 1; min-height: 0; display: flex; flex-wrap: nowrap; align-items: center; justify-content: center; gap: 8px; padding: 48px 12px 8px; container-type: size; }
.tile {
  position: relative; background: #121212; border-radius: 10px; overflow: hidden; display: grid; place-items: center;
  /* One row that always fits: limited by the stage's width (shared between --n tiles) and its height. */
  aspect-ratio: 16 / 9; flex-shrink: 0;
  width: min(640px, calc((100cqw - (var(--n, 2) - 1) * 8px) / var(--n, 2)), calc(100cqh * 16 / 9));
  outline: 3px solid transparent; outline-offset: -3px; transition: outline-color 0.1s;
}
.call-panel.audio .tile { width: min(214px, calc((100cqw - (var(--n, 2) - 1) * 8px) / var(--n, 2)), calc(100cqh * 16 / 9)); }
.tile.speaking { outline-color: var(--green); }
/* Sound from this person is arriving with bits missing. */
.tile.lossy::after { content: "Weak connection"; position: absolute; left: 8px; top: 8px; z-index: 2; padding: 2px 6px; border-radius: 4px; background: rgba(0,0,0,.6); color: #ddd; font-size: 11px; font-weight: 600; }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile video.mirror { transform: scaleX(-1); }
.tile.screen video { object-fit: contain; }
.tile .t-avatar { z-index: 0; }
.tile .avatar { --status-ring: #121212; }
.tile .t-label {
  position: absolute; left: 8px; bottom: 8px; z-index: 2; display: flex; align-items: center; gap: 6px;
  padding: 3px 8px; border-radius: 6px; background: rgba(0,0,0,.6); font-size: 13px; font-weight: 600; max-width: calc(100% - 16px);
}
.tile .t-label span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .t-label .live { background: var(--red); color: var(--on-accent); font-size: 10px; font-weight: 800; padding: 1px 5px; border-radius: 4px; }
.tile .t-muted { color: var(--red); }
.tile .t-tools { position: absolute; right: 8px; bottom: 8px; z-index: 2; display: none; gap: 4px; align-items: center; padding: 2px 4px; border-radius: 6px; background: rgba(0,0,0,.6); }
.tile:hover .t-tools, .tile.touch-tools .t-tools { display: flex; }
.tile .t-tools .icon-btn { color: #ddd; width: 30px; height: 30px; }
.tile .t-tools .icon-btn:hover { background: rgba(255,255,255,.15); color: #fff; }
.tile .t-tools input[type="range"] { width: 90px; accent-color: #fff; }
.tile .t-center { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.tile.ringing .avatar { animation: ring 1.6s infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 rgba(255,255,255,.22); } 70% { box-shadow: 0 0 0 18px rgba(255,255,255,0); } 100% { box-shadow: 0 0 0 0 rgba(255,255,255,0); } }

.call-panel.focus .call-stage { flex-wrap: nowrap; flex-direction: column; padding-top: 44px; }
.call-panel.focus .tile.focused { height: auto; flex: 1; min-height: 0; width: 100%; aspect-ratio: auto; }
.call-panel.focus .strip { display: flex; gap: 8px; height: 96px; flex-shrink: 0; justify-content: center; width: 100%; }
.call-panel.focus .strip .tile { height: 100%; width: auto; }
.call-panel:not(.focus) .strip { display: contents; }

.call-controls { display: flex; justify-content: center; gap: 10px; padding: 8px 12px 14px; flex-shrink: 0; }
.cc-btn {
  width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center;
  background: #1b1b1b; color: #d8d8d8; transition: background 0.15s;
}
.cc-btn:hover:not(:disabled) { background: #262626; }
.cc-btn.on, .cc-btn.end { color: #0a0a0a; }
.cc-btn.off { background: #d8d8d8; color: #0a0a0a; }
.cc-btn.off:hover { background: #c4c4c4; }
.cc-btn.on { background: var(--green); }
.cc-btn.on:hover { background: var(--green-hover); }
.cc-btn.end { background: var(--red); width: 62px; border-radius: 25px; }
.cc-btn.end:hover { background: var(--red-hover); }

.incoming {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; background: rgba(0,0,0,.6);
  animation: fadein 0.15s;
}
.incoming-card {
  width: min(320px, calc(100% - 32px)); background: var(--bg-1); border-radius: 16px; padding: 28px 20px 20px;
  text-align: center; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center;
}
.incoming-card .avatar { animation: ring 1.6s infinite; margin-bottom: 16px; --status-ring: var(--bg-1); }
.incoming-card h3 { margin: 0 0 4px; font-size: 20px; }
.incoming-card p { margin: 0 0 24px; color: var(--text-2); font-size: 14px; }
.incoming-card .ic-actions { display: flex; gap: 20px; }
.incoming-card .cc-btn { width: 56px; height: 56px; }
.incoming-card .cc-label { font-size: 12px; color: var(--muted); margin-top: 6px; }
.incoming-card .ic-actions > div { display: flex; flex-direction: column; align-items: center; }

.hidden-media { position: fixed; width: 1px; height: 1px; left: -10px; top: -10px; opacity: 0; pointer-events: none; }

/* ---------- Voice chats (a call panel with a tile per person and per shared screen) ---------- */
.call-panel.room-panel .call-stage { flex-wrap: wrap; align-content: center; }
.call-panel.room-panel:not(.focus) .call-stage .tile { width: var(--tile-w, 200px); max-width: 100%; }
.call-panel.room-panel.focus .call-stage { flex-wrap: nowrap; }
.call-panel.room-panel.focus .strip { overflow-x: auto; justify-content: safe center; }
.tile.clickable { cursor: pointer; }
.tile .t-wait { color: #9a9a9a; font-weight: 500; }
.cc-btn.cant { opacity: .45; }
/* Looking at a voice chat without being in it: one slim row saying who is there, with a Join button. */
.call-panel.room-panel.lobby { height: auto; min-height: 0; background: var(--bg-1); color: var(--text); border-bottom: 1px solid var(--line); }
.room-panel.lobby .call-top, .room-panel.lobby .call-stage, .room-panel.lobby .call-controls { display: none; }
.room-panel:not(.lobby) .room-lobby { display: none; }
.room-lobby { display: flex; align-items: center; gap: 12px; padding: 10px 16px; flex-wrap: wrap; }
.rl-people { display: flex; padding-left: 8px; }
.rl-people .avatar { margin-left: -8px; --status-ring: var(--bg-1); box-shadow: 0 0 0 2px var(--bg-1); }
.rl-text { flex: 1; min-width: 140px; font-size: 14px; color: var(--text-2); }
/* The people in a voice chat, listed under it in the sidebar. */
.voice-people { padding: 0 8px 6px 34px; display: grid; gap: 2px; }
.voice-person { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 13px; color: var(--text-2); padding: 2px 0; }
.voice-person .vp-name { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.voice-person .vp-mark { color: var(--muted); display: grid; place-items: center; flex-shrink: 0; }
.voice-person .vp-live { background: var(--red); color: var(--on-accent); font-size: 9px; font-weight: 800; padding: 1px 4px; border-radius: 4px; flex-shrink: 0; }

/* ---------- Files view ---------- */
.files-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chip { height: 30px; padding: 0 12px; border-radius: 15px; background: var(--bg-3); color: var(--text-2); font-size: 13px; font-weight: 600; }
.chip:hover { color: var(--text); }
.chip.active { background: var(--accent); color: var(--on-accent); }
.files-toolbar .input { width: 220px; height: 32px; margin-left: auto; }
/* My Chats: one row per person or group. */
.chats-list { flex: 1; min-height: 0; padding: 0 16px 24px; }
.chats-list .section-title { padding: 16px 8px 10px; }
.chats-list .empty-hint { padding: 20px 8px; }
.chat-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 8px; border-top: 1px solid var(--line); border-radius: 8px;
  cursor: pointer; color: var(--text-2); --status-ring: var(--bg-2); outline: none;
}
.chat-row:hover, .chat-row:focus-visible { background: var(--bg-3); border-top-color: transparent; --status-ring: var(--bg-3); }
.chat-row:hover + .chat-row, .chat-row:focus-visible + .chat-row { border-top-color: transparent; }
.chat-row .icon-avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-4); color: var(--text); flex-shrink: 0; }
.chat-row .cr-text { flex: 1; min-width: 0; line-height: 1.3; }
.chat-row .cr-name { font-size: 15px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row .cr-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-row .badge { box-shadow: none; flex-shrink: 0; }
.chat-row .cr-actions { display: flex; gap: 6px; flex-shrink: 0; }
.chat-row .cr-actions .icon-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--bg-1); }
.chat-row .cr-actions .icon-btn:hover { background: var(--bg-0); }
.files-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; padding: 16px; align-content: start; }
.file-card { background: var(--bg-1); border-radius: 8px; overflow: hidden; display: flex; flex-direction: column; border: 1px solid var(--line); text-align: left; }
.file-card:hover { border-color: var(--line-strong); }
.file-card .fc-thumb { aspect-ratio: 4 / 3; background: var(--bg-0); display: grid; place-items: center; color: var(--muted); overflow: hidden; position: relative; }
.file-card .fc-thumb img, .file-card .fc-thumb video { width: 100%; height: 100%; object-fit: cover; }
.file-card .fc-thumb .fc-play { position: absolute; width: 40px; height: 40px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; display: grid; place-items: center; }
.file-card .fc-ext { font-size: 13px; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; margin-top: 6px; }
.file-card .fc-info { padding: 8px 10px; display: flex; gap: 6px; align-items: center; }
.file-card .fc-text { flex: 1; min-width: 0; }
.file-card .fc-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-card .fc-meta { font-size: 11px; color: var(--muted); }
.empty-state { margin: auto; text-align: center; color: var(--muted); padding: 40px 16px; }
.empty-state h3 { color: var(--text); margin: 12px 0 4px; }

/* ---------- Settings ---------- */
/* A list of categories on the left, the open category next to it. */
.settings-view { container: settings / inline-size; }
.settings-body { flex: 1; min-height: 0; display: flex; }
.settings-nav { width: 220px; flex-shrink: 0; padding: 4px 8px 24px; border-right: 1px solid var(--line); }
.settings-nav .section-title { padding: 16px 10px 6px; }
.settings-nav .section-title:hover { color: var(--muted); }
.set-item {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; margin-bottom: 2px; border-radius: 6px;
  color: var(--text-2); font-size: 15px; font-weight: 500; text-align: left;
}
.set-item:hover { background: var(--bg-3); color: var(--text); text-decoration: none; }
.set-item.active { background: var(--bg-4); color: var(--text); }
.set-item span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.set-item .badge { box-shadow: none; }
.set-item .go { display: none; color: var(--muted); }
.set-sep { height: 1px; background: var(--line); margin: 12px 10px; }
.settings { flex: 1; min-width: 0; min-height: 0; }
.settings-inner { max-width: 740px; padding: 24px 32px 64px; }
/* No room for both: the list is a page of its own, and each category opens from it. (640: also in settings.js.) */
@container settings (max-width: 640px) {
  .settings-nav { width: auto; flex: 1; border-right: 0; padding: 4px 12px 32px; }
  .set-item { padding: 12px 10px; }
  .set-item.active { background: none; color: var(--text-2); }
  .set-item .go { display: grid; }
  .settings-view.pick .settings { display: none; }
  .settings-view:not(.pick) .settings-nav { display: none; }
  .settings-view:not(.pick) .topbar .back { display: inline-grid; }
  .settings-inner { padding: 16px 12px 48px; }
}
.settings h2 { font-size: 20px; margin: 32px 0 4px; }
.settings h2:first-child { margin-top: 0; }
.settings .s-desc { color: var(--text-2); font-size: 14px; margin: 0 0 16px; }
.card { background: var(--bg-1); border-radius: 8px; padding: 16px; margin-bottom: 12px; border: 1px solid var(--line); --status-ring: var(--bg-1); }
.row { display: flex; align-items: center; gap: 12px; }
.row + .row { margin-top: 12px; }
.row .r-text { flex: 1; min-width: 0; }
.row .r-title { font-weight: 600; }
.row .r-sub { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 32px; height: 32px; border-radius: 50%; background: var(--c); box-shadow: inset 0 0 0 2px rgba(0,0,0,.15); display: grid; place-items: center; color: #fff; }
.swatch.active { box-shadow: 0 0 0 2px var(--bg-1), 0 0 0 4px var(--text); }
.seg { display: inline-flex; background: var(--bg-0); border-radius: 6px; padding: 2px; }
.seg button { height: 30px; padding: 0 12px; border-radius: 4px; font-size: 13px; font-weight: 600; color: var(--text-2); }
.seg button.active { background: var(--bg-4); color: var(--text); }
.url-row { display: flex; gap: 8px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.url-row:first-child { border-top: 0; padding-top: 0; }
.url-row code { font-family: var(--mono); font-size: 13px; background: var(--bg-0); padding: 3px 6px; border-radius: 4px; overflow-wrap: anywhere; }
/* The mailbox form: two boxes side by side, one under the other on a phone. */
/* The desktop app's "what do you want to share?" window */
.src-pick { max-height: min(460px, 60vh); overflow-y: auto; margin: 0 -8px; padding: 0 8px; scrollbar-width: thin; scrollbar-color: var(--bg-4) transparent; }
.src-pick .section-title { padding-left: 0; }
.src-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
.src-card { display: flex; flex-direction: column; gap: 6px; padding: 6px; border-radius: 8px; background: var(--bg-1); border: 1px solid var(--line); text-align: left; min-width: 0; }
.src-card:hover { background: var(--bg-3); }
.src-card.active { border-color: var(--accent); background: var(--bg-3); }
.src-thumb { display: block; aspect-ratio: 16 / 9; border-radius: 4px; background: #000; overflow: hidden; }
.src-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.src-name { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: 12px; color: var(--text-2); }
.src-name img { width: 16px; height: 16px; flex-shrink: 0; }
.src-name span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (max-width: 520px) { .src-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

/* Settings → Voice */
.voice-set .vs-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 16px; }
.voice-set .field { min-width: 0; align-content: start; }
.voice-set .field select { width: 100%; min-width: 0; }
.voice-set .field > span b, .voice-set .r-title b { font-weight: 500; color: var(--muted); text-transform: none; letter-spacing: 0; margin-left: 4px; }
.voice-set .r-title b { font-size: 13px; }
.voice-set input[type="range"] { width: 100%; margin: 0; padding: 0; height: 24px; border: 0; background: none; accent-color: var(--accent); }
.voice-set .row + .r-sub { margin-top: 8px; font-size: 13px; color: var(--muted); }
.voice-set .card > .r-sub { font-size: 13px; color: var(--muted); }
.vs-bar { flex: 1; min-width: 0; height: 8px; border-radius: 4px; background: var(--bg-4); overflow: hidden; }
.vs-level { height: 100%; width: 0; background: var(--text-2); transition: width 0.06s linear; }
.vs-level.cut { background: var(--muted); }
/* Input sensitivity: the slider lies on top of the bar that shows how loud the mic is. */
.vs-sens { position: relative; height: 28px; margin: 8px 0; }
.vs-sens .vs-bar { position: absolute; left: 0; right: 0; top: 10px; }
.vs-sens input[type="range"] { position: absolute; inset: 0; height: 28px; appearance: none; -webkit-appearance: none; background: transparent; cursor: pointer; }
.vs-sens input[type="range"]::-webkit-slider-runnable-track { background: transparent; height: 28px; }
.vs-sens input[type="range"]::-moz-range-track { background: transparent; height: 28px; }
.vs-sens input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 6px; height: 24px; margin-top: 2px; border-radius: 3px; background: var(--text); border: 0; }
.vs-sens input[type="range"]::-moz-range-thumb { width: 6px; height: 24px; border-radius: 3px; background: var(--text); border: 0; }
@media (max-width: 560px) { .voice-set .vs-grid { grid-template-columns: minmax(0, 1fr); } }

.mail-grid { display: grid; grid-template-columns: minmax(0, 1fr) 96px; gap: 0 12px; }
.mail-grid.even { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.mail-grid .field { min-width: 0; }
.mail-grid input, form.field input { min-width: 0; width: 100%; }
.steps { margin: 8px 0 0; padding-left: 20px; color: var(--text-2); font-size: 14px; }
.steps li { margin: 4px 0; }
.steps code { font-family: var(--mono); font-size: 13px; background: var(--bg-0); padding: 1px 5px; border-radius: 4px; color: var(--text); }

/* ---------- Overlays ---------- */
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { transform: scale(0.96); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-backdrop { position: fixed; inset: 0; z-index: 90; background: rgba(0,0,0,.65); display: grid; place-items: center; padding: 16px; animation: fadein 0.12s; }
.modal { width: min(460px, 100%); max-height: calc(100% - 32px); display: flex; flex-direction: column; background: var(--bg-2); border-radius: 10px; box-shadow: var(--shadow); animation: pop 0.15s; }
.modal-head { padding: 20px 20px 8px; display: flex; align-items: flex-start; gap: 12px; }
.modal-head h3 { margin: 0; font-size: 20px; flex: 1; }
.modal-body { padding: 8px 20px 16px; overflow-y: auto; color: var(--text-2); }
.modal-foot { padding: 14px 20px; background: var(--bg-1); border-radius: 0 0 10px 10px; display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.modal-foot-start { margin-right: auto; min-width: 0; }
.modal-remember { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); cursor: pointer; user-select: none; }

.menu {
  position: fixed; z-index: 95; min-width: 188px; padding: 6px; border-radius: 6px; background: var(--bg-float);
  box-shadow: var(--shadow); border: 1px solid var(--line); animation: pop 0.08s;
}
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 8px; border-radius: 4px; font-size: 14px; color: var(--text-2); text-align: left; }
.menu-item:hover { background: var(--accent); color: var(--on-accent); }
.menu-item.danger { color: var(--red); }
.menu-item.danger:hover { background: var(--red); color: var(--on-accent); }
.menu-item:disabled:hover { background: none; color: var(--text-2); }
.menu-sep { height: 1px; background: var(--line-strong); margin: 4px 6px; }
.menu-title { padding: 6px 8px 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.sheet-backdrop { position: fixed; inset: 0; z-index: 94; background: rgba(0,0,0,.5); animation: fadein 0.12s; }
.menu.sheet { left: 8px !important; right: 8px; top: auto !important; bottom: calc(8px + env(safe-area-inset-bottom)); border-radius: 12px; padding: 8px; }
.menu.sheet .menu-item { padding: 12px; font-size: 16px; }

/* Notices appear at the top, just under the top bar, so they never cover the call buttons or the message box. */
#toasts { position: fixed; z-index: 200; left: 50%; top: calc(56px + env(safe-area-inset-top, 0px)); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: max-content; max-width: calc(100% - 24px); }
.toast { pointer-events: auto; background: var(--bg-float); color: var(--text); border: 1px solid var(--line-strong); padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); font-size: 14px; animation: pop 0.15s; display: flex; gap: 8px; align-items: center; }
.toast.error { border-color: var(--red); }
.toast.success { border-color: var(--green); }

/* The file preview. Its backdrop is solid, so nothing of the page behind shows through the name and the buttons. */
.lightbox { position: fixed; inset: 0; z-index: 150; background: #050505; display: flex; flex-direction: column; animation: fadein 0.12s; color: #fff; }
.lb-top { flex-shrink: 0; display: flex; align-items: center; gap: 4px; height: calc(44px + env(safe-area-inset-top, 0px)); padding: env(safe-area-inset-top, 0px) 6px 0 14px; }
.lb-top .lb-name { flex: 1; min-width: 0; margin-right: 8px; display: flex; align-items: baseline; gap: 10px; white-space: nowrap; }
.lb-top .lb-file { min-width: 0; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.lb-top .lb-meta { flex-shrink: 0; font-size: 12px; color: #999; }
.lb-top .icon-btn { color: #ccc; flex-shrink: 0; }
.lb-top .icon-btn:hover { color: #fff; background: rgba(255,255,255,.12); }
/* One cell that is exactly as big as the space left under the top row: the picture is fitted inside it. Without
   the fixed cell size, "at most 100% high" has nothing to measure against and a big picture runs off the bottom. */
.lb-stage { flex: 1; min-height: 0; min-width: 0; display: grid; grid-template: minmax(0, 1fr) / minmax(0, 1fr); place-items: center; position: relative; padding: 4px 56px 20px; overflow: hidden; }
.lb-stage img, .lb-stage video { display: block; min-width: 0; min-height: 0; max-width: 100%; max-height: 100%; width: auto; height: auto; object-fit: contain; border-radius: 4px; }
.lb-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border-radius: 50%; background: rgba(255,255,255,.1); color: #fff; display: grid; place-items: center; }
.lb-nav:hover { background: rgba(255,255,255,.2); }
.lb-nav.prev { left: 8px; }
.lb-nav.next { right: 8px; }

.banner { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 6px 12px; font-size: 13px; font-weight: 600; background: var(--bg-3); color: var(--text-2); }
.banner.offline { box-shadow: inset 0 -1px 0 var(--red); }

.spinner { width: 18px; height: 18px; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-fill { flex: 1; display: grid; place-items: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .members { display: none; }
}
@media (max-width: 760px) {
  :root { --sidebar: 1fr; }
  .shell { grid-template-columns: var(--rail) 1fr; }
  .shell.rail-hidden { grid-template-columns: 1fr; }
  .shell .main { display: none; }
  .shell.show-main { grid-template-columns: 1fr; }
  .shell.show-main .rail, .shell.show-main .sidebar { display: none; }
  .shell.show-main .main { display: flex; }
  .topbar .back { display: inline-grid; }
  .topbar .tb-sub { display: none; }
  .msg { padding-right: 16px; padding-left: 64px; }
  .msg > .avatar { left: 12px; }
  .msg .gutter-time { width: 64px; }
  .call-log { padding-left: 64px; padding-right: 16px; }
  .call-log .cl-icon { left: 26px; }
  .reply-ref::before { left: -32px; width: 24px; }
  .composer-wrap { padding: 0 8px calc(6px + env(safe-area-inset-bottom)); }
  .call-panel.has-video { height: 40vh; }
  .tile { max-width: 100%; }
  .call-panel:not(.focus) .tile { max-width: calc(50% - 4px); }
  .files-toolbar .input { width: 100%; margin-left: 0; }
  .files-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; padding: 8px; }
  .mail-grid.even { grid-template-columns: minmax(0, 1fr); }
  .lb-top .lb-name { flex-direction: column; align-items: flex-start; gap: 0; line-height: 1.25; }
  .lb-top .lb-file { max-width: 100%; }
  .lb-stage { padding: 0 0 12px; }
  .lb-nav { display: none; }
}
