/* ========== HP Chat — giao diện kiểu WeChat ========== */
:root {
  --accent: #07C160;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --radius: 6px;
  --rail-w: 62px;
  --side-w: 300px;
}
/* 10 template màu */
[data-theme="wechat"] { --accent: #07C160; }
[data-theme="ocean"]  { --accent: #1677FF; }
[data-theme="tea"]    { --accent: #5E8B2E; }
[data-theme="indigo"] { --accent: #5B5BD6; }
[data-theme="violet"] { --accent: #8B5CF6; }
[data-theme="rose"]   { --accent: #E11D74; }
[data-theme="sunset"] { --accent: #F26B1D; }
[data-theme="teal"]   { --accent: #0D9488; }
[data-theme="coffee"] { --accent: #8B5E3C; }
[data-theme="slate"]  { --accent: #475569; }

[data-mode="light"] {
  --bg: #F5F5F5;
  --chat-bg: #F2F2F2;
  --rail: #2E2E2E;
  --rail-fg: #9B9B9B;
  --rail-active: #fff;
  --side: #F7F7F7;
  --side-hover: #ECECEC;
  --side-active: #DEDEDE;
  --panel: #FFFFFF;
  --line: #E3E3E3;
  --fg: #191919;
  --fg-2: #5f5f5f;
  --fg-3: #9a9a9a;
  --bubble: #FFFFFF;
  --bubble-fg: #191919;
  --bubble-me: color-mix(in srgb, var(--accent) 42%, #ffffff);
  --bubble-me-fg: #111;
  --input: #FFFFFF;
  --chip: #EDEDED;
  --shadow: 0 8px 30px rgba(0,0,0,.12);
  --danger: #E5484D;
  --mention-bg: color-mix(in srgb, var(--accent) 16%, transparent);
  --overlay: rgba(0,0,0,.45);
  color-scheme: light;
}
[data-mode="dark"] {
  --bg: #111111;
  --chat-bg: #141414;
  --rail: #1B1B1B;
  --rail-fg: #7c7c7c;
  --rail-active: #fff;
  --side: #1E1E1E;
  --side-hover: #262626;
  --side-active: #303030;
  --panel: #222222;
  --line: #2c2c2c;
  --fg: #E8E8E8;
  --fg-2: #A9A9A9;
  --fg-3: #6f6f6f;
  --bubble: #2A2A2A;
  --bubble-fg: #E8E8E8;
  --bubble-me: color-mix(in srgb, var(--accent) 62%, #1a1a1a);
  --bubble-me-fg: #fff;
  --input: #1A1A1A;
  --chip: #2E2E2E;
  --shadow: 0 10px 40px rgba(0,0,0,.55);
  --danger: #FF6369;
  --mention-bg: color-mix(in srgb, var(--accent) 22%, transparent);
  --overlay: rgba(0,0,0,.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 var(--font); background: var(--bg); color: var(--fg); -webkit-font-smoothing: antialiased; overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, select, textarea { font: inherit; color: var(--fg); }
a { color: var(--accent); }
svg.i { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.hidden { display: none !important; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--fg) 18%, transparent); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

.boot { height: 100dvh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Form controls ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; color: var(--fg-2); }
.input, select.input, textarea.input {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--input); 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) 20%, transparent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 16px; border-radius: var(--radius); background: var(--chip); color: var(--fg); font-weight: 500; white-space: nowrap; transition: filter .15s, background .15s; }
.btn:hover { filter: brightness(1.06); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; user-select: none; color: var(--fg-2); }
.check input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ---------- Login ---------- */
.login { height: 100dvh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 10% -10%, color-mix(in srgb, var(--accent) 25%, transparent), transparent 60%), var(--bg); }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 34px 30px 26px; box-shadow: var(--shadow); }
.login-logo { width: 58px; height: 58px; border-radius: 15px; background: var(--accent); display: grid; place-items: center; margin: 0 auto 14px; color: #fff; }
.login-logo svg { width: 34px; height: 34px; fill: #fff; stroke: none; }
.login h1 { text-align: center; font-size: 21px; margin: 0 0 4px; }
.login p.sub { text-align: center; color: var(--fg-3); margin: 0 0 24px; font-size: 13px; }
.login .btn.primary { width: 100%; padding: 11px; font-size: 15px; margin-top: 6px; }
.login .err { color: var(--danger); font-size: 13px; min-height: 20px; margin: 4px 0; }
.login .row { display: flex; justify-content: space-between; align-items: center; margin: 2px 0 10px; }

/* ---------- Shell ---------- */
.app { height: 100dvh; display: grid; grid-template-columns: var(--rail-w) var(--side-w) 1fr; grid-template-rows: minmax(0, 1fr); overflow: hidden; }
.app.admin-mode { grid-template-columns: var(--rail-w) 1fr; }
.rail { background: var(--rail); display: flex; flex-direction: column; align-items: center; padding: 22px 0 14px; gap: 6px; }
.rail .me { margin-bottom: 18px; cursor: pointer; }
.rail-btn { position: relative; width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center; color: var(--rail-fg); transition: color .15s, background .15s; }
.rail-btn:hover { color: #d8d8d8; background: rgba(255,255,255,.05); }
.rail-btn.active { color: var(--accent); }
.rail-btn svg.i { width: 23px; height: 23px; }
.rail-spacer { flex: 1; }
.badge { position: absolute; top: 4px; right: 3px; min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px; background: #FA5151; color: #fff; font-size: 10.5px; font-weight: 600; line-height: 17px; text-align: center; }
.badge.dot { min-width: 9px; width: 9px; height: 9px; padding: 0; top: 8px; right: 8px; }

/* ---------- Avatar ---------- */
.avatar { position: relative; flex: none; width: 40px; height: 40px; border-radius: 6px; display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 16px; user-select: none; text-transform: uppercase; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; border-radius: 5px; }
.avatar.xs { width: 22px; height: 22px; font-size: 10px; border-radius: 4px; }
.avatar.lg { width: 56px; height: 56px; font-size: 22px; border-radius: 8px; }
.avatar .dot-on, .avatar .dot-off { position: absolute; right: -3px; bottom: -3px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--side); }
.avatar .dot-on { background: #2BD46A; }
.avatar .dot-off { background: #8a8a8a; }
.avatar.group { background: #CFCFCF; padding: 2px; display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: 1fr 1fr; gap: 2px; }
[data-mode="dark"] .avatar.group { background: #3a3a3a; }
.avatar.group > span { display: grid; place-items: center; font-size: 10px; border-radius: 2px; color: #fff; width: 100%; height: 100%; min-height: 0; }
.avatar.group.n1 { grid-template-columns: 1fr; grid-template-rows: 1fr; }
.avatar.group.n2 { grid-template-rows: 1fr; }
.avatar.group.n3 > span:first-child { grid-column: span 2; }

/* ---------- Sidebar ---------- */
.side { background: var(--side); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.side-head { padding: 22px 12px 10px; display: flex; gap: 8px; align-items: center; }
.search { flex: 1; display: flex; align-items: center; gap: 6px; background: var(--chip); border-radius: 6px; padding: 0 8px; height: 30px; color: var(--fg-3); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; font-size: 13px; }
.search svg.i { width: 15px; height: 15px; }
.icon-btn { width: 30px; height: 30px; border-radius: 6px; display: grid; place-items: center; color: var(--fg-2); background: var(--chip); flex: none; }
.icon-btn:hover { color: var(--fg); filter: brightness(1.08); }
.icon-btn svg.i { width: 18px; height: 18px; }
.side-title { padding: 2px 16px 8px; font-size: 12px; color: var(--fg-3); text-transform: uppercase; letter-spacing: .04em; }
.list { flex: 1; overflow-y: auto; }
.item { display: flex; gap: 11px; padding: 11px 12px; cursor: pointer; align-items: center; position: relative; }
.item:hover { background: var(--side-hover); }
.item.active { background: var(--side-active); }
.item .meta { flex: 1; min-width: 0; }
.item .top { display: flex; align-items: baseline; gap: 6px; }
.item .name { flex: 1; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .time { font-size: 11.5px; color: var(--fg-3); flex: none; }
.item .bottom { display: flex; align-items: center; gap: 6px; margin-top: 2px; }
.item .preview { flex: 1; font-size: 12.5px; color: var(--fg-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .preview .at { color: #FA5151; }
.item .muted-ic svg.i { width: 14px; height: 14px; color: var(--fg-3); }
.item .avatar-wrap { position: relative; }
.item .avatar-wrap .badge { top: -6px; right: -6px; }
.item .sub { font-size: 12px; color: var(--fg-3); }
.item .pin-default { font-size: 10.5px; padding: 0 5px; border-radius: 3px; background: var(--mention-bg); color: var(--accent); flex: none; }
.empty-list { text-align: center; color: var(--fg-3); padding: 40px 20px; font-size: 13px; }

/* ---------- Main / chat ---------- */
.main { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; background: var(--chat-bg); }
.placeholder { flex: 1; display: grid; place-items: center; color: var(--fg-3); text-align: center; }
.placeholder svg { width: 84px; height: 84px; opacity: .25; fill: var(--fg); }
.chat-head { height: 62px; padding: 0 18px 0 22px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); background: var(--chat-bg); flex: none; }
.chat-head .title { flex: 1; min-width: 0; }
.chat-head .title b { font-size: 16px; font-weight: 600; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .title small { color: var(--fg-3); font-size: 12px; }
.chat-head .title small.on { color: #2BD46A; }
.head-btn { width: 34px; height: 34px; border-radius: 6px; display: grid; place-items: center; color: var(--fg-2); }
.head-btn:hover { background: var(--side-hover); color: var(--fg); }
.back-btn { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 14px 22px 8px; overscroll-behavior: contain; }
.load-more { text-align: center; padding: 6px; color: var(--fg-3); font-size: 12px; }
.sep-time { text-align: center; margin: 14px 0 10px; }
.sep-time span { font-size: 12px; color: var(--fg-3); padding: 2px 8px; border-radius: 4px; }
.sys { text-align: center; margin: 10px 0; }
.sys span { display: inline-block; font-size: 12px; color: var(--fg-3); background: color-mix(in srgb, var(--fg) 6%, transparent); padding: 3px 10px; border-radius: 4px; max-width: 80%; }

.msg { display: flex; gap: 10px; margin: 6px 0 12px; align-items: flex-start; position: relative; }
.msg.me { flex-direction: row-reverse; }
.msg .body { max-width: min(70%, 620px); display: flex; flex-direction: column; align-items: flex-start; min-width: 0; }
.msg.me .body { align-items: flex-end; }
.msg .sender { font-size: 12px; color: var(--fg-3); margin: -2px 0 3px 2px; }
.bubble { position: relative; padding: 9px 12px; border-radius: 6px; background: var(--bubble); color: var(--bubble-fg); word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; font-size: 14.5px; line-height: 1.55; max-width: 100%; }
.bubble::before { content: ""; position: absolute; top: 13px; left: -5px; width: 10px; height: 10px; background: inherit; transform: rotate(45deg); border-radius: 1px; }
.msg.me .bubble { background: var(--bubble-me); color: var(--bubble-me-fg); }
.msg.me .bubble::before { left: auto; right: -5px; }
.bubble.mention-me { box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 60%, transparent); }
.bubble code { font-family: var(--mono); font-size: 12.5px; background: color-mix(in srgb, currentColor 12%, transparent); padding: 1px 5px; border-radius: 4px; }
.bubble a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.msg:not(.me) .bubble a { color: var(--accent); }
.mention { color: var(--accent); font-weight: 600; }
.msg.me .mention { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; }
.mention.me-tag { background: var(--mention-bg); border-radius: 3px; padding: 0 2px; }
.bubble.media { padding: 0; background: transparent !important; }
.bubble.media::before { display: none; }
.bubble.media img { display: block; max-width: min(280px, 100%); max-height: 300px; border-radius: 6px; cursor: zoom-in; background: var(--chip); min-width: 60px; min-height: 40px; object-fit: cover; }
.file-card { display: flex; gap: 12px; align-items: center; width: 280px; max-width: 100%; padding: 12px; background: var(--bubble); color: var(--bubble-fg); border-radius: 6px; border: 1px solid var(--line); white-space: normal; }
.file-card .fi { width: 42px; height: 48px; border-radius: 4px; display: grid; place-items: center; font-size: 10px; font-weight: 700; color: #fff; flex: none; background: #7a7a7a; position: relative; text-transform: uppercase; }
.file-card .fi::after { content: ""; position: absolute; right: 0; top: 0; border-width: 0 10px 10px 0; border-style: solid; border-color: var(--bubble) color-mix(in srgb, #000 25%, transparent); }
.file-card .fmeta { flex: 1; min-width: 0; }
.file-card .fname { font-size: 13.5px; line-height: 1.35; word-break: break-all; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.file-card .fsize { font-size: 11.5px; color: var(--fg-3); margin-top: 3px; }
.file-card .dl { color: var(--accent); flex: none; padding: 6px; border-radius: 6px; }
.file-card .dl:hover { background: var(--mention-bg); }
.file-card.deleted { opacity: .6; }
.quote { font-size: 12.5px; color: var(--fg-2); background: color-mix(in srgb, var(--fg) 7%, transparent); border-left: 3px solid color-mix(in srgb, var(--fg) 25%, transparent); padding: 4px 8px; border-radius: 3px; margin-bottom: 6px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.msg.me .bubble .quote { color: inherit; opacity: .85; }
.quote-out { margin-top: 4px; max-width: 100%; }
.msg .actions { position: absolute; top: -14px; display: none; gap: 2px; background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 2px; box-shadow: var(--shadow); z-index: 2; }
.msg:not(.me) .actions { left: 52px; }
.msg.me .actions { right: 52px; }
.msg:hover .actions { display: flex; }
.msg .actions button { width: 28px; height: 26px; display: grid; place-items: center; border-radius: 4px; color: var(--fg-2); }
.msg .actions button:hover { background: var(--side-hover); color: var(--fg); }
.msg .actions svg.i { width: 15px; height: 15px; }
.msg .read-tag { font-size: 11px; color: var(--fg-3); margin-top: 3px; }
.msg.pending .bubble { opacity: .65; }
.msg.flash .bubble { animation: flash 1.4s ease; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 3px var(--accent); } 100% { box-shadow: 0 0 0 0 transparent; } }
.avatar.clickable { cursor: pointer; }

.typing { height: 20px; padding: 0 24px; font-size: 12px; color: var(--fg-3); flex: none; }
.new-pill { position: absolute; right: 26px; bottom: 210px; background: var(--panel); color: var(--accent); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 16px; padding: 5px 12px; font-size: 12.5px; z-index: 3; }

/* ---------- Composer ---------- */
.composer { border-top: 1px solid var(--line); background: var(--chat-bg); flex: none; display: flex; flex-direction: column; min-height: 168px; max-height: 50vh; }
.toolbar { display: flex; align-items: center; gap: 2px; padding: 6px 14px 0; flex-wrap: wrap; }
.tb { width: 32px; height: 30px; border-radius: 5px; display: grid; place-items: center; color: var(--fg-2); font-weight: 700; font-size: 14px; }
.tb:hover { background: var(--side-hover); color: var(--fg); }
.tb.on { color: var(--accent); background: var(--mention-bg); }
.tb svg.i { width: 19px; height: 19px; }
.tb-sep { width: 1px; height: 18px; background: var(--line); margin: 0 6px; }
.editor { flex: 1; min-height: 60px; overflow-y: auto; padding: 6px 20px; outline: none; font-size: 14.5px; line-height: 1.55; word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; }
.editor:empty::before { content: attr(data-placeholder); color: var(--fg-3); pointer-events: none; }
.editor code { font-family: var(--mono); font-size: 13px; background: var(--chip); padding: 1px 4px; border-radius: 4px; }
.editor .mention { background: var(--mention-bg); border-radius: 3px; padding: 0 2px; }
.composer-foot { display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 4px 18px 12px; }
.composer-foot .hint { font-size: 11.5px; color: var(--fg-3); margin-right: auto; }
.send-btn { padding: 6px 22px; }
.reply-bar { display: flex; align-items: center; gap: 8px; margin: 8px 18px 0; padding: 6px 10px; background: var(--chip); border-radius: 6px; font-size: 12.5px; color: var(--fg-2); }
.reply-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-strip { display: flex; gap: 8px; padding: 10px 18px 0; overflow-x: auto; }
.att { position: relative; width: 74px; flex: none; }
.att .thumb { width: 74px; height: 74px; border-radius: 6px; background: var(--chip); display: grid; place-items: center; overflow: hidden; font-size: 11px; color: var(--fg-2); text-align: center; padding: 4px; word-break: break-all; }
.att .thumb img { width: 100%; height: 100%; object-fit: cover; }
.att .x { position: absolute; top: -6px; right: -6px; width: 20px; height: 20px; border-radius: 50%; background: #555; color: #fff; display: grid; place-items: center; font-size: 13px; line-height: 1; }
.att .bar { position: absolute; left: 4px; right: 4px; bottom: 4px; height: 4px; border-radius: 2px; background: rgba(0,0,0,.35); overflow: hidden; }
.att .bar i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.att .nm { font-size: 10.5px; color: var(--fg-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }

.drop-overlay { position: absolute; inset: 0; background: color-mix(in srgb, var(--accent) 14%, var(--overlay)); border: 2px dashed var(--accent); display: grid; place-items: center; color: #fff; font-size: 18px; font-weight: 600; z-index: 20; pointer-events: none; }

/* ---------- Popups ---------- */
.popup { position: fixed; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: var(--shadow); z-index: 60; overflow: hidden; }
.mention-pop { width: 240px; max-height: 260px; overflow-y: auto; padding: 4px; }
.mention-pop .opt { display: flex; gap: 8px; align-items: center; padding: 6px 8px; border-radius: 5px; cursor: pointer; }
.mention-pop .opt.sel, .mention-pop .opt:hover { background: var(--side-hover); }
.mention-pop .opt small { color: var(--fg-3); margin-left: auto; }
.emoji-pop { width: 312px; padding: 8px; display: grid; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-pop button { font-size: 21px; height: 36px; border-radius: 5px; }
.emoji-pop button:hover { background: var(--side-hover); }
.menu { min-width: 180px; padding: 4px; }
.menu button { width: 100%; text-align: left; padding: 8px 10px; border-radius: 5px; display: flex; gap: 8px; align-items: center; }
.menu button:hover { background: var(--side-hover); }
.menu button.danger { color: var(--danger); }

.modal-back { position: fixed; inset: 0; background: var(--overlay); display: grid; place-items: center; z-index: 80; padding: 16px; animation: fade .15s ease; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 440px; max-height: calc(100dvh - 32px); background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; }
.modal.wide { max-width: 640px; }
.modal-head { padding: 16px 20px; display: flex; align-items: center; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 16px; flex: 1; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--line); }
.pick-list { max-height: 300px; overflow-y: auto; border: 1px solid var(--line); border-radius: 8px; }
.pick { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; }
.pick:hover { background: var(--side-hover); }
.pick input { accent-color: var(--accent); width: 16px; height: 16px; }
.pick .avatar .dot-on, .pick .avatar .dot-off { border-color: var(--panel); }
.settings-section { margin-bottom: 22px; }
.settings-section h4 { margin: 0 0 10px; font-size: 13px; color: var(--fg-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.seg { display: inline-flex; background: var(--chip); border-radius: 8px; padding: 3px; gap: 2px; }
.seg button { padding: 6px 14px; border-radius: 6px; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.seg button.on { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.15); color: var(--accent); font-weight: 600; }
.swatches { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; }
.swatch { border-radius: 10px; padding: 8px 4px 6px; border: 2px solid transparent; display: flex; flex-direction: column; align-items: center; gap: 5px; font-size: 11.5px; color: var(--fg-2); background: var(--chip); }
.swatch i { width: 30px; height: 30px; border-radius: 50%; display: block; box-shadow: inset 0 0 0 3px rgba(255,255,255,.25); }
.swatch.on { border-color: var(--accent); color: var(--fg); }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; }
.toggle-row small { display: block; color: var(--fg-3); font-size: 12px; }
.switch { position: relative; width: 42px; height: 24px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--chip); border-radius: 12px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::before { transform: translateX(18px); }

/* info drawer */
.drawer { position: absolute; top: 62px; right: 0; bottom: 0; width: 300px; background: var(--panel); border-left: 1px solid var(--line); z-index: 15; display: flex; flex-direction: column; box-shadow: var(--shadow); animation: slide .18s ease; }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px; }
.member-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px 6px; margin-bottom: 16px; }
.member-grid .mg { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 11.5px; color: var(--fg-2); text-align: center; position: relative; cursor: pointer; }
.member-grid .mg span { max-width: 62px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.member-grid .mg .avatar .dot-on, .member-grid .mg .avatar .dot-off { border-color: var(--panel); }
.member-grid .add { width: 40px; height: 40px; border: 1.5px dashed var(--fg-3); border-radius: 6px; display: grid; place-items: center; color: var(--fg-3); }
.drawer .row-btn { width: 100%; text-align: left; padding: 11px 4px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 10px; }
.drawer .row-btn.danger { color: var(--danger); justify-content: center; }
.drawer .file-row { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); font-size: 12.5px; }
.drawer .file-row .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.9); z-index: 90; display: flex; flex-direction: column; animation: fade .15s; }
.lightbox .lb-img { flex: 1; display: grid; place-items: center; overflow: auto; padding: 20px; }
.lightbox img { max-width: 100%; max-height: calc(100dvh - 100px); object-fit: contain; }
.lightbox .lb-bar { display: flex; justify-content: center; gap: 10px; padding: 12px; }
.lightbox .lb-bar .btn { background: rgba(255,255,255,.14); color: #fff; }

/* toasts */
.toasts { position: fixed; right: 18px; top: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); border-radius: 8px; padding: 10px 14px; max-width: 340px; font-size: 13px; animation: slide .2s; cursor: default; }
.toast.err { border-left: 3px solid var(--danger); }
.toast.ok { border-left: 3px solid var(--accent); }
.toast.mention { border-left: 3px solid #FA5151; cursor: pointer; }
.toast b { display: block; margin-bottom: 2px; }

/* mentions list */
.mention-item .meta .preview { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.mention-item.unread .name::after { content: ""; display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: #FA5151; margin-left: 6px; vertical-align: middle; }

/* ---------- Admin ---------- */
.admin { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); overflow: hidden; }
.admin-head { padding: 18px 26px 0; border-bottom: 1px solid var(--line); background: var(--side); }
.admin-head h2 { margin: 0 0 12px; font-size: 19px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; }
.tabs button { padding: 9px 14px; border-bottom: 2px solid transparent; color: var(--fg-2); display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
.tabs button.on { color: var(--accent); border-color: var(--accent); font-weight: 600; }
.tabs svg.i { width: 17px; height: 17px; }
.admin-body { flex: 1; overflow: auto; padding: 20px 26px 40px; }
.toolbar-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar-row .input { width: auto; min-width: 160px; padding: 7px 10px; }
.toolbar-row .grow { flex: 1; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.table-wrap { overflow-x: auto; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-weight: 600; color: var(--fg-2); font-size: 12px; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; background: color-mix(in srgb, var(--fg) 3%, transparent); }
table.t td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.t tr:last-child td { border-bottom: 0; }
table.t tr:hover td { background: color-mix(in srgb, var(--fg) 3%, transparent); }
table.t .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.t .nowrap { white-space: nowrap; }
table.t .mono { font-family: var(--mono); font-size: 12px; }
table.t .muted { color: var(--fg-3); }
table.t input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
.ucell { display: flex; gap: 10px; align-items: center; }
.ucell .avatar .dot-on, .ucell .avatar .dot-off { border-color: var(--panel); }
.ucell small { display: block; color: var(--fg-3); font-size: 12px; }
.tag { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 10px; background: var(--chip); color: var(--fg-2); white-space: nowrap; }
.tag.green { background: color-mix(in srgb, #2BD46A 18%, transparent); color: #1fa956; }
[data-mode="dark"] .tag.green { color: #4fe08a; }
.tag.red { background: color-mix(in srgb, var(--danger) 16%, transparent); color: var(--danger); }
.tag.accent { background: var(--mention-bg); color: var(--accent); }
.tag.amber { background: color-mix(in srgb, #F5A524 18%, transparent); color: #c98207; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; }
.row-actions button { width: 30px; height: 30px; border-radius: 6px; display: grid; place-items: center; color: var(--fg-2); }
.row-actions button:hover { background: var(--side-hover); color: var(--fg); }
.row-actions button.danger:hover { color: var(--danger); }
.row-actions svg.i { width: 16px; height: 16px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 12px; color: var(--fg-3); font-size: 12.5px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 14px 16px; }
.stat .k { font-size: 12px; color: var(--fg-3); display: flex; align-items: center; gap: 6px; }
.stat .k svg.i { width: 15px; height: 15px; }
.stat .v { font-size: 22px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .s { font-size: 12px; color: var(--fg-3); margin-top: 2px; }
.meter { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; margin-top: 10px; }
.meter i { display: block; height: 100%; background: var(--accent); border-radius: 4px; }
.meter i.warn { background: #F5A524; }
.meter i.crit { background: var(--danger); }
.section-title { font-size: 14px; font-weight: 600; margin: 22px 0 10px; display: flex; align-items: center; gap: 8px; }
.thumb-sm { width: 36px; height: 36px; border-radius: 5px; object-fit: cover; background: var(--chip); display: block; }
.ext-sm { width: 36px; height: 36px; border-radius: 5px; background: var(--chip); display: grid; place-items: center; font-size: 9.5px; font-weight: 700; color: var(--fg-2); text-transform: uppercase; }
.alert { padding: 12px 14px; border-radius: 8px; background: color-mix(in srgb, #F5A524 12%, transparent); color: var(--fg-2); font-size: 13px; margin-bottom: 14px; }
.alert code { font-family: var(--mono); font-size: 12px; }

/* ---------- Mobile ---------- */
@media (max-width: 768px) {
  .app, .app.admin-mode { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) 56px; }
  .rail { grid-row: 2; flex-direction: row; justify-content: space-around; padding: 0 6px; gap: 0; order: 2; }
  .rail .me, .rail-spacer, .rail .desk-only { display: none; }
  .side { grid-row: 1; border-right: 0; }
  .main { grid-row: 1 / span 2; grid-column: 1; position: fixed; inset: 0; z-index: 30; transform: translateX(100%); transition: transform .2s ease; }
  .app.chat-open .main { transform: none; }
  .admin { grid-row: 1; }
  .back-btn { display: grid; }
  .chat-head { padding: 0 10px; }
  .messages { padding: 10px 12px; }
  .msg .body { max-width: 78%; }
  .drawer { width: 100%; }
  .composer { min-height: 0; }
  .editor { min-height: 44px; max-height: 30vh; padding: 6px 14px; }
  .composer-foot .hint { display: none; }
  .admin-body { padding: 14px; }
  .admin-head { padding: 14px 14px 0; }
  .swatches { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .new-pill { bottom: 170px; }
  .toasts { left: 12px; right: 12px; top: 12px; }
  .toast { max-width: none; }
}
