* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

:root {
  --bg:        #f5f5f7;
  --card:      #ffffff;
  --text:      #1c1c1e;
  --text-dim:  #8e8e93;
  --line:      #e5e5ea;
  --blue:      #007aff;
  --green:     #34c759;
  --red:       #ff3b30;
  --yellow:    #ff9500;
  --topbar-h:  48px;
}

html, body { height: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
               "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior-y: none;
}

/* ── 整体布局：左侧栏 + 右侧主区 ────────────────────────── */
.layout {
  display: flex;
  height: 100%;
  overflow: hidden;
}

/* ── 侧栏 ──────────────────────────────────────────────── */
.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .2s ease;
}
.layout.collapsed .sidebar { width: 0; border-right: none; }

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  height: var(--topbar-h);
  padding: 0 8px 0 14px;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.sidebar-head .brand {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.collapse-btn {
  width: 26px; height: 26px;
  flex-shrink: 0;
  border: none; border-radius: 7px;
  background: #f2f2f7; color: var(--text-dim);
  font-size: 15px; line-height: 1;
  cursor: pointer;
}
.collapse-btn:hover { background: #e5e5ea; color: var(--text); }

/* 导航项 */
.nav { padding: 8px; overflow-y: auto; flex: 1; }
.nav button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 4px;
  border: none;
  border-radius: 9px;
  background: none;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav button:hover { background: #f2f2f7; }
.nav button.active { background: #e8f2ff; color: var(--blue); font-weight: 600; }
.nav .icon { font-size: 17px; line-height: 1; flex-shrink: 0; }

/* ── 主区 ──────────────────────────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.topbar {
  height: var(--topbar-h);
  flex-shrink: 0;
  background: rgba(255,255,255,.85);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  font-size: 16px;
  font-weight: 600;
}
/* 侧栏收起后才显示展开按钮，展开时按钮隐藏（收起按钮在侧栏内） */
.menu-btn {
  position: absolute;
  left: 10px;
  width: 34px; height: 34px;
  border: none; border-radius: 8px;
  background: none; color: var(--text);
  font-size: 17px; cursor: pointer;
  display: none;
}
.menu-btn:hover { background: #f2f2f7; }
.layout.collapsed .menu-btn { display: block; }

/* ── 内容区：每个 tab 独立滚动 ───────────────────────────── */
.content {
  flex: 1;
  overflow: hidden;
  position: relative;
}
.tab-pane {
  display: none;
  height: 100%;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px 24px;
}
.tab-pane.active { display: block; }

/* 对话 tab 需要铺满、自己管理内部滚动 */
.tab-pane.chat-pane { padding: 0; overflow: hidden; }


/* ── 通用卡片 / 表单 ────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.card > label {
  display: block;
  font-size: 13px; font-weight: 500; color: var(--text-dim);
  margin-bottom: 8px;
}
textarea, select, input[type=text] {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 9px;
  font-size: 15px; font-family: inherit;
  background: #fafafa; color: var(--text);
}
textarea { min-height: 88px; resize: vertical; line-height: 1.5; }
textarea:focus, select:focus { outline: 2px solid var(--blue); outline-offset: -1px; }

.btn {
  width: 100%; padding: 13px;
  border: none; border-radius: 10px;
  font-size: 16px; font-weight: 600; font-family: inherit;
  background: var(--blue); color: #fff;
  cursor: pointer;
  transition: opacity .15s;
}
.btn:active { opacity: .75; }
.btn:disabled { background: #c7c7cc; cursor: not-allowed; }
.btn-danger { background: var(--red); }
.btn-success { background: var(--green); }
.btn-sm { padding: 9px; font-size: 14px; }

/* ── 上传区 ────────────────────────────────────────────── */
.upload-area {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 22px;
  text-align: center;
  color: var(--text-dim);
  font-size: 14px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.upload-area:hover, .upload-area.dragover { border-color: var(--blue); color: var(--blue); }
.upload-area input { display: none; }

.previews { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.preview-item { position: relative; width: 72px; height: 72px; }
.preview-item img {
  width: 72px; height: 72px; object-fit: cover;
  border-radius: 8px; border: 1px solid var(--line);
}
.preview-item .del {
  position: absolute; top: -5px; right: -5px;
  width: 20px; height: 20px;
  background: var(--red); color: #fff;
  border: 2px solid #fff; border-radius: 50%;
  font-size: 12px; line-height: 1; cursor: pointer;
}

/* ── 状态 / 结果 ───────────────────────────────────────── */
.status-box { text-align: center; padding: 10px 0; }
.spinner {
  display: inline-block; width: 28px; height: 28px;
  border: 3px solid var(--line); border-top-color: var(--blue);
  border-radius: 50%; animation: spin .8s linear infinite;
  margin-bottom: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.elapsed { font-size: 12px; color: var(--text-dim); margin-top: 4px; }
.result-img { width: 100%; border-radius: 10px; display: block; }
.error-text {
  color: var(--red); font-size: 14px;
  padding: 8px 0; word-break: break-word; white-space: pre-wrap;
}
.muted-text { color: var(--text-dim); font-size: 14px; padding: 8px 0; }

/* ── 过程日志面板 ──────────────────────────────────────── */
.log-panel {
  margin-top: 10px;
  background: #1c1c1e; color: #d4d4d4;
  border-radius: 9px; padding: 10px;
  font-family: Menlo, Consolas, "Courier New", monospace;
  font-size: 11.5px; line-height: 1.6;
  max-height: 200px; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  text-align: left;
}
.log-line { white-space: pre-wrap; word-break: break-all; }
.log-ts { color: #61afef; }
.log-line.lvl-info    { color: #98c379; }
.log-line.lvl-debug   { color: #7f848e; }
.log-line.lvl-warning { color: #e5c07b; }
.log-line.lvl-error   { color: #e06c75; }

/* ── 空状态 ────────────────────────────────────────────── */
.empty {
  text-align: center; padding: 48px 20px;
  color: var(--text-dim); font-size: 14px;
}
.empty .icon { font-size: 40px; display: block; margin-bottom: 10px; opacity: .4; }

/* ── 对话 tab ──────────────────────────────────────────── */
.chat-wrap {
  display: flex; flex-direction: column;
  height: 100%;
}

.chat-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.chat-toolbar select {
  flex: 1; padding: 7px 10px; font-size: 14px;
}

/* 联网搜索开关 */
.chat-toolbar .web-toggle {
  flex-shrink: 0;
  padding: 7px 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fafafa;
  color: var(--text-dim);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s, color .15s, border-color .15s;
}
.chat-toolbar .web-toggle:hover { border-color: #c7c7cc; }
.chat-toolbar .web-toggle.on {
  background: #e8f2ff;
  border-color: var(--blue);
  color: var(--blue);
  font-weight: 600;
}
.chat-toolbar .web-toggle:disabled { opacity: .5; cursor: not-allowed; }

/* 会话标签页栏（IDE 风格，可拖拽排序） */
.session-tabs {
  display: flex;
  align-items: stretch;
  gap: 3px;
  padding: 6px 8px 0;
  background: #ececf0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  flex-shrink: 0;
  -webkit-overflow-scrolling: touch;
}
.session-tabs::-webkit-scrollbar { height: 4px; }
.session-tabs::-webkit-scrollbar-thumb { background: #c7c7cc; border-radius: 2px; }

.session-tab {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  max-width: 190px;
  padding: 7px 9px 7px 12px;
  border-radius: 8px 8px 0 0;
  background: #dcdce1;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: relative;
  transition: background .12s, color .12s;
}
.session-tab:hover { background: #d2d2d8; }
.session-tab.active {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
}
.session-tab .t {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
  pointer-events: none;   /* 拖拽时以整个标签为判定目标 */
}
.session-tab .d {
  flex-shrink: 0;
  width: 17px; height: 17px;
  border: none; border-radius: 5px;
  background: none; color: inherit;
  font-size: 13px; line-height: 1;
  cursor: pointer; opacity: .55;
}
.session-tab .d:hover { background: rgba(0,0,0,.12); opacity: 1; }

/* 拖拽中的标签与会跟随的替身 */
.session-tab.dragging { opacity: .35; }
.session-tab.ghost {
  position: fixed;
  z-index: 999;
  pointer-events: none;
  opacity: .9;
  box-shadow: 0 4px 14px rgba(0,0,0,.22);
  background: var(--card);
  color: var(--text);
}
/* 插入位置指示线 */
.session-tab.drop-before::before,
.session-tab.drop-after::after {
  content: '';
  position: absolute;
  top: 3px; bottom: 3px;
  width: 2px;
  background: var(--blue);
  border-radius: 1px;
}
.session-tab.drop-before::before { left: -2px; }
.session-tab.drop-after::after { right: -2px; }

/* 新建会话按钮紧跟标签之后 */
.session-tabs .new-tab {
  flex: 0 0 auto;
  align-self: center;
  width: 26px; height: 26px;
  margin-left: 2px;
  border: none; border-radius: 7px;
  background: none; color: var(--text-dim);
  font-size: 17px; line-height: 1;
  cursor: pointer;
}
.session-tabs .new-tab:hover { background: #d2d2d8; color: var(--text); }

/* 消息流 */
.chat-messages {
  flex: 1; overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 16px;
  font-size: 15px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word;
}
.msg.user {
  align-self: flex-end;
  background: var(--blue); color: #fff;
  border-bottom-right-radius: 5px;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--card); color: var(--text);
  border-bottom-left-radius: 5px;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.msg.error {
  align-self: stretch; max-width: 100%;
  background: #ffeaea; color: var(--red);
  font-size: 13px;
}
.msg img.att {
  display: block; max-width: 180px; border-radius: 10px;
  margin-bottom: 6px;
}
.msg .meta {
  font-size: 11px; opacity: .6; margin-top: 4px;
}

/* 输入区 */
.chat-input {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  background: var(--card);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom));
}
.chat-input .att-strip {
  display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 6px;
}
.chat-input .att-strip:empty { display: none; }
.att-chip { position: relative; width: 48px; height: 48px; }
.att-chip img { width: 48px; height: 48px; object-fit: cover; border-radius: 8px; }
.att-chip button {
  position: absolute; top: -5px; right: -5px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--red); color: #fff;
  border: 2px solid #fff; font-size: 11px; line-height: 1;
  cursor: pointer;
}
.chat-input .row { display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea {
  flex: 1; min-height: 40px; max-height: 120px;
  padding: 9px 12px; font-size: 15px;
}
.chat-input .send {
  padding: 10px 16px; border-radius: 10px;
  border: none; background: var(--blue); color: #fff;
  font-size: 15px; font-weight: 600; cursor: pointer;
  white-space: nowrap;
}
.chat-input .send:disabled { background: #c7c7cc; cursor: not-allowed; }
.chat-input .icon-btn {
  padding: 9px 11px; border-radius: 10px;
  border: 1px solid var(--line); background: #fafafa;
  font-size: 17px; cursor: pointer; line-height: 1;
}

/* ── 登录页 ────────────────────────────────────────────── */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100%;
  padding: 20px;
  background: var(--bg);
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--card);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 4px 24px rgba(0,0,0,.08);
}

.auth-logo {
  text-align: center;
  font-size: 34px;
  margin-bottom: 10px;
}

.auth-title {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 6px;
}

.auth-sub {
  font-size: 13px;
  color: var(--text-dim);
  text-align: center;
  margin-bottom: 22px;
  line-height: 1.5;
}

.auth-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-dim);
  margin: 14px 0 6px;
}
.auth-label:first-of-type { margin-top: 0; }

.auth-card input[type=text],
.auth-card input[type=password] {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 15px;
  font-family: inherit;
  background: #fafafa;
  color: var(--text);
}
.auth-card input:focus {
  outline: 2px solid var(--blue);
  outline-offset: -1px;
  background: #fff;
}

.auth-card .btn { margin-top: 22px; }

.auth-error {
  margin-top: 14px;
  padding: 9px 12px;
  border-radius: 8px;
  background: #ffeaea;
  color: var(--red);
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}

.auth-foot {
  margin-top: 18px;
  text-align: center;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
}
.auth-foot a {
  color: var(--blue);
  text-decoration: none;
  cursor: pointer;
}

/* 侧栏底部：当前用户 + 登出 */
.sidebar-user {
  flex-shrink: 0;
  border-top: 1px solid var(--line);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.sidebar-user .name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-dim);
}
.sidebar-user .out {
  flex-shrink: 0;
  padding: 5px 9px;
  border: none;
  border-radius: 7px;
  background: #f2f2f7;
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.sidebar-user .out:hover { background: #ffeaea; color: var(--red); }

/* ── 管理页 ────────────────────────────────────────────── */
.admin-page {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
}

.admin-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 2px 16px;
}
.admin-head .back {
  color: var(--blue);
  text-decoration: none;
  font-size: 15px;
  white-space: nowrap;
}
.admin-head .title {
  font-size: 17px;
  font-weight: 600;
  flex: 1;
}

.admin-page .hint {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.6;
  margin-bottom: 14px;
}

/* 新生成的邀请码 */
.new-code {
  margin-top: 14px;
  padding: 12px;
  border-radius: 10px;
  background: #e8f2ff;
  text-align: center;
}
.new-code .label {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.new-code code {
  display: block;
  font-family: Menlo, Consolas, monospace;
  font-size: 17px;
  font-weight: 600;
  color: var(--blue);
  letter-spacing: .5px;
  word-break: break-all;
  user-select: all;   /* 便于一键全选复制 */
}
.new-code .copy {
  margin-top: 10px;
  padding: 7px 14px;
  border: none;
  border-radius: 8px;
  background: var(--blue);
  color: #fff;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
}

/* 邀请码列表 */
.invite-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.invite-row:last-child { border-bottom: none; }

.invite-row .code {
  font-family: Menlo, Consolas, monospace;
  font-size: 13px;
  flex-shrink: 0;
}
.invite-row .meta {
  flex: 1;
  font-size: 12px;
  color: var(--text-dim);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.invite-row .del {
  flex-shrink: 0;
  width: 26px; height: 26px;
  border: none; border-radius: 7px;
  background: #f2f2f7;
  color: var(--text-dim);
  font-size: 14px; line-height: 1;
  cursor: pointer;
}
.invite-row .del:hover { background: #ffeaea; color: var(--red); }

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 11px;
  flex-shrink: 0;
}
.badge.used { background: #f2f2f7; color: var(--text-dim); }
.badge.free { background: #e5f7ea; color: #1a8a3c; }

/* 侧栏入口 */
.sidebar-user .admin-link {
  flex-shrink: 0;
  padding: 5px 9px;
  border: none;
  border-radius: 7px;
  background: #f2f2f7;
  color: var(--text-dim);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.sidebar-user .admin-link:hover { background: #e8f2ff; color: var(--blue); }

/* ── 图片浮层 ──────────────────────────────────────────── */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(0,0,0,.92);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 48px 12px 12px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.lightbox.open { display: flex; }

.lightbox .lb-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 44px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: linear-gradient(rgba(0,0,0,.6), transparent);
  z-index: 1;
}
.lightbox .lb-hint {
  flex: 1;
  color: rgba(255,255,255,.65);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lightbox .lb-close {
  width: 32px; height: 32px;
  flex-shrink: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}
.lightbox .lb-close:hover { background: rgba(255,255,255,.28); }

.lightbox .lb-img {
  max-width: 100%;
  max-height: calc(100vh - 60px);
  object-fit: contain;
  border-radius: 6px;
  cursor: zoom-in;
  transition: transform .18s ease;
  transform-origin: center center;
}

/* 页面里可点击放大的图片 */
img[data-lightbox] { cursor: zoom-in; }

/* ── 管理页 tab ────────────────────────────────────────── */
.admin-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
}
.admin-tabs button {
  flex: 1;
  padding: 9px;
  border: none;
  border-radius: 9px;
  background: #ececf0;
  color: var(--text-dim);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.admin-tabs button.active {
  background: var(--card);
  color: var(--text);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.admin-pane { display: none; }
.admin-pane.active { display: block; }

/* 使用记录 */
.usage-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.usage-filter label { margin: 0; flex-shrink: 0; }
.usage-filter select { flex: 1; padding: 7px 10px; font-size: 14px; }

.stat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.stat-row:last-child { border-bottom: none; }
.stat-row .feat { flex: 1; font-weight: 500; }
.stat-row .num { color: var(--text-dim); font-size: 13px; }
.stat-row .num b { color: var(--text); }

.usage-row {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.usage-row:last-child { border-bottom: none; }
.usage-row .head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 3px;
}
.usage-row .feat {
  font-weight: 600;
  font-size: 13px;
}
.usage-row .who {
  color: var(--text-dim);
  font-size: 12px;
}
.usage-row .time {
  margin-left: auto;
  color: var(--text-dim);
  font-size: 12px;
  flex-shrink: 0;
}
.usage-row .detail {
  color: var(--text-dim);
  font-size: 12px;
  font-family: Menlo, Consolas, monospace;
  word-break: break-all;
  line-height: 1.5;
}

.badge.ok      { background: #e5f7ea; color: #1a8a3c; }
.badge.failed  { background: #ffeaea; color: var(--red); }
.badge.cancel  { background: #f2f2f7; color: var(--text-dim); }

/* ── 助手消息里的 Markdown ─────────────────────────────── */
.msg.assistant .md > *:first-child { margin-top: 0; }
.msg.assistant .md > *:last-child { margin-bottom: 0; }

.msg.assistant .md p { margin: 0 0 8px; }
.msg.assistant .md h1,
.msg.assistant .md h2,
.msg.assistant .md h3,
.msg.assistant .md h4,
.msg.assistant .md h5,
.msg.assistant .md h6 {
  margin: 12px 0 6px;
  font-weight: 600;
  line-height: 1.35;
}
.msg.assistant .md h1 { font-size: 17px; }
.msg.assistant .md h2 { font-size: 16px; }
.msg.assistant .md h3 { font-size: 15px; }
.msg.assistant .md h4,
.msg.assistant .md h5,
.msg.assistant .md h6 { font-size: 14px; }

.msg.assistant .md ul,
.msg.assistant .md ol {
  margin: 6px 0 10px;
  padding-left: 22px;
}
.msg.assistant .md li { margin: 3px 0; }

.msg.assistant .md strong { font-weight: 600; }
.msg.assistant .md del { opacity: .6; }

.msg.assistant .md code {
  background: rgba(0,0,0,.06);
  padding: 1px 5px;
  border-radius: 4px;
  font-family: Menlo, Consolas, monospace;
  font-size: 12.5px;
  word-break: break-word;
}
.msg.assistant .md pre {
  background: #1c1c1e;
  color: #d4d4d4;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
  -webkit-overflow-scrolling: touch;
}
.msg.assistant .md pre code {
  background: none;
  padding: 0;
  color: inherit;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
}

.msg.assistant .md blockquote {
  margin: 8px 0;
  padding: 2px 0 2px 10px;
  border-left: 3px solid var(--line);
  color: var(--text-dim);
}

.msg.assistant .md hr {
  border: none;
  border-top: 1px solid var(--line);
  margin: 12px 0;
}

.msg.assistant .md a {
  color: var(--blue);
  text-decoration: none;
  word-break: break-all;
}
.msg.assistant .md a:active { text-decoration: underline; }

.msg.assistant .md table {
  width: 100%;
  border-collapse: collapse;
  margin: 8px 0;
  font-size: 13px;
  display: block;
  overflow-x: auto;       /* 手机上宽表格可横向滚动 */
  -webkit-overflow-scrolling: touch;
}
.msg.assistant .md th,
.msg.assistant .md td {
  border: 1px solid var(--line);
  padding: 6px 9px;
  text-align: left;
  white-space: nowrap;
}
.msg.assistant .md th {
  background: #f7f7f9;
  font-weight: 600;
}

/* Markdown 里的图片 */
.msg.assistant .md-img {
  display: block;
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  margin: 8px 0;
  background: #f2f2f7;      /* 图片加载前的占位底色 */
}
/* 表格单元格内的图片缩小显示，避免撑破表格 */
.msg.assistant .md td .md-img,
.msg.assistant .md th .md-img {
  max-width: 120px;
  margin: 0;
  border-radius: 5px;
}
