/**
 * 全站移动端统一规范（首页 + 工作台等）
 * 与 PC 共存：默认仅 @media (max-width: 768px) 内生效的增强；全局防横向溢出对全宽生效。
 */

/* ── 全局：禁止横向溢出 ── */
html {
  overflow-x: hidden;
  max-width: 100%;
  -webkit-text-size-adjust: 100%;
}
body {
  overflow-x: hidden;
  max-width: 100vw;
  box-sizing: border-box;
}
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* 主容器、卡片、弹层默认不撑破视口 */
main,
section,
article,
.container,
.card,
.drawer,
.modal-root {
  max-width: 100%;
}

/* ── 设计变量（移动端） ── */
@media (max-width: 768px) {
  :root {
    --m-page-pad: 16px;
    --m-card-radius: 16px;
    --m-modal-radius: 20px;
    --m-btn-radius: 12px;
    --m-gap: 16px;
    --m-title-page: 22px;
    --m-title-module: 18px;
    --m-title-card: 16px;
    --m-body: 15px;
    --m-caption: 12px;
    --m-safe-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
}

/* ========== 首页轮播 / 首屏（≤768px） ========== */
@media (max-width: 768px) {
  .carousel {
    margin-top: 0;
    min-height: auto;
    height: min(100svh, 720px);
    height: min(100dvh, 720px);
    max-height: none;
  }
  .carousel-track,
  .slide {
    min-height: inherit;
  }
  .slide-content {
    justify-content: flex-start;
    padding: calc(72px + env(safe-area-inset-top, 0px)) var(--m-page-pad, 16px)
      calc(100px + env(safe-area-inset-bottom, 0px));
    text-align: left;
    align-items: stretch;
  }
  .slide-html {
    padding: calc(72px + env(safe-area-inset-top, 0px)) var(--m-page-pad, 16px)
      calc(96px + env(safe-area-inset-bottom, 0px));
    overflow: visible;
  }
  .slide-tag {
    font-size: 11px;
    padding: 6px 14px;
    margin-bottom: 12px;
    align-self: flex-start;
  }
  .slide-title {
    font-size: clamp(24px, 7vw, 34px);
    line-height: 1.25;
    margin-bottom: 12px;
    text-align: left;
  }
  .slide-subtitle {
    font-size: 14px;
    line-height: 1.65;
    margin-bottom: 20px;
    max-width: none;
    text-align: left;
  }
  /* 「查看详情」与左右箭头同一水平线（垂直居中对齐视口），水平居中 */
  .slide .slide-content,
  .slide .slide-content.slide-html {
    position: relative;
  }
  .slide .slide-actions {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    z-index: 5;
    width: auto;
    max-width: calc(100% - 120px);
    margin: 0;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: nowrap;
    pointer-events: auto;
  }
  .slide .slide-actions .slide-btn {
    width: auto;
    max-width: 100%;
    justify-content: center;
    border-radius: 999px;
    padding: 12px 28px;
    box-shadow: 0 10px 28px rgba(0, 0, 0, 0.22);
  }
  .slide-btn {
    align-self: flex-start;
    min-height: 46px;
    font-size: 15px;
  }
  .carousel-arrow {
    z-index: 8;
  }
  .carousel-dots {
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    padding: 0 16px;
  }
  .carousel-arrow {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
  }
  .carousel-arrow.prev {
    left: 8px;
  }
  .carousel-arrow.next {
    right: 8px;
  }
  .container {
    padding-left: var(--m-page-pad, 16px);
    padding-right: var(--m-page-pad, 16px);
  }
  section {
    padding: 48px 0;
    scroll-margin-top: 72px;
  }
}

/* ========== 工作台：顶栏双行 ========== */
.wb-hdr {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0 var(--m-page-pad, 16px);
  padding-top: max(8px, env(safe-area-inset-top, 0px));
  background: var(--green, #1a4d2e);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}
.wb-hdr-row1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 48px;
}
.wb-hdr-title {
  font-size: clamp(16px, 4.2vw, 20px);
  font-weight: 800;
  flex: 1;
  min-width: 0;
  line-height: 1.25;
}
.wb-hdr-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.wb-hdr-row2 {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
}
.wb-hdr-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.wb-hdr-user {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  line-height: 1.35;
  opacity: 0.92;
  word-break: break-word;
}

.hdr-btn,
.wb-hdr .hdr-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  padding: 8px 12px;
  min-height: 44px;
  min-width: 44px;
  border-radius: var(--m-btn-radius, 12px);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

@media (min-width: 769px) {
  .wb-hdr {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    row-gap: 8px;
    padding: 0 20px;
    min-height: 56px;
  }
  .wb-hdr-row1 {
    flex: 1 1 auto;
    min-height: 56px;
  }
  .wb-hdr-row2 {
    flex: 1 1 100%;
    order: 3;
    border-top: none;
    padding: 0 0 8px;
    border-bottom: none;
  }
  .wb-hdr-title {
    font-size: 20px;
  }
}

@media (min-width: 900px) {
  .wb-hdr-row2 {
    flex: 0 1 auto;
    order: 0;
    padding: 0;
    margin-left: 12px;
    border-top: none;
  }
  .wb-hdr {
    flex-direction: row;
    align-items: center;
  }
}

/* 底部主导航（仅移动端显示） */
.wb-bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 95;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid rgba(26, 77, 46, 0.12);
  box-shadow: 0 -4px 20px rgba(15, 40, 25, 0.08);
  padding: 6px max(8px, env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom, 0px))
    max(8px, env(safe-area-inset-left));
  justify-content: space-around;
  align-items: stretch;
}
.wb-bottom-nav button {
  flex: 1;
  max-width: 20%;
  border: none;
  background: transparent;
  color: #35543f;
  font-size: 10px;
  font-weight: 700;
  padding: 4px 2px 2px;
  border-radius: 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}
