/* =============================================================
   responsive.css — 手机 / 平板适配层
   紫丁香环保油墨 · 一个文件管住所有「小屏 + 触摸」的事
   -------------------------------------------------------------
   为什么单独开一个文件（而不是改原来的 layout/components）：
     dist/_headers 给 /assets/* 配了 30 天强缓存，老访客手里的
     layout.css 会「粘」住旧版最多 30 天。新开一个文件从没被缓存
     过，配上 ?v= 就一定能立刻生效。

   加载顺序：必须排在 tokens/base/layout/components/pages/utilities
   之后（由 worker 与 prepare-dist.py 插在 </head> 前），
   这样同优先级的规则才能压住原样式。

   内容分八块：
     0. 基础（文字缩放 / 断词 / 防横向溢出）
     1. 触摸端修正（悬停态残留、点按高亮、点按目标）
     2. 安全区（刘海屏 / 底部手势条）
     3. 小屏布局微调
     4. 图片与媒体的稳健性
     5. 长页面与滚动容器
     6. 无障碍与降级（大字模式、横屏、减动效、打印）
     7. 编辑器窄视口兜底（工具条单行化、属性面板变底部抽屉）
   ============================================================= */

/* ================= 0. 基础 ================= */

/* iOS 横屏时不要偷偷放大字号 */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* 长串英文/邮箱/链接不要顶破容器 */
body {
  overflow-wrap: break-word;
}

/* 兜底防横向溢出。
   用 clip 而不是 hidden：clip 不会把 body 变成滚动容器，
   页面头部的 position: sticky 依然有效。 */
body {
  overflow-x: clip;
}

/* 触摸端更跟手：告诉浏览器纵向滚动优先，别为横向手势等 300ms */
.cf-scroll-x,
.filter-tabs {
  touch-action: pan-x pan-y;
}

/* ================= 1. 触摸端修正 ================= */

@media (hover: none), (pointer: coarse) {

  /* 1.1 悬停位移在触摸屏上会「粘住」——
       点过一张卡片，它会一直浮着直到你点别处，看着像坏了。
       触摸设备上把这些位移效果关掉。 */
  .btn:hover,
  .feature:hover,
  .card:hover,
  .brand-card:hover,
  .contact-card:hover,
  .cert-wall figure:hover {
    transform: none;
  }
  .card:hover .card-media img,
  .gallery-item:hover img {
    transform: none;
  }
  .text-link:hover svg { transform: none; }

  /* 1.2 点按反馈：去掉系统灰块，换成品牌色的一点点高亮 */
  a,
  button,
  [role="button"],
  label,
  summary,
  .filter-tab,
  .nav-toggle {
    -webkit-tap-highlight-color: rgba(30, 90, 214, .14);
  }

  /* 1.3 按下时给一点即时反馈（触摸端没有 hover，得有别的反馈） */
  .btn:active { transform: scale(.975); }
  .card:active,
  .feature:active,
  .brand-card:active,
  .contact-card:active { transform: scale(.99); }
  .filter-tab:active { border-color: var(--c-blue-300); }
  .footer-links a:active,
  .breadcrumb a:active { color: #fff; }
}

/* 1.4 点按目标补到「手指点得着」的尺寸。
     Apple HIG 建议 44px，Material 建议 48px。
     正文里的行内链接不能撑成 44px（会把版面撑散），
     所以只处理「独立成块」的那些。 */
@media (max-width: 980px) {

  /* 页脚链接：本来就一行一个，撑到 44px 最舒服 */
  .footer-links li { margin-bottom: 0; }
  .footer-links a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    font-size: 15px;
  }

  /* 页脚底部「联系我们 · 招商合作」那行 */
  .footer-bottom { font-size: var(--fs-sm); }
  .footer-bottom a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
    padding-inline: 2px;
  }

  /* 语言切换：原 19px 高，太难点 */
  .lang-switch a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    padding-inline: 14px;
    font-size: 14px;
  }
  .lang-switch { padding: 2px; }

  /* 面包屑（首页 / 产品中心） */
  .breadcrumb a,
  .breadcrumb span {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
  }

  /* 小号按钮 */
  .btn--sm { min-height: 40px; padding-inline: 20px; }

  /* 产品筛选标签 */
  .filter-tab { min-height: 40px; padding: 0 18px; display: inline-flex; align-items: center; }

  /* 「了解更多」这类文字链 */
  .text-link { min-height: 40px; }

  /* 电话 / 邮箱链接：手机上只有 19~25px 高，是页面上最难点的两个
     （用属性选择器，免得去猜它们外面套的是什么 class；首页那三张
     联系卡里的「微信/咨询」也一样小，一并撑起来） */
  a[href^="tel:"],
  a[href^="mailto:"],
  .contact-card p a {
    display: inline-flex;
    align-items: center;
    min-height: 40px;
  }

  /* 汉堡按钮已经 44x44，保持 */
  .nav-toggle { min-width: 44px; min-height: 44px; }
}

