:root {
  --bg: #f3f7fe;
  --surface: #ffffff;
  --surface-2: #f7faff;
  --ink: #132a46;
  --ink-soft: #324a68;
  --muted: #66788f;
  --line: #dfe8f5;
  --line-strong: #cbd9ec;
  --brand: #2563eb;
  --brand-strong: #1d4ed8;
  --brand-soft: #e7efff;
  --accent: #93c5fd;
  --sidebar: #0b2545;
  --sidebar-2: #10305a;
  --sidebar-ink: #eef5ff;
  --sidebar-muted: #9db4d2;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --shadow: 0 14px 40px rgba(15, 35, 70, 0.08);
  --radius: 16px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, textarea, input { font: inherit; }
button { cursor: pointer; }

.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: 100dvh;
  overflow: hidden;
}

/* ---------- sidebar ---------- */

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 22px;
  padding: 26px 22px 22px;
  background:
    radial-gradient(120% 70% at 0% 0%, rgba(147, 197, 253,0.10), transparent 58%),
    linear-gradient(180deg, var(--sidebar) 0%, #071a33 100%);
  color: var(--sidebar-ink);
  overflow-y: auto;
  /* 深色侧栏上默认滚动条几乎看不见：加宽轨道 + 高亮滑块 */
  scrollbar-gutter: stable;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--accent);
  color: #0b2545;
  box-shadow: 0 6px 18px rgba(147, 197, 253,0.18);
}

.brand-mark svg { width: 24px; height: 24px; }

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.25;
}

.brand-text strong {
  font-size: 18px;
  letter-spacing: 0.2px;
}

.brand-text span {
  font-size: 12px;
  color: var(--sidebar-muted);
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  align-self: flex-start;
  padding: 7px 11px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.045);
  color: var(--sidebar-muted);
  font-size: 12px;
  line-height: 1;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #8ba3c4;
  box-shadow: 0 0 0 3px rgba(139, 163, 196, 0.18);
}

.status.ok .status-dot {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(147, 197, 253,0.16);
}

