/* ==========================================================================
   孕程记 · 响应式增强层（移动端 / 平板适配）
   --------------------------------------------------------------------------
   本文件在 index.html 中于所有组件样式之后引入，作为「覆盖层」补齐已构建
   前端在移动端 / 平板上缺失的体验。设计 token 沿用 index-B5gxZLmV.css 中
   定义的 CSS 变量（--primary-color / --radius-* / --safe-bottom 等），不
   改变桌面端视觉与暗色模式（html.dark）。
   断点约定：
     ≤1024px  平板
     ≤768px   移动（与前端 isMobile 判定一致，底部 TabBar 切换）
     ≤480px   小屏手机
     ≤374px   超小屏手机
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. 全局溢出与可读性保护
   -------------------------------------------------------------------------- */
html, body {
  overflow-x: hidden; /* 兜底：老浏览器 */
}
@supports (overflow-x: clip) {
  html, body {
    overflow-x: clip; /* 不产生滚动容器，不破坏 position:sticky */
  }
}
#app,
.main-layout,
.content-inner,
.page-container {
  max-width: 100%;
}
.main-content {
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}

/* 媒体与表格不撑破容器 */
img,
video,
canvas,
svg,
iframe {
  max-width: 100%;
}
img,
video {
  height: auto;
}

/* 长文本 / 连续数字 / URL 防横向溢出 */
.diary-html,
.diary-text,
.detail-text,
.mood-note,
.checkup-desc,
.cell-advice,
.note-content,
.push-log-content,
.log-box,
.backup-result,
.db-path,
.rcp-desc,
.stage-desc {
  overflow-wrap: break-word;
  word-break: break-word;
}

/* --------------------------------------------------------------------------
   2. 触控交互基础优化（全设备，桌面端无副作用）
   -------------------------------------------------------------------------- */
a,
button,
.n-button,
[role="button"],
.tabbar-item,
.nav-item {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; /* 消除双击缩放 / 300ms 延迟 */
}
.sidebar,
.tabbar,
.nav-item,
.tabbar-item,
.category-row,
.card-header,
.sub-items-toggle,
.preparation-toggle,
.day-cell {
  -webkit-user-select: none;
  user-select: none;
}

/* --------------------------------------------------------------------------
   3. 平板断点（≤1024px）
   -------------------------------------------------------------------------- */
@media (max-width: 1024px) {
  .page-container {
    padding: 20px;
  }
  /* 宽表格容器确保内部横向滚动可用，且不撑破平板布局 */
  .table-body,
  .glucose-table {
    max-width: 100%;
  }
}

