/**
 * PWA 移动端优化样式
 * 针对触摸设备、下拉刷新、手势操作等进行优化
 */

/* ===== 触摸优化 ===== */

/* 增大触摸目标尺寸（符合 WCAG 2.1 标准：44x44px） */
.touch-target,
button,
a,
[role="button"],
input[type="submit"],
input[type="button"] {
  min-height: 44px;
  min-width: 44px;
}

/* 触摸反馈优化 */
.touch-feedback {
  -webkit-tap-highlight-color: rgba(37, 99, 235, 0.1);
  tap-highlight-color: rgba(37, 99, 235, 0.1);
}

/* 禁用长按选择文本（对于交互元素） */
.no-select,
button,
[role="button"] {
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ===== 下拉刷新优化 ===== */

/* 防止页面过度滚动（iOS Safari） */
body {
  overscroll-behavior-y: contain;
}

/* 下拉刷新容器 */
.pull-to-refresh {
  position: relative;
  overflow: hidden;
}

/* 下拉指示器 */
.pull-to-refresh-indicator {
  position: absolute;
  top: -60px;
  left: 0;
  right: 0;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease;
  z-index: 10;
}

.pull-to-refresh-indicator.visible {
  transform: translateY(60px);
}

/* ===== 移动端表格优化 ===== */

@media (max-width: 768px) {
  /* 表格卡片化布局 */
  .responsive-table-card table {
    display: block;
  }
  
  .responsive-table-card thead {
    display: none;
  }
  
  .responsive-table-card tbody {
    display: block;
  }
  
  .responsive-table-card tr {
    display: flex;
    flex-direction: column;
    margin-bottom: 1rem;
    padding: 1rem;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 0.5rem;
  }
  
  .responsive-table-card td {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border: none;
  }
  
  .responsive-table-card td::before {
    content: attr(data-label);
    font-weight: 600;
    color: #6b7280;
  }
}

/* ===== 侧边栏移动端优化 ===== */

@media (max-width: 768px) {
  /* 侧边栏抽屉式 */
  .sidebar-drawer {
    position: fixed;
    left: -100%;
    top: 0;
    bottom: 0;
    width: 280px;
    transition: left 0.3s ease;
    z-index: 1000;
  }
  
  .sidebar-drawer.open {
    left: 0;
  }
  
  /* 遮罩层 */
  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }
  
  .sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
  }
}

/* ===== iOS 安全区域适配 ===== */

/* 顶部安全区域（刘海屏、状态栏） */
@supports (padding-top: env(safe-area-inset-top)) {
  .ios-safe-top {
    padding-top: calc(env(safe-area-inset-top) + 1rem);
  }
  
  .ios-safe-bottom {
    padding-bottom: calc(env(safe-area-inset-bottom) + 1rem);
  }
}

/* ===== 手势操作优化 ===== */

/* 滑动操作反馈 */
.swipeable {
  touch-action: pan-y;
  -webkit-overflow-scrolling: touch;
}

/* 快速滚动优化 */
.smooth-scroll {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* ===== 虚拟键盘优化 ===== */

/* 输入框获得焦点时，防止布局偏移 */
input:focus,
textarea:focus,
select:focus {
  scroll-margin-top: 100px;
}

/* 虚拟键盘弹出时的视口调整 */
@supports (height: 100dvh) {
  .mobile-viewport {
    min-height: 100dvh;
  }
}

/* ===== 横屏适配 ===== */

@media (orientation: landscape) and (max-height: 500px) {
  /* 横屏时减少垂直空间占用 */
  .mobile-header {
    height: 48px;
  }
  
  .mobile-padding {
    padding: 0.5rem;
  }
}

/* ===== 暗色模式支持（可选） ===== */

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary: #1f2937;
    --bg-secondary: #111827;
    --text-primary: #f3f4f6;
    --text-secondary: #9ca3af;
    --border-color: #374151;
  }
  
  /* 暗色模式下的样式覆盖 */
  /* 可根据需要逐步添加 */
}

/* ===== 性能优化 ===== */

/* 减少动画消耗（用户偏好） */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* GPU 加速优化 */
.gpu-accelerated {
  transform: translateZ(0);
  -webkit-transform: translateZ(0);
  will-change: transform;
}

