:root {
  --bg: #f4f6fa; --panel: #fdfeff; --side: #101c30; --side-text: #dbe4f3; --side-muted: #8fa2c2;
  --text: #101c30; --muted: #5a6780; --line: #dce3ee; --accent: #2563d9; --accent-text: #fff;
  --user: #e3ecfb; --ok: #17794a; --ok-bg: #e4f5ec; --warn: #9a4a05; --warn-bg: #fff1e3;
  --bad: #b3261e; --bad-bg: #fdeaea; --info: #2f4a7a; --info-bg: #eaf0fa;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1626; --panel: #172238; --side: #0a111e; --side-text: #dbe4f3; --side-muted: #7f92b3;
    --text: #e8eef9; --muted: #9aa9c4; --line: #2a3a58; --accent: #5b93ff; --accent-text: #0a111e;
    --user: #223457; --ok: #6fd3a0; --ok-bg: #123324; --warn: #ffb974; --warn-bg: #3a2610;
    --bad: #ff8f88; --bad-bg: #3d1614; --info: #a9c3f5; --info-bg: #1b2a47;
  }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", Roboto, Arial, sans-serif;
  -webkit-text-size-adjust: 100%; overscroll-behavior: none;
}
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.boot { height: 100%; display: grid; place-items: center; color: var(--muted); }

.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 10px; padding: 10px 16px; cursor: pointer; min-height: 44px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { border-color: var(--bad); color: var(--bad); }
.btn.link { border: 0; background: none; color: var(--accent); padding: 6px 4px; min-height: 0; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: none; width: 44px; height: 44px; border-radius: 22px; display: grid; place-items: center; cursor: pointer; color: var(--text); flex: none; }
.icon-btn:hover { background: var(--info-bg); }

