/* ==========================================================================
   LLM Hub 前端样式表
   - 深色为主题默认，浅色通过 html[data-theme="light"] 覆盖 CSS 变量
   - 宽屏（≥1100px）三栏；窄屏抽屉式布局
   ========================================================================== */

:root {
  color-scheme: dark;
  --bg: #0e1116;
  --bg-1: #151a21;
  --bg-2: #1a212b;
  --bg-3: #222b37;
  --bg-hover: #232c38;
  --border: #2a323d;
  --border-strong: #3b4655;
  --text: #e7ebf0;
  --text-dim: #9aa5b4;
  --text-faint: #6d7887;
  --accent: #4c8dff;
  --accent-hover: #649bff;
  --accent-soft: rgba(76, 141, 255, 0.16);
  --accent-text: #ffffff;
  --ok: #3ecf8e;
  --ok-soft: rgba(62, 207, 142, 0.14);
  --warn: #f5b544;
  --warn-soft: rgba(245, 181, 68, 0.14);
  --danger: #ff6b6b;
  --danger-soft: rgba(255, 107, 107, 0.14);
  --user-bubble: #21304a;
  --assistant-bubble: #171d25;
  --code-bg: #0a0e13;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --header-h: 56px;
  --tap: 44px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Noto Sans SC", Roboto, Helvetica, Arial, sans-serif;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f5f9;
  --bg-1: #ffffff;
  --bg-2: #f7f9fc;
  --bg-3: #edf1f7;
  --bg-hover: #eef2f8;
  --border: #dde3ea;
  --border-strong: #c2ccd9;
  --text: #131a22;
  --text-dim: #56616f;
  --text-faint: #8a95a3;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: rgba(37, 99, 235, 0.1);
  --accent-text: #ffffff;
  --ok: #0f9d63;
  --ok-soft: rgba(15, 157, 99, 0.12);
  --warn: #b7791f;
  --warn-soft: rgba(183, 121, 31, 0.12);
  --danger: #d93b3b;
  --danger-soft: rgba(217, 59, 59, 0.1);
  --user-bubble: #e2ecff;
  --assistant-bubble: #ffffff;
  --code-bg: #f3f5f8;
  --shadow: 0 10px 28px rgba(15, 23, 42, 0.14);
  --shadow-sm: 0 1px 4px rgba(15, 23, 42, 0.1);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-text-size-adjust: 100%;
  overflow: hidden;
}

a {
  color: var(--accent);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

code,
pre,
.mono {
  font-family: var(--mono);
}

::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: content-box;
}

/* ------------------------------- 基础工具类 ------------------------------- */

