body.chat-app { flex-direction: row; background: var(--surface); }

.icon-button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  width: 34px;
  height: 34px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.icon-button:hover { background: var(--bg); color: var(--text); }
.icon-button.active { background: var(--accent-soft); color: var(--accent-dark); }
.only-mobile { display: none; }

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: var(--surface-alt);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 10px; }
.new-chat {
  margin: 4px 12px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.new-chat:hover { border-color: var(--accent); color: var(--accent-dark); }
.conversation-list { flex: 1; overflow-y: auto; padding: 0 8px 16px; }
.conversation-group { font-size: 11px; font-weight: 600; color: var(--text-muted); padding: 14px 8px 6px; letter-spacing: 0.3px; }
.conversation-item {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 8px 8px 10px;
  border-radius: 9px;
  cursor: pointer;
  font-size: 13.5px;
  color: var(--text);
}
.conversation-item:hover { background: var(--bg); }
.conversation-item.active { background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.conversation-item .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversation-item .delete {
  visibility: hidden;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 6px;
}
.conversation-item:hover .delete { visibility: visible; }
.conversation-item .delete:hover { color: var(--red); background: var(--red-soft); }
.conversation-empty { font-size: 12.5px; color: var(--text-muted); padding: 16px 10px; }

/* ── Main ────────────────────────────────────────────────────── */
.chat-main { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
  flex-shrink: 0;
}
.topbar-title { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; }
.topbar-title span { cursor: text; display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.topbar-title input { width: 100%; font-size: 15px; font-weight: 600; padding: 4px 8px; border-radius: 8px; border: 1.5px solid var(--accent); outline: none; }

.thread { flex: 1; overflow-y: auto; min-height: 0; }
.thread-inner { max-width: 820px; margin: 0 auto; padding: 24px 20px 32px; display: flex; flex-direction: column; gap: 22px; }

.empty-state { margin: 14vh auto 0; text-align: center; color: var(--text-dim); }
.empty-state h1 { font-size: 26px; color: var(--text); letter-spacing: -0.5px; margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

/* Messages */
.msg { display: flex; gap: 12px; }
.msg-user { justify-content: flex-end; }
.msg-user .msg-content { align-items: flex-end; max-width: 78%; }
.msg-content { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.msg-assistant .msg-content { flex: 1; }
.bubble {
  background: var(--accent-soft);
  color: var(--text);
  padding: 10px 15px;
  border-radius: 18px 18px 4px 18px;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.bubble.unanswered { border: 1px dashed #F59E0B; }
.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8B5CF6);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}
.answer { font-size: 15px; line-height: 1.7; word-break: break-word; }
.answer.plain { white-space: pre-wrap; font-family: var(--mono); font-size: 13.5px; }
.answer .cursor { margin-left: 2px; }
.answer.waiting::after { content: '思考中…'; color: var(--text-muted); font-size: 14px; }
.msg-error { color: var(--red); font-size: 13.5px; display: flex; align-items: center; gap: 10px; }
.reasoning-block summary { cursor: pointer; font-size: 12.5px; color: var(--text-dim); }
.reasoning-block pre { white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; color: var(--text-dim); margin-top: 6px; }

.msg-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 11.5px; color: var(--text-muted); font-family: var(--mono); }
.msg-meta.live { color: var(--text-dim); }
.live-badge { display: inline-flex; align-items: center; gap: 5px; }
.live-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); animation: sf-blink 1s step-end infinite; }
#liveStats { font-variant-numeric: tabular-nums; }
.msg-meta .badge { font-family: inherit; font-size: 11px; padding: 2px 7px; }
.msg-actions { display: flex; gap: 2px; opacity: 0; transition: opacity 0.15s; }
.msg:hover .msg-actions, .msg-actions.pinned { opacity: 1; }
.msg-actions button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 7px;
  cursor: pointer;
}
.msg-actions button:hover { background: var(--bg); color: var(--text); }
.msg-actions button.on { color: var(--accent-dark); }

.edit-box { width: min(620px, 100%); display: flex; flex-direction: column; gap: 8px; }
.edit-box textarea {
  width: 100%;
  min-height: 80px;
  font-size: 15px;
  line-height: 1.6;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1.5px solid var(--accent);
  outline: none;
  resize: vertical;
}
.edit-box .row { display: flex; gap: 6px; justify-content: flex-end; }

/* ── Composer ────────────────────────────────────────────────── */
.composer { padding: 0 20px 16px; flex-shrink: 0; }
.composer-box {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  border: 1.5px solid var(--border);
  border-radius: 18px;
  padding: 8px 8px 8px 16px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.composer-box:focus-within { border-color: #A5B0FB; box-shadow: 0 0 0 3px var(--accent-soft); }
.composer-box.over { border-color: var(--red); }
.composer-box textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  font-size: 15px;
  line-height: 1.55;
  padding: 7px 0;
  max-height: 220px;
  background: transparent;
  color: var(--text);
}
.send-button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}
.send-button:hover:not(:disabled) { background: var(--accent-dark); }
.send-button:disabled { background: var(--border); color: var(--text-muted); cursor: not-allowed; }
.send-button.stop { background: var(--text); }
.composer-meta {
  max-width: 820px;
  margin: 8px auto 0;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  font-size: 11.5px;
  color: var(--text-muted);
}
.meter { display: flex; align-items: center; gap: 8px; min-width: 0; }
.meter-bar { width: 120px; height: 5px; border-radius: 99px; background: var(--bg); display: flex; overflow: hidden; flex-shrink: 0; }
.meter-prompt { background: var(--accent); width: 0; }
.meter-output { background: #34D399; width: 0; }
.meter-text { font-family: var(--mono); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.meter.over .meter-text { color: var(--red); }
.meter.dropped .meter-text { color: var(--amber); }

/* ── Settings drawer ─────────────────────────────────────────── */
.settings {
  width: 320px;
  flex-shrink: 0;
  border-left: 1px solid var(--border);
  background: var(--surface-alt);
  overflow-y: auto;
  padding: 0 16px 20px;
}
body.settings-closed .settings { display: none; }
.settings-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 0 6px; position: sticky; top: 0; background: var(--surface-alt); z-index: 1; }
.settings-group { padding: 12px 0; border-bottom: 1px solid var(--border); }
.settings-group h3 { font-size: 12px; font-weight: 700; color: var(--text-dim); letter-spacing: 0.4px; text-transform: uppercase; margin-bottom: 10px; }
.settings-group h3 small { text-transform: none; font-weight: 500; color: var(--text-muted); }
.settings-group textarea {
  width: 100%;
  font-size: 13.5px;
  line-height: 1.5;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  resize: vertical;
  outline: none;
  background: var(--surface);
}
.settings-group textarea:focus { border-color: var(--accent); }
.param-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.param-grid .field input, .param-grid .field select { width: 100%; min-width: 0; }
.hint { font-size: 11.5px; color: var(--text-muted); margin-top: 8px; line-height: 1.5; }
.hint.warn { color: var(--amber); }
.settings-actions { padding-top: 14px; }

/* ── Prompt viewer ───────────────────────────────────────────── */
.overlay { position: fixed; inset: 0; background: rgba(17, 24, 39, 0.35); display: flex; align-items: center; justify-content: center; padding: 32px; z-index: 50; }
.overlay-panel { width: min(900px, 100%); max-height: 100%; }
.prompt-view { padding: 16px 18px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-family: var(--mono); font-size: 13px; line-height: 1.6; }
.prompt-view .tpl-marker { color: var(--accent-dark); background: var(--accent-soft); border-radius: 4px; padding: 0 2px; }

@media (max-width: 1100px) {
  .settings { position: fixed; right: 0; top: 0; bottom: 0; z-index: 40; box-shadow: var(--shadow-md); }
}
@media (max-width: 860px) {
  .only-mobile { display: inline-flex; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 45; box-shadow: var(--shadow-md); transform: translateX(-100%); transition: transform 0.2s; }
  body.sidebar-open .sidebar { transform: none; }
  .composer-hint { display: none; }
  #modelBar .model-facts { display: none; }
}
.reasoning-block.live summary { display: flex; align-items: center; gap: 6px; }
.reasoning-block.live pre { max-height: 220px; overflow: auto; }
