/* ===================================
   移动端优化样式表 - Mobile First
   优化项目：触摸区域、表单、导航、手势、图片
   测试设备：iPhone SE / iPhone 14 / iPad
   =================================== */

/* ===== 触摸区域优化 (≥44px) ===== */
/* Apple 人机交互指南推荐最小触摸区域 */
@media (max-width: 768px) {
  /* 按钮 */
  .btn, button, [role="button"] {
    min-height: 44px;
    min-width: 44px;
    padding: 12px 20px;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
  
  /* 小按钮 */
  .btn-sm, .btn-small {
    min-height: 40px;
    min-width: 40px;
    padding: 10px 16px;
  }
  
  /* 大按钮 */
  .btn-lg, .btn-large {
    min-height: 52px;
    padding: 14px 28px;
  }
  
  /* 图标按钮 */
  .btn-icon, .icon-btn {
    min-height: 44px;
    min-width: 44px;
    padding: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  
  /* 导航链接 */
  .nav-links a {
    min-height: 48px;
    display: flex;
    align-items: center;
    padding: 12px 20px;
  }
  
  /* 卡片可点击区域 */
  .card, .clickable-card, [data-clickable] {
    min-height: 44px;
    cursor: pointer;
  }
  
  /* 下拉选择 */
  select, .select-wrapper select {
    min-height: 44px;
    padding: 12px 40px 12px 16px;
  }
  
  /* 复选框和单选框 */
  input[type="checkbox"],
  input[type="radio"] {
    width: 24px;
    height: 24px;
    min-width: 24px;
    min-height: 24px;
    margin: 8px;
  }
  
  /* 开关 */
  .toggle-switch, .switch {
    width: 52px;
    height: 32px;
    min-width: 52px;
  }
  
  /* 分页按钮 */
  .pagination-btn {
    min-width: 44px;
    min-height: 44px;
    padding: 10px 14px;
  }
  
  /* Tab 标签 */
  .tab-btn, .tabs a {
    min-height: 44px;
    padding: 12px 16px;
    white-space: nowrap;
  }
  
  /* 搜索按钮 */
  .hero-search button {
    min-height: 52px;
  }
  
  /* 语言切换按钮 */
  .lang-btn {
    min-height: 44px;
    min-width: 60px;
    padding: 10px 16px;
  }
  
  /* 评价星级 */
  .star {
    min-width: 32px;
    min-height: 32px;
    font-size: 1.4rem;
  }
  
  /* 工具提示 */
  .tooltip {
    padding: 10px 14px;
    font-size: 14px;
  }
}

/* ===== 表单优化 ===== */
@media (max-width: 768px) {
  /* 输入框基础样式 */
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="search"],
  input[type="tel"],
  input[type="url"],
  input[type="number"],
  input[type="date"],
  input[type="datetime-local"],
  textarea {
    min-height: 48px;
    padding: 14px 16px;
    font-size: 16px; /* 防止iOS缩放 */
    border-radius: var(--radius);
  }
  
  /* textarea */
  textarea {
    min-height: 120px;
    resize: vertical;
  }
  
  /* 表单标签 */
  .form-label, label {
    font-size: 15px;
    margin-bottom: 8px;
    display: block;
  }
  
  /* 表单组 */
  .form-group {
    margin-bottom: 20px;
  }
  
  /* 表单行 */
  .form-row {
    gap: 16px;
  }
  
  /* 内联表单 */
  .form-inline {
    flex-direction: column;
    gap: 12px;
  }
  
  /* 表单验证提示 */
  .form-error, .error-message {
    font-size: 13px;
    padding: 8px 12px;
    border-radius: var(--radius);
  }
  
  /* 搜索框 */
  .search-input,
  .hero-search input {
    min-height: 48px;
    font-size: 16px;
  }
  
  /* 过滤器下拉 */
  .filter-select {
    min-height: 44px;
    padding: 10px 36px 10px 14px;
    font-size: 14px;
  }
  
  /* 数量输入 */
  .quantity-input {
    min-height: 44px;
    width: 80px;
  }
  
  /* 日期选择 */
  .date-input {
    min-height: 48px;
  }
  
  /* 滑块 */
  input[type="range"] {
    height: 44px;
    -webkit-appearance: none;
    background: transparent;
  }
  
  input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 50%;
    cursor: pointer;
    margin-top: -10px;
  }
  
  input[type="range"]::-webkit-slider-runnable-track {
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
  }
  
  /* 文件上传 */
  .file-upload {
    min-height: 100px;
    padding: 20px;
    border-radius: var(--radius-md);
  }
  
  /* 标签输入 */
  .tag-input {
    min-height: 44px;
    padding: 8px 12px;
  }
  
  /* 密码可见切换 */
  .password-toggle {
    min-width: 44px;
    min-height: 44px;
    padding: 10px;
  }
}