.wb-bottom-nav button .wb-bnav-ic {
  font-size: 20px;
  line-height: 1;
}
.wb-bottom-nav button.active {
  background: rgba(45, 122, 78, 0.12);
  color: #1a4d2e;
}

@media (max-width: 768px) {
  .wb-bottom-nav {
    display: flex;
  }
  .app.has-wb-bottom-nav .content {
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }
}

/* Tab：胶囊 + 横向滚动 */
@media (max-width: 768px) {
  .tabs {
    padding: 8px 12px;
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    flex-wrap: nowrap;
    scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar {
    display: none;
  }
  .tabs .tab {
    scroll-snap-align: start;
    flex: 0 0 auto;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    border-bottom: none !important;
    background: #eef4f0;
    color: #496052;
  }
  .tabs .tab.active {
    background: #1a4d2e;
    color: #fff;
    box-shadow: none;
  }
}

/* 农事日历页 */
.wb-cal-page {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}
.wb-cal-nav-card {
  border-radius: var(--m-card-radius, 16px);
  margin-bottom: var(--m-gap, 16px);
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  width: 100%;
  max-width: 100%;
}
.wb-cal-nav-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.wb-cal-month-label {
  font-weight: 800;
  font-size: 16px;
  text-align: center;
  flex: 1;
  min-width: 0;
}
.wb-cal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}
.wb-cal-actions .btn {
  width: 100%;
  justify-content: center;
  min-height: 44px;
  border-radius: var(--m-btn-radius, 12px);
}
.wb-cal-actions .wb-cal-span2 {
  grid-column: 1 / -1;
}
.wb-cal-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.wb-cal-scroll .cal-table {
  min-width: 100%;
  table-layout: fixed;
  width: 100%;
}
@media (max-width: 768px) {
  .wb-cal-scroll .cal-table th,
  .wb-cal-scroll .cal-table td {
    width: 14.28%;
    max-width: 14.28%;
  }
  .cal-cell {
    min-width: 0 !important;
    padding: 4px 2px !important;
    vertical-align: top;
  }
  .cal-num {
    font-size: 11px;
  }
  .cal-task {
    font-size: 10px !important;
    padding: 4px 4px !important;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-height: 0 !important;
    display: block;
  }
}

/* 客户详情抽屉 */
.wb-cust-drawer {
  width: 100%;
  max-width: 100%;
}
.wb-cust-drawer .drawer-title {
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.wb-cust-drawer .drawer-title > span:first-child {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.3;
  padding-right: 44px;
  position: relative;
}
.wb-cust-drawer .drawer-title-toolbar {
  width: 100%;
  max-width: 100%;
  margin-left: 0 !important;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 8px;
  overflow-x: visible;
  padding: 8px 0 4px;
  border-top: 1px solid #e8efe8;
}
.wb-cust-drawer .drawer-title-toolbar .btn-sm {
  white-space: normal;
  text-align: center;
  line-height: 1.25;
  min-height: 40px;
  flex: 1 1 calc(50% - 6px);
  max-width: calc(50% - 4px);
}
.wb-cust-drawer .drawer-title-toolbar .wb-tb-dd {
  flex: 1 1 calc(50% - 6px);
  max-width: calc(50% - 4px);
}
.wb-cust-drawer .drawer-title-toolbar .wb-tb-dd > summary {
  width: 100%;
  text-align: center;
  justify-content: center;
}
.wb-cust-drawer .drawer-title-toolbar .close-btn {
  position: absolute;
  top: 0;
  right: 0;
  margin-left: 0 !important;
}
@media (max-width: 768px) {
  .wb-cust-drawer .drawer-title {
    position: relative;
  }
}

.wb-cust-drawer .wb-cust-bridge-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.wb-cust-drawer .wb-cust-bridge-grid .btn-sm {
  width: 100%;
  justify-content: center;
  min-height: 40px;
}
@media (min-width: 769px) {
  .wb-cust-drawer .wb-cust-bridge-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .wb-cust-drawer .wb-cust-bridge-grid .btn-sm {
    width: auto;
  }
}

/* 仓库页：选择器卡片 + 宫格 */
.wb-wh-header .fi {
  max-width: 100% !important;
  width: 100%;
}
.wh-whsel-card {
  border-radius: var(--m-card-radius, 16px);
  margin-bottom: var(--m-gap, 16px);
  background: var(--card, #fff);
  border: 1px solid var(--border, #d4e8d8);
}
.wh-whsel-card .wh-whsel-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: stretch;
}
@media (max-width: 768px) {
  .wh-quick-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 10px !important;
  }
  .wh-quick-actions .btn {
    min-height: 44px;
    border-radius: var(--m-btn-radius, 12px);
  }
  .wh-quick-actions .wh-act-export[style*='grid-column'] {
    grid-column: 1 / -1 !important;
  }
}

/* 抽屉通用：圆角与安全区 */
@media (max-width: 768px) {
  .drawer {
    border-radius: var(--m-modal-radius, 20px) var(--m-modal-radius, 20px) 0 0;
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
    padding-bottom: max(20px, env(safe-area-inset-bottom, 0px));
    max-height: min(92dvh, 900px);
  }
}

/* 带底部 Dock 的站点：锚点滚动为底栏与顶栏预留空间（配合 scrollIntoView / scroll-margin） */
@media (max-width: 1024px) {
  html {
    scroll-padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 12px);
  }
  body.has-bottom-dock section {
    scroll-margin-top: min(128px, max(96px, 20vw));
    scroll-margin-bottom: 12px;
  }
  body.page-home section {
    scroll-margin-top: min(128px, max(96px, 20vw));
  }
}