/* login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px 16px; }
.login-box { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 32px 24px; text-align: center; }
.login-box h1 { font-size: 24px; margin: 12px 0 8px; }
.login-box form { display: flex; flex-direction: column; gap: 12px; }
.login-box input { border: 1px solid var(--line); background: var(--bg); border-radius: 10px; padding: 12px 14px; text-align: center; font-size: 18px; min-height: 48px; }
.login-msg { min-height: 24px; color: var(--bad); margin: 12px 0 0; }

/* layout */
.app { height: 100dvh; display: flex; overflow: hidden; }
.side { width: 280px; flex: none; background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding-top: env(safe-area-inset-top); }
.side-top { padding: 14px; }
.side-new { width: 100%; background: transparent; color: var(--side-text); border-color: #2e4366; text-align: left; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.conv { display: flex; align-items: center; border-radius: 10px; }
.conv button.open { flex: 1; min-width: 0; text-align: left; border: 0; background: none; color: var(--side-text); padding: 10px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 44px; }
.conv button.del { border: 0; background: none; color: var(--side-muted); width: 36px; height: 44px; cursor: pointer; visibility: hidden; }
.conv:hover button.del, .conv.active button.del { visibility: visible; }
.conv.active, .conv:hover { background: #1a2a45; }
.side-foot { padding: 12px 14px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid #1f3050; font-size: 14px; }
.side-foot .who { display: flex; justify-content: space-between; align-items: center; }
.side-foot .btn.link { color: #8fb6ff; }
.budget { color: var(--side-muted); font-size: 13px; margin-bottom: 6px; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 9; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 4px; padding: calc(4px + env(safe-area-inset-top)) 8px 4px; border-bottom: 1px solid var(--line); }
.title { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
#menu { display: none; }

.thread { flex: 1; overflow-y: auto; padding: 16px 16px 8px; scroll-behavior: smooth; }
.messages, .empty, .composer-row, .fine, .voicebar, .lock, .attached { max-width: 800px; margin-left: auto; margin-right: auto; }
.empty { padding-top: 10vh; text-align: center; }
.empty h2 { font-size: 28px; margin: 0 0 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 24px; }
.chip { border: 1px solid var(--line); background: var(--panel); border-radius: 999px; padding: 10px 16px; cursor: pointer; min-height: 44px; font-size: 15px; }
.chip:hover { border-color: var(--accent); }

.msg { margin: 0 0 18px; display: flex; flex-direction: column; gap: 10px; }
.msg.user { align-items: flex-end; }
.bubble { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--user); border-radius: 18px 18px 4px 18px; padding: 10px 16px; max-width: 85%; }
.msg.bot .bubble { padding: 0 2px; }
.card { max-width: 720px; }
.status { color: var(--muted); font-size: 15px; display: flex; align-items: center; gap: 8px; }
.status::before { content: ""; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); animation: pulse 1.1s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: .25; transform: scale(.8); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .status::before, .voice-dot { animation: none !important; } .thread { scroll-behavior: auto; } }
.msg-tools { display: flex; gap: 4px; }
.msg-tools button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px 8px; border-radius: 8px; font-size: 13px; }
.msg-tools button:hover { background: var(--info-bg); }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; width: 100%; }
.card-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.card-head .t { flex: 1; min-width: 0; }
.card-title { font-weight: 700; font-size: 17px; overflow-wrap: anywhere; }
.card-sub { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.badge { flex: none; font-size: 13px; font-weight: 600; border-radius: 999px; padding: 3px 10px; white-space: nowrap; }
.tone-ok { color: var(--ok); } .tone-warn { color: var(--warn); } .tone-bad { color: var(--bad); } .tone-info { color: var(--info); }
.badge.tone-ok, .note.tone-ok { background: var(--ok-bg); } .badge.tone-warn, .note.tone-warn { background: var(--warn-bg); }
.badge.tone-bad, .note.tone-bad { background: var(--bad-bg); } .badge.tone-info, .note.tone-info { background: var(--info-bg); }
.block { margin-top: 14px; }
.card-head + .block { margin-top: 0; }
.block-title { font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.rows { display: grid; grid-template-columns: minmax(72px, 104px) 1fr; gap: 6px 12px; font-size: 15px; line-height: 1.4; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 28px; margin-top: 14px; }
.cols > .block { margin-top: 0; min-width: 0; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(132px, 1fr)); gap: 8px; }
.fact { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; min-width: 0; }
.fl { font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.fv { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.list .item { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.list .item:last-child { border-bottom: 0; padding-bottom: 2px; }
.list .main { flex: 1; min-width: 0; }
.list .p { font-weight: 600; overflow-wrap: anywhere; }
.list .s { font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.list .s.tone-ok { color: var(--ok); } .list .s.tone-warn { color: var(--warn); } .list .s.tone-bad { color: var(--bad); }
.wa { flex: none; display: inline-flex; align-items: center; min-height: 40px; padding: 0 16px; border-radius: 20px; background: #1f9d55; color: #fff; font-weight: 600; font-size: 14px; text-decoration: none; }
.wa:hover { filter: brightness(1.08); }
.rows .l { color: var(--muted); }
.rows .v { overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.rows a { color: var(--accent); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; font-size: 14px; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; background: var(--bg); }
tr:last-child td { border-bottom: 0; }
td { max-width: 260px; overflow-wrap: anywhere; }
.steps { list-style: none; margin: 0; padding: 0; }
.steps li { display: grid; grid-template-columns: 18px 1fr; gap: 10px; padding: 5px 0; font-size: 15px; }
.steps .dot { width: 12px; height: 12px; border-radius: 50%; margin-top: 6px; border: 2px solid var(--line); }
.steps .done .dot { background: var(--ok); border-color: var(--ok); }
.steps .now .dot { background: var(--accent); border-color: var(--accent); }
.steps .warn .dot { background: var(--warn); border-color: var(--warn); }
.steps .sv { color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.block-foot { color: var(--muted); font-size: 13px; margin-top: 4px; overflow-wrap: anywhere; }
.note { border-radius: 10px; padding: 8px 12px; font-size: 14px; overflow-wrap: anywhere; }
pre.pre { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; font: 14px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.files, .act { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.file { display: inline-flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; text-decoration: none; color: var(--text); background: var(--bg); min-height: 44px; font-size: 15px; }
.file:hover { border-color: var(--accent); }
.file .k { font-size: 11px; font-weight: 700; color: var(--accent-text); background: var(--accent); border-radius: 5px; padding: 2px 6px; }
.act-state { font-size: 14px; color: var(--muted); }

/* composer */
.composer { padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); }
.composer-row { display: flex; align-items: flex-end; gap: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 26px; padding: 4px; }
.attached { max-width: 800px; margin: 0 auto 8px; display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--panel); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 11px; border: 0; background: rgba(16,28,48,.8); color: #fff; font-size: 12px; line-height: 22px; padding: 0; cursor: pointer; }

.composer-row:focus-within { border-color: var(--accent); }
textarea { flex: 1; border: 0; outline: 0; background: none; resize: none; padding: 10px 0; max-height: 160px; min-width: 0; }
.send { background: var(--accent); color: var(--accent-text); }
.send:hover { background: var(--accent); filter: brightness(1.08); }
.send:disabled { opacity: .4; }
.mic.on { background: var(--bad); color: #fff; }
.fine { font-size: 12px; color: var(--muted); text-align: center; margin: 6px auto 0; }
.lock { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 10px 14px; margin-bottom: 8px; font-size: 14px; }
.voicebar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; width: calc(100% - 32px); background: var(--panel); border: 1px solid var(--line); border-radius: 16px; margin-bottom: 4px; }
.voicebar span:nth-child(2) { flex: 1; }
.voice-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--bad); animation: pulse 1.1s ease-in-out infinite; }
.voice-dot.think { background: var(--warn); } .voice-dot.speak { background: var(--ok); }

@media (max-width: 820px) {
  .side { position: fixed; z-index: 10; top: 0; bottom: 0; left: 0; transform: translateX(-100%); transition: transform .2s ease; width: min(84vw, 320px); }
  .side.open { transform: none; }
  #menu { display: grid; }
  .msg.user .bubble { max-width: 92%; }
  .card { padding: 14px; }
  .cols { grid-template-columns: 1fr; }
  .facts { grid-template-columns: 1fr 1fr; }
  .empty { padding-top: 6vh; }
}
@media (min-width: 821px) { #new-chat-top { display: none; } }