/* ===== 移动端导航优化 ===== */
@media (max-width: 768px) {
  /* 导航容器 */
  .navbar {
    height: 56px;
  }
  
  .navbar .container {
    height: 56px;
  }
  
  /* 汉堡菜单 */
  .nav-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 6px;
    width: 56px;
    height: 56px;
    padding: 12px;
    border: none;
    background: transparent;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  
  .nav-toggle span {
    width: 24px;
    height: 2.5px;
    background: var(--gray-800);
    border-radius: 2px;
    transition: all 0.3s ease;
  }
  
  /* 汉堡动画 */
  .nav-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 6px);
  }
  
  .nav-toggle.active span:nth-child(2) {
    opacity: 0;
  }
  
  .nav-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(6px, -7px);
  }
  
  /* 移动菜单 */
  .nav-links {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(20px);
    flex-direction: column;
    padding: 20px;
    gap: 4px;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    z-index: 999;
  }
  
  .nav-links.open,
  .nav-links.active {
    transform: translateX(0);
    display: flex;
  }
  
  /* 菜单项 */
  .nav-links a {
    min-height: 52px;
    padding: 14px 20px;
    font-size: 16px;
    background: var(--gray-50);
    border-radius: var(--radius-md);
    border: 1px solid var(--gray-100);
  }
  
  .nav-links a:hover,
  .nav-links a:active {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary);
  }
  
  /* 语言切换 */
  .lang-switcher {
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--gray-200);
  }
  
  /* 菜单关闭按钮 */
  .nav-close {
    display: block;
    position: absolute;
    top: 16px;
    right: 16px;
    width: 44px;
    height: 44px;
    padding: 10px;
    font-size: 24px;
    background: var(--gray-100);
    border: none;
    border-radius: 50%;
    cursor: pointer;
  }
  
  /* 下拉子菜单 */
  .has-submenu > .submenu {
    position: static;
    box-shadow: none;
    padding-left: 20px;
    display: none;
  }
  
  .has-submenu.open > .submenu {
    display: block;
  }
  
  /* 底部导航栏 */
  .bottom-nav, .mobile-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: #fff;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    z-index: 1000;
    -webkit-tap-highlight-color: transparent;
  }
  
  .bottom-nav a {
    flex: 1;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    color: var(--gray-500);
    font-size: 11px;
    min-height: 64px;
    padding: 8px;
  }
  
  .bottom-nav a span:first-child {
    font-size: 22px;
  }
  
  .bottom-nav a.active {
    color: var(--primary);
  }
  
  /* 添加底部导航占位 */
  .has-bottom-nav {
    padding-bottom: 80px;
  }
}