.muted {
  color: var(--text-dim);
}
.faint {
  color: var(--text-faint);
}
.small {
  font-size: 12.5px;
}
.tiny {
  font-size: 11.5px;
}
.strong {
  font-weight: 600;
}
.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nowrap {
  white-space: nowrap;
}
.center {
  text-align: center;
}
.right {
  text-align: right;
}
.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.stack-sm {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.grow {
  flex: 1 1 auto;
  min-width: 0;
}
.hidden,
[hidden] {
  display: none !important;
}

/* --------------------------------- 按钮 ---------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  line-height: 1.2;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--accent);
}
.btn:active:not(:disabled) {
  transform: translateY(1px);
}
.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}
.btn-danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
}
.btn-ghost:hover:not(:disabled) {
  background: var(--bg-3);
  border-color: var(--border);
  color: var(--text);
}
.btn-sm {
  min-height: 30px;
  padding: 0 10px;
  font-size: 13px;
}
.btn-lg {
  min-height: 44px;
  padding: 0 20px;
  font-size: 15px;
}
.btn-block {
  width: 100%;
}
.btn-icon {
  min-width: 36px;
  padding: 0 8px;
}
.btn.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent);
}

/* --------------------------------- 表单 ---------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field > span.label,
.field > label {
  font-size: 13px;
  color: var(--text-dim);
  font-weight: 500;
}
.input,
.select,
.textarea {
  width: 100%;
  min-height: 38px;
  padding: 8px 10px;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
}
.textarea {
  resize: vertical;
  min-height: 90px;
}
.input:focus,
.select:focus,
.textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder,
.textarea::placeholder {
  color: var(--text-faint);
}
.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-dim) 50%),
    linear-gradient(135deg, var(--text-dim) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
.hint {
  font-size: 12px;
  color: var(--text-faint);
  line-height: 1.5;
}
.form-error {
  margin: 0;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
}
.checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  min-height: 30px;
  user-select: none;
}
.checkbox input {
  width: 17px;
  height: 17px;
  accent-color: var(--accent);
}
.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-size: 14px;
  min-height: 32px;
}
.switch input {
  appearance: none;
  width: 40px;
  height: 22px;
  border-radius: 11px;
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  position: relative;
  cursor: pointer;
  transition: background 0.15s;
  flex: 0 0 auto;
}
.switch input::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked {
  background: var(--accent);
  border-color: var(--accent);
}
.switch input:checked::after {
  transform: translateX(18px);
  background: #fff;
}

.slider-row {
  display: grid;
  grid-template-columns: 1fr 74px;
  gap: 8px;
  align-items: center;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 24px;
}

/* --------------------------------- 卡片 ---------------------------------- */

.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.card-title {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.card-body {
  padding: 14px;
}
.card-foot {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}
.card.is-error {
  border-color: var(--danger);
}

.panel {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.panel-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.panel-body {
  padding: 12px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  line-height: 18px;
  border: 1px solid var(--border-strong);
  background: var(--bg-2);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge-ok {
  color: var(--ok);
  border-color: var(--ok);
  background: var(--ok-soft);
}
.badge-warn {
  color: var(--warn);
  border-color: var(--warn);
  background: var(--warn-soft);
}
.badge-err {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
}
.badge-accent {
  color: var(--accent);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--bg-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
  max-width: 100%;
}
.chip button {
  border: 0;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.chip button:hover {
  color: var(--danger);
}

/* --------------------------------- 统计 ---------------------------------- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.stat {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
}
.stat-value {
  font-size: 20px;
  font-weight: 650;
  line-height: 1.3;
}
.stat-label {
  font-size: 12px;
  color: var(--text-dim);
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
table.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.table th,
table.table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}
table.table th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  background: var(--bg-2);
  position: sticky;
  top: 0;
}
table.table td.num,
table.table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty {
  padding: 26px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
}
.empty strong {
  color: var(--text);
}

.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
  font-size: 13px;
  padding: 10px 0;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex: 0 0 auto;
}
.spinner.lg {
  width: 28px;
  height: 28px;
  border-width: 3px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ------------------------------- 启动 / 登录 ------------------------------ */

.app-root {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
}

.boot-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-dim);
}

.login-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 26px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.login-title {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.5px;
}
.login-sub {
  margin: 0;
  color: var(--text-dim);
  font-size: 14px;
}
.login-foot {
  margin: 0;
  text-align: center;
}

/* --------------------------------- 顶栏 ---------------------------------- */

.app-header {
  height: var(--header-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 12px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.3px;
  white-space: nowrap;
  flex: 0 0 auto;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
}
.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
}
.main-nav::-webkit-scrollbar {
  display: none;
}
.nav-link {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
  white-space: nowrap;
}
.nav-link:hover {
  background: var(--bg-3);
  color: var(--text);
  text-decoration: none;
}
.nav-link.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.header-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
}
.header-stats {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.view-root {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* --------------------------------- Toast -------------------------------- */

.toast-host {
  position: fixed;
  z-index: 200;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
  width: min(560px, calc(100vw - 24px));
}
.toast {
  pointer-events: auto;
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  animation: toast-in 0.18s ease-out;
  word-break: break-word;
}
.toast-ok {
  border-color: var(--ok);
  background: var(--ok-soft);
  color: var(--text);
}
.toast-error {
  border-color: var(--danger);
  background: var(--danger-soft);
}
.toast-warn {
  border-color: var(--warn);
  background: var(--warn-soft);
}
@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* --------------------------------- Modal -------------------------------- */

.modal-host {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.5);
}
.modal-card {
  width: 100%;
  max-width: 780px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal-card.narrow {
  max-width: 520px;
}
.modal-card.wide {
  max-width: 1000px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.modal-title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}
.modal-body {
  padding: 14px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}
.modal-foot {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  flex-wrap: wrap;
}

/* --------------------------------- 页面 ---------------------------------- */

.page {
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
}
.page-inner {
  max-width: 1180px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.page-title {
  margin: 0;
  font-size: 19px;
  font-weight: 680;
}
.page-sub {
  margin: 2px 0 0;
  color: var(--text-dim);
  font-size: 13px;
}
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}
.grid-3 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 12px;
}
@media (max-width: 720px) {
  .split {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* --------------------------------- 列表项 -------------------------------- */

.list {
  display: flex;
  flex-direction: column;
}
.list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  min-height: var(--tap);
}
.list-item:hover {
  background: var(--bg-3);
}
.list-item.is-active {
  background: var(--accent-soft);
}

/* ================================ 对话界面 ================================ */

.chat-layout {
  position: relative;
  height: 100%;
  min-height: 0;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr) 330px;
}

.session-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-1);
  border-right: 1px solid var(--border);
}
.control-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-1);
  border-left: 1px solid var(--border);
}
.pane-head {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 0 0 auto;
}
.pane-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.pane-foot {
  flex: 0 0 auto;
  padding: 8px;
  border-top: 1px solid var(--border);
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.session-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  min-height: var(--tap);
}
.session-item:hover {
  background: var(--bg-3);
}
.session-item.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
}
.session-item .title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 550;
  min-width: 0;
}
.session-item .title .truncate {
  flex: 1 1 auto;
}
.session-item .meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  color: var(--text-faint);
}
.session-item .preview {
  font-size: 12px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.session-actions {
  display: flex;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s;
}
.session-item:hover .session-actions,
.session-item:focus-within .session-actions {
  opacity: 1;
}
.session-actions .btn {
  min-height: 26px;
  min-width: 26px;
  padding: 0 6px;
  font-size: 12px;
}

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--bg);
}
.chat-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  min-height: 48px;
}
.chat-head .chat-title {
  font-size: 15px;
  font-weight: 620;
  min-width: 0;
  flex: 1 1 auto;
}
.chat-head .chat-sub {
  font-size: 11.5px;
  color: var(--text-faint);
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.hamburger {
  display: none;
}
.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
}