/* ================= 2. 安全区（刘海 / 底部手势条） ================= */

@supports (padding: env(safe-area-inset-bottom)) {

  /* 头部左右留出刘海的横向安全区（横屏时最明显） */
  .site-header .container {
    padding-left: max(var(--gutter), env(safe-area-inset-left));
    padding-right: max(var(--gutter), env(safe-area-inset-right));
  }

  /* 页脚同理，底部还要躲开手势条 */
  .site-footer .container {
    padding-left: max(var(--gutter), env(safe-area-inset-left));
    padding-right: max(var(--gutter), env(safe-area-inset-right));
    padding-bottom: env(safe-area-inset-bottom);
  }

  /* 返回顶部按钮别被手势条盖住 */
  .to-top {
    right: max(20px, env(safe-area-inset-right));
    bottom: calc(24px + env(safe-area-inset-bottom));
    width: 48px;
    height: 48px;
  }
}

/* ================= 3. 小屏布局微调 ================= */

@media (max-width: 980px) {

  /* 3.1 手机侧边抽屉导航：留出安全区 + 点按区更大 */
  .nav {
    padding-left: max(var(--sp-5), env(safe-area-inset-left));
    padding-bottom: calc(var(--sp-6) + env(safe-area-inset-bottom));
  }
  .nav-link {
    min-height: 52px;
    display: flex;
    align-items: center;
    font-size: 17px;
  }

  /* 3.2 二维码在手机上是给人扫的，别太小也别太大 */
  .footer-qr img { width: 108px; height: 108px; }

  /* 3.3 证书墙：小屏两列，图别占满 */
  .cert-wall img { height: 110px; }
}

@media (max-width: 560px) {

  /* 3.4 主流手机（360~430px）上把内外边距收紧一点点，
       正文宽度更舒服，也不会出现「一行只放得下 8 个字」 */
  :root { --gutter: 20px; }

  /* 3.5 手机端加宽页脚二维码到可扫尺寸 */
  .footer-qr img { width: 120px; height: 120px; }

  /* 3.6 首屏 hero 的上下留白收紧，让「查看产品」按钮尽量在首屏内 */
  .hero-inner { padding-block: 44px; }
  .hero-stats { margin-top: var(--sp-6); padding-top: var(--sp-5); }
  .hero-ribbon { opacity: .22; }

  /* 3.7 区块间距：桌面的大留白在手机上会显得空 */
  .section { padding-block: 48px; }

  /* 3.8 证书墙改两列并缩小 */
  .cert-wall { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cert-wall img { height: 96px; }

  /* 3.9 二维码面板 */
  .qr-panel img { width: 140px; height: 140px; }
}

/* ================= 4. 图片与媒体 ================= */

/* 4.1 给了 width/height 属性的图，让浏览器按比例自适应：
     属性负责「占位、防跳动」，CSS 负责「随容器缩放」。
     用 :where() 把优先级压到 0，这样 .brand-logo{height:46px}
     这类本来就写死高度的规则依然说了算。 */
:where(img[width][height]) { height: auto; }

/* 4.2 图标类小图不要被拉变形 */
.brand-logo,
.footer-brand img,
.brand-card img,
.cert-wall img {
  object-fit: contain;
}

/* ================= 5. 长页面与横向滚动容器 ================= */

@media (max-width: 720px) {

  /* 5.1 产品筛选条：加一个右侧渐隐，提示「还能往右滑」，
        再加滚动吸附，滑到哪一格就停在哪一格 */
  .filter-tabs {
    scroll-snap-type: x proximity;
    scroll-padding-inline: var(--gutter);
    -webkit-mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 44px), transparent 100%);
    mask-image: linear-gradient(90deg, #000 0, #000 calc(100% - 44px), transparent 100%);
  }
  .filter-tab { scroll-snap-align: start; }
}

