/* ===========================================================
 * Agent · 豆包浅色风格
 * =========================================================== */
:root {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --border: #ebedf0;
  --border-soft: #f2f3f5;
  --text: #1d2129;
  --text-2: #4e5969;
  --dim: #86909c;
  --dim-2: #c9cdd4;
  --accent: #4080ff;
  --accent-soft: #e8f0ff;
  --green: #00b42a;
  --yellow: #ff7d00;
  --red: #f53f3f;
  --user-bg: #f2f3f5;
  --code-bg: #f5f6f8;
  --code-border: #e5e6eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; height: 100%;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
}
body {
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", "Microsoft YaHei", Arial, sans-serif;
  display: flex; flex-direction: column;
  height: 100dvh;
}

/* ============ 顶部栏 ============ */
header {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  padding-top: calc(6px + env(safe-area-inset-top));
  background: var(--panel);
  border-bottom: 1px solid var(--border-soft);
  flex: 0 0 auto;
}

/* 左上品牌区(固定) */
.brand-fixed {
  display: flex; align-items: center; gap: 6px;
  padding: 0 6px;
}
.brand-fixed .brand-logo {
  font-size: 22px;
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #fff5ee 0%, #ffe4d4 100%);
  border-radius: 10px;
  border: 1px solid #ffe0cc;
}
.brand-fixed .brand-name {
  font-size: 16px; font-weight: 700;
  letter-spacing: 0.3px;
  color: var(--text);
}

/* 中间会话信息 */
.conv-meta {
  display: flex; flex-direction: column; align-items: center;
  min-width: 0; gap: 2px;
}
.conv-title-bar {
  font-size: 14px; font-weight: 500; color: var(--text);
  max-width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.header-actions { display: flex; gap: 2px; }

@media (max-width: 480px) {
  .brand-fixed { gap: 4px; padding: 0 2px; }
  .brand-fixed .brand-logo { width: 28px; height: 28px; font-size: 18px; }
  .brand-fixed .brand-name { display: none; }   /* 手机端只留 logo + 菜单按钮 */
  .conv-title-bar { font-size: 13px; }
}

/* ============ 侧边栏 ============ */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: 280px; max-width: 80vw;
  background: var(--panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 200;
  transform: translateX(0);
  transition: transform 0.25s ease;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.08);
}
.sidebar.hidden { transform: translateX(-100%); }
.sidebar-mask {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 150;
  opacity: 1;
  transition: opacity 0.2s ease;
}
.sidebar-mask.hidden { opacity: 0; pointer-events: none; }

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border-soft);
}
.sidebar-logo {
  font-size: 16px; font-weight: 600;
}

.sidebar-new {
  margin: 12px 12px 6px;
  padding: 11px 14px;
  background: var(--text); color: var(--panel);
  border: 0; border-radius: 12px; cursor: pointer;
  font-size: 14px; font-weight: 500;
  display: flex; align-items: center; gap: 8px;
  transition: opacity 0.15s ease;
}
.sidebar-new:hover { opacity: 0.86; }
.sidebar-new:active { opacity: 0.7; }

.sidebar-section-title {
  font-size: 11px; color: var(--dim);
  padding: 14px 16px 6px;
  letter-spacing: 0.5px;
}

