/* ============================================================
   二工区花名册管理系统 — 样式
   配色：工程蓝主色 + 警示橙辅色，浅灰底、白卡片
   布局：响应式（桌面表格 / 移动端卡片）
   ============================================================ */
:root {
  --c-primary: #1d4ed8;      /* 工程蓝 */
  --c-primary-d: #1e40af;
  --c-accent: #f59e0b;       /* 警示橙 */
  --c-danger: #dc2626;
  --c-ok: #16a34a;
  --c-bg: #f1f5f9;
  --c-card: #ffffff;
  --c-border: #e2e8f0;
  --c-text: #0f172a;
  --c-muted: #64748b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
  --shadow-lg: 0 10px 30px rgba(15, 23, 42, .18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
[hidden] { display: none !important; }   /* 修复：author display 覆盖 hidden 的问题 */
body {
  font-family: var(--font);
  color: var(--c-text);
  background: var(--c-bg);
  font-size: 14px;
  line-height: 1.5;
}

/* ===== 导航栏 ===== */
.navbar {
  display: flex; align-items: center; gap: 20px;
  padding: 12px 24px;
  background: linear-gradient(120deg, var(--c-primary), var(--c-primary-d));
  color: #fff;
  position: sticky; top: 0; z-index: 20;
  box-shadow: var(--shadow);
}
.navbar__brand { display: flex; align-items: center; gap: 12px; }
.navbar__logo { font-size: 26px; }
.navbar__title { font-weight: 700; font-size: 16px; letter-spacing: .5px; }
.navbar__subtitle { font-size: 12px; opacity: .8; }
.navbar__nav { display: flex; gap: 6px; margin-left: 8px; }
.nav-item {
  background: transparent; border: none; color: #dbeafe;
  padding: 8px 14px; border-radius: 8px; cursor: pointer; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-item--active { background: #fff; color: var(--c-primary); font-weight: 600; }
.navbar__status {
  margin-left: auto; display: flex; align-items: center; gap: 8px;
  font-size: 12px; background: rgba(255,255,255,.14); padding: 6px 12px; border-radius: 999px;
}
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot--ok { background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.3); }

/* ===== 容器 ===== */
.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 60px; }

/* ===== 统计卡片 ===== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card {
  background: var(--c-card); border: 1px solid var(--c-border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px;
}
.stat-card__num { font-size: 28px; font-weight: 800; color: var(--c-primary); }
.stat-card__label { font-size: 13px; color: var(--c-muted); }
.stat-card--accent .stat-card__num { color: var(--c-accent); }
.stat-card--danger .stat-card__num { color: var(--c-danger); }

/* ===== 工具栏 ===== */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center;
  background: var(--c-card); border: 1px solid var(--c-border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px; box-shadow: var(--shadow);
}
.toolbar__search { flex: 1 1 280px; }
.toolbar__search input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--c-border);
  border-radius: 8px; font-size: 14px; outline: none;
}
.toolbar__search input:focus { border-color: var(--c-primary); }
.toolbar__filters { display: flex; gap: 10px; }
.toolbar__filters select {
  padding: 10px 12px; border: 1px solid var(--c-border); border-radius: 8px;
  font-size: 14px; background: #fff; outline: none; cursor: pointer;
}
.toolbar__actions { display: flex; gap: 10px; margin-left: auto; }

