/* ==========================================================================
   移动端适配
   ──────────────────────────────────────────────────────────────────────────
   修复内容：
     1. 导航栏：汉堡菜单 + 抽屉式展开
     2. 表格：横向滚动，不撑破容器
     3. 网格：单列堆叠
     4. 字号与间距：缩小适配窄屏
     5. 防止横向溢出
   ========================================================================== */

/* ──────────────────────────────────────────────────────────
   1. 导航栏：桌面隐藏汉堡，移动端收起菜单
   ────────────────────────────────────────────────────────── */
.nav-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 34px;
  height: 34px;
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  flex: none;
}
.nav-toggle span {
  display: block;
  width: 18px;
  height: 2px;
  margin: 0 auto;
  background: var(--ink-2);
  border-radius: 2px;
  transition: transform .25s ease, opacity .2s ease;
}
.nav-toggle[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.nav-toggle[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.nav-toggle[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

@media (max-width: 860px) {
  /* 汉堡按钮出现 */
  .nav-toggle { display: flex; }

  /* 导航链接变成下拉面板 */
  .topnav-links {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    margin: 0;
    padding: 8px 24px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    font-size: var(--fs-base);
    background: #fff;
    border-bottom: 1px solid var(--line);
    box-shadow: 0 12px 28px rgba(30, 41, 80, .10);
    /* 收起状态 */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity .22s ease, transform .22s ease, visibility .22s;
  }
  html[data-theme="dark"] .topnav-links {
    background: #0f1520;
    box-shadow: 0 12px 28px rgba(0, 0, 0, .5);
  }
  .topnav-links.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
  }
  .topnav-links a {
    padding: 12px 2px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
  }
  .topnav-links a:last-child { border-bottom: none; }
  .topnav-links a::after { display: none; }

  /* 导航容器需要定位上下文 */
  .topnav { position: fixed; }
  .topnav-inner { position: relative; }

  /* 右侧按钮紧凑一些 */
  .topnav-actions { margin-left: auto; gap: 6px; }
  .topnav-actions .btn-sm { padding: 0 12px; }
  /* 移动端隐藏「注册」按钮，避免过于拥挤（登录页里有注册入口） */
  .topnav-actions .btn-primary { display: none; }
}

@media (max-width: 420px) {
  .topnav-actions .btn-ghost { display: none; }
}

/* ──────────────────────────────────────────────────────────
   2. 表格：允许横向滚动
   ────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  /* 所有直接放在页面里的表格，包一层滚动 */
  .pretty,
  .vip-compare-table,
  table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
  }
  table th, table td {
    padding: 10px 12px;
    font-size: var(--fs-xs);
  }
  /* 表格外层容器也要允许滚动 */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ──────────────────────────────────────────────────────────
   3. 网格：多列变单列
   ────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .hero-layout,
  .feature-grid,
  .steps,
  .quick-grid,
  .footer-grid,
  .vip-compare,
  .pkg-grid,
  .mu-grid {
    grid-template-columns: 1fr !important;
    gap: 16px;
  }

  /* 首页 hero 右卡片 */
  .hero-card, .hero-start { width: 100%; }
}

@media (max-width: 640px) {
  /* 两列变一列 */
  .stat-grid,
  .metric-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ──────────────────────────────────────────────────────────
   4. 字号与间距
   ────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  :root {
    --fs-5xl: 32px;
    --fs-4xl: 26px;
    --fs-3xl: 22px;
    --sec-pad: 52px;
    --hero-pad-b: 56px;
  }
  h1 { font-size: var(--fs-3xl); line-height: 1.3; }
  h2 { font-size: var(--fs-2xl); }
  body { font-size: var(--fs-sm); }

  .section { padding: var(--sec-pad) 0; }
  .section-head { margin-bottom: 26px; }
  .wrap { padding: 0 18px; }
}

@media (max-width: 420px) {
  :root {
    --fs-5xl: 28px;
    --fs-4xl: 23px;
    --fs-3xl: 20px;
  }
  .wrap { padding: 0 14px; }
}

