:root {
  --bg: #ffffff;
  --bg-2: #f4f4f7;
  --bg-3: #e9e9ef;
  --text: #16161d;
  --muted: #6b6b78;
  --border: #e2e2e8;
  --accent: #4f46e5;
  --accent-text: #ffffff;
  --accent-soft: #eef0ff;
  --bubble-in: #eeeef3;
  --bubble-in-text: #16161d;
  --bubble-out: #4f46e5;
  --bubble-out-text: #ffffff;
  --danger: #d6336c;
  --warn-bg: #fff4d6;
  --warn-text: #7a5300;
  --shadow: 0 8px 30px rgba(0, 0, 0, .12);
  --radius: 14px;
  --bar-h: 56px;
  color-scheme: light dark;
}
/* Dark colors: when the device is dark (unless Light was picked in Settings), or when Dark was picked. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121217;
    --bg-2: #1b1b22;
    --bg-3: #26262f;
    --text: #ececf1;
    --muted: #9a9aa8;
    --border: #2c2c36;
    --accent: #7c74ff;
    --accent-soft: #24234a;
    --bubble-in: #26262f;
    --bubble-in-text: #ececf1;
    --bubble-out: #5b52f0;
    --danger: #f06595;
    --warn-bg: #3d3011;
    --warn-text: #ffd875;
    --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  }
}
:root[data-theme="dark"] {
  --bg: #121217;
  --bg-2: #1b1b22;
  --bg-3: #26262f;
  --text: #ececf1;
  --muted: #9a9aa8;
  --border: #2c2c36;
  --accent: #7c74ff;
  --accent-soft: #24234a;
  --bubble-in: #26262f;
  --bubble-in-text: #ececf1;
  --bubble-out: #5b52f0;
  --danger: #f06595;
  --warn-bg: #3d3011;
  --warn-text: #ffd875;
  --shadow: 0 8px 30px rgba(0, 0, 0, .5);
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); font-size: 14px; margin: 4px 0; }

/* ---------- buttons & inputs ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--bg-2);
  border-radius: 10px;
  padding: 10px 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 14px; }
.btn.link { background: none; border: none; color: var(--accent); font-weight: 500; padding: 6px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: none; cursor: pointer; color: var(--text); flex: none;
}
.icon-btn:hover { background: var(--bg-3); }
.icon-btn.small { width: 28px; height: 28px; font-size: 13px; }
input:not([type=checkbox]), textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
label { display: grid; gap: 6px; font-size: 14px; font-weight: 600; }
.stack { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1; min-width: 0; }
.form-error { color: var(--danger); font-size: 14px; margin: 0; min-height: 0; }
.form-error:empty { display: none; }

/* ---------- auth ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; background: var(--bg-2); }
.auth-card { width: 100%; max-width: 380px; background: var(--bg); padding: 28px 24px; border-radius: 20px; box-shadow: var(--shadow); text-align: center; }
.auth-card form { text-align: left; margin-top: 20px; }
.auth-logo { border-radius: 18px; }
.auth h1 { margin-top: 10px; font-size: 24px; }
.setup-note { background: var(--accent-soft); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin: 0; }

/* ---------- layout ---------- */
.app { height: 100dvh; display: grid; grid-template-columns: 340px 1fr; }
.sidebar { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--bg); }
.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); position: relative; }
.chat-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.chat-placeholder { margin: auto; color: var(--muted); padding: 24px; text-align: center; }
.back-btn { display: none; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .chat { position: fixed; inset: 0; transform: translateX(100%); transition: transform .22s ease; z-index: 5; }
  .app.chat-open .chat { transform: none; }
  .back-btn { display: inline-grid; }
}

