/* ==================== Reset & Variables ==================== */
:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --success: #10b981;
  --success-light: #ecfdf5;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --white: #ffffff;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
  --radius: 8px;
  --radius-sm: 4px;
  --radius-lg: 12px;
  --sidebar-width: 220px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  font-size: 14px;
  color: var(--gray-800);
  background: var(--gray-50);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ==================== Layout ==================== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width);
  background: var(--gray-900);
  color: var(--white);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform 0.3s ease;
}

/* 移动端汉堡菜单按钮 */
.menu-toggle {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 200;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: var(--gray-900);
  color: var(--white);
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  align-items: center;
  justify-content: center;
}

/* 移动端遮罩 */
.sidebar-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

.sidebar-brand {
  padding: 20px;
  font-size: 18px;
  font-weight: 700;
  border-bottom: 1px solid var(--gray-700);
  display: flex;
  align-items: center;
  gap: 8px;
}

.sidebar-nav { flex: 1; padding: 12px 0; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--gray-300);
  text-decoration: none;
  transition: all 0.2s;
  font-size: 14px;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
  color: var(--white);
  background: rgba(255,255,255,0.1);
}

.sidebar-nav a .icon { width: 20px; text-align: center; font-size: 16px; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-700);
}

.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px;
  transition: margin-left 0.3s ease;
}

.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 600;
  color: var(--gray-900);
}

/* ==================== Login Page ==================== */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.login-box {
  background: var(--white);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 380px;
  box-shadow: var(--shadow-lg);
}

.login-box h1 {
  text-align: center;
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--gray-900);
}

.login-box .subtitle {
  text-align: center;
  color: var(--gray-500);
  margin-bottom: 32px;
}

/* ==================== Form ==================== */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  margin-bottom: 6px;
  font-weight: 500;
  color: var(--gray-700);
  font-size: 13px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius-sm);
  font-size: 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
  background: var(--white);
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-inline {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* ==================== Buttons ==================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { text-decoration: none; }

.btn-primary { background: var(--primary); color: var(--white); }
.btn-primary:hover { background: var(--primary-hover); }

.btn-success { background: var(--success); color: var(--white); }
.btn-success:hover { background: #059669; }

.btn-danger { background: var(--danger); color: var(--white); }
.btn-danger:hover { background: #dc2626; }

.btn-outline {
  background: var(--white);
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-outline:hover { background: var(--gray-50); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-block { width: 100%; }

/* ==================== Card ==================== */
.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--gray-200);
  margin-bottom: 16px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
}

.card-body { padding: 20px; }

/* ==================== Table ==================== */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

table th {
  padding: 10px 12px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  background: var(--gray-50);
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}

table td {
  padding: 12px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

table tr:hover td { background: var(--gray-50); }

/* ==================== Stats Grid ==================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--white);
  border-radius: var(--radius);
  padding: 20px;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
}

.stat-card .stat-label {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 4px;
}

.stat-card.primary { border-left: 4px solid var(--primary); }
.stat-card.success { border-left: 4px solid var(--success); }
.stat-card.warning { border-left: 4px solid var(--warning); }

/* ==================== Modal ==================== */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 600px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 16px;
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 1;
}

.modal-body { padding: 20px; }

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--gray-200);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  position: sticky;
  bottom: 0;
  background: var(--white);
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-400);
  padding: 4px;
  line-height: 1;
}
.modal-close:hover { color: var(--gray-700); }

/* ==================== Badge / Status ==================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-primary { background: var(--primary-light); color: var(--primary); }

/* ==================== Toast ==================== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 2000;
  padding: 12px 20px;
  border-radius: var(--radius);
  color: var(--white);
  font-size: 14px;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease;
  max-width: 400px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ==================== User Info ==================== */
.user-info {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--gray-300);
  font-size: 13px;
}

.user-info .avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
}

/* ==================== Empty State ==================== */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--gray-400);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { font-size: 14px; }

/* ==================== Search Bar ==================== */
.search-bar {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-bar .form-control { width: 240px; }

/* ==================== Toggle Switch ==================== */
.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  display: inline-block;
}

.toggle input { opacity: 0; width: 0; height: 0; }

