/* ============================================================
 * mobile.css — 移动端 · 桌面端通用适配 v2.1.0
 * 色彩能量精油 · 一百零八瓶疗愈系统
 * ------------------------------------------------------------
 * 设计原则：
 *  · 桌面端体验不变；≤860px 逐步收拢；≤640px 启用底部 Tab 导航
 *  · 触控优先：点击目标 ≥44px，hover 降级为直接可点
 *  · 刘海屏 / 安全区适配（env(safe-area-inset-*)）
 *  · 修复既有小屏问题：选瓶槽位溢出 / 年轮画布过高 / 图鉴单列
 * ============================================================ */

/* ---------- 通用：触控目标与滚动条 ---------- */
@media (hover: none) {
  .btn, .nav-link, .chip, .icon-btn, .filter-bar select,
  .fp-tab, .gs-item, .oil-card {
    cursor: default;
  }
  /* 触屏：取消 hover 依赖的浮起效果，改为按下反馈 */
  .btn:active, .nav-link:active, .chip:active, .icon-btn:active { opacity: .75; }
  .oil-card:active { transform: scale(.97); transition: transform .12s; }
}
button, .btn, .nav-link, .chip, .icon-btn, select, input[type="text"] {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- ≤860px：平板 / 窄桌面 ---------- */
@media (max-width: 860px) {
  .oil-detail { grid-template-columns: 1fr; gap: 18px; }
  .oil-detail > *:first-child { max-width: 260px; margin: 0 auto; }
  .theory-layout { grid-template-columns: 1fr; }
  .theory-nav { position: static; display: flex; overflow-x: auto; gap: 6px; padding-bottom: 8px; }
  .therapy-grid { grid-template-columns: 1fr; }
  .home-catalog { grid-template-columns: repeat(2, 1fr); }

  /* 图鉴筛选栏：横向滚动，避免换行堆叠过高 */
  .filter-bar {
    display: flex;
    overflow-x: auto;
    gap: 8px;
    padding-bottom: 6px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .filter-bar::-webkit-scrollbar { display: none; }
  .filter-bar > * { flex: none; }

  /* 顶部导航：仅显示图标级精简 */
  .nav-inner { padding: 0 12px; }
  .nav-links { gap: 2px; }
  .nav-link { padding: 6px 9px; font-size: 13px; }
}

/* ---------- 底部 Tab 导航：默认隐藏，≤640px 启用 ---------- */
#tab-bar { display: none; }

/* ---------- ≤640px：手机 ---------- */
@media (max-width: 640px) {
  :root { --nav-h: 54px; }

  body {
    /* 底部 Tab 占位：内容不被遮挡 */
    padding-bottom: calc(62px + env(safe-area-inset-bottom, 0px));
  }
  body.landing-on { padding-bottom: 0; }
  /* 登录页为沉浸式体验，隐藏底部导航 */
  body.landing-on #tab-bar { display: none; }

  .container { padding: 0 14px; }

  /* 顶部导航：品牌 + 主题/搜索按钮，链接隐藏（交给底部 Tab） */
  .nav { position: sticky; }
  .nav-links { display: none !important; }
  .brand span:last-child { font-size: 14px; }
  .icon-btn {
    width: 42px;
    height: 42px;
    font-size: 18px;
  }

  /* 底部 Tab 导航（结构由 mobile.js 注入） */
  #tab-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1500;
    display: flex;
    background: color-mix(in srgb, var(--card) 92%, transparent);
    -webkit-backdrop-filter: blur(14px);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--line2);
    padding-bottom: env(safe-area-inset-bottom, 0px);
    box-shadow: 0 -4px 24px rgba(0, 0, 0, .07);
  }
  #tab-bar .tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 7px 0 6px;
    min-height: 55px;
    border: none;
    background: transparent;
    color: var(--sub);
    font-size: 10.5px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  #tab-bar .tab .t-ico { font-size: 20px; line-height: 1; transition: transform .18s; }
  #tab-bar .tab.on { color: var(--teal); font-weight: 600; }
  #tab-bar .tab.on .t-ico { transform: translateY(-1px) scale(1.12); }
  #tab-bar .tab.accent .t-ico { color: var(--accent); }
  #tab-bar .tab:active .t-ico { transform: scale(.88); }

  /* 选瓶槽位：三槽等分一行，修复 200px 内联宽度溢出 */
  .sel-slots { flex-wrap: nowrap; gap: 8px !important; }
  .sel-slot {
    width: 30% !important;
    min-width: 0;
    height: auto !important;
    aspect-ratio: 10 / 9;
  }
  .sel-slot img { max-width: 62%; height: auto; }
  .sel-slot .rm {
    width: 34px;
    height: 34px;
    font-size: 20px;
    top: 2px;
    right: 2px;
  }
  .sel-slot div div:first-child { font-size: 26px !important; margin-top: 14% !important; }
  .sel-slot div div:last-child { font-size: 12px !important; margin-top: 10% !important; }

  /* 流程步骤条收窄 */
  .wizard-steps { transform: scale(.92); transform-origin: top center; margin-bottom: 4px; }

  /* 图鉴：小卡两列；卡片信息不溢出 */
  .oil-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px !important; }
  .oil-card { padding: 10px 8px !important; }
  .oil-card img { max-height: 110px; }

  /* 能量图谱：年轮画布 520px → 视口自适应（覆盖内联高度） */
  #wheel-canvas, #wheel-canvas2 {
    height: min(92vw, 460px) !important;
  }
  #radar-canvas { max-width: 84vw; }
  .chart-wrap { margin: 0 auto; }

  /* 确认页 / 报告页 */
  .confirm-grid { grid-template-columns: 1fr; }
  .stats-bar { grid-template-columns: repeat(2, 1fr) !important; }

  /* 预约页 */
  .book-grid, .booking-grid { grid-template-columns: 1fr !important; }

  /* 五行能量环画布：撑满屏宽 */
  #culture-canvas { width: 100% !important; height: auto !important; }

  /* 演算之幕 SVG 三瓶连线：等比缩放不截断 */
  .trans-stage svg { width: 100%; height: auto; }

  /* 剧场 / 登录页：粒子容器全屏 */
  .hero { grid-template-columns: 1fr; }

  /* 页脚：纵向堆叠 + 居中 */
  footer .container { flex-direction: column; text-align: center; gap: 8px; }
  footer .container > div:last-child { text-align: center !important; }

  /* 返回顶部按钮：避开底部 Tab */
  #back-top { bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }

  /* 报告打印按钮等长条按钮换行 */
  .btn.lg { width: 100%; max-width: 360px; }

  /* 表格横向滚动兜底 */
  .record-table, table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Toast 位置避开 Tab */
  .toast { bottom: calc(76px + env(safe-area-inset-bottom, 0px)) !important; }
}

