:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --ink: #1e2430;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #4f46e5;
  --accent-2: #6d5ef0;
  --accent-soft: #eef1ff;
  --ok: #10b981;
  --warn: #f59e0b;
  --err: #ef4444;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px -12px rgba(16, 24, 40, .16);
}

* { box-sizing: border-box; }

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

body {
  background: var(--bg);
  color: var(--ink);
  font-family: "PingFang SC", "Microsoft YaHei UI", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: .2px; }
p { margin: 0; }
button { font: inherit; }
ul { margin: 0; padding: 0; list-style: none; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------------- 布局 ---------------- */
.layout {
  display: grid;
  grid-template-columns: 312px minmax(0, 1fr);
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 16px 16px;
  background: #fbfcfe;
  border-right: 1px solid var(--line);
  overflow: hidden;
}

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

.logo {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  box-shadow: 0 6px 16px -6px rgba(79, 70, 229, .7);
}

.brand h1 { font-size: 17px; }
.brand-text p { margin-top: 1px; }

.status-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
}

.status-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; }

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warn);
  flex: none;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, .15);
}
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(16, 185, 129, .15); }
.dot.err { background: var(--err); box-shadow: 0 0 0 3px rgba(239, 68, 68, .15); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  font-size: 12px;
  color: #4b5563;
  background: #f3f4f6;
  border-radius: 999px;
  padding: 2px 9px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .4px;
  padding: 0 2px;
}

.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 8px;
}
.icon-btn:hover { background: #eef0f4; color: var(--ink); }

.doc-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 2px;
}

.doc-item {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid transparent;
}
.doc-item:hover { background: #f2f4f8; border-color: var(--line); }

.doc-icon { font-size: 14px; line-height: 1.5; flex: none; opacity: .75; }
.doc-meta { min-width: 0; }
.doc-name {
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doc-sub { font-size: 11.5px; color: var(--muted); }
.empty-doc { padding: 6px 10px; }

.sidebar-foot { display: flex; gap: 8px; }
.sidebar-foot .btn { flex: 1; }

.progress { display: flex; flex-direction: column; gap: 6px; }
.progress-bar {
  height: 6px;
  border-radius: 999px;
  background: #e8eaf0;
  overflow: hidden;
}
.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width .25s ease;
}

/* ---------------- 主区域 ---------------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 26px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .82);
  backdrop-filter: blur(8px);
}
.topbar h2 { font-size: 16px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 26px 26px 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  scroll-behavior: smooth;
}

.empty {
  margin: auto;
  max-width: 520px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
}
.empty-icon { font-size: 40px; }
.empty h3 { font-size: 20px; }
.empty p { font-size: 14px; }

.suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-top: 8px;
}
.suggestion {
  border: 1px solid var(--line);
  background: var(--panel);
  color: #4b5563;
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s ease;
}
.suggestion:hover {
  border-color: #c7cdf7;
  background: var(--accent-soft);
  color: var(--accent);
}

/* 消息 */
.msg { display: flex; gap: 12px; max-width: 860px; width: 100%; margin: 0 auto; }
.msg.user { justify-content: flex-end; }

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 10px;
  flex: none;
  display: grid;
  place-items: center;
  font-size: 14px;
  background: #eef1ff;
  color: var(--accent);
  font-weight: 700;
}
.msg.user .avatar { background: #e6f7f1; color: #059669; }

.bubble {
  padding: 12px 16px;
  border-radius: 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  max-width: min(720px, 100%);
  min-width: 0;
  word-break: break-word;
}
.msg.user .bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 10px 24px -14px rgba(79, 70, 229, .9);
}

.bubble p + p { margin-top: 9px; }
.bubble code {
  background: #f1f3f8;
  border-radius: 5px;
  padding: 1px 5px;
  font-size: 13px;
  font-family: "Cascadia Code", Consolas, "Courier New", monospace;
}
.bubble pre {
  background: #1f2333;
  color: #e6e8f0;
  padding: 12px 14px;
  border-radius: 10px;
  overflow-x: auto;
  margin: 10px 0 0;
  font-size: 13px;
}
.bubble pre code { background: none; padding: 0; color: inherit; }
.bubble ul.md, .bubble ol.md { padding-left: 20px; margin: 8px 0 0; list-style: revert; }
.bubble li { margin: 3px 0; }
.bubble strong { font-weight: 650; }