.toggle .slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--gray-300);
  border-radius: 22px;
  transition: 0.2s;
}

.toggle .slider:before {
  content: "";
  position: absolute;
  height: 16px; width: 16px;
  left: 3px; bottom: 3px;
  background: var(--white);
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .slider { background: var(--primary); }
.toggle input:checked + .slider:before { transform: translateX(18px); }

/* ==================== Action Buttons in Table ==================== */
.actions { display: flex; gap: 4px; }

/* ==================== Mobile Responsive ==================== */

/* 平板及以下 (≤1024px) */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 200px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .search-bar .form-control {
    width: 180px;
  }
}

/* 手机横屏及以下 (≤768px) */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 0px;
  }

  /* --- 侧边栏改为抽屉式 --- */
  .sidebar {
    transform: translateX(-100%);
    width: 260px;
    box-shadow: var(--shadow-lg);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.active {
    display: block;
  }

  .menu-toggle {
    display: flex;
  }

  .main-content {
    margin-left: 0 !important;
    padding: 16px;
    padding-top: 56px; /* 给汉堡菜单留空间 */
  }

  /* --- 登录页 --- */
  .login-page {
    padding: 20px;
    align-items: flex-start;
    padding-top: 60px;
  }

  .login-box {
    width: 100%;
    max-width: 400px;
    padding: 32px 24px;
    margin: 0;
  }

  .login-box h1 {
    font-size: 22px;
  }

  .login-box .subtitle {
    font-size: 13px;
    margin-bottom: 24px;
  }

  /* --- 页面标题 --- */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .page-header h1 {
    font-size: 20px;
  }

  /* --- 统计卡片 --- */
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card {
    padding: 14px;
  }

  .stat-card .stat-value {
    font-size: 22px;
  }

  .stat-card .stat-label {
    font-size: 12px;
  }

  /* --- 表格 --- */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -16px;
    padding: 0 16px;
  }

  table th,
  table td {
    padding: 8px 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  /* --- 卡片在小屏幕上全宽 --- */
  .card {
    margin-left: -8px;
    margin-right: -8px;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }

  .card-header {
    padding: 12px 16px;
  }

  .card-body {
    padding: 16px;
  }

  /* --- 弹窗全屏 --- */
  .modal-overlay {
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-width: 100%;
    max-height: 90vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }

  .modal-header {
    font-size: 15px;
    padding: 14px 16px;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px;
  }

  /* --- 表单 --- */
  .form-row {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .form-group {
    margin-bottom: 12px;
  }

  .form-control {
    font-size: 16px; /* 防止iOS缩放 */
    padding: 10px 12px;
  }

  .form-group label {
    font-size: 13px;
  }

  /* --- 按钮 --- */
  .btn {
    padding: 10px 16px;
    font-size: 14px;
    min-height: 44px; /* 触摸友好 */
  }

  .btn-sm {
    padding: 6px 12px;
    font-size: 13px;
    min-height: 36px;
  }

  .btn-lg {
    padding: 14px 24px;
    font-size: 16px;
  }

  /* --- 搜索栏 --- */
  .search-bar {
    flex-wrap: wrap;
    width: 100%;
  }

  .search-bar .form-control {
    flex: 1;
    min-width: 0;
  }

  /* --- Toast位置调整 --- */
  .toast {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
    text-align: center;
    font-size: 13px;
  }

  /* --- 操作按钮 --- */
  .actions {
    flex-wrap: wrap;
    gap: 4px;
  }
}

/* 小屏手机 (≤480px) */
@media (max-width: 480px) {
  /* --- 统计卡片单列 --- */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  /* --- 登录页 --- */
  .login-page {
    padding: 12px;
    padding-top: 40px;
  }

  .login-box {
    padding: 28px 18px;
  }

  .login-box h1 img {
    width: 48px !important;
    height: 48px !important;
  }

  .login-box h1 {
    font-size: 20px;
  }

  /* --- 页面标题 --- */
  .page-header h1 {
    font-size: 18px;
  }

  /* --- 弹窗占用更多高度 --- */
  .modal {
    max-height: 95vh;
  }

  /* --- 用户信息简化 --- */
  .user-info {
    font-size: 12px;
  }
}

