/* =============================================
   KiKi Responsive Fix  |  hiib.cn
   断点: 768px(平板) / 480px(手机)
   v2.1 - 修复 mobile-nav 通配符污染问题
   ============================================= */

/* --- 基础重置 --- */
*, *::before, *::after { box-sizing: border-box; }
img, video, iframe, embed, object {
  max-width: 100% !important;
  height: auto !important;
}
table { max-width: 100% !important; }
html, body { overflow-x: hidden; }

/* --- 修复固定宽度容器（排除 mobile-nav） --- */
[style*="width:"]:not(.mobile-nav):not(.mobile-overlay) {
  max-width: 100% !important;
}

/* ============ 平板 ≤ 768px ============ */
@media screen and (max-width: 768px) {

  /* 容器自适应（精确类名，不用通配符） */
  .container, .wrapper, .wrap, .main,
  .content, .inner, .page, .section {
    width: 100% !important;
    max-width: 100% !important;
    padding-left: 16px !important;
    padding-right: 16px !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    float: none !important;
  }

  /* 多列布局折叠（排除 mobile-nav 相关） */
  .row, .grid, .cols {
    display: flex !important;
    flex-wrap: wrap !important;
  }
  .col, [class*="col-"], [class*="span"] {
    width: 100% !important;
    max-width: 100% !important;
    flex: 0 0 100% !important;
    float: none !important;
    padding-left: 0 !important;
    padding-right: 0 !important;
  }

  /* 导航栏（精确匹配，不用 [class*="nav"] 通配符） */
  .header, .site-header {
    width: 100% !important;
    overflow-x: hidden !important;
  }
  /* header-inner 保持 flex 横排（logo + 汉堡按钮） */
  .header-inner {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    padding: 0 16px !important;
  }

  /* ★ 关键修复：移动端抽屉菜单不受通配符影响 ★ */
  .mobile-nav {
    position: fixed !important;
    top: 0 !important;
    right: -300px !important;   /* 默认隐藏在屏幕右侧 */
    width: 280px !important;    /* 固定宽度，不能 100% */
    height: 100vh !important;
    z-index: 1000 !important;
    overflow-x: visible !important;
    overflow-y: auto !important;
    transition: right 0.3s ease !important;
  }
  .mobile-nav.show {
    right: 0 !important;
  }
  .mobile-overlay {
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    z-index: 999 !important;
  }
  /* mobile-nav 内部链接不受 col 通配符影响 */
  .mobile-nav-links a,
  .mobile-nav-links span {
    width: 100% !important;
    flex: none !important;
    display: block !important;
  }

  /* Logo 文字不竖排 */
  .logo { display: flex !important; flex-direction: row !important; align-items: center !important; }
  .logo-text { display: flex !important; flex-direction: column !important; }
  .logo-en { display: block !important; white-space: nowrap !important; }

  /* 汉堡菜单按钮 */
  .menu-btn {
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 5px !important;
    width: 44px !important;
    height: 44px !important;
    padding: 10px !important;
    cursor: pointer !important;
    background: none !important;
    border: none !important;
    flex-shrink: 0 !important;
  }
  .menu-btn span {
    display: block !important;
    width: 22px !important;
    height: 2px !important;
    border-radius: 2px !important;
  }

  /* 字体缩放 */
  h1 { font-size: clamp(22px, 5vw, 36px) !important; }
  h2 { font-size: clamp(18px, 4vw, 28px) !important; }
  h3 { font-size: clamp(16px, 3.5vw, 22px) !important; }
  p, li, td, th { font-size: clamp(13px, 3.5vw, 16px) !important; line-height: 1.7 !important; word-break: break-word !important; }

  /* 按钮可点击性（排除 mobile-nav-close 避免样式冲突） */
  button:not(.mobile-nav-close):not(#kiki-back-top),
  .btn, a.btn,
  input[type="submit"], input[type="button"], input[type="reset"] {
    min-height: 44px !important;
    min-width: 44px !important;
    padding: 10px 18px !important;
    font-size: 15px !important;
    touch-action: manipulation !important;
    cursor: pointer !important;
  }

  /* 表单输入框 */
  input[type="text"], input[type="email"], input[type="tel"],
  input[type="password"], input[type="search"],
  textarea, select {
    width: 100% !important;
    min-height: 44px !important;
    font-size: 16px !important;
    padding: 8px 12px !important;
  }

  /* 图片居中 */
  img { display: block; margin: 0 auto; }

  /* 表格横向滚动 */
  table {
    display: block !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  /* Banner / Hero 区域 */
  .banner, .hero, .slider, .swiper {
    min-height: 200px !important;
    height: auto !important;
  }

  /* 侧边栏折叠 */
  .sidebar, .aside, aside {
    width: 100% !important;
    float: none !important;
    margin: 0 0 20px 0 !important;
  }

  /* 卡片网格 */
  .card-grid, .cards {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }

  /* 返回顶部按钮 */
  #kiki-back-top {
    bottom: 20px !important;
    right: 16px !important;
    width: 40px !important;
    height: 40px !important;
    font-size: 18px !important;
  }

  /* 备案栏 */
  #kiki-beian-bar {
    font-size: 11px !important;
    padding: 10px 12px !important;
    line-height: 2 !important;
  }
}

/* ============ 手机 ≤ 480px ============ */
@media screen and (max-width: 480px) {

  body { overflow-x: hidden !important; }

  .container, .wrapper, .wrap, .main,
  .content, .inner, .page, .section {
    padding-left: 12px !important;
    padding-right: 12px !important;
  }

  .col, [class*="col-"], [class*="span"] {
    width: 100% !important;
    flex: 0 0 100% !important;
  }

  h1 { font-size: clamp(20px, 6vw, 28px) !important; }
  h2 { font-size: clamp(17px, 5vw, 22px) !important; }
  h3 { font-size: clamp(15px, 4.5vw, 18px) !important; }

  .btn-block {
    width: 100% !important;
    display: block !important;
  }

  [class*="decor"], [class*="ornament"],
  [class*="deco-"] { display: none !important; }
}