.bar {
  height: calc(var(--bar-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 8px 0;
  display: flex; align-items: center; gap: 6px;
  border-bottom: 1px solid var(--border);
  flex: none;
  background: var(--bg);
}
.bar-title { flex: 1; font-size: 18px; padding-left: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.banner { display: flex; align-items: center; gap: 8px; padding: 10px 12px; background: var(--accent-soft); font-size: 14px; }
.banner span { flex: 1; }
.banner.warn { background: var(--warn-bg); color: var(--warn-text); justify-content: center; }

/* ---------- avatars ---------- */
.avatar {
  --size: 44px;
  width: var(--size); height: var(--size); border-radius: 50%;
  display: inline-grid; place-items: center; flex: none;
  color: #fff; font-weight: 700; font-size: calc(var(--size) * .4);
  background: var(--c, #888);
  position: relative;
  user-select: none;
}
.avatar.group { background: var(--bg-3); color: var(--muted); }
.avatar.group svg { width: 55%; height: 55%; }
.avatar.online::after {
  content: ''; position: absolute; right: 0; bottom: 0;
  width: 28%; height: 28%; border-radius: 50%;
  background: #2f9e44; border: 2px solid var(--bg);
}
.avatar.sm { --size: 28px; }
.avatar.md { --size: 36px; }
.avatar-btn { border: none; background: none; padding: 4px; cursor: pointer; border-radius: 50%; }

/* ---------- conversation list ---------- */
.conv-list { list-style: none; margin: 0; padding: 4px 0; overflow-y: auto; flex: 1; }
.conv {
  display: flex; gap: 12px; align-items: center;
  padding: 10px 14px; cursor: pointer; border-radius: 12px; margin: 2px 6px;
}
.conv:hover { background: var(--bg-2); }
.conv.active { background: var(--accent-soft); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; gap: 8px; align-items: baseline; }
.conv-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--muted); flex: none; }
.conv-bottom { display: flex; gap: 8px; align-items: center; }
.conv-preview { flex: 1; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv.unread .conv-preview { color: var(--text); font-weight: 600; }
.unread-badge {
  background: var(--accent); color: var(--accent-text);
  font-size: 12px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px;
  border-radius: 10px; display: inline-grid; place-items: center;
}
.muted-icon { width: 14px; height: 14px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }

/* ---------- chat ---------- */
.chat-title-btn {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px;
  border: none; background: none; padding: 4px 6px; border-radius: 10px; cursor: pointer; text-align: left;
}
.chat-title-btn:hover { background: var(--bg-2); }
.chat-title-btn .avatar { --size: 38px; }
.chat-title-text { display: grid; min-width: 0; }
.chat-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub.typing { color: var(--accent); }

.messages { flex: 1; overflow-y: auto; padding: 12px 12px 4px; overscroll-behavior: contain; outline: none; }
.load-more { text-align: center; padding: 8px; }
.day { text-align: center; margin: 16px 0 8px; }
.day span { font-size: 12px; font-weight: 600; color: var(--muted); background: var(--bg-2); padding: 4px 10px; border-radius: 10px; }
.sys { text-align: center; font-size: 13px; color: var(--muted); margin: 8px 24px; }

.msg { display: flex; gap: 8px; align-items: flex-end; margin-top: 2px; }
.msg.first { margin-top: 10px; }
.msg.out { flex-direction: row-reverse; }
.msg .avatar { --size: 28px; visibility: hidden; }
.msg.last .avatar { visibility: visible; }
.msg-col { display: flex; flex-direction: column; max-width: min(75%, 560px); min-width: 0; }
.msg.out .msg-col { align-items: flex-end; }
.sender { font-size: 12px; font-weight: 600; color: var(--c, var(--muted)); margin: 0 12px 2px; }
.bubble {
  padding: 8px 12px; border-radius: 18px;
  background: var(--bubble-in); color: var(--bubble-in-text);
  white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word;
  position: relative;
}
.msg.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); }
.msg.in:not(.last) .bubble { border-bottom-left-radius: 6px; }
.msg.in:not(.first) .bubble { border-top-left-radius: 6px; }
.msg.out:not(.last) .bubble { border-bottom-right-radius: 6px; }
.msg.out:not(.first) .bubble { border-top-right-radius: 6px; }
.bubble a { color: inherit; text-decoration: underline; }
.bubble.emoji-only { background: none !important; font-size: 40px; line-height: 1.15; padding: 0 4px; }
.bubble.deleted { font-style: italic; opacity: .7; background: none !important; border: 1px dashed var(--border); color: var(--muted) !important; }
.bubble.media { padding: 0; background: none !important; overflow: hidden; }
.bubble.media img, .bubble.media video {
  display: block; max-width: min(100%, 320px); max-height: 360px; border-radius: 16px; cursor: zoom-in;
  background: var(--bg-3); min-width: 80px; min-height: 80px; object-fit: cover;
}
.bubble.media video { cursor: auto; }
.bubble audio { max-width: 260px; }
.file-card { display: flex; gap: 10px; align-items: center; text-decoration: none !important; color: inherit; }
.file-card svg { flex: none; }
.file-card small { display: block; opacity: .75; }
.caption { padding: 6px 4px 0; white-space: pre-wrap; }
.msg.pending .bubble { opacity: .6; }
.msg.failed .bubble { outline: 2px solid var(--danger); cursor: pointer; }
.meta { font-size: 11px; color: var(--muted); margin: 2px 8px 0; }
.meta.failed { color: var(--danger); }
.progress { height: 4px; background: var(--bg-3); border-radius: 2px; width: 160px; overflow: hidden; margin: 6px 0; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

.composer {
  display: flex; align-items: flex-end; gap: 6px;
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--bg); flex: none;
}
.composer textarea {
  resize: none; max-height: 160px; border-radius: 20px; padding: 9px 14px; line-height: 1.35;
  background: var(--bg-2); border-color: transparent;
}
.send-btn { color: var(--accent); }
.send-btn:disabled { color: var(--muted); opacity: .5; }
.drop-hint {
  position: absolute; inset: 0; display: grid; place-items: center; z-index: 3;
  background: color-mix(in srgb, var(--accent) 15%, transparent);
  border: 3px dashed var(--accent); font-size: 20px; font-weight: 700; color: var(--accent); pointer-events: none;
}

/* ---------- dialogs ---------- */
dialog.sheet {
  border: none; padding: 0; border-radius: 20px; background: var(--bg); color: var(--text);
  width: min(460px, calc(100% - 24px)); max-height: min(720px, 90dvh); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, .45); }
