/**
 * chat.css — 紫微助教聊天页样式
 * 适配 index.html 架构，复用 global.css 变量
 */

/* ============================================================
   Layout
   ============================================================ */

#chat-view.view {
  display: flex;
  flex-direction: column;
  /* 和 tabbar 对齐：最大宽 480px 居中，与其他页面视觉一致 */
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  /* 底部 tabbar (~56px) 是 position:fixed，需从视口高度中扣除；
     safe-area 不在此扣，由 input-bar / recording-bar 的 padding-bottom 统一处理 */
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);
  overflow: hidden;
  background: #f5f5f5;
}

/* ============================================================
   Header
   ============================================================ */

.chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: #fff;
  border-bottom: 1px solid #e8e8e8;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  z-index: 10;
}

.chat-header__title {
  font-size: 17px;
  font-weight: 600;
  color: #222;
  letter-spacing: 0.02em;
}

.tts-toggle {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 8px;
  transition: background 0.15s;
  line-height: 1;
}

.tts-toggle:hover {
  background: rgba(0, 0, 0, 0.06);
}

.tts-toggle.active {
  background: rgba(91, 141, 239, 0.12);
}

/* ============================================================
   顶部可用额度进度条 (chat-quota-bar)
   数据源：T2 mount = POST /self-conversation 响应 data.quota.chat；
          后续每轮 = root-chat done.quota.chat（log 已入库，含本轮消耗）
   显示规则（见 docs/apis/04-page-walkthrough-chat.md § t2-quota-bar）：
     unlimited / quota=null → hidden
     remainingPct ≤ 20 → 文字 + fill 变红警示
   ============================================================ */
.chat-quota-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 16px;
  background: #fff;
  border-bottom: 1px solid #f0f0f0;
  font-size: 12px;
}
.chat-quota-bar[hidden] { display: none; }

.chat-quota-bar__track {
  flex: 1 1 auto;
  height: 4px;
  background: rgba(0, 0, 0, 0.06);
  border-radius: 2px;
  overflow: hidden;
}
.chat-quota-bar__fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #5b8def, #8aa9f5);
  border-radius: 2px;
  transition: width 0.3s ease, background 0.2s ease;
}
.chat-quota-bar__label {
  flex: 0 0 auto;
  color: #666;
  white-space: nowrap;
}
.chat-quota-bar--warn .chat-quota-bar__fill {
  background: #e85a4f;
}
.chat-quota-bar--warn .chat-quota-bar__label {
  color: #e85a4f;
}

/* ============================================================
   Messages area
   ============================================================ */

.chat-messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* 底部留出 input bar 高度兜底，避免最后一条消息被遮住 */
  padding-bottom: 8px;
}

/* 空状态 */
.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 8px;
  color: #999;
  font-size: 15px;
  padding: 40px 0;
}

.chat-empty__icon {
  font-size: 40px;
  margin-bottom: 4px;
}

/* ============================================================
   Message bubbles
   ============================================================ */

.msg-row {
  display: flex;
  flex-direction: column;
  max-width: 85%;
}

.msg-row--user {
  align-self: flex-end;
  align-items: flex-end;
}

.msg-row--assistant {
  align-self: flex-start;
  align-items: flex-start;
}

.msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-row--user .msg-bubble {
  background: #5b8def;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-row--assistant .msg-bubble {
  background: #fff;
  color: #222;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

/* PR-D5: 多段 reply 已拆成 N 个独立 .msg-row, 不再 .msg-bubble 内 .msg-segment 段间细线 —
 * 旧 PR-D3 .msg-segment / .multi-segment CSS 已删 (DOM 不再生成此类). 多 row 之间用 .msg-row
 * 自身 margin 自然分隔, 不需额外样式. */

/* 流式 streaming 状态光标 — 挂在 streaming bubble 尾部 (单段 / 多段当前 row 都用同一规则) */
.msg-bubble--streaming::after {
  content: '|';
  display: inline-block;
  animation: blink 0.8s step-start infinite;
  margin-left: 1px;
  color: #5b8def;
  font-weight: 300;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* 工具调用 hint */
.tool-hint {
  font-size: 12px;
  color: #999;
  margin-bottom: 4px;
}

/* TTS 按钮 */
.tts-play-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 4px;
  margin-top: 6px;
  color: #5b8def;
  opacity: 0.7;
  border-radius: 4px;
  line-height: 1;
  transition: opacity 0.15s;
}

.tts-play-btn:hover {
  opacity: 1;
}

.tts-play-btn.playing {
  color: #e05454;
  opacity: 1;
}

/* 续问 SQ chips：只渲染在最后一条 AI 消息下方 */
.sq-chips {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  margin-top: 8px;
  max-width: 100%;
}

.sq-chip {
  background: #fff;
  color: #4a6fd1;
  border: 1px solid #d6dcf3;
  border-radius: 14px;
  padding: 6px 12px;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  max-width: 100%;
  text-align: left;
}

.sq-chip:hover {
  background: #f3f6ff;
  border-color: #b4c2ec;
}

.sq-chip:active {
  background: #e6ecfa;
}

/* 错误消息 */
.msg-row--error .msg-bubble {
  background: #fff0f0;
  color: #c0392b;
  border: 1px solid #ffd0d0;
}

/* 系统事件卡（archive_created 等）*/
.msg-row--system {
  align-self: center;
  align-items: center;
  width: 90%;
  max-width: 90%;
  margin: 12px 0;
}

.system-card {
  background: rgba(91, 141, 239, 0.08);
  border: 1px solid rgba(91, 141, 239, 0.2);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  box-sizing: border-box;
}

.system-card__icon {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(91, 141, 239, 0.18);
  border-radius: 8px;
  color: #5b8def;
  font-size: 16px;
}

.system-card__body {
  flex: 1;
  min-width: 0;
}

.system-card__title {
  font-size: 13px;
  font-weight: 500;
  color: #222;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.system-card__subtitle {
  font-size: 12px;
  color: #666;
  margin-top: 2px;
}

.system-card__link {
  flex: 0 0 auto;
  font-size: 12px;
  color: #5b8def;
  text-decoration: none;
  white-space: nowrap;
}

.system-card__link:hover {
  color: #4a7be0;
}

/* ============================================================
   Input bar
   ============================================================ */

.chat-input-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid #e8e8e8;
  box-shadow: 0 -1px 4px rgba(0, 0, 0, 0.05);
}

.chat-mic-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  background: #f0f0f0;
  border: none;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  line-height: 1;
}

.chat-mic-btn:hover {
  background: #e0e0e0;
}

.chat-mic-btn.recording {
  background: rgba(224, 84, 84, 0.15);
  color: #e05454;
}

.chat-input-text {
  flex: 1 1 auto;
  min-height: 38px;
  max-height: 120px;
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.4;
  resize: none;
  outline: none;
  background: #f9f9f9;
  font-family: inherit;
  overflow-y: auto;
  transition: border-color 0.15s;
}

.chat-input-text:focus {
  border-color: #5b8def;
  background: #fff;
}

.chat-send-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  background: #5b8def;
  color: #fff;
  border: none;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
  line-height: 1;
}

.chat-send-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.chat-send-btn:not(:disabled):hover {
  background: #4a7ae0;
}

/* ============================================================
   Recording bar（替换 input bar）
   ============================================================ */

.recording-bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  background: #fff;
  border-top: 1px solid #e8e8e8;
}

.recording-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #e05454;
  animation: recording-pulse 1s ease-in-out infinite;
}

@keyframes recording-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

.recording-time {
  font-size: 14px;
  color: #666;
  flex: 1;
}

.recording-cancel {
  padding: 6px 14px;
  border: 1px solid #ddd;
  border-radius: 16px;
  background: none;
  font-size: 14px;
  cursor: pointer;
  color: #666;
}

.recording-send {
  padding: 6px 14px;
  border: none;
  border-radius: 16px;
  background: #5b8def;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

/* ============================================================
   T1 聊天入口屏（#/home）
   ============================================================ */

#home-view.view {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  width: 100%;
  margin: 0 auto;
  height: calc(100vh - 56px);
  height: calc(100dvh - 56px);
  overflow: auto;
  background: #f5f5f5;
}