.status.ok { color: #cfe2f7; }

.status.bad .status-dot {
  background: #ff8b7b;
  box-shadow: 0 0 0 3px rgba(255, 139, 123, 0.16);
}

.side-panel {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding-top: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.panel-head h2 {
  margin: 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.9px;
  text-transform: uppercase;
  color: var(--sidebar-muted);
}

.link-btn {
  border: 0;
  padding: 2px;
  background: none;
  color: #a8bdd8;
  font-size: 12px;
  border-radius: 6px;
}

.link-btn:hover { color: var(--accent); }

.config-tag {
  padding: 3px 8px;
  border-radius: 999px;
  border: 1px solid rgba(147, 197, 253,0.22);
  background: rgba(147, 197, 253,0.1);
  color: var(--accent);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.3;
  letter-spacing: 0.2px;
}

.funnel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.funnel-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 26px;
  align-items: center;
  gap: 9px;
  padding: 4px 7px;
  margin: 0 -7px;
  border-radius: 8px;
  font-size: 11.5px;
  line-height: 1;
  color: #d3e2f5;
  transition: background 0.16s ease;
}

.funnel-row:hover { background: rgba(255, 255, 255, 0.045); }

.funnel-label {
  color: var(--sidebar-muted);
  letter-spacing: 0.3px;
}

.funnel-track {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.funnel-fill {
  display: block;
  height: 100%;
  width: 0;
  min-width: 10px;
  border-radius: inherit;
  background: rgba(222, 234, 255,0.38);
  transition: width 0.55s cubic-bezier(0.22, 1, 0.36, 1);
}

.funnel-value {
  color: #e6f0fb;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.funnel-row.is-config {
  background: rgba(147, 197, 253,0.07);
}

.funnel-row.is-config .funnel-label { color: #bcd7fb; }

.funnel-row.is-config .funnel-fill {
  background: var(--accent);
  box-shadow: 0 0 10px rgba(147, 197, 253,0.35);
}

.funnel-row.is-config .funnel-value {
  color: var(--accent);
  font-weight: 600;
}

.funnel-row.is-editor { margin-top: 2px; }

.funnel-range {
  width: 100%;
  height: 14px;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.funnel-range:disabled {
  cursor: default;
  opacity: 0.4;
}

.funnel-row.is-editor .funnel-value { color: #bcd7fb; }

.side-config.is-off .funnel-row.is-config {
  background: transparent;
  opacity: 0.45;
}

.side-config.is-off .funnel-row.is-config .funnel-fill {
  background: rgba(222, 234, 255,0.2);
  box-shadow: none;
}

.config-note {
  display: flex;
  gap: 7px;
  align-items: flex-start;
  margin-top: 12px;
}

.config-dot {
  flex: none;
  width: 6px;
  height: 6px;
  margin-top: 5px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(147, 197, 253,0.14);
}

.config-note code {
  font-family: var(--mono);
  font-size: 10px;
  color: #a9c1de;
}

.config-note.is-ok { color: var(--accent); }

.config-note.is-err { color: #ff9c8f; }
.config-note.is-err .config-dot { background: #ff9c8f; box-shadow: none; }

.panel-count {
  color: var(--sidebar-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.session-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 150px;
  padding-right: 2px;
  overflow-y: auto;
}

/* 列表内滚动条：细但看得见，别让 Chromium 画出带箭头的系统滚动条 */
.session-list::-webkit-scrollbar { width: 8px; }

.session-list::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.05);
}

.session-list::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
  background-color: rgba(147, 197, 253,0.45);
}

.session-list::-webkit-scrollbar-thumb:hover {
  background-color: rgba(147, 197, 253,0.75);
}

.session-list .muted {
  margin: 0;
  color: var(--sidebar-muted);
  font-size: 12px;
  line-height: 1.7;
}

.session-item {
  display: flex;
  align-items: stretch;
  border: 1px solid transparent;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.035);
  transition: background 0.16s ease, border-color 0.16s ease;
}

.session-item:hover { background: rgba(255, 255, 255, 0.062); }

.session-item.is-active {
  background: rgba(147, 197, 253,0.08);
  border-color: rgba(147, 197, 253,0.28);
}

.session-open {
  flex: 1;
  min-width: 0;
  padding: 7px 4px 7px 9px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: #d6e4f4;
  font-size: 12px;
  line-height: 1.35;
  text-align: left;
}

.session-title {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item.is-active .session-title { color: var(--accent); }

.session-meta {
  display: block;
  margin-top: 2px;
  overflow: hidden;
  color: #71849c;
  font-size: 10.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-del {
  flex: none;
  width: 26px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: #6d829c;
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.14s ease, color 0.14s ease;
}

.session-item:hover .session-del,
.session-del:focus-visible { opacity: 1; }

.session-del:hover { color: #ff9c8f; }

@media (pointer: coarse) {
  .session-del { opacity: 1; }
}

.profile {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.profile .chip {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  max-width: 100%;
  padding: 6px 9px;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.065);
  color: #dbe8f8;
  font-size: 12px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.profile .chip b {
  color: var(--sidebar-muted);
  font-weight: 500;
  flex: none;
}

.profile .muted {
  margin: 0;
  color: var(--sidebar-muted);
  font-size: 12px;
  line-height: 1.7;
}

.examples {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.example {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.035);
  color: #d6e4f4;
  font-size: 12.5px;
  line-height: 1.45;
  text-align: left;
  transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

.example:hover {
  background: rgba(147, 197, 253,0.09);
  border-color: rgba(147, 197, 253,0.28);
  transform: translateX(2px);
}

.side-foot {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.switch {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #c4d4e8;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  /* 里面的隐藏 checkbox 是 absolute：不定位父级会让它相对页面定位，
     逃出侧栏的滚动裁剪，把整个文档撑高出一片空白 */
  position: relative;
}

.switch input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  width: 34px;
  height: 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
  transition: background 0.18s ease;
  flex: none;
}

.switch-track span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #dce8f7;
  transition: transform 0.18s ease, background 0.18s ease;
}

.switch input:checked + .switch-track { background: var(--accent); }
.switch input:checked + .switch-track span {
  transform: translateX(14px);
  background: #0b2545;
}
.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.side-note {
  margin: 0;
  color: #71849c;
  font-size: 11px;
  line-height: 1.65;
}

/* ---------- main ---------- */

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100dvh;
  background:
    radial-gradient(70% 50% at 100% 0%, rgba(37, 99, 235,0.055), transparent 70%),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px clamp(20px, 4vw, 48px) 16px;
  border-bottom: 1px solid rgba(19, 42, 70, 0.06);
  background: rgba(243, 247, 254,0.82);
  backdrop-filter: blur(10px);
}

.title-block h1 {
  margin: 0;
  font-size: 19px;
  letter-spacing: -0.2px;
}

.title-block p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12.5px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 11px;
  border: 1px solid transparent;
  transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease,
    transform 0.06s ease;
}

.btn:active { transform: translateY(1px); }

.btn-ghost {
  padding: 9px 13px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink-soft);
  font-size: 12.5px;
  box-shadow: 0 2px 6px rgba(15, 35, 70,0.03);
}

.btn-ghost:hover {
  border-color: var(--line-strong);
  background: #fbfdff;
}

.btn-ghost svg { width: 15px; height: 15px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 28px clamp(18px, 4vw, 48px) 18px;
  scroll-behavior: smooth;
}

.messages-inner {
  width: min(100%, 860px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.msg {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: rise 0.24s ease both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg.user { justify-content: flex-end; }

.avatar {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 10px;
  flex: none;
  margin-top: 2px;
  background: var(--brand);
  color: white;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

.avatar svg { width: 17px; height: 17px; }

.bubble {
  max-width: min(100%, 700px);
  padding: 13px 16px;
  border-radius: 4px 16px 16px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 3px 14px rgba(15, 35, 70,0.035);
  font-size: 14px;
  line-height: 1.75;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  max-width: min(84%, 620px);
  border-radius: 16px 4px 16px 16px;
  background: var(--brand);
  border-color: var(--brand);
  color: #f4f9ff;
  box-shadow: 0 6px 18px rgba(37, 99, 235,0.16);
}

.bubble .answer strong { font-weight: 650; color: var(--ink); }
.msg.user .bubble .answer strong { color: inherit; }

.product-link {
  display: inline;
  padding: 0;
  border: 0;
  background: none;
  color: var(--brand-strong);
  font: inherit;
  font-weight: inherit;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: rgba(37, 99, 235,0.35);
  text-underline-offset: 3px;
}

.product-link:hover {
  color: var(--brand);
  text-decoration-color: currentColor;
}

.product-link:focus-visible {
  border-radius: 3px;
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.product-refs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px dashed var(--line);
}

.product-refs-label {
  color: var(--muted);
  font-size: 11px;
}

.product-ref {
  max-width: 100%;
  padding: 4px 8px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.product-ref:hover {
  border-color: #bcd6f2;
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.product-ref:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 11.5px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.2;
}

.pill.intent {
  background: var(--brand-soft);
  border-color: #cfe2f8;
  color: var(--brand-strong);
}

.pill.model-pill {
  background: #eef4ff;
  border-color: #d7e5fb;
  color: #1e4f8f;
}

.pill.stopped {
  background: var(--danger-soft);
  border-color: #f7d5d2;
  color: var(--danger);
}

.trace {
  margin-top: 9px;
  border-top: 1px dashed var(--line);
  padding-top: 8px;
}

.trace summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 11.5px;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.trace summary::-webkit-details-marker { display: none; }

.trace summary::before {
  content: "▸";
  font-size: 10px;
  transition: transform 0.15s ease;
}

.trace[open] summary::before { transform: rotate(90deg); }

.trace pre {
  margin: 8px 0 0;
  padding: 10px 12px;
  border-radius: 9px;
  background: #f4f8ff;
  border: 1px solid var(--line);
  color: #43586f;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.msg.error .bubble {
  background: var(--danger-soft);
  border-color: #fbd9d5;
  color: var(--danger);
}

.typing .bubble {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  max-width: min(84%, 620px);
}

.typing-text {
  min-width: 0;
  overflow-wrap: anywhere;
}

/* 流式输出时末尾的光标；答案写完（去掉 .streaming）就消失 */
.msg.streaming .answer::after {
  content: "▍";
  margin-left: 2px;
  color: var(--brand);
  animation: caret 1s steps(1) infinite;
}

@keyframes caret {
  50% { opacity: 0; }
}

.dots {
  display: inline-flex;
  gap: 4px;
}

.dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
  opacity: 0.35;
  animation: blink 1.2s infinite ease-in-out;
}

.dots span:nth-child(2) { animation-delay: 0.18s; }
.dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes blink {
  0%, 70%, 100% { opacity: 0.25; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-2px); }
}

/* ---------- empty state ---------- */

.empty {
  width: min(100%, 720px);
  margin: auto;
  padding: 8vh 12px 30px;
  text-align: center;
  animation: rise 0.3s ease both;
}

.empty-mark {
  display: grid;
  place-items: center;
  width: 62px;
  height: 62px;
  margin: 0 auto 18px;
  border-radius: 19px;
  background: var(--brand);
  color: var(--accent);
  box-shadow: 0 14px 30px rgba(37, 99, 235,0.2);
}

.empty-mark svg { width: 32px; height: 32px; }

.empty h2 {
  margin: 0;
  font-size: clamp(22px, 3.2vw, 30px);
  letter-spacing: -0.5px;
}

.empty p {
  max-width: 480px;
  margin: 10px auto 0;
  color: var(--muted);
  font-size: 13.5px;
  line-height: 1.7;
}

.empty-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-top: 24px;
}

.empty-chip {
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12.5px;
  box-shadow: 0 2px 8px rgba(15, 35, 70,0.03);
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.15s ease;
}

.empty-chip:hover {
  border-color: var(--brand);
  background: var(--brand-soft);
  transform: translateY(-1px);
}

/* ---------- composer ---------- */

.composer-wrap {
  padding: 12px clamp(18px, 4vw, 48px) 18px;
  background: linear-gradient(180deg, rgba(243, 247, 254,0) 0%, var(--bg) 26%);
}

.model-bar {
  width: min(100%, 860px);
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  row-gap: 6px;
  padding: 0 4px;
}

.model-picker {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: none;
  font-size: 11.5px;
  color: var(--muted);
}

.model-select {
  padding: 4px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 11.5px;
  outline: none;
  cursor: pointer;
}

.model-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235,0.08);
}

.model-select:disabled { opacity: 0.6; cursor: not-allowed; }

.model-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-size: 11.5px;
  color: var(--muted);
}

#model-status-text,
#router-status-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: #b8c6d8;
}

.model-status[data-state="ok"] .model-dot {
  background: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.13);
}

.model-status[data-state="err"] { color: var(--danger); }
.model-status[data-state="err"] .model-dot {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.12);
}

.model-status[data-state="checking"] .model-dot {
  background: #d97706;
  animation: model-pulse 1s ease-in-out infinite;
}

@keyframes model-pulse {
  50% { opacity: 0.35; }
}

.model-refresh {
  flex: none;
  padding: 3px 6px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 1;
}

.model-refresh:hover { background: var(--brand-soft); color: var(--brand); }
.model-refresh.is-busy { animation: model-spin 0.8s linear infinite; }

@keyframes model-spin {
  to { transform: rotate(360deg); }
}

/* router 开关：就放在模型选择旁边，本地 LoRA / 云端 DeepSeek 二选一。
   和侧栏的 .switch 分开写，这里是浅色底。 */
.model-bar-sep {
  flex: none;
  margin-left: auto;
  width: 1px;
  height: 18px;
  background: var(--line);
}

.router-toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex: none;
  color: var(--muted);
  font-size: 11.5px;
  cursor: pointer;
  user-select: none;
  position: relative;
}

