/* ============================================================
   DeepSeek Chat · 设计系统
   基调：安静的开发者控制台。单一强调色 + 中性底色，
   信息密度偏高但留白克制，浅色/深色共用同一套 token。
   ============================================================ */

:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Source Han Sans SC", "Noto Sans CJK SC", system-ui, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono",
    "Courier New", monospace;

  --accent: #4d6bfe;
  --accent-soft: rgba(77, 107, 254, 0.12);
  --accent-strong: #3a56d8;
  --warn: #d97706;
  --warn-soft: rgba(217, 119, 6, 0.12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --ok: #059669;

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;
  --radius-pill: 999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --sidebar-w: 264px;
  --content-w: 880px;
  --sources-w: 320px;

  --transition: 160ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* 浅色 */
body[data-theme="light"] {
  --bg: #f7f8fa;
  --bg-elevated: #ffffff;
  --bg-sunken: #eef0f4;
  --bg-code: #f4f6f9;
  --bg-hover: rgba(15, 23, 42, 0.05);
  --text: #101828;
  --text-muted: #667085;
  --text-faint: #98a2b3;
  --border: #e4e7ec;
  --border-strong: #d0d5dd;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
  --shadow: 0 6px 24px rgba(16, 24, 40, 0.08);
  --code-keyword: #8250df;
  --code-string: #0a7d55;
  --code-number: #b35309;
  --code-comment: #98a2b3;
  --code-func: #0550ae;
  --code-punct: #475467;
  --user-bubble: var(--accent);
  --user-bubble-text: #ffffff;
}

/* 深色 */
body[data-theme="dark"] {
  --bg: #0e1116;
  --bg-elevated: #161b22;
  --bg-sunken: #0a0d12;
  --bg-code: #10151c;
  --bg-hover: rgba(255, 255, 255, 0.06);
  --text: #e6edf3;
  --text-muted: #9aa4b2;
  --text-faint: #6e7781;
  --border: #262d36;
  --border-strong: #333c47;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  --code-keyword: #d2a8ff;
  --code-string: #7ee787;
  --code-number: #ffa657;
  --code-comment: #8b949e;
  --code-func: #79c0ff;
  --code-punct: #a1a8b3;
  --accent-soft: rgba(77, 107, 254, 0.2);
  --user-bubble: #2b4bd8;
  --user-bubble-text: #ffffff;
}

* {
  box-sizing: border-box;
}

/* display 声明会覆盖 hidden 属性的默认 display:none，这里统一兜底 */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

body {
  overflow: hidden;
}

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

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------- 布局 ---------------- */

.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  height: 100dvh;
  background: var(--bg);
}

.app.sources-open {
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr) var(--sources-w);
}

/* ---------------- 侧边栏 ---------------- */

.sider {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-sunken);
  border-right: 1px solid var(--border);
}

.sider-head {
  padding: var(--space-4) var(--space-3) var(--space-2);
}

.sider-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-2) var(--space-2) var(--space-4);
}

.sider-list-group {
  padding: var(--space-3) var(--space-2) var(--space-1);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}

.session-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  line-height: 1.4;
}

.session-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.session-item.is-active {
  background: var(--bg-elevated);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font-weight: 500;
}

.session-item-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item-actions {
  display: none;
  gap: 2px;
}

.session-item:hover .session-item-actions,
.session-item:focus-within .session-item-actions {
  display: flex;
}

.session-item-menu {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  border-radius: 6px;
  padding: 2px 5px;
  font-size: 13px;
  line-height: 1;
}

.session-item-menu:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sider-foot {
  padding: var(--space-2) var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}

.sider-mask {
  display: none;
}

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

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  flex: 0 0 auto;
}

.topbar-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: text;
}

.topbar-title[contenteditable="true"] {
  outline: 2px solid var(--accent);
  border-radius: 4px;
  padding: 0 4px;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
}

.topbar-tools::-webkit-scrollbar {
  display: none;
}

