/* ==========================================================================
   AI 菌根菌问答 · 聊天界面
   只在 ai.html 用，不动 style.css。视觉沿用主站：暖白纸、墨绿、赤陶，
   中文衬线用于回答正文（像专家在说话），无衬线用于界面文字。
   ========================================================================== */

.chat-page {
  --navh: 90px;
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
/* 聊天页的导航必须不透明，否则下面的卡片会透上来 */
.chat-page .nav {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
.chat-page .progress { display: none; }

.chat-main {
  flex: 1;
  min-height: 0;
  display: flex;
  justify-content: center;
  padding: calc(var(--navh) + 18px) 20px 18px;
}

.chat-shell {
  width: 100%;
  max-width: 940px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border: 1px solid var(--line);
  box-shadow: 0 24px 60px -40px rgba(15, 26, 20, 0.35);
}

/* ---------- 顶部：品牌 + 标题 ---------- */
.chat-head {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
  flex: none;
}
.chat-logo {
  width: 46px;
  height: auto;
  flex: none;
}
.chat-head-text { flex: 1; min-width: 0; }
.chat-kicker {
  margin: 0 0 3px;
  font-family: var(--mono);
  font-size: 9.5px;
  letter-spacing: 0.24em;
  text-transform: uppercase;
  color: var(--moss);
}
.chat-head h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 21px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.3;
}
.chat-sub {
  margin: 4px 0 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink-3);
}
.chat-sub-2 { display: block; }
.chat-new {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  font-family: inherit;
  font-size: 12.5px;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid var(--line-hard);
  cursor: pointer;
  transition: background 0.3s var(--ease), color 0.3s var(--ease), border-color 0.3s var(--ease);
}
.chat-new svg { width: 13px; height: 13px; }
.chat-new:hover { background: var(--ink); border-color: var(--ink); color: var(--paper); }

/* ---------- 消息流 ---------- */
.chat-log {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 26px 22px 30px;
  background: var(--paper-2);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}
.chat-log::-webkit-scrollbar { width: 8px; }
.chat-log::-webkit-scrollbar-thumb { background: rgba(15, 26, 20, 0.18); border-radius: 4px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }

/* 空态 */
.chat-empty { max-width: 46em; margin: 8px auto 0; }
.chat-intro { max-width: 640px; margin-bottom: 26px; }
.chat-intro .msg-body { font-size: 15px; }
/* 全局 a 是 color:inherit + 无下划线，开场白里的电话和网址会看不出来能点，单独加下划线 */
.chat-intro a { text-decoration: underline; text-underline-offset: 2px; }
.chat-empty-lead {
  margin: 0 0 14px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.chips { display: flex; flex-direction: column; gap: 9px; align-items: flex-start; }
.chip {
  text-align: left;
  font-family: inherit;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-2);
  background: var(--paper);
  border: 1px solid var(--line);
  padding: 11px 15px;
  cursor: pointer;
  transition: border-color 0.3s var(--ease), color 0.3s var(--ease), transform 0.3s var(--ease);
}
/* 注意：style.css 里 .chip:hover 是深底深字（给知识页用的），这里必须把底色显式写回浅色，
   否则 chat.css 后加载、只覆盖了 color，就会变成深底 + 深字，一点上去看不见文字。 */
.chip:hover,
.chip:focus-visible {
  border-color: var(--terra);
  background: var(--paper);
  color: var(--ink);
  transform: translateX(3px);
}
.chip:active { background: var(--paper-2); }

/* 一条消息 */
.msg {
  display: flex;
  flex-direction: column;
  max-width: 78%;
  margin-bottom: 22px;
  animation: msgIn 0.42s var(--ease) both;
}
@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
.msg-user { margin-left: auto; align-items: flex-end; }
.msg-ai { margin-right: auto; align-items: flex-start; }

.msg-body {
  padding: 13px 17px;
  font-size: 15.5px;
  line-height: 1.82;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.msg-user .msg-body {
  background: var(--ink);
  color: var(--paper);
  border-radius: 14px 14px 3px 14px;
}
.msg-ai .msg-body {
  max-width: 62ch;                 /* 中文衬线一行 40 字上下，再宽就不好读 */
  background: var(--paper);
  color: var(--ink);
  border: 1px solid var(--line);
  border-left: 2px solid var(--terra);
  border-radius: 3px 14px 14px 14px;
  font-family: var(--serif);
}
.msg-ai .msg-body > *:first-child { margin-top: 0; }
.msg-ai .msg-body > *:last-child { margin-bottom: 0; }
.msg-body p { margin: 0 0 0.85em; }
.msg-body strong { font-weight: 600; }
.msg-body ul, .msg-body ol { margin: 0 0 0.85em; padding-left: 1.35em; }
.msg-body li { margin: 0.22em 0; }
.msg-body h3 {
  margin: 1em 0 0.45em;
  font-size: 15.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
}
.msg-body code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: rgba(15, 26, 20, 0.06);
  padding: 1px 5px;
}

