/* ---------- 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); }
.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; }
.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 .input { height: 28px; font-size: 13px; padding: 0 8px; background: var(--bg-0); }
.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; }
.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); }

.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; }

.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; }
.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; }
@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; }
.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; }
.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; }
@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); }
.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; }

/* ---------- 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; }
.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 ---------- */
.settings { flex: 1; min-height: 0; }
.settings-inner { max-width: 740px; padding: 24px 24px 64px; margin: 0 auto; }
.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; }
.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; gap: 8px; }

.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; }

#toasts { position: fixed; z-index: 200; left: 50%; bottom: 24px; 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); }

.lightbox { position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,.9); display: flex; flex-direction: column; animation: fadein 0.12s; color: #fff; }
.lb-top { display: flex; align-items: center; gap: 8px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); }
.lb-top .lb-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lb-top .lb-meta { font-size: 12px; color: #aaa; font-weight: 400; }
.lb-top .icon-btn { color: #ccc; }
.lb-top .icon-btn:hover { color: #fff; background: rgba(255,255,255,.12); }
.lb-stage { flex: 1; min-height: 0; display: grid; place-items: center; position: relative; padding: 0 56px 24px; }
.lb-stage img, .lb-stage video { max-width: 100%; max-height: 100%; 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 .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; }
  .settings-inner { padding: 16px 12px 48px; }
  .lb-stage { padding: 0 0 16px; }
  .lb-nav { display: none; }
}