.cite {
  display: inline-block;
  font-size: 11px;
  line-height: 1.4;
  padding: 0 5px;
  margin: 0 1px;
  border-radius: 6px;
  background: #eef1ff;
  color: var(--accent);
  vertical-align: 1px;
  cursor: pointer;
  font-weight: 600;
}
.cite:hover { background: #dfe4ff; }

/* 来源 */
.sources { margin: 12px 0 0; border-top: 1px dashed var(--line); padding-top: 10px; }
.sources-title {
  font-size: 12px;
  color: var(--muted);
  letter-spacing: .4px;
  margin-bottom: 7px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.source {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 6px;
  background: #fcfcfe;
  cursor: pointer;
}
.source:hover { border-color: #cfd5f5; }
.source-head { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.source-idx {
  width: 18px;
  height: 18px;
  flex: none;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  display: grid;
  place-items: center;
  font-weight: 600;
}
.source-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-score { margin-left: auto; color: var(--muted); font-size: 11px; flex: none; }
.source-snippet {
  font-size: 12.5px;
  color: var(--muted);
  margin-top: 4px;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.source.open .source-snippet { -webkit-line-clamp: unset; display: block; white-space: pre-wrap; color: #4b5563; }

.ref-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px dashed #e5e7eb;
  font-size: 12px;
  color: #6b7280;
}
.ref-line::before {
  content: "来源";
  color: #9aa3b2;
  letter-spacing: .02em;
}
.ref-chip {
  padding: 1px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4f46e5;
  font-size: 12px;
  white-space: nowrap;
}

.typing { display: inline-flex; gap: 4px; vertical-align: middle; }
.typing i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #9aa3b2;
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) { animation-delay: .2s; }
.typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .25; } 40% { opacity: 1; } }

.error-box {
  color: #b91c1c;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 13.5px;
}

/* 输入区 */
.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 14px 26px 20px;
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(8px);
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 180px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  font: inherit;
  color: inherit;
  line-height: 1.5;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.composer textarea:focus {
  border-color: #b9bff2;
  box-shadow: 0 0 0 4px rgba(79, 70, 229, .09);
}

/* 按钮 */
.btn {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13.5px;
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn:hover { background: #f4f5f8; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-color: transparent;
  box-shadow: 0 8px 18px -10px rgba(79, 70, 229, .9);
  padding: 10px 20px;
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { background: #fff; }
.btn.small { padding: 6px 11px; font-size: 12.5px; }

/* 弹窗 */
.dialog {
  border: none;
  border-radius: 16px;
  padding: 0;
  width: min(560px, 92vw);
  box-shadow: 0 30px 70px -20px rgba(16, 24, 40, .45);
  background: var(--panel);
  color: var(--ink);
}
.dialog::backdrop { background: rgba(16, 24, 40, .42); backdrop-filter: blur(2px); }
.dialog-body { padding: 22px 24px; display: flex; flex-direction: column; gap: 12px; }
.dialog-body h3 { font-size: 17px; }

.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.field input, .field select {
  font: inherit;
  font-size: 13.5px;
  color: var(--ink);
  padding: 8px 11px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fbfcfe;
  outline: none;
}
.field input:focus, .field select:focus {
  border-color: #b9bff2;
  box-shadow: 0 0 0 3px rgba(79, 70, 229, .09);
  background: #fff;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.dialog-actions { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

.test-result {
  border-radius: 10px;
  padding: 9px 12px;
  font-size: 12.5px;
  background: #f6f7fb;
  border: 1px solid var(--line);
  white-space: pre-wrap;
}
.test-result.ok { background: #ecfdf5; border-color: #a7f3d0; color: #047857; }
.test-result.err { background: #fef2f2; border-color: #fecaca; color: #b91c1c; }

/* 模型实例 */
.inst-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: #f8f9fd;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 13px;
}
.inst-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.inst-title { font-size: 13px; font-weight: 600; color: #1f2937; }
.inst-list { display: flex; flex-direction: column; gap: 6px; }
.inst-empty { margin: 2px 0; }
.inst-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
}
.inst-item.active { border-color: #c7d2fe; background: #f6f7ff; }
.inst-main { min-width: 0; flex: 1; display: flex; flex-direction: column; gap: 2px; }
.inst-name-row { display: flex; align-items: center; gap: 6px; min-width: 0; }
.inst-name {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inst-cur {
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft, #eef2ff);
  border-radius: 999px;
  padding: 1px 7px;
  flex: none;
}
.inst-nokey {
  font-size: 11px;
  color: #b45309;
  background: #fef3c7;
  border-radius: 999px;
  padding: 1px 7px;
  flex: none;
}
.inst-meta {
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.inst-ops { display: flex; gap: 4px; flex: none; }
.btn.tiny { padding: 4px 8px; font-size: 11.5px; border-radius: 7px; }
.btn.tiny.danger { background: #fff; border-color: #fecaca; color: #b91c1c; }
.btn.tiny.danger:hover { background: #fef2f2; }
.inst-rename {
  font-size: 13px;
  font-weight: 600;
  color: #111827;
  border: 1px solid #c7d2fe;
  border-radius: 7px;
  padding: 2px 7px;
  width: 100%;
  max-width: 220px;
  font-family: inherit;
  outline: none;
}
.inst-now {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  padding-top: 7px;
  border-top: 1px dashed var(--line);
  font-size: 12px;
  color: #374151;
  min-width: 0;
}
.inst-now-k {
  flex: none;
  font-size: 11px;
  color: var(--accent);
  background: var(--accent-soft, #eef2ff);
  border-radius: 999px;
  padding: 1px 7px;
}
#instNowName {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* toast */
.toast-wrap {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 99;
}
.toast {
  background: #1f2430;
  color: #fff;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: 0 12px 30px -12px rgba(0, 0, 0, .5);
  animation: toast-in .18s ease;
}
.toast.err { background: #b91c1c; }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* 滚动条 */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #d6dae3; border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: #c2c8d4; }
::-webkit-scrollbar-track { background: transparent; }

/* 窄屏 */
@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar {
    height: auto;
    max-height: 42vh;
    border-right: none;
    border-bottom: 1px solid var(--line);
  }
  .doc-list { max-height: 19vh; }
  .messages { padding: 18px 14px 6px; }
  .composer { padding: 10px 14px 14px; }
  .topbar { padding: 12px 14px; }
}

/* ---------- admin ---------- */
a.btn { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; }
.admin-wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 24px 60px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.admin-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.admin-top h1 { font-size: 20px; }
.admin-top-actions { display: flex; gap: 8px; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.panel-head h2 { font-size: 15px; }
.stats-panel { flex-direction: row; flex-wrap: wrap; gap: 10px; padding: 16px 18px; }
.stat { display: flex; flex-direction: column; gap: 2px; min-width: 90px; }
.stat-n { font-size: 20px; font-weight: 600; letter-spacing: -.01em; }
.stat-l { font-size: 12px; color: var(--muted); }
.stat-wide { flex: 1; align-items: flex-end; text-align: right; }
.stat-wide .stat-n { font-size: 13px; font-weight: 500; color: #374151; }
.dropzone {
  border: 1.5px dashed #cfd5e3;
  border-radius: 12px;
  padding: 28px 18px;
  text-align: center;
  cursor: pointer;
  transition: all .15s ease;
  background: #fbfcfe;
}
.dropzone:hover, .dropzone.hot { border-color: var(--accent); background: var(--accent-soft); }
.dropzone-inner p { margin: 4px 0; font-size: 14px; }
.dropzone-icon { font-size: 22px; }
.link-btn {
  border: none;
  background: none;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 0 2px;
}
.link-btn:hover { text-decoration: underline; }
.upload-result { font-size: 13px; padding: 10px 12px; border-radius: 10px; white-space: pre-line; }
.upload-result.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.upload-result.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.table-wrap { overflow-x: auto; }
.doc-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.doc-table th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 12px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}
.doc-table td { padding: 10px; border-bottom: 1px solid #f1f3f7; vertical-align: middle; }
.doc-table tr:last-child td { border-bottom: none; }
.col-num { text-align: right; white-space: nowrap; }
.col-state { white-space: nowrap; }
.col-act { text-align: right; white-space: nowrap; width: 70px; }
.col-check { width: 34px; padding-left: 4px !important; }
.col-check input { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; }
.doc-table tr.picked td { background: #f5f6ff; }

.panel-tools { display: flex; gap: 8px; align-items: center; }
.bulk-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 4px 0 10px;
  padding: 8px 12px;
  border-radius: 10px;
  background: var(--accent-soft);
  border: 1px solid #e0e5ff;
  font-size: 13px;
}
.bulk-bar[hidden] { display: none; }
.bulk-info { color: #374151; margin-right: auto; }
.bulk-info b { color: var(--accent); font-weight: 700; }
.cell-file { display: flex; align-items: center; gap: 8px; min-width: 0; }
.cell-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 340px; }
.doc-icon { flex: none; }
.badge { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; }
.badge.ok { background: #ecfdf5; color: #047857; }
.badge.warn { background: #fffbeb; color: #b45309; }
.danger-link { border: none; background: none; color: #dc2626; font-size: 13px; cursor: pointer; padding: 2px 4px; }
.danger-link:hover { text-decoration: underline; }
.table-hint { margin-top: -4px; }
.sidebar-tip {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
  border: 1px dashed #e2e6ef;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fbfcfe;
}
@media (max-width: 860px) {
  .admin-wrap { padding: 16px 12px 40px; }
  .stats-panel { gap: 8px; }
  .stat { min-width: 70px; }
}

/* ---------- confirm dialog ---------- */
.confirm-mask {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, .38);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}
.confirm-box {
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 24px 60px -18px rgba(16, 24, 40, .45);
  padding: 20px;
  width: min(400px, 100%);
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.confirm-text { font-size: 14px; line-height: 1.6; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn.danger { background: #dc2626; border-color: #dc2626; color: #fff; }
.btn.danger:hover { filter: brightness(1.06); }

/* ---------- markdown extras ---------- */
.bubble hr { border: none; border-top: 1px solid var(--line); margin: 14px 0; }
.bubble blockquote {
  margin: 10px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--accent);
  background: var(--accent-soft);
  border-radius: 0 8px 8px 0;
  color: #374151;
}
.bubble .md-h { margin: 14px 0 6px; }
.md-table-wrap { overflow-x: auto; margin: 10px 0; }
.md-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.md-table th, .md-table td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }
.md-table th { background: #f7f8fb; font-weight: 600; }
.md-table tr:nth-child(even) td { background: #fbfcfe; }

/* ---------- 回答里的分块卡片 / 键值行 / 例句高亮 ---------- */

.msg.assistant .bubble { max-width: min(840px, 100%); }
.msg.assistant .bubble .sec + .sec { margin-top: 12px; }

.bubble .sec {
  margin: 10px 0;
  padding: 10px 12px 11px;
  border: 1px solid #eef1f7;
  border-radius: 12px;
  background: linear-gradient(180deg, #fcfcff, #fafbff);
}
.bubble .sec:first-child { margin-top: 2px; }
.bubble .sec-title {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13.5px;
  font-weight: 700;
  color: #1f2937;
  margin-bottom: 7px;
}
.bubble .sec-title::before {
  content: "";
  width: 3px;
  height: 14px;
  border-radius: 2px;
  background: linear-gradient(180deg, var(--accent), var(--accent-2));
}
.bubble .sec-title.tl::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.bubble .sec > p:first-of-type { margin-top: 0; }
.bubble .sec ul.md, .bubble .sec ol.md { margin-top: 4px; }
.bubble .sec p { margin: 6px 0; }

.bubble .kv {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin: 5px 0;
  line-height: 1.7;
}
.bubble .kv-k {
  flex: none;
  padding: 0 8px;
  border-radius: 6px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 12.5px;
  white-space: nowrap;
}
.bubble .kv-v { min-width: 0; }

.bubble li.eg {
  margin: 5px 0;
  padding: 4px 9px;
  border-left: 3px solid #c7d2fe;
  border-radius: 0 8px 8px 0;
  background: #f8f9ff;
}
.bubble li.tl {
  list-style: none;
  position: relative;
  padding-left: 14px;
  margin: 6px 0;
}
.bubble li.tl::before {
  content: "";
  position: absolute;
  left: 0;
  top: .72em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.bubble li.tl.eg {
  padding: 4px 9px 4px 18px;
  background: #f8f9ff;
  border-left: 3px solid #c7d2fe;
  border-radius: 0 8px 8px 0;
}
.bubble li.tl.eg::before { left: 6px; }

/* --------------------------- 语音输入 --------------------------- */
.mic-btn {
  position: relative;
  flex: none;
  width: 46px;
  height: 46px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: #6b7280;
  cursor: pointer;
  transition: color .15s, border-color .15s, background .15s, box-shadow .15s;
}
.mic-btn:hover {
  color: var(--accent);
  border-color: #c7d2fe;
  background: #f6f7ff;
}
.mic-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.mic-btn.recording {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, #ef4444, #f97316);
  box-shadow: 0 6px 18px rgba(239, 68, 68, .35);
}
.mic-btn.recording .mic-ring {
  position: absolute;
  inset: -4px;
  border-radius: 16px;
  border: 2px solid rgba(239, 68, 68, .45);
  animation: micPulse 1.4s ease-out infinite;
}
@keyframes micPulse {
  0%   { transform: scale(.94); opacity: .9; }
  70%  { transform: scale(1.12); opacity: 0; }
  100% { transform: scale(1.12); opacity: 0; }
}
.mic-btn.unsupported {
  opacity: .45;
  cursor: not-allowed;
}
.mic-btn.unsupported:hover {
  color: #6b7280;
  border-color: var(--line);
  background: #fff;
}

/* ------------------------- 语音识别配置块 ------------------------- */
.asr-block {
  margin-top: 4px;
  padding: 12px 14px 2px;
  border: 1px dashed #dfe3ee;
  border-radius: 10px;
  background: #fbfcff;
}
.asr-head {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.asr-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
}
.mic-btn.busy {
  opacity: .6;
  cursor: progress;
}
.mic-btn.busy::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(79, 70, 229, .25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: micSpin .8s linear infinite;
}
@keyframes micSpin {
  to { transform: rotate(360deg); }
}

/* --------------------------- 记忆卡片（单词拆解小图） --------------------------- */
.word-card {
  margin: 16px 0 4px;
  padding: 14px 16px 12px;
  border: 1px dashed #c7d2fe;
  border-radius: 16px;
  background: linear-gradient(160deg, #f8f9ff 0%, #eef2ff 55%, #fdf2f8 100%);
}
.wc-head {
  display: flex;
  align-items: center;
  gap: 12px;
}
.wc-scene {
  font-size: 34px;
  line-height: 1;
  filter: drop-shadow(0 3px 6px rgba(79, 70, 229, .18));
}
.wc-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.wc-title b {
  font-size: 16px;
  color: #312e81;
  letter-spacing: .2px;
}
.wc-title span {
  font-size: 12.5px;
  color: #6366f1;
}
.wc-parts {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 12px 0 10px;
}
.wc-part {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  background: #fff;
  border: 1px solid #e0e7ff;
  border-radius: 10px;
  box-shadow: 0 2px 6px rgba(79, 70, 229, .06);
}
.wc-emo {
  font-style: normal;
  font-size: 15px;
}
.wc-part b {
  font-size: 13px;
  color: #4338ca;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.wc-part em {
  font-style: normal;
  font-size: 11.5px;
  color: #8b93a7;
}
.wc-plus {
  color: #a5b4fc;
  font-weight: 700;
  font-size: 12px;
}
.wc-caption {
  margin-top: 2px;
  padding-top: 8px;
  border-top: 1px dashed #dbe2ff;
  font-size: 12.5px;
  color: #5b6478;
}
.wc-loading {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  color: #8b93a7;
}
.wc-spark {
  animation: wcTwinkle 1.1s ease-in-out infinite;
}
@keyframes wcTwinkle {
  0%, 100% { opacity: .35; transform: scale(.9); }
  50%      { opacity: 1;   transform: scale(1.1); }
}

/* 记忆卡片：卡通化细节 */
.word-card { position: relative; }
.wc-badge {
  position: absolute;
  top: -9px;
  right: 14px;
  padding: 2px 9px;
  font-size: 11px;
  letter-spacing: .08em;
  color: #fff;
  background: linear-gradient(135deg, #6366f1, #a855f7);
  border-radius: 999px;
  box-shadow: 0 3px 8px rgba(99, 102, 241, .35);
}
.wc-scene-wrap {
  flex: none;
  width: 62px;
  height: 62px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 25%, #ffffff 0%, #e9edff 65%, #dde3ff 100%);
  box-shadow: inset 0 -3px 8px rgba(99, 102, 241, .12), 0 6px 14px rgba(99, 102, 241, .16);
  transform: rotate(-4deg);
}
.wc-scene { font-size: 32px; line-height: 1; filter: none; }
.wc-title b { font-size: 17px; }
.wc-part { padding: 6px 11px; }
.wc-emo { font-size: 19px; }
.wc-part b { font-size: 13.5px; }
.wc-plus { font-size: 14px; }
.wc-caption { font-size: 13px; color: #4b5563; }