/* ---------------- 控件 ---------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
  white-space: nowrap;
}

.btn:hover:not(:disabled) {
  background: var(--bg-hover);
}

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

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

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-muted);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.btn-block {
  width: 100%;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 15px;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  flex: 0 0 auto;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.select,
.input {
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  max-width: 100%;
}

.input {
  width: 100%;
}

.textarea {
  resize: vertical;
  min-height: 76px;
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.toggle .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--border-strong);
  transition: background var(--transition);
}

.toggle[aria-pressed="true"] {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

.toggle[aria-pressed="true"] .dot {
  background: var(--accent);
}

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

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: var(--space-4);
  font-size: 14px;
}

.field > span {
  font-weight: 500;
}

.field small {
  color: var(--text-faint);
  font-size: 12px;
  line-height: 1.5;
}

.field-inline {
  display: inline-flex;
  align-items: center;
}

/* ---------------- 消息区 ---------------- */

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-behavior: smooth;
}

.message-column {
  max-width: var(--content-w);
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.message {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  animation: rise 220ms ease-out both;
}

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

.message-user {
  align-items: flex-end;
}

.message-user .bubble {
  background: var(--user-bubble);
  color: var(--user-bubble-text);
  border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
  max-width: min(78%, 620px);
  padding: 10px 14px;
  white-space: pre-wrap;
  word-break: break-word;
}

body[data-position="left"] .message-user {
  align-items: flex-start;
}

body[data-position="left"] .message-user .bubble {
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-lg) 4px;
}

body[data-position="full"] .message-user .bubble {
  max-width: 100%;
  width: 100%;
}

.message-assistant {
  align-items: stretch;
}

.bubble-assistant {
  max-width: 100%;
}

.message-role {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-faint);
  letter-spacing: 0.03em;
}

.message-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  opacity: 0;
  transition: opacity var(--transition);
}

.message:hover .message-actions,
.message:focus-within .message-actions {
  opacity: 1;
}

.act {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
}

.act:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.act:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.branch-switch {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 12.5px;
  color: var(--text-muted);
}

.branch-switch button {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 2px 5px;
  border-radius: 5px;
}

.branch-switch button:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text);
}

.branch-switch button:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

/* 思考过程 */
.thinking {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  overflow: hidden;
}

.thinking > summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-muted);
  list-style: none;
  user-select: none;
}

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

.thinking > summary::before {
  content: "▸";
  font-size: 11px;
  transition: transform var(--transition);
}

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

.thinking-body {
  padding: 0 12px 12px;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13.5px;
}

/* 工具调用 */
.tool-step {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: 8px 12px;
  font-size: 13px;
  color: var(--text-muted);
}

.tool-step-head {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.tool-step-name {
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--text);
}

.tool-badge {
  margin-left: auto;
  font-size: 11.5px;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--bg-hover);
}

.tool-badge.is-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.tool-step pre {
  margin: 8px 0 0;
  padding: 10px;
  border-radius: var(--radius-sm);
  background: var(--bg-code);
  font-family: var(--font-mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow: auto;
}

/* 搜索步骤 */
.search-step {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  padding: 2px 0;
}

.search-step .spinner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  animation: spin 700ms linear infinite;
}

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

/* 来源引用 */
.cite {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  margin: 0 2px;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  vertical-align: super;
  cursor: pointer;
  border: none;
  font-family: var(--font-sans);
}

.cite:hover {
  background: var(--accent);
  color: #fff;
}

.source-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--space-2);
}

.source-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 260px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 12.5px;
  text-decoration: none;
  cursor: pointer;
}

.source-chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.source-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 附件 */
.msg-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.msg-attachment {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  padding: 6px 10px;
  font-size: 12.5px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}

.msg-attachment img {
  max-width: 180px;
  max-height: 180px;
  border-radius: 6px;
  display: block;
}

/* 提示条 */
.notice {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13.5px;
}

.notice.is-info {
  background: var(--accent-soft);
  color: var(--accent);
}

/* 编辑态 */
.edit-box {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: 100%;
}

.edit-box textarea {
  width: 100%;
  min-height: 76px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--accent);
  background: var(--bg-elevated);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
}

.edit-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}

/* 空状态 */
.welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  min-height: 60vh;
  text-align: center;
  color: var(--text-muted);
}

.welcome h2 {
  margin: 0;
  font-size: 22px;
  color: var(--text);
}

.welcome-suggestions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--space-3);
  width: 100%;
  max-width: 680px;
  margin-top: var(--space-3);
}

.suggestion {
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  color: var(--text-muted);
  font-size: 13.5px;
  cursor: pointer;
  text-align: left;
  font-family: inherit;
}

.suggestion:hover {
  border-color: var(--accent);
  color: var(--text);
}

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

