:root {
  --bg: #eef0f3;
  --panel: #ffffff;
  --panel-2: #f7f8fa;
  --hover: #f2f4f7;
  --active: #ebf7f0;
  --border: #e6e8ec;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #8a94a6;
  --accent: #10a35b;
  --accent-2: #0c8a4c;
  --accent-soft: #e3f6ec;
  --on-accent: #ffffff;
  --bubble-in: #ffffff;
  --bubble-out: #dcf5e6;
  --bubble-shadow: 0 1px 1px rgba(15, 23, 42, .06);
  --chat-bg: #eef1ee;
  --chat-dot: rgba(16, 163, 91, .07);
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #dc2626;
  --read: #2f8cff;
  --shadow-lg: 0 20px 50px -12px rgba(15, 23, 42, .25), 0 2px 6px rgba(15, 23, 42, .06);
  --radius: 14px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0c0f; --panel: #111418; --panel-2: #161a1f; --hover: #1a1f25; --active: #13261c;
    --border: #22282f; --text: #e8ebef; --text-2: #b4bcc8; --muted: #7c8696;
    --accent: #22c372; --accent-2: #1aa660; --accent-soft: #13261c; --on-accent: #04120a;
    --bubble-in: #1a1f25; --bubble-out: #11392a; --bubble-shadow: none;
    --chat-bg: #0d1013; --chat-dot: rgba(34, 195, 114, .05);
    --warn: #fbbf24; --warn-soft: #3a2a07; --danger: #f87171; --read: #53a6ff;
    --shadow-lg: 0 20px 50px -12px rgba(0, 0, 0, .7);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0c0f; --panel: #111418; --panel-2: #161a1f; --hover: #1a1f25; --active: #13261c;
  --border: #22282f; --text: #e8ebef; --text-2: #b4bcc8; --muted: #7c8696;
  --accent: #22c372; --accent-2: #1aa660; --accent-soft: #13261c; --on-accent: #04120a;
  --bubble-in: #1a1f25; --bubble-out: #11392a; --bubble-shadow: none;
  --chat-bg: #0d1013; --chat-dot: rgba(34, 195, 114, .05);
  --warn: #fbbf24; --warn-soft: #3a2a07; --danger: #f87171; --read: #53a6ff;
  --shadow-lg: 0 20px 50px -12px rgba(0, 0, 0, .7);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); font-size: 14.5px; line-height: 1.45; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
svg { flex-shrink: 0; }
a { color: var(--accent); }
.hidden { display: none !important; }

/* ---------- Icon button ---------- */
.icon-btn {
  width: 38px; height: 38px; display: inline-grid; place-items: center; border-radius: 10px; color: var(--text-2);
  transition: background .15s, color .15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn:focus-visible, .btn:focus-visible, .chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn svg { width: 20px; height: 20px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 40px; padding: 0 16px;
  border-radius: 10px; font-weight: 600; font-size: 14px; transition: background .15s, opacity .15s;
}
.btn-primary { background: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-2); }
.btn-ghost { background: var(--panel-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--hover); }
.btn-danger { color: var(--danger); background: transparent; border: 1px solid var(--border); }
.btn:disabled { opacity: .55; cursor: default; }
.btn svg { width: 18px; height: 18px; }

.input {
  width: 100%; height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--panel-2); outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent); }
label.field { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--text-2); }

/* ---------- Layout ---------- */
.app {
  height: 100dvh; display: grid; grid-template-columns: minmax(320px, 400px) 1fr;
  background: var(--panel); max-width: 1680px; margin: 0 auto;
}
@media (min-width: 1700px) { .app { height: calc(100dvh - 32px); margin-top: 16px; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow-lg); } }