/* ──────────────────────────────────────────────────────────
   5. 防止横向溢出
   ────────────────────────────────────────────────────────── */
html, body {
  max-width: 100%;
  overflow-x: hidden;
}

/* 长 URL、代码块不撑破容器 */
pre, code, .mono {
  overflow-wrap: anywhere;
  word-break: break-word;
}
pre {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* 卡片内的一切不超出 */
.card, .hero-card, .svc, .metric, .pkg-card {
  max-width: 100%;
  box-sizing: border-box;
}

/* 链接、按钮在窄屏换行 */
.btn { max-width: 100%; }

/* ──────────────────────────────────────────────────────────
   6. 首页首屏（hero）特殊处理
   ────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .hero { padding-top: 96px !important; }
  .hero-title { font-size: var(--fs-4xl) !important; }
  .hero-sub { font-size: var(--fs-sm) !important; }
  .hero-cta { flex-wrap: wrap; gap: 10px; }
  .hero-cta .btn { flex: 1 1 auto; min-width: 130px; }
  /* 价格标签卡片 */
  .price-tag, .hero-badge { width: 100%; }
}

/* ──────────────────────────────────────────────────────────
   7. 文档页双栏 → 单栏
   ────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .docs-layout {
    grid-template-columns: 1fr !important;
    gap: 24px;
  }
  /* 侧边目录变成可折叠块，不再占满整屏 */
  .docs-toc, .toc {
    position: static !important;
    max-height: 240px;
    overflow-y: auto;
    border: 1px solid var(--line);
    border-radius: var(--r-sm);
    padding: 14px 16px;
    background: var(--soft);
  }
}
html[data-theme="dark"] .docs-toc,
html[data-theme="dark"] .toc { background: #141b28; }

/* ──────────────────────────────────────────────────────────
   8. 价格页筛选条换行
   ────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  .filter-bar, .chips, .seg {
    flex-wrap: wrap !important;
    gap: 8px;
  }
  .chips > *, .seg > * { flex: 0 0 auto; }
}

/* ──────────────────────────────────────────────────────────
   9. 触控友好：加大点击区域
   ────────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .btn-sm { height: 38px; padding: 0 16px; }
  .theme-btn { width: 38px; height: 38px; }
  a, button { -webkit-tap-highlight-color: transparent; }
}

/* ══════════════════════════════════════════════════════════
   v2 修复：彻底消除横向溢出
   ══════════════════════════════════════════════════════════ */

/* 1. 全局兜底 —— 任何情况下都不允许横向滚动 */
html {
  overflow-x: hidden !important;
}
body {
  overflow-x: hidden !important;
  max-width: 100vw !important;
}

/* 2. 表格：改为「块级 + 容器内滚动」
      关键是不让 min-width 影响页面宽度 */
@media (max-width: 860px) {
  table,
  table.pretty,
  .vip-compare-table,
  .ud-tbl {
    display: block !important;
    width: 100% !important;
    min-width: 0 !important;
    max-width: 100% !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    font-size: var(--fs-2xs, 11.5px) !important;
  }
  table thead, table tbody,
  table.pretty thead, table.pretty tbody {
    display: table;
    width: 100%;
    min-width: 420px;
  }
  table th, table td,
  table.pretty th, table.pretty td {
    padding: 9px 10px !important;
    font-size: 11.5px !important;
    white-space: nowrap;
  }
  /* 长内容允许换行 */
  table td.wrap, table.pretty td.wrap {
    white-space: normal;
    word-break: break-word;
  }
}

/* 3. 所有可能溢出的容器 */
@media (max-width: 860px) {
  .wrap, .hero, .hero-inner, .section > .wrap,
  .card, .hero-card, .pkg-card, .svc, .metric, .ud-stat {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* 绝对定位装饰元素不参与宽度计算 */
  .hero-glow, .hero-glow::before, .hero-glow::after {
    max-width: 100vw !important;
    overflow: hidden !important;
  }

  /* 代码块内滚动 */
  pre, .codeblock pre {
    max-width: 100% !important;
    overflow-x: auto !important;
    white-space: pre !important;
    word-break: normal !important;
  }

  /* 长 URL / 模型名 强制断行 */
  code, .mono, .model-name {
    word-break: break-word !important;
    overflow-wrap: anywhere !important;
  }
}

/* 4. 网格统一单列 */
@media (max-width: 860px) {
  .hero-layout,
  .feature-grid,
  .quick-grid,
  .footer-grid,
  .steps,
  .vip-compare,
  .pkg-grid,
  .mu-grid,
  .docs-layout,
  .stat-grid,
  .metric-grid,
  .ch-summary,
  .cs-grid,
  .ud-stats {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 14px !important;
  }
}

/* 5. hero 区域文字 */
@media (max-width: 860px) {
  .hero-sub {
    max-width: 100% !important;
    font-size: var(--fs-sm) !important;
    line-height: 1.75 !important;
  }
  .hero-title, .hero h1 {
    max-width: 100% !important;
    word-break: break-word;
  }
  .hero-note {
    flex-wrap: wrap !important;
    gap: 6px 10px !important;
  }
  .price-highlight {
    flex-wrap: wrap !important;
    gap: 10px !important;
  }
}

/* ══════════════════════════════════════════════════════════
   v3：flex 子项收缩问题（经典 min-width: auto 陷阱）
   ══════════════════════════════════════════════════════════ */

@media (max-width: 860px) {
  /* 所有 flex 容器内的子项必须允许收缩 */
  .hero-layout > *,
  .hero-inner > *,
  .hero-actions > *,
  .hero-note > *,
  .price-highlight > *,
  .topnav-inner > *,
  .feature-grid > *,
  .quick-grid > *,
  .footer-grid > *,
  .card-head > *,
  .svc > *,
  .metric > *,
  .pkg-card > *,
  .cs-row > *,
  .ud-row > *,
  .dim-item > *,
  .nt-item > *,
  .rd-form > *,
  .lg-filters > * {
    min-width: 0 !important;
    max-width: 100% !important;
  }

  /* 可以让文字换行的 flex 容器 */
  .hero-note,
  .price-highlight,
  .hero-actions,
  .card-head,
  .rd-form,
  .lg-filters {
    flex-wrap: wrap !important;
  }

  /* 价格高亮条：改为纵向堆叠 */
  .price-highlight {
    display: flex !important;
    flex-direction: column !important;
    align-items: flex-start !important;
    gap: 8px !important;
    padding: 14px 16px !important;
  }
  .price-highlight > div,
  .price-highlight > span,
  .price-highlight p {
    max-width: 100% !important;
    white-space: normal !important;
    word-break: break-word !important;
    line-height: 1.7 !important;
    font-size: var(--fs-xs) !important;
  }

  /* hero-sub 不要用 em 限宽 */
  .hero-sub {
    max-width: 100% !important;
    white-space: normal !important;
    word-break: break-word !important;
  }

  /* 所有段落类文字强制换行 */
  p, li, .hero-sub, .section-head p, .vip-lead, .vip-note, .foot-note {
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
    max-width: 100% !important;
  }

  /* 标题不溢出 */
  h1, h2, h3, h4 {
    max-width: 100% !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
  }

  /* 首页 hero 卡片（从这里开始）宽度约束 */
  .hero-card,
  .hero-start,
  .start-card {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* 卡片内输入框/下拉不溢出 */
  input, select, textarea {
    max-width: 100% !important;
    box-sizing: border-box !important;
  }

  /* 代码块内的行内 code 不撑宽 */
  code {
    white-space: normal !important;
    word-break: break-all !important;
  }
  /* 但代码块内的 code 保持原样，靠容器滚动 */
  pre code {
    white-space: pre !important;
    word-break: normal !important;
  }
}