/* --------------------------------------------------------------------------
   4. 移动断点（≤768px）
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  /* 4.1 布局与内容 */
  .page-container {
    padding: 12px !important;
    max-width: 100%;
  }
  .settings-view {
    padding: 12px !important;
  }
  /* 内容顶部预留安全区（刘海屏），非刘海屏 env 为 0 无副作用 */
  .main-content {
    padding-top: var(--safe-top, 0px) !important;
  }

  /* 4.2 底部导航 TabBar：8 个入口保持可点，收紧间距避免挤压 */
  .tabbar {
    padding-left: 2px !important;
    padding-right: 2px !important;
  }
  .tabbar-item {
    gap: 2px !important;
    padding: 5px 2px !important;
    min-width: 0;
  }
  .tabbar-icon {
    font-size: 19px !important;
  }
  .tabbar-label {
    font-size: 10px !important;
    letter-spacing: 0 !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

  /* 4.3 触控目标：主要可点元素提升到 ≥44px 命中高度 */
  .nav-item,
  .album-tab,
  .category-tab,
  .cat-tab,
  .filter-btn,
  .period-tab,
  .sub-tab-btn,
  .mode-tab,
  .tag-chip,
  .symptom-chip,
  .supp-chip,
  .type-tag,
  .symptom-tag,
  .preset-item-tag,
  .mood-btn,
  .sleep-quality-btn,
  .intimacy-btn,
  .mood-pick-btn,
  .sub-items-toggle,
  .preparation-toggle,
  .db-root-btn,
  .db-nav-btn,
  .db-quick-btn,
  .nav-btn,
  .quick-add-btn,
  .card-action-btn,
  .upload-link {
    min-height: 44px;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  /* 日历格子：增大命中高度并对齐数字（密集网格取 36px 平衡触控与版面） */
  .day-cell {
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
  }
  .day-number {
    line-height: 1;
  }

  /* 4.4 表单与输入：iOS 防自动缩放（16px）+ 触控高度 */
  input,
  select,
  textarea,
  .n-input__input-el,
  .n-input__textarea-el,
  .n-base-selection {
    font-size: 16px !important;
  }
  .n-input,
  .n-input-number,
  .n-select,
  .n-date-picker {
    min-height: 44px;
  }
  .date-input,
  .diary-date-input,
  .album-date-input,
  .custom-date-input,
  .native-date-input,
  .search-input,
  .add-input,
  .add-cat-select {
    min-height: 44px;
    box-sizing: border-box;
  }
  /* 表单多字段行在窄屏纵向排列 */
  .form-row,
  .qf-row {
    flex-direction: column;
    gap: 8px;
  }

  /* 4.5 Naive UI 弹窗 / 抽屉 / 气泡：小屏收敛为全宽，避免横向溢出 */
  .n-dialog {
    width: calc(100vw - 28px) !important;
    max-width: calc(100vw - 28px) !important;
    margin: 0 14px !important;
  }
  .n-drawer {
    max-width: 88vw !important;
  }
  .n-popover,
  .n-date-panel {
    max-width: calc(100vw - 16px) !important;
  }
  .n-modal-container {
    padding: 8px !important;
  }
  .n-button {
    min-height: 44px;
  }

  /* 4.6 记录页：全屏日历避让底部 TabBar（原 height:100dvh 会被遮挡） */
  .record-view {
    height: calc(100dvh - var(--tabbar-height, 60px) - var(--safe-bottom, 0px)) !important;
  }

  /* 4.7 设置页 & 目录浏览器：行布局防溢出 */
  .setting-item {
    flex-wrap: wrap;
    gap: 8px;
  }
  .setting-item label {
    min-width: 64px;
  }
  .setting-hint {
    padding-left: 0;
    margin-top: 0;
  }
  .push-log-content {
    max-width: 130px;
  }
  .db-bar {
    flex-wrap: wrap;
    gap: 8px;
  }
  .backup-card {
    padding: 12px 14px;
  }

  /* 4.8 运动指导 & 胎动计数：补足头部与计数区的移动端收敛 */
  .exercise-guide {
    padding: 0 0 16px;
  }
  .eg-header {
    padding: 16px 14px;
    gap: 12px;
  }
  .eg-icon {
    font-size: 30px;
  }
  .eg-title h2 {
    font-size: 18px;
  }
  .eg-current-stage {
    padding: 14px 16px;
  }
  .fetal-counter {
    padding: 16px 12px;
  }
  .count-display {
    font-size: 76px !important;
  }
  .kick-button {
    width: 140px !important;
    height: 140px !important;
    font-size: 18px !important;
  }
}

/* --------------------------------------------------------------------------
   5. 小屏手机断点（≤480px）
   -------------------------------------------------------------------------- */
@media (max-width: 480px) {
  /* 数字与标题进一步收敛 */
  .countdown-num {
    font-size: 44px !important;
  }
  .countdown-unit {
    font-size: 16px !important;
  }
  .countdown-meta {
    gap: 6px !important;
  }
  /* TabBar 图标与标签微调，保证 8 项在 375px 下不拥挤 */
  .tabbar-icon {
    font-size: 18px !important;
  }
  .tabbar-label {
    font-size: 9.5px !important;
  }
  /* 饮食 / 运动等双列网格收敛为单列，减少折行压力 */
  .nutrient-grid {
    grid-template-columns: 1fr 1fr !important;
  }
  .step-grid,
  .phase-grid,
  .forbid-grid {
    grid-template-columns: 1fr !important;
  }
  /* 设置页目录快捷按钮占满整行，方便点按 */
  .db-quick-list {
    flex-direction: column;
  }
  .db-quick-btn {
    justify-content: flex-start;
    width: 100%;
  }
}

/* --------------------------------------------------------------------------
   6. 超小屏手机断点（≤374px）
   -------------------------------------------------------------------------- */
@media (max-width: 374px) {
  .tabbar-label {
    font-size: 9px !important;
  }
  .tabbar-icon {
    font-size: 17px !important;
  }
  .countdown-num {
    font-size: 40px !important;
  }
  .page-container {
    padding: 10px !important;
  }
}

/* --------------------------------------------------------------------------
   7. 暗色模式兼容：覆盖层只使用变量，此处仅兜底关键阴影/边框
   -------------------------------------------------------------------------- */
html.dark .tabbar {
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.35);
}
