:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --ink: #1f2420;
  --muted: #6b716c;
  --line: #ddd8cc;
  --brand: #2f6b4f;
  --brand-ink: #ffffff;
  --mine: #d9efd9;
  --owner: #fff3cf;
  --peer: #e3ecf7;
  --danger: #a3322a;
  --warn: #9a5b00;
  --warn-bg: #fff1dc;
  --bad: #a3322a;
  --bad-bg: #fbe6e3;
  --code-bg: #f1eee6;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a18;
    --card: #222624;
    --ink: #ecefe9;
    --muted: #a2a8a2;
    --line: #3a3f3b;
    --brand: #5fae86;
    --brand-ink: #0f1411;
    --mine: #23412f;
    --owner: #423a1d;
    --peer: #22344a;
    --danger: #f08a80;
    --warn: #f0b45a;
    --warn-bg: #3d2f18;
    --bad: #f08a80;
    --bad-bg: #44221f;
    --code-bg: #2c302d;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 19px/1.65 -apple-system, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.muted { color: var(--muted); }
.center-view { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }

/* 登录 */
.login-card { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 18px; }
.login-card h1 { font-size: 28px; margin: 0 0 8px; text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 18px; color: var(--muted); }
.login-card input {
  font-size: 20px; padding: 14px 14px; border-radius: 12px; border: 1.5px solid var(--line);
  background: var(--card); color: var(--ink);
}
.login-card input:focus { outline: none; border-color: var(--brand); }
.form-msg { min-height: 1.6em; margin: 0; color: var(--bad); text-align: center; }

.btn-primary {
  background: var(--brand); color: var(--brand-ink); border: 0; border-radius: 12px;
  padding: 12px 22px; font-size: 19px; font-weight: 600; min-height: 50px;
}
.btn-primary:disabled { opacity: .45; }
.btn-soft {
  background: var(--card); border: 1.5px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 17px; min-height: 46px;
}
.btn-link { background: none; border: 0; color: var(--brand); font-size: 17px; padding: 8px 6px; }