.sidebar { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-right: 1px solid var(--border); background: var(--panel); }
.side-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 10px 16px; }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1; text-align: left; border-radius: 12px; padding: 4px; margin: -4px; }
.me:hover { background: var(--hover); }
.me-text { min-width: 0; }
.me-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-line { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.dot.ok { background: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.dot.bad { background: var(--danger); }
.dot.warn { background: #f59e0b; }

.search-wrap { padding: 0 14px 10px; position: relative; }
.search-wrap svg { position: absolute; left: 26px; top: 11px; width: 18px; height: 18px; color: var(--muted); }
.search { padding-left: 40px; height: 40px; }

.chips { display: flex; gap: 6px; padding: 0 14px 10px; overflow-x: auto; scrollbar-width: none; }
.chip {
  height: 30px; padding: 0 12px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--border);
  font-size: 13px; font-weight: 500; color: var(--text-2); white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { background: var(--hover); }
.chip.on { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 40%, transparent); color: var(--accent); font-weight: 600; }
.chip .count { font-size: 11px; background: var(--accent); color: var(--on-accent); border-radius: 999px; padding: 0 6px; line-height: 17px; }
.chip.warnchip .count { background: #f59e0b; color: #1f1300; }

.chat-list { flex: 1; overflow-y: auto; min-height: 0; padding: 0 8px 12px; overscroll-behavior: contain; }
.chat-item {
  display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; width: 100%; text-align: left;
  position: relative; transition: background .12s;
}
.chat-item:hover { background: var(--hover); }
.chat-item.active { background: var(--active); }
.ci-body { flex: 1; min-width: 0; }
.ci-row { display: flex; align-items: baseline; gap: 8px; }
.ci-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci-time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.chat-item.unread .ci-time { color: var(--accent); font-weight: 600; }
.ci-prev { flex: 1; min-width: 0; color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; align-items: center; gap: 4px; }
.chat-item.unread .ci-prev { color: var(--text-2); }
.ci-prev .tick { width: 16px; height: 16px; }
.badge { min-width: 20px; height: 20px; border-radius: 999px; background: var(--accent); color: var(--on-accent); font-size: 11.5px; font-weight: 700; display: grid; place-items: center; padding: 0 6px; }
.flag { width: 20px; height: 20px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); display: grid; place-items: center; }
.flag svg { width: 12px; height: 12px; }
.pin { width: 14px; height: 14px; color: var(--muted); }
.list-empty { text-align: center; color: var(--muted); padding: 40px 20px; font-size: 13.5px; }
.list-more { display: block; width: 100%; padding: 12px; color: var(--accent); font-weight: 600; }

/* ---------- Avatar ---------- */
.avatar {
  --s: 46px; width: var(--s); height: var(--s); border-radius: 50%; flex-shrink: 0; display: grid; place-items: center;
  font-weight: 700; font-size: calc(var(--s) * .38); color: #fff; background: var(--c, #64748b); overflow: hidden; position: relative;
  letter-spacing: .02em; user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.avatar svg { width: 55%; height: 55%; }
.avatar.sm { --s: 36px; }
.avatar.xs { --s: 28px; }
.avatar.lg { --s: 84px; }

/* ---------- Main / chat ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); position: relative; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
  min-height: 64px; z-index: 3;
}
.chat-head .back { display: none; }
.ch-info { flex: 1; min-width: 0; text-align: left; }
.ch-name { font-weight: 700; font-size: 15.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-sub { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ch-actions { display: flex; gap: 2px; align-items: center; }
.label-all {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 999px;
  background: var(--warn-soft); color: var(--warn); font-size: 12.5px; font-weight: 600; margin-right: 4px;
}
.label-all svg { width: 14px; height: 14px; }

.messages {
  flex: 1; overflow-y: auto; min-height: 0; padding: 14px 6% 10px; overscroll-behavior: contain;
  background-color: var(--chat-bg);
  background-image: radial-gradient(var(--chat-dot) 1.2px, transparent 1.2px);
  background-size: 22px 22px;
}
.load-older { display: flex; justify-content: center; padding: 6px 0 12px; }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 2.5px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.day { display: flex; justify-content: center; margin: 14px 0 10px; position: sticky; top: 4px; z-index: 2; pointer-events: none; }
.day span { background: var(--panel); color: var(--text-2); font-size: 12px; font-weight: 600; padding: 5px 12px; border-radius: 8px; box-shadow: var(--bubble-shadow); border: 1px solid var(--border); }

.msg { display: flex; margin: 2px 0; }
.msg.out { justify-content: flex-end; }
.msg.first { margin-top: 10px; }
.bubble {
  max-width: min(72%, 620px); background: var(--bubble-in); border-radius: 12px; padding: 7px 10px 6px; position: relative;
  box-shadow: var(--bubble-shadow); word-wrap: break-word; overflow-wrap: anywhere; min-width: 90px;
}
.msg.out .bubble { background: var(--bubble-out); }
.msg.first.in .bubble { border-top-left-radius: 4px; }
.msg.first.out .bubble { border-top-right-radius: 4px; }
.msg.deleted .bubble { font-style: italic; color: var(--muted); }
.author { font-size: 12.5px; font-weight: 700; margin-bottom: 2px; color: var(--c, var(--accent)); }
.text { white-space: pre-wrap; }
.text code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; background: color-mix(in srgb, var(--text) 8%, transparent); padding: 1px 4px; border-radius: 4px; }
.meta { float: right; display: inline-flex; align-items: center; gap: 3px; font-size: 11px; color: var(--muted); margin: 6px 0 -3px 12px; line-height: 1; position: relative; top: 3px; }
.meta .tick { width: 16px; height: 16px; }
.tick.read { color: var(--read); }
.tick.err { color: var(--danger); }
.quoted { border-left: 3px solid var(--accent); background: color-mix(in srgb, var(--text) 5%, transparent); border-radius: 6px; padding: 5px 8px; font-size: 13px; color: var(--text-2); margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* sender label chip */
.who { display: flex; justify-content: flex-end; margin: 0 0 3px; }
.who-chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; padding: 2px 8px 2px 6px; border-radius: 999px;
  background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); border: 1px solid transparent; transition: border-color .12s;
}
.who-chip:hover { border-color: color-mix(in srgb, var(--c) 45%, transparent); }
.who-chip i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.who-chip.none { --c: var(--warn); background: var(--warn-soft); border-style: dashed; border-color: color-mix(in srgb, var(--warn) 50%, transparent); }
.who-chip svg { width: 12px; height: 12px; }
.msg-err { font-size: 12px; color: var(--danger); margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.msg-err button { color: var(--danger); font-weight: 700; text-decoration: underline; }
.reacts { position: absolute; bottom: -12px; left: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 999px; font-size: 12px; padding: 0 6px; line-height: 20px; box-shadow: var(--bubble-shadow); }
.msg.has-react { margin-bottom: 14px; }

/* media */
.media { display: block; margin: -3px -6px 4px; border-radius: 9px; overflow: hidden; position: relative; background: color-mix(in srgb, var(--text) 6%, transparent); cursor: zoom-in; }
.media img, .media video { display: block; width: 100%; max-width: 340px; max-height: 380px; object-fit: cover; min-width: 200px; min-height: 120px; }
.media .thumb { filter: blur(8px); transform: scale(1.05); }
.media .play { position: absolute; inset: 0; display: grid; place-items: center; }
.media .play span { width: 54px; height: 54px; border-radius: 50%; background: rgba(0, 0, 0, .5); display: grid; place-items: center; color: #fff; }
.media .play svg { width: 24px; height: 24px; margin-left: 3px; }
.media.loading::after { content: ""; position: absolute; inset: 0; margin: auto; width: 26px; height: 26px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .5); border-top-color: #fff; animation: spin .8s linear infinite; }
.sticker img { width: 140px; height: 140px; object-fit: contain; display: block; }
.doc { display: flex; align-items: center; gap: 10px; padding: 8px; margin: -2px -4px 4px; border-radius: 9px; background: color-mix(in srgb, var(--text) 5%, transparent); text-decoration: none; color: inherit; min-width: 220px; }
.doc .ficon { width: 38px; height: 44px; border-radius: 6px; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.doc .fname { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
.doc .fsub { font-size: 12px; color: var(--muted); }
audio { width: 260px; max-width: 100%; height: 40px; display: block; margin: 2px 0 4px; }
.loc { display: flex; align-items: center; gap: 8px; font-weight: 600; text-decoration: none; padding: 4px 0; }
.loc svg { width: 20px; height: 20px; }

/* jump */
.jump {
  position: absolute; right: 22px; bottom: 92px; width: 42px; height: 42px; border-radius: 50%; background: var(--panel);
  box-shadow: var(--shadow-lg); display: grid; place-items: center; color: var(--text-2); z-index: 4; border: 1px solid var(--border);
}
.jump svg { width: 20px; height: 20px; }
.jump .badge { position: absolute; top: -6px; right: -4px; }

/* ---------- Composer ---------- */
.composer { background: var(--panel); border-top: 1px solid var(--border); padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); z-index: 3; }
.attach-preview { display: flex; align-items: center; gap: 10px; padding: 8px; margin-bottom: 8px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--border); }
.attach-preview img { width: 52px; height: 52px; object-fit: cover; border-radius: 8px; }
.attach-preview .ficon { width: 44px; height: 52px; }
.ap-text { flex: 1; min-width: 0; }
.ap-name { font-weight: 600; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ap-sub { font-size: 12px; color: var(--muted); }
.comp-row { display: flex; align-items: flex-end; gap: 8px; }
.comp-box { flex: 1; display: flex; align-items: flex-end; background: var(--panel-2); border: 1px solid var(--border); border-radius: 22px; padding: 2px 4px 2px 4px; transition: border-color .15s; }
.comp-box:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, transparent); }
.comp-box textarea { flex: 1; resize: none; border: 0; outline: none; background: transparent; padding: 9px 8px; max-height: 160px; min-height: 40px; line-height: 1.4; }
.comp-box .icon-btn { border-radius: 50%; }
.send { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); color: var(--on-accent); display: grid; place-items: center; transition: transform .1s, background .15s; }
.send:hover { background: var(--accent-2); }
.send:active { transform: scale(.94); }
.send svg { width: 20px; height: 20px; margin-left: 2px; }
.send:disabled { opacity: .5; }
.as-who { font-size: 11.5px; color: var(--muted); margin: 6px 0 0 16px; display: flex; align-items: center; gap: 6px; }
.as-who i { width: 7px; height: 7px; border-radius: 50%; background: var(--c); }
.drop-overlay { position: absolute; inset: 0; background: color-mix(in srgb, var(--accent) 14%, transparent); border: 3px dashed var(--accent); z-index: 10; display: grid; place-items: center; font-weight: 700; color: var(--accent); font-size: 18px; pointer-events: none; }

/* ---------- Empty state ---------- */
.empty { flex: 1; display: grid; place-items: center; text-align: center; padding: 30px; background: var(--panel-2); }
.empty-art { width: 92px; height: 92px; border-radius: 28px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin: 0 auto 18px; }
.empty-art svg { width: 44px; height: 44px; }
.empty h2 { margin: 0 0 6px; font-size: 22px; letter-spacing: -.01em; }
.empty p { margin: 0 auto; color: var(--muted); max-width: 380px; }
.empty .btn { margin-top: 18px; }
.setup-card { margin: 22px auto 0; max-width: 440px; text-align: left; background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.setup-card h4 { margin: 0 0 6px; font-size: 14px; display: flex; gap: 8px; align-items: center; }
.setup-card p { font-size: 13px; max-width: none; }

/* ---------- Popover / modal ---------- */
.popover {
  position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 260px; padding: 8px; animation: pop .12s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(4px) scale(.98); } }
.pop-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 6px 8px; }
.pop-list { max-height: 240px; overflow-y: auto; }
.pop-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px; border-radius: 8px; text-align: left; font-weight: 500; }
.pop-item:hover, .pop-item.kb { background: var(--hover); }
.pop-item i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.pop-item .chk { margin-left: auto; width: 16px; height: 16px; color: var(--accent); }
.pop-input { display: flex; gap: 6px; padding: 6px 4px 2px; border-top: 1px solid var(--border); margin-top: 6px; }
.pop-input .input { height: 36px; font-size: 13.5px; }
.pop-input .btn { height: 36px; padding: 0 12px; }
.pop-foot { font-size: 11.5px; color: var(--muted); padding: 6px 8px 2px; }