/* ---------- ≤380px：小屏手机 ---------- */
@media (max-width: 380px) {
  .oil-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px !important; }
  .home-catalog { grid-template-columns: 1fr; }
  .brand span:last-child { display: none; }
}

/* ---------- 桌面端悬停精修（≥861px 且支持 hover） ---------- */
@media (hover: hover) and (min-width: 861px) {
  .oil-card { transition: transform .22s, box-shadow .22s; }
  .oil-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
}

/* ---------- 横屏手机（可选优化） ---------- */
@media (max-height: 480px) and (orientation: landscape) {
  #tab-bar { display: none; }
  body { padding-bottom: 0; }
}

/* ============================================================
   v3.0 ≤480px 专项优化
   56px Tab / 单列 Hero / 底部抽屉 / 全屏筛选 / 触摸 HIG
   ============================================================ */
.flt-entry { display: none; }
.swipe-hint { display: none; }

@media (max-width: 480px) {

  /* —— 导航：顶部仅 Logo+搜索+主题；底部 Tab 56px + 刘海安全区 —— */
  :root { --nav-h: 52px; }
  body { padding-bottom: calc(66px + env(safe-area-inset-bottom, 0px)); }
  .nav-inner { padding: 0 12px; gap: 10px; }
  #tab-bar .tab { min-height: 56px; padding: 6px 0 5px; }
  #tab-bar .tab .t-label { font-size: 10px; letter-spacing: .5px; }
  #tab-bar .tab .t-ico { font-size: 21px; }
  #tab-bar .tab.on { color: var(--accent); }

  /* —— 触摸反馈（HIG）：active 加深 + 缩放；目标 ≥44×44 —— */
  .btn, .icon-btn, .chip, .tab, .ms-item, .flt-close, .wxd { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
  .btn { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .chip { min-height: 40px; padding: 8px 14px; }
  .btn:active, .chip:active, .icon-btn:active, .ms-item:active { transform: scale(.97); filter: brightness(.9); }
  .oil-card:active, .catalog-card:active, .ht-card:active, .lnk-card:active { transform: scale(.97); }
  #tab-bar .tab:active { transform: scale(.94); }
  .rm { width: 40px !important; height: 40px !important; }

  /* —— 滚动列表：iOS 惯性滚动 —— */
  body, .h-scroll, .filter-bar, .ms-box, .focus-card, .oil-grid,
  .home-catalog, .view, .search-results { -webkit-overflow-scrolling: touch; }

  /* —— Hero / 节气 Banner：单列全屏、层次保留 —— */
  .hero { grid-template-columns: 1fr; padding: 44px 20px 36px; gap: 20px; }
  .hero h1 { font-size: clamp(26px, 7.2vw, 34px); }
  .hero .lead { font-size: 14px; line-height: 1.9; }
  .hero-bottles { display: none; }
  .term-banner { min-height: min(74vh, 620px); padding: 26px 18px 24px; }
  .tb-name { font-size: clamp(52px, 16vw, 72px); }
  .tb-sub { font-size: 12.5px; }
  .tb-phrase { font-size: 13.5px; line-height: 1.95; padding: 12px 14px; }
  .cd-num { font-size: 24px; }

  /* —— 精油网格：最小 2 列，高度自适应 —— */
  .oil-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 10px; }
  .oil-card img { max-height: 96px; }

  /* —— 图表：宽度 100%，高度按屏宽比例缩放（ResizeObserver 自动重绘） —— */
  .chart-wrap canvas { max-width: 100%; }
  #ch-radar, #ch-balance { height: 88vw !important; max-height: 380px; }
  #ch-water { height: 44vw !important; min-height: 150px; }
  #ch-emo { height: 52vw !important; min-height: 190px; }
  #ch-heat { height: 150px !important; }
  #ch-body { height: 106vw !important; max-height: 460px; }
  #ch-ring { height: min(94vw, 440px) !important; }

  /* —— 精油详情弹层 → 底部抽屉（iOS Sheet，translateY 动画） —— */
  .overlay { align-items: flex-end !important; justify-content: center; padding: 0 !important; }
  .focus-card {
    position: relative;
    width: 100% !important; max-width: 100% !important;
    max-height: 90vh; overflow-y: auto;
    border-radius: 20px 20px 0 0 !important;
    transform: translateY(100%);
    animation: sheet-up .34s cubic-bezier(.32, .72, .28, 1) forwards;
    overscroll-behavior: contain;
  }
  .focus-card::before {
    content: '';
    position: absolute; top: 8px; left: 50%; transform: translateX(-50%);
    width: 42px; height: 4.5px; border-radius: 3px;
    background: var(--line); z-index: 5;
  }
  @keyframes sheet-up { to { transform: translateY(0); } }
  .focus-close { top: 14px; right: 14px; width: 44px; height: 44px; }

  /* —— 筛选面板 → 全屏覆盖抽屉 —— */
  .flt-entry {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 12px;
  }
  .flt-entry .btn { min-height: 44px; }
  .filter-bar.flt-drawer {
    position: fixed; inset: 0; z-index: 1700;
    height: 100vh; height: 100dvh; max-height: 100vh; max-height: 100dvh;
    background: var(--bg); margin: 0; border: none; border-radius: 0;
    padding: calc(14px + env(safe-area-inset-top, 0px)) 16px calc(28px + env(safe-area-inset-bottom, 0px));
    overflow-y: auto; overscroll-behavior: contain;
    transform: translateY(100%);
    transition: transform .32s cubic-bezier(.32, .72, .28, 1);
  }
  body.flt-open .filter-bar.flt-drawer { transform: translateY(0); }
  body.flt-open { overflow: hidden; }
  .flt-head {
    position: sticky; top: 0; z-index: 3;
    display: flex; align-items: center; justify-content: space-between;
    padding: 4px 0 12px; margin-bottom: 6px;
    background: var(--bg);
    border-bottom: 1px solid var(--line2);
  }
  .flt-title { font-family: var(--serif); font-size: 17px; font-weight: 700; }
  .flt-close {
    min-height: 44px; padding: 8px 20px;
    border: none; border-radius: 999px;
    background: var(--accent); color: #fff;
    font-size: 14px; font-weight: 600; cursor: pointer;
  }
  .flt-close:active { transform: scale(.96); }

  /* —— 五行分组指示点（横滑切换的位置指示） —— */
  .wx-dots { display: flex; gap: 8px; justify-content: center; margin: 2px 0 14px; }
  .wxd {
    min-width: 44px; min-height: 44px;
    display: inline-flex; align-items: center; justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--line); background: var(--card);
    color: var(--sub); font-size: 14px; font-weight: 600; cursor: pointer;
    transition: all .2s ease;
  }
  .wxd.on {
    background: var(--accent); border-color: var(--accent); color: #fff;
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(176, 58, 46, .3);
  }
  .swipe-hint {
    display: block; text-align: center;
    font-size: 11.5px; color: var(--sub); opacity: .75;
    margin: 4px 0 12px; letter-spacing: 1px;
  }
  .home-v3.m-compact .swipe-hint { display: none; }

  /* —— 长按拖拽排序视觉态 —— */
  .sel-slot { touch-action: pan-y; }
  .sel-slot.drag-src { opacity: .35; }
  .sel-slot.drop-hint { outline: 2px dashed var(--accent); outline-offset: 3px; border-radius: 14px; }
  body.reordering { user-select: none; -webkit-user-select: none; overflow: hidden; }
  body.reordering .sel-slot img { pointer-events: none; }
}

/* —— 更小屏（≤360px）兜底 —— */
@media (max-width: 360px) {
  .oil-grid { grid-template-columns: repeat(2, 1fr) !important; gap: 8px; }
  .flt-entry .result-count { display: none; }
}