.composer-wrap {
  flex: 0 0 auto;
  padding: 0 var(--space-4) var(--space-3);
  background: linear-gradient(to bottom, transparent, var(--bg) 24%);
}

.composer {
  max-width: var(--content-w);
  margin: 0 auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.composer:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.composer-field {
  position: relative;
}

.composer-input {
  display: block;
  width: 100%;
  max-height: 260px;
  min-height: 52px;
  padding: 14px 16px 6px;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.6;
  resize: none;
  outline: none;
  overflow-y: auto;
}

.composer-input.is-hidden {
  visibility: hidden;
}

.spectrum {
  position: absolute;
  left: 16px;
  right: 12px;
  top: 16px;
  height: 30px;
  width: calc(100% - 28px);
  opacity: 0.75;
  pointer-events: none;
}

.drag-mask {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 14px;
  pointer-events: none;
}

.composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: 6px 10px 10px 8px;
}

.composer-left,
.composer-right {
  display: flex;
  align-items: center;
  gap: 4px;
}

.hint {
  font-size: 12px;
  color: var(--text-faint);
}

.voice-timer {
  font-size: 12px;
  color: var(--danger);
  font-variant-numeric: tabular-nums;
}

.draft-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 12px 0;
}

.draft-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: 12.5px;
  color: var(--text-muted);
  max-width: 220px;
}

.draft-chip span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.draft-chip button {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  padding: 0 2px;
}

.draft-chip button:hover {
  color: var(--danger);
}

.disclaimer {
  max-width: var(--content-w);
  margin: 6px auto 0;
  font-size: 12px;
  color: var(--text-faint);
  text-align: center;
}

/* ---------------- 来源面板 ---------------- */

.sources {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--border);
  background: var(--bg-sunken);
}

.sources-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px var(--space-4);
  border-bottom: 1px solid var(--border);
}

.sources-head h2 {
  margin: 0;
  font-size: 14px;
}

.sources-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-3);
}

.source-card {
  display: block;
  padding: 10px 12px;
  margin-bottom: 8px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  text-decoration: none;
  color: inherit;
}

.source-card:hover {
  border-color: var(--accent);
}

.source-card-title {
  font-size: 13.5px;
  font-weight: 500;
  margin-bottom: 4px;
}

.source-card-meta {
  font-size: 12px;
  color: var(--text-faint);
  margin-bottom: 4px;
}

.source-card-snippet {
  font-size: 12.5px;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------------- 工作区抽屉 ---------------- */

.workspace {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(420px, 92vw);
  z-index: 40;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--border);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
}

.workspace-body {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.workspace-tree {
  flex: 0 1 45%;
  min-height: 120px;
  overflow-y: auto;
  padding: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.workspace-file {
  flex: 1 1 55%;
  min-height: 0;
  overflow: auto;
  margin: 0;
  padding: var(--space-3);
  background: var(--bg-code);
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.workspace-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}

.workspace-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.workspace-item.is-dir {
  color: var(--text-faint);
}

.workspace-empty {
  padding: var(--space-3);
  font-size: 13px;
  color: var(--text-faint);
  text-align: center;
}

/* ---------------- Markdown ---------------- */

.md {
  font-size: 15px;
  line-height: 1.75;
  word-break: break-word;
}

.md > *:first-child {
  margin-top: 0;
}

.md > *:last-child {
  margin-bottom: 0;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  margin: 1.2em 0 0.5em;
  line-height: 1.35;
  font-weight: 650;
}

.md h1 {
  font-size: 1.5em;
}
.md h2 {
  font-size: 1.32em;
}
.md h3 {
  font-size: 1.16em;
}
.md h4 {
  font-size: 1.04em;
}

.md p {
  margin: 0.7em 0;
}

.md ul,
.md ol {
  margin: 0.6em 0;
  padding-left: 1.5em;
}

.md li {
  margin: 0.25em 0;
}

.md li.task-item {
  list-style: none;
  margin-left: -1.2em;
}

.md blockquote {
  margin: 0.8em 0;
  padding: 2px 0 2px 14px;
  border-left: 3px solid var(--border-strong);
  color: var(--text-muted);
}

.md code {
  padding: 0.15em 0.4em;
  border-radius: 5px;
  background: var(--bg-code);
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.md pre {
  margin: 0.8em 0;
}

.md table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.94em;
}

.md th,
.md td {
  border: 1px solid var(--border);
  padding: 7px 10px;
  text-align: left;
}

.md th {
  background: var(--bg-sunken);
  font-weight: 600;
}

.md table-wrap {
  overflow-x: auto;
}

.md hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 1.4em 0;
}

.md a {
  color: var(--accent);
  text-decoration: none;
}

.md a:hover {
  text-decoration: underline;
}

.md img {
  max-width: 100%;
  border-radius: var(--radius-sm);
}

/* 代码块 */
.code-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-code);
  overflow: hidden;
}

