/* AI 助手页（views/coach.js）专用样式
 * 只做本页独有的东西：页内头部、会话抽屉、消息气泡、三点指示器、
 * 输入区（自增高 textarea + 计数）、[回到最新] 药丸。
 * 通用组件（按钮/卡片/骨架/toast）由 ft-app/ui.css 提供，这里不重复定义。
 */

.ft-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;
}

/* 桌面：把这一页锁进视口高度，消息流内部滚动，输入区常驻底部 */
@media (min-width: 861px) {
  @supports selector(:has(*)) { .ft-main:has(.ft-coach) { overflow: hidden; } }
}
.ft-coach {
  display: flex;
  flex-direction: column;
  gap: var(--ft-s3);
  min-height: 0;
}
@media (min-width: 861px) {
  /* 高度夹紧，避免外壳的页脚/内边距变化时把输入区挤出屏幕 */
  .ft-coach { height: clamp(420px, calc(100vh - var(--ft-topbar-h) - 168px), 760px); }
}

/* ── 页内头部 ─────────────────────────────────────────────── */

.ft-coach-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--ft-s4);
  flex-wrap: wrap;
}
.ft-coach-disclaimer {
  display: flex;
  align-items: center;
  gap: var(--ft-s2);
  margin: 0;
  max-width: 60ch;
}
.ft-coach-head-actions { display: flex; gap: var(--ft-s2); }

/* ── 会话抽屉 ─────────────────────────────────────────────── */

.ft-coach-convs {
  background: var(--ft-surface);
  border: 1px solid var(--ft-border);
  border-radius: var(--ft-r-card);
  box-shadow: var(--ft-shadow-2);
  padding: var(--ft-s2);
  max-height: 300px;
  overflow-y: auto;
}
.ft-conv-row {
  display: flex;
  align-items: center;
  gap: var(--ft-s2);
  border-radius: var(--ft-r-control);
}
.ft-conv-row:hover { background: var(--ft-surface-2); }
.ft-conv-row.is-active { background: var(--ft-brand-tint); }
.ft-conv-open {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: var(--ft-s3);
  background: none;
  border: 0;
  text-align: left;
  color: inherit;
  border-radius: var(--ft-r-control);
}
.ft-conv-title {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}
.ft-conv-meta { font-size: var(--ft-fs-micro); color: var(--ft-ink-3); }

/* ── 消息流 ───────────────────────────────────────────────── */

.ft-coach-stage { position: relative; min-height: 0; flex: 1; display: flex; }
.ft-coach-stream {
  flex: 1;
  min-height: 180px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: var(--ft-s2) var(--ft-s1);
}
.ft-coach-messages { display: flex; flex-direction: column; gap: var(--ft-s5); }

.ft-msg { display: flex; flex-direction: column; max-width: 78%; }
.ft-msg--user { align-self: flex-end; align-items: flex-end; }
.ft-msg--assistant { align-self: flex-start; align-items: flex-start; }

.ft-msg-body {
  padding: var(--ft-s3) var(--ft-s4);
  border-radius: var(--ft-r-card);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.ft-msg--user .ft-msg-body {
  background: var(--ft-brand-tint);
  color: var(--ft-ink);
  border-radius: var(--ft-r-card) var(--ft-r-card) var(--ft-s1) var(--ft-r-card);
}
.ft-msg--assistant .ft-msg-body {
  background: var(--ft-surface);
  border: 1px solid var(--ft-border);
  box-shadow: var(--ft-shadow-1);
}
.ft-msg-text { white-space: pre-wrap; }

.ft-msg--assistant .ft-msg-foot {
  display: flex;
  gap: var(--ft-s2);
  margin-top: var(--ft-s1);
  opacity: 0;
  transition: opacity var(--ft-dur-hover) var(--ft-ease-out);
}
.ft-msg--assistant:hover .ft-msg-foot,
.ft-msg--assistant:focus-within .ft-msg-foot { opacity: 1; }
@media (hover: none) { .ft-msg--assistant .ft-msg-foot { opacity: 1; } }

/* 首字到达前的三点呼吸指示器 */
.ft-typing { display: inline-flex; gap: 4px; align-items: center; padding: 2px 0; }
.ft-typing[hidden] { display: none; }
.ft-typing i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ft-ink-3);
  animation: ft-typing 1.1s infinite ease-in-out;
}
.ft-typing i:nth-child(2) { animation-delay: .16s; }
.ft-typing i:nth-child(3) { animation-delay: .32s; }
@keyframes ft-typing {
  0%, 70%, 100% { opacity: .28; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-2px); }
}

