/**
 * 龙虾教培助手 - 移动端优化样式
 * 🦞 Mobile Optimization Styles
 * 
 * 设计理念：触摸优先、单手操作、内容优先
 */

/* ============================================
   1. 全局移动端优化
   ============================================ */

@media (max-width: 768px) {
  /* 增大触摸目标 */
  .btn, button, a.btn {
    min-height: 44px; /* iOS推荐最小触摸区域 */
    padding: 12px 16px;
    font-size: 16px; /* 防止iOS自动缩放 */
  }

  .btn-sm {
    min-height: 36px;
    padding: 8px 12px;
    font-size: 14px;
  }

  /* 表单输入优化 */
  input, textarea, select {
    font-size: 16px !important; /* 防止iOS缩放 */
    min-height: 44px;
    padding: 12px !important;
  }

  /* 卡片间距优化 */
  .card {
    margin-bottom: 12px;
    border-radius: 12px;
  }

  /* 标题层级优化 */
  h1 { font-size: 24px; }
  h2 { font-size: 20px; }
  h3 { font-size: 18px; }
  h4 { font-size: 16px; }

  /* 减少内边距，节省空间 */
  .content-wrapper {
    padding: 12px;
  }

  .header {
    padding: 12px 16px;
  }
}

/* ============================================
   2. 移动端底部导航栏（新增）
   ============================================ */

.mobile-tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.08);
  z-index: 1000;
  border-top: 1px solid var(--border-light);
}

.mobile-tab-bar-items {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 100%;
  padding: 0 8px;
  padding-bottom: env(safe-area-inset-bottom); /* iPhone X安全区 */
}

.mobile-tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 4px;
  color: var(--text-secondary);
  transition: all 0.2s;
  text-decoration: none;
  font-size: 12px;
}

.mobile-tab-item.active {
  color: var(--color-primary-600);
}

.mobile-tab-item .icon {
  font-size: 24px;
  line-height: 1;
}

.mobile-tab-item .label {
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

@media (max-width: 768px) {
  .mobile-tab-bar {
    display: block;
  }

  /* 为底部导航留出空间 */
  body {
    padding-bottom: 60px;
  }

  /* 隐藏桌面端侧边栏 */
  .sidebar {
    display: none;
  }

  .main-content {
    margin-left: 0 !important;
  }
}

/* ============================================
   3. 移动端表格优化
   ============================================ */

@media (max-width: 768px) {
  /* 将表格转换为卡片式布局 */
  .table-responsive {
    overflow-x: visible;
  }

  table.data-table {
    display: block;
  }

  table.data-table thead {
    display: none; /* 隐藏表头 */
  }

  table.data-table tbody {
    display: block;
  }

  table.data-table tr {
    display: block;
    margin-bottom: 12px;
    border: 1px solid var(--border-default);
    border-radius: 12px;
    padding: 12px;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  }

  table.data-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border: none;
    border-bottom: 1px solid var(--border-light);
  }

  table.data-table td:last-child {
    border-bottom: none;
  }

  /* 在每行前添加标签 */
  table.data-table td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--text-secondary);
    margin-right: 12px;
    flex-shrink: 0;
  }

  table.data-table td:last-child {
    justify-content: flex-end;
  }
}

/* ============================================
   4. 移动端网格优化
   ============================================ */

@media (max-width: 768px) {
  .grid-cols-2,
  .grid-cols-3,
  .grid-cols-4 {
    grid-template-columns: 1fr !important;
    gap: 12px;
  }

  /* 统计卡片横向滚动 */
  .stats-grid {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
    gap: 12px;
    padding-bottom: 8px;
  }

  .stat-card {
    min-width: 140px;
    scroll-snap-align: start;
    flex-shrink: 0;
  }
}

/* ============================================
   5. 移动端表单优化
   ============================================ */

@media (max-width: 768px) {
  .form-group {
    margin-bottom: 16px;
  }

  .form-label {
    display: block;
    margin-bottom: 6px;
    font-size: 14px;
    font-weight: 500;
  }

  .form-input,
  .form-select,
  .form-textarea {
    width: 100%;
    border-radius: 10px;
    border: 1.5px solid var(--border-default);
    transition: all 0.2s;
  }

  .form-input:focus,
  .form-select:focus,
  .form-textarea:focus {
    border-color: var(--color-primary-500);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
  }

  /* 单选/复选框增大 */
  input[type="checkbox"],
  input[type="radio"] {
    width: 20px;
    height: 20px;
    margin-right: 8px;
  }

  /* 下拉选择器优化 */
  select {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%236b7280'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
  }
}