.home-page {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  padding: 24px 20px 32px;
  gap: 24px;
}

.home-welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 16px;
  background: #fff;
  border-radius: 16px;
}

.home-welcome__title {
  font-size: 18px;
  font-weight: 600;
  color: #222;
}

.home-welcome__avatar {
  font-size: 56px;
  line-height: 1;
}

.home-suggested {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.home-card {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: 12px;
  background: #fff;
  font-size: 15px;
  line-height: 1.4;
  color: #333;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  transition: background 0.15s ease;
}

.home-card:hover {
  background: #f0f4ff;
}

.home-card--skeleton {
  pointer-events: none;
  min-height: 52px;
  background: linear-gradient(90deg, #eee 0%, #f5f5f5 50%, #eee 100%);
  background-size: 200% 100%;
  animation: home-skeleton-shimmer 1.4s ease-in-out infinite;
}

@keyframes home-skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.home-cta {
  margin-top: auto;
  padding: 14px 20px;
  border: none;
  border-radius: 28px;
  background: #5b8def;
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}

.home-cta:hover { background: #4a7be0; }


/* ============================================================
   电话模式（满屏覆盖层）— 从 tutor.html L569-617 迁移
   设计文档：docs/designs/tutor-call-mode-v1.md
   ============================================================ */
.chat-call-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: linear-gradient(180deg, #1a1f2e 0%, #0d1525 100%);
  display: flex; flex-direction: column; align-items: center;
  padding: 24px 20px; box-sizing: border-box;
}
.chat-call-overlay[hidden] { display: none; }
.chat-call-close {
  align-self: flex-end; background: none; border: none;
  color: rgba(255,255,255,0.7); font-size: 28px; cursor: pointer;
  width: 40px; height: 40px; line-height: 1;
}
.chat-call-header {
  text-align: center; color: #fff; margin: 8px 0 24px;
}
.chat-call-header h2 { font-size: 22px; font-weight: 500; margin-bottom: 4px; }
.chat-call-header .sub { font-size: 14px; color: rgba(255,255,255,0.5); }
/* part2：通话计时器 + 剩余分钟 */
.chat-call-meter {
  display: flex; gap: 12px; align-items: center; justify-content: center;
  color: rgba(255,255,255,0.85); font-size: 14px; margin: -16px 0 16px;
}
.chat-call-meter[hidden] { display: none; }
.chat-call-timer { font-variant-numeric: tabular-nums; letter-spacing: 0.5px; }
.chat-call-remain {
  padding: 2px 10px; border-radius: 999px;
  background: rgba(255,255,255,0.1); font-size: 13px;
}
.chat-call-remain[hidden] { display: none; }
/* 回复模型分段选择器（电话/语音专用）。深色覆盖层主题，选中态用与按钮同色的蓝 */
.chat-call-model {
  display: inline-flex; gap: 4px; padding: 4px;
  background: rgba(255,255,255,0.08); border-radius: 999px;
}
.chat-call-model__opt {
  padding: 7px 16px; border-radius: 999px; font-size: 14px;
  color: rgba(255,255,255,0.6); cursor: pointer; user-select: none;
  transition: color 0.15s, background 0.15s;
}
.chat-call-model__opt:has(input:checked) { background: #2a7fff; color: #fff; }
.chat-call-model__opt input { position: absolute; opacity: 0; pointer-events: none; }
.chat-call-btn {
  width: 200px; height: 200px; border-radius: 50%; border: none;
  background: #2a7fff; color: white; font-size: 20px; font-weight: 500;
  cursor: pointer; touch-action: none; user-select: none;
  box-shadow: 0 8px 32px rgba(42,127,255,0.35);
  transition: background 0.15s, transform 0.15s;
  margin: 32px 0 16px;
}
.chat-call-btn.recording { background: #ef4444; transform: scale(0.96); box-shadow: 0 8px 32px rgba(239,68,68,0.4); }
.chat-call-btn.processing { background: #6b7280; cursor: not-allowed; box-shadow: none; }
.chat-call-btn.playing { background: #f59e0b; box-shadow: 0 8px 32px rgba(245,158,11,0.35); }
/* V3 VAD 模式：'listening' = 一直监听等用户说话。柔和呼吸脉动让用户知道"麦克风在听" */
.chat-call-btn.listening { background: #2a7fff; cursor: default; animation: chat-call-pulse 1.8s ease-in-out infinite; }
@keyframes chat-call-pulse {
  0%, 100% { box-shadow: 0 8px 32px rgba(42,127,255,0.35); transform: scale(1); }
  50%      { box-shadow: 0 8px 48px rgba(42,127,255,0.65); transform: scale(1.03); }
}
.chat-call-status {
  color: rgba(255,255,255,0.8); font-size: 15px;
  min-height: 1.4em; text-align: center; margin-bottom: 16px;
}
.chat-call-status.error { color: #ff8a8a; }
.chat-call-log {
  flex: 1; width: 100%; max-width: 560px;
  overflow-y: auto; padding: 0 4px;
}
.chat-call-turn {
  padding: 10px 14px; border-radius: 12px; margin: 8px 0;
  line-height: 1.5; font-size: 15px; color: #fff;
  word-break: break-word; overflow-wrap: anywhere;
}
.chat-call-turn.user { background: rgba(42,127,255,0.18); }
.chat-call-turn.master { background: rgba(245,158,11,0.15); }
.chat-call-turn .label {
  font-size: 11px; color: rgba(255,255,255,0.55);
  margin-right: 6px; font-weight: 600;
}

/* chat-input-bar 内的 📞 电话按钮 — 与 .chat-mic-btn 风格平行 */
.chat-call-entry-btn {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 6px;
  line-height: 1;
}
.chat-call-entry-btn:active { opacity: 0.6; }

/* 📞 通话方式选择浮层（普通线路 / 高清线路·降噪声纹），点 📞 弹出底部 sheet */
.chat-call-chooser {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 19, 32, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: ccc-fade 0.15s ease;
}
@keyframes ccc-fade { from { opacity: 0; } to { opacity: 1; } }
.ccc-sheet {
  width: 100%;
  max-width: 480px;
  box-sizing: border-box;
  background: #fff;
  border-radius: 18px 18px 0 0;
  padding: 18px 16px calc(16px + env(safe-area-inset-bottom));
  box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.18);
  animation: ccc-slide 0.2s ease;
}
@keyframes ccc-slide { from { transform: translateY(100%); } to { transform: translateY(0); } }
.ccc-title { text-align: center; font-size: 15px; color: #8a93ab; margin: 0 0 14px; }
.ccc-opt {
  display: block;
  width: 100%;
  text-align: left;
  cursor: pointer;
  border: 1px solid #e6e9f2;
  border-radius: 14px;
  background: #f8f9fc;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.ccc-opt:active { background: #eef1f8; }
.ccc-opt--rtc { border-color: #cdd9ff; background: linear-gradient(180deg, #f4f8ff, #eef3ff); }
.ccc-opt__name { font-size: 17px; font-weight: 600; color: #1f2740; }
.ccc-opt__desc { font-size: 13px; color: #8a93ab; margin-top: 3px; }
.ccc-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  vertical-align: middle;
  color: #4a6bff;
  background: #e3eaff;
  border-radius: 6px;
  padding: 1px 7px;
  margin-left: 4px;
}
.ccc-cancel {
  display: block;
  width: 100%;
  cursor: pointer;
  border: none;
  border-radius: 14px;
  background: #f0f1f5;
  padding: 13px;
  margin-top: 4px;
  font-size: 16px;
  color: #5a6275;
}
.ccc-cancel:active { background: #e6e7ec; }

/* 需求#1 建档引导「去建档」CTA（archive_guide 回复下） */
.archive-guide-cta {
  display: inline-block;
  margin: 8px 0 4px 44px;
  padding: 7px 16px;
  border: none;
  border-radius: 999px;
  background: #c1995a;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.archive-guide-cta:active { transform: scale(0.97); }