/* ── 空态（欢迎语 + 快捷提问）────────────────────────────── */

.ft-coach-welcome { display: flex; flex-direction: column; gap: var(--ft-s4); padding: var(--ft-s6) 0; }
.ft-coach-welcome-text { margin: 0; font-size: var(--ft-fs-heading); line-height: var(--ft-lh-heading); max-width: 46ch; }
.ft-coach-hint { margin: 0; }
.ft-coach-quick { display: flex; flex-wrap: wrap; gap: var(--ft-s2); }

/* ── 快捷提问 ─────────────────────────────────────────────── */

/* 推荐问题：与输入框拉开距离，避免误触与拥挤 */
.ft-coach-quickbar { display: flex; gap: var(--ft-s2); flex-wrap: wrap; margin-bottom: var(--ft-s4); }
.ft-coach-quickbar:empty { display: none; }
.ft-coach-quick-btn {
  padding: 6px var(--ft-s3);
  border: 1px solid var(--ft-border-strong);
  border-radius: var(--ft-r-pill);
  background: var(--ft-surface);
  color: var(--ft-ink-2);
  font-size: var(--ft-fs-label);
  transition: background var(--ft-dur-hover) var(--ft-ease-out), color var(--ft-dur-hover) var(--ft-ease-out);
}
.ft-coach-quick-btn:hover { background: var(--ft-brand-tint); color: var(--ft-brand-strong); border-color: var(--ft-brand); }
@media (max-width: 720px) {
  .ft-coach-quickbar { flex-wrap: nowrap; overflow-x: auto; padding-bottom: var(--ft-s1); }
  .ft-coach-quick-btn { flex: none; }
}

/* ── [回到最新] 药丸 ──────────────────────────────────────── */

.ft-coach-jump {
  position: absolute;
  right: var(--ft-s4);
  bottom: var(--ft-s4);
  display: inline-flex;
  align-items: center;
  gap: var(--ft-s1);
  padding: 6px var(--ft-s3);
  border: 1px solid var(--ft-border-strong);
  border-radius: var(--ft-r-pill);
  background: var(--ft-surface);
  color: var(--ft-ink-2);
  box-shadow: var(--ft-shadow-2);
  font-size: var(--ft-fs-label);
}
.ft-coach-jump[hidden] { display: none; }

/* ── 输入区 ───────────────────────────────────────────────── */

.ft-coach-composer { display: flex; flex-direction: column; gap: var(--ft-s2); }
.ft-coach-ctx { display: flex; }

.ft-composer {
  display: flex;
  align-items: flex-end;
  gap: var(--ft-s2);
  padding: var(--ft-s2);
  background: var(--ft-surface);
  border: 1px solid var(--ft-border-strong);
  border-radius: var(--ft-r-card);
  box-shadow: var(--ft-shadow-1);
}
.ft-composer:focus-within { border-color: var(--ft-focus); }

.ft-composer-input {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ft-ink);
  font: inherit;
  line-height: var(--ft-composer-line, 24px);
  padding: 8px var(--ft-s2);
  /* 高度由 JS 写入 --ft-composer-h（1–4 行之间夹紧） */
  height: clamp(calc(var(--ft-composer-line, 24px) + 16px), var(--ft-composer-h, 40px), calc(4 * var(--ft-composer-line, 24px) + 16px));
}
.ft-composer-side { display: flex; gap: var(--ft-s2); flex: none; }
.ft-composer-foot { display: flex; align-items: center; justify-content: space-between; gap: var(--ft-s2); }
.ft-composer-count { font-variant-numeric: tabular-nums; }
.ft-composer-count[hidden] { display: none; }
.ft-composer-count.is-warn { color: var(--ft-warn); font-weight: 600; }