.router-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.router-track {
  position: relative;
  width: 30px;
  height: 17px;
  flex: none;
  border-radius: 999px;
  background: #cbd6e4;
  transition: background 0.18s ease;
}

.router-track span {
  position: absolute;
  top: 2.5px;
  left: 2.5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 2px rgba(15, 35, 70, 0.22);
  transition: transform 0.18s ease;
}

.router-toggle input:checked + .router-track { background: var(--brand); }
.router-toggle input:checked + .router-track span { transform: translateX(13px); }
.router-toggle input:focus-visible + .router-track {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.router-toggle.is-busy { opacity: 0.6; cursor: progress; }

.composer {
  width: min(100%, 860px);
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 9px;
  padding: 8px 8px 8px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 17px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.composer:focus-within {
  border-color: var(--brand);
  box-shadow: 0 14px 40px rgba(15, 35, 70,0.1), 0 0 0 3px rgba(37, 99, 235,0.08);
}

.composer textarea {
  flex: 1;
  min-height: 25px;
  max-height: 160px;
  padding: 9px 0;
  border: 0;
  outline: none;
  resize: none;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}

.composer textarea::placeholder { color: #97a6ba; }

.btn-send {
  padding: 10px 14px;
  background: var(--brand);
  color: white;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(37, 99, 235,0.18);
  flex: none;
}

.btn-send svg { width: 15px; height: 15px; }
.btn-send:hover { background: var(--brand-strong); }

.btn-send:disabled,
.composer textarea:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* 生成中把「发送」换成「停止」 */
.btn-stop {
  display: none;
  padding: 10px 14px;
  background: var(--danger);
  color: white;
  font-size: 13px;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(180, 35, 24, 0.18);
  flex: none;
}

.btn-stop svg { width: 14px; height: 14px; }
.btn-stop:hover { background: #8f1c13; }

.composer.is-sending .btn-stop { display: inline-flex; }
.composer.is-sending .btn-send { display: none; }

.hint {
  width: min(100%, 860px);
  margin: 9px auto 0;
  color: #8a99ad;
  font-size: 11px;
  text-align: center;
}

/* ---------- 商品库页签 ---------- */

.view-tabs {
  display: inline-flex;
  gap: 3px;
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 4px 14px rgba(15, 35, 70,0.06);
  flex: none;
}

.view-tab {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 500;
  line-height: 1;
  transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease,
    transform 0.06s ease;
}

.view-tab:hover {
  background: var(--brand-soft);
  color: var(--brand-strong);
}

.view-tab:active { transform: translateY(1px); }

.view-tab.is-active {
  background: var(--brand);
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 6px 16px rgba(37, 99, 235,0.24);
}

.view-tab.is-active:hover {
  background: var(--brand-strong);
  color: #ffffff;
}

.tab-icon {
  width: 16px;
  height: 16px;
  flex: none;
}

.view-tab:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

#new-chat { margin-left: auto; }

.main.is-catalog .messages,
.main.is-catalog .composer-wrap,
.main.is-catalog #new-chat { display: none; }

.catalog {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.catalog-inner {
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 24px clamp(18px, 4vw, 48px) 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.catalog-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(188px, 1fr));
  gap: 12px;
}

.stat-card {
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(15, 35, 70,0.035);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 10.5px;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  margin-top: 6px;
  font-size: 25px;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}

.stat-card small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.catalog-charts {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.chart-card {
  padding: 17px 19px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 4px 16px rgba(15, 35, 70,0.035);
}

.chart-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.chart-head h2 {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.2px;
}

.chart-note {
  color: var(--muted);
  font-size: 10.5px;
  text-align: right;
}

.bars {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bar-row {
  display: grid;
  grid-template-columns: 88px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 11px;
}

.bar-label {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.bar-track {
  height: 8px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
}

.bar-fill {
  width: 0;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--brand) 0%, #3b82f6 100%);
  transition: width 0.45s cubic-bezier(0.2, 0.7, 0.3, 1);
}

.bar-row.is-muted .bar-fill {
  background: linear-gradient(90deg, #b9c8da 0%, #d3dbec 100%);
}

.bar-value {
  color: var(--ink-soft);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.catalog-browser {
  padding: 18px 20px 20px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: 0 6px 22px rgba(15, 35, 70,0.04);
}

.browser-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 9px;
}

.search-box {
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 220px;
  gap: 8px;
  padding: 9px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface-2);
  transition: border-color 0.16s ease, box-shadow 0.16s ease;
}

.search-box:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235,0.08);
}

.search-box svg {
  width: 15px;
  height: 15px;
  flex: none;
  color: var(--muted);
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 13px;
}

.search-box input::placeholder { color: #97a6ba; }

.select {
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12.5px;
  outline: none;
}

.select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(37, 99, 235,0.08);
}

.browser-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 14px 0 12px;
  color: var(--muted);
  font-size: 11px;
}

.catalog-count { margin: 0; }
.catalog-source { color: #8a99ad; }

.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}

.product-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 168px;
  padding: 14px 15px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
  cursor: pointer;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
}

.product-card:hover {
  border-color: #bcd6f2;
  box-shadow: 0 8px 22px rgba(15, 35, 70,0.07);
  transform: translateY(-1px);
}

.product-card:focus-visible {
  outline: 3px solid rgba(37, 99, 235,0.25);
  outline-offset: 2px;
}

.product-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-badge {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  flex: none;
  border-radius: 8px;
  background: var(--brand-soft);
  color: var(--brand-strong);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.product-brand {
  flex: 1;
  min-width: 0;
  color: var(--muted);
  font-size: 11.5px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.product-price {
  flex: none;
  color: var(--brand-strong);
  font-size: 13px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.product-price.is-unknown {
  padding: 3px 7px;
  border-radius: 999px;
  background: #fdf3dd;
  color: #96620a;
  font-size: 10px;
  font-weight: 600;
}

.product-card h3 {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.45;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.product-desc {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  color: var(--muted);
  font-size: 11.5px;
  line-height: 1.6;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.product-desc.is-match {
  padding-left: 7px;
  border-left: 2px solid #cfe2f8;
  color: var(--ink-soft);
}

.product-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: auto;
  color: #8a99ad;
  font-size: 10px;
}

.product-foot code {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.2px;
}

.product-more {
  color: var(--brand-strong);
  font-size: 10.5px;
  font-weight: 600;
}

.catalog-empty {
  grid-column: 1 / -1;
  padding: 46px 12px;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

/* ---------- 商品详情弹窗 ---------- */

body.modal-open { overflow: hidden; }

.product-modal {
  width: min(760px, calc(100vw - 32px));
  max-height: min(88vh, 920px);
  margin: auto;
  padding: 0;
  overflow: hidden;
  border: 0;
  border-radius: 18px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 30px 90px rgba(11, 37, 69,0.28);
}

.product-modal::backdrop {
  background: rgba(11, 37, 69,0.42);
  backdrop-filter: blur(2px);
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px 15px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(8px);
}

.modal-heading { min-width: 0; }

.modal-kicker {
  display: block;
  margin-bottom: 5px;
  color: var(--brand);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
}

.modal-head h2 {
  margin: 0;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 18px;
  line-height: 1.4;
}

.modal-close {
  display: grid;
  flex: none;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--muted);
  font-size: 20px;
  line-height: 1;
}

.modal-close:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
  color: var(--ink);
}

.modal-close:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}

.modal-body {
  max-height: calc(88vh - 82px);
  padding: 18px 24px 26px;
  overflow-y: auto;
}

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

.detail-brand {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}

.detail-brand-name {
  font-size: 13px;
  font-weight: 600;
}

.detail-asin {
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10.5px;
}

.detail-price {
  flex: none;
  color: var(--brand-strong);
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.detail-price.is-unknown {
  padding: 5px 9px;
  border-radius: 999px;
  background: #fdf3dd;
  color: #96620a;
  font-size: 11px;
  font-weight: 600;
}

.detail-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 14px 0 2px;
}

.detail-tag {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
}

.detail-tag.is-warn {
  border-color: #f1dba9;
  background: #fdf8ea;
  color: #96620a;
}

.detail-copy {
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
}

.detail-copy:hover {
  border-color: var(--brand);
  color: var(--brand-strong);
}

.detail-section { margin-top: 18px; }

.detail-section h3 {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.detail-text {
  margin: 0;
  padding: 12px 14px;
  overflow-wrap: anywhere;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--ink-soft);
  font-size: 12.5px;
  line-height: 1.75;
  white-space: pre-wrap;
}

.detail-loading,
.detail-error {
  margin: 0;
  padding: 30px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.detail-error { color: var(--danger); }

.detail-raw {
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.detail-raw summary {
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}

.detail-raw pre {
  max-height: 280px;
  margin: 10px 0 0;
  padding: 12px;
  overflow: auto;
  overflow-wrap: anywhere;
  border-radius: 10px;
  background: #0a2142;
  color: #d7e5f5;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.page-btn {
  padding: 7px 12px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 12px;
}

.page-btn:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand-strong);
}

.page-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.page-label {
  color: var(--muted);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}

/* ---------- scrollbar ---------- */

.messages::-webkit-scrollbar,
.catalog::-webkit-scrollbar { width: 9px; }

.messages::-webkit-scrollbar-thumb,
.catalog::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
  background-color: #c9d5e6;
}

/* 侧栏：常显的宽滚动条，深色底上用品牌浅蓝，滑块可见宽度 6px */
.sidebar::-webkit-scrollbar { width: 12px; }

.sidebar::-webkit-scrollbar-track {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
}

.sidebar::-webkit-scrollbar-thumb {
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
  background-color: rgba(147, 197, 253,0.40);
}

.sidebar::-webkit-scrollbar-thumb:hover {
  background-color: rgba(147, 197, 253,0.72);
}

.sidebar::-webkit-scrollbar-thumb:active {
  background-color: var(--accent);
}

/* Firefox 没有 ::-webkit-scrollbar，用标准属性兜底 */
@supports (-moz-appearance: none) {
  .sidebar {
    scrollbar-width: thin;
    scrollbar-color: rgba(147, 197, 253,0.55) rgba(255, 255, 255, 0.06);
  }

  .session-list {
    scrollbar-width: thin;
    scrollbar-color: rgba(147, 197, 253,0.45) rgba(255, 255, 255, 0.05);
  }
}

/* ---------- responsive ---------- */

@media (max-width: 860px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }

  /* 桌面端 .main 固定 100dvh；移动端它只是 grid 的第二行，
     再写死 100dvh 会把页面撑高一个侧栏，把顶部栏顶出视口。 */
  .main {
    height: auto;
    min-height: 0;
  }

  .sidebar {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    overflow: visible;
  }

  .brand-mark { width: 36px; height: 36px; border-radius: 11px; }
  .brand-mark svg { width: 21px; height: 21px; }
  .brand-text strong { font-size: 16px; }
  .brand-text span, .status, .side-panel, .side-note { display: none; }

  .side-foot {
    margin: 0 0 0 auto;
    padding: 0;
    border: 0;
    flex-direction: row;
    align-items: center;
  }

  .switch { font-size: 11.5px; }

  .topbar {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 16px;
  }
  .title-block { flex: 1 1 auto; }
  .title-block h1 { font-size: 17px; }
  .title-block p { display: none; }
  .btn-ghost { padding: 8px 11px; }
  .view-tabs { order: 3; flex: 1 1 100%; }
  .view-tab { flex: 1; padding: 10px 14px; font-size: 13px; }

  .messages { padding: 20px 14px 12px; }
  .bubble { font-size: 13.5px; padding: 11px 13px; }
  .avatar { width: 27px; height: 27px; }
  .msg.user .bubble { max-width: 88%; }

  .composer-wrap { padding: 8px 12px 12px; }
  .model-bar { gap: 7px; padding: 0 2px; }
  .model-picker-label { display: none; }
  .model-status { font-size: 11px; }
  .composer { padding-left: 12px; border-radius: 15px; }
  .btn-send span,
  .btn-stop span { display: none; }
  .btn-send,
  .btn-stop { padding: 10px; border-radius: 12px; }
  .btn-send svg { width: 17px; height: 17px; }
  .btn-stop svg { width: 18px; height: 18px; }
  .hint { display: none; }

  .empty { padding-top: 5vh; }
  .empty-chips { gap: 6px; }
  .empty-chip { font-size: 11.5px; padding: 8px 11px; }

  .catalog-inner { padding: 16px 14px 28px; gap: 14px; }
  .catalog-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .stat-card { padding: 12px 13px; }
  .stat-card strong { font-size: 21px; }
  .catalog-charts { grid-template-columns: 1fr; gap: 10px; }
  .chart-card { padding: 14px 15px; }
  .catalog-browser { padding: 14px 13px 16px; }
  .browser-toolbar { flex-direction: column; align-items: stretch; }
  .search-box { min-width: 0; }
  .select { width: 100%; }
  .product-grid { grid-template-columns: 1fr; }
  .product-card { min-height: 150px; }
  .browser-meta { flex-direction: column; gap: 3px; }

  .product-modal {
    width: calc(100vw - 20px);
    max-height: 92vh;
    border-radius: 14px;
  }
  .modal-head { padding: 16px 16px 12px; }
  .modal-head h2 { font-size: 16px; }
  .modal-body { max-height: calc(92vh - 76px); padding: 14px 16px 20px; }
  .detail-hero { flex-wrap: wrap; }
  .detail-price { margin-left: auto; }
  .detail-text { font-size: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
