/* ==========================================================
   WorkBuddy / QClaw QA · 移动端深度适配补丁
   覆盖：≤960 / ≤768 / ≤640 / ≤480 / ≤360 / 横屏 / iOS 安全区
   引入顺序必须在 styles.css 之后，以便覆盖。
   ========================================================== */

/* ---------- 基础：iOS 友好 ---------- */
html { -webkit-text-size-adjust: 100%; }
body {
  /* 防止 iOS 横屏时字体被自动放大 */
  text-size-adjust: 100%;
  /* 让滚动更顺滑 */
  -webkit-overflow-scrolling: touch;
}

/* 移动端禁用 details summary 的高亮闪烁 */
summary,
button,
a,
.qa-q,
.cat-card,
.compare-card {
  -webkit-tap-highlight-color: rgba(21, 101, 192, 0.08);
}

/* 防止 iOS 自动把数字识别成电话链接 */
.qa-a, .step-body, .footer { -webkit-touch-callout: none; }

/* ---------- iPhone 刘海 / 底部安全区 ---------- */
.nav-inner,
.container,
.footer .container {
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}
.footer { padding-bottom: max(24px, env(safe-area-inset-bottom)); }

/* ---------- 表格统一可横向滚动（解决最严重溢出） ---------- */
.tbl {
  display: block;
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  white-space: nowrap;
}
.tbl thead, .tbl tbody, .tbl tr { display: table; width: 100%; table-layout: fixed; }
.tbl td, .tbl th { white-space: normal; word-break: break-word; }
@media (min-width: 720px) {
  /* 桌面端恢复正常表格行为 */
  .tbl { display: table; overflow: visible; white-space: normal; }
  .tbl thead, .tbl tbody, .tbl tr { display: table-row-group; }
  .tbl thead { display: table-header-group; }
  .tbl tr { display: table-row; }
}

/* ============================================================
   断点 1：≤ 960px（小平板 / 大手机横屏）
   ============================================================ */
@media (max-width: 960px) {
  .section { padding: 48px 0; }
  .hero { padding: 48px 0 56px !important; }
  .hero p.lead { font-size: 16px; }
}

/* ============================================================
   断点 2：≤ 768px（标准手机竖屏）
   ============================================================ */
@media (max-width: 768px) {
  /* 全局留白收紧 */
  .container { padding-left: 16px; padding-right: 16px; }
  .section { padding: 40px 0; }

  /* Hero 区域 */
  .hero { padding: 40px 0 44px !important; }
  .hero h1 { font-size: clamp(26px, 7vw, 34px); }
  .hero p.lead { font-size: 15.5px; line-height: 1.7; }
  .hero-eyebrow { font-size: 11px; padding: 5px 12px; }
  .hero-actions { gap: 10px; }
  .hero-actions .btn {
    flex: 1 1 auto;
    min-width: 140px;
    justify-content: center;
    padding: 12px 18px;
    font-size: 14.5px;
  }

  /* 区块标题 */
  .section-title { margin-bottom: 28px; }
  .section-title h2 { font-size: clamp(22px, 5.5vw, 28px); }
  .section-title p { font-size: 14px; }

  /* QA 章节 head 防换行错乱 */
  .qa-section-head { gap: 10px; flex-wrap: wrap; }
  .qa-section-head h3 { font-size: 18px; flex: 1 1 auto; min-width: 0; }
  .qa-section-head .num { width: 30px; height: 30px; font-size: 14px; border-radius: 8px; }
  .qa-section-head .count { font-size: 11px; flex-shrink: 0; }

  /* 对比表 */
  .compare { gap: 16px; }
  .compare-card { padding: 22px 18px 20px; border-radius: 18px; }
  .cc-name { font-size: 19px; }

  /* 分类卡 */
  .cat-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .cat-card { padding: 16px 14px 14px; border-radius: 14px; }
  .cat-icon { width: 38px; height: 38px; font-size: 18px; }
  .cat-title { font-size: 15px; }
  .cat-desc { font-size: 12.5px; }

  /* 步骤卡 */
  .step { padding: 14px 16px; gap: 12px; }
  .step-n { width: 28px; height: 28px; font-size: 13px; }
  .step-body h4 { font-size: 15px; }
  .step-body p { font-size: 13.5px; }

  /* 信息盒（box.warn / box.success） */
  .box { padding: 12px 14px; font-size: 13.5px; }

  /* 触摸热区放大 */
  .nav-toggle { width: 40px; height: 40px; font-size: 20px; }
  .qa-q { min-height: 56px; }
  .qa-q .chev { font-size: 16px; padding: 4px; }

  /* TOC 在移动端折叠成横向滚动 */
  .toc {
    position: static;
    margin: 0 0 20px;
    padding: 12px 14px;
  }
  .toc ul {
    display: flex;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    gap: 6px;
    padding-bottom: 4px;
    scrollbar-width: thin;
  }
  .toc li { margin-bottom: 0; flex-shrink: 0; }
  .toc a {
    white-space: nowrap;
    padding: 6px 12px;
    border-left: none !important;
    border: 1px solid var(--border-soft);
    border-radius: 999px;
    font-size: 12.5px;
  }
  .toc a.active, .toc a:hover {
    background: var(--primary-soft);
    border-color: var(--primary);
  }

  /* Footer */
  .footer { padding-top: 36px; margin-top: 56px; }
  .footer-grid { gap: 24px; margin-bottom: 24px; }
  .footer h4 { font-size: 13px; margin-bottom: 10px; }
  .footer-bottom { font-size: 11.5px; flex-direction: column; align-items: flex-start; gap: 4px; }

  /* 滚动条变细 */
  ::-webkit-scrollbar { width: 4px; height: 4px; }
}

