/* ==================== AI 对话界面 ==================== */
/* 完全复用 main.css 的 :root 设计系统（--primary: #0D9488 等） */

/* 100dvh 适配移动端地址栏 + 底部导航 */
.ai-chat-container {
  padding: 0 !important;
  padding-bottom: 0 !important;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  overflow: hidden;
  flex: 1;
  min-height: 0;
}

@media (max-width: 1024px) {
  #aiPage.page.active > main.ai-chat-container {
    padding-top: 0 !important;
    margin-top: calc(var(--safe-top, env(safe-area-inset-top, 0px)) + var(--mobile-chrome-row, 48px) + 6px);
  }
}

@media (min-width: 768px) {
  .ai-chat-container {
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
  }
}

@media (min-width: 1025px) {
  .ai-chat-container {
    height: calc(100dvh - 48px);
  }
}

.ai-chat-root {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg-secondary, #F1F5F9);
}

/* ── 消息列表 ── */
.ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  box-sizing: border-box;
}
.ai-chat-messages.has-conversation #aiChatEmpty {
  display: none !important;
}
.ai-chat-messages:not(.has-conversation) #aiChatEmpty {
  flex: 1;
  min-height: 0;
  width: 100%;
}

/* ── 空态 ── */
.ai-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px 28px;
  text-align: center;
  flex: 1;
}
.ai-chat-empty-inner {
  background: var(--card, #FFF);
  border-radius: 20px;
  padding: 36px 24px 28px;
  max-width: 400px;
  width: 100%;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
  display: flex;
  flex-direction: column;
  align-items: center;
}
.ai-chat-empty-avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary, #0D9488), #14B8A6);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin-bottom: 16px;
  line-height: 1;
  box-shadow: 0 0 24px rgba(13, 148, 136, 0.12);
}
.ai-chat-empty-avatar .fa-robot {
  font-size: 34px;
}
.ai-chat-empty-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary, #1E293B);
  margin: 0 0 2px;
}
.ai-chat-empty-region-tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--primary, #0D9488);
  background: var(--primary-lighter, #F0FDFA);
  padding: 4px 12px;
  border-radius: 20px;
  margin-bottom: 16px;
  font-weight: 500;
}
.ai-chat-empty-hint {
  font-size: 13px;
  color: var(--text-tertiary, #94A3B8);
  margin: 0 0 16px;
}
.ai-chat-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  max-width: 340px;
}
.ai-chat-suggestion-chip {
  padding: 8px 16px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 20px;
  background: var(--card, #FFF);
  font-size: 13px;
  color: var(--text-primary, #1E293B);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  line-height: 1.4;
  text-align: center;
}
.ai-chat-suggestion-chip:hover {
  border-color: var(--primary, #0D9488);
  background: var(--primary-lighter, #F0FDFA);
}

/* ── Loading / 状态行（勿用 ai-chat-message，避免误判已有对话） ── */
.ai-chat-status {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: min(92%, 560px);
  align-self: flex-start;
}
.ai-chat-status.is-hidden {
  display: none !important;
}

/* ── 消息气泡 ── */
.ai-chat-message {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 88%;
  width: auto;
  animation: aiChatFadeIn 0.25s ease;
  position: relative;
}
.ai-chat-message--ai {
  align-self: flex-start;
  max-width: min(92%, 560px);
  width: 100%;
}
.ai-chat-message--user {
  align-self: flex-end;
  flex-direction: row-reverse;
  max-width: 85%;
  width: auto;
}
.ai-chat-message-body {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  min-width: 0;
  flex: 1;
  width: 100%;
  gap: 0;
}
.ai-chat-message + .ai-chat-message--user,
.ai-chat-message--user + .ai-chat-message {
  margin-top: 4px;
}
.ai-chat-message--ai + .ai-chat-message--user,
.ai-chat-message--user + .ai-chat-message--ai {
  margin-top: 16px;
}

.ai-chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary, #0D9488);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  line-height: 1;
}
.ai-chat-avatar .fa-robot {
  font-size: 17px;
}

.ai-chat-bubble {
  padding: 12px 14px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.55;
  overflow-wrap: break-word;
  word-break: normal;
  white-space: pre-wrap;
  position: relative;
  max-width: 100%;
}
.ai-chat-message--user .ai-chat-bubble {
  background: var(--primary, #0D9488);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ai-chat-message--user .ai-chat-bubble::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: -6px;
  width: 10px;
  height: 10px;
  background: var(--primary, #0D9488);
  border-radius: 2px;
  clip-path: polygon(0 0, 100% 0, 100% 100%);
}
.ai-chat-message--ai .ai-chat-bubble {
  background: var(--primary-light, #CCFBF1);
  color: var(--text-primary, #1E293B);
  border-bottom-left-radius: 4px;
}
.ai-chat-message--ai .ai-chat-bubble::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: -6px;
  width: 10px;
  height: 10px;
  background: var(--primary-light, #CCFBF1);
  border-radius: 2px;
  clip-path: polygon(0 0, 0 100%, 100% 100%);
}

.ai-chat-timestamp {
  display: block;
  font-size: 11px;
  color: var(--text-tertiary, #94A3B8);
  margin-top: 6px;
  text-align: right;
  align-self: flex-end;
}
.ai-chat-message--ai .ai-chat-source,
.ai-chat-message--ai .ai-chat-pro-upsell {
  width: 100%;
  box-sizing: border-box;
}
.ai-chat-message--user .ai-chat-timestamp {
  color: rgba(255, 255, 255, 0.7);
}

/* ── 来源标签 ── */
.ai-chat-source {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid rgba(13, 148, 136, 0.15);
  font-size: 12px;
  color: var(--primary, #0D9488);
  cursor: pointer;
}
.ai-chat-source:hover {
  text-decoration: underline;
}

/* ── 反馈行 ── */
.ai-chat-feedback {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.ai-chat-feedback-btn {
  padding: 4px 12px;
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 16px;
  background: var(--card, #FFF);
  font-size: 13px;
  color: var(--text-secondary, #64748B);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}
.ai-chat-feedback-btn:hover {
  border-color: var(--primary, #0D9488);
  background: var(--primary-lighter, #F0FDFA);
}
.ai-chat-feedback-btn--active {
  background: var(--primary-light, #CCFBF1);
  border-color: var(--primary, #0D9488);
  color: var(--primary, #0D9488);
}

/* ── 图片内联 ── */
.ai-chat-image {
  max-width: 200px;
  border-radius: 12px;
  margin-top: 8px;
  display: block;
}

/* ── 打字动画 ── */
.ai-chat-typing-dot {
  animation: aiChatTyping 1.4s infinite;
  font-size: 20px;
  line-height: 1;
  color: var(--primary, #0D9488);
}
.ai-chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes aiChatTyping {
  0%, 60%, 100% { opacity: 0.3; }
  30% { opacity: 1; }
}

@keyframes aiChatFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Error 横幅 ── */
.ai-chat-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--danger-light, #FEE2E2);
  border: 1px solid var(--danger, #EF4444);
  border-radius: 12px;
  font-size: 14px;
  color: var(--danger, #EF4444);
  margin: 8px 0;
}
#aiChatRetryBtn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--danger, #EF4444);
  border-radius: 8px;
  padding: 4px 12px;
  color: var(--danger, #EF4444);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
}
#aiChatRetryBtn:hover {
  background: var(--danger-light, #FEE2E2);
}

/* ── 底部输入区 ── */
.ai-chat-input-area {
  position: sticky;
  bottom: 0;
  background: var(--card, #FFF);
  border-top: none;
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -4px 16px rgba(15, 23, 42, 0.08);
  padding: 8px 12px calc(8px + var(--safe-bottom, env(safe-area-inset-bottom, 0px)));
  z-index: 10;
  flex-shrink: 0;
  box-sizing: border-box;
}

/* 手机/平板：输入 dock 固定贴底栏正上方（消除与底栏之间的空隙） */
@media (max-width: 1024px) {
  #aiPage:not([data-view="pricing"]) .ai-chat-input-area {
    position: fixed;
    left: 50%;
    right: auto;
    transform: translateX(-50%);
    bottom: calc(var(--mobile-tab-row, 56px) + var(--safe-bottom, env(safe-area-inset-bottom, 0px)));
    width: 100%;
    max-width: min(100%, 480px);
    margin: 0;
    z-index: 96;
    padding: 8px 12px 10px;
    box-sizing: border-box;
    border-radius: 16px 16px 0 0;
    display: flex;
    flex-direction: column;
    align-items: stretch;
  }

  #aiPage:not([data-view="pricing"]) .ai-chat-messages {
    padding-bottom: calc(
      128px + var(--mobile-tab-row, 56px) + var(--safe-bottom, env(safe-area-inset-bottom, 0px))
    );
  }

  .ai-chat-input-shell {
    display: flex !important;
    flex-direction: row !important;
    align-items: flex-end !important;
    width: 100%;
    box-sizing: border-box;
  }

  .ai-chat-input {
    flex: 1 1 auto;
    min-width: 0;
    width: auto;
  }

  .ai-chat-quota-meter {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .ai-chat-empty {
    justify-content: flex-start;
    padding-top: 20px;
  }
}

/* ── 豆包式一体输入 shell ── */
.ai-chat-input-shell {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  min-height: 48px;
  padding: 4px 4px 4px 6px;
  background: var(--bg-secondary, #F1F5F9);
  border: 1px solid var(--border, #E2E8F0);
  border-radius: 24px;
  transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
}
.ai-chat-input-shell:focus-within {
  background: var(--card, #FFF);
  border-color: var(--primary, #0D9488);
  box-shadow: 0 0 0 4px rgba(13, 148, 136, 0.08);
}
.ai-chat-plus-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--text-secondary, #64748B);
  transition: background 0.15s, color 0.15s;
  line-height: 1;
  padding: 0;
  font-family: inherit;
}
.ai-chat-plus-btn:hover,
.ai-chat-plus-btn:active {
  background: rgba(15, 23, 42, 0.06);
  color: var(--text-primary, #1E293B);
}
.ai-chat-file-input {
  display: none;
}

/* ── 图片预览（shell 上方） ── */
.ai-chat-image-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 4px 8px;
}
.ai-chat-image-preview.is-hidden {
  display: none !important;
}
.ai-chat-image-preview img,
.ai-chat-image-preview .preview-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border, #E2E8F0);
}
.ai-chat-remove-img,
.ai-chat-image-preview .preview-clear {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--danger, #EF4444);
  color: #fff;
  border: none;
  font-size: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  flex-shrink: 0;
}

.ai-chat-input {
  flex: 1;
  min-width: 0;
  border: none;
  border-radius: 0;
  padding: 8px 4px;
  font-size: 15px;
  line-height: 1.5;
  resize: none;
  max-height: 120px;
  outline: none;
  background: transparent;
  font-family: inherit;
  box-sizing: border-box;
}
.ai-chat-input:focus {
  border: none;
  box-shadow: none;
  background: transparent;
}
.ai-chat-input::placeholder {
  color: var(--text-tertiary, #94A3B8);
}

.ai-chat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--primary, #0D9488);
  color: #fff;
  border: none;
  font-size: 17px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s, background 0.15s;
  line-height: 1;
  padding: 0;
}
.ai-chat-send-btn .fa-arrow-up {
  font-size: 16px;
  font-weight: 700;
}
.ai-chat-send-btn:hover:not(:disabled) {
  background: var(--primary-hover, #0F766E);
  transform: scale(1.04);
}
.ai-chat-send-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  transform: none;
}

/* ── 附件 sheet ── */
.ai-attach-drawer {
  padding-top: 8px;
  padding-bottom: calc(16px + var(--safe-bottom, env(safe-area-inset-bottom, 0px)));
}
.ai-attach-sheet-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 8px 4px 4px;
}
.ai-attach-sheet-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  border-radius: 12px;
  transition: background 0.15s;
}
.ai-attach-sheet-item:hover,
.ai-attach-sheet-item:active {
  background: var(--bg-secondary, #F1F5F9);
}
.ai-attach-sheet-icon {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  background: var(--bg-secondary, #F1F5F9);
  border: 1px solid var(--border, #E2E8F0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  color: var(--primary, #0D9488);
}
.ai-attach-sheet-label {
  font-size: 12px;
  color: var(--text-secondary, #64748B);
  line-height: 1.3;
}

/* ── 额度进度条（仅条 + 小字，点击进定价） ── */
.ai-chat-quota-meter {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px 2px;
  margin-top: 2px;
  cursor: pointer;
  border: none;
  background: transparent;
  width: 100%;
  box-sizing: border-box;
  font-family: inherit;
  text-align: left;
}
.ai-chat-quota-meter:focus-visible {
  outline: 2px solid var(--primary, #0D9488);
  outline-offset: 2px;
  border-radius: 8px;
}
.ai-chat-quota-meter-track {
  flex: 1;
  height: 3px;
  border-radius: 999px;
  background: var(--border, #E2E8F0);
  overflow: hidden;
  min-width: 0;
}
.ai-chat-quota-meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--primary, #0D9488);
  transition: width 0.25s ease, background 0.2s;
}
.ai-chat-quota-meter-label {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-tertiary, #94A3B8);
  font-variant-numeric: tabular-nums;
  min-width: 2.8em;
  text-align: right;
}
.ai-chat-quota-meter--low .ai-chat-quota-meter-fill {
  background: #F59E0B;
}
.ai-chat-quota-meter--low .ai-chat-quota-meter-label {
  color: #B45309;
}
.ai-chat-quota-meter--empty .ai-chat-quota-meter-fill {
  background: #CBD5E1;
  width: 100% !important;
}
.ai-chat-quota-meter--empty .ai-chat-quota-meter-label {
  color: var(--text-secondary, #64748B);
}
.ai-chat-quota-meter--unlimited {
  cursor: default;
  justify-content: center;
  padding-top: 6px;
}
.ai-chat-quota-meter--unlimited .ai-chat-quota-meter-label {
  color: var(--primary, #0D9488);
  font-weight: 600;
  min-width: 0;
}
.ai-chat-dev-quota-btn {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 6px 10px;
  border: 1px dashed #CBD5E1;
  border-radius: 10px;
  background: #FFFBEB;
  color: #B45309;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  box-sizing: border-box;
}
.ai-chat-dev-quota-btn.is-hidden {
  display: none !important;
}
.ai-chat-dev-quota-btn--active {
  background: #ECFDF5;
  border-color: #6EE7B7;
  color: #047857;
}
.ai-chat-dev-quota-btn:hover {
  opacity: 0.9;
}

/* ── AI 页顶栏地区选择器（与攻略页 gcv2-region-picker 对齐） ── */
#aiPage .header-right {
  position: relative;
  flex-shrink: 0;
}
#aiPage .gcv2-region-picker {
  position: relative;
  flex-shrink: 0;
}
#aiPage .gcv2-region-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  max-width: min(240px, 62vw);
  background: var(--primary-light);
  color: var(--primary);
  border: none;
  border-radius: var(--radius-full, 20px);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  min-width: 0;
  font-family: inherit;
}
#aiPage .gcv2-region-pill-text {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
#aiPage .gcv2-region-pill .arrow {
  font-size: 10px;
  opacity: 0.75;
  flex-shrink: 0;
  transition: transform 0.2s;
}
#aiPage .gcv2-region-picker.active .gcv2-region-pill .arrow {
  transform: rotate(180deg);
}
#aiPage .gcv2-region-panel {
  display: none !important;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: auto;
  z-index: 120;
  width: min(336px, calc(100vw - 24px));
  max-height: min(420px, 60vh);
  overflow: auto;
  padding: 10px 12px 12px;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
  border: 1px solid var(--border-light, #e2e8f0);
  box-sizing: border-box;
}
#aiPage .gcv2-region-panel.show {
  display: block !important;
}
#aiPage .gcv2-region-panel-hint {
  margin: 0 0 10px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--text-tertiary, #94a3b8);
}
#aiPage .gcv2-region-panel-section + .gcv2-region-panel-section {
  margin-top: 10px;
}
#aiPage .gcv2-region-panel-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary, #64748b);
  margin-bottom: 6px;
}
#aiPage .gcv2-region-chip-scroll {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}
#aiPage .gcv2-region-chip {
  border: 1px solid var(--border-light, #e2e8f0);
  background: var(--bg-secondary, #f8fafc);
  color: var(--text-primary, #1e293b);
  border-radius: 10px;
  padding: 7px 4px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
#aiPage .gcv2-region-chip.is-active {
  border-color: var(--primary, #0d9488);
  background: var(--primary-lighter, #f0fdfa);
  color: var(--primary, #0d9488);
  font-weight: 600;
}

/* ── is-hidden 工具类 ── */
.is-hidden {
  display: none !important;
}

