:root{
  --bg: #f6f7fb;
  --panel: rgba(255,255,255,.78);
  --panelSolid: #ffffff;
  --border: rgba(15,23,42,.10);
  --text: #0f172a;
  --muted: rgba(15,23,42,.65);
  --muted2: rgba(15,23,42,.45);
  --primary: #2f6bff;
  --primary2: #1f4de0;
  --danger: #e11d48;
  --shadow: 0 10px 30px rgba(15,23,42,.08);
  --shadow2: 0 6px 18px rgba(15,23,42,.08);
  --radius: 14px;
  --radius2: 18px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  --sans: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", "Heiti SC", sans-serif;
}

*{ box-sizing: border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: var(--sans);
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 20% 20%, rgba(47,107,255,.12), transparent 60%),
    radial-gradient(900px 500px at 80% 10%, rgba(124,58,237,.10), transparent 55%),
    radial-gradient(900px 600px at 50% 90%, rgba(16,185,129,.08), transparent 55%),
    var(--bg);
}

code{ font-family: var(--mono); font-size: 12px; }

.appShell{
  height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  padding: 16px;
}

.sidebar{
  position: relative;
  border-radius: var(--radius2);
  background: linear-gradient(180deg, rgba(255,255,255,.80), rgba(255,255,255,.65));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}

.brand{
  display:flex;
  align-items:center;
  gap: 12px;
  padding: 10px 10px 6px;
}
.brandMark{
  width: 42px;
  height: 42px;
  border-radius: 14px;
  display:grid;
  place-items:center;
  color: #0b1220;
  background: linear-gradient(145deg, rgba(47,107,255,.20), rgba(255,255,255,.80));
  border: 1px solid rgba(47,107,255,.18);
}
.brandTitle{ font-weight: 800; letter-spacing: .2px; }
.brandSub{ color: var(--muted2); font-size: 12px; margin-top: 2px; }

.sidebarCard{
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow2);
  padding: 12px;
  backdrop-filter: blur(10px);
}

.kv{
  display:flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px dashed rgba(15,23,42,.10);
}
.kv:last-of-type{ border-bottom: none; }
.k{ color: var(--muted2); font-size: 12px; }
.v{ font-weight: 600; font-size: 12.5px; max-width: 220px; overflow:hidden; text-overflow: ellipsis; white-space: nowrap; }

.sidebarActions{
  display:flex;
  gap: 10px;
  margin-top: 10px;
}

.hint{
  margin-top: 10px;
  color: var(--muted2);
  font-size: 12px;
  line-height: 1.5;
}

.select{
  width: 100%;
  height: 34px;
  border-radius: 10px;
  border: 1px solid rgba(15,23,42,.14);
  background: rgba(255,255,255,.9);
  padding: 0 10px;
  font-size: 12.5px;
  outline: none;
}
.select:focus{ border-color: rgba(47,107,255,.65); box-shadow: 0 0 0 3px rgba(47,107,255,.12); }

.filterWrap{
  position: relative;
  display: inline-flex;
  align-items: center;
}

.filterMenu{
  position: absolute;
  left: 0;
  bottom: calc(100% + 10px);
  min-width: 220px;
  max-width: min(320px, 80vw);
  max-height: 280px;
  overflow: auto;
  padding: 8px;
  border-radius: 14px;
  background: rgba(255,255,255,.96);
  border: 1px solid rgba(15,23,42,.14);
  box-shadow: 0 18px 40px rgba(15,23,42,.14);
  backdrop-filter: blur(10px);
  z-index: 50;
}
.filterMenu.hidden{ display:none; }

.filterItem{
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 10px;
  border-radius: 12px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  text-align: left;
}
.filterItem:hover{
  background: rgba(47,107,255,.08);
  border-color: rgba(47,107,255,.18);
}
.filterItem.isActive{
  background: rgba(16,185,129,.10);
  border-color: rgba(16,185,129,.25);
}