.backdrop { position: fixed; inset: 0; background: rgba(2, 6, 12, .45); z-index: 40; display: grid; place-items: center; padding: 16px; animation: fade .15s; backdrop-filter: blur(2px); }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 460px; max-height: min(720px, calc(100dvh - 32px)); background: var(--panel); border-radius: 18px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden; animation: pop .15s ease-out; border: 1px solid var(--border); }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px 20px; }
.modal-head h3 { flex: 1; margin: 0; font-size: 17px; }
.modal-body { padding: 4px 20px 20px; overflow-y: auto; }
.modal-body .search-wrap { padding: 0 0 10px; }
.modal-body .search-wrap svg { left: 12px; }
.new-contact { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px; border-radius: 12px; font-weight: 600; text-align: left; }
.new-contact:hover { background: var(--hover); }
.new-contact .avatar { background: var(--accent); }
.dir-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 10px; border-radius: 12px; text-align: left; }
.dir-item:hover { background: var(--hover); }
.dir-name { font-weight: 600; }
.dir-sub { font-size: 12.5px; color: var(--muted); }
.section-label { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 14px 4px 6px; }
.form-grid { display: grid; gap: 14px; }
.form-err { color: var(--danger); font-size: 13px; min-height: 18px; }
.hint { font-size: 12.5px; color: var(--muted); }