/* ===== 移动端手势支持 ===== */
@media (max-width: 768px) {
  /* 触摸高亮 */
  * {
    -webkit-tap-highlight-color: rgba(79, 134, 247, 0.15);
  }
  
  /* 禁用文本选择 */
  .no-select,
  .nav-links a,
  .bottom-nav a {
    -webkit-user-select: none;
    user-select: none;
  }
  
  /* 允许文本选择 */
  .allow-select,
  .form-group,
  p, h1, h2, h3, h4, h5, h6 {
    -webkit-user-select: text;
    user-select: text;
  }
  
  /* 弹性滚动 */
  .nav-links,
  .scrollable,
  .modal-body,
  .dropdown-menu,
  .submenu {
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
  }
  
  /* 触摸反馈 */
  .touch-feedback {
    transition: transform 0.1s ease, opacity 0.1s ease;
  }
  
  .touch-feedback:active {
    transform: scale(0.97);
    opacity: 0.9;
  }
  
  /* 滑动手势区域 */
  .swipe-container {
    overflow: hidden;
    position: relative;
  }
  
  .swipe-content {
    display: flex;
    transition: transform 0.3s ease;
    -webkit-overflow-scrolling: touch;
  }
  
  .swipe-item {
    flex: 0 0 100%;
  }
  
  /* 左右滑动指示器 */
  .swipe-hint-left::before,
  .swipe-hint-right::after {
    content: '';
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 60px;
    background: linear-gradient(to right, rgba(0,0,0,0.1), transparent);
    pointer-events: none;
    z-index: 10;
  }
  
  .swipe-hint-right::after {
    right: 0;
    background: linear-gradient(to left, rgba(0,0,0,0.1), transparent);
  }
  
  /* 长按菜单 */
  .long-press-menu {
    position: absolute;
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 8px 0;
    min-width: 160px;
    z-index: 1000;
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
  }
  
  .long-press-menu.show {
    opacity: 1;
    transform: scale(1);
    pointer-events: auto;
  }
  
  .long-press-menu a {
    display: block;
    padding: 12px 20px;
    min-height: 44px;
  }
  
  /* 拖拽排序 */
  .draggable {
    touch-action: none;
    cursor: grab;
  }
  
  .draggable:active {
    cursor: grabbing;
  }
  
  .drag-handle {
    touch-action: none;
    min-width: 44px;
    min-height: 44px;
  }
}

