:root {
  --bg: #f7f5f0;
  --panel: #ffffff;
  --ink: #23201b;
  --ink-soft: #6b6357;
  --line: #e4ded2;
  --accent: #8a6d3b;
  --accent-soft: #f1e8d8;
  --ok: #2f855a;
  --warn: #b7791f;
  --err: #c53030;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.6 "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", system-ui, sans-serif;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: center; gap: 10px; }

.logo {
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 17px;
}

.title { font-size: 15px; font-weight: 600; }
.subtitle { font-size: 12px; color: var(--ink-soft); }
.topbar-right { display: flex; align-items: center; gap: 10px; }

.health { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-soft); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); display: inline-block; }
.health.ok .dot { background: var(--ok); }
.health.bad .dot { background: var(--err); }

.layout { flex: 1; display: flex; min-height: 0; }

.sidebar {
  width: 288px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  font-size: 12px; color: var(--ink-soft);
}

.session-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }

.session-list li {
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; margin-bottom: 4px;
}
.session-list li:hover { background: #faf7f1; }
.session-list li.active { background: var(--accent-soft); border-color: #e2d3b6; }
.session-list .row1 { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.session-list .sid { font-family: var(--mono); font-size: 12px; color: var(--ink-soft); }
.session-list .ttl { font-size: 13px; margin-top: 2px; word-break: break-all; }
.session-list .row2 { font-size: 11px; color: var(--ink-soft); margin-top: 2px; display: flex; gap: 8px; }

.sidebar-foot { border-top: 1px solid var(--line); padding: 8px 12px; font-size: 11px; color: var(--ink-soft); }

.conversation { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }

.conv-head {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.conv-id-wrap { display: flex; align-items: center; gap: 6px; }
.conv-id-wrap .label { font-size: 11px; color: var(--ink-soft); }
.conv-id { font-family: var(--mono); font-size: 12px; background: #f6f2ea; padding: 2px 6px; border-radius: 4px; }
.conv-meta { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.conv-actions { margin-left: auto; display: flex; gap: 6px; }

.stream { flex: 1; overflow-y: auto; padding: 18px 20px 6px; min-height: 0; }

.turn { margin-bottom: 22px; }

.msg { display: flex; margin-bottom: 8px; }
.msg.user { justify-content: flex-end; }
.bubble {
  max-width: 78%; padding: 9px 13px; border-radius: 12px; white-space: pre-wrap; word-break: break-word;
}
.msg.user .bubble { background: var(--accent); color: #fff; border-bottom-right-radius: 3px; }
.msg.assistant .bubble { background: var(--panel); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.msg.assistant .bubble.streaming::after {
  content: "▍"; color: var(--accent); animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

.process { margin: 4px 0 0 2px; font-size: 12px; color: var(--ink-soft); }
.process details { margin-bottom: 4px; }
.process summary { cursor: pointer; }
.process .line { padding: 2px 0 2px 10px; border-left: 2px solid var(--line); white-space: pre-wrap; }
.process .thought { color: #7a736a; }

.turn-meta { font-size: 11px; color: var(--ink-soft); margin-top: 6px; }

.approval {
  margin-top: 8px; padding: 10px 12px; border: 1px solid #e6c98a; background: #fffaf0; border-radius: 10px;
}
.approval .desc { font-size: 13px; margin-bottom: 8px; }
.approval .opts { display: flex; gap: 8px; flex-wrap: wrap; }
.approval.settled { opacity: .6; }

.badge {
  display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px;
  background: #eee9df; color: var(--ink-soft); border: 1px solid var(--line);
}
.badge.running { background: #e6f0ff; color: #2b5fa8; border-color: #c9dcf7; }
.badge.completed { background: #e7f6ec; color: var(--ok); border-color: #c6e7d2; }
.badge.closed { background: #ececec; color: #666; }
.badge.cancelled { background: #fff4e5; color: var(--warn); border-color: #f0d8b0; }
.badge.failed { background: #fdecea; color: var(--err); border-color: #f5c6c2; }
.dim { color: var(--ink-soft); }

.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 16px 14px; }
.mode { display: flex; gap: 14px; font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; }
.mode label { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; }
.mode .profile-pick { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; }
.mode .profile-pick[hidden] { display: none !important; }
.mode .profile-pick select {
  font: inherit; font-size: 12px; padding: 2px 6px; border: 1px solid var(--line);
  border-radius: 6px; background: var(--panel); color: var(--ink); max-width: 200px;
}
.quota { font-size: 12px; color: var(--ink-soft); }
.quota.warn { color: #b3261e; font-weight: 600; }
.hint.warn { color: #b3261e; font-weight: 600; }
textarea {
  width: 100%; resize: vertical; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--line); font: inherit; background: #fffdf9;
}
textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.composer-actions { display: flex; align-items: center; justify-content: space-between; margin-top: 8px; }
.hint { font-size: 12px; color: var(--ink-soft); }

.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 6px 12px; border-radius: 8px; cursor: pointer; font: inherit;
}
.btn:hover { background: #faf7f1; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #7a5f33; }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.tiny { padding: 1px 8px; font-size: 11px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.empty { text-align: center; color: var(--ink-soft); margin-top: 12vh; }
.empty h3 { color: var(--ink); }

/* ---------- 登录页 ---------- */
.auth-body { display: grid; place-items: center; background: var(--bg); }
.auth-card {
  width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 22px 22px 18px; box-shadow: 0 8px 30px rgba(60, 50, 30, .08);
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-soft); }
.auth-form input {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fffdf9;
}
.auth-note { font-size: 12px; color: var(--warn); background: #fff8ec; border: 1px solid #f0dcb4; padding: 8px 10px; border-radius: 8px; }
.auth-msg { font-size: 12px; min-height: 16px; color: var(--err); }
.auth-msg.ok { color: var(--ok); }
.auth-msg.info { color: var(--ink-soft); }

/* ---------- 弹窗 ---------- */
/* 注意：.modal 设了 display，必须显式补 [hidden] 规则，否则 hidden 属性失效（弹窗关不掉） */
.modal[hidden] { display: none !important; }
.modal { position: fixed; inset: 0; background: rgba(35, 32, 27, .35); display: grid; place-items: center; z-index: 50; }
.modal-card {
  width: 380px; max-width: 92vw; background: var(--panel); border-radius: 12px; padding: 18px 20px;
  border: 1px solid var(--line); box-shadow: 0 12px 40px rgba(40, 30, 10, .18);
  display: flex; flex-direction: column; gap: 10px;
}
.modal-card.wide { width: 720px; max-height: 84vh; overflow: auto; }
.modal-card h3 { margin: 0 0 2px; }
.modal-card input {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fffdf9;
}
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }
.modal .msg { font-size: 12px; color: var(--err); min-height: 14px; }
.modal .msg.ok { color: var(--ok); }
.modal .msg.dim { color: var(--ink-soft); }

/* ---------- 后台 ---------- */
.admin-body { background: var(--bg); }
.tabs { display: flex; gap: 6px; padding: 10px 18px 0; background: var(--panel); border-bottom: 1px solid var(--line); }
.tab {
  border: 1px solid var(--line); border-bottom: none; background: #faf7f1; color: var(--ink-soft);
  padding: 7px 14px; border-radius: 8px 8px 0 0; cursor: pointer; font: inherit;
}
.tab.active { background: var(--panel); color: var(--ink); font-weight: 600; }
.admin-main { padding: 16px 18px 40px; overflow-y: auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; }
.panel h2 { margin: 0 0 12px; font-size: 16px; }
.panel h3 { margin: 18px 0 8px; font-size: 14px; }
.cards { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.card { border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px; min-width: 120px; background: #fffdf9; }
.card .k { font-size: 11px; color: var(--ink-soft); }
.card .v { font-size: 17px; font-weight: 600; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: left; vertical-align: middle; }
.tbl thead th { color: var(--ink-soft); font-weight: 500; background: #faf7f1; }
.tbl.mini { width: auto; margin-top: 8px; }
.tbl .ops { white-space: nowrap; }
.btn.tiny.danger { color: var(--err); border-color: #f0c9c5; }
.inline { width: 150px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; font: inherit; }
.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.form-row input, .form-row select {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fffdf9;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; margin-bottom: 10px; }
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--ink-soft); }
.form-grid input, .form-grid select {
  padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font: inherit; background: #fffdf9;
}
.chk { flex-direction: row !important; align-items: center; gap: 6px !important; font-size: 13px; color: var(--ink) !important; }
.msg { font-size: 12px; min-height: 16px; color: var(--ink-soft); margin-bottom: 6px; }
.msg.ok { color: var(--ok); }
.msg.error { color: var(--err); }
.msg.dim { color: var(--ink-soft); }
.hint { font-size: 12px; color: var(--ink-soft); margin-bottom: 12px; line-height: 1.7; }
.usage-body { font-size: 13px; }
.badge.running { }