/* settings drawer */
.drawer { position: fixed; inset: 0 auto 0 0; width: min(420px, 100vw); background: var(--panel); z-index: 45; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(-30px); opacity: 0; } }
.drawer .modal-body { flex: 1; }
.card { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 14px; background: var(--panel-2); }
.card h4 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; font-size: 13.5px; }
.kv span:first-child { color: var(--muted); }
.kv span:last-child { font-weight: 600; text-align: right; min-width: 0; overflow-wrap: anywhere; }
.copy-row { display: flex; gap: 6px; margin-top: 8px; }
.copy-row code { flex: 1; min-width: 0; font-size: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; overflow-x: auto; white-space: nowrap; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 10px; border-radius: 999px; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); font-size: 13px; font-weight: 600; }
.tag button { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; }
.tag button:hover { background: color-mix(in srgb, var(--c) 20%, transparent); }
.tag button svg { width: 12px; height: 12px; }
.people { display: flex; flex-direction: column; gap: 8px; }
.person { display: flex; align-items: center; gap: 10px; font-size: 13.5px; font-weight: 500; }

/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, .92); z-index: 60; display: grid; place-items: center; padding: 20px; animation: fade .15s; }
.lightbox img, .lightbox video { max-width: 100%; max-height: 100%; border-radius: 6px; }
.lightbox .icon-btn { position: absolute; top: 14px; right: 14px; color: #fff; background: rgba(255, 255, 255, .1); }

/* toast */
.toasts { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 70; display: grid; gap: 8px; }
.toast { background: var(--text); color: var(--panel); padding: 10px 16px; border-radius: 10px; font-size: 13.5px; font-weight: 500; box-shadow: var(--shadow-lg); animation: pop .15s; }
.banner { display: flex; align-items: center; gap: 8px; justify-content: center; padding: 7px 12px; font-size: 12.5px; font-weight: 600; background: var(--warn-soft); color: var(--warn); }

/* scrollbars */
.chat-list::-webkit-scrollbar, .messages::-webkit-scrollbar, .pop-list::-webkit-scrollbar, .modal-body::-webkit-scrollbar { width: 8px; }
.chat-list::-webkit-scrollbar-thumb, .messages::-webkit-scrollbar-thumb, .pop-list::-webkit-scrollbar-thumb, .modal-body::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--text) 15%, transparent); border-radius: 8px; }