.sheet-body { display: grid; gap: 14px; padding: 16px 18px 20px; overflow-y: auto; max-height: inherit; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 20px; }
.sheet h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 6px; }
.sheet section { display: grid; gap: 6px; }
@media (max-width: 760px) {
  dialog.sheet { width: 100%; max-width: 100%; margin: auto 0 0; border-radius: 20px 20px 0 0; max-height: 92dvh; }
  .sheet-body { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

.people { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 320px; overflow-y: auto; }
.person { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; font-weight: 500; }
label.person { cursor: pointer; display: flex; font-size: 16px; }
label.person:hover { background: var(--bg-2); }
.person input { width: 20px; height: 20px; accent-color: var(--accent); margin-left: auto; }
.person .who { display: grid; }
.person .who small { color: var(--muted); font-weight: 400; }
.group-name { font-weight: 600; }
.switch-row { display: flex; align-items: center; gap: 10px; font-weight: 500; font-size: 15px; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--accent); }

.invites { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.invite { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg-2); border-radius: 10px; font-size: 14px; }
.invite code { font-size: 15px; font-weight: 700; letter-spacing: .06em; }
.invite .grow { flex: 1; min-width: 0; }
.invite small { display: block; color: var(--muted); }
.version { text-align: center; }

dialog.viewer {
  border: none; padding: 0; background: rgba(0, 0, 0, .92); width: 100vw; height: 100dvh; max-width: none; max-height: none;
  display: none; place-items: center;
}
dialog.viewer[open] { display: grid; }
.viewer img { max-width: 100vw; max-height: 100dvh; object-fit: contain; }
.viewer-close { position: fixed; top: calc(10px + env(safe-area-inset-top)); right: 10px; color: #fff; background: rgba(255, 255, 255, .15); }
.viewer-dl { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); right: 16px; text-decoration: none; }

.toast {
  position: fixed; left: 50%; bottom: calc(80px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 50; max-width: calc(100% - 32px); cursor: pointer;
}

.spinner {
  display: inline-block; width: 20px; height: 20px; border-radius: 50%;
  border: 2px solid var(--bg-3); border-top-color: var(--accent); animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- welcome / how-to ---------- */
.steps { margin: 0; padding-left: 22px; display: grid; gap: 14px; }
.steps li::marker { font-weight: 700; color: var(--accent); }
.steps strong { display: block; margin-bottom: 2px; }
.steps p { margin: 0 0 6px; color: var(--muted); font-size: 15px; }
.steps .btn { justify-self: start; }

/* ---------- calls ---------- */
.avatar.xl { --size: 112px; }
.join-call-btn { background: #2f9e44; border-color: #2f9e44; color: #fff; flex: none; }

.call-ctl {
  display: grid; justify-items: center; gap: 6px; border: none; background: none; color: #fff;
  font-size: 12px; font-weight: 600; cursor: pointer; min-width: 64px;
}
.call-ctl svg {
  width: 56px; height: 56px; padding: 15px; border-radius: 50%;
  background: rgba(255, 255, 255, .16); box-sizing: border-box;
}
.call-ctl:hover svg { background: rgba(255, 255, 255, .26); }
.call-ctl.off svg { background: #fff; color: #16161d; }
.call-ctl.hangup svg { background: #e03131; }
.call-ctl.hangup:hover svg { background: #c92a2a; }
.call-ctl.accept svg { background: #2f9e44; }
.call-ctl.accept:hover svg { background: #2b8a3e; }

.incoming {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(10, 10, 20, .88); backdrop-filter: blur(6px); color: #fff;
  padding: env(safe-area-inset-top) 16px env(safe-area-inset-bottom);
}
.incoming-card { display: grid; justify-items: center; gap: 10px; text-align: center; }
.incoming-avatar .avatar { --size: 112px; animation: pulse 1.6s ease-in-out infinite; }
.incoming-name { font-size: 26px; font-weight: 700; margin-top: 8px; }
.incoming-kind { color: rgba(255, 255, 255, .75); }
.incoming-actions { display: flex; gap: 28px; margin-top: 36px; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(124, 116, 255, .6); } 50% { box-shadow: 0 0 0 18px rgba(124, 116, 255, 0); } }

.call-screen {
  position: fixed; inset: 0; z-index: 50; background: #0b0b12; color: #fff;
  display: flex; flex-direction: column;
}
.call-head {
  display: flex; align-items: center; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) 10px 8px; position: relative; z-index: 2;
}
.call-head .icon-btn { color: #fff; }
.call-head .icon-btn:hover { background: rgba(255, 255, 255, .12); }
.call-name { font-weight: 700; font-size: 18px; }
.call-status { font-size: 13px; color: rgba(255, 255, 255, .7); font-variant-numeric: tabular-nums; }

.call-tiles { flex: 1; min-height: 0; display: grid; gap: 6px; padding: 0 6px; grid-template-columns: 1fr; grid-auto-rows: 1fr; }
.call-tiles[data-count="2"] { grid-template-columns: 1fr; }
.call-tiles[data-count="3"], .call-tiles[data-count="4"] { grid-template-columns: 1fr 1fr; }
.call-tiles[data-count="5"], .call-tiles[data-count="6"] { grid-template-columns: 1fr 1fr; }
@media (min-width: 761px) {
  .call-tiles[data-count="2"] { grid-template-columns: 1fr 1fr; }
  .call-tiles[data-count="5"], .call-tiles[data-count="6"] { grid-template-columns: 1fr 1fr 1fr; }
}
.tile { position: relative; background: #1b1b26; border-radius: 16px; overflow: hidden; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.call-tiles[data-count="1"] .tile video { object-fit: contain; }
.tile-avatar { position: absolute; inset: 0; display: none; place-items: center; }
.tile.no-video .tile-avatar { display: grid; }
.tile.no-video video { opacity: 0; } /* keep playing: it carries the audio */
.tile.waiting .tile-avatar .avatar { animation: pulse 1.6s ease-in-out infinite; }
.tile-label {
  position: absolute; left: 10px; bottom: 10px; font-size: 13px; font-weight: 600;
  background: rgba(0, 0, 0, .5); padding: 4px 10px; border-radius: 10px; max-width: calc(100% - 20px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tile-label:empty { display: none; }

.self-view {
  position: absolute; right: 14px; bottom: calc(120px + env(safe-area-inset-bottom)); z-index: 3;
  width: 110px; aspect-ratio: 3 / 4; border-radius: 14px; overflow: hidden;
  background: #222; box-shadow: 0 6px 20px rgba(0, 0, 0, .5); border: 2px solid rgba(255, 255, 255, .25);
}
@media (min-width: 761px) { .self-view { width: 200px; aspect-ratio: 16 / 10; } }
.self-view video { width: 100%; height: 100%; object-fit: cover; }
.self-view.mirror video { transform: scaleX(-1); }

.call-controls {
  display: flex; justify-content: center; gap: 14px; flex-wrap: wrap;
  padding: 18px 12px calc(18px + env(safe-area-inset-bottom));
}

.call-pill {
  position: fixed; z-index: 40; left: 50%; transform: translateX(-50%);
  top: calc(8px + env(safe-area-inset-top));
  background: #2f9e44; color: #fff; border: none; border-radius: 20px; padding: 8px 16px;
  font-weight: 600; font-size: 14px; box-shadow: var(--shadow); cursor: pointer;
  display: flex; align-items: center; gap: 6px; max-width: calc(100% - 32px); white-space: nowrap; overflow: hidden;
}
.call-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: #fff; animation: blink 1.2s infinite; flex: none; }
@keyframes blink { 50% { opacity: .3; } }
body.in-call { overflow: hidden; }

/* ---------- profile photos ---------- */
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
.avatar.online::after { z-index: 1; }
.profile-photo-row { display: flex; align-items: center; gap: 16px; margin-bottom: 6px; }
.profile-photo-row .avatar.xl { --size: 88px; }

/* ---------- reactions ---------- */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin: -6px 6px 2px; position: relative; z-index: 1; }
.msg.out .reactions { justify-content: flex-end; }
.reaction {
  display: inline-flex; align-items: center; gap: 3px;
  border: 1px solid var(--border); background: var(--bg); border-radius: 12px;
  padding: 1px 7px; font-size: 14px; line-height: 20px; cursor: pointer;
}
.reaction span { font-size: 12px; font-weight: 600; color: var(--muted); }
.reaction.mine { border-color: var(--accent); background: var(--accent-soft); }
.reaction.mine span { color: var(--accent); }

.react-btn {
  align-self: center; border: none; background: none; color: var(--muted); cursor: pointer;
  width: 28px; height: 28px; border-radius: 50%; font-size: 18px; line-height: 1; opacity: 0; flex: none;
}
.msg:hover .react-btn, .react-btn:focus-visible { opacity: 1; }
.react-btn:hover { background: var(--bg-2); }

/* Long-press on phones opens our menu instead of the system text-selection popup. */
@media (hover: none) {
  .bubble { -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }
}

.menu-backdrop { position: fixed; inset: 0; z-index: 30; }
.msg-menu {
  position: fixed; z-index: 31; background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);
  padding: 6px; max-width: min(340px, calc(100vw - 16px));
}
.menu-quick { display: flex; gap: 2px; }
.menu-emoji {
  border: none; background: none; font-size: 26px; width: 42px; height: 42px; border-radius: 50%;
  cursor: pointer; display: grid; place-items: center; flex: none;
}
.menu-emoji:hover { background: var(--bg-2); }
.menu-emoji.mine { background: var(--accent-soft); }
.menu-emoji.more-btn { font-size: 24px; color: var(--muted); background: var(--bg-2); }
.menu-more { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 2px; padding-top: 6px; border-top: 1px solid var(--border); margin-top: 6px; max-height: 180px; overflow-y: auto; }
.menu-more .menu-emoji { width: 40px; height: 40px; font-size: 24px; }
.menu-who { list-style: none; margin: 6px 0 0; padding: 6px 6px 0; border-top: 1px solid var(--border); font-size: 14px; display: grid; gap: 4px; }
.who-emoji { display: inline-block; width: 26px; }
.menu-actions { display: grid; margin-top: 6px; border-top: 1px solid var(--border); padding-top: 4px; }
.menu-actions button { border: none; background: none; text-align: left; padding: 10px; border-radius: 10px; font-weight: 500; cursor: pointer; }
.menu-actions button:hover { background: var(--bg-2); }
.menu-actions .danger { color: var(--danger); }

/* ---------- replies ---------- */
.quote {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  border: none; cursor: pointer; font: inherit; color: inherit;
  background: rgba(0, 0, 0, .08); border-left: 3px solid var(--c-line, var(--accent));
  border-radius: 8px; padding: 5px 8px; margin: 0 0 6px; min-width: 0;
}
.msg.out .bubble .quote { background: rgba(255, 255, 255, .18); --c-line: rgba(255, 255, 255, .8); }
.msg-col > .quote { background: var(--bg-2); max-width: 100%; margin-bottom: 2px; border-radius: 12px; }
.quote-text { display: grid; min-width: 0; flex: 1; }
.quote-name { font-size: 12px; font-weight: 700; color: var(--c); }
.msg.out .bubble .quote-name { color: inherit; }
.quote-preview { font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quote img { width: 36px; height: 36px; border-radius: 6px; object-fit: cover; flex: none; }
.quote.deleted .quote-preview { font-style: italic; }

.reply-bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 10px 0 14px;
  background: var(--bg); border-top: 1px solid var(--border); flex: none;
}
.reply-bar + .composer { border-top: none; }
.reply-bar-text { display: grid; flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 8px; }
.reply-bar-name { font-size: 13px; font-weight: 700; color: var(--accent); }
.reply-bar-preview { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.hover-actions { display: flex; align-self: center; flex: none; }
.msg-col { transition: transform .15s ease; }
.msg-col.swipe-ready .bubble { box-shadow: 0 0 0 2px var(--accent); }
@keyframes flash { 0%, 100% { background: transparent; } 25%, 60% { background: var(--accent-soft); } }
.msg.flash { animation: flash 1.6s ease; border-radius: 12px; }

/* ---------- voice messages ---------- */
.mic-btn { color: var(--accent); }
.recorder {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border); background: var(--bg); flex: none;
}
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #e03131; animation: blink 1s infinite; flex: none; }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 42px; }
.rec-level { flex: 1; height: 6px; background: var(--bg-3); border-radius: 3px; overflow: hidden; }
.rec-level > div { height: 100%; width: 0; background: var(--accent); transition: width .08s linear; }

.voice { display: flex; align-items: center; gap: 10px; min-width: 200px; }
.vp-btn {
  width: 36px; height: 36px; border-radius: 50%; border: none; cursor: pointer; flex: none;
  display: grid; place-items: center; background: var(--accent); color: var(--accent-text);
}
.msg.out .vp-btn { background: rgba(255, 255, 255, .9); color: var(--bubble-out); }
.vp-btn svg { width: 18px; height: 18px; stroke: none; }
.vp-bar { flex: 1; height: 6px; border-radius: 3px; background: rgba(127, 127, 127, .3); cursor: pointer; position: relative; overflow: hidden; }
.msg.out .vp-bar { background: rgba(255, 255, 255, .35); }
.vp-fill { height: 100%; width: 0; background: currentColor; border-radius: 3px; }
.vp-time { font-size: 12px; font-variant-numeric: tabular-nums; opacity: .85; min-width: 34px; text-align: right; }

/* ---------- search ---------- */
.sidebar-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.search-view { overflow-y: auto; padding-bottom: 12px; }
.search-bar {
  display: flex; align-items: center; gap: 8px; margin: 8px 10px 4px; padding: 0 10px;
  background: var(--bg-2); border-radius: 12px; flex: none;
}
.search-bar svg { width: 18px; height: 18px; color: var(--muted); flex: none; }
.search-bar input { border: none; background: none; padding: 9px 0; min-width: 0; flex: 1; }
.search-bar input:focus { border: none; }
.search-scope {
  display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted);
  background: var(--bg); border-radius: 10px; padding: 2px 4px 2px 8px; white-space: nowrap; max-width: 45%;
  overflow: hidden; text-overflow: ellipsis;
}
.search-scope b { color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.search-scope button { border: none; background: none; color: var(--muted); cursor: pointer; padding: 2px 4px; }
.search-heading { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 12px 16px 4px; }
.search-hint { color: var(--muted); font-size: 14px; margin: 8px 16px; }
.search-chats { flex: none; overflow: visible; padding: 0; }
.search-results { list-style: none; margin: 0; padding: 0; }
.search-result { display: flex; gap: 12px; align-items: flex-start; padding: 10px 14px; margin: 2px 6px; border-radius: 12px; cursor: pointer; }
.search-result:hover { background: var(--bg-2); }
.search-snippet { font-size: 14px; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.search-snippet b { color: var(--text); font-weight: 600; }
.search-snippet mark { background: color-mix(in srgb, var(--accent) 28%, transparent); color: var(--text); border-radius: 3px; padding: 0 1px; }
.search-more { margin: 8px auto 0; display: block; }

/* ---------- availability / Do Not Disturb ---------- */
.status-pill {
  display: inline-flex; align-items: center; gap: 6px; flex: none;
  border: 1px solid var(--border); background: var(--bg-2); color: var(--text);
  border-radius: 14px; padding: 4px 10px; font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.status-pill:hover { background: var(--bg-3); }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: #2f9e44; flex: none; }
.status-pill.dnd { background: #3b2f63; border-color: #5f4bb6; color: #fff; }
.status-pill.dnd .status-dot { background: none; width: auto; height: auto; }
.status-pill.dnd .status-dot::before { content: '🌙'; font-size: 12px; }
@media (max-width: 380px) { .status-pill #status-label { display: none; } }

.avatar.dnd::after {
  content: '🌙'; position: absolute; right: -3px; bottom: -3px;
  font-size: max(9px, calc(var(--size) * .3)); line-height: 1;
  background: var(--bg); border-radius: 50%; padding: 1px; z-index: 1;
}

.status-menu { width: 270px; }
.status-menu-head { font-weight: 700; padding: 6px 10px 2px; }
.status-menu-note { font-size: 13px; color: var(--muted); margin: 0 10px 4px; }
.muted-inline { color: var(--muted); font-weight: 400; }

/* ---------- attach menu, camera, appearance ---------- */
.chat-inner { position: relative; }
.msg-menu.attach-menu { position: absolute; left: 8px; top: auto; width: 220px; z-index: 31; }
.attach-menu .menu-actions { margin: 0; border: none; padding: 0; }

.camera-dialog {
  border: none; padding: 0; width: min(720px, 100vw); max-height: 100dvh; background: #000; color: #fff; border-radius: 16px; overflow: hidden;
}
.camera-dialog::backdrop { background: rgba(0, 0, 0, .8); }
.camera-dialog video { display: block; width: 100%; max-height: 70dvh; object-fit: contain; background: #000; }
.camera-dialog video.mirror { transform: scaleX(-1); }
.camera-error { padding: 40px 24px; text-align: center; margin: 0; }
.camera-controls { display: flex; align-items: center; justify-content: space-evenly; padding: 14px 10px 18px; }
.shutter {
  width: 68px; height: 68px; border-radius: 50%; border: 4px solid #fff; background: rgba(255, 255, 255, .25); cursor: pointer;
  box-shadow: inset 0 0 0 4px #000;
}
.shutter:hover { background: rgba(255, 255, 255, .45); }
.shutter:disabled { opacity: .4; cursor: default; }

.segmented { display: flex; background: var(--bg-2); border-radius: 12px; padding: 4px; gap: 4px; }
.segmented button {
  flex: 1; border: none; background: none; border-radius: 9px; padding: 8px 6px; font-weight: 600; font-size: 14px;
  color: var(--muted); cursor: pointer; white-space: nowrap;
}
.segmented button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.profile-photo-row .stack { gap: 6px; }
