/**
 * 响应式设计 - 桌面端和H5通用
 * 移动优先设计策略
 */

/* ========== 基础重置 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -ms-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  line-height: 1.6;
  color: var(--text-primary);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* ========== 移动优先容器 ========== */
.container {
  width: 100%;
  max-width: 100%;
  padding: 16px;
  margin: 0 auto;
}

/* 平板 */
@media (min-width: 768px) {
  .container {
    max-width: 720px;
    padding: 24px;
  }
}

/* 桌面 */
@media (min-width: 1024px) {
  .container {
    max-width: 960px;
    padding: 32px;
  }
}

/* 大屏 */
@media (min-width: 1280px) {
  .container {
    max-width: 1200px;
  }
}

/* ========== 响应式卡片 ========== */
.card {
  background: var(--bg-primary);
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  margin-bottom: 16px;
  transition: all 0.3s ease;
}

@media (min-width: 768px) {
  .card {
    border-radius: 16px;
    padding: 28px;
    margin-bottom: 24px;
  }
}

@media (min-width: 1024px) {
  .card {
    padding: 32px;
  }
}

.card:active {
  transform: scale(0.98);
}

@media (min-width: 768px) {
  .card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-xl);
  }
  
  .card:active {
    transform: translateY(0);
  }
}

/* ========== 响应式按钮 ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px 20px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  text-align: center;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

@media (min-width: 768px) {
  .btn {
    padding: 12px 24px;
    font-size: 15px;
  }
}

.btn:active {
  transform: scale(0.96);
}

@media (min-width: 768px) {
  .btn:hover {
    transform: translateY(-2px);
  }
  
  .btn:active {
    transform: translateY(0);
  }
}

.btn-small {
  padding: 10px 16px;
  font-size: 14px;
}

@media (min-width: 768px) {
  .btn-small {
    padding: 8px 16px;
    width: auto;
  }
}

/* ========== 响应式表单 ========== */
.form-group {
  margin-bottom: 16px;
}

@media (min-width: 768px) {
  .form-group {
    margin-bottom: 20px;
  }
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 14px;
}

@media (min-width: 768px) {
  .form-group label {
    font-size: 15px;
  }
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border-color);
  border-radius: 8px;
  font-size: 16px; /* 防止iOS自动缩放 */
  font-family: inherit;
  transition: all 0.2s ease;
  background: var(--bg-primary);
  color: var(--text-primary);
  -webkit-appearance: none;
  appearance: none;
}