/* 关键修正：定高纵向 flex 容器里的子项不能被压缩，
   否则内容会被裁掉（且滚动条不会出现）。 */
.messages > *,
.pane-body > *,
.session-list > *,
.list > *,
.ctrl-body > *,
.compare-targets > *,
.prompt-list > *,
.attach-list > * {
  flex: 0 0 auto;
}

.msg {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 100%;
  animation: msg-in 0.16s ease-out;
}
@keyframes msg-in {
  from {
    opacity: 0.4;
  }
}
.msg-user {
  align-items: flex-end;
}
.msg-assistant {
  align-items: stretch;
}
.msg-bubble {
  position: relative;
  max-width: min(760px, 100%);
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--assistant-bubble);
  overflow-wrap: break-word;
  word-break: break-word;
}
.msg-user .msg-bubble {
  background: var(--user-bubble);
  border-color: transparent;
}
.msg-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--text-faint);
  min-height: 20px;
}
.msg-actions {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  opacity: 0;
  transition: opacity 0.12s;
}
.msg:hover .msg-actions,
.msg:focus-within .msg-actions {
  opacity: 1;
}
.msg-actions .btn {
  min-height: 28px;
  font-size: 12px;
  padding: 0 8px;
}
.sys-note {
  align-self: center;
  max-width: 90%;
  text-align: center;
  font-size: 12.5px;
  color: var(--text-dim);
  background: var(--bg-2);
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  padding: 4px 14px;
}
.stream-caret::after {
  content: "▋";
  color: var(--accent);
  animation: blink 1s steps(2, start) infinite;
  margin-left: 1px;
}
@keyframes blink {
  50% {
    opacity: 0;
  }
}

