:root {
  color-scheme: light dark;
  --bg: #f6f7f9; --panel: #fff; --text: #16181d; --muted: #6b7280; --border: #e2e5ea;
  --accent: #2563eb; --danger: #dc2626; --ok: #15803d; --warn: #b45309;
  --add: #15803d; --del: #b91c1c; --add-bg: #e7f6ec; --del-bg: #fdecec;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111418; --panel: #1a1e24; --text: #e6e8eb; --muted: #9aa3ad; --border: #2a3038;
    --accent: #60a5fa; --danger: #f87171; --ok: #4ade80; --warn: #fbbf24;
    --add: #4ade80; --del: #f87171; --add-bg: #12301f; --del-bg: #3a1a1a;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", sans-serif; -webkit-text-size-adjust: 100%; }
#app, .page { height: 100%; }
.page { display: flex; flex-direction: column; }
.bar { display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; background: var(--panel); border-bottom: 1px solid var(--border); }
.bar h1 { flex: 1; margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { font-size: 22px; text-decoration: none; color: var(--text); padding: 0 6px; }
main { flex: 1; overflow-y: auto; padding: 12px 14px 20px; -webkit-overflow-scrolling: touch; }
.conn { font-size: 12px; color: var(--muted); }
.conn-offline, .conn-away { color: var(--danger); }
.group { margin: 16px 0 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.card { display: block; padding: 12px; margin-bottom: 8px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; color: inherit; text-decoration: none; }
.row { display: flex; align-items: center; gap: 8px; }
.name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meta { font-size: 12px; color: var(--muted); }
.last { margin-top: 4px; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat { margin-top: 4px; font-size: 12px; color: var(--muted); }
.add { color: var(--add); } .del { color: var(--del); }
.badge { padding: 1px 8px; border-radius: 999px; font-size: 12px; border: 1px solid var(--border); white-space: nowrap; }
.agent { flex: none; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--border); white-space: nowrap; }
.st-blocked, .st-error { color: var(--danger); border-color: var(--danger); }
.st-done { color: var(--ok); border-color: var(--ok); }
.st-working { color: var(--accent); border-color: var(--accent); }
section { margin-bottom: 14px; }
section h2 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
.status { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
.perm { padding: 12px; background: var(--panel); border: 1px solid var(--danger); border-radius: 10px; }
.reply { white-space: pre-wrap; overflow-wrap: anywhere; padding: 12px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
pre { margin: 0; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-x: auto; white-space: pre; }
.perm pre { margin-bottom: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
details { margin-bottom: 10px; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
summary { padding: 10px 12px; cursor: pointer; overflow-wrap: anywhere; }
details pre { padding: 10px 12px; border-top: 1px solid var(--border); }
.diff span { display: block; min-width: max-content; }
.diff .add { background: var(--add-bg); } .diff .del { background: var(--del-bg); } .diff .hunk { color: var(--muted); }
button, .button { font: inherit; padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--panel); color: var(--text); text-align: center; text-decoration: none; }
button:disabled { opacity: .5; }
.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.danger { color: var(--danger); border-color: var(--danger); }
.wide { display: block; width: 100%; }
.composer { padding: 8px 14px calc(8px + env(safe-area-inset-bottom)); background: var(--panel); border-top: 1px solid var(--border); }
.composer { position: relative; }
.composer::before { content: ''; position: absolute; left: 0; right: 0; top: -2px; height: 2px; background: linear-gradient(90deg, transparent, var(--accent), transparent) no-repeat; background-size: 50% 100%; opacity: 0; }
.waiting .composer::before { opacity: 1; animation: waitbar 1s linear infinite; }
@keyframes waitbar { from { background-position: -100% 0; } to { background-position: 200% 0; } }
.wait { display: none; color: var(--accent); font-size: 12px; }
.waiting .wait { display: inline; }
@media (prefers-reduced-motion: reduce) { .waiting .composer::before { animation: none; background-size: 100% 100%; } }
.keys { display: flex; gap: 6px; margin-bottom: 8px; overflow-x: auto; }
.keys button { padding: 6px 10px; font-size: 13px; white-space: nowrap; }
textarea, select { font: inherit; width: 100%; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.composer .row textarea { flex: 1; resize: none; }
.composer .row button { flex: none; }
.composer > textarea { margin-bottom: 8px; }
.composer .row > button { flex: 1; }
.composer .row > textarea + button { flex: none; }
label { display: block; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 8px; margin: 14px 0; }
.check input { width: 18px; height: 18px; }
.empty, .warn { padding: 24px 8px; text-align: center; color: var(--muted); }
.warn { color: var(--warn); padding: 10px 12px; text-align: left; }
#toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%); max-width: 86%; padding: 9px 14px; border-radius: 8px; background: #111c; color: #fff; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }
[hidden] { display: none !important; }