/* ============================================================
   断点 3：≤ 640px（中小手机）
   ============================================================ */
@media (max-width: 640px) {
  /* 分类卡变单列更易读 */
  .cat-grid { grid-template-columns: 1fr; }

  /* QA 卡内排版 */
  .qa-q { padding: 14px 14px; font-size: 14.5px; gap: 10px; }
  .qa-q .marker { width: 24px; height: 24px; font-size: 11px; border-radius: 6px; }
  .qa-a {
    padding: 0 14px 16px 14px !important;
    font-size: 13.5px;
    line-height: 1.7;
  }
  .qa-a ul, .qa-a ol { padding-left: 20px; }
  .qa-a .source { font-size: 11px; }

  /* 表格字体缩小 */
  .tbl { font-size: 12.5px; }
  .tbl th, .tbl td { padding: 8px 10px; }
  .tbl th { font-size: 12px; }

  /* 搜索框 */
  .search-box { margin-bottom: 20px; }
  .search-box input { padding: 12px 16px 12px 40px; font-size: 14px; }

  /* 筛选 tabs 横向滚动 */
  .filter-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    padding: 4px 2px;
    margin-bottom: 20px;
    -webkit-overflow-scrolling: touch;
  }
  .filter-tabs button {
    flex-shrink: 0;
    padding: 7px 14px;
    font-size: 12.5px;
  }
}

/* ============================================================
   断点 4：≤ 480px（小屏手机：iPhone SE 等）
   ============================================================ */
@media (max-width: 480px) {
  .container { padding-left: 14px; padding-right: 14px; }
  .section { padding: 32px 0; }

  /* Hero 极致紧凑 */
  .hero { padding: 32px 0 36px !important; }
  .hero h1 { font-size: clamp(22px, 7vw, 28px); margin-bottom: 14px; }
  .hero p.lead { font-size: 14.5px; margin-bottom: 22px; }
  .hero-eyebrow { margin-bottom: 14px; }

  /* 按钮全宽更易点 */
  .hero-actions { flex-direction: column; }
  .hero-actions .btn { width: 100%; min-width: 0; }

  /* 导航 logo 文字截短 */
  .nav-logo { font-size: 14px; gap: 8px; }
  .nav-logo .badge { width: 24px; height: 24px; font-size: 12px; border-radius: 6px; }

  /* QA 章节标题再次精简 */
  .qa-section-head h3 { font-size: 16px; }
  .qa-section-head .count { display: none; }

  /* 对比卡 */
  .compare-card { padding: 20px 16px 18px; }
  .cc-icon { width: 40px; height: 40px; font-size: 18px; border-radius: 10px; }
  .cc-name { font-size: 17px; }
  .cc-team { font-size: 11px; }
  .cc-desc { font-size: 13.5px; }
  .cc-features li { font-size: 13px; }
  .cc-cta { flex-direction: column; }
  .cc-cta .btn { width: 100%; justify-content: center; }
}

/* ============================================================
   断点 5：≤ 360px（极窄屏：旧款 Android）
   ============================================================ */
@media (max-width: 360px) {
  .hero h1 { font-size: 21px; line-height: 1.18; }
  .hero p.lead { font-size: 14px; }
  .nav-logo span:not(.badge) { font-size: 12px; }
  .qa-q { padding: 12px 12px; font-size: 14px; }
  .qa-q .marker { display: none; }
  .qa-a { padding: 0 12px 14px 12px !important; font-size: 13px; }
  .qa-section-head { gap: 8px; }
  .qa-section-head .num { width: 26px; height: 26px; font-size: 12px; }
  .qa-section-head h3 { font-size: 15px; }
  .footer { padding-top: 28px; }
  .footer-grid { grid-template-columns: 1fr; gap: 18px; }
}

/* ============================================================
   横屏（Landscape）专项优化
   ============================================================ */
@media (max-height: 480px) and (orientation: landscape) {
  .hero { padding: 24px 0 28px !important; }
  .hero h1 { font-size: 24px; margin-bottom: 10px; }
  .hero p.lead { font-size: 14px; margin-bottom: 16px; }
  .nav { position: relative; }   /* 横屏不固定，避免遮挡 */
}

/* ============================================================
   减少动画偏好（无障碍）
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   暗色模式下的最低可读性兜底（不强制切换主题，仅修一些惨白）
   ============================================================ */
@media (prefers-color-scheme: dark) {
  /* 这里不主动切暗，避免改原设计，但确保表单元素可读 */
  .search-box input { color-scheme: light; }
}
