/* ============================================================
   UI-3 · 三端适配
   ------------------------------------------------------------
   一、PC 端   ≥ 1200px  原生设计，本文件不生效
   二、平板端 768 – 1199  导航收缩 + 侧栏图标轨 + 三列栅格
   三、移动端 ≤ 767       App 壳：顶部栏 + 底部 Tab + 抽屉菜单
   必须在全部基础样式之后引入。
   ============================================================ */

:root {
  --tabbar-h: 58px;
  --appbar-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

/* ============================================================
   一、平板端 768 – 1199
   ============================================================ */
@media (max-width: 1199px) and (min-width: 768px) {
  .wrap { padding: 0 20px; }

  /* 顶部导航：压缩 + 菜单横向滚动，右侧操作固定 */
  .logo__sub { display: none; }
  .logo__name { font-size: 17px; }
  .nav .wrap { gap: 10px; }
  .nav__menu {
    flex: 1 1 auto; min-width: 0; gap: 0;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .nav__menu::-webkit-scrollbar { display: none; }
  .nav__link { padding: 0 9px; font-size: 13px; white-space: nowrap; flex: none; }
  .nav__right { flex: none; gap: 6px; }
  .nav__right .btn--brand { display: none; }

  /* 首屏 */
  .hero { padding: 60px 0 54px; }
  .hero__in { grid-template-columns: minmax(0, 1fr) !important; gap: 26px; }
  .hero h1 { font-size: 38px; margin: 16px 0 14px; }
  .hero__sub { font-size: 14px; }
  .hero__side { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }

  /* 栅格：四列 → 三列，多列 → 单列 */
  .svc-grid, .svc-grid--3, .cat-grid, .case-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .svc-grid--2, .stats, .state-grid, .ov-grid, .swatches { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .ws-grid--2, .ws-grid--3, .ws-cols, .home-split, .detail, .pdp,
  .shophead, .market, .brief, .trust, .deliver, .co, .kv, .mtl__row,
  .flow, .hall, .edu, .sku, .dmd__facts {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .footer__main { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 26px; }
  .form-grid--3, .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

  /* 内联写死的多列栅格一并收敛 */
  [style*="repeat(4,"], [style*="repeat(5,"] { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  [style*="1fr 300px"], [style*="1fr 320px"], [style*="1fr 340px"], [style*="1fr 360px"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* 栅格/弹性子项允许收缩 */
  .co__card, .market__side, .market__main, .panel, .card, aside, section,
  .form-grid > *, .row > *, .ws__body > *, .wrap > * { min-width: 0; }

  /* 工作台：侧栏收成图标轨 */
  .ws { grid-template-columns: 76px 1fr; }
  .ws__side { padding-bottom: var(--sp-4); }
  .ws__brand { justify-content: center; padding: 14px 0 12px; }
  .ws__brand > span { display: none; }
  .ws__group { padding: 10px 6px 0; }
  .ws__group h5 { display: none; }
  .ws__link {
    position: relative; justify-content: center; gap: 0;
    padding: 11px 0; font-size: 0; line-height: 0;
  }
  .ws__link .icon { width: 20px; height: 20px; }
  .ws__link .badge {
    position: absolute; top: 4px; right: 6px; margin: 0;
    min-width: 15px; height: 15px; padding: 0 4px; font-size: 10px; line-height: 15px;
  }
  .ws__top { padding: 0 20px; gap: 12px; }
  .ws__body { padding: 18px 20px 40px; }
  .ws__top-right .ws__id { display: none; }

  /* 列表表格：自身横向滚动，避免撑破版面 */
  .tbl {
    display: block; width: 100%; max-width: 100%;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .tbl th, .tbl td { white-space: nowrap; }
}

/* ============================================================
   二、移动端 ≤ 767 —— App 体验
   ============================================================ */
@media (max-width: 767px) {

  /* ---------- 全局基础 ---------- */
  html, body { -webkit-text-size-adjust: 100%; }
  body {
    padding-bottom: calc(var(--tabbar-h) + var(--safe-b));
    overscroll-behavior-y: contain;
    overflow-x: clip;
  }
  img, svg, video { max-width: 100%; }
  .wrap { padding: 0 14px; }

  /* 输入类元素统一 16px，避免 iOS 聚焦缩放 */
  .input, .select, textarea, .searchbar input { font-size: 16px; }

  /* ---------- 门户：顶部 App 栏 ---------- */
  .site-header { display: none !important; }
  .topbar { display: none !important; }

  .appbar {
    position: sticky; top: 0; z-index: var(--z-nav);
    display: flex; align-items: center; gap: 10px;
    height: var(--appbar-h); padding: 0 14px;
    background: rgba(255, 255, 255, .94);
    backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--line);
  }
  .appbar__logo { display: flex; align-items: center; gap: 7px; flex: none; }
  .appbar__logo img { width: 26px; height: 26px; }
  .appbar__logo b {
    font-size: 15px; color: var(--brand-900); letter-spacing: .2px;
    white-space: nowrap; font-weight: 700;
  }
  .appbar__search {
    flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px;
    height: 34px; padding: 0 11px; border-radius: var(--r-pill);
    background: var(--surface-3); color: var(--text-3); font-size: 12px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .appbar__search svg { width: 15px; height: 15px; flex: none; }
  .appbar__bell {
    position: relative; flex: none; width: 34px; height: 34px;
    display: grid; place-items: center; border-radius: 50%;
    color: var(--text-2); background: var(--surface-3);
  }
  .appbar__bell svg { width: 18px; height: 18px; }
  .appbar__dot {
    position: absolute; top: 7px; right: 8px; width: 6px; height: 6px;
    border-radius: 50%; background: var(--deal-500); border: 1.5px solid #fff;
  }

  /* ---------- 底部 Tab ---------- */
  .tabbar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: var(--z-nav);
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    height: calc(var(--tabbar-h) + var(--safe-b));
    padding-bottom: var(--safe-b);
    background: rgba(255, 255, 255, .96);
    backdrop-filter: saturate(1.6) blur(12px);
    border-top: 1px solid var(--line);
    box-shadow: 0 -1px 0 rgba(16, 24, 40, .02);
  }
  .tabbar__item {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; color: var(--text-3); font-size: 10px; letter-spacing: .2px;
    position: relative; min-width: 0;
  }
  .tabbar__item svg { width: 21px; height: 21px; }
  .tabbar__item b { font-weight: 500; }
  .tabbar__item.is-on { color: var(--brand-700); }
  .tabbar__item.is-on b { font-weight: 700; }
  .tabbar__item.is-on::before {
    content: ""; position: absolute; top: 0; width: 22px; height: 2px;
    border-radius: 0 0 2px 2px; background: var(--brand-700);
  }
  .tabbar__badge {
    position: absolute; top: 5px; left: calc(50% + 6px);
    min-width: 15px; height: 15px; padding: 0 4px;
    border-radius: var(--r-pill); background: var(--deal-500); color: #fff;
    font: 700 10px/15px var(--font-num); text-align: center;
  }

  /* ---------- 首屏 / 区块 ---------- */
  .hero { padding: 26px 0 22px; border-bottom: 0; }
  .hero__in { grid-template-columns: 1fr !important; gap: 16px; }
  .hero h1 { font-size: 27px; line-height: 1.32; letter-spacing: -.5px; margin: 12px 0 10px; }
  .hero__sub { font-size: 13px; line-height: 1.7; }
  .hero__kicker { font-size: 11px; }
  .hero__side { display: grid; grid-template-columns: 1fr; gap: 8px; }
  .hero-card { padding: 12px 14px; }
  .searchbar { flex-wrap: nowrap; height: 44px; border-radius: var(--r-pill); }
  .searchbar__cat { display: none; }
  .searchbar input { min-width: 0; font-size: 14px; }

  section, .sec, .block { scroll-margin-top: calc(var(--appbar-h) + 8px); }
  h2, .sec__title { font-size: 19px !important; }
  h3 { font-size: 15px; }

  /* 区块标题行：标题不换行塌缩，描述独占一行 */
  .sect__head { flex-wrap: wrap; align-items: flex-start; gap: 6px; }
  .sect__title { flex: none; white-space: nowrap; }
  .sect__desc { flex: 1 1 100%; padding-bottom: 0; }
  .sect__more { margin-left: 0; }
  .market__bar { flex-wrap: wrap; gap: 6px; }

  /* ---------- 栅格：全部单列（minmax(0,1fr) 防止内容撑破） ---------- */
  .svc-grid, .svc-grid--2, .svc-grid--3, .case-grid, .cat-grid,
  .stats, .state-grid, .ov-grid, .swatches, .ws-grid--2, .ws-grid--3,
  .ws-cols, .home-split, .detail, .pdp, .shophead, .market, .brief,
  .trust, .deliver, .form-grid, .form-grid--3, .kv, .mtl__row,
  .shopcard__data, .prov__stats, .flow, .hall, .co, .edu, .sku,
  .dmd__facts, .auth-req, .filters__list, .menu-grid,
  .hall__banner, .audit-row, .shophead__actions, .idswitch__foot {
    grid-template-columns: minmax(0, 1fr) !important;
  }
  .hall__banner { gap: 12px !important; padding: 16px !important; }
  .hall__banner .nums { flex-wrap: wrap; gap: var(--sp-4); }
  .hall__tools { gap: 6px; }
  /* 工具行里的搜索框独占一行，避免被挤成圆点 */
  .hall__tools .searchbar, .market__bar .searchbar {
    flex: 1 1 100% !important; max-width: none !important;
  }
  .searchbar { min-width: 0; }
  .searchbar input { flex: 1 1 auto; min-width: 0; }
  .stats { gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .dmd__facts { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .stat { padding: 12px 14px; }
  .stat__val { font-size: 22px; }

  /* 栅格/弹性子项允许收缩，避免长表格与长文本把布局撑破 */
  .co__card, .market__side, .market__main, .panel, .card, aside, section,
  .form-grid > *, .kv > *, .row > *, .dmd__meta > *, .dmd__facts > div,
  .ws__body > *, .wrap > * { min-width: 0; }
  .row { flex-wrap: wrap !important; }
  .steps { overflow-x: auto; scrollbar-width: none; }
  .steps::-webkit-scrollbar { display: none; }
  .steps__item { flex: none; }
  h1, h2, h3, h4, p, dd, dt, li, label, .hint { overflow-wrap: anywhere; }
  .panel { border-radius: var(--r-3); }
  .panel__body { padding: 12px; }
  .panel__head { padding: 12px 14px; flex-wrap: wrap; gap: 6px; }
  .panel__head h3 { font-size: 14px; }

  /* 卡片列表：贴边全宽，接近原生列表 */
  .dmd {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 10px !important; padding: 13px 14px;
  }
  .dmd__title { font-size: 14px; }
  .dmd__side {
    flex-direction: row; align-items: center; justify-content: space-between;
    width: 100%; text-align: left;
    border-left: 0; border-top: 1px dashed var(--line);
    padding-left: 0; padding-top: 10px;
  }
  .dmd__budget { font-size: 17px; }

  /* 内联栅格（模板里写死的多列）一并收敛 */
  [style*="repeat(3,"], [style*="repeat(4,"], [style*="repeat(5,"] {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
  [style*="1fr 300px"], [style*="1fr 320px"], [style*="1fr 340px"], [style*="1fr 360px"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  /* 标签栏横向滚动 */
  .tabs, .chips, .subnav__in, .seg {
    overflow-x: auto; flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar, .chips::-webkit-scrollbar, .seg::-webkit-scrollbar { display: none; }
  .tabs__btn, .chip { white-space: nowrap; flex: none; }

  /* 表格：自身成为横向滚动容器，避免撑破页面 */
  .tbl {
    display: block; width: 100%; max-width: 100%;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    font-size: 12px;
  }
  .tbl th, .tbl td { white-space: nowrap; padding: 9px 10px; }
  .tbl thead, .tbl tbody { width: 100%; }
  .pager { flex-wrap: wrap; gap: 4px; padding-top: 14px; }
  .pager__sum { width: 100%; text-align: center; margin: 4px 0 0; }

  /* 页脚 */
  .footer { margin-top: 32px; }
  .footer__main { grid-template-columns: 1fr 1fr; gap: 22px; padding: 28px 0 20px; }
  .footer__brand { grid-column: 1 / -1; }
  .footer__base { font-size: 11px; }

  /* ---------- 筛选：侧栏 → 底部弹层 ---------- */
  .market__side { display: none; }
  .market__side.is-on {
    display: block; position: fixed;
    left: 0; right: 0; bottom: 0; top: auto; z-index: calc(var(--z-modal) + 5);
    max-height: 78vh; overflow: auto; -webkit-overflow-scrolling: touch;
    padding: 12px 12px calc(16px + var(--safe-b));
    background: #fff; border-radius: 16px 16px 0 0;
    box-shadow: 0 -14px 44px rgba(16, 24, 40, .22);
  }
  .market__side.is-on .filters { border: 0; }
  .sheet-mask {
    position: fixed; inset: 0; z-index: calc(var(--z-modal) + 4);
    background: rgba(16, 24, 40, .45);
    opacity: 0; visibility: hidden; transition: .2s var(--ease);
  }
  .sheet-mask.is-on { opacity: 1; visibility: visible; }
  .sheet-close {
    display: block; width: 100%; height: 38px; margin: 0 0 10px;
    border: 0; border-radius: var(--r-2); background: var(--surface-3);
    color: var(--text-2); font-size: 13px; font-weight: 600; cursor: pointer;
  }
  .filter-fab {
    position: fixed; right: 14px;
    bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 60;
    display: inline-flex; align-items: center; gap: 5px;
    height: 40px; padding: 0 16px; border: 0; border-radius: var(--r-pill);
    background: var(--brand-700); color: #fff;
    font-size: 13px; font-weight: 600; cursor: pointer;
    box-shadow: 0 8px 22px rgba(27, 92, 240, .32);
  }
  .filter-fab svg { width: 15px; height: 15px; }

  /* ---------- 工作台：侧栏改抽屉 ---------- */
  .ws { display: block; min-height: auto; }
  .ws__side {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: var(--z-modal);
    width: 264px; height: 100%; padding-bottom: 24px;
    transform: translateX(-101%);
    transition: transform .24s var(--ease);
    box-shadow: var(--shadow-3);
    border-right: 0;
  }
  .ws__side.is-open { transform: translateX(0); }
  .drawer-mask {
    position: fixed; inset: 0; z-index: calc(var(--z-modal) - 1);
    background: rgba(16, 24, 40, .42);
    opacity: 0; visibility: hidden; transition: opacity .24s var(--ease);
  }
  .drawer-mask.is-on { opacity: 1; visibility: visible; }

  .ws__main { display: block; }
  .ws__top {
    height: 50px; padding: 0 12px; gap: 8px;
    position: sticky; top: 0;
  }
  .ws__top h1 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .ws__top > .tag { display: none; }
  .ws__top .ws__role-tag { display: none; }
  .ws__top-right { gap: 6px; }
  .ws__top-right .ws__id { display: none; }
  .ws__top-right .ws__role { display: none; }
  .ws__top-right .btn { height: 30px; padding: 0 10px; font-size: 12px; }
  .ws__body { padding: 12px 12px 24px; gap: 10px; }

  .ws__menu-btn {
    flex: none; width: 32px; height: 32px; display: grid; place-items: center;
    border: 1px solid var(--line); border-radius: var(--r-2);
    background: #fff; color: var(--text-2); cursor: pointer;
  }
  .ws__menu-btn svg { width: 18px; height: 18px; }

  /* 工作台内容：表格/图表容器不再撑破 */
  .ws__body .panel, .ws__body .card { min-width: 0; }
  .audit { grid-template-columns: 1fr !important; }
  .audit__list { max-height: 320px; }
  .msg { grid-template-columns: 1fr !important; }
  .msg__side { display: none; }
  .msg__thread { min-height: 60vh; }

  /* ---------- 登录 / 注册：单列全屏 ---------- */
  body.is-auth { overflow: auto; padding-bottom: 0; }
  .auth { grid-template-columns: 1fr; height: auto; min-height: 100vh; overflow: visible; }
  .auth__aside { display: none; }
  .auth__panel { padding: 22px 16px 32px; align-items: start; overflow: visible; }
  .auth__box { max-width: none; margin: 0; }
  .roles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .rolediff { font-size: 11px; }

  /* ---------- 弹层：底部抽屉化 ---------- */
  .modal, .dialog { align-items: flex-end !important; }
  .modal__box, .dialog__box {
    width: 100% !important; max-width: none !important;
    border-radius: var(--r-4) var(--r-4) 0 0 !important;
    max-height: 88vh; overflow: auto;
  }
  .toast { bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px) !important; }

  /* 悬浮发布入口上移，避免被 Tab 遮挡 */
  .fab { bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px) !important; }
}

/* ============================================================
   三、窄屏微调 ≤ 400
   ============================================================ */
@media (max-width: 400px) {
  .appbar__logo b { font-size: 14px; }
  .hero h1 { font-size: 24px; }
  .tabbar__item { font-size: 9px; }
  .footer__main { grid-template-columns: 1fr; }
}

/* ============================================================
   四、触屏交互优化（PC 鼠标端不受影响）
   ============================================================ */
@media (hover: none) and (pointer: coarse) {
  a, button, .tabbar__item, .ws__link, .chip, .tabs__btn { -webkit-tap-highlight-color: transparent; }
  .btn, .nav__link, .chip, .tabs__btn, .role { min-height: 34px; }
  .svc:hover, .dmd:hover, .case:hover, .hero-card:hover { transform: none; }
}

/* 移动端隐藏桌面专有元素 */
@media (max-width: 767px) {
  .app-desk-only { display: none !important; }
}