.ft-coach-notice { margin: 0; }
.ft-coach-notice[hidden] { display: none; }

/* ── 手机：输入区吸底 + 安全区 ────────────────────────────── */

@media (max-width: 860px) {
  .ft-coach { height: auto; }
  .ft-coach-stream { min-height: 45vh; padding-inline: 0; }
  .ft-msg { max-width: 92%; }
  .ft-coach-composer {
    position: sticky;
    bottom: calc(var(--ft-tabbar-h) + env(safe-area-inset-bottom, 0px));
    z-index: 4;
    padding-top: var(--ft-s2);
    background: var(--ft-bg);
  }
}

/* ── 动作回执（AI 帮记后的可撤销卡片）──────────────────────── */
.ft-action-receipt {
  display: flex; align-items: center; gap: 10px; align-self: flex-start;
  max-width: min(92%, 520px); margin: 6px 0 10px var(--ft-s2, 8px);
  padding: 10px 14px; border-radius: 12px;
  background: var(--ft-brand-tint); border: 1px solid var(--ft-border);
  font-size: 13px; color: var(--ft-ink); line-height: 1.5;
}
.ft-action-receipt.is-error { background: var(--ft-danger-tint); }
.ft-action-icon { flex: none; width: 20px; height: 20px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; background: var(--ft-brand); color: var(--ft-brand-contrast); font-size: 12px; font-weight: 700; }
.ft-action-receipt.is-error .ft-action-icon { background: var(--ft-danger); color: #fff; }
.ft-action-text { flex: 1; min-width: 0; }
.ft-action-undo { flex: none; border: none; background: none; font: inherit; font-weight: 600; color: var(--ft-brand-strong); cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.ft-action-undo:hover { background: var(--ft-surface-2); }

/* 已撤销的回执：淡化 + 划线，视觉上明确不再是有效记录 */
.ft-action-receipt.is-undone { background: var(--ft-surface-2); opacity: .75; }
.ft-action-receipt.is-undone .ft-action-icon { background: var(--ft-ink-3); }
.ft-action-receipt.is-undone .ft-action-text { text-decoration: line-through; color: var(--ft-ink-3); }

/* ── 能力卡片（AI 助手空态）────────────────────────────────── */
.ft-coach-abilities { display: grid; gap: 10px; width: 100%; max-width: 520px; margin: 4px 0 6px; }
.ft-coach-ability {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  padding: 13px 14px; font: inherit; color: var(--ft-ink); cursor: pointer;
  background: var(--ft-surface); border: 1px solid var(--ft-border); border-radius: 16px;
  box-shadow: var(--ft-shadow-1);
  transition: transform var(--ft-dur-hover) var(--ft-ease-out), box-shadow var(--ft-dur-hover), border-color var(--ft-dur-hover);
}
.ft-coach-ability:hover { transform: translateY(-1px); border-color: var(--ft-brand); box-shadow: var(--ft-shadow-2); }
.ft-coach-ability > svg { color: var(--ft-ink-3); flex: none; }
.ft-coach-ability-ico {
  flex: none; width: 36px; height: 36px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--ft-brand-tint); color: var(--ft-brand-strong);
}
.ft-coach-ability-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.ft-coach-ability-main strong { font-size: 14px; }
.ft-coach-ability-main span { font-size: 12.5px; color: var(--ft-ink-3); line-height: 1.45; }
.ft-coach-quick-hint { margin: 10px 0 4px; color: var(--ft-ink-2); }


/* ═══════════════════════════════════════════════════════════
   AI 助手页视觉重做：品牌头部条 + 居中欢迎态 + 胶囊输入区
   ═══════════════════════════════════════════════════════════ */

/* 头部：品牌渐变条，和今日页主视觉同一套语言 */
.ft-coach-head {
  position: relative; overflow: hidden;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 18px; margin-bottom: var(--ft-s4, 16px);
  border-radius: 18px; color: #fff;
  background: linear-gradient(120deg, #1B7A4C 0%, #14663F 60%, #0F5636 100%);
  box-shadow: 0 14px 32px -18px rgba(14, 92, 60, .5);
}
:root[data-theme="dark"] .ft-coach-head { background: linear-gradient(120deg, #17653F 0%, #104E31 60%, #0B3C25 100%); box-shadow: 0 14px 32px -20px rgba(0,0,0,.75); }
.ft-coach-head::after {
  content: ""; position: absolute; right: -50px; top: -70px; width: 200px; height: 200px; border-radius: 50%;
  background: radial-gradient(circle, rgba(255,255,255,.26) 0%, rgba(255,255,255,0) 70%); pointer-events: none;
}
.ft-coach-head .ft-coach-disclaimer { position: relative; flex: 1; min-width: 200px; margin: 0; color: rgba(255,255,255,.92); }
.ft-coach-head .ft-coach-disclaimer svg { color: rgba(255,255,255,.8); }
.ft-coach-head-actions { position: relative; display: flex; gap: 8px; flex-wrap: wrap; }
.ft-coach-head-actions .ft-btn--secondary {
  background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.28); color: #fff;
}
.ft-coach-head-actions .ft-btn--secondary:hover { background: rgba(255,255,255,.26); border-color: rgba(255,255,255,.5); }

/* 欢迎态：垂直居中，不再出现"内容挤在上、输入框飘在最下"的大空档 */
.ft-coach-welcome {
  flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 14px; padding: 12px 0 20px; min-height: 0;
}
.ft-coach-welcome-text { max-width: 560px; text-align: center; font-size: 15px; line-height: 1.7; color: var(--ft-ink-2); margin: 0; }

/* 能力卡片：图标固定尺寸（之前 SVG 没有尺寸规则被撑成了巨型图标） */
.ft-coach-ability-ico svg { width: 18px; height: 18px; }

/* 快捷提问：横向可滑，圆角胶囊 */
.ft-coach-quick { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.ft-coach-quick-btn {
  border-radius: 999px; padding: 8px 15px; font-size: 13px;
  background: var(--ft-surface); border: 1px solid var(--ft-border);
  box-shadow: var(--ft-shadow-1); transition: transform var(--ft-dur-hover), border-color var(--ft-dur-hover), color var(--ft-dur-hover);
}
.ft-coach-quick-btn:hover { transform: translateY(-1px); border-color: var(--ft-brand); color: var(--ft-brand-strong); }

/* 输入区：胶囊 + 内嵌发送按钮 */
.ft-coach-compose { border-radius: 20px; border: 1px solid var(--ft-border); background: var(--ft-surface); box-shadow: var(--ft-shadow-2); padding: 10px 12px; }
.ft-coach-compose textarea { border: none !important; box-shadow: none !important; background: transparent; }


/* 让聊天页真正撑满可用高度：头部固定、消息区自适应、输入区贴底 */
.ft-coach { min-height: min(72vh, 760px); }
@media (min-width: 861px) { .ft-coach { min-height: min(70vh, 720px); } }
.ft-coach-stream { scrollbar-gutter: stable; }
.ft-coach-messages { display: flex; flex-direction: column; gap: 2px; min-height: 100%; }

/* 动作回执：右上角关闭 + 淡出（原来会永久留在对话里，用户要求"看一眼就够了"） */
.ft-action-receipt { position: relative; padding-right: 30px; transition: opacity .22s ease, transform .22s ease; }
.ft-action-receipt.is-leaving { opacity: 0; transform: translateY(-4px); }
.ft-action-close {
  position: absolute; top: 6px; right: 6px;
  width: 20px; height: 20px; padding: 0; margin: 0;
  display: grid; place-items: center;
  border: none; border-radius: 50%; cursor: pointer;
  background: transparent; color: var(--ft-ink-3);
  font-size: 15px; line-height: 1; opacity: .55;
  transition: background var(--ft-dur-hover), opacity var(--ft-dur-hover), color var(--ft-dur-hover);
}
.ft-action-close:hover { opacity: 1; background: rgba(18,22,15,.08); color: var(--ft-ink); }
.ft-action-receipt.is-error .ft-action-close { color: var(--ft-warn); }

/* AI 草稿确认卡：识别到食物后先问一句，用户点「加入今天」才入账 */
.ft-draft-card {
  margin: 10px 0; padding: 14px 16px; border-radius: var(--ft-r-card, 16px);
  background: var(--ft-brand-tint); border: 1px solid color-mix(in oklab, var(--ft-brand) 26%, transparent);
  transition: opacity .25s ease, transform .25s ease;
}
.ft-draft-card.is-done, .ft-draft-card.is-skipped { opacity: .6; }
.ft-draft-head { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ft-brand-strong); }
.ft-draft-list { margin: 10px 0 0; padding-left: 18px; display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ft-ink); }
.ft-draft-list li { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.ft-draft-list li b { font-weight: 600; }
.ft-draft-list li span { font-variant-numeric: tabular-nums; color: var(--ft-ink-2); font-size: 12px; }
.ft-draft-foot { margin-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.ft-draft-total { font-size: 12.5px; color: var(--ft-ink-2); }
.ft-draft-total b { font-size: 15px; color: var(--ft-ink); }
.ft-draft-total i { font-style: normal; display: block; font-size: 11.5px; color: var(--ft-ink-3); margin-top: 2px; }
.ft-draft-actions { display: flex; gap: 8px; }
.ft-draft-result { font-size: 12.5px; font-weight: 600; color: var(--ft-brand-strong); }
.ft-draft-hint { margin: 8px 0 0; font-size: 12.5px; color: var(--ft-ink-2); }

/* 草稿确认弹框：浮在输入框上方（用户要的位置），不塞进消息流 */
.ft-draft-pop {
  margin: 0 0 10px; padding: 12px 14px;
  border-radius: 14px; border: 1px solid color-mix(in oklab, var(--ft-brand) 30%, transparent);
  background: var(--ft-brand-tint);
  box-shadow: 0 12px 30px -20px rgba(14, 60, 38, .5);
  animation: ft-draft-in .18s ease-out;
}
@keyframes ft-draft-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.ft-draft-pop[hidden] { display: none; }
.ft-draft-pop-head { display: flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ft-brand-strong); }
.ft-draft-pop-head > span { flex: 1; }
.ft-draft-pop-x {
  flex: none; width: 24px; height: 24px; border: 0; border-radius: 8px; cursor: pointer;
  background: transparent; color: var(--ft-ink-3); font-size: 16px; line-height: 1;
}
.ft-draft-pop-x:hover { background: rgba(0, 0, 0, .06); color: var(--ft-ink); }
.ft-draft-pop-items { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.ft-draft-pop-item {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 4px 10px; border-radius: 999px; background: var(--ft-surface);
  border: 1px solid color-mix(in oklab, var(--ft-brand) 18%, transparent);
  font-size: 12.5px; color: var(--ft-ink);
}
.ft-draft-pop-item i { font-style: normal; font-size: 11.5px; color: var(--ft-ink-3); font-variant-numeric: tabular-nums; }
.ft-draft-pop-hint { margin: 8px 0 0; font-size: 12.5px; color: var(--ft-ink-2); }
.ft-draft-pop-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 11px; flex-wrap: wrap; }
.ft-draft-pop-total { font-size: 12.5px; color: var(--ft-ink-2); }
.ft-draft-pop-total b { font-size: 14.5px; color: var(--ft-ink); }
.ft-draft-pop-actrow { display: flex; gap: 8px; }
@media (max-width: 560px) {
  .ft-draft-pop-foot { flex-direction: column; align-items: stretch; }
  .ft-draft-pop-actrow { justify-content: flex-end; }
}