.reasoning {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  font-size: 13px;
}
.reasoning > summary {
  cursor: pointer;
  padding: 6px 10px;
  color: var(--text-dim);
  font-size: 12.5px;
  list-style: none;
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.reasoning > summary::-webkit-details-marker {
  display: none;
}
.reasoning > summary::before {
  content: "▸";
}
.reasoning[open] > summary::before {
  content: "▾";
}
.reasoning .reasoning-body {
  padding: 4px 12px 10px;
  color: var(--text-dim);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}

/* 对比卡片组 */
.compare-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-1);
  padding: 10px;
}
.compare-head {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--text-dim);
}
.compare-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}
.compare-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  padding: 10px;
  min-width: 0;
}
.compare-card.is-current {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.compare-card.is-error {
  border-color: var(--danger);
}
.compare-card .cc-head {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
}
.compare-card .cc-model {
  font-weight: 650;
  color: var(--text);
  font-size: 13px;
}
.compare-card .cc-body {
  font-size: 14px;
  overflow-wrap: break-word;
  word-break: break-word;
  max-height: 460px;
  overflow-y: auto;
}
.compare-card .cc-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 11.5px;
  color: var(--text-faint);
  border-top: 1px dashed var(--border);
  padding-top: 6px;
}

/* Markdown 渲染结果 */
.md > *:first-child {
  margin-top: 0;
}
.md > *:last-child {
  margin-bottom: 0;
}
.md p {
  margin: 0 0 10px;
}
.md h1,
.md h2,
.md h3,
.md h4,
.md h5,
.md h6 {
  margin: 16px 0 8px;
  line-height: 1.35;
}
.md h1 {
  font-size: 20px;
}
.md h2 {
  font-size: 18px;
}
.md h3 {
  font-size: 16px;
}
.md h4,
.md h5,
.md h6 {
  font-size: 15px;
}
.md ul,
.md ol {
  margin: 0 0 10px;
  padding-left: 24px;
}
.md li {
  margin: 2px 0;
}
.md blockquote {
  margin: 0 0 10px;
  padding: 4px 12px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-dim);
  background: var(--bg-2);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.md hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 14px 0;
}
.md a {
  color: var(--accent);
  text-decoration: underline;
}
.md code {
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 0.9em;
}
.md del {
  color: var(--text-faint);
}
.md table {
  border-collapse: collapse;
  margin: 0 0 10px;
  font-size: 13px;
}
.md th,
.md td {
  border: 1px solid var(--border);
  padding: 5px 9px;
}

.code-block {
  margin: 0 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--code-bg);
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 3px 6px 3px 10px;
  background: var(--bg-3);
  border-bottom: 1px solid var(--border);
  font-size: 11.5px;
  color: var(--text-dim);
}
.code-head .code-lang {
  font-family: var(--mono);
  text-transform: lowercase;
}
.code-block pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 13px;
  line-height: 1.55;
}
.code-block code {
  background: none;
  border: 0;
  padding: 0;
  white-space: pre;
}

/* --------------------------------- 输入区 -------------------------------- */

