/* ============================================================================
   问答机器人：悬浮入口 + 分步表单
   ----------------------------------------------------------------------------
   只在 base.html 引入（后台用自己的骨架，不加载）。
   位置：右下角，避让 iOS 安全区；面板在桌面是右侧抽屉、移动端是底部整屏。
   ========================================================================== */

/* ------------------------------------------------------ 01 悬浮入口 */

.bot-fab {
  position: fixed;
  right: var(--sp-3);
  bottom: calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
  /* 页头是 100、吸顶条 90，入口要压过它们才点得到 */
  z-index: 150;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 18px 12px 14px;
  font-size: var(--fs-sm);
  font-weight: 600;
  color: #fff;
  background: var(--c-primary);
  border: 0;
  border-radius: 999px;
  box-shadow: 0 6px 20px rgba(11, 26, 43, .22);
  cursor: pointer;
  transition: transform var(--t-fast), box-shadow var(--t-fast), background var(--t-fast);
}
.bot-fab:hover {
  background: var(--c-primary-dark);
  box-shadow: 0 8px 26px rgba(11, 26, 43, .3);
  transform: translateY(-2px);
}
.bot-fab:active { transform: translateY(0); }
.bot-fab .icon { flex: 0 0 auto; }

/* 首次到访轻微提示：不弹窗、不挡内容，2 秒后自己停 */
@keyframes bot-hint {
  0%, 88%, 100% { transform: translateY(0); }
  92%           { transform: translateY(-5px); }
  96%           { transform: translateY(-2px); }
}
.bot-fab.is-hinting { animation: bot-hint 3.2s var(--e-out) 1; }

/* 面板打开时藏起来，避免和关闭按钮打架 */
.bot-fab[hidden] { display: none; }

/* ------------------------------------------------------ 02 面板骨架 */

.bot-panel {
  position: fixed;
  inset: 0;
  /* 必须高于页头（100）与吸顶条（90）。之前是 80，头部会盖住关闭按钮，
     测试时表现为「按钮可见但点不动」。 */
  z-index: 200;
}
.bot-panel[hidden] { display: none; }

.bot-panel__mask {
  position: absolute;
  inset: 0;
  background: rgba(11, 26, 43, .42);
  opacity: 0;
  transition: opacity var(--t-base);
}
.bot-panel.is-open .bot-panel__mask { opacity: 1; }

.bot-panel__sheet {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  width: min(460px, 100%);
  background: var(--c-surface);
  box-shadow: -8px 0 40px rgba(11, 26, 43, .18);
  transform: translateX(100%);
  transition: transform var(--t-base) var(--e-out);
}
.bot-panel.is-open .bot-panel__sheet { transform: none; }

/* ------------------------------------------------------ 03 头部 */

.bot-head {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-2);
  padding: var(--sp-3);
  border-bottom: 1px solid var(--c-line);
}
.bot-head__main {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex: 1 1 auto;
  min-width: 0;
}
.bot-head__avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  color: #fff;
  background: var(--c-primary);
  border-radius: 10px;
}
.bot-head__title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  line-height: 1.4;
  color: var(--c-ink);
}
.bot-head__sub {
  margin: 2px 0 0;
  font-size: var(--fs-xs);
  color: var(--c-text-3);
}
.bot-head__close {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  /* 40px 是触屏可点下限；视觉上图标仍是 20px，不会显得笨重 */
  width: 40px;
  height: 40px;
  margin: -4px -4px 0 0;
  color: var(--c-text-3);
  background: transparent;
  border: 0;
  border-radius: var(--r-xs);
  cursor: pointer;
  transition: color var(--t-fast), background var(--t-fast);
}
.bot-head__close:hover { color: var(--c-ink); background: var(--c-bg-3); }

/* ------------------------------------------------------ 04 表单主体 */

