:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --danger: #ef4444;
  --danger-dark: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --bg: #f3f4f6;
  --card-bg: #ffffff;
  --text: #1f2937;
  --text-light: #6b7280;
  --border: #e5e7eb;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.1);
  --radius: 12px;
  --navbar-h: 56px;
  --tabbar-h: 60px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ===== 顶部导航栏（桌面） ===== */
.navbar {
  background: var(--card-bg);
  box-shadow: var(--shadow);
  padding: 0 24px;
  height: var(--navbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  font-size: 17px;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
}

.navbar-brand .icon {
  font-size: 22px;
  flex-shrink: 0;
}

.navbar-brand .brand-text {
  overflow: hidden;
  text-overflow: ellipsis;
}

.navbar-nav {
  display: flex;
  gap: 4px;
  align-items: center;
}

.nav-item {
  padding: 8px 16px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text-light);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s;
  border: none;
  background: none;
  text-decoration: none;
  white-space: nowrap;
}

.nav-item:hover {
  background: var(--bg);
  color: var(--text);
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
}

.nav-item.danger {
  color: var(--danger);
}

/* ===== 底部 Tab 栏（移动端） ===== */
.tabbar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card-bg);
  box-shadow: 0 -1px 8px rgba(0, 0, 0, 0.08);
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tabbar-items {
  display: flex;
  align-items: stretch;
  height: var(--tabbar-h);
}

.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--text-light);
  font-size: 11px;
  text-decoration: none;
  border: none;
  background: none;
  cursor: pointer;
  transition: color 0.2s;
  position: relative;
}

.tabbar-item .tab-icon {
  font-size: 20px;
  line-height: 1;
}

.tabbar-item.active {
  color: var(--primary);
  font-weight: 600;
}

.tabbar-item.active::before {
  content: "";
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 32px;
  height: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--primary);
}

.tabbar-item.danger {
  color: var(--danger);
}

/* 移动端顶部简化导航 */
.mobile-topbar {
  display: none;
  background: var(--card-bg);
  box-shadow: var(--shadow);
  height: var(--navbar-h);
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.mobile-topbar .topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.mobile-topbar .topbar-logout {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 13px;
  cursor: pointer;
  padding: 6px 10px;
}

/* ===== 容器 ===== */
.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px;
}

/* ===== 卡片 ===== */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.card-title {
  font-size: 18px;
  font-weight: 600;
}

/* ===== 统计卡片 ===== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}

.stat-card .stat-value {
  font-size: 32px;
  font-weight: 700;
  color: var(--primary);
  line-height: 1.2;
}

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

.stat-card.danger .stat-value { color: var(--danger); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.warning .stat-value { color: var(--warning); }

/* ===== 按钮 ===== */
.btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.form-label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text);
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 16px; /* 16px 防止 iOS 缩放 */
  font-family: inherit;
  transition: border-color 0.2s;
  background: #fff;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary);
}

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

/* ===== 表格（桌面） ===== */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  text-align: left;
  padding: 12px;
  font-size: 13px;
  color: var(--text-light);
  font-weight: 600;
  border-bottom: 2px solid var(--border);
}

.table td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}

.table tr:hover { background: var(--bg); }

/* ===== 移动端卡片列表（替代表格） ===== */
.mobile-list {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.mobile-list-item {
  background: var(--bg);
  border-radius: 10px;
  padding: 14px 16px;
}

.mobile-list-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
}

.mobile-list-row .ml-label {
  color: var(--text-light);
  font-size: 13px;
  flex-shrink: 0;
}

.mobile-list-row .ml-value {
  font-size: 14px;
  font-weight: 500;
  text-align: right;
  word-break: break-word;
}

.mobile-list-row .ml-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  justify-content: flex-end;
}

/* ===== 徽章 ===== */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-active { background: #fef3c7; color: #92400e; }
.badge-completed { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* ===== 模态框 ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title { font-size: 18px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text-light);
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.modal-close:hover { background: var(--bg); }
.modal-body { padding: 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ===== 空状态 ===== */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-light);
}

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

/* ===== Toast ===== */
.toast {
  position: fixed;
  top: 72px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--card-bg);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 12px 20px;
  z-index: 300;
  border-left: 4px solid var(--success);
  font-size: 14px;
  animation: toastIn 0.3s ease;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.error { border-left-color: var(--danger); }

@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-10px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== 角色选择页 ===== */
.role-select {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.role-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 24px;
  max-width: 640px;
  width: 100%;
}

.role-card {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 40px 32px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  border: 2px solid transparent;
}

.role-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
}

.role-card .role-icon { font-size: 56px; margin-bottom: 16px; }
.role-card .role-title { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.role-card .role-desc { color: var(--text-light); font-size: 14px; }

/* ===== 登录表单 ===== */
.login-box { max-width: 380px; margin: 0 auto; }
.login-box h2 { text-align: center; margin-bottom: 24px; }

/* ===== 移动端响应式 ===== */
@media (max-width: 768px) {
  /* 隐藏桌面导航，显示移动端导航 */
  .navbar { display: none; }
  .mobile-topbar { display: flex; }
  .tabbar { display: block; }

  /* 内容区底部留出 tabbar 空间 */
  .container {
    padding: 16px 12px calc(var(--tabbar-h) + 20px);
  }

  /* 卡片缩小内边距 */
  .card { padding: 16px; }

  .card-header {
    flex-wrap: wrap;
    margin-bottom: 12px;
  }

  .card-title { font-size: 16px; }

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

  .stat-card { padding: 14px 8px; }
  .stat-card .stat-value { font-size: 26px; }
  .stat-card .stat-label { font-size: 12px; }

  /* 隐藏桌面表格，显示移动端列表 */
  .table-wrapper-desktop { display: none; }
  .mobile-list { display: flex; }

  /* 按钮全宽 */
  .btn-full-mobile {
    width: 100%;
    justify-content: center;
  }

  /* 模态框底部按钮自适应 */
  .modal-footer {
    flex-direction: column-reverse;
  }
  .modal-footer .btn {
    width: 100%;
    justify-content: center;
  }

  /* 模态框全屏化 */
  .modal-overlay { padding: 0; }
  .modal {
    border-radius: 0;
    max-width: 100%;
    max-height: 100vh;
    min-height: 100vh;
  }

  /* 角色选择页 */
  .role-cards {
    grid-template-columns: 1fr;
    gap: 16px;
  }
  .role-card { padding: 28px 20px; }
  .role-card .role-icon { font-size: 44px; }

  /* select 在移动端可换行 */
  .card-header select {
    width: 100%;
    margin-top: 8px;
  }
  .card-header {
    flex-direction: column;
    align-items: stretch;
  }
}

/* 超小屏幕 */
@media (max-width: 380px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .container { padding: 12px 10px calc(var(--tabbar-h) + 16px); }
  .card { padding: 14px 12px; }
  .stat-card .stat-value { font-size: 22px; }
}