/* ---------- Mobile ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .main { display: none; }
  .app.in-chat .sidebar { display: none; }
  .app.in-chat .main { display: flex; }
  .chat-head { padding: 8px 8px; padding-top: calc(8px + env(safe-area-inset-top)); }
  .side-head { padding-top: calc(14px + env(safe-area-inset-top)); }
  .chat-head .back { display: inline-grid; }
  .messages { padding: 10px 10px 8px; }
  .bubble { max-width: 86%; }
  .composer { padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); }
  .label-all #labelAllText { display: none; }
  .label-all { padding: 0 9px; }
  #renameBtn { display: none; }
  .jump { right: 14px; bottom: 86px; }
  .drawer { width: 100vw; }
  .modal { max-height: calc(100dvh - 32px); }
  .media img, .media video { min-width: 160px; max-width: 260px; }
}

/* ---------- Filters / tags / assignment ---------- */
.filter-bar { display: flex; align-items: center; gap: 4px; padding: 0 14px 10px; }
.filter-btn { flex: 1; justify-content: flex-start; border-style: dashed; color: var(--muted); min-width: 0; }
.filter-btn span:last-child { overflow: hidden; text-overflow: ellipsis; }
.filter-btn svg { width: 14px; height: 14px; }
.filter-btn.on { border-style: solid; }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.chip .count.mine { background: var(--accent); }