.bot-form {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.bot-lead {
  margin: 0;
  padding: var(--sp-2) var(--sp-3);
  font-size: var(--fs-sm);
  line-height: 1.75;
  color: var(--c-text-2);
  background: var(--c-primary-soft);
}

.bot-body {
  flex: 1 1 auto;
  min-height: 0;
  padding: var(--sp-3);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.bot-step[hidden] { display: none; }

.bot-step__title {
  margin: 0 0 var(--sp-3);
  font-size: 15px;
  font-weight: 600;
  color: var(--c-ink);
}

/* 分组用 fieldset，去掉默认边框但保留语义（读屏能报出组名） */
.bot-field {
  margin: 0 0 var(--sp-3);
  padding: 0;
  border: 0;
}
.bot-field[hidden] { display: none; }
.bot-field legend { padding: 0; }

/* ------------------------------------------------------ 05 选项片 */

.bot-chips {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.bot-chips--wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.bot-chips--sm { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.bot-chip {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 9px 6px;
  font-size: var(--fs-sm);
  text-align: center;
  color: var(--c-text-2);
  background: var(--c-surface);
  border: 1px solid var(--c-line-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: border-color var(--t-fast), color var(--t-fast), background var(--t-fast);
}
.bot-chip:hover { border-color: var(--c-text-3); }

/* 原生控件藏起来但保持可聚焦，键盘和读屏都能用 */
.bot-chip input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* 选中态：:has 支持度已够（Chrome 105+ / Safari 15.4+）；不支持时靠 :focus-visible 兜底 */
.bot-chip:has(input:checked) {
  color: var(--c-primary-dark);
  background: var(--c-primary-soft);
  border-color: var(--c-primary);
  font-weight: 600;
}
.bot-chip:has(input:focus-visible) {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

/* ------------------------------------------------------ 06 问题清单 */

.bot-issues { display: grid; gap: 8px; }

.bot-issue {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 11px 12px;
  font-size: var(--fs-sm);
  line-height: 1.6;
  color: var(--c-text-2);
  background: var(--c-surface);
  border: 1px solid var(--c-line-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: border-color var(--t-fast), background var(--t-fast);
}
.bot-issue:hover { border-color: var(--c-text-3); }

.bot-issue input {
  position: absolute;
  width: 1px; height: 1px;
  opacity: 0;
  pointer-events: none;
}

/* 自绘勾选框，比原生 checkbox 更贴合设计系统 */
.bot-issue::before {
  content: "";
  flex: 0 0 auto;
  width: 16px;
  height: 16px;
  margin-top: 2px;
  border: 1.5px solid var(--c-line-2);
  border-radius: 4px;
  transition: background var(--t-fast), border-color var(--t-fast);
}
.bot-issue:has(input:checked) {
  border-color: var(--c-primary);
  background: var(--c-primary-soft);
}
.bot-issue:has(input:checked)::before {
  background: var(--c-primary) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23fff' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m3.5 8.5 3 3 6-6'/%3E%3C/svg%3E") center / 12px no-repeat;
  border-color: var(--c-primary);
}
.bot-issue:has(input:focus-visible) {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
}

/* ------------------------------------------------------ 07 联系方式 */

.bot-contact {
  margin-top: var(--sp-3);
  padding-top: var(--sp-3);
  border-top: 1px dashed var(--c-line-2);
}
.bot-contact__title {
  margin: 0 0 var(--sp-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--c-ink);
}

.bot-privacy {
  margin: var(--sp-2) 0 0;
  font-size: var(--fs-xs);
  line-height: 1.7;
  color: var(--c-text-3);
}

/* ------------------------------------------------------ 08 提交成功 */

.bot-done {
  padding: var(--sp-5) var(--sp-2);
  text-align: center;
}
.bot-done__icon { color: var(--c-success); }
.bot-done__icon .icon { width: 56px; height: 56px; }
.bot-done__title {
  margin: var(--sp-2) 0 var(--sp-1);
  font-size: 17px;
  font-weight: 600;
  color: var(--c-ink);
}
.bot-done__text {
  margin: 0;
  font-size: var(--fs-sm);
  line-height: 1.8;
  color: var(--c-text-2);
}
.bot-done__text a { color: var(--c-primary); font-weight: 600; }

/* ------------------------------------------------------ 09 底部操作 */

.bot-foot {
  flex: 0 0 auto;
  padding: var(--sp-2) var(--sp-3) calc(var(--sp-3) + env(safe-area-inset-bottom, 0px));
  background: var(--c-surface);
  border-top: 1px solid var(--c-line);
}

.bot-progress {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
}
.bot-progress[hidden] { display: none; }
.bot-progress__bar {
  flex: 1 1 auto;
  height: 3px;
  background: var(--c-bg-3);
  border-radius: 999px;
  overflow: hidden;
}
.bot-progress__bar i {
  display: block;
  height: 100%;
  background: var(--c-primary);
  border-radius: 999px;
  transition: width var(--t-base) var(--e-out);
}
.bot-progress__text {
  flex: 0 0 auto;
  font-size: 11px;
  color: var(--c-text-3);
  font-variant-numeric: tabular-nums;
}

.bot-actions {
  display: flex;
  gap: var(--sp-1);
  justify-content: flex-end;
}
.bot-actions .btn { min-width: 96px; }
.bot-actions .btn[hidden] { display: none; }

.bot-alert {
  margin: var(--sp-2) 0 0;
  padding: 8px 10px;
  font-size: var(--fs-xs);
  line-height: 1.6;
  color: #B4232A;
  background: #FDF1F1;
  border: 1px solid #F3C9C9;
  border-radius: var(--r-xs);
}
.bot-alert[hidden] { display: none; }

/* ------------------------------------------------------ 10 响应式 */

/* 移动端改成底部整屏，避免右侧抽屉只剩一条窄缝 */
@media (max-width: 560px) {
  .bot-panel__sheet {
    top: auto;
    left: 0;
    width: 100%;
    max-height: 92vh;
    height: auto;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    transform: translateY(100%);
  }
  .bot-panel.is-open .bot-panel__sheet { transform: none; }

  .bot-fab {
    right: var(--sp-2);
    padding: 11px 16px 11px 12px;
  }
  /* 窄屏藏掉按钮文字，只留图标，别挡住内容 */
  .bot-fab__text { display: none; }
  .bot-fab { padding: 13px; }

  .bot-chips,
  .bot-chips--sm { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bot-chips--wide { grid-template-columns: 1fr; }

  .bot-foot { padding-bottom: calc(var(--sp-2) + env(safe-area-inset-bottom, 0px)); }
  .bot-actions .btn { flex: 1 1 auto; }
}

/* 减少动效偏好：去掉位移动画，只保留状态切换 */
@media (prefers-reduced-motion: reduce) {
  .bot-panel__sheet { transition: none; }
  .bot-fab.is-hinting { animation: none; }
}

/* 打印时不该出现 */
@media print {
  .bot-fab,
  .bot-panel { display: none !important; }
}