/* 聊天 */
.chat { height: 100dvh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.topbar-title { flex: 1; font-weight: 600; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scroller { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 12px 16px 8px; -webkit-overflow-scrolling: touch; }
.more-wrap { text-align: center; margin: 4px 0 12px; }
.msgs { display: flex; flex-direction: column; gap: 14px; }
#outbox:not(:empty) { margin-top: 14px; }

.msg { max-width: 100%; }
.msg .who { font-size: 14px; color: var(--muted); margin: 0 4px 3px; }
.bubble {
  padding: 12px 15px; border-radius: 16px; background: var(--card);
  border: 1px solid var(--line); overflow-wrap: anywhere; min-width: 0;
}
.msg.right { align-self: flex-end; max-width: 88%; }
.msg.right .who { text-align: right; }
.msg.right .bubble { background: var(--mine); border-color: transparent; border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg.owner { align-self: flex-start; max-width: 92%; }
.msg.owner .bubble { background: var(--owner); border-color: transparent; border-bottom-left-radius: 6px; white-space: pre-wrap; }
.msg.peer { align-self: flex-start; max-width: 88%; }
.msg.peer .bubble { background: var(--peer); border-color: transparent; border-bottom-left-radius: 6px; white-space: pre-wrap; }
.msg.assistant { align-self: stretch; }
.msg.assistant .bubble { border-bottom-left-radius: 6px; }

.tag { display: inline-block; margin-top: 6px; font-size: 15px; padding: 2px 10px; border-radius: 999px; }
.msg.right .tag { float: right; }
.tag.wait { background: var(--card); color: var(--muted); border: 1px solid var(--line); }
.tag.hold { background: var(--warn-bg); color: var(--warn); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.msg::after { content: ""; display: block; clear: both; }

.files { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; white-space: normal; }
.file-chip {
  display: inline-flex; align-items: center; gap: 4px; max-width: 100%;
  font-size: 15px; padding: 4px 10px; border-radius: 10px; background: rgba(0,0,0,.06);
  color: inherit; text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* Markdown */
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p, .md ul, .md ol, .md blockquote, .md pre, .md .table-wrap { margin: .55em 0; }
.md h1, .md h2, .md h3, .md h4 { line-height: 1.35; margin: 1em 0 .4em; }
.md h1 { font-size: 1.35em; } .md h2 { font-size: 1.22em; } .md h3 { font-size: 1.1em; } .md h4 { font-size: 1em; }
.md ul, .md ol { padding-left: 1.4em; }
.md li { margin: .2em 0; }
.md a { color: var(--brand); word-break: break-all; }
.md a.file-link { font-weight: 600; text-decoration: none; border-bottom: 1.5px solid currentColor; }
.md a.file-link::before { content: "📄 "; }
.md code { background: var(--code-bg); padding: .08em .35em; border-radius: 6px; font-size: .88em; }
.md pre { background: var(--code-bg); padding: 10px 12px; border-radius: 10px; overflow-x: auto; font-size: 15px; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 4px solid var(--line); margin-left: 0; padding-left: 12px; color: var(--muted); }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 1em 0; }
.md img { max-width: 100%; border-radius: 8px; }
.md .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 10px; }
.md table { border-collapse: collapse; font-size: 16px; min-width: 100%; }
.md th, .md td { border-bottom: 1px solid var(--line); padding: 8px 10px; text-align: left; vertical-align: top; white-space: nowrap; }
.md td { white-space: normal; min-width: 6em; }
.md th { background: var(--code-bg); }
.md tr:last-child td { border-bottom: 0; }

.status { padding: 4px 16px; font-size: 16px; color: var(--muted); min-height: 30px; }
.status.busy::after { content: ""; display: inline-block; width: 1.2em; text-align: left; animation: dots 1.4s steps(4) infinite; }
.status.err { color: var(--bad); }
@keyframes dots { 0% { content: ""; } 25% { content: "."; } 50% { content: ".."; } 75% { content: "..."; } }

.composer {
  border-top: 1px solid var(--line); background: var(--bg); padding: 10px 16px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
}
.composer textarea {
  width: 100%; resize: none; font-size: 19px; line-height: 1.5; padding: 10px 12px;
  border-radius: 12px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  max-height: 40dvh; min-height: 50px;
}
.composer textarea:focus { outline: none; border-color: var(--brand); }
.composer-row { display: flex; align-items: center; gap: 10px; }
.counter { flex: 1; font-size: 14px; color: var(--muted); }
.counter.over { color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips:empty { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 15px; background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 4px 4px 4px 10px; max-width: 100%;
}
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 52vw; }
.chip.err { border-color: var(--bad); color: var(--bad); }
.chip button { border: 0; background: none; font-size: 20px; line-height: 1; padding: 2px 8px; color: var(--muted); }

/* 机主页 */
.admin { min-height: 100dvh; }
.admin-body { padding: 12px 16px 40px; max-width: 760px; margin: 0 auto; }
.admin h2 { font-size: 18px; color: var(--muted); margin: 28px 0 10px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin-bottom: 12px; }
.item .meta { font-size: 14px; color: var(--muted); margin-bottom: 6px; }
.item .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.item .reason { margin-top: 8px; font-size: 16px; background: var(--warn-bg); color: var(--warn); padding: 6px 10px; border-radius: 10px; }
.item .actions { display: flex; gap: 10px; margin-top: 10px; }
.item.small { padding: 8px 12px; font-size: 16px; }
.empty { color: var(--muted); padding: 12px 0; }

/* 管理页 */
.tabs { display: flex; gap: 6px; padding: 8px 16px 0; border-bottom: 1px solid var(--line); background: var(--bg); position: sticky; top: 0; z-index: 2; }
.tab { flex: 1; background: none; border: 0; border-bottom: 3px solid transparent; padding: 10px 4px; font-size: 17px; color: var(--muted); }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 600; }
.form-msg.ok { color: var(--brand); text-align: left; min-height: 0; }
.form-msg.ok:empty { display: none; }
.item summary { font-weight: 600; font-size: 18px; cursor: pointer; padding: 4px 0; }
.acct-form { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.acct-form label { display: flex; flex-direction: column; gap: 4px; font-size: 16px; color: var(--muted); }
.acct-form label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); font-size: 17px; }
.acct-form input:not([type=checkbox]) {
  font-size: 18px; padding: 10px 12px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--bg); color: var(--ink); width: 100%;
}
.acct-form input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--brand); }
.acct-form input:focus { outline: none; border-color: var(--brand); }
.acct-form input:disabled { opacity: .5; }
.hint { font-size: 15px; color: var(--muted); margin: 0; }
.acct-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.acct-name { font-size: 19px; font-weight: 600; margin-right: 4px; overflow-wrap: anywhere; }
.badge { font-size: 13px; padding: 1px 8px; border-radius: 999px; background: var(--code-bg); color: var(--muted); }
.badge.b-owner { background: var(--owner); color: var(--ink); }
.badge.b-on { background: var(--mine); color: var(--ink); }
.badge.b-off { background: var(--bad-bg); color: var(--bad); }
.badge.b-self { background: var(--brand); color: var(--brand-ink); }
.acct .meta { margin: 6px 0 0; font-size: 15px; }
.actions.wrap { flex-wrap: wrap; }
.actions .btn-soft, .actions .btn-danger { min-height: 42px; padding: 6px 14px; font-size: 16px; }
.btn-danger { background: var(--card); border: 1.5px solid var(--danger); color: var(--danger); border-radius: 12px; }
.acct-panel { border-top: 1px dashed var(--line); margin-top: 12px; }
.acct-panel .acct-form { margin-top: 10px; }
.secret { background: var(--warn-bg); border: 1.5px solid var(--warn); border-radius: 14px; padding: 12px 14px; margin-bottom: 14px; }
.secret-title { font-weight: 600; }
.secret-pw { display: block; font-size: 22px; letter-spacing: .03em; margin: 8px 0; padding: 8px 10px; background: var(--card); border-radius: 10px; user-select: all; -webkit-user-select: all; overflow-wrap: anywhere; }
.secret-note { font-size: 15px; color: var(--warn); }