/* ================= 6. 无障碍与降级 ================= */

/* 6.1 用户把系统字号调大时，别让按钮文字憋不住 */
@media (max-width: 980px) {
  .btn { white-space: normal; }
}

/* 6.2 将来加表单也不会被 iOS 自动放大（触发放大的是 <16px） */
@media (max-width: 980px) {
  input,
  select,
  textarea {
    font-size: 16px;
  }
}

/* 6.3 横屏手机（高度很小）：首屏不要硬撑 */
@media (max-width: 980px) and (orientation: landscape) and (max-height: 520px) {
  .hero-inner { padding-block: 32px; }
  .hero-stats { display: none; }
}

/* 6.4 尊重「减弱动态效果」——把位移类过渡也去掉 */
@media (prefers-reduced-motion: reduce) {
  .btn:hover,
  .btn:active,
  .card:hover,
  .feature:hover,
  .brand-card:hover,
  .contact-card:hover,
  .card:hover .card-media img,
  .gallery-item:hover img {
    transform: none !important;
  }
}

/* 6.5 打印：不要二维码和返回顶部 */
@media print {
  .to-top,
  .footer-qr,
  .nav-toggle {
    display: none !important;
  }
}

/* ================= 7. 编辑器在窄视口下（手机上 / 手机预览框里） =================
   下面这些只对 ?edit=1 的编辑页生效（#ie-ui 只存在于编辑页），
   访客页完全不受影响。让编辑器在 360~440px 的视口里依然可用：
   底部工具条横向滚动、属性面板变成贴底抽屉。 */

@media (max-width: 900px) {

  /* 7.0 内核自带的底部浮条：桌面上一行放得下，390px 下会折成 5 行、
        实测高达 350px（占屏 41%），把网页全挡住了。
        改成「单行 + 横向滑动」，高度立刻回到 ~56px。 */
  #ie-ui .ie-bar {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overflow-y: hidden;
    max-height: 64px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #ie-ui .ie-bar::-webkit-scrollbar { display: none; }
  #ie-ui .ie-bar > * { flex: 0 0 auto; }

  /* 内核的引导浮层：窄屏下别做成一根 486px 高的竖条 */
  #ie-ui .ie-note {
    left: 10px !important;
    right: 10px !important;
    width: auto !important;
    max-height: 62vh;
    overflow-y: auto;
  }

  /* 7.1 底部工具条：一行放不下就横向滑动，别挤成两行压住页面 */
  #ie-ui .ie-x-bar,
  #ie-ui .cf-bar {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  #ie-ui .ie-x-bar::-webkit-scrollbar,
  #ie-ui .cf-bar::-webkit-scrollbar { display: none; }

  /* 结构编辑的每一行也不许内部折行，改成整行横向滑动 */
  #ie-ui .ie-x-row {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #ie-ui .ie-x-row::-webkit-scrollbar { display: none; }
  #ie-ui .ie-x-row > * { flex: 0 0 auto; }

  /* 7.2 工具条按钮撑到手指点得着 */
  #ie-ui button,
  #ie-ui .cf-bar-btn {
    min-height: 40px;
    min-width: 40px;
  }

  /* 7.3 右侧属性面板改成「贴底抽屉」，宽度占满，高度不超半屏 */
  #ie-ui .ie-x-panel {
    left: 0;
    right: 0;
    top: auto;
    bottom: 0;
    width: auto;
    max-width: 100%;
    max-height: 58vh;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #ie-ui .ie-x-panel .ie-x-pbody { max-height: calc(58vh - 96px); }
  #ie-ui .ie-x-panel input,
  #ie-ui .ie-x-panel select,
  #ie-ui .ie-x-panel textarea { font-size: 16px; }

  /* 7.4 顶部浮条 / 弹出菜单也要能横向滑动 */
  #ie-ui .ie-x-hd,
  #ie-ui .ie-x-menu,
  #ie-ui .cf-bar {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-width: none;
  }
  #ie-ui .ie-x-hd::-webkit-scrollbar,
  #ie-ui .ie-x-menu::-webkit-scrollbar { display: none; }

  /* 7.5 编辑页在窄视口下不要横向滚动 */
  html.cf-editing,
  html.cf-editing body { overflow-x: clip; }
}