@media (min-width: 768px) {
  .form-group input,
  .form-group textarea,
  .form-group select {
    font-size: 15px;
  }
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

/* ========== 响应式网格 ========== */
.grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

@media (min-width: 640px) {
  .grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 768px) {
  .grid {
    gap: 20px;
  }
  
  .grid-3 {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .grid {
    gap: 24px;
  }
  
  .grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
  
  .grid-4 {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* ========== 响应式文字 ========== */
h1 {
  font-size: 28px;
  font-weight: 700;
  line-height: 1.2;
  margin-bottom: 16px;
}

@media (min-width: 768px) {
  h1 {
    font-size: 32px;
    margin-bottom: 20px;
  }
}

@media (min-width: 1024px) {
  h1 {
    font-size: 36px;
    margin-bottom: 24px;
  }
}

h2 {
  font-size: 22px;
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 12px;
}

@media (min-width: 768px) {
  h2 {
    font-size: 24px;
    margin-bottom: 16px;
  }
}

@media (min-width: 1024px) {
  h2 {
    font-size: 28px;
    margin-bottom: 20px;
  }
}

h3 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
}

@media (min-width: 768px) {
  h3 {
    font-size: 20px;
  }
}

p {
  font-size: 15px;
  line-height: 1.6;
  margin-bottom: 12px;
}

@media (min-width: 768px) {
  p {
    font-size: 16px;
  }
}

/* ========== 响应式导航 ========== */
.admin-header {
  background: var(--bg-primary);
  padding: 16px 20px;
  border-radius: 12px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
}

@media (min-width: 768px) {
  .admin-header {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 20px 28px;
    margin-bottom: 24px;
  }
}

@media (min-width: 1024px) {
  .admin-header {
    padding: 24px 32px;
  }
}

.admin-header h1 {
  font-size: 20px;
  margin-bottom: 0;
}

@media (min-width: 768px) {
  .admin-header h1 {
    font-size: 24px;
  }
}

.user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* ========== 响应式标签页 ========== */
.admin-nav {
  background: var(--bg-primary);
  padding: 0;
  border-radius: 12px;
  margin-bottom: 16px;
  display: flex;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border-color);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

@media (min-width: 768px) {
  .admin-nav {
    padding: 0 20px;
    margin-bottom: 24px;
  }
}

.admin-nav::-webkit-scrollbar {
  height: 4px;
}

.admin-nav::-webkit-scrollbar-track {
  background: transparent;
}

.admin-nav::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.nav-btn {
  padding: 14px 20px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: all 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

@media (min-width: 768px) {
  .nav-btn {
    padding: 16px 24px;
    font-size: 15px;
  }
}

.nav-btn:active {
  background: var(--bg-secondary);
}

@media (min-width: 768px) {
  .nav-btn:hover {
    color: var(--primary-color);
    background: var(--bg-secondary);
  }
}

.nav-btn.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

/* ========== 响应式列表 ========== */
.qrcode-item,
.user-item {
  border: 2px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: all 0.3s ease;
  background: var(--bg-primary);
  margin-bottom: 12px;
}

@media (min-width: 768px) {
  .qrcode-item,
  .user-item {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    margin-bottom: 16px;
  }
}

@media (min-width: 1024px) {
  .qrcode-item,
  .user-item {
    padding: 24px;
  }
}

.qrcode-item:active,
.user-item:active {
  transform: scale(0.98);
}

@media (min-width: 768px) {
  .qrcode-item:hover,
  .user-item:hover {
    border-color: var(--primary-light);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
  }
}

.qrcode-info,
.user-item-info {
  flex: 1;
}

.qrcode-info h3,
.user-item-info h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

@media (min-width: 768px) {
  .qrcode-info h3,
  .user-item-info h3 {
    font-size: 18px;
  }
}

.qrcode-info p,
.user-item-info p {
  font-size: 14px;
  margin: 4px 0;
}

.user-item-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

@media (min-width: 768px) {
  .user-item-actions {
    flex-direction: row;
    width: auto;
  }
}

/* ========== 响应式模态框 ========== */
.modal {
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
}

@media (min-width: 768px) {
  .modal {
    align-items: center;
    padding: 20px;
  }
}

.modal-content {
  background: var(--bg-primary);
  padding: 24px;
  border-radius: 20px 20px 0 0;
  max-width: 100%;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: var(--shadow-2xl);
  animation: slideUp 0.3s ease;
  border: 1px solid var(--border-color);
}

@media (min-width: 768px) {
  .modal-content {
    border-radius: 16px;
    max-width: 600px;
    width: 90%;
    max-height: 85vh;
    padding: 32px;
  }
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

@media (min-width: 768px) {
  @keyframes slideUp {
    from {
      transform: translateY(20px);
      opacity: 0;
    }
    to {
      transform: translateY(0);
      opacity: 1;
    }
  }
}

/* ========== 响应式表格 ========== */
.table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -16px;
  padding: 0 16px;
}

@media (min-width: 768px) {
  .table-container {
    margin: 0;
    padding: 0;
  }
}

table {
  width: 100%;
  min-width: 600px;
  border-collapse: collapse;
}

@media (min-width: 768px) {
  table {
    min-width: 100%;
  }
}

th, td {
  padding: 12px 8px;
  text-align: left;
  font-size: 14px;
}

@media (min-width: 768px) {
  th, td {
    padding: 16px 12px;
    font-size: 15px;
  }
}

/* ========== 触摸优化 ========== */
@media (max-width: 767px) {
  /* 增大触摸目标 */
  button,
  a,
  input[type="checkbox"],
  input[type="radio"] {
    min-height: 44px;
    min-width: 44px;
  }
  
  /* 防止双击缩放 */
  * {
    touch-action: manipulation;
  }
  
  /* 优化滚动 */
  .modal-content,
  .admin-nav {
    -webkit-overflow-scrolling: touch;
  }
}

/* ========== 状态徽章响应式 ========== */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

@media (min-width: 768px) {
  .status-badge {
    padding: 6px 14px;
    font-size: 13px;
  }
}

/* ========== 响应式间距 ========== */
.button-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (min-width: 768px) {
  .button-group {
    gap: 16px;
  }
}

.link-group {
  text-align: center;
  margin-top: 16px;
  font-size: 14px;
}

@media (min-width: 768px) {
  .link-group {
    margin-top: 20px;
    font-size: 15px;
  }
}

/* ========== 隐藏/显示工具类 ========== */
.mobile-only {
  display: block;
}

@media (min-width: 768px) {
  .mobile-only {
    display: none;
  }
}

.desktop-only {
  display: none;
}

@media (min-width: 768px) {
  .desktop-only {
    display: block;
  }
}

/* ========== 安全区域适配（iPhone X等） ========== */
@supports (padding: max(0px)) {
  body {
    padding-left: max(0px, env(safe-area-inset-left));
    padding-right: max(0px, env(safe-area-inset-right));
  }
  
  .modal-content {
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
}

/* ========== 横屏优化 ========== */
@media (max-height: 500px) and (orientation: landscape) {
  .modal-content {
    max-height: 95vh;
  }
  
  .card {
    padding: 16px;
  }
}

/* ========== 打印样式 ========== */
@media print {
  body {
    background: white;
  }
  
  .btn,
  .admin-nav,
  .user-info {
    display: none;
  }
  
  .card {
    box-shadow: none;
    border: 1px solid #ddd;
  }
}