.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px 5px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sunken);
  font-size: 12px;
  color: var(--text-faint);
}

.code-head .lang {
  font-family: var(--font-mono);
}

.code-block pre {
  margin: 0;
  padding: 12px 14px;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.code-block .copy {
  border: none;
  background: transparent;
  color: inherit;
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 5px;
  font-size: 12px;
  font-family: inherit;
}

.code-block .copy:hover {
  background: var(--bg-hover);
  color: var(--text);
}

/* 语法高亮 token */
.tok-keyword {
  color: var(--code-keyword);
}
.tok-string {
  color: var(--code-string);
}
.tok-number {
  color: var(--code-number);
}
.tok-comment {
  color: var(--code-comment);
  font-style: italic;
}
.tok-function {
  color: var(--code-func);
}
.tok-punct {
  color: var(--code-punct);
}
.tok-tag {
  color: var(--code-keyword);
}
.tok-attr {
  color: var(--code-func);
}

/* 公式 */
.math-block {
  overflow-x: auto;
  text-align: center;
  margin: 0.9em 0;
}

.math-error {
  color: var(--danger);
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* Mermaid */
.mermaid-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: var(--space-3);
  overflow-x: auto;
  text-align: center;
}

.mermaid-wrap svg {
  max-width: 100%;
  height: auto;
}

/* ---------------- 弹窗 / 提示 ---------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.modal-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(680px, 100%);
  max-height: min(86dvh, 760px);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: pop 180ms ease-out both;
}

@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  margin: 0;
  font-size: 16px;
}

.modal-nav {
  display: flex;
  gap: var(--space-1);
  padding: var(--space-2) var(--space-4) 0;
  border-bottom: 1px solid var(--border);
}

.modal-nav-item {
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 14px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.modal-nav-item.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-4);
}

.tab-panel {
  display: none;
}

.tab-panel.is-active {
  display: block;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border-top: 1px solid var(--border);
}

.row {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}

.toast-host {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  padding: 9px 16px;
  border-radius: var(--radius-pill);
  background: var(--text);
  color: var(--bg);
  font-size: 13.5px;
  box-shadow: var(--shadow);
  animation: rise 200ms ease-out both;
}

.toast.is-error {
  background: var(--danger);
  color: #fff;
}

/* ---------------- 响应式 ---------------- */

.only-mobile {
  display: none;
}

@media (max-width: 1023px) {
  .app.sources-open {
    grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  }

  .sources {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(340px, 88vw);
    z-index: 40;
    box-shadow: var(--shadow);
  }
}

@media (max-width: 767px) {
  .app,
  .app.sources-open {
    grid-template-columns: minmax(0, 1fr);
  }

  .only-mobile {
    display: inline-flex;
  }

  .sider {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 86vw);
    z-index: 45;
    transform: translateX(-100%);
    transition: transform 220ms cubic-bezier(0.4, 0, 0.2, 1);
  }

  .app.sider-open .sider {
    transform: translateX(0);
  }

  .sider-mask {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 44;
    background: rgba(15, 23, 42, 0.4);
  }

  .message-column {
    padding: var(--space-4) var(--space-3) var(--space-3);
    gap: var(--space-4);
  }

  .message-user .bubble {
    max-width: 88%;
  }

  .topbar {
    padding: 8px var(--space-3);
  }

  .topbar .select {
    max-width: 132px;
  }

  .topbar-title {
    font-size: 14px;
  }

  .topbar-tools {
    gap: 6px;
  }

  .toggle span:not(.dot) {
    display: none;
  }

  .toggle {
    padding: 5px 8px;
  }

  .composer-wrap {
    padding: 0 var(--space-2) var(--space-2);
  }

  .sources {
    width: 100vw;
  }

  .modal {
    align-items: flex-end;
    padding: 0;
  }

  .modal-panel {
    width: 100%;
    max-height: 92dvh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .message-actions {
    opacity: 1;
  }
}

@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;
  }
}
