:root {
  --bg: #eef2f0; --panel: #ffffff; --panel2: #f6f8f7; --hover: #f0f4f2; --line: #e2e8e5;
  --text: #15201a; --muted: #687770; --accent: #128c4a; --accent-strong: #0f7a3d; --accent-ink: #fff;
  --accent-soft: #dcf5e6; --danger: #d92d20; --danger-soft: #fde8e7; --warn: #a15c07; --warn-soft: #fdf1d8;
  --info: #1d6fd6; --info-soft: #e1edfc; --read: #34b7f1;
  --chat-bg: #efeae2; --chat-dot: rgba(0,0,0,.035); --bin: #ffffff; --bout: #d9fdd3; --bubble-ink: #111b21;
  --rail: #0f2a1d; --rail-ink: #9fb8aa; --rail-on: #ffffff; --rail-on-bg: rgba(255,255,255,.12);
  --shadow: 0 1px 2px rgba(16,24,20,.05), 0 6px 20px rgba(16,24,20,.05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b100e; --panel: #121a16; --panel2: #18221d; --hover: #1b2620; --line: #233029;
    --text: #e3ebe6; --muted: #8c9c93; --accent: #25c16f; --accent-strong: #1fa85f; --accent-ink: #04210f;
    --accent-soft: #123524; --danger: #f97066; --danger-soft: #3a1513; --warn: #f5b13d; --warn-soft: #36270a;
    --info: #6aa8f7; --info-soft: #132741; --read: #53bdeb;
    --chat-bg: #0b141a; --chat-dot: rgba(255,255,255,.025); --bin: #202c33; --bout: #005c4b; --bubble-ink: #e9edef;
    --rail: #0a120e; --rail-ink: #7f948a; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b100e; --panel: #121a16; --panel2: #18221d; --hover: #1b2620; --line: #233029;
  --text: #e3ebe6; --muted: #8c9c93; --accent: #25c16f; --accent-strong: #1fa85f; --accent-ink: #04210f;
  --accent-soft: #123524; --danger: #f97066; --danger-soft: #3a1513; --warn: #f5b13d; --warn-soft: #36270a;
  --info: #6aa8f7; --info-soft: #132741; --read: #53bdeb;
  --chat-bg: #0b141a; --chat-dot: rgba(255,255,255,.025); --bin: #202c33; --bout: #005c4b; --bubble-ink: #e9edef;
  --rail: #0a120e; --rail-ink: #7f948a; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14.5px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
.hidden, [hidden] { display: none !important; }
h1 { font-size: 22px; margin: 0 0 18px; letter-spacing: -.01em; }
h1 small { font-size: 14px; font-weight: 500; }
h3 { font-size: 15px; margin: 0 0 12px; }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 12.5px; background: var(--panel2); padding: 1px 5px; border-radius: 5px; border: 1px solid var(--line); }
pre { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 12px; overflow-x: auto; font-size: 12.5px; margin: 8px 0 16px; }
pre code { background: none; border: 0; padding: 0; }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
a.link { color: var(--accent); text-decoration: none; font-size: 13px; font-weight: 500; }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; line-height: 1.55; }