.msg-body .cite {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
  color: var(--moss);
  background: rgba(61, 90, 67, 0.09);
  padding: 1px 6px;
  margin: 0 2px;
  border-radius: 2px;
  white-space: nowrap;
  vertical-align: 1px;
}
/* ---------- 回答里的素材：直接摊在正文里 ---------- */
.media-ph { display: none; }                 /* 流式过程中的占位，定稿后换成图 */
.media-set {
  display: flex;
  flex-direction: column;      /* 一张一行，根系的图横着并排会小得看不清 */
  align-items: flex-start;
  gap: 10px;
  margin: 12px 0 4px;
}
.media-shot { margin: 0; max-width: 100%; }
.media-shot img {
  display: block;
  max-width: 100%;
  max-height: 320px;
  width: auto;
  border-radius: 2px;
  cursor: zoom-in;
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
}
.media-shot video {
  display: block;
  max-width: 100%;
  max-height: 360px;
  border-radius: 2px;
  background: #000;
}
.media-shot figcaption {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--ink-3);
}

/* 素材说明：地区作物一行、看点一行、价值一行。
   跟上面那句模型括注的 figcaption 分开写，别让 mono 小字把正文压成一片灰。
   字号一律用 1em 跟着 .msg-body 走——图注是给人读的段落，不是脚注，
   正文 15.5px（窄屏 15px）时它也必须一样大，否则整块素材像被压成小字注释。 */
.media-shot figcaption.media-cap {
  margin-top: 9px;
  max-width: 34em;
  font-family: inherit;
  font-size: 1em;
  letter-spacing: 0;
  color: var(--ink);
  line-height: 1.82;
}
.media-where {
  font-family: inherit;
  font-size: 1em;
  letter-spacing: 0;
  color: var(--ink-2);        /* 这行是客户判断「这是哪儿」的唯一依据，别用最淡那档 */
  margin-bottom: 2px;
}
.media-look { margin: 0; font-size: 1em; }
.media-why {
  margin: 0.55em 0 0;
  color: var(--ink-2);
  font-size: 1em;
}

/* 附件上的文件名：正文里不写编号，这里给内部对账用。跟在图注之后，别挡在中间 */
.media-fn {
  margin-top: 7px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  color: var(--ink-3);
  opacity: 0.62;
}

/* 点开看大图：不走新窗口，省得「另存为」顺手就来 */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 4vh 4vw;
  background: rgba(10, 16, 13, 0.93);
  cursor: zoom-out;
  animation: lbIn 0.22s var(--ease) both;
}
@keyframes lbIn { from { opacity: 0; } to { opacity: 1; } }
.lightbox img {
  max-width: 100%;
  max-height: 74vh;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.5);
  -webkit-user-drag: none;
  -webkit-touch-callout: none;
  user-select: none;
}
/* 大图下面的说明：点开图的人是真在看细节，这里把「好在哪」说全。
   字号跟正文齐平（正文 15.5px），暗底上再小一档就看不清了。 */
.lb-cap {
  max-width: 700px;
  color: rgba(255, 255, 255, 0.9);
  font-size: 15.5px;
  line-height: 1.82;
  cursor: default;
}
.lb-where {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.05em;
  color: rgba(255, 255, 255, 0.52);
  margin-bottom: 6px;
}
.lb-look { margin: 0; font-weight: 600; }
.lb-why { margin: 5px 0 0; color: rgba(255, 255, 255, 0.68); }

/* 图片铺满气泡内容宽，不留深色空档（气泡宽由文字决定，图跟着走） */
.msg-img {
  margin: 0 0 9px;
  display: block;
  line-height: 0;
}
.msg-img img {
  display: block;
  width: 100%;
  max-width: 300px;
  height: auto;
  border-radius: 2px;
}

.msg-meta {
  margin-top: 6px;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.05em;
  color: var(--ink-3);
}
.msg-meta .warn { color: var(--terra); }

/* 等待中的三点 */
.typing { display: inline-flex; gap: 5px; align-items: center; padding: 3px 0; }
.typing i {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--moss-mid);
  animation: blink 1.25s infinite ease-in-out;
}
.typing i:nth-child(2) { animation-delay: 0.18s; }
.typing i:nth-child(3) { animation-delay: 0.36s; }
@keyframes blink {
  0%, 70%, 100% { opacity: 0.25; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-3px); }
}

/* 出错 */
.msg-err .msg-body {
  background: rgba(168, 80, 47, 0.07);
  border: 1px solid rgba(168, 80, 47, 0.35);
  border-left: 2px solid var(--terra);
  border-radius: 3px 14px 14px 14px;
  font-family: var(--sans);
  font-size: 14.5px;
  color: var(--ink);
}
.msg-err .retry {
  margin-top: 8px;
  font: inherit;
  font-size: 13px;
  color: var(--terra);
  background: none;
  border: 0;
  border-bottom: 1px solid currentColor;
  padding: 0 0 1px;
  cursor: pointer;
}

/* ---------- 输入区 ---------- */
.chat-foot {
  flex: none;
  padding: 14px 22px 10px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}

