/* =========================================================
   制度问答（知识库问答 · 聊天页）  —— 2026-10-10 重设计
   设计基调：延续主系统「品牌黑红 + 玻璃拟态」，三主题（light/dark/system）自适应
   结构：.qa-layout = [.qa-chat 滚动消息] + [.qa-quick 推荐问题] + [.qa-composer 输入区]
   适配：≥900px 桌面卡片限宽居中；<900px 铺满并让出底部导航；
        高度由 JS（qaFit）按实际视口精算后写回 #page-qa，杜绝 calc 猜值
   ========================================================= */

/* ---------- 页面容器：让卡片吃掉 topbar 以下的全部可用高度 ---------- */
#page-qa.on {
  display: flex; flex-direction: column;
  height: calc(100vh - 190px);   /* 兜底值，JS 就绪后覆盖为精确像素 */
  min-height: 360px;
  padding-bottom: 0;
}
/* QA 页内部自滚动，屏蔽主容器为底部导航预留的 padding，避免多出一条页面级滚动 */
.app-main.qa-full { padding-bottom: 0 !important; }

/* 顶栏右侧说明（桌面显示、窄屏收起） */
.qa-tag {
  flex: none; max-width: 46%;
  font-size: 12.5px; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------- 聊天卡片 ---------- */
.qa-layout {
  position: relative;
  flex: 1 1 auto; min-height: 0;
  display: flex; flex-direction: column;
  margin: 10px 12px 12px;
  background: var(--card-solid);
  border: 1px solid var(--border);
  border-radius: var(--r-lg, 18px);
  box-shadow: var(--shadow-md);
  overflow: hidden;
  isolation: isolate;
}
/* 顶部一层极淡品牌光晕，给卡片「被激活」的观感（纯 CSS，零资源） */
.qa-layout::before {
  content: ''; position: absolute; inset: 0 0 auto; height: 140px; z-index: 0;
  pointer-events: none;
  background: radial-gradient(120% 100% at 50% 0%, rgba(198, 40, 40, .06), rgba(198, 40, 40, 0) 72%);
}

/* ---------- 消息区 ---------- */
.qa-chat {
  position: relative; z-index: 1;
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; overscroll-behavior: contain;
  padding: 18px 16px 8px;
  display: flex; flex-direction: column; gap: 14px;
  scrollbar-width: thin;
  scrollbar-color: rgba(148, 152, 162, .38) transparent;
}
.qa-chat::-webkit-scrollbar { width: 6px; }
.qa-chat::-webkit-scrollbar-thumb { background: rgba(148, 152, 162, .32); border-radius: 99px; }
.qa-chat::-webkit-scrollbar-track { background: transparent; }

.msg { display: flex; gap: 10px; align-items: flex-start; max-width: 86%; }
.msg .av {
  flex: none; width: 36px; height: 36px; border-radius: 50%;
  overflow: hidden; display: grid; place-items: center;
  background: linear-gradient(135deg, #8B0000, #C62828);
  border: 1px solid rgba(255, 255, 255, .55);
  box-shadow: 0 4px 10px -4px rgba(198, 40, 40, .5);
}
.msg .av img { width: 100%; height: 100%; object-fit: cover; display: block; }
.msg .bubble {
  position: relative;
  padding: 11px 14px;
  border-radius: 6px 16px 16px 16px;
  font-size: 14px; line-height: 1.62;
  background: var(--card-solid);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  overflow-wrap: break-word; word-break: break-word;
}
.msg.ai { align-self: flex-start; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.me .bubble {
  border-radius: 16px 6px 16px 16px;
  background: linear-gradient(135deg, #8B0000 0%, #B71C1C 55%, #D32F2F 100%);
  color: #fff; border-color: transparent;
  box-shadow: 0 6px 16px -8px rgba(198, 40, 40, .65);
}

/* 出处标注：从「虚线分隔」升级为独立胶囊，长文档名可省略号收口 */
.qa-src {
  display: flex; align-items: center; gap: 5px;
  width: max-content; max-width: 100%;
  margin-top: 10px; padding: 4px 11px;
  border-radius: 999px;
  font-size: 11.5px; line-height: 1.6;
  background: rgba(198, 40, 40, .07);
  border: 1px solid rgba(198, 40, 40, .16);
  color: var(--brand-1);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg.me .qa-src {
  background: rgba(255, 255, 255, .18);
  border-color: rgba(255, 255, 255, .34);
  color: #fff;
}

/* 生成中：三点跳动（替代原 clip-path 方案，跟随文字色、三主题通用） */
.qa-typing {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13.5px; color: var(--text-sub);
}
.qa-typing i {
  width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .3;
  animation: qaDot 1.15s infinite ease-in-out;
}
.qa-typing i:nth-child(2) { animation-delay: .16s; }
.qa-typing i:nth-child(3) { animation-delay: .32s; }
@keyframes qaDot {
  0%, 60%, 100% { opacity: .25; transform: translateY(0); }
  30% { opacity: .95; transform: translateY(-3px); }
}

/* ---------- 推荐问题（横向滚动一条，不占纵向空间） ---------- */
.qa-quick { position: relative; z-index: 1; flex: none; padding-bottom: 10px; }
.qa-quick-hd {
  padding: 0 16px 7px;
  font-size: 11.5px; color: var(--text-dim); letter-spacing: .2px;
}
.qa-chips {
  display: flex; gap: 8px; align-items: center;
  overflow-x: auto; overscroll-behavior-x: contain;
  padding: 1px 16px 2px;
  scroll-snap-type: x proximity;
  scrollbar-width: none; -ms-overflow-style: none;
  /* 两端渐隐：暗示「可横向滑动」，避免胶囊被卡片边缘硬切 */
  -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 22px), transparent 100%);
  mask-image: linear-gradient(90deg, transparent 0, #000 16px, #000 calc(100% - 22px), transparent 100%);
}
.qa-chips::-webkit-scrollbar { display: none; }
.qa-chips:empty { display: none; }
.qa-chips .chip {
  flex: 0 0 auto; scroll-snap-align: start;
  padding: 8px 14px; border-radius: 999px;
  font-size: 12.5px; line-height: 1.35; white-space: nowrap;
  background: var(--card-solid); color: var(--text-sub);
  border: 1px solid var(--border);
  cursor: pointer;
  /* 覆盖 app.css 通用 .chip 的 max-width:180px（否则推荐问题会被硬裁成省略号） */
  max-width: 300px;
  overflow: hidden; text-overflow: ellipsis;
  transition: color .18s var(--ease), border-color .18s var(--ease),
              background .18s var(--ease), transform .18s var(--ease);
}
.qa-chips .chip:hover {
  color: var(--brand-1); border-color: rgba(198, 40, 40, .42);
  background: rgba(198, 40, 40, .05); transform: translateY(-1px);
}
.qa-chips .chip:active { transform: scale(.97); }

/* ---------- 输入区（本次重设计重点） ---------- */
.qa-composer {
  position: relative; z-index: 1; flex: none;
  padding: 12px 14px 10px;
  border-top: 1px solid var(--border);
  background: var(--card-solid);
}
/* 一体化胶囊：左侧小图标 + 无边框自增高输入域 + 右侧圆形发送键 */
.qa-input {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 5px 5px 5px 13px;
  border: 1px solid var(--border);
  border-radius: 24px;
  background: var(--bg-1, var(--card-solid));
  transition: border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.qa-input.focus {
  border-color: rgba(198, 40, 40, .5);
  box-shadow: 0 0 0 3px rgba(198, 40, 40, .11);
}
.qa-input-ico {
  flex: none; width: 20px; height: 20px; margin-bottom: 9px;
  display: grid; place-items: center;
  font-size: 15px; line-height: 1; opacity: .85;
}
.qa-input textarea {
  flex: 1 1 auto; min-width: 0;
  border: none; outline: none; resize: none;
  background: transparent; color: var(--text);
  font: inherit; font-size: 14px; line-height: 1.5;
  padding: 9px 0; max-height: 132px;
  scrollbar-width: thin;
}
.qa-input textarea::placeholder { color: var(--text-dim); }
.qa-count {
  flex: none; align-self: center; padding-bottom: 2px;
  font-size: 11px; color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  opacity: 0; transition: opacity .2s var(--ease);
}
.qa-input.focus .qa-count { opacity: 1; }
.qa-count.warn { color: var(--brand-1); font-weight: 600; }
.qa-send {
  flex: none; width: 38px; height: 38px; border-radius: 50%;
  border: none; cursor: pointer; padding: 0;
  display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, #8B0000, #C62828 58%, #E53935);
  box-shadow: 0 6px 14px -6px rgba(198, 40, 40, .72);
  transition: transform .18s var(--ease), box-shadow .18s var(--ease),
              background .18s var(--ease), color .18s var(--ease);
}
.qa-send svg { width: 17px; height: 17px; }
.qa-send:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 8px 18px -6px rgba(198, 40, 40, .8); }
.qa-send:active:not(:disabled) { transform: scale(.92); }
.qa-send:disabled { background: var(--gray-btn); color: var(--gray-btn-tx); box-shadow: none; cursor: not-allowed; }
.qa-send.busy svg { display: none; }
.qa-send.busy::after {
  content: ''; width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .45); border-top-color: #fff;
  animation: qaSpin .7s linear infinite;
}
@keyframes qaSpin { to { transform: rotate(360deg); } }
.qa-tips {
  margin-top: 7px; padding: 0 4px;
  font-size: 11px; color: var(--text-dim);
  text-align: center; letter-spacing: .1px;
}

/* ---------- 消息入场 ---------- */
@media (prefers-reduced-motion: no-preference) {
  .msg { animation: qaMsgIn .32s var(--ease); }
  @keyframes qaMsgIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
  }
}

/* =========================================================
   深色主题修正：--card-solid 与 --bg-1 同色，气泡/输入框会「消失」，
   --brand-1(#C62828) 在深底上仅约 2.9:1 也偏低 —— 逐项提亮
   ========================================================= */
[data-theme='dark'] .qa-layout::before {
  background: radial-gradient(120% 100% at 50% 0%, rgba(229, 57, 53, .10), rgba(229, 57, 53, 0) 72%);
}
[data-theme='dark'] .msg .bubble {
  background: rgba(255, 255, 255, .045);
  border-color: rgba(255, 255, 255, .10);
}
[data-theme='dark'] .msg .av { border-color: rgba(255, 255, 255, .18); }
/* 来源胶囊：底色加厚 + 文字提到 #FF8A80 档，深底对比度 ~7:1 */
[data-theme='dark'] .qa-src {
  background: rgba(198, 40, 40, .16);
  border-color: rgba(229, 57, 53, .30);
  color: #FF9A90;
}
[data-theme='dark'] .qa-input {
  background: rgba(255, 255, 255, .04);
  border-color: rgba(255, 255, 255, .13);
}
[data-theme='dark'] .qa-input.focus {
  border-color: rgba(229, 57, 53, .60);
  box-shadow: 0 0 0 3px rgba(229, 57, 53, .16);
}
[data-theme='dark'] .qa-chips .chip {
  background: rgba(255, 255, 255, .05);
  border-color: rgba(255, 255, 255, .11);
}
[data-theme='dark'] .qa-chips .chip:hover {
  color: #FF9A90; border-color: rgba(229, 57, 53, .45);
  background: rgba(198, 40, 40, .16);
}

/* =========================================================
   桌面端（≥900px）：主容器已有 248px 侧边栏，页面限宽居中
   ========================================================= */
@media (min-width: 900px) {
  #page-qa { max-width: 1000px; padding: 0 28px 0; }
  .qa-layout { margin: 12px 0 0; }
  .qa-chat { padding: 20px 22px 8px; gap: 15px; }
  .qa-chips, .qa-quick-hd { padding-left: 22px; padding-right: 22px; }
  .qa-composer { padding: 12px 22px 14px; }
  .msg { max-width: 74%; }
  .qa-input { border-radius: 24px; padding-left: 15px; }
  .qa-send { width: 40px; height: 40px; }
  .qa-send svg { width: 18px; height: 18px; }
}

/* =========================================================
   平板 / 手机（<900px）：铺满视口，让出底部导航
   ========================================================= */
@media (max-width: 899px) {
  #page-qa { max-width: 100%; padding: 0; }
  .qa-layout { margin: 6px 10px 10px; border-radius: 16px; }
  .qa-chat { padding: 14px 12px 6px; gap: 12px; }
  .msg { max-width: 90%; }
  .msg .av { width: 32px; height: 32px; }
  .msg .bubble { padding: 10px 13px; font-size: 14px; }
  .qa-quick-hd { padding-left: 12px; padding-right: 12px; }
  .qa-chips { padding-left: 12px; padding-right: 12px; }
  .qa-composer { padding: 10px 10px 10px; }
  .qa-input { border-radius: 22px; }
  /* iOS 聚焦不缩放（字号 <16px 会触发自动放大） */
  .qa-input textarea { font-size: 16px; }
  .qa-tips { display: none; }
  .qa-tag { display: none; }
}

/* 窄屏手机 */
@media (max-width: 420px) {
  .qa-layout { margin: 4px 8px 8px; border-radius: 14px; }
  .qa-chat { padding: 12px 10px 4px; gap: 11px; }
  .msg { max-width: 94%; }
  .qa-quick-hd { padding-left: 10px; padding-right: 10px; font-size: 11px; }
  .qa-chips { padding-left: 10px; padding-right: 10px; gap: 7px; }
  .qa-chips .chip { padding: 7px 12px; font-size: 12px; }
  .qa-composer { padding: 9px 9px 9px; }
  .qa-input { padding-left: 11px; gap: 6px; }
  .qa-send { width: 38px; height: 38px; }
}

/* 极窄屏（≤360px）：收起输入框前缀图标，把宽度让给文字 */
@media (max-width: 360px) {
  .qa-input-ico { display: none; }
  .qa-input { padding-left: 13px; }
}
