* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", sans-serif;
  background: #ffffff;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── 顶部标题栏 ── */
.header {
  background: #fff;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top));
  text-align: center;
  border-bottom: 1px solid #e8e8e8;
  flex-shrink: 0;
  position: relative;
}
.header h1 { font-size: 17px; font-weight: 600; color: #1a1a1a; }
.header p  { font-size: 12px; color: #999; margin-top: 2px; }

.mute-btn {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  margin-top: calc(env(safe-area-inset-top) / 2);
  width: 36px; height: 36px;
  border: none; background: none;
  cursor: pointer;
  color: #999;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  transition: background .15s, color .15s;
}
.mute-btn:active { background: #f0f0f0; }
.mute-btn.muted { color: #1a1a1a; }

/* ── 消息列表 ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.msg-row.user { flex-direction: row-reverse; }

.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  background: #e8ffe8;
}

/* AI 消息：全宽卡片 */
.msg-row.ai .bubble-wrap { width: 100%; }
.msg-row.ai .bubble {
  width: 100%;
  padding: 14px 16px;
  background: #f7f7f7;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.7;
  color: #1a1a1a;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
  word-break: break-word;
}

/* Markdown */
.msg-row.ai .bubble h1,
.msg-row.ai .bubble h2,
.msg-row.ai .bubble h3 { font-weight: 700; margin: 10px 0 4px; color: #111; }
.msg-row.ai .bubble h1 { font-size: 17px; }
.msg-row.ai .bubble h2 { font-size: 16px; }
.msg-row.ai .bubble h3 { font-size: 15px; }
.msg-row.ai .bubble p  { margin: 4px 0; }
.msg-row.ai .bubble ul,
.msg-row.ai .bubble ol { padding-left: 20px; margin: 4px 0; }
.msg-row.ai .bubble li { margin: 3px 0; }
.msg-row.ai .bubble strong { font-weight: 700; }
.msg-row.ai .bubble em { font-style: italic; }
.msg-row.ai .bubble code {
  background: #f5f5f5; padding: 1px 5px;
  border-radius: 4px; font-size: 13px; font-family: monospace;
}
.msg-row.ai .bubble table {
  border-collapse: collapse; width: 100%; font-size: 13px; margin: 6px 0;
}
.msg-row.ai .bubble th,
.msg-row.ai .bubble td { border: 1px solid #e0e0e0; padding: 5px 8px; text-align: left; }
.msg-row.ai .bubble th { background: #f5f5f5; font-weight: 600; }

/* 来源卡片 */
.source-card {
  display: flex; align-items: center; gap: 6px;
  padding-bottom: 9px;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(0,0,0,.07);
  font-size: 12.5px; color: #aaa;
  width: 100%;
}
.source-card .sc-dot {
  width: 6px; height: 6px; border-radius: 50%; background: #07c160; flex-shrink: 0;
}

/* 操作栏 */
.msg-actions {
  display: flex; gap: 8px; align-items: center;
  padding: 10px 4px 2px;
  border-top: 1px solid rgba(0,0,0,.06);
  margin-top: 10px;
}
.msg-action-btn {
  width: 36px; height: 36px; border-radius: 50%;
  border: none; background: #eef2ff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
  flex-shrink: 0;
}
.msg-action-btn:active { background: #dce6ff; }
.msg-action-btn.playing { background: #dce6ff; }
.msg-action-btn svg { display: block; }

/* 用户气泡 */
.msg-row.user .bubble-wrap { display: flex; flex-direction: column; align-items: flex-end; max-width: 82%; }
.msg-row.user .bubble {
  padding: 11px 16px;
  background: #0066ff; color: #fff;
  border-radius: 22px; border-bottom-right-radius: 6px;
  font-size: 15px; line-height: 1.55;
  word-break: break-word; white-space: pre-wrap;
}

/* 加载动画 */
.typing { display: flex; gap: 4px; padding: 14px 18px; width: 100%; }
.typing span {
  width: 7px; height: 7px;
  background: #ccc; border-radius: 50%;
  animation: bounce 1.2s infinite ease-in-out;
}
.typing span:nth-child(2) { animation-delay: .2s; }
.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* ── 输入区域 ── */
.input-area {
  background: #fff;
  border-top: 1px solid rgba(0,0,0,.07);
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

/* 语音模式 */
.input-voice {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mode-icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%; border: none;
  background: #ebebeb; color: #555;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, transform .1s;
}
.mode-icon-btn:active { transform: scale(.88); background: #ddd; }

.talk-btn {
  flex: 1; height: 44px;
  border: none; border-radius: 22px;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,.10);
  font-size: 16px; font-weight: 500; color: #333;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  letter-spacing: .5px;
}
.talk-btn:active {
  background: #eef3ff;
  transform: scale(.97);
  box-shadow: 0 0 0 3px rgba(51,112,255,.2);
}
.talk-btn.active-rec {
  background: #eef3ff;
  box-shadow: 0 0 0 3px rgba(51,112,255,.2);
}

/* 文字模式 */
.input-normal {
  display: none;
  align-items: flex-end;
  gap: 8px;
}

.input-pill {
  flex: 1;
  display: flex; align-items: center;
  background: #fff;
  border: none; border-radius: 28px;
  padding: 6px 8px 6px 16px; gap: 8px;
  box-shadow: 0 2px 14px rgba(0,0,0,.11);
}

.text-input {
  flex: 1; border: none; background: transparent;
  font-size: 17px; outline: none; color: #1a1a1a;
  resize: none; max-height: 120px; line-height: 1.5;
  padding: 0; font-family: inherit;
}
.text-input::placeholder { color: #c0c0c0; }

.send-btn {
  width: 32px; height: 32px;
  border-radius: 50%; border: none;
  background: #3370ff;
  color: #fff; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; align-self: center;
  transition: transform .12s, background .15s;
}
.send-btn:active { transform: scale(.88); }
.send-btn:disabled { background: #c8c8c8; cursor: not-allowed; }

/* ── 录音覆盖层 ── */
.rec-overlay {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: 62vh;
  min-height: 360px;
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  background: radial-gradient(
    ellipse 130% 72% at 50% 112%,
    #1a56e8 0%,
    #3b82f6 22%,
    #7eb6fa 46%,
    rgba(190, 220, 255, 0.55) 66%,
    rgba(255, 255, 255, 0) 82%
  );
}
.rec-overlay.active { display: flex; }

.rec-overlay.cancel-mode {
  background: radial-gradient(
    ellipse 130% 72% at 50% 112%,
    #c0392b 0%,
    #e05050 22%,
    #f0908a 46%,
    rgba(255, 200, 200, 0.55) 66%,
    rgba(255, 255, 255, 0) 82%
  );
}

.rec-hint {
  color: rgba(255,255,255,.95);
  font-size: 17px;
  font-weight: 400;
  letter-spacing: .5px;
  margin-bottom: 40px;
  text-shadow: 0 1px 6px rgba(0,0,0,.15);
}

.rec-wave-h {
  display: flex;
  align-items: center;
  gap: 4px;
}
.rec-wave-h span {
  display: inline-block;
  width: 4px; height: 4px;
  border-radius: 50%;
  background: rgba(255,255,255,.9);
  animation: dotPulse 1.1s ease-in-out infinite alternate;
}
.rec-wave-h span:nth-child(1)  { width:3px; height:3px; animation-delay:0s;    opacity:.4; }
.rec-wave-h span:nth-child(2)  { width:3px; height:3px; animation-delay:.06s;  opacity:.5; }
.rec-wave-h span:nth-child(3)  { width:4px; height:4px; animation-delay:.12s;  opacity:.6; }
.rec-wave-h span:nth-child(4)  { width:5px; height:5px; animation-delay:.18s;  opacity:.75; }
.rec-wave-h span:nth-child(5)  { width:6px; height:6px; animation-delay:.24s;  opacity:.85; }
.rec-wave-h span:nth-child(6)  { width:6px; height:6px; animation-delay:.30s;  opacity:.9; }
.rec-wave-h span:nth-child(7)  { width:7px; height:7px; animation-delay:.24s;  opacity:1; }
.rec-wave-h span:nth-child(8)  { width:7px; height:7px; animation-delay:.18s;  opacity:1; }
.rec-wave-h span:nth-child(9)  { width:6px; height:6px; animation-delay:.24s;  opacity:.9; }
.rec-wave-h span:nth-child(10) { width:6px; height:6px; animation-delay:.30s;  opacity:.85; }
.rec-wave-h span:nth-child(11) { width:5px; height:5px; animation-delay:.24s;  opacity:.75; }
.rec-wave-h span:nth-child(12) { width:4px; height:4px; animation-delay:.18s;  opacity:.6; }
.rec-wave-h span:nth-child(13) { width:3px; height:3px; animation-delay:.12s;  opacity:.5; }
.rec-wave-h span:nth-child(14) { width:3px; height:3px; animation-delay:.06s;  opacity:.4; }
@keyframes dotPulse {
  from { transform: scale(.5); }
  to   { transform: scale(1.4); }
}

.rec-overlay-timer {
  margin-top: 18px;
  color: rgba(255,255,255,.65);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  transition: color .3s, font-size .3s;
}
.rec-overlay-timer.warning {
  color: rgba(255, 220, 80, 1);
  font-size: 15px;
  font-weight: 600;
}

.rec-countdown {
  height: 16px;
  margin-top: 4px;
  font-size: 12px;
  color: rgba(255, 220, 80, .9);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  letter-spacing: .3px;
}

/* 错误提示 */
.toast {
  display: none;
  position: fixed; top: 60px; left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,.75); color: #fff;
  padding: 8px 20px; border-radius: 20px;
  font-size: 13px; z-index: 300;
}
.toast.show { display: block; }

.error-bubble {
  background: #fff4f4 !important;
  border: 1px solid #ffc8c8 !important;
  color: #c0392b !important;
}
.retry-btn {
  margin-top: 6px;
  background: none;
  border: 1px solid #e05050;
  color: #c0392b;
  border-radius: 12px;
  padding: 4px 14px;
  font-size: 12px;
  cursor: pointer;
  transition: background .15s;
}
.retry-btn:active { background: #fff0f0; }

/* ── 图表卡片 ── */
.chart-wrap {
  margin-top: 12px;
  background: #fff;
  border-radius: 16px;
  padding: 14px 16px 12px;
  box-shadow: 0 2px 12px rgba(0,0,0,.07);
  border: 1px solid #f0f4ff;
}
.chart-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.chart-card-title {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
  color: #1a1a1a;
}
.chart-card-title svg { flex-shrink: 0; }
.chart-card-badge {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  color: #07c160;
  border: 1px solid #b7eb8f;
  border-radius: 20px;
  padding: 2px 8px;
  background: #f6ffed;
}
.chart-period {
  font-size: 12px;
  color: #888;
  margin-bottom: 6px;
}
.chart-big-num {
  font-size: 14px;
  color: #1a1a1a;
  margin-bottom: 10px;
  line-height: 1.3;
}
.chart-big-num strong {
  font-size: 28px;
  font-weight: 700;
  color: #1677ff;
  margin: 0 3px;
}
.chart-canvas-box {
  position: relative;
}
.chart-footer {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #f5f5f5;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.chart-footer-row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  color: #999;
}
.chart-footer-row svg { flex-shrink: 0; }