/* ===== 图片自适应优化 ===== */
@media (max-width: 768px) {
  /* 响应式图片 */
  img, .img {
    max-width: 100%;
    height: auto;
  }
  
  /* 图片占位 */
  .img-placeholder {
    background: var(--gray-100);
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* 头像 */
  .avatar, .user-avatar {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }
  
  .avatar-lg {
    width: 64px;
    height: 64px;
  }
  
  .avatar-sm {
    width: 36px;
    height: 36px;
  }
  
  /* 卡片图片 */
  .card-img {
    aspect-ratio: 16 / 9;
    object-fit: cover;
  }
  
  .card-img-square {
    aspect-ratio: 1 / 1;
  }
  
  /* 图片画廊 */
  .gallery-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
  
  .gallery-item {
    aspect-ratio: 1;
    overflow: hidden;
    border-radius: var(--radius);
  }
  
  .gallery-item:first-child {
    grid-column: span 2;
    aspect-ratio: 2 / 1;
  }
  
  /* 懒加载占位 */
  img[data-src] {
    background: linear-gradient(90deg, var(--gray-100) 25%, var(--gray-200) 50%, var(--gray-100) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
  }
  
  @keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }
}

/* ===== 滑动流畅优化 ===== */
@media (max-width: 768px) {
  /* 弹性滚动 */
  html {
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
  }
  
  body {
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-y: contain;
  }
  
  /* 滚动条样式 */
  ::-webkit-scrollbar {
    width: 4px;
    height: 4px;
  }
  
  ::-webkit-scrollbar-track {
    background: transparent;
  }
  
  ::-webkit-scrollbar-thumb {
    background: var(--gray-300);
    border-radius: 2px;
  }
  
  /* 惯性滚动 */
  .smooth-scroll {
    scroll-behavior: auto;
    -webkit-overflow-scrolling: touch;
    overflow-y: auto;
  }
  
  /* 吸顶元素 */
  .sticky-mobile {
    position: sticky;
    top: 0;
    z-index: 50;
    background: #fff;
  }
  
  /* 固定底部 */
  .fixed-bottom {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    padding: 12px 20px;
    background: #fff;
    border-top: 1px solid var(--gray-200);
  }
  
  /* 固定底部按钮 */
  .fixed-bottom .btn {
    width: 100%;
  }
  
  /* 模态框底部按钮 */
  .modal-footer-fixed {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
    margin: 0 -20px;
  }
  
  /* 滚动阴影指示 */
  .scroll-shadow-top {
    box-shadow: inset 0 4px 8px -4px rgba(0,0,0,0.1);
  }
  
  .scroll-shadow-bottom {
    box-shadow: inset 0 -4px 8px -4px rgba(0,0,0,0.1);
  }
  
  /* 加载更多 */
  .load-more-btn {
    min-height: 48px;
    width: 100%;
    padding: 14px 20px;
  }
}

/* ===== iPad 平板适配 (768px - 1024px) ===== */
@media (min-width: 769px) and (max-width: 1024px) {
  .container {
    padding: 0 40px;
  }
  
  /* 网格调整 */
  .grid-cards {
    grid-template-columns: repeat(2, 1fr);
  }
  
  .dest-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  /* 侧边栏 */
  .sidebar {
    width: 300px;
  }
}

/* ===== 小屏设备特殊适配 (iPhone SE 等) ===== */
@media (max-width: 375px) {
  /* 缩小间距 */
  .container {
    padding: 0 16px;
  }
  
  .hero h1 {
    font-size: 1.5rem;
  }
  
  .hero p {
    font-size: 0.95rem;
  }
  
  /* 卡片 */
  .card {
    padding: 16px;
  }
  
  .card-title {
    font-size: 1rem;
  }
  
  /* 按钮文字 */
  .btn {
    font-size: 14px;
    padding: 10px 16px;
  }
  
  /* 底部导航 */
  .bottom-nav a span:first-child {
    font-size: 20px;
  }
  
  .bottom-nav a {
    font-size: 10px;
  }
  
  /* 模态框 */
  .modal-content {
    margin: 10px;
  }
  
  /* Tab */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  
  .tab-btn {
    font-size: 13px;
    padding: 10px 12px;
  }
}

/* ===== 大屏手机横屏适配 ===== */
@media (max-height: 500px) and (orientation: landscape) {
  .hero {
    padding: 30px 0;
  }
  
  .hero h1 {
    font-size: 1.5rem;
    margin-bottom: 10px;
  }
  
  .hero-entries {
    margin-top: 20px;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .entry-card {
    min-width: 160px;
    padding: 14px 20px;
  }
  
  /* 隐藏底部导航 */
  .bottom-nav {
    height: 56px;
  }
  
  .bottom-nav a {
    min-height: 56px;
    font-size: 10px;
  }
  
  .has-bottom-nav {
    padding-bottom: 72px;
  }
}

/* ===== 触摸设备优化 ===== */
@media (hover: none) and (pointer: coarse) {
  /* 悬停效果改为点击效果 */
  [data-href]:hover {
    opacity: 1;
  }
  
  [data-href]:active {
    opacity: 0.8;
  }
  
  /* 卡片悬停 */
  .card:hover {
    transform: none;
  }
  
  /* 禁用图片放大预览 */
  img {
    -webkit-touch-callout: default;
  }
  
  /* 触摸友好的 focus */
  :focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
  }
  
  :focus:not(:focus-visible) {
    outline: none;
  }
}

/* ===== 安全区域适配 (iPhone X+) ===== */
@supports (padding: max(0px)) {
  .fixed-bottom {
    padding-left: max(20px, env(safe-area-inset-left));
    padding-right: max(20px, env(safe-area-inset-right));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  
  .bottom-nav {
    padding-bottom: max(0px, env(safe-area-inset-bottom));
  }
  
  .navbar {
    padding-top: max(0px, env(safe-area-inset-top));
  }
}

/* ===== 减少动画 (尊重用户设置) ===== */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ===== 深色模式适配 ===== */
@media (prefers-color-scheme: dark) {
  .img-placeholder {
    background: var(--gray-800);
  }
  
  img[data-src] {
    background: linear-gradient(90deg, var(--gray-800) 25%, var(--gray-700) 50%, var(--gray-800) 75%);
  }
}