.conv-list {
  flex: 1 1 auto; overflow-y: auto;
  padding: 0 6px 12px;
}
.conv-item {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 10px; margin: 1px 0;
  border-radius: 10px; cursor: pointer;
  font-size: 14px; color: var(--text-2);
  transition: background 0.12s ease;
  position: relative;
}
.conv-item:hover { background: var(--border-soft); }
.conv-item.active { background: var(--accent-soft); color: var(--accent); }
.conv-item-icon {
  width: 18px; height: 18px; flex: 0 0 18px;
  color: var(--dim);
}
.conv-item.active .conv-item-icon { color: var(--accent); }
.conv-item-title {
  flex: 1 1 auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.conv-item-del {
  width: 24px; height: 24px; flex: 0 0 24px;
  border-radius: 6px; border: 0; background: transparent;
  color: var(--dim); cursor: pointer;
  display: none; place-items: center;
  font-size: 14px;
}
.conv-item:hover .conv-item-del { display: grid; }
.conv-item-del:hover { background: var(--border); color: var(--red); }

@media (min-width: 900px) {
  /* 桌面端可永久显示侧边栏:body 加 .sidebar-pinned 时不挡内容 */
  body.sidebar-pinned .sidebar { transform: translateX(0); position: relative; box-shadow: none; }
  body.sidebar-pinned .sidebar.hidden { display: none; }
  body.sidebar-pinned .sidebar-mask { display: none; }
  body.sidebar-pinned { flex-direction: row; }
  body.sidebar-pinned > header,
  body.sidebar-pinned > #suggestions,
  body.sidebar-pinned > main,
  body.sidebar-pinned > form,
  body.sidebar-pinned > #modelMenu { /* main column */ }
  /* 简化:不做永久固定,移动端/桌面端都用浮层 */
}
.model-picker {
  background: transparent; border: 0; padding: 2px 8px;
  display: inline-flex; align-items: center; gap: 4px;
  border-radius: 999px; cursor: pointer;
  font-size: 11px; color: var(--dim);
  transition: background 0.15s ease;
}
.model-picker:hover { background: var(--border-soft); color: var(--text-2); }
.model-picker:active { background: var(--border); }

/* 模型选项菜单 */
.model-menu {
  position: absolute;
  top: 56px; left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
  padding: 6px; min-width: 240px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  z-index: 100;
}
.model-menu.hidden { display: none; }
.model-option {
  width: 100%; text-align: left;
  background: transparent; border: 0; padding: 9px 12px;
  border-radius: 8px; cursor: pointer;
}
.model-option:hover { background: var(--border-soft); }
.model-option.active { background: var(--accent-soft); }
.model-option .opt-name {
  font-size: 14px; font-weight: 600; color: var(--text);
  display: flex; align-items: center; gap: 6px;
}
.model-option .opt-speed { font-size: 10px; color: var(--accent); }
.model-option .opt-desc {
  font-size: 12px; color: var(--dim); margin-top: 2px;
}

.iconbtn {
  background: transparent; border: 0; color: var(--text-2);
  width: 40px; height: 40px; border-radius: 50%;
  cursor: pointer; display: grid; place-items: center;
  padding: 0;
  transition: background 0.15s ease;
}
.iconbtn:hover { background: var(--border-soft); }
.iconbtn:active { background: var(--border); }
.iconbtn.ghost { color: var(--text-2); }
.iconbtn.round { width: 38px; height: 38px; min-width: 38px; background: var(--border-soft); color: var(--text-2); }
.iconbtn.round:hover { background: var(--border); }
.iconbtn.round.primary { background: var(--accent); color: white; }
.iconbtn.round.primary:hover { background: #2a6df0; }
.iconbtn.round.primary:disabled { background: var(--dim-2); cursor: not-allowed; }
.iconbtn.active { color: var(--accent); }
.iconbtn.active .tts-wave { opacity: 1; }

/* ============ 主体消息流 ============ */
main {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 16px 8px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.hint {
  text-align: center;
  padding: 60px 20px 30px;
  color: var(--dim);
}
.hint-icon { font-size: 56px; margin-bottom: 10px; }
.hint-title { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.hint-sub { font-size: 13px; color: var(--dim); line-height: 1.7; }

.msg { margin-bottom: 18px; max-width: 100%; }
.msg .role { display: none; }

/* 用户消息:浅灰圆角,右对齐 */
.msg.user { display: flex; justify-content: flex-end; }
.msg.user .body {
  background: var(--user-bg);
  padding: 10px 14px;
  border-radius: 16px;
  max-width: 86%;
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
.msg.user .user-atts { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.msg.user .user-atts:empty { display: none; }
.msg.user .user-atts img {
  max-width: 180px; max-height: 180px; border-radius: 10px;
  display: block; object-fit: cover; cursor: pointer;
}
.msg.user .file-chip {
  background: var(--panel); padding: 5px 10px; border-radius: 6px;
  font-size: 12px; color: var(--text-2); text-decoration: none;
  border: 1px solid var(--border);
}
.msg.user .user-text { white-space: pre-wrap; word-break: break-word; }
.msg.user .user-text:empty { display: none; }

/* AI 消息:无气泡,直接排版(豆包风格) */
.msg.thinking .body {
  color: var(--dim); font-size: 13px; font-style: italic;
  padding: 4px 0; line-height: 1.7;
  border-left: 2px solid var(--border); padding-left: 10px;
  margin: 4px 0;
  white-space: pre-wrap;
}
.msg.text .body {
  color: var(--text); font-size: 15px; line-height: 1.7;
  padding: 4px 0;
  position: relative;
}

/* Markdown 内部样式(浅色版) */
.msg.text .body h1, .msg.text .body h2, .msg.text .body h3, .msg.text .body h4 {
  margin: 16px 0 8px; font-weight: 600; line-height: 1.4;
}
.msg.text .body h1 { font-size: 20px; }
.msg.text .body h2 { font-size: 18px; border-bottom: 1px solid var(--border); padding-bottom: 6px; }
.msg.text .body h3 { font-size: 16px; }
.msg.text .body h4 { font-size: 15px; color: var(--text-2); }
.msg.text .body p { margin: 8px 0; }
.msg.text .body ul, .msg.text .body ol { margin: 8px 0; padding-left: 22px; }
.msg.text .body li { margin: 4px 0; }
.msg.text .body code {
  background: var(--code-bg); padding: 2px 6px; border-radius: 4px;
  font-size: 13px; font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
  color: #d4380d;
  border: 1px solid var(--code-border);
}
.msg.text .body pre {
  background: var(--code-bg); padding: 14px 16px;
  border-radius: 10px; overflow-x: auto; margin: 10px 0;
  border: 1px solid var(--code-border);
}
.msg.text .body pre code {
  background: transparent; padding: 0; color: var(--text); border: 0;
  font-size: 13px; line-height: 1.6; display: block; white-space: pre;
}
.msg.text .body blockquote {
  border-left: 3px solid var(--accent); padding-left: 12px;
  color: var(--text-2); margin: 10px 0;
  background: var(--accent-soft); border-radius: 0 8px 8px 0;
  padding-top: 8px; padding-bottom: 8px; padding-right: 12px;
}
.msg.text .body table {
  border-collapse: collapse; margin: 10px 0; font-size: 13px;
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
  width: 100%;
}
.msg.text .body th, .msg.text .body td {
  border-bottom: 1px solid var(--border); padding: 8px 12px; text-align: left;
}
.msg.text .body tr:last-child th, .msg.text .body tr:last-child td { border-bottom: 0; }
.msg.text .body th { background: var(--code-bg); font-weight: 600; }
.msg.text .body a { color: var(--accent); text-decoration: none; }
.msg.text .body a:hover { text-decoration: underline; }
.msg.text .body hr { border: 0; border-top: 1px solid var(--border); margin: 14px 0; }
.msg.text .body strong { color: var(--text); font-weight: 600; }
.msg.text .body em { color: var(--text-2); font-style: italic; }

/* 思考中占位 — 用户点发送的瞬间出现,收到第一个 SSE 事件移除 */
.msg.thinking-placeholder {
  margin: 14px 0 8px;
  padding: 12px 16px;
  display: flex; align-items: center; gap: 12px;
  background: var(--accent-soft);
  border: 1px solid rgba(64, 128, 255, 0.18);
  border-radius: 14px;
  font-size: 14px; color: var(--text-2);
  max-width: fit-content;
}
.msg.thinking-placeholder .ph-fox {
  font-size: 20px;
  animation: foxBounce 1.4s ease-in-out infinite;
}
@keyframes foxBounce {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-3px) rotate(3deg); }
}
.msg.thinking-placeholder .ph-text { color: var(--accent); font-weight: 500; }
.msg.thinking-placeholder .ph-dots {
  display: inline-flex; gap: 3px;
}
.msg.thinking-placeholder .ph-dots span {
  width: 5px; height: 5px; border-radius: 50%; background: var(--accent);
  animation: dotwave 1.2s ease-in-out infinite;
}
.msg.thinking-placeholder .ph-dots span:nth-child(2) { animation-delay: 0.15s; }
.msg.thinking-placeholder .ph-dots span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dotwave {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* 工具调用 — Manus 风格任务卡片(连续 tool 用左侧竖线串联) */
.msg.tool {
  margin: 4px 0;
  position: relative;
  padding-left: 20px;
}
/* 左侧竖线 */
.msg.tool::before {
  content: ''; position: absolute;
  left: 9px; top: -4px; bottom: -4px;
  width: 2px; background: var(--border);
}
/* 第一个 .tool 不要顶部线;最后一个不要底部线 */
.msg.tool + .msg.tool { margin-top: 2px; }
.msg.tool::before { top: 0; }
.msg.tool:not(.msg.tool + .msg.tool)::before { top: 18px; }
/* 圆点 */
.msg.tool::after {
  content: ''; position: absolute;
  left: 5px; top: 18px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--panel);
  border: 2px solid var(--green);
  z-index: 1;
}
.msg.tool[data-state="running"]::after {
  border-color: var(--accent);
  animation: dotpulse2 1.2s ease infinite;
}
@keyframes dotpulse2 {
  0%, 100% { box-shadow: 0 0 0 0 rgba(64, 128, 255, 0.45); }
  50% { box-shadow: 0 0 0 6px rgba(64, 128, 255, 0); }
}
.msg.tool .body {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  background: transparent; border: 0; border-radius: 0;
  font-size: 13px; color: var(--text-2);
  transition: all 0.2s ease;
}
.msg.tool .body .tool-icon {
  width: 22px; height: 22px; flex: 0 0 22px;
  display: grid; place-items: center;
  font-size: 14px;
}
.msg.tool .body .tool-info { flex: 1 1 auto; min-width: 0; }
.msg.tool .body .tool-action { color: var(--dim); font-size: 12px; margin-bottom: 1px; }
.msg.tool .body .tool-arg {
  color: var(--text); font-weight: 500;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  max-width: 100%;
}
.msg.tool .body .tool-status {
  /* 状态点已经迁到 .msg.tool::after,这里隐藏 inline status */
  display: none;
}

/* 可视化占位(流式中) */
.viz-placeholder {
  background: var(--panel); border: 1px dashed var(--border); border-radius: 12px;
  padding: 24px; margin: 10px 0;
  text-align: center; color: var(--dim); font-size: 13px;
}
.viz-placeholder .viz-spinner {
  display: inline-block; width: 14px; height: 14px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite;
  margin-right: 8px; vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* result / 元信息 */
.msg.result .body {
  color: var(--dim); font-size: 11.5px;
  padding: 4px 0; letter-spacing: 0.3px;
  font-family: "SF Mono", ui-monospace, Menlo, monospace;
}
.msg.error .body { color: var(--red); padding: 8px 12px; background: #fff1f0; border: 1px solid #ffccc7; border-radius: 8px; }

/* AI 回答右上角 工具栏(🔊 复制 等) */
.msg-actions {
  display: flex; gap: 4px; margin-top: 4px;
}
.msg-action {
  width: 32px; height: 32px; border-radius: 8px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--dim); display: grid; place-items: center;
  transition: all 0.15s ease;
}
.msg-action:hover { background: var(--border-soft); color: var(--text-2); }
.msg-action.active { color: var(--accent); }

/* 可视化容器 */
.viz {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  margin: 12px 0; padding: 14px; position: relative; overflow: hidden;
}
.viz::before {
  content: attr(data-kind); position: absolute; top: 8px; right: 12px;
  font-size: 10px; color: var(--dim); letter-spacing: 1px; text-transform: uppercase;
  opacity: 0.5;
}
.viz svg { display: block; max-width: 100%; height: auto; margin: 0 auto; }
.viz.echarts-render { height: 320px; padding: 0; }
.viz.echarts-render::before { top: 8px; right: 12px; z-index: 1; }
.viz-error {
  background: #fff1f0; border-color: #ffccc7; color: var(--red);
  padding: 10px 12px; font-family: "SF Mono", Menlo, monospace; font-size: 12px;
}

/* ============ 推荐 prompt chips ============ */
.suggestions {
  flex: 0 0 auto;
  background: var(--bg);
  padding: 0 12px 8px;
}
.suggestions.hidden { display: none; }
.suggestions-title {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0 auto 8px;
  padding: 4px 12px;
  background: transparent; border: 0;
  font-size: 12px; color: var(--dim);
  cursor: pointer;
  border-radius: 999px;
  transition: background 0.15s ease, color 0.15s ease;
}
.suggestions-title:hover { background: var(--border-soft); color: var(--text-2); }
.suggestions-title:active { background: var(--border); }
.suggestions-title .refresh-icon {
  transition: transform 0.4s cubic-bezier(0.3, 0, 0.3, 1);
}
.suggestions-title.refreshing .refresh-icon {
  animation: spinRefresh 0.7s linear infinite;
}
@keyframes spinRefresh { to { transform: rotate(360deg); } }
.suggestions { text-align: center; }
.chips {
  display: flex; gap: 8px; overflow-x: auto;
  padding-bottom: 4px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  background: var(--panel); border: 1px solid var(--border);
  padding: 8px 14px; border-radius: 999px;
  font-size: 13px; color: var(--text-2); cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ============ 底部输入 ============ */
form {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--border-soft);
  padding: 8px 10px;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
.attachments {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 0 4px 8px;
}
.attachments:empty { display: none; }
.attachment {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--border-soft); border: 1px solid var(--border);
  border-radius: 10px; padding: 4px 8px 4px 4px; font-size: 12px;
}
.attachment img { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; }
.attachment .name { color: var(--text-2); max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment .x {
  background: transparent; border: 0; color: var(--dim); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0 4px;
}
.attachment .x:hover { color: var(--red); }
.attachment.uploading { opacity: 0.5; }
form.dragover { background: var(--accent-soft); }
form.dragover .input-bar { border-color: var(--accent); }

.input-bar {
  display: flex; align-items: flex-end; gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 4px 6px;
}
.input-bar:focus-within { border-color: var(--accent); }
textarea {
  flex: 1 1 auto;
  background: transparent; color: var(--text);
  border: 0; outline: none;
  resize: none; padding: 9px 4px;
  font: inherit; font-size: 15px;
  max-height: 140px; min-height: 38px;
}
textarea::placeholder { color: var(--dim); }

/* 麦克风按下时(录音中) */
.iconbtn#mic.recording {
  background: var(--accent); color: white;
  animation: mic-pulse 1.2s ease-out infinite;
}
@keyframes mic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(64, 128, 255, 0.4); }
  50% { box-shadow: 0 0 0 10px rgba(64, 128, 255, 0); }
}

/* ============ Toast 提示 ============ */
.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.85); color: white;
  padding: 10px 20px; border-radius: 24px; font-size: 14px;
  z-index: 1000; opacity: 0; pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-6px); }

/* ============ 移动端微调 ============ */
@media (max-width: 480px) {
  .msg.text .body, .msg.user .body { font-size: 14.5px; }
  main { padding: 12px 14px 8px; }
  .chip { font-size: 12.5px; padding: 7px 12px; }
}

/* ============ 暗色支持(系统跟随)============ */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17171a;
    --panel: #1e1e22;
    --border: #2c2c30;
    --border-soft: #232328;
    --text: #e8e8ed;
    --text-2: #b8b8bf;
    --dim: #7a7a85;
    --dim-2: #4a4a52;
    --user-bg: #2a2a30;
    --code-bg: #16161a;
    --code-border: #2c2c30;
    --accent-soft: rgba(64, 128, 255, 0.15);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  }
  .msg.tool .body { background: #2a2410; border-color: #4a3a10; color: #f0c060; }
  .msg.tool .body code { color: #f0c060; }
  .msg.error .body { background: rgba(245, 63, 63, 0.1); border-color: rgba(245, 63, 63, 0.3); }
  .msg.text .body code { color: #ff9966; background: var(--code-bg); border-color: var(--code-border); }
  .msg.text .body blockquote { background: var(--accent-soft); }
}
