:root {
  --bg: #f4f6f9; --card: #ffffff; --text: #102a43; --muted: #627d98; --line: #d9e2ec;
  --navy: #102a43; --accent: #1f7ae0; --ok: #1f9d55; --warn: #d97706; --err: #d64545;
  --me: #1f7ae0; --me-text: #ffffff; --tool: #829ab1;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1724; --card: #132235; --text: #e6edf5; --muted: #9fb3c8; --line: #23364d; --me: #1f6fd0; --tool: #7b93ad; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 16px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif; overflow-x: hidden; }
#app { display: flex; flex-direction: column; height: 100dvh; }
.hidden { display: none !important; }
.top { background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); }
.brand { font-weight: 700; display: flex; gap: 8px; align-items: center; }
.logo { background: var(--accent); width: 28px; height: 28px; border-radius: 8px; display: inline-grid; place-items: center; }
.busy { font-size: 13px; display: flex; gap: 6px; align-items: center; opacity: .9; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #4ade80; animation: p 1s infinite alternate; }
@keyframes p { to { opacity: .25; } }
main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px; }
nav.bottom { display: flex; border-top: 1px solid var(--line); background: var(--card); padding-bottom: env(safe-area-inset-bottom); }
nav.bottom a { flex: 1; text-align: center; padding: 8px 0 10px; color: var(--muted); text-decoration: none; font-size: 12px; position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; }
nav.bottom a .ic { font-size: 20px; }
nav.bottom a.on { color: var(--accent); font-weight: 600; }
.badge { position: absolute; top: 4px; left: 55%; background: var(--err); color: #fff; border-radius: 10px; font-size: 11px; padding: 1px 6px; }
h2 { font-size: 20px; margin: 4px 0 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px; margin-bottom: 12px; }
.btn { appearance: none; border: 0; border-radius: 12px; padding: 13px 16px; font-size: 16px; font-weight: 600; cursor: pointer; background: var(--accent); color: #fff; }
.btn.sec { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
.btn.ok { background: var(--ok); } .btn.err { background: var(--err); } .btn.warn { background: var(--warn); }
.btn.full { width: 100%; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; } .row > * { flex: 1; }
input, textarea { width: 100%; font: inherit; color: var(--text); background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
textarea { resize: none; }
label { display: block; font-size: 14px; color: var(--muted); margin: 10px 0 6px; }
.err-msg { color: var(--err); margin-top: 10px; min-height: 1em; }
.muted { color: var(--muted); font-size: 14px; }
.list a.item { display: block; text-decoration: none; color: inherit; }
.item .t { font-weight: 600; } .item .s { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--line); color: var(--text); margin-right: 6px; }
.chip.done { background: #d1fae5; color: #065f46; } .chip.error { background: #fee2e2; color: #991b1b; } .chip.running { background: #dbeafe; color: #1e40af; }
@media (prefers-color-scheme: dark) { .chip.done { background: #064e3b; color: #a7f3d0; } .chip.error { background: #7f1d1d; color: #fecaca; } .chip.running { background: #1e3a8a; color: #bfdbfe; } }
/* chat */
.chat { display: flex; flex-direction: column; height: 100%; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); background: var(--card); }
.chat-head .title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head button { background: none; border: 0; color: var(--accent); font-size: 16px; padding: 6px; }
.msgs { flex: 1; overflow-y: auto; padding: 12px; }
.m { max-width: 92%; margin: 0 0 10px; padding: 10px 12px; border-radius: 14px; word-wrap: break-word; overflow-wrap: anywhere; }
.m.user { margin-left: auto; background: var(--me); color: var(--me-text); border-bottom-right-radius: 4px; white-space: pre-wrap; }
.m.assistant { background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.m.tool { background: none; color: var(--tool); font-size: 13px; padding: 2px 4px; margin: 0 0 4px; }
.m.assistant table { border-collapse: collapse; font-size: 14px; display: block; overflow-x: auto; max-width: 100%; }
.m.assistant th, .m.assistant td { border: 1px solid var(--line); padding: 4px 6px; text-align: left; white-space: nowrap; }
.m.assistant p { margin: 6px 0; } .m.assistant ul { margin: 6px 0; padding-left: 20px; }
.m.assistant code { background: var(--bg); border-radius: 4px; padding: 0 4px; font-size: 14px; }
.m.assistant pre { background: var(--bg); padding: 8px; border-radius: 8px; overflow-x: auto; font-size: 13px; }
.m .apr { border-left: 4px solid var(--warn); padding: 6px 10px; margin: 8px 0; background: var(--bg); border-radius: 8px; }
.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: var(--card); }
.composer textarea { flex: 1; max-height: 140px; }
.composer .btn { padding: 0 16px; }
.qr { display: block; margin: 10px auto; width: 220px; height: 220px; background: #fff; padding: 8px; border-radius: 12px; }
.secret { font-family: monospace; word-break: break-all; font-size: 13px; }
.det { white-space: pre-wrap; font-size: 14px; color: var(--muted); margin: 6px 0 10px; }