.ci-tags { display: flex; gap: 4px; margin-top: 4px; flex-wrap: nowrap; overflow: hidden; }
.tpill { display: inline-flex; align-items: center; gap: 4px; height: 18px; padding: 0 7px; border-radius: 999px; font-size: 11px; font-weight: 600;
  background: color-mix(in srgb, var(--c) 15%, transparent); color: var(--c); white-space: nowrap; }
.tpill.more { --c: var(--muted); }
.ci-assignee { --s: 18px; font-size: 9px; border: 2px solid var(--panel); margin-left: 2px; }

.assign-btn { display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 10px 0 4px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--panel-2); font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-right: 2px; max-width: 170px; }
.assign-btn:hover { background: var(--hover); }
.assign-btn .avatar { --s: 24px; font-size: 10px; }
.assign-btn .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.assign-btn.none { padding: 0 12px; color: var(--muted); border-style: dashed; }
.assign-btn svg { width: 16px; height: 16px; }

.tag-bar { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border); z-index: 3; }
.tag-bar .tpill { height: 24px; font-size: 12px; padding: 0 10px; }
.tag-bar .tpill button { margin-left: 2px; display: grid; place-items: center; border-radius: 50%; width: 16px; height: 16px; }
.tag-bar .tpill button:hover { background: color-mix(in srgb, var(--c) 25%, transparent); }
.tag-bar .tpill svg { width: 11px; height: 11px; }

.pop-section { padding: 2px 0 4px; }
.pop-section + .pop-section { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.pop-item .avatar { --s: 24px; font-size: 10px; }
.pop-item.on { background: var(--active); }
.swatches { display: flex; gap: 6px; padding: 6px 8px 2px; flex-wrap: wrap; }
.swatch { width: 22px; height: 22px; border-radius: 50%; background: var(--c); border: 2px solid transparent; }
.swatch.on { border-color: var(--text); box-shadow: inset 0 0 0 2px var(--panel); }
.popover.wide { width: 290px; }

/* ---------- Voice recording ---------- */
.rec-bar { display: flex; align-items: center; gap: 10px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 42px; }
.rec-hint { flex: 1; color: var(--muted); font-size: 13px; }
.voice-label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; margin-bottom: 2px; }
.voice-label svg { width: 13px; height: 13px; }

/* ---------- Team admin ---------- */
.team-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.tr-actions { display: flex; gap: 6px; width: 100%; padding-left: 46px; }
.team-row:last-of-type { border-bottom: 0; }
.team-row .tr-main { flex: 1; min-width: 0; }
.team-row .tr-name { font-weight: 600; font-size: 13.5px; display: flex; gap: 6px; align-items: center; }
.team-row .tr-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); }
.role.off { background: var(--hover); color: var(--muted); }
.team-row.inactive { opacity: .55; }
.mini-btn { font-size: 12px; font-weight: 600; color: var(--text-2); padding: 5px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); }
.mini-btn:hover { background: var(--hover); }
.stack { display: grid; gap: 8px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
select.input { appearance: auto; padding: 0 10px; }
@media (max-width: 820px) {
  .assign-btn .nm { display: none; }
  .assign-btn { padding: 0 4px; }
  .assign-btn.none { padding: 0 8px; }
}