/* controls */
.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); border-radius: 9px; padding: 8px 14px; font: inherit; font-weight: 550; cursor: pointer; transition: background .15s, border-color .15s, filter .15s; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 11px; font-size: 13px; }
.btn.block { width: 100%; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 50%; border: 0; background: transparent; color: var(--muted); cursor: pointer; flex: none; transition: background .15s, color .15s; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm svg { width: 16px; height: 16px; }
.icon-btn.on { color: var(--accent); }
label { display: block; font-weight: 550; font-size: 13px; margin-bottom: 14px; }
input, select, textarea { display: block; width: 100%; margin-top: 6px; background: var(--panel2); color: var(--text); border: 1px solid var(--line); border-radius: 9px; padding: 9px 11px; font: inherit; font-weight: 400; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--accent) 35%, transparent); border-color: var(--accent); }
textarea { resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.center { text-align: center; padding: 12px; }
.unit { display: flex; align-items: center; gap: 8px; }
.unit input { margin-top: 6px; }
.unit span { color: var(--muted); font-weight: 400; margin-top: 6px; white-space: nowrap; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: radial-gradient(1200px 500px at 50% -10%, var(--accent-soft), transparent), var(--bg); }
.login-card { width: 100%; max-width: 370px; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 30px; box-shadow: var(--shadow); }
.err { color: var(--danger); min-height: 20px; margin: 0 0 8px; font-size: 13px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand b { display: block; font-size: 16px; }
.brand small { color: var(--muted); font-size: 12px; }
.brand.big { padding: 0 0 24px; }
.logo { width: 38px; height: 38px; border-radius: 11px; background: var(--accent) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 23l1.4-4.2A7 7 0 1 1 13.3 21.7z' fill='none' stroke='white' stroke-width='2' stroke-linejoin='round'/%3E%3C/svg%3E") center/28px no-repeat; flex: none; }

/* layout */
.app { display: grid; grid-template-columns: 76px 1fr; height: 100vh; height: 100dvh; }
.rail { background: var(--rail); display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 14px 0; }
.rail > .logo { margin-bottom: 14px; }
.rail a { position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; width: 62px; padding: 9px 0 7px; border-radius: 12px; color: var(--rail-ink); text-decoration: none; font-size: 10.5px; font-weight: 600; transition: background .15s, color .15s; }
.rail a:hover { color: var(--rail-on); }
.rail a.on { background: var(--rail-on-bg); color: var(--rail-on); }
.rail a svg { width: 22px; height: 22px; }
.rail .dot { position: absolute; top: 6px; right: 14px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--accent); color: #fff; font: 700 10.5px/18px system-ui; font-style: normal; text-align: center; }
.rail-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; }
.rail-foot .icon-btn { color: var(--rail-ink); }
.rail-foot .icon-btn:hover { background: var(--rail-on-bg); color: var(--rail-on); }
.me-btn { width: 38px; height: 38px; border-radius: 50%; border: 2px solid var(--rail-on-bg); color: #fff; font: 700 13px system-ui; cursor: pointer; margin-top: 4px; }
.me-btn.mob { display: none; }
.role { font-size: 11.5px; font-weight: 650; padding: 2px 8px; border-radius: 99px; background: var(--panel2); border: 1px solid var(--line); color: var(--muted); white-space: nowrap; }
.role.owner, .role.admin { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.online { color: var(--accent); font-weight: 600; }
.online::before { content: "●"; margin-right: 5px; font-size: 10px; }
.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell .avatar { width: 34px; height: 34px; font-size: 12px; }
.user-cell small { display: block; color: var(--muted); }
tr.inactive td { opacity: .55; }
.b .src.by { background: rgba(0,0,0,.06); }
.act { font-weight: 600; white-space: nowrap; }
.act.bad { color: var(--danger); }
.menu-list { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; }
.menu-list .btn { text-align: left; }
main { min-width: 0; min-height: 0; overflow: hidden; display: flex; }
.view { flex: 1; min-width: 0; }
.view.page { overflow-y: auto; padding: 26px 32px 48px; }
.view.page > * { max-width: 1240px; }

/* ---------- inbox ---------- */
.inbox { display: grid; grid-template-columns: minmax(300px, 380px) minmax(0, 1fr); min-height: 0; height: 100%; }
.chatlist { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.cl-head { display: flex; gap: 4px; align-items: center; padding: 12px 10px 8px 14px; }
.cl-head select { margin: 0; font-weight: 600; border-radius: 10px; min-width: 0; flex: 1; }
.cl-search { position: relative; margin: 0 14px 8px; }
.cl-search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.cl-search input { margin: 0; padding-left: 34px; border-radius: 10px; background: var(--panel2); border-color: transparent; }
.chips { display: flex; gap: 6px; padding: 0 14px 10px; overflow-x: auto; scrollbar-width: none; }
.chips button { border: 1px solid var(--line); background: transparent; color: var(--muted); border-radius: 99px; padding: 4px 12px; font: 600 12.5px system-ui; cursor: pointer; white-space: nowrap; }
.chips button.on { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.chips b { background: var(--danger); color: #fff; border-radius: 9px; padding: 0 6px; margin-left: 3px; font-size: 11px; }
.chips b:empty { display: none; }
.cl-items { flex: 1; overflow-y: auto; min-height: 0; }
.ci { display: flex; gap: 12px; align-items: center; padding: 10px 14px; cursor: pointer; position: relative; }
.ci:hover { background: var(--hover); }
.ci.on { background: var(--accent-soft); }
.ci .grow { flex: 1; min-width: 0; border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: -10px; }
.ci .l1, .ci .l2 { display: flex; gap: 8px; align-items: center; }
.ci .l1 b { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.ci .l1 time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.ci.unread .l1 time { color: var(--accent); font-weight: 600; }
.ci .l2 span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 13.5px; }
.ci .l2 .tick { flex: none; }
.ci .count { background: var(--accent); color: #fff; border-radius: 10px; min-width: 20px; height: 20px; padding: 0 6px; font: 700 11.5px/20px system-ui; text-align: center; }
.ci .flag { color: var(--danger); display: inline-flex; }
.ci .flag svg { width: 16px; height: 16px; }
.ci .ai-mini { color: var(--accent); display: inline-flex; }
.ci .ai-mini svg { width: 14px; height: 14px; }
.cl-empty { padding: 40px 24px; text-align: center; color: var(--muted); }

.avatar { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; flex: none; color: #fff; font-size: 15px; background: var(--accent); }

.thread { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); background-image: radial-gradient(var(--chat-dot) 1.2px, transparent 1.2px); background-size: 18px 18px; position: relative; }
.thread-empty { margin: auto; text-align: center; padding: 24px; max-width: 420px; }
.te-art { width: 84px; height: 84px; border-radius: 26px; background: var(--panel); display: grid; place-items: center; margin: 0 auto 16px; box-shadow: var(--shadow); color: var(--accent); }
.te-art svg { width: 40px; height: 40px; }
.thread-empty h2 { margin: 0 0 6px; font-size: 20px; }
.thread-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.th-head { display: flex; align-items: center; gap: 12px; padding: 9px 16px; background: var(--panel); border-bottom: 1px solid var(--line); min-height: 62px; }
.th-head .back { display: none; margin-left: -8px; }
.th-head .avatar { width: 40px; height: 40px; font-size: 14px; }
.th-who { flex: 1; min-width: 0; cursor: pointer; }
.th-who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.th-who small { color: var(--muted); font-size: 12.5px; }
.ai-chip { display: inline-flex; align-items: center; gap: 6px; border-radius: 99px; padding: 6px 12px; font: 600 12.5px system-ui; cursor: pointer; border: 1px solid var(--line); background: var(--panel2); color: var(--muted); white-space: nowrap; }
.ai-chip svg { width: 15px; height: 15px; }
.ai-chip.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.ai-chip.paused { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.banner { display: flex; align-items: center; gap: 10px; padding: 9px 16px; background: var(--danger-soft); color: var(--danger); font-weight: 550; font-size: 13.5px; }
.banner span { flex: 1; }
.banner.warn { background: var(--warn-soft); color: var(--warn); border-radius: 12px; margin-bottom: 16px; max-width: 1240px; }

.msgs { flex: 1; overflow-y: auto; padding: 14px 6% 10px; display: flex; flex-direction: column; gap: 2px; min-height: 0; }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; font-weight: 600; padding: 4px 12px; border-radius: 8px; margin: 10px 0; box-shadow: 0 1px .5px rgba(0,0,0,.08); }
.b { max-width: min(560px, 78%); padding: 6px 9px 5px; border-radius: 10px; color: var(--bubble-ink); box-shadow: 0 1px .5px rgba(0,0,0,.13); position: relative; overflow-wrap: anywhere; margin-top: 2px; }
.b.in { align-self: flex-start; background: var(--bin); border-top-left-radius: 3px; }
.b.out { align-self: flex-end; background: var(--bout); border-top-right-radius: 3px; }
.b.cont { border-radius: 10px; }
.b.gap { margin-top: 8px; }
.b .who { font-size: 12.5px; font-weight: 700; color: var(--accent); margin-bottom: 1px; }
.b .txt { white-space: pre-wrap; }
.b .meta { float: right; display: inline-flex; align-items: center; gap: 4px; margin: 6px 0 -3px 12px; font-size: 11px; color: color-mix(in srgb, var(--bubble-ink) 55%, transparent); white-space: nowrap; }
.b .src { font-weight: 700; font-size: 10px; letter-spacing: .02em; padding: 0 5px; border-radius: 4px; background: rgba(0,0,0,.07); }
.b .src.ai { background: color-mix(in srgb, var(--accent) 22%, transparent); color: var(--accent-strong); }
:root[data-theme="dark"] .b .src.ai { color: #9ef0c2; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .b .src.ai { color: #9ef0c2; } }
.tick { display: inline-flex; color: color-mix(in srgb, var(--bubble-ink) 50%, transparent); }
.tick svg { width: 16px; height: 16px; stroke-width: 2.2; }
.tick.read { color: var(--read); }
.tick.failed { color: var(--danger); }
.b .err-txt { color: var(--danger); font-size: 12px; display: block; }
.b img.media { display: block; max-width: 100%; width: 320px; max-height: 360px; object-fit: cover; border-radius: 7px; margin: -2px -5px 4px; cursor: zoom-in; background: rgba(0,0,0,.05); }
.b img.sticker { width: 140px; height: 140px; object-fit: contain; background: none; margin: 0; cursor: default; }
.b video, .b audio { display: block; max-width: 100%; border-radius: 7px; margin-bottom: 4px; }
.b audio { width: 260px; }
.doc { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.05); border-radius: 8px; padding: 10px; margin-bottom: 4px; color: inherit; text-decoration: none; }
.doc svg { color: var(--accent); }
.doc span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.load-older { align-self: center; margin: 4px 0 10px; }

.suggest { margin: 0 12px 8px; background: var(--panel); border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--line)); border-radius: 14px; padding: 10px 12px; box-shadow: var(--shadow); }
.sg-head { display: flex; align-items: center; gap: 6px; font: 700 12px system-ui; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; margin-bottom: 4px; }
.sg-head svg { width: 15px; height: 15px; }
.sg-text { white-space: pre-wrap; margin-bottom: 8px; max-height: 160px; overflow-y: auto; }
.attach { display: flex; align-items: center; gap: 8px; margin: 0 12px 6px; background: var(--panel); border-radius: 10px; padding: 6px 6px 6px 12px; font-size: 13px; }
.attach span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach svg { color: var(--accent); }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 12px 10px; background: var(--panel2); border-top: 1px solid var(--line); }
.composer textarea { margin: 0; resize: none; max-height: 160px; border-radius: 22px; padding: 10px 16px; background: var(--panel); border-color: transparent; line-height: 1.4; }
.composer .icon-btn { margin: 0 0 1px; }
.composer .icon-btn.ai { color: var(--accent); }
.composer .icon-btn.ai.busy { animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
.send-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--accent); color: #fff; display: grid; place-items: center; cursor: pointer; flex: none; }
.send-btn:disabled { opacity: .5; }
.send-btn svg { width: 19px; height: 19px; margin-left: -2px; }
.composer.flat { padding: 10px 0 0; background: none; border: 0; }
.composer.flat textarea { background: var(--panel2); border-color: var(--line); }

/* ---------- pages ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card + .card { margin-top: 16px; }
.card-h { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 8px; }
.card-h h3 { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid2.tight { gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid2 > .card + .card { margin-top: 0; }
.ai-grid { grid-template-columns: 1.25fr 1fr; align-items: start; }
.col { display: flex; flex-direction: column; min-width: 0; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat span { color: var(--muted); font-size: 13px; }
.stat b { display: block; font-size: 30px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat small { color: var(--muted); }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar h1 { margin: 0; }
.filters { justify-content: flex-start; margin-bottom: 16px; }
.filters select, .filters input { width: auto; margin: 0; min-width: 160px; }
.filters input { flex: 1; }

/* switch & radio cards */
.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; padding: 12px 14px; border-radius: 12px; background: var(--panel2); border: 1px solid var(--line); }
.switch input { display: none; }
.switch span { width: 42px; height: 24px; border-radius: 12px; background: var(--line); position: relative; transition: .2s; flex: none; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { left: 21px; }
.radio-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.radio-cards label { margin: 0; cursor: pointer; }
.radio-cards input { display: none; }
.radio-cards div { height: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px 14px; transition: .15s; }
.radio-cards b { display: block; margin-bottom: 2px; }
.radio-cards small { color: var(--muted); font-weight: 400; font-size: 12.5px; line-height: 1.45; display: block; }
.radio-cards input:checked + div { border-color: var(--accent); background: var(--accent-soft); }

/* sessions */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.cards .card + .card { margin-top: 0; }
.sess { display: flex; flex-direction: column; gap: 12px; }
.sess-h { display: flex; align-items: center; gap: 12px; }
.sess-h b { display: block; }
.sess-h small { color: var(--muted); }
.sess-h .badge { margin-left: auto; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 5px 10px; font-size: 13px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.badge { font-size: 11.5px; font-weight: 650; padding: 3px 9px; border-radius: 99px; white-space: nowrap; }
.b-connected { background: var(--accent-soft); color: var(--accent); }
.b-qr, .b-pair_code, .b-connecting { background: var(--warn-soft); color: var(--warn); }
.b-disconnected, .b-failed { background: var(--danger-soft); color: var(--danger); }
.b-logged_out, .b-delivered, .b-sent, .b-received { background: var(--panel2); color: var(--muted); border: 1px solid var(--line); }
.b-in, .b-read { background: var(--info-soft); color: var(--info); }
.b-out { background: var(--accent-soft); color: var(--accent); }

/* qr */
.qr-box { display: grid; place-items: center; gap: 12px; text-align: center; }
.qr-box img { width: 280px; height: 280px; background: #fff; padding: 10px; border-radius: 12px; border: 1px solid var(--line); }
.pair-code { font: 700 30px ui-monospace, Menlo, monospace; letter-spacing: 6px; background: var(--panel2); border: 1px dashed var(--accent); padding: 14px 20px; border-radius: 12px; }
.steps { text-align: left; color: var(--muted); font-size: 13px; margin: 0; padding-left: 20px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; margin-bottom: 14px; }
.seg button { border: 0; background: transparent; color: var(--muted); padding: 7px 14px; font: inherit; cursor: pointer; }
.seg button.on { background: var(--accent-soft); color: var(--accent); font-weight: 650; }

/* lists */
.mini-list { display: flex; flex-direction: column; }
.mini { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); min-width: 0; }
.mini:last-child { border-bottom: 0; }
.mini .grow { flex: 1; min-width: 0; }
.mini .grow b, .mini .grow span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini .grow span { color: var(--muted); font-size: 13px; }
.mini time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.mini.link { cursor: pointer; }
.mini .avatar { width: 38px; height: 38px; font-size: 13px; }
.empty { color: var(--muted); padding: 18px 0; text-align: center; }

/* table */
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th { text-align: left; font-weight: 600; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); background: var(--panel2); white-space: nowrap; }
.tbl td { padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl td.body { max-width: 460px; white-space: pre-wrap; overflow-wrap: anywhere; }
.tbl td.nowrap { white-space: nowrap; }
.tbl small { color: var(--muted); display: block; }
.tbl a { color: var(--accent); }

/* preview phone */
.phone { background: var(--chat-bg); background-image: radial-gradient(var(--chat-dot) 1.2px, transparent 1.2px); background-size: 18px 18px; border-radius: 12px; padding: 16px; min-height: 160px; display: flex; flex-direction: column; gap: 6px; margin-bottom: 4px; overflow-y: auto; }
.phone.tall { height: 340px; }
.phone .bubble { max-width: 85%; padding: 7px 10px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: 0 1px .5px rgba(0,0,0,.13); color: var(--bubble-ink); }
.phone .bubble.out { align-self: flex-end; background: var(--bout); border-top-right-radius: 3px; }
.phone .bubble.in { align-self: flex-start; background: var(--bin); border-top-left-radius: 3px; }
.phone .note { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); padding: 3px 10px; border-radius: 8px; }
.send-log { margin-top: 12px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; max-height: 220px; overflow-y: auto; }
.send-log .ok { color: var(--accent); }
.send-log .no { color: var(--danger); }

/* docs */
.docs h4 { margin: 20px 0 4px; font-size: 14px; }
.docs p { margin: 4px 0; }
.docs .m { display: inline-block; font: 700 11px ui-monospace, monospace; padding: 2px 6px; border-radius: 4px; margin-right: 6px; }
.m.get { background: var(--info-soft); color: var(--info); }
.m.post { background: var(--accent-soft); color: var(--accent); }
.m.patch, .m.put { background: var(--warn-soft); color: var(--warn); }
.m.del { background: var(--danger-soft); color: var(--danger); }
.key { display: block; padding: 10px 12px; margin-bottom: 8px; overflow-wrap: anywhere; }

/* modal, lightbox, toast */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 22px; width: 100%; max-width: 440px; max-height: 92vh; overflow: auto; }
.modal-card .row.end { justify-content: flex-end; margin-top: 8px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 55; cursor: zoom-out; padding: 20px; }
.lightbox img { max-width: 100%; max-height: 100%; border-radius: 8px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; opacity: 0; pointer-events: none; transition: .2s; z-index: 60; max-width: calc(100% - 32px); font-weight: 550; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--danger); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid2, .ai-grid { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .rail { order: 2; flex-direction: row; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); gap: 0; }
  .rail > .logo, .rail-foot, .rail a.desk { display: none; }
  .me-btn.mob { display: block; width: 34px; height: 34px; margin: 6px 8px 0; flex: none; }
  .rail a { width: auto; flex: 1; padding: 6px 0 4px; }
  .rail .dot { right: calc(50% - 22px); top: 2px; }
  main { order: 1; }
  .view.page { padding: 18px 16px 32px; }
  .inbox { grid-template-columns: minmax(0, 1fr); }
  .inbox .thread { display: none; }
  .inbox.show-thread .chatlist { display: none; }
  .inbox.show-thread .thread { display: flex; }
  body.in-thread .rail { display: none; }
  .th-head .back { display: inline-grid; }
  .th-head { padding: 8px 10px; gap: 8px; }
  .ai-chip span { display: none; }
  .msgs { padding: 10px 10px 8px; }
  .b { max-width: 88%; }
  .grid3, .radio-cards { grid-template-columns: 1fr; }
  .stats { gap: 10px; }
  .stat b { font-size: 24px; }
  .cards { grid-template-columns: 1fr; }
  .filters select, .filters input { min-width: 0; width: 100%; }
  .qr-box img { width: 240px; height: 240px; }
  h1 { font-size: 20px; }
}
