:root {
  --primary: #3390ec;
  --primary-hover: #2a7fd4;
  --bg: #ffffff;
  --bg-2: #f4f4f5;
  --bg-hover: #f1f1f1;
  --bg-active: #3390ec;
  --text: #000000;
  --text-2: #707579;
  --border: #e6e6e6;
  --bubble-in: #ffffff;
  --bubble-out: #e3fee0;
  --bubble-out-meta: #4fae4e;
  --link: #3390ec;
  --danger: #e53935;
  --online: #0ac630;
  --shadow: 0 2px 12px rgba(0, 0, 0, .14);
  --chat-bg: linear-gradient(150deg, #d8e7b5 0%, #a9d0a3 40%, #8cc5b5 75%, #b6d6a1 100%);
  --service-bg: rgba(0, 0, 0, .22);
  --radius: 12px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --primary: #8774e1;
  --primary-hover: #7a66d8;
  --bg: #212121;
  --bg-2: #181818;
  --bg-hover: #2c2c2c;
  --bg-active: #8774e1;
  --text: #ffffff;
  --text-2: #aaaaaa;
  --border: #303030;
  --bubble-in: #212121;
  --bubble-out: #766ac8;
  --bubble-out-meta: #e0dcff;
  --link: #a99bff;
  --chat-bg: linear-gradient(150deg, #10151b 0%, #1b2a28 45%, #15202b 100%);
  --service-bg: rgba(0, 0, 0, .4);
  --shadow: 0 2px 12px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font: 15px/1.35 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text); background: var(--bg); overflow: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--text-2); }
svg.ic { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.ic.filled { fill: currentColor; stroke: none; }

/* splash */
.splash { position: fixed; inset: 0; display: grid; place-items: center; background: var(--bg); z-index: 100; }
.splash img { width: 96px; height: 96px; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(.9); opacity: .7; } }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 44px; padding: 0 20px;
  border-radius: 10px; font-weight: 500; background: var(--bg-2); transition: background .15s; }
.btn:hover { background: var(--bg-hover); }
.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.danger { color: var(--danger); }
.btn.wide { width: 100%; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; color: var(--text-2); flex: none; transition: background .15s; }
.icon-btn:hover { background: var(--bg-hover); }
.icon-btn.round.primary { width: 48px; height: 48px; background: var(--primary); color: #fff; }
.icon-btn.round.primary:hover { background: var(--primary-hover); }
.icon-btn.danger { color: var(--danger); }

/* auth */
.auth { position: fixed; inset: 0; display: grid; place-items: center; padding: 20px; overflow: auto; background: var(--bg); }
.auth-card { width: 100%; max-width: 360px; text-align: center; }
.auth-logo { width: 140px; height: 140px; }
.auth h1 { margin: 12px 0 6px; font-size: 30px; }
.tabs { display: flex; background: var(--bg-2); border-radius: 10px; padding: 4px; margin: 22px 0 16px; }
.tab { flex: 1; height: 36px; border-radius: 8px; color: var(--text-2); font-weight: 500; }
.tab.active { background: var(--bg); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.field { display: block; text-align: left; margin-bottom: 14px; position: relative; }
.field > span { display: block; font-size: 13px; color: var(--text-2); margin: 0 0 4px 4px; }
.field input, .field textarea { width: 100%; height: 48px; padding: 0 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--bg); outline: none; transition: border-color .15s; }
.field textarea { height: 80px; padding: 12px 14px; resize: none; }
.field input:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.field small { display: block; margin: 4px 0 0 4px; color: var(--text-2); font-size: 12px; }
.form-error { color: var(--danger); min-height: 20px; font-size: 14px; margin-bottom: 8px; }

/* layout */
.app { position: fixed; inset: 0; display: flex; }
.sidebar { position: relative; width: 26vw; min-width: 300px; max-width: 420px; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--bg); }
.chat { position: relative; flex: 1; min-width: 0; background: var(--chat-bg); background-attachment: fixed; display: flex; }
.info { width: 340px; flex: none; border-left: 1px solid var(--border); background: var(--bg); overflow-y: auto; }