.filterItemMeta{
  font-weight: 800;
  font-size: 12px;
  color: rgba(16,185,129,.92);
}

.btn{
  height: 38px;
  border-radius: 12px;
  padding: 0 14px;
  border: 1px solid rgba(15,23,42,.14);
  background: rgba(255,255,255,.85);
  color: var(--text);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform .06s ease, box-shadow .12s ease, background .12s ease, border-color .12s ease;
  user-select: none;
}
.btn:active{ transform: translateY(1px); }
.btn:disabled{ opacity: .55; cursor: not-allowed; }
.btnSm{ height: 30px; padding: 0 10px; border-radius: 10px; font-size: 12px; }

.btnPrimary{
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  color: #fff;
  border-color: rgba(47,107,255,.55);
  box-shadow: 0 10px 18px rgba(47,107,255,.18);
}
.btnPrimary:hover{ box-shadow: 0 12px 22px rgba(47,107,255,.22); }
.btnGhost:hover{ background: rgba(255,255,255,.98); border-color: rgba(15,23,42,.20); }
.btnDanger{
  background: rgba(225,29,72,.08);
  border-color: rgba(225,29,72,.25);
  color: #b10d32;
}
.btnDanger:hover{ background: rgba(225,29,72,.12); }

.btnIcon{ display:inline-flex; }

.cardHeader{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}
.cardTitle{ font-weight: 800; font-size: 13px; }

.historyList{
  display:flex;
  flex-direction: column;
  gap: 8px;
  max-height: 340px;
  overflow:auto;
  padding-right: 2px;
}
.historyItem{
  border: 1px solid rgba(15,23,42,.10);
  background: rgba(255,255,255,.75);
  border-radius: 12px;
  padding: 10px;
}
.historyQ{
  font-weight: 800;
  font-size: 12.5px;
  line-height: 1.35;
  margin-bottom: 6px;
}
.historyA{
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  max-height: 3.1em;
  overflow:hidden;
}
.historyEmpty{
  color: var(--muted2);
  font-size: 12px;
  padding: 10px 2px;
}

.main{
  border-radius: var(--radius2);
  background: linear-gradient(180deg, rgba(255,255,255,.70), rgba(255,255,255,.60));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
  display:flex;
  flex-direction: column;
  min-width: 0;
}

.topbar{
  height: 56px;
  display:flex;
  align-items:center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid rgba(15,23,42,.10);
  background: rgba(255,255,255,.78);
  backdrop-filter: blur(10px);
}
.topbarTitle{
  font-weight: 900;
  letter-spacing: .2px;
}
.pill{
  display:inline-flex;
  align-items:center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid rgba(15,23,42,.12);
  background: rgba(255,255,255,.75);
  font-size: 12px;
  color: var(--muted);
}
.dot{
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: rgba(15,23,42,.25);
}

.chat{
  flex: 1 1 auto;
  min-height: 0;
  display:flex;
  flex-direction: column;
}
.chatList{
  flex: 1 1 auto;
  overflow:auto;
  padding: 18px 18px 10px;
  display:flex;
  flex-direction: column;
  gap: 12px;
}

.msgRow{
  display:flex;
  gap: 10px;
  align-items: flex-start;
}
.msgRow.user{ justify-content: flex-end; }
.avatar{
  width: 34px;
  height: 34px;
  border-radius: 12px;
  display:grid;
  place-items:center;
  font-weight: 900;
  font-size: 12px;
  border: 1px solid rgba(15,23,42,.10);
  background: rgba(255,255,255,.8);
  color: rgba(15,23,42,.75);
  flex: 0 0 auto;
}
.avatar.bot{
  background: linear-gradient(145deg, rgba(47,107,255,.18), rgba(255,255,255,.85));
  color: rgba(15,23,42,.85);
}
.bubble{
  max-width: min(760px, 88%);
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(15,23,42,.10);
  background: rgba(255,255,255,.82);
  box-shadow: 0 8px 16px rgba(15,23,42,.05);
  white-space: pre-wrap;
  line-height: 1.55;
  font-size: 14px;
}
.bubble.bot{
  /* assistant 气泡：改为 Markdown 排版（不要强制 pre-wrap，否则列表/表格/段落会变形） */
  white-space: normal;
}
.bubble.user{
  /* 用户气泡：尽量少换行 -> 给更大的可用宽度（不影响 bot 的阈值） */
  max-width: min(920px, 96%);
  background: linear-gradient(135deg, rgba(47,107,255,.14), rgba(255,255,255,.82));
  border-color: rgba(47,107,255,.18);
}
.meta{
  margin-top: 6px;
  color: var(--muted2);
  font-size: 12px;
}