.composer {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: var(--bg-1);
  padding: 8px 12px calc(10px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.template-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 2px;
  scrollbar-width: none;
}
.template-bar::-webkit-scrollbar {
  display: none;
}
.template-chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-2);
  color: var(--text-dim);
  font-size: 12.5px;
  cursor: pointer;
  min-height: 30px;
  font-family: inherit;
}
.template-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.template-chip .tpl-use,
.template-chip .tpl-del {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  cursor: pointer;
  padding: 0 2px;
  min-height: 24px;
}
.template-chip .tpl-del {
  color: var(--text-faint);
  font-size: 14px;
  line-height: 1;
}
.template-chip .tpl-del:hover {
  color: var(--danger);
}
.composer-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.composer textarea {
  flex: 1 1 auto;
  min-height: 46px;
  max-height: 40vh;
  resize: none;
  background: var(--bg-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.composer-hint {
  font-size: 11.5px;
  color: var(--text-faint);
}
.attach-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.estimate {
  font-size: 11.5px;
  color: var(--text-dim);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

/* 控制面板内部 */
.ctrl-section {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  overflow: hidden;
}
.ctrl-section > summary {
  cursor: pointer;
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 38px;
}
.ctrl-section > summary::-webkit-details-marker {
  display: none;
}
.ctrl-section > summary::before {
  content: "▸";
  margin-right: 4px;
  color: var(--text-faint);
}
.ctrl-section[open] > summary::before {
  content: "▾";
}
.ctrl-section .ctrl-body {
  padding: 2px 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.param-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.param-row .param-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.param-row .param-label code {
  color: var(--text-faint);
  font-size: 11px;
}

.compare-targets {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.compare-target {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-1);
}
.compare-target .ct-full {
  grid-column: 1 / -1;
}

/* 抽屉与遮罩（窄屏） */
.drawer-mask {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 90;
  opacity: 0;
  transition: opacity 0.2s;
}
.drawer-mask.show {
  display: block;
  opacity: 1;
}

@media (max-width: 1099px) {
  .chat-layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .hamburger {
    display: inline-flex;
  }
  .session-pane,
  .control-pane {
    position: fixed;
    top: calc(var(--header-h) + env(safe-area-inset-top));
    bottom: 0;
    width: min(88vw, 340px);
    z-index: 95;
    transition: transform 0.22s ease-out;
    box-shadow: var(--shadow);
    border-right: 1px solid var(--border);
  }
  .session-pane {
    left: 0;
    transform: translateX(-102%);
  }
  .control-pane {
    right: 0;
    left: auto;
    transform: translateX(102%);
    border-left: 1px solid var(--border);
  }
  .session-pane.open,
  .control-pane.open {
    transform: translateX(0);
  }
  .messages {
    padding: 12px;
  }
}

@media (max-width: 640px) {
  body {
    font-size: 15px;
  }
  .app-header {
    gap: 6px;
    padding: 0 8px;
  }
  .brand-name {
    display: none;
  }
  .btn {
    min-height: var(--tap);
  }
  .btn-sm {
    min-height: 34px;
  }
  .hide-sm {
    display: none;
  }
  .header-stats {
    display: none;
  }
  .msg-bubble {
    max-width: 100%;
  }
  .msg-actions {
    opacity: 1;
  }
  .session-actions {
    opacity: 1;
  }
  .chat-head {
    padding: 6px 8px;
  }
  .page {
    padding: 12px;
  }
  .modal-host {
    padding: 0;
    align-items: flex-end;
  }
  .modal-card {
    max-width: 100%;
    max-height: 92vh;
    max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  .compare-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* --------------------------------- 提示词预览 ---------------------------- */

.prompt-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.prompt-item {
  border: 1px solid var(--border);
  border-left-width: 4px;
  border-radius: var(--radius-sm);
  background: var(--bg-2);
  padding: 8px 10px;
}
.prompt-item.role-system {
  border-left-color: var(--warn);
}
.prompt-item.role-user {
  border-left-color: var(--accent);
}
.prompt-item.role-assistant {
  border-left-color: var(--ok);
}
.prompt-item .pi-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.prompt-item pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12.5px;
  max-height: 320px;
  overflow-y: auto;
  color: var(--text);
}

.kv {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  font-size: 12.5px;
}
.kv dt {
  color: var(--text-dim);
}
.kv dd {
  margin: 0;
  overflow-wrap: break-word;
}

.header-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) minmax(120px, 2fr) auto;
  gap: 6px;
  align-items: center;
}
@media (max-width: 560px) {
  .header-row {
    grid-template-columns: 1fr;
  }
}