/* sidebar */
.side-head { display: flex; align-items: center; gap: 8px; padding: 8px 12px; height: 56px; flex: none; }
.search { flex: 1; display: flex; align-items: center; gap: 8px; height: 42px; padding: 0 12px; border-radius: 22px;
  background: var(--bg-2); color: var(--text-2); border: 2px solid transparent; }
.search:focus-within { border-color: var(--primary); background: var(--bg); }
.search svg.ic { width: 20px; height: 20px; }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); }
.conn-state { padding: 6px 16px; font-size: 13px; color: var(--text-2); background: var(--bg-2); }
.chat-list { flex: 1; overflow-y: auto; padding: 0 8px 80px; }
.list-title { padding: 12px 10px 6px; font-size: 14px; font-weight: 500; color: var(--text-2); }
.list-empty { padding: 30px 16px; text-align: center; color: var(--text-2); }
.chat-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; cursor: pointer; user-select: none; }
.chat-item:hover { background: var(--bg-hover); }
.chat-item.active { background: var(--bg-active); color: #fff; }
.chat-item.active .ci-sub, .chat-item.active .ci-time, .chat-item.active .ci-sub b { color: rgba(255,255,255,.85) !important; }
.chat-item.active .badge { background: #fff; color: var(--bg-active); }
.ci-body { flex: 1; min-width: 0; }
.ci-row { display: flex; align-items: center; gap: 6px; }
.ci-title { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }
.ci-title svg.ic { width: 16px; height: 16px; }
.ci-time { font-size: 12px; color: var(--text-2); flex: none; display: flex; align-items: center; gap: 2px; }
.ci-time svg.ic { width: 16px; height: 16px; color: var(--online); }
.chat-item.active .ci-time svg.ic { color: #fff; }
.ci-sub { flex: 1; min-width: 0; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.ci-sub b { color: var(--text); font-weight: 500; }
.ci-sub .typing { color: var(--primary); }
.badge { min-width: 22px; height: 22px; padding: 0 7px; border-radius: 11px; background: var(--online); color: #fff; font-size: 12px;
  font-weight: 600; display: inline-grid; place-items: center; flex: none; }
.badge.muted-badge { background: #c4c9cc; }
.fab { position: absolute; right: 20px; bottom: 20px; width: 56px; height: 56px; border-radius: 50%; background: var(--primary);
  color: #fff; display: grid; place-items: center; box-shadow: var(--shadow); transition: transform .15s; }
.fab:hover { transform: scale(1.05); }

/* avatar */
.avatar { position: relative; width: 54px; height: 54px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 20px; background: var(--c1, #3390ec); background-image: linear-gradient(var(--c1), var(--c2));
  user-select: none; }
.avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; display: block; }
.avatar svg.ic { width: 55%; height: 55%; }
.avatar.online::after { content: ""; position: absolute; right: 1px; bottom: 1px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--online); border: 2px solid var(--bg); }
.avatar.sm { width: 40px; height: 40px; font-size: 16px; }
.avatar.xs { width: 34px; height: 34px; font-size: 14px; }
.avatar.lg { width: 120px; height: 120px; font-size: 44px; }
.avatar.lg.online::after { width: 20px; height: 20px; right: 6px; bottom: 6px; }

/* dropdown menus */
.dropdown { position: absolute; z-index: 30; min-width: 240px; padding: 6px; border-radius: 12px; background: var(--bg);
  box-shadow: var(--shadow); border: 1px solid var(--border); animation: pop .12s ease-out; }
@keyframes pop { from { transform: scale(.95); opacity: 0; } }
.dropdown button, .ctx button { display: flex; align-items: center; gap: 14px; width: 100%; padding: 9px 12px; border-radius: 8px;
  font-size: 15px; text-align: left; white-space: nowrap; }
.dropdown button:hover, .ctx button:hover { background: var(--bg-hover); }
.dropdown button svg.ic, .ctx button svg.ic { width: 20px; height: 20px; color: var(--text-2); }
.dropdown button.danger, .ctx button.danger, .dropdown button.danger svg.ic, .ctx button.danger svg.ic { color: var(--danger); }
#menu { top: 52px; left: 12px; transform-origin: top left; }
.fab-menu { right: 20px; bottom: 86px; transform-origin: bottom right; }
.attach-menu { left: 8px; bottom: 64px; transform-origin: bottom left; }
.ctx { position: fixed; z-index: 60; min-width: 190px; padding: 6px; border-radius: 12px; background: var(--bg); box-shadow: var(--shadow);
  border: 1px solid var(--border); animation: pop .12s ease-out; }

/* chat view */
.empty-chat { flex: 1; display: grid; place-items: center; }
.empty-chat span, .service span { background: var(--service-bg); color: #fff; padding: 4px 12px; border-radius: 14px; font-size: 14px; font-weight: 500; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.chat-head { display: flex; align-items: center; gap: 6px; height: 56px; padding: 0 8px 0 16px; background: var(--bg); flex: none;
  border-bottom: 1px solid var(--border); }
.back-btn { display: none; margin-left: -8px; }
.chat-head-main { flex: 1; min-width: 0; display: flex; align-items: center; gap: 12px; cursor: pointer; }
.chat-head-text { min-width: 0; }
.chat-title { font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status { font-size: 14px; color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-status.online, .chat-status.typing { color: var(--primary); }
.messages { flex: 1; overflow-y: auto; overflow-x: hidden; overscroll-behavior: contain; }
.messages-inner { max-width: 760px; margin: 0 auto; padding: 12px 16px 8px; display: flex; flex-direction: column; min-height: 100%; justify-content: flex-end; }
.loader { text-align: center; padding: 8px; color: var(--text-2); font-size: 13px; }
.date-sep { position: sticky; top: 6px; z-index: 2; align-self: center; margin: 10px 0; }
.date-sep span, .service span { display: inline-block; }
.date-sep span { background: var(--service-bg); color: #fff; padding: 3px 10px; border-radius: 14px; font-size: 13px; font-weight: 500; }
.service { align-self: center; text-align: center; margin: 6px 0; max-width: 80%; }

.msg { display: flex; align-items: flex-end; gap: 8px; margin: 1px 0; max-width: 100%; }
.msg.out { flex-direction: row-reverse; }
.msg.group-end { margin-bottom: 6px; }
.msg .avatar { visibility: hidden; }
.msg.group-end .avatar { visibility: visible; }
.msg.flash .bubble { animation: flash 1.2s; }
@keyframes flash { 30% { filter: brightness(.8); } }
.bubble { position: relative; max-width: min(480px, 78%); padding: 6px 10px 6px; border-radius: 16px; background: var(--bubble-in);
  box-shadow: 0 1px 1px rgba(0,0,0,.1); word-wrap: break-word; overflow-wrap: anywhere; min-width: 64px; }
.msg.out .bubble { background: var(--bubble-out); }
.msg.in.group-end .bubble { border-bottom-left-radius: 4px; }
.msg.out.group-end .bubble { border-bottom-right-radius: 4px; }
.bubble .sender { font-size: 14px; font-weight: 600; margin-bottom: 2px; cursor: pointer; }
.bubble .text { white-space: pre-wrap; }
.bubble .meta { float: right; margin: 6px -2px -4px 10px; font-size: 12px; color: var(--text-2); display: flex; align-items: center; gap: 2px;
  user-select: none; line-height: 1; height: 16px; position: relative; top: 2px; }
.msg.out .bubble .meta { color: var(--bubble-out-meta); }
.bubble .meta svg.ic { width: 16px; height: 16px; }
.bubble.media { padding: 0; overflow: hidden; }
.bubble.media .sender { padding: 6px 10px 0; }
.bubble.media .photo { display: block; max-width: 100%; max-height: 420px; min-width: 160px; min-height: 80px; object-fit: cover; cursor: zoom-in; background: rgba(0,0,0,.08); }
.bubble.media video { display: block; max-width: 100%; max-height: 420px; background: #000; }
.bubble.media .caption { padding: 6px 10px 6px; }
.bubble.media.no-caption .meta { position: absolute; right: 8px; bottom: 8px; margin: 0; top: auto; padding: 3px 6px; height: auto;
  border-radius: 10px; background: rgba(0,0,0,.45); color: #fff !important; }
.reply-quote { display: block; border-left: 3px solid var(--primary); padding: 2px 8px; margin: 2px 0 4px; border-radius: 4px;
  background: color-mix(in srgb, var(--primary) 10%, transparent); font-size: 14px; cursor: pointer; min-width: 0; }
.msg.out .reply-quote { border-color: var(--bubble-out-meta); background: color-mix(in srgb, var(--bubble-out-meta) 14%, transparent); }
.reply-quote b { display: block; color: var(--primary); font-weight: 600; font-size: 13px; }
.msg.out .reply-quote b { color: var(--bubble-out-meta); }
.reply-quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.bubble.media .reply-quote { margin: 6px 8px 4px; }
.file-row { display: flex; align-items: center; gap: 12px; padding: 2px 0; min-width: 200px; }
.file-icon { width: 48px; height: 48px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; flex: none; }
.msg.out .file-icon { background: var(--bubble-out-meta); }
:root[data-theme="dark"] .msg.out .file-icon { color: var(--bubble-out); }
.file-info { min-width: 0; }
.file-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; color: var(--text); }
.file-size { font-size: 13px; color: var(--text-2); }
.msg.out .file-size { color: var(--bubble-out-meta); }
.voice { display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 2px 0; }
.voice .file-icon svg.ic { width: 22px; height: 22px; }
.voice-body { flex: 1; min-width: 0; }
.wave { display: flex; align-items: center; gap: 2px; height: 26px; cursor: pointer; }
.wave i { flex: 1; min-width: 2px; max-width: 3px; border-radius: 2px; background: color-mix(in srgb, var(--primary) 35%, transparent); }
.wave i.on { background: var(--primary); }
.msg.out .wave i { background: color-mix(in srgb, var(--bubble-out-meta) 40%, transparent); }
.msg.out .wave i.on { background: var(--bubble-out-meta); }
.voice-time { font-size: 13px; color: var(--text-2); }
.msg.out .voice-time { color: var(--bubble-out-meta); }

.scroll-down { position: absolute; right: 20px; bottom: 84px; width: 48px; height: 48px; border-radius: 50%; background: var(--bg);
  color: var(--text-2); display: grid; place-items: center; box-shadow: var(--shadow); z-index: 5; }
.scroll-down .badge { position: absolute; top: -6px; right: -4px; background: var(--primary); }
.drop-zone { position: absolute; inset: 64px 12px 12px; z-index: 20; border: 3px dashed var(--primary); border-radius: 16px;
  background: color-mix(in srgb, var(--bg) 85%, transparent); display: grid; place-items: center; font-size: 20px; color: var(--primary); pointer-events: none; }

/* composer */
.composer-wrap { position: relative; max-width: 760px; width: 100%; margin: 0 auto; padding: 0 16px 14px; padding-bottom: max(14px, env(safe-area-inset-bottom)); flex: none; }
.composer, .recorder { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; min-width: 0; min-height: 48px; max-height: 200px; resize: none; padding: 13px 14px; border: 0; outline: 0;
  border-radius: 14px; background: var(--bg); box-shadow: 0 1px 2px rgba(0,0,0,.12); line-height: 1.4; }
.composer > .icon-btn:first-child { width: 48px; height: 48px; background: var(--bg); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.recorder { align-items: center; background: var(--bg); border-radius: 14px; padding: 0 0 0 4px; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.recorder #recTime { font-variant-numeric: tabular-nums; min-width: 44px; }
.rec-hint { flex: 1; color: var(--text-2); }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.reply-bar, .upload-bar { display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 12px; margin-bottom: 6px; border-radius: 12px;
  background: var(--bg); color: var(--primary); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.reply-bar-text { flex: 1; min-width: 0; border-left: 2px solid var(--primary); padding-left: 8px; }
.reply-bar-text b { display: block; font-size: 14px; }
.reply-bar-text span { display: block; color: var(--text); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-bar { position: relative; overflow: hidden; padding: 10px 14px; color: var(--text); font-size: 14px; }
.upload-progress { position: absolute; left: 0; top: 0; bottom: 0; background: color-mix(in srgb, var(--primary) 18%, transparent); width: 0; transition: width .2s; }
.upload-bar span { position: relative; }
.join-bar { text-align: center; padding: 12px; background: var(--bg); border-radius: 14px; box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.join-bar .btn { height: 40px; }

/* info panel */
.info-head { display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 8px; position: sticky; top: 0; background: var(--bg); z-index: 1; }
.info-head h3 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; }
.info-hero { text-align: center; padding: 8px 16px 18px; }
.info-hero .avatar { margin: 0 auto 12px; cursor: pointer; }
.info-hero h2 { margin: 0; font-size: 20px; word-break: break-word; }
.info-hero .chat-status { margin-top: 2px; }
.info-rows { padding: 0 8px; border-bottom: 8px solid var(--bg-2); }
.info-row { display: flex; align-items: flex-start; gap: 20px; padding: 10px 12px; border-radius: 10px; }
.info-row svg.ic { color: var(--text-2); margin-top: 2px; }
.info-row div { min-width: 0; word-break: break-word; white-space: pre-wrap; }
.info-row small { display: block; color: var(--text-2); font-size: 13px; }
.info-row.click { cursor: pointer; }
.info-row.click:hover { background: var(--bg-hover); }
.info-actions { padding: 8px; display: grid; gap: 4px; }
.info-section-title { padding: 14px 20px 6px; font-weight: 500; color: var(--text-2); font-size: 14px; display: flex; align-items: center; justify-content: space-between; }
.member { display: flex; align-items: center; gap: 12px; padding: 7px 12px; margin: 0 8px; border-radius: 10px; cursor: pointer; }
.member:hover { background: var(--bg-hover); }
.member-body { flex: 1; min-width: 0; }
.member-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-sub { font-size: 13px; color: var(--text-2); }
.member-sub.online { color: var(--primary); }
.member-role { font-size: 13px; color: var(--text-2); }
.member .icon-btn { width: 34px; height: 34px; }

/* modal */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 16px; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 420px; max-height: calc(100% - 20px); overflow-y: auto; background: var(--bg); border-radius: 16px; padding: 18px 20px 20px; box-shadow: var(--shadow); animation: pop .15s ease-out; }
.modal h3 { margin: 0 0 16px; font-size: 20px; display: flex; align-items: center; justify-content: space-between; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal .avatar-edit { display: grid; place-items: center; margin-bottom: 16px; }
.modal .avatar-edit .avatar { cursor: pointer; }
.modal .avatar-edit small { margin-top: 6px; color: var(--primary); cursor: pointer; }
.pick-list { max-height: 260px; overflow-y: auto; margin: 0 -8px 10px; }
.pick-list .member.selected { background: color-mix(in srgb, var(--primary) 14%, transparent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 3px; border-radius: 16px; background: var(--bg-2); font-size: 14px; cursor: pointer; }
.chip .avatar { width: 26px; height: 26px; font-size: 12px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; padding: 6px 4px 14px; }

/* lightbox, toast */
.lightbox { position: fixed; inset: 0; z-index: 70; background: rgba(0,0,0,.9); display: grid; place-items: center; animation: fade .15s; }
.lightbox img { max-width: 96vw; max-height: 92vh; object-fit: contain; }
.lightbox .icon-btn { position: absolute; top: 12px; right: 12px; color: #fff; }
.toast { position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%); z-index: 80; background: rgba(0,0,0,.82); color: #fff;
  padding: 10px 18px; border-radius: 10px; max-width: 90vw; font-size: 14px; animation: fade .15s; }

/* responsive */
@media (max-width: 1100px) {
  .info { position: absolute; right: 0; top: 0; bottom: 0; z-index: 25; box-shadow: var(--shadow); }
}
@media (max-width: 760px) {
  .sidebar { width: 100%; max-width: none; min-width: 0; border: 0; }
  .chat { position: absolute; inset: 0; transform: translateX(100%); transition: transform .2s ease; z-index: 10; }
  .app.chat-open .chat { transform: none; }
  .back-btn { display: inline-grid; }
  .chat-head { padding-left: 8px; }
  .info { width: 100%; border: 0; z-index: 40; }
  .messages-inner { padding: 8px 8px 6px; }
  .composer-wrap { padding: 0 8px 8px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
  .bubble { max-width: 86%; }
  .msg.in .avatar.xs { width: 30px; height: 30px; }
  .scroll-down { bottom: 72px; right: 12px; }
}

/* extras */
.unread-sep { align-self: stretch; text-align: center; margin: 8px -16px; padding: 4px 0; font-size: 14px; font-weight: 500;
  color: var(--text-2); background: color-mix(in srgb, var(--bg) 80%, transparent); }
.send-preview { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; max-height: 50vh; overflow-y: auto; }
.send-thumb { max-width: 100%; max-height: 260px; border-radius: 10px; object-fit: cover; flex: 1 1 120px; min-width: 0; }
.send-preview .file-row { width: 100%; }
.dropdown button.menu-me { padding: 8px 10px; margin-bottom: 4px; border-bottom: 1px solid var(--border); border-radius: 8px 8px 0 0; }
.menu-me-text { display: flex; flex-direction: column; min-width: 0; text-align: left; }
.menu-me-text b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-me-text small { color: var(--text-2); font-size: 13px; }
.picker-label { font-size: 13px; color: var(--text-2); margin: 0 0 6px 4px; }
.pick-list { max-height: 240px; overflow-y: auto; margin: 0 -8px 10px; }
.pick-list .member svg.ic { color: var(--primary); }
.modal p { margin: 0 0 12px; line-height: 1.5; }
.info-row.click:active { opacity: .7; }
a.dl-btn { display: flex; align-items: center; justify-content: center; text-decoration: none; margin-bottom: 10px; }

/* telegram look */
:root { --chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260' viewBox='0 0 260 260'%3E%3Cg fill='none' stroke='%231b3a1e' stroke-opacity='.13' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cg transform='translate(22 24)'%3E%3Ccircle cx='12' cy='18' r='7'/%3E%3Ccircle cx='3' cy='8' r='3'/%3E%3Ccircle cx='10' cy='2' r='3'/%3E%3Ccircle cx='18' cy='2' r='3'/%3E%3Ccircle cx='24' cy='9' r='3'/%3E%3C/g%3E%3Cpath d='M120 40c-6-10-22-6-20 6 2 9 20 20 20 20s18-11 20-20c2-12-14-16-20-6z'/%3E%3Cpath d='M210 18l5 11 12 1-9 8 3 12-11-6-11 6 3-12-9-8 12-1z'/%3E%3Cg transform='translate(40 110) rotate(-25)'%3E%3Cpath d='M6 0a5 5 0 016 6h26a5 5 0 116 6 5 5 0 01-6 6H12a5 5 0 11-6-6 5 5 0 010-12z'/%3E%3C/g%3E%3Cpath d='M150 110h36a8 8 0 018 8v18a8 8 0 01-8 8h-22l-10 9v-9h-4a8 8 0 01-8-8v-18a8 8 0 018-8z'/%3E%3Cpath d='M158 127h20'/%3E%3Cg transform='translate(228 100)'%3E%3Cpath d='M0 24V2l14-2v22'/%3E%3Ccircle cx='-4' cy='24' r='4'/%3E%3Ccircle cx='10' cy='22' r='4'/%3E%3C/g%3E%3Ccircle cx='96' cy='180' r='10'/%3E%3Cpath d='M91 178h0M101 178h0M92 184q4 3 8 0'/%3E%3Cg transform='translate(190 190)'%3E%3Ccircle cx='12' cy='18' r='7'/%3E%3Ccircle cx='3' cy='8' r='3'/%3E%3Ccircle cx='10' cy='2' r='3'/%3E%3Ccircle cx='18' cy='2' r='3'/%3E%3Ccircle cx='24' cy='9' r='3'/%3E%3C/g%3E%3Cpath d='M30 220l8-14 8 14z'/%3E%3Ccircle cx='140' cy='230' r='4'/%3E%3Ccircle cx='70' cy='70' r='3'/%3E%3Ccircle cx='245' cy='60' r='3'/%3E%3Cpath d='M128 190l6 6m0-6l-6 6'/%3E%3Cpath d='M18 160c6-6 12 6 18 0s12 6 18 0'/%3E%3Cpath d='M226 240c6-6 12 6 18 0'/%3E%3C/g%3E%3C/svg%3E"); }
:root[data-theme="dark"] { --chat-pattern: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='260' height='260' viewBox='0 0 260 260'%3E%3Cg fill='none' stroke='%23ffffff' stroke-opacity='.05' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cg transform='translate(22 24)'%3E%3Ccircle cx='12' cy='18' r='7'/%3E%3Ccircle cx='3' cy='8' r='3'/%3E%3Ccircle cx='10' cy='2' r='3'/%3E%3Ccircle cx='18' cy='2' r='3'/%3E%3Ccircle cx='24' cy='9' r='3'/%3E%3C/g%3E%3Cpath d='M120 40c-6-10-22-6-20 6 2 9 20 20 20 20s18-11 20-20c2-12-14-16-20-6z'/%3E%3Cpath d='M210 18l5 11 12 1-9 8 3 12-11-6-11 6 3-12-9-8 12-1z'/%3E%3Cg transform='translate(40 110) rotate(-25)'%3E%3Cpath d='M6 0a5 5 0 016 6h26a5 5 0 116 6 5 5 0 01-6 6H12a5 5 0 11-6-6 5 5 0 010-12z'/%3E%3C/g%3E%3Cpath d='M150 110h36a8 8 0 018 8v18a8 8 0 01-8 8h-22l-10 9v-9h-4a8 8 0 01-8-8v-18a8 8 0 018-8z'/%3E%3Cpath d='M158 127h20'/%3E%3Cg transform='translate(228 100)'%3E%3Cpath d='M0 24V2l14-2v22'/%3E%3Ccircle cx='-4' cy='24' r='4'/%3E%3Ccircle cx='10' cy='22' r='4'/%3E%3C/g%3E%3Ccircle cx='96' cy='180' r='10'/%3E%3Cpath d='M91 178h0M101 178h0M92 184q4 3 8 0'/%3E%3Cg transform='translate(190 190)'%3E%3Ccircle cx='12' cy='18' r='7'/%3E%3Ccircle cx='3' cy='8' r='3'/%3E%3Ccircle cx='10' cy='2' r='3'/%3E%3Ccircle cx='18' cy='2' r='3'/%3E%3Ccircle cx='24' cy='9' r='3'/%3E%3C/g%3E%3Cpath d='M30 220l8-14 8 14z'/%3E%3Ccircle cx='140' cy='230' r='4'/%3E%3Ccircle cx='70' cy='70' r='3'/%3E%3Ccircle cx='245' cy='60' r='3'/%3E%3Cpath d='M128 190l6 6m0-6l-6 6'/%3E%3Cpath d='M18 160c6-6 12 6 18 0s12 6 18 0'/%3E%3Cpath d='M226 240c6-6 12 6 18 0'/%3E%3C/g%3E%3C/svg%3E"); }
.chat { background: var(--chat-pattern), var(--chat-bg); background-size: 260px 260px, cover; background-attachment: fixed, fixed; }
.msg { position: relative; touch-action: pan-y; }
.msg.in.group-end .bubble:not(.media) { border-bottom-left-radius: 0; }
.msg.out.group-end .bubble:not(.media) { border-bottom-right-radius: 0; }
.msg.group-end .bubble:not(.media)::before { content: ''; position: absolute; bottom: 0; width: 9px; height: 17px; background: inherit;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='17'%3E%3Cpath d='M9 0v17H1.5a1 1 0 01-.72-1.7C3.6 12.4 6.7 8.2 8.2 3.3 8.6 2 8.9 1 9 0z'/%3E%3C/svg%3E") no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='17'%3E%3Cpath d='M9 0v17H1.5a1 1 0 01-.72-1.7C3.6 12.4 6.7 8.2 8.2 3.3 8.6 2 8.9 1 9 0z'/%3E%3C/svg%3E") no-repeat; }
.msg.in.group-end .bubble:not(.media)::before { left: -8.5px; }
.msg.out.group-end .bubble:not(.media)::before { right: -8.5px; transform: scaleX(-1); }
.msg.in .avatar.xs + .bubble { margin-left: 2px; }
.msg.appear .bubble { animation: msgIn .22s cubic-bezier(.2,.9,.3,1.2); }
.msg.out.appear .bubble { transform-origin: bottom right; }
.msg.in.appear .bubble { transform-origin: bottom left; }
@keyframes msgIn { from { transform: translateY(14px) scale(.92); opacity: 0; } }
.msg { transition: transform .22s ease; }
.msg.swiping { transition: none; }
.swipe-ic { position: absolute; right: -40px; top: 50%; transform: translateY(-50%) scale(.5); width: 30px; height: 30px; border-radius: 50%;
  background: var(--service-bg); color: #fff; display: grid; place-items: center; opacity: 0; transition: opacity .2s; pointer-events: none; }
.swipe-ic svg.ic { width: 18px; height: 18px; }
.bubble .meta .edited { margin-right: 4px; font-style: italic; }
.bubble .fwd { display: flex; align-items: center; gap: 4px; font-size: 14px; color: var(--primary); margin-bottom: 2px; }
.msg.out .bubble .fwd { color: var(--bubble-out-meta); }
.bubble .fwd svg.ic { width: 16px; height: 16px; flex: none; }
.bubble.media .fwd { padding: 6px 10px 0; }
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; clear: both; }
.bubble.media .reactions { padding: 0 8px 8px; }
.bubble.media.no-caption .reactions { padding-top: 6px; }
.react { display: inline-flex; align-items: center; gap: 4px; height: 28px; padding: 0 8px 0 6px; border-radius: 14px; border: 0; cursor: pointer;
  background: color-mix(in srgb, var(--primary) 14%, transparent); color: var(--primary); font: inherit; font-size: 14px; font-weight: 600;
  animation: pop .18s ease-out; }
.react .re { font-size: 17px; line-height: 1; }
.react.mine { background: var(--primary); color: #fff; }
.msg.out .react { background: color-mix(in srgb, var(--bubble-out-meta) 20%, transparent); color: var(--bubble-out-meta); }
.msg.out .react.mine { background: var(--bubble-out-meta); color: var(--bubble-out); }
.react-pick { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 6px; margin-bottom: 4px; border-bottom: 1px solid var(--border);
  max-width: 260px; }
.react-pick::-webkit-scrollbar { display: none; }
.ctx .react-pick button { flex: none; width: 38px; height: 38px; padding: 0; justify-content: center; font-size: 22px; border-radius: 50%;
  transition: transform .12s; }
.ctx .react-pick button:hover { transform: scale(1.2); background: var(--bg-hover); }
.ctx .react-pick button.on { background: color-mix(in srgb, var(--primary) 20%, transparent); }
.composer .emoji-btn { width: 44px; height: 48px; flex: none; margin-right: -8px; border-radius: 14px 0 0 14px; background: var(--bg);
  box-shadow: -1px 1px 2px rgba(0,0,0,.08); color: var(--text-2); }
.composer .emoji-btn + textarea { border-radius: 0 14px 14px 0; padding-left: 6px; }
.emoji-panel { position: absolute; left: 16px; right: 16px; bottom: calc(100% - 6px); max-height: 300px; overflow-y: auto; z-index: 30;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); gap: 2px; padding: 8px; border-radius: 14px;
  background: var(--bg); box-shadow: var(--shadow); animation: pop .14s ease-out; transform-origin: bottom left; }
.emoji-panel[hidden] { display: none; }
.emoji-panel button { height: 42px; border: 0; background: none; font-size: 26px; border-radius: 10px; cursor: pointer; padding: 0; line-height: 1; }
.emoji-panel button:hover { background: var(--bg-hover); }
.edit-bar { animation: fade .15s; }
.reply-bar { animation: fade .15s; }
.ci-pin, .ci-muted { display: inline-grid; place-items: center; color: var(--text-2); flex: none; }
.ci-pin svg.ic { width: 18px; height: 18px; transform: rotate(45deg); }
.ci-title .ci-muted svg.ic { width: 15px; height: 15px; }
.chat-item.active .ci-pin, .chat-item.active .ci-muted { color: #fff; }
.archive-row .avatar.arch { background: #9aa3ab; color: #fff; }
.archive-row .avatar.arch svg.ic { width: 26px; height: 26px; }
.archive-row.back .avatar.arch { background: var(--bg-hover); color: var(--text-2); }
.archive-row .ci-body { flex: 1; min-width: 0; }
.fwd-list { max-height: 55vh; overflow-y: auto; }
.fwd-list .member { cursor: pointer; border-radius: 10px; }
.fwd-list .member:hover { background: var(--bg-hover); }
.fwd-list .member.busy { opacity: .5; pointer-events: none; }
@media (max-width: 760px) {
  .emoji-panel { left: 8px; right: 8px; max-height: 260px; }
}
.messages { overflow-x: hidden; }
.msg.no-anim .bubble { animation: none; }