.composer{
  border-top: 1px solid rgba(15,23,42,.10);
  background: rgba(255,255,255,.80);
  backdrop-filter: blur(10px);
}
.composerInner{
  padding: 12px 14px 14px;
  display:flex;
  flex-direction: column;
  gap: 10px;
}
.composerCard{
  border-radius: 22px;
  border: 1px solid rgba(15,23,42,.12);
  background: rgba(255,255,255,.86);
  box-shadow: 0 10px 24px rgba(15,23,42,.06);
  padding: 12px 12px 10px;
}
.composerTop{
  padding: 4px 6px 8px;
}
.composerTextarea{
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  background: transparent;
  padding: 10px 8px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
}
.composerTextarea::placeholder{
  color: rgba(15,23,42,.40);
}
.composerBottom{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 4px 2px;
}
.composerLeft,
.composerRight{
  display:flex;
  align-items:center;
  gap: 10px;
}
.iconBtn{
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(15,23,42,.12);
  background: rgba(255,255,255,.88);
  color: rgba(15,23,42,.70);
  display:grid;
  place-items:center;
  cursor: pointer;
  transition: transform .06s ease, background .12s ease, border-color .12s ease, box-shadow .12s ease, color .12s ease;
}
.iconBtn.isRecording{
  border-color: rgba(225,29,72,.55);
  background: rgba(225,29,72,.08);
  color: rgba(225,29,72,.92);
  box-shadow: 0 0 0 4px rgba(225,29,72,.10);
  animation: micPulse 1.15s ease-in-out infinite;
}
.iconBtn.isRecording:hover{
  border-color: rgba(225,29,72,.70);
  background: rgba(225,29,72,.10);
  box-shadow: 0 0 0 5px rgba(225,29,72,.12);
}
.iconBtn.isRecording:disabled{
  animation: none;
}
@keyframes micPulse{
  0%{ transform: translateY(0); }
  50%{ transform: translateY(-1px); }
  100%{ transform: translateY(0); }
}
.iconBtn:hover{
  background: rgba(255,255,255,.98);
  border-color: rgba(15,23,42,.18);
  box-shadow: 0 8px 16px rgba(15,23,42,.06);
  color: rgba(15,23,42,.82);
}
.iconBtn:active{ transform: translateY(1px); }
.iconBtn:disabled{
  opacity: .55;
  cursor: not-allowed;
  box-shadow: none;
}

.chipBtn{
  height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid rgba(15,23,42,.12);
  background: rgba(255,255,255,.88);
  color: rgba(15,23,42,.78);
  display:inline-flex;
  align-items:center;
  gap: 8px;
  cursor: pointer;
  font-weight: 800;
  font-size: 13px;
  transition: transform .06s ease, background .12s ease, border-color .12s ease, box-shadow .12s ease, color .12s ease;
}
.chipBtn:hover{
  background: rgba(255,255,255,.98);
  border-color: rgba(15,23,42,.18);
  box-shadow: 0 8px 16px rgba(15,23,42,.06);
}
.chipBtn:active{ transform: translateY(1px); }
.chipBtn[aria-pressed="true"]{
  background: rgba(47,107,255,.12);
  border-color: rgba(47,107,255,.30);
  color: rgba(15,23,42,.88);
}
.chipIcon{
  width: 18px;
  height: 18px;
  display:grid;
  place-items:center;
  color: rgba(47,107,255,.95);
}