/* ============================================
   6. 移动端模态框优化
   ============================================ */

@media (max-width: 768px) {
  .modal {
    align-items: flex-end; /* 从底部弹出 */
  }

  .modal-content {
    width: 100%;
    max-width: 100%;
    max-height: 85vh;
    margin: 0;
    border-radius: 20px 20px 0 0;
    animation: slideUp 0.3s ease-out;
  }

  @keyframes slideUp {
    from {
      transform: translateY(100%);
    }
    to {
      transform: translateY(0);
    }
  }

  .modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
  }

  .modal-body {
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-light);
  }
}

/* ============================================
   7. 移动端列表优化
   ============================================ */

@media (max-width: 768px) {
  .list-item {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-light);
  }

  .list-item:active {
    background: var(--bg-hover);
  }

  .list-item-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
  }

  .list-item-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
  }

  .list-item-action {
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
}

/* ============================================
   8. 移动端图片优化
   ============================================ */

@media (max-width: 768px) {
  img {
    max-width: 100%;
    height: auto;
  }

  .image-gallery {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .image-upload-preview {
    width: 100%;
    aspect-ratio: 1;
  }
}

/* ============================================
   9. 移动端加载状态优化
   ============================================ */

@media (max-width: 768px) {
  .loading-spinner {
    width: 40px;
    height: 40px;
  }

  .skeleton {
    border-radius: 8px;
  }

  .skeleton-text {
    height: 16px;
    margin-bottom: 8px;
  }
}

/* ============================================
   10. 移动端特殊场景优化
   ============================================ */

/* AI点评页面 */
@media (max-width: 768px) {
  .comment-scenario-tags {
    flex-wrap: wrap;
    gap: 8px;
  }

  .scenario-tag {
    padding: 8px 14px;
    font-size: 14px;
  }

  .performance-tags {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }

  .performance-tag {
    padding: 10px;
    font-size: 14px;
    text-align: center;
  }
}

/* 学员管理页面 */
@media (max-width: 768px) {
  .student-card {
    padding: 16px;
  }

  .student-name {
    font-size: 18px;
    margin-bottom: 8px;
  }

  .student-info {
    font-size: 14px;
    color: var(--text-secondary);
  }

  .student-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
  }

  .student-actions .btn {
    flex: 1;
  }
}

/* 课表页面 */
@media (max-width: 768px) {
  .schedule-grid {
    display: flex;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch;
  }

  .schedule-day {
    min-width: 280px;
    scroll-snap-align: start;
    flex-shrink: 0;
  }
}

/* 智能体市场 */
@media (max-width: 768px) {
  .agent-card {
    padding: 16px;
  }

  .agent-avatar {
    width: 48px;
    height: 48px;
    font-size: 24px;
  }

  .agent-name {
    font-size: 16px;
  }

  .agent-description {
    font-size: 14px;
    line-height: 1.5;
  }
}

/* ============================================
   11. 移动端手势优化
   ============================================ */

@media (max-width: 768px) {
  /* 禁用双击缩放 */
  * {
    touch-action: manipulation;
  }

  /* 长按菜单优化 */
  .context-menu-trigger:active {
    background: var(--bg-hover);
  }

  /* 滑动删除提示 */
  .swipe-action {
    position: relative;
    overflow: hidden;
  }

  .swipe-action-content {
    transition: transform 0.2s;
  }

  .swipe-action-buttons {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    display: flex;
    transform: translateX(100%);
  }
}

/* ============================================
   12. 深色模式支持（可选）
   ============================================ */

@media (prefers-color-scheme: dark) and (max-width: 768px) {
  :root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --border-light: #334155;
    --border-default: #475569;
  }

  .mobile-tab-bar {
    background: rgba(15, 23, 42, 0.98);
  }
}

/* ============================================
   13. 横屏模式优化
   ============================================ */

@media (max-width: 768px) and (orientation: landscape) {
  .mobile-tab-bar {
    height: 50px;
  }

  body {
    padding-bottom: 50px;
  }

  .modal-content {
    max-height: 90vh;
  }
}

/* ============================================
   14. iPhone安全区适配
   ============================================ */

@supports (padding: max(0px)) {
  @media (max-width: 768px) {
    .mobile-tab-bar-items {
      padding-bottom: max(8px, env(safe-area-inset-bottom));
    }

    body {
      padding-bottom: max(60px, calc(60px + env(safe-area-inset-bottom)));
    }
  }
}
