:root {
  --bg: #F5F5F7; --card: #FFFFFF; --fill: #F0F1F3; --line: #EBEBEB;
  --text: #1F1F1F; --text2: #666666; --text3: #8C8C8C;
  --primary: #1A6FD8; --primary-soft: #EAF2FD; --primary-ink: #1A5FB4;
  --danger: #D4380D; --ok: #2E8B57; --warn: #C98A00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616; --card: #222222; --fill: #2C2C2E; --line: #333333;
    --text: #E6E6E6; --text2: #A6A6A6; --text3: #8A8A8A;
    --primary: #3B86E8; --primary-soft: #1D2A3A; --primary-ink: #8DB8F2;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.6 -apple-system, "PingFang SC", "Helvetica Neue", sans-serif;
  min-height: 100dvh; display: flex; flex-direction: column;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; border: 0; border-radius: 10px; min-height: 44px; padding: 0 16px; cursor: pointer; }
.primary { background: var(--primary); color: #fff; }
.ghost { background: var(--fill); color: var(--text); }

.bar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 8px) 16px 8px; background: var(--bg);
}
.title { font-size: 22px; font-weight: 600; }
.title .sub { font-size: 13px; font-weight: 400; color: var(--text2); margin-left: 6px; }
.bar .ghost { min-height: 36px; font-size: 14px; }

.status {
  display: flex; align-items: center; gap: 8px; margin: 0 16px 8px;
  padding: 8px 12px; background: var(--card); border-radius: 12px; font-size: 13px; color: var(--text2);
  position: sticky; top: calc(env(safe-area-inset-top) + 60px); z-index: 2;
}
.status .fp { margin-left: auto; color: var(--text3); font-variant-numeric: tabular-nums; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text3); flex: none; }
.dot.ok { background: var(--ok); }
.dot.wait { background: var(--warn); }
.dot.off { background: var(--danger); }

main { flex: 1; padding: 0 16px 16px; }
.card { background: var(--card); border-radius: 12px; padding: 20px; margin-bottom: 16px; }
.card h2 { font-size: 16px; font-weight: 600; margin: 0 0 8px; }
.card p { color: var(--text2); font-size: 14px; margin: 0 0 12px; overflow-wrap: anywhere; }
.card textarea { width: 100%; margin-bottom: 12px; }
.err { color: var(--danger) !important; }

textarea {
  font: inherit; color: var(--text); background: var(--fill); border: 0; border-radius: 10px;
  padding: 10px 12px; resize: none; outline: none;
}

.log { display: flex; flex-direction: column; gap: 12px; }
.msg { display: flex; }
.msg.me { justify-content: flex-end; flex-direction: column; align-items: flex-end; }
.bubble { max-width: 86%; padding: 10px 14px; border-radius: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--primary-soft); color: var(--text); }
.msg.ai .bubble { background: var(--card); }
.sys { font-size: 13px; color: var(--text2); text-align: center; overflow-wrap: anywhere; }
.sys.tool { text-align: left; font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: var(--text3); }
.sys.meta, .meta { font-size: 12px; color: var(--text3); }
.sys.err { color: var(--danger); }

.perm { background: var(--card); border-radius: 12px; padding: 16px; border: 1px solid var(--primary); }
.perm.done { border-color: var(--line); opacity: .75; }
.perm-title { font-weight: 600; margin-bottom: 8px; }
.perm-input {
  margin: 0 0 12px; padding: 10px; background: var(--fill); border-radius: 8px;
  font-size: 12px; max-height: 180px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere;
}
.acts { display: flex; gap: 8px; justify-content: flex-end; }

.composer {
  position: sticky; bottom: 0; background: var(--bg); border-top: 1px solid var(--line);
  padding: 8px 12px calc(env(safe-area-inset-bottom) + 8px);
}
.composer .row { display: flex; align-items: flex-end; gap: 8px; }
.composer textarea { flex: 1; min-height: 44px; max-height: 140px; }
.send { flex: none; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; color: var(--text2); flex: none; cursor: pointer; }
.thumbs { display: flex; gap: 8px; overflow-x: auto; }
.thumbs:not(:empty) { padding-bottom: 8px; }
.thumb { padding: 0; width: 56px; height: 56px; min-height: 0; border-radius: 8px; overflow: hidden; flex: none; background: var(--fill); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