/* ===== 按钮 ===== */
.btn {
  border: none; border-radius: 8px; padding: 10px 16px; font-size: 14px;
  cursor: pointer; font-weight: 600; transition: filter .15s, background .15s;
}
.btn--primary { background: var(--c-primary); color: #fff; }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost { background: #f1f5f9; color: var(--c-text); }
.btn--ghost:hover { background: #e2e8f0; }
.btn--danger { background: var(--c-danger); color: #fff; }
.btn--sm { padding: 6px 10px; font-size: 13px; }

/* ===== 表格 ===== */
.table-wrap {
  background: var(--c-card); border: 1px solid var(--c-border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.roster-table { width: 100%; border-collapse: collapse; }
.roster-table th, .roster-table td {
  padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--c-border); white-space: nowrap;
}
.roster-table thead th {
  background: #f8fafc; color: var(--c-muted); font-weight: 600; font-size: 13px;
  position: sticky; top: 0;
}
.roster-table tbody tr:hover { background: #f8fafc; }
.roster-table td .tag {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.tag--in { background: #dcfce7; color: #15803d; }
.tag--out { background: #fee2e2; color: #b91c1c; }
.col-ops { text-align: right; }
.row-ops { display: flex; gap: 8px; justify-content: flex-end; }
.empty { padding: 40px; text-align: center; color: var(--c-muted); }

/* ===== 统计视图 ===== */
.stats-view { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.panel {
  background: var(--c-card); border: 1px solid var(--c-border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 12px; font-size: 15px; }
.bar { height: 10px; border-radius: 6px; background: #e2e8f0; overflow: hidden; margin: 8px 0; }
.bar__fill { height: 100%; background: var(--c-primary); }
.kv { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px dashed var(--c-border); }
.kv:last-child { border-bottom: none; }

.about-view { background: var(--c-card); border: 1px solid var(--c-border); border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow); }
.about-view h2 { margin-top: 0; }
.about-view code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; }

/* ===== 弹窗 ===== */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.5); }
.modal__panel {
  position: relative; background: #fff; border-radius: var(--radius); width: 100%; max-width: 640px;
  max-height: 90vh; overflow: auto; box-shadow: var(--shadow-lg);
}
.modal__head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--c-border); }
.modal__head h3 { margin: 0; font-size: 16px; }
.modal__close { border: none; background: transparent; font-size: 24px; cursor: pointer; color: var(--c-muted); line-height: 1; }
.form { padding: 20px; }
.form__grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--c-muted); }
.field input, .field select {
  padding: 9px 10px; border: 1px solid var(--c-border); border-radius: 8px; font-size: 14px;
  color: var(--c-text); outline: none; width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--c-primary); }
.field--invalid input { border-color: var(--c-danger); }
.form__error { color: var(--c-danger); font-size: 13px; margin: 10px 0 0; }
.form__foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ===== Toast ===== */
.toast {
  position: fixed; left: 50%; bottom: 30px; transform: translateX(-50%);
  background: #0f172a; color: #fff; padding: 12px 20px; border-radius: 10px;
  box-shadow: var(--shadow-lg); z-index: 60; font-size: 14px; animation: pop .2s ease;
}
@keyframes pop { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ===== 响应式 ===== */
@media (max-width: 900px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 680px) {
  .navbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .navbar__nav { order: 3; width: 100%; justify-content: space-between; }
  .navbar__status { margin-left: 0; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar__actions { margin-left: 0; }
  .toolbar__actions .btn { flex: 1; }
  /* 移动端：表格转为卡片列表 */
  .roster-table thead { display: none; }
  .roster-table, .roster-table tbody, .roster-table tr, .roster-table td { display: block; width: 100%; }
  .roster-table tr {
    border: 1px solid var(--c-border); border-radius: var(--radius); margin: 10px;
    padding: 6px; box-shadow: var(--shadow);
  }
  .roster-table td { border: none; display: flex; justify-content: space-between; gap: 12px; padding: 6px 10px; white-space: normal; }
  .roster-table td::before { content: attr(data-label); color: var(--c-muted); font-size: 12px; font-weight: 600; }
  .roster-table td.col-ops { justify-content: flex-start; }
  .row-ops { justify-content: flex-start; }
  .form__grid { grid-template-columns: 1fr; }
}

/* ============================================================
   移动端增强（≤768px 竖屏优先）
   - 顶部导航 → 底部标签栏
   - 新增 → 悬浮按钮(FAB)
   - 表单弹窗 → 底部弹层(bottom sheet)
   - 列表 → 可滑动卡片 + 下拉刷新
   - 触控目标 ≥ 44px；安全区(env safe-area)适配
   ============================================================ */
:root {
  --tabbar-h: 56px;
  --fab-size: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

/* ===== 离线提示条 ===== */
.offline-banner {
  background: var(--c-accent); color: #1f2937; font-size: 13px; font-weight: 600;
  text-align: center; padding: 8px 12px;
}

/* ===== 底部标签栏 ===== */
.tabbar {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  background: #fff; border-top: 1px solid var(--c-border);
  box-shadow: 0 -2px 10px rgba(15, 23, 42, .06);
}
.tabbar__item {
  flex: 1; border: none; background: transparent; cursor: pointer; min-height: var(--tabbar-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; color: var(--c-muted); font-size: 11px;
}
.tabbar__icon { font-size: 20px; line-height: 1; }
.tabbar__item--active { color: var(--c-primary); }
.tabbar__item--active .tabbar__icon { transform: translateY(-1px); }

/* ===== 新增悬浮按钮 ===== */
.fab {
  display: none; position: fixed; right: 16px;
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  width: var(--fab-size); height: var(--fab-size); border-radius: 50%;
  background: var(--c-primary); color: #fff; border: none; font-size: 28px; line-height: 1;
  align-items: center; justify-content: center; cursor: pointer;
  box-shadow: 0 6px 16px rgba(29, 78, 216, .45); z-index: 45;
  transition: transform .12s ease;
}
.fab:active { transform: scale(.92); }

/* ===== 移动端卡片列表 ===== */
.mobile-list { display: flex; flex-direction: column; gap: 10px; }
.mobile-empty { text-align: center; color: var(--c-muted); padding: 40px 16px; }
.mcard {
  position: relative; overflow: hidden; background: var(--c-card);
  border: 1px solid var(--c-border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.mcard__actions { position: absolute; top: 0; right: 0; height: 100%; display: flex; }
.mcard__actions button {
  border: none; color: #fff; font-size: 14px; font-weight: 600; min-width: 76px; padding: 0 18px;
}
.mcard__actions .act-edit { background: var(--c-primary); }
.mcard__actions .act-del { background: var(--c-danger); }
.mcard__body {
  position: relative; background: var(--c-card); padding: 12px 14px;
  display: flex; flex-direction: column; gap: 8px;
  transition: transform .22s ease; will-change: transform;
}
.mcard.swiping .mcard__body { transition: none; }
.mcard__main { display: flex; align-items: center; gap: 12px; }
.mcard__avatar {
  width: 42px; height: 42px; border-radius: 50%; flex: 0 0 auto;
  background: var(--c-primary); color: #fff; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.mcard__name { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.mcard__sub { color: var(--c-muted); font-size: 13px; margin-top: 2px; }
.mcard__meta { display: flex; flex-wrap: wrap; gap: 6px 16px; color: var(--c-muted); font-size: 12px; }
.mcard__meta b { color: var(--c-text); font-weight: 600; }

/* ===== 下拉刷新指示 ===== */
.ptr {
  position: absolute; top: 0; left: 0; right: 0; height: 44px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--c-muted); font-size: 13px;
  transform: translateY(-44px); opacity: 0; transition: transform .2s ease, opacity .2s ease;
  pointer-events: none; z-index: 5;
}
.ptr.show { transform: translateY(0); opacity: 1; }
.ptr__spinner {
  width: 18px; height: 18px; border: 2px solid var(--c-border); border-top-color: var(--c-primary);
  border-radius: 50%;
}
.ptr.is-refreshing .ptr__spinner { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== 移动端（竖屏优先）布局开关 ===== */
@media (max-width: 768px) {
  .tabbar { display: flex; }
  .fab { display: flex; }
  .navbar__nav { display: none; }                 /* 顶部导航让位给底部标签栏 */
  .navbar { padding: calc(10px + var(--safe-t)) 14px 10px; }
  body { padding-bottom: calc(var(--tabbar-h) + var(--safe-b)); }
  .container { padding: 14px 12px calc(var(--tabbar-h) + var(--safe-b) + 16px); }

  /* 触控目标放大 */
  .btn { min-height: 44px; padding: 12px 16px; }
  .toolbar__search input, .toolbar__filters select { min-height: 44px; font-size: 16px; }
  .toolbar__filters { flex: 1 1 100%; }
  .toolbar__filters select { flex: 1; }
  .toolbar__actions .btn { flex: 1; }
  #addBtn { display: none; }                       /* 移动端用 FAB 新增 */

  /* 表单弹窗 → 底部弹层 */
  .modal { padding: 0; align-items: flex-end; }
  .modal__panel {
    max-width: 100%; max-height: 92vh; border-radius: 16px 16px 0 0;
    padding-bottom: var(--safe-b); animation: sheetUp .25s ease;
    -webkit-overflow-scrolling: touch;
  }
  @keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

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

/* 尊重"减少动态效果"系统偏好 */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ============================================================
   队伍管理 & 批量添加 样式
   ============================================================ */

/* 队伍添加行 */
.team-add-row {
  display: flex; gap: 10px; align-items: center;
}
.team-add-row .btn { white-space: nowrap; }

/* 队伍列表项 */
.team-list {
  display: flex; flex-direction: column; gap: 8px;
}
.team-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 14px; background: #f8fafc; border: 1px solid var(--c-border);
  border-radius: 8px;
}
.team-item__info { display: flex; flex-direction: column; gap: 2px; }
.team-item__name { font-weight: 600; font-size: 14px; color: var(--c-text); }
.team-item__count { font-size: 12px; color: var(--c-muted); }

/* 批量添加选项行 */
.batch-opts {
  display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 8px;
}
.batch-opts .field { gap: 4px; }

/* 批量预览 */
.batch-preview {
  margin: 12px 0; max-height: 240px; overflow-y: auto;
  border: 1px solid var(--c-border); border-radius: 8px; padding: 8px;
  background: #f8fafc;
}
.batch-row {
  display: flex; gap: 10px; padding: 6px 8px; border-bottom: 1px dashed var(--c-border);
  font-size: 13px; align-items: center;
}
.batch-row:last-child { border-bottom: none; }
.batch-row span { flex: 1; }
.batch-row__team { flex: 0 0 auto; color: var(--c-primary); font-weight: 600; }

/* 移动端适配 */
@media (max-width: 768px) {
  .team-add-row { flex-direction: column; align-items: stretch; }
  .team-add-row input { width: 100%; }
  .batch-opts { flex-direction: column; }
  .batch-opts .field { flex: 1 1 100% !important; }
  .batch-row { flex-wrap: wrap; }
}