.chat-preview {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 11px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--paper-2);
}
/* hidden 属性会被 display:flex 压掉，必须单独写一条 */
.chat-preview[hidden] { display: none; }
.chat-preview-thumb {
  position: relative;
  flex: none;
  line-height: 0;
}
.chat-preview img {
  width: 74px; height: 74px;
  object-fit: cover;
  display: block;
  border: 1px solid var(--line-hard);
}
/* 删除键压在缩略图右上角，一眼能看到，也好点 */
.chat-preview-x {
  position: absolute;
  top: -9px; right: -9px;
  width: 26px; height: 26px;
  display: grid;
  place-items: center;
  padding: 0;
  font-family: inherit;
  font-size: 15px;
  line-height: 1;
  color: var(--paper);
  background: var(--terra);
  border: 2px solid var(--paper-2);
  border-radius: 50%;
  cursor: pointer;
  transition: background 0.2s var(--ease), transform 0.2s var(--ease);
}
.chat-preview-x:hover { background: #8d4026; transform: scale(1.08); }
.chat-preview-meta {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  color: var(--ink-3);
  min-width: 0;
}
.chat-preview-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-preview-hint { font-family: var(--mono); font-size: 10.5px; letter-spacing: 0.04em; }

.chat-input {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 6px 8px 6px 6px;
  border: 1px solid var(--line-hard);
  background: #fffdf8;
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
.chat-input:focus-within {
  border-color: var(--terra);
  box-shadow: 0 0 0 3px rgba(168, 80, 47, 0.09);
}
.chat-attach {
  flex: none;
  width: 38px; height: 38px;
  display: grid;
  place-items: center;
  color: var(--ink-3);
  cursor: pointer;
  transition: color 0.3s var(--ease), background 0.3s var(--ease);
}
.chat-attach:hover { color: var(--terra); background: var(--paper-2); }
.chat-attach svg { width: 19px; height: 19px; }

#text {
  flex: 1;
  min-width: 0;
  font-family: inherit;
  font-size: 15.5px;
  line-height: 1.65;
  color: var(--ink);
  background: transparent;
  border: 0;
  outline: 0;
  resize: none;
  padding: 8px 2px;
  /* 起步就给三行多，输入再长也不至于把上面的对话挤没 */
  min-height: 88px;
  max-height: 132px;
  overflow-y: auto;
}
#text::placeholder { color: var(--ink-3); }

.chat-send {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 16px;
  font-family: inherit;
  font-size: 13.5px;
  letter-spacing: 0.02em;
  color: var(--paper);
  background: var(--terra);
  border: 1px solid var(--terra);
  cursor: pointer;
  transition: background 0.3s var(--ease), opacity 0.3s var(--ease);
}
.chat-send svg { width: 15px; height: 15px; }
.chat-send:hover { background: #8d4026; border-color: #8d4026; }
.chat-send:disabled { opacity: 0.42; cursor: not-allowed; }

/* 今日剩余额度：一行小字，用完时转赤陶色，不弹窗、不挡输入 */
.chat-quota {
  margin: 8px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-3);
}
.chat-quota[hidden] { display: none; }
.chat-quota b { font-weight: 600; color: var(--ink-2); }
.chat-quota.out { color: var(--terra); }
.chat-quota.out b { color: var(--terra); }

.chat-note {
  margin: 9px 0 0;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--ink-3);
}.chat-note a { color: var(--ink-2); border-bottom: 1px solid var(--line-hard); }
.chat-note a:hover { color: var(--terra); border-color: var(--terra); }

/* ---------- 移动端 ---------- */
@media (max-width: 960px) {
  .chat-page { --navh: 76px; }
  .chat-main { padding: calc(var(--navh) + 10px) 0 0; }
  .chat-shell {
    max-width: none;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
    box-shadow: none;
  }
  .chat-head { padding: 14px 16px; gap: 13px; }
  .chat-logo { width: 38px; }
  .chat-head h1 { font-size: 18px; }
  /* 2026-11-13：手机上原来把这几行字藏了，导致同一页面在手机与电脑上文字不一致。
     按「以电脑端为准」的要求恢复显示，字号小一档以便排得下。 */
  .chat-sub { display: block; font-size: 11.5px; line-height: 1.45; }
  .chat-new span { display: inline; }
  .chat-new { padding: 8px 10px; font-size: 11.5px; }
  .chat-log { padding: 18px 14px 22px; }
  .msg { max-width: 88%; }
  .msg-body { font-size: 15px; padding: 11px 14px; }
  .chat-foot { padding: 10px 12px 8px; }
  /* 手机上键盘占地方，起步两行半就够 */
  #text { min-height: 74px; max-height: 108px; }
  .chat-preview img { width: 60px; height: 60px; }
  .chat-preview-hint { display: inline; font-size: 10px; }
  .media-shot img { max-height: 240px; }
  .media-shot video { max-height: 260px; }
  .chat-send { padding: 0 11px; font-size: 12.5px; }
  .chat-send .txt { display: inline; }
  .chat-log::-webkit-scrollbar { display: none; }
  .chat-head h1 { margin-bottom: 0; }
  .chat-kicker { margin-bottom: 1px; }
}