.sendBtn{
  width: 38px;
  height: 38px;
  border-radius: 999px;
  border: 1px solid rgba(15,23,42,.10);
  background: rgba(15,23,42,.06);
  color: rgba(15,23,42,.55);
  display:grid;
  place-items:center;
  cursor: pointer;
  transition: transform .06s ease, background .12s ease, color .12s ease, box-shadow .12s ease, border-color .12s ease;
}
.sendBtn:hover{
  background: rgba(15,23,42,.08);
  color: rgba(15,23,42,.72);
  box-shadow: 0 8px 16px rgba(15,23,42,.06);
}
.sendBtn:active{ transform: translateY(1px); }
.sendBtn:disabled{
  opacity: .55;
  cursor: not-allowed;
  box-shadow: none;
}
.sendBtn.isActive{
  background: linear-gradient(135deg, var(--primary), var(--primary2));
  border-color: rgba(47,107,255,.55);
  color: #fff;
  box-shadow: 0 10px 18px rgba(47,107,255,.18);
}

.hiddenFileInput{
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.composerExtras{
  margin-top: 8px;
  display:flex;
  align-items:flex-start;
  justify-content: space-between;
  gap: 12px;
}

.composerStatus{
  margin-top: 8px;
  padding: 0 8px 2px;
  font-size: 12px;
  color: var(--muted2);
  min-height: 16px;
}
.composerRow{
  display:flex;
  align-items: flex-end;
  gap: 10px;
}
.composerRow.sub{
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.rightHint{
  color: var(--muted2);
  font-size: 12px;
  padding-top: 6px;
  min-width: 120px;
  text-align: right;
}

.textarea{
  width: 100%;
  resize: none;
  border-radius: 14px;
  border: 1px solid rgba(15,23,42,.14);
  background: rgba(255,255,255,.92);
  padding: 12px 12px;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
  box-shadow: 0 4px 14px rgba(15,23,42,.04);
}
.textarea:focus{ border-color: rgba(47,107,255,.60); box-shadow: 0 0 0 4px rgba(47,107,255,.12); }
.textareaSub{ font-size: 13px; }

.input{
  width: 100%;
  height: 34px;
  border-radius: 12px;
  border: 1px solid rgba(15,23,42,.14);
  background: rgba(255,255,255,.92);
  padding: 0 12px;
  font-size: 13px;
  outline: none;
}
.input:focus{ border-color: rgba(47,107,255,.60); box-shadow: 0 0 0 4px rgba(47,107,255,.12); }

.details{
  width: 100%;
  border-radius: 14px;
  border: 1px solid rgba(15,23,42,.10);
  background: rgba(255,255,255,.65);
  padding: 10px 10px 10px;
}
.details > summary{
  cursor: pointer;
  font-weight: 800;
  color: rgba(15,23,42,.78);
  list-style: none;
}
.details > summary::-webkit-details-marker{ display:none; }
.details[open] > summary{ margin-bottom: 10px; }

.toast{
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  background: rgba(15,23,42,.86);
  color: #fff;
  padding: 10px 12px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 12px 22px rgba(0,0,0,.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity .18s ease, transform .18s ease;
}
.toast.show{
  opacity: 1;
  transform: translateX(-50%) translateY(-2px);
}

@media (max-width: 960px){
  .appShell{ grid-template-columns: 1fr; }
  .sidebar{ display:none; }
}

/* -------------------------
 * Markdown（assistant 气泡）样式
 * ------------------------- */
.bubble.bot .md{
  font-size: 14px;
  line-height: 1.65;
  color: rgba(15,23,42,.92);
}

.bubble.bot .md img{
  /* 视觉优化：图片默认显示小一些，避免占满气泡导致“突兀” */
  max-width: min(320px, 100%);
  max-height: 220px;
  width: auto;
  height: auto;
  display: block;
  margin: 10px 0;
  border-radius: 12px;
  border: 1px solid rgba(15,23,42,.10);
  box-shadow: 0 6px 16px rgba(15,23,42,.08);
  background: rgba(255,255,255,.9);
  object-fit: contain;
  cursor: zoom-in;
  transition: transform .12s ease, box-shadow .12s ease;
}
.bubble.bot .md a > img{ cursor: zoom-in; }
.bubble.bot .md img:hover{
  transform: translateY(-1px);
  box-shadow: 0 10px 24px rgba(15,23,42,.12);
}

@media (max-width: 640px){
  .bubble.bot .md img{
    max-width: min(260px, 100%);
    max-height: 180px;
  }
}

.bubble.bot .md > :first-child{ margin-top: 0; }
.bubble.bot .md > :last-child{ margin-bottom: 0; }

.bubble.bot .md p{ margin: 0 0 10px; }
.bubble.bot .md h1,
.bubble.bot .md h2,
.bubble.bot .md h3{
  margin: 12px 0 8px;
  line-height: 1.25;
  letter-spacing: .1px;
}
.bubble.bot .md h1{ font-size: 18px; }
.bubble.bot .md h2{ font-size: 16px; }
.bubble.bot .md h3{ font-size: 14.5px; }

.bubble.bot .md a{
  color: rgba(47,107,255,.95);
  text-decoration: none;
  border-bottom: 1px solid rgba(47,107,255,.35);
}
.bubble.bot .md a:hover{ border-bottom-color: rgba(47,107,255,.65); }

.bubble.bot .md ul,
.bubble.bot .md ol{
  margin: 0 0 10px;
  padding-left: 1.25em;
}
.bubble.bot .md li{ margin: 4px 0; }

.bubble.bot .md blockquote{
  margin: 10px 0;
  padding: 8px 10px;
  border-left: 3px solid rgba(47,107,255,.35);
  background: rgba(47,107,255,.06);
  border-radius: 10px;
  color: rgba(15,23,42,.78);
}

.bubble.bot .md hr{
  border: none;
  border-top: 1px dashed rgba(15,23,42,.16);
  margin: 12px 0;
}

.bubble.bot .md code{
  font-family: var(--mono);
  font-size: 12.5px;
  background: rgba(15,23,42,.06);
  padding: 2px 6px;
  border-radius: 8px;
  border: 1px solid rgba(15,23,42,.08);
}

.bubble.bot .md pre{
  margin: 10px 0;
  padding: 12px 12px;
  background: rgba(255,255,255,.95);
  color: rgba(15,23,42,.92);
  border-radius: 14px;
  overflow: auto;
  border: 1px solid rgba(15,23,42,.12);
  box-shadow: 0 4px 12px rgba(15,23,42,.06);
}
.bubble.bot .md pre code{
  background: transparent;
  border: none;
  padding: 0;
  color: inherit;
  font-size: 12.5px;
  white-space: pre; /* 代码块保持原始空白 */
}

.bubble.bot .md table{
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  margin: 10px 0;
  overflow: hidden;
  border-radius: 12px;
  border: 1px solid rgba(15,23,42,.10);
}
.bubble.bot .md th,
.bubble.bot .md td{
  padding: 8px 10px;
  border-bottom: 1px solid rgba(15,23,42,.08);
  border-right: 1px solid rgba(15,23,42,.08);
  vertical-align: top;
  font-size: 13px;
}
.bubble.bot .md th{
  background: rgba(15,23,42,.04);
  font-weight: 800;
}
.bubble.bot .md tr:last-child td{ border-bottom: none; }
.bubble.bot .md th:last-child,
.bubble.bot .md td:last-child{ border-right: none; }

/* marked/DOMPurify 不可用时的降级展示（仍保持可读） */
.bubble.bot .mdFallback .mdPlain{
  margin: 0;
  white-space: pre-wrap;
  font-family: var(--sans);
  color: rgba(15,23,42,.92);
}


