:root {
  color-scheme: light dark;
  --bg: #eef0f3; --panel: #ffffff; --panel-2: #f6f7f9; --text: #1b1f24; --muted: #667085; --line: #e3e6ea;
  --accent: #0a9d58; --accent-ink: #ffffff; --accent-soft: #e3f6ec;
  --mine: #d8f5c8; --other: #ffffff; --link: #1d6fd6;
  --warn: #8a5300; --warn-bg: #fff1cc; --bad: #b42318; --bad-bg: #fde8e6; --ok: #146c43; --ok-bg: #dcf5e6;
  --shadow: 0 1px 2px rgba(16, 24, 40, .08);
  --radius: 14px;
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0f12; --panel: #16191e; --panel-2: #1c2026; --text: #e8eaed; --muted: #9aa3ad; --line: #2a2f37;
    --accent: #2fc77a; --accent-ink: #06210f; --accent-soft: #123424;
    --mine: #1d4a2c; --other: #20252c; --link: #6aa8ff;
    --warn: #ffd37a; --warn-bg: #3a2c0b; --bad: #ff9b92; --bad-bg: #3d1713; --ok: #8fe3b4; --ok-bg: #11301f;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5);
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; overflow: hidden; }
body.no-scroll { overflow: hidden; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }

/* ---------- 通用控件 ---------- */
.btn { white-space: nowrap; border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 8px 14px; min-height: 40px; transition: background .12s; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { padding: 4px 10px; min-height: 32px; font-size: 13px; border-radius: 8px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.link { white-space: nowrap; flex: none; background: none; border: 0; padding: 2px 4px; color: var(--link); text-decoration: underline; text-underline-offset: 2px; font-size: inherit; }
.link.danger { color: var(--bad); }
.icon-btn { width: 40px; height: 40px; border: 0; background: transparent; border-radius: 10px; font-size: 20px; line-height: 1; }
.icon-btn:hover { background: var(--panel-2); }
input[type=text], input[type=tel], input[type=password], input[type=number], textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; background: var(--panel); min-height: 40px;
}
input.num { width: 84px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #98a2b3; vertical-align: middle; }
.dot.ok { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .2); }
.dot.wait { background: #f59e0b; animation: pulse 1.1s ease-in-out infinite; }
.dot.bad { background: #ef4444; }
.dot.off { background: #98a2b3; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .dot.wait { animation: none; } * { scroll-behavior: auto !important; } }
.avatar { position: relative; flex: none; width: 44px; height: 44px; border-radius: 12px; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 600; font-size: 18px; overflow: hidden; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 34px; height: 34px; font-size: 15px; border-radius: 10px; }
.avatar-gap { flex: none; width: 34px; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 16px; overflow-y: auto; }
.login-card { width: 100%; max-width: 400px; background: var(--panel); border-radius: 20px; padding: 28px 24px; box-shadow: 0 8px 30px rgba(16, 24, 40, .12); }
.login-card h1 { margin: 6px 0 6px; font-size: 22px; }
.logo { font-size: 38px; }
.tabs, .drawer-tabs { display: flex; gap: 4px; background: var(--panel-2); border-radius: 12px; padding: 4px; margin: 14px 0; }
.tab { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 8px; min-height: 38px; color: var(--muted); }
.tab.active { background: var(--panel); color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.login-form label { display: block; margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.pw-row { display: flex; align-items: center; gap: 6px; }
.form-msg { min-height: 22px; margin: 10px 0 4px; font-size: 13.5px; color: var(--muted); }
.form-msg.err { color: var(--bad); }
.form-note { background: var(--accent-soft); border-radius: 10px; padding: 8px 10px; font-size: 13px; margin-bottom: 8px; word-break: break-all; }
.login-extra { text-align: center; margin-top: 8px; min-height: 24px; }

/* ---------- 主布局 ---------- */
.app { display: grid; grid-template-columns: 350px minmax(0, 1fr); height: 100dvh; background: var(--panel); }
.sidebar { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--line); background: var(--panel); }
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); padding-top: max(10px, env(safe-area-inset-top)); }
.me { display: flex; align-items: center; gap: 10px; min-width: 0; }
.me-text { min-width: 0; }
.me-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 130px; }
.me-status { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.side-actions { display: flex; gap: 4px; flex: none; }
.banner { display: flex; align-items: center; gap: 8px; padding: 8px 12px; font-size: 13px; border-bottom: 1px solid var(--line); }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.bad { background: var(--bad-bg); color: var(--bad); }
.banner.ok { background: var(--ok-bg); color: var(--ok); }
.banner-text { flex: 1; }
.conv-list { flex: 1; overflow-y: auto; overscroll-behavior: contain; }
.conv-list:empty { display: none; }
.conv-empty { flex: 1; padding: 40px 20px; color: var(--muted); text-align: center; font-size: 14px; }
.conv { display: flex; width: 100%; gap: 12px; padding: 10px 12px; border: 0; border-bottom: 1px solid var(--line); background: transparent; text-align: left; align-items: center; }
.conv:hover { background: var(--panel-2); }
.conv.active { background: var(--accent-soft); }
.conv-main { flex: 1; min-width: 0; display: block; }
.conv-top, .conv-bottom { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.conv-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { flex: none; font-size: 12px; color: var(--muted); }
.conv-preview { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { flex: none; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: #ef4444; color: #fff; font-size: 12px; line-height: 20px; text-align: center; font-weight: 600; }

/* ---------- 聊天 ---------- */
.chat { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.chat-head { display: flex; align-items: center; gap: 4px; padding: 8px 10px; background: var(--panel); border-bottom: 1px solid var(--line); padding-top: max(8px, env(safe-area-inset-top)); }
.chat-head-text { flex: 1; min-width: 0; }
.chat-title { font-weight: 600; display: flex; align-items: center; gap: 8px; min-width: 0; }
.chat-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title .dot { flex: none; width: 8px; height: 8px; }
.chat-sub { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-btn { display: none; }
.chat[data-empty=true] .chat-head, .chat[data-empty=true] .messages, .chat[data-empty=true] .composer { display: none; }
.chat:not([data-empty=true]) .chat-empty { display: none; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; }
.chat-empty-card .big { font-size: 44px; }
.messages { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 8px 12px 12px; }
.msg-list { display: flex; flex-direction: column; max-width: 920px; margin: 0 auto; }
.top-row { text-align: center; color: var(--muted); font-size: 12.5px; padding: 8px; background: none; border: 0; }
.day-sep { display: flex; justify-content: center; margin: 14px 0 6px; }
.day-sep span { background: rgba(120, 130, 145, .18); color: var(--muted); border-radius: 999px; padding: 2px 12px; font-size: 12px; }
.unread-sep { display: flex; align-items: center; gap: 10px; margin: 12px 0 6px; color: var(--accent); font-size: 12px; }
.unread-sep::before, .unread-sep::after { content: ""; flex: 1; height: 1px; background: var(--accent); opacity: .5; }
.row { display: flex; align-items: flex-end; gap: 8px; margin: 2px 0; }
.row.head { margin-top: 10px; }
.row.mine { justify-content: flex-end; }
.row .body { display: flex; flex-direction: column; max-width: min(78%, 600px); min-width: 0; }
.row.mine .body { align-items: flex-end; }
.sender { font-size: 12px; color: var(--muted); margin: 0 4px 2px; }
.bubble { background: var(--other); padding: 8px 12px; border-radius: var(--radius); box-shadow: var(--shadow); white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.bubble.img { padding: 4px; }
.chat-img { display: block; max-width: min(260px, 100%); max-height: 320px; border-radius: 10px; }
.bubble.alt { font-style: italic; color: var(--muted); }
.row.mine .bubble { background: var(--mine); }
.row.st-queued .bubble, .row.st-sending .bubble { opacity: .72; }
.row.st-failed .bubble { outline: 1.5px solid var(--bad); }
.meta { display: flex; gap: 6px; align-items: center; font-size: 11.5px; color: var(--muted); margin: 2px 4px 0; }
.st.ok { color: var(--accent); font-weight: 700; }
.st.bad { color: var(--bad); font-weight: 600; }
.fail { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; font-size: 12.5px; color: var(--bad); margin: 2px 4px 0; max-width: 100%; }
.fail-text { overflow-wrap: anywhere; }
.new-pill { position: absolute; right: 16px; bottom: 84px; border: 0; background: var(--accent); color: var(--accent-ink); border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 600; box-shadow: 0 4px 14px rgba(0, 0, 0, .25); z-index: 5; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
.composer-row { display: flex; gap: 8px; align-items: flex-end; }
.composer-input { resize: none; max-height: 140px; line-height: 1.45; border-radius: 14px; }
.send-btn { flex: none; border: 0; background: var(--accent); color: var(--accent-ink); font-weight: 600; border-radius: 12px; padding: 0 18px; min-height: 40px; }
.send-btn:disabled { opacity: .45; cursor: default; }
.offline-hint { font-size: 12.5px; color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding: 4px 10px; margin-bottom: 6px; }
.counter { text-align: right; font-size: 12px; color: var(--muted); }
.counter.over { color: var(--bad); font-weight: 600; }

/* ---------- 抽屉 / 面板 ---------- */
.drawer-wrap { position: fixed; inset: 0; background: rgba(15, 20, 27, .45); z-index: 30; display: flex; justify-content: flex-end; }
.drawer { width: min(520px, 100vw); height: 100%; background: var(--panel); display: flex; flex-direction: column; box-shadow: -8px 0 30px rgba(0, 0, 0, .25); }
.drawer-head { display: flex; align-items: center; gap: 8px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top)); border-bottom: 1px solid var(--line); }
.drawer-tabs { flex: 1; margin: 0; }
.drawer-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 4px 14px calc(24px + env(safe-area-inset-bottom)); }
.panel section { padding: 12px 0; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
.panel h3 { margin: 0 0 8px; font-size: 14px; }
.panel p { margin: 4px 0 8px; }
.kvs { display: grid; grid-template-columns: 1fr; gap: 4px; }
.kv { display: flex; justify-content: space-between; gap: 12px; font-size: 13.5px; }
.kv .k { color: var(--muted); flex: none; }
.kv .v { text-align: right; overflow-wrap: anywhere; }
.counters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.counter-cell { background: var(--panel-2); border-radius: 10px; padding: 8px; text-align: center; }
.counter-cell .n { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.counter-cell .l { font-size: 11.5px; color: var(--muted); }
.counter-cell.warn .n { color: var(--bad); }
.table-wrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
th, td { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
thead th { color: var(--muted); font-weight: 500; }
.btn-row { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
.btn-row.wrap { flex-wrap: wrap; }
.field-row { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.result { font-size: 13px; margin-top: 6px; min-height: 0; overflow-wrap: anywhere; }
.result.ok { color: var(--ok); }
.result.err { color: var(--bad); }
.card { background: var(--panel-2); border-radius: 12px; padding: 10px 12px; margin-top: 8px; }
.card-title { font-weight: 600; }
.list { display: flex; flex-direction: column; gap: 6px; }
.list-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; background: var(--panel-2); border-radius: 10px; padding: 6px 10px; }
.pick-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.pick { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border-radius: 999px; padding: 4px 12px 4px 8px; }
.token { font-family: ui-monospace, Menlo, monospace; font-size: 12px; background: var(--panel-2); padding: 6px 8px; border-radius: 8px; margin-top: 6px; overflow-wrap: anywhere; }
.events { list-style: none; margin: 8px 0 0; padding: 0; max-height: 360px; overflow-y: auto; font: 12px/1.45 ui-monospace, Menlo, Consolas, monospace; }
.ev { display: flex; gap: 8px; padding: 2px 0; border-bottom: 1px dashed var(--line); }
.ev-t { color: var(--muted); flex: none; }
.ev-k { flex: none; min-width: 42px; color: var(--accent); }
.ev.error .ev-k, .ev.gap .ev-k { color: var(--bad); }
.ev.sim .ev-k { color: var(--warn); }
.ev-m { overflow-wrap: anywhere; }
.section.mock, section.mock { background: var(--panel-2); border-radius: 12px; padding: 12px; margin-top: 12px; border-bottom: 0; }

/* ---------- 提示 / 弹窗 ---------- */
.toasts { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 420px); }
.toast { background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, .3); font-size: 14px; }
.toast.error { background: #b42318; }
.toast.ok { background: #0f7a46; }
.modal-wrap { position: fixed; inset: 0; background: rgba(15, 20, 27, .5); z-index: 80; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { background: var(--panel); border-radius: 18px; padding: 22px; max-width: 420px; width: 100%; }
.modal h2 { margin: 0 0 8px; font-size: 18px; }

/* ---------- 手机 ---------- */
@media (max-width: 759px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar, .chat { grid-column: 1; grid-row: 1; }
  .app[data-pane=list] .chat { display: none; }
  .app[data-pane=chat] .sidebar { display: none; }
  .back-btn { display: inline-block; }
  .row .body { max-width: 84%; }
  .drawer { width: 100vw; }
  .counters { grid-template-columns: repeat(2, 1fr); }
  .new-pill { bottom: 96px; }
}
