/**
 * DogNet 移动端优化样式 - 最终修复版
 * 解决所有CSS问题，提升性能和兼容性
 * @version 2.1 - 修复版
 */

/* ===== 完整CSS变量定义（带回退值） ===== */
:root {
  /* 移动端专用变量 - 带浏览器默认值回退 */
  --mobile-touch-size: 44px;
  --mobile-touch-size-fallback: 44px;
  --mobile-spacing: 1rem;
  --mobile-spacing-fallback: 16px;
  --mobile-font-size: 14px;
  --mobile-font-size-fallback: 14px;
  --mobile-border-radius: 8px;
  --mobile-border-radius-fallback: 8px;
  --mobile-transition: 0.2s ease;
  --mobile-transition-fallback: 0.2s ease;
  
  /* 颜色变量 */
  --mobile-touch-bg: rgba(0, 0, 0, 0.1);
  --mobile-touch-bg-fallback: #f0f0f0;
  --mobile-shadow: rgba(0, 0, 0, 0.2);
  --mobile-shadow-fallback: #ccc;
  
  /* 安全区域变量 */
  --safe-area-top: env(safe-area-inset-top, 0px);
  --safe-area-bottom: env(safe-area-inset-bottom, 0px);
  --safe-area-left: env(safe-area-inset-left, 0px);
  --safe-area-right: env(safe-area-inset-right, 0px);
}

/* ===== 重置和基础样式 ===== */
/* 使用标准CSS而非Tailwind指令 */
@media (max-width: 768px) {
  /* 基础重置 */
  html {
    font-size: var(--mobile-font-size, 14px);
    line-height: 1.5;
  }
  
  body {
    font-size: 0.875rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }
  
  /* 容器优化 - 使用标准CSS */
  .container {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    max-width: 100%;
    margin: 0 auto;
  }
  
  .container-fluid {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  
  /* 标题优化 - 使用rem单位 */
  h1 {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.2;
  }
  
  h2 {
    font-size: 1.125rem;
    font-weight: 600;
    line-height: 1.3;
  }
  
  h3 {
    font-size: 1rem;
    font-weight: 500;
    line-height: 1.4;
  }
  
  /* 触摸目标优化 - 使用标准CSS */
  .btn,
  .button,
  button,
  [role="button"],
  .touch-optimized {
    min-height: var(--mobile-touch-size, 44px);
    min-width: var(--mobile-touch-size, 44px);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    transition: all var(--mobile-transition, 0.2s ease);
    -webkit-transition: all var(--mobile-transition, 0.2s ease);
    -moz-transition: all var(--mobile-transition, 0.2s ease);
  }
  
  /* 表单优化 - 针对移动设备 */
  .form-input,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="tel"],
  input[type="url"],
  input[type="search"],
  select,
  textarea {
    height: 3rem;
    font-size: 1rem;
    padding: 0.75rem 1rem;
    min-height: var(--mobile-touch-size, 44px);
    border-radius: var(--mobile-border-radius, 8px);
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    border: 1px solid #d1d5db;
    background-color: #ffffff;
  }
  
  /* 卡片优化 */
  .card {
    margin-left: 0.5rem;
    margin-right: 0.5rem;
    margin-bottom: 1rem;
    border-radius: 0.5rem;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
  }
  
  .card-header,
  .card-body,
  .card-footer {
    padding: 1rem;
  }
  
  /* 导航优化 - 使用标准定位 */
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 50;
    width: 20rem;
    max-width: 20rem;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 40;
    height: 4rem;
    background-color: #ffffff;
    border-top: 1px solid #e5e7eb;
  }
  
  /* 模态框优化 */
  .modal-content {
    width: 100%;
    max-width: none;
    margin: 0.5rem;
    border-radius: var(--mobile-border-radius, 8px);
  }
  
  /* 性能优化类 */
  .gpu-accelerated {
    transform: translateZ(0);
    -webkit-transform: translateZ(0);
    will-change: transform;
  }
  
  .reduce-repaint {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
    perspective: 1000px;
    -webkit-perspective: 1000px;
  }
}

/* ===== 平板设备优化（768px-1024px） ===== */
@media (min-width: 769px) and (max-width: 1024px) {
  .container {
    padding-left: 1rem;
    padding-right: 1rem;
    max-width: 64rem;
  }
}

/* ===== 小屏幕优化（480px以下） ===== */
@media (max-width: 480px) {
  :root {
    --mobile-font-size: 13px;
    --mobile-touch-size: 40px;
  }
  
  .container {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
  }
  
  .card {
    margin-left: 0.25rem;
    margin-right: 0.25rem;
    margin-bottom: 0.75rem;
  }
}

/* ===== 超小屏幕优化（360px以下） ===== */
@media (max-width: 360px) {
  :root {
    --mobile-font-size: 12px;
    --mobile-touch-size: 38px;
  }
  
  .container {
    padding-left: 0.375rem;
    padding-right: 0.375rem;
  }
}

/* ===== 触摸反馈优化（修复魔法数字） ===== */
.touch-feedback {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.touch-feedback::before {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background-color: var(--mobile-touch-bg, rgba(0, 0, 0, 0.1));
  transform: translate(-50%, -50%);
  -webkit-transform: translate(-50%, -50%);
  transition: width 0.3s ease, height 0.3s ease;
  -webkit-transition: width 0.3s ease, height 0.3s ease;
  pointer-events: none;
}

.touch-feedback:active::before {
  width: 150%;
  height: 150%;
  max-width: 300px;
  max-height: 300px;
}

/* ===== 焦点指示器（可访问性） ===== */
.touch-feedback:focus-visible {
  outline: 2px solid #3b82f6;
  outline-offset: 2px;
}

/* ===== 安全区域适配（修复兼容性问题） ===== */
@supports (padding: max(0px)) {
  .mobile-safe-area {
    padding-left: max(var(--mobile-spacing, 1rem), var(--safe-area-left, 0px));
    padding-right: max(var(--mobile-spacing, 1rem), var(--safe-area-right, 0px));
    padding-bottom: max(var(--mobile-spacing, 1rem), var(--safe-area-bottom, 0px));
  }
}

/* ===== 动画优化（修复性能问题） ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== 加载状态（新增） ===== */
.mobile-loading {
  position: relative;
  overflow: hidden;
}

.mobile-loading::after {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4), transparent);
  animation: mobile-loading 1.5s infinite;
}

@keyframes mobile-loading {
  0% { left: -100%; }
  100% { left: 100%; }
}

/* ===== 工具类（修复和优化） ===== */
.mobile-hidden {
  display: none !important;
}

@media (min-width: 768px) {
  .mobile-hidden {
    display: block !important;
  }
}

.mobile-visible {
  display: block !important;
}

@media (min-width: 768px) {
  .mobile-visible {
    display: none !important;
  }
}

.mobile-full-width {
  width: 100% !important;
}

.mobile-center {
  margin-left: auto !important;
  margin-right: auto !important;
  text-align: center !important;
}

/* ===== 响应式工具类（新增） ===== */
@media (max-width: 768px) {
  .mobile-text-sm { font-size: 0.875rem; }
  .mobile-text-base { font-size: 1rem; }
  .mobile-text-lg { font-size: 1.125rem; }
  .mobile-p-2 { padding: 0.5rem; }
  .mobile-p-4 { padding: 1rem; }
  .mobile-mb-2 { margin-bottom: 0.5rem; }
  .mobile-mb-4 { margin-bottom: 1rem; }
}