:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #e7e9ee;
  --text: #15181e;
  --text-2: #5b6270;
  --text-3: #9198a5;
  --accent: #2f6fed;
  --accent-soft: #e6eefe;
  --accent-text: #1f56c7;
  --err: #d9363e;
  --err-soft: #fdecec;
  --warn: #c98a06;
  --warn-soft: #fdf4dc;
  --ok-text: #1d8a4a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
  --font: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans SC", sans-serif;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #181b21;
    --surface-2: #22262e;
    --line: #2a2f38;
    --text: #eceef2;
    --text-2: #a4abb8;
    --text-3: #6d7482;
    --accent: #5b8ff9;
    --accent-soft: #1f2c47;
    --accent-text: #9dbcff;
    --err: #f06a70;
    --err-soft: #3a1f22;
    --warn: #e5b23c;
    --warn-soft: #382f17;
    --ok-text: #6fd59a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
h2, h3 { margin: 0; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  padding-top: env(safe-area-inset-top);
}
.topbar-row {
  max-width: 720px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 16px;
}
.nav-tabs { display: flex; gap: 4px; }
.tab {
  border: 0; background: none; padding: 6px 10px; border-radius: 10px;
  font-size: 17px; font-weight: 600; color: var(--text-3);
}
.tab.active { color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 6px; }

.app {
  max-width: 720px; margin: 0 auto;
  padding: 4px 16px calc(96px + env(safe-area-inset-bottom));
}

/* ---------- 按钮 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px;
  border: 0; border-radius: 12px;
  background: var(--surface-2); color: var(--text);
  font-weight: 600; text-decoration: none; white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { background: var(--err-soft); color: var(--err); }
.btn.ghost { background: none; color: var(--text-2); padding: 0 8px; font-weight: 500; }
.btn.subtle { background: var(--surface-2); color: var(--text-2); min-height: 34px; padding: 0 12px; font-weight: 500; }
.modal button:not(.btn):not(.candidate-btn) {
  min-height: 40px; padding: 0 16px; border: 0; border-radius: 12px;
  background: var(--surface-2); font-weight: 600;
}

.badge {
  display: inline-flex; align-items: center; min-height: 28px;
  padding: 0 10px; border-radius: 999px; border: 0;
  background: var(--surface-2); color: var(--text-2); font-size: 13px; font-weight: 600;
}
.error-badge { background: var(--err-soft); color: var(--err); }

/* ---------- 期切换 ---------- */
.board-head { display: grid; gap: 10px; margin: 6px 0 14px; }
.seg {
  display: flex; padding: 3px; gap: 3px;
  background: var(--surface-2); border-radius: 12px;
}
.seg-btn {
  flex: 1; min-height: 44px; border: 0; border-radius: 10px; background: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-2); line-height: 1.2;
}
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg-label { font-weight: 600; font-size: 15px; }
.seg-sub { font-size: 12px; color: var(--text-3); }
.months { display: flex; gap: 6px; }
.month {
  min-height: 32px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text-2); font-size: 14px;
}
.month.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }

.notice {
  margin: 0 0 12px; padding: 10px 12px; border-radius: 12px;
  background: var(--warn-soft); color: var(--text); font-size: 14px;
}

/* ---------- 分组表 ---------- */
.roster {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.roster-row {
  display: grid; align-items: center; column-gap: 10px;
  grid-template-columns: 60px minmax(0, 1fr) auto;
  min-height: 52px; padding: 6px 12px 6px 14px;
  border-top: 1px solid var(--line);
  position: relative;
}
.roster.is-compare .roster-row { grid-template-columns: 50px minmax(0, 1fr) 62px 88px; column-gap: 8px; }
.roster-head {
  min-height: 34px; border-top: 0;
  font-size: 12px; color: var(--text-3); background: var(--surface-2);
}
.unit-label {
  padding: 12px 14px 6px; font-size: 13px; font-weight: 600; color: var(--accent-text);
  border-top: 1px solid var(--line);
}
.roster-head + .unit-label { border-top: 0; }
.roster-row.st-error { background: var(--err-soft); }
.roster-row.st-error::before, .roster-row.st-warn::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0;
}
.roster-row.st-error::before { background: var(--err); }
.roster-row.st-warn::before { background: var(--warn); }
.roster-row.is-drag-over { background: var(--accent-soft); }

.c-group { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.roster-head .c-group, .roster-head .c-cur, .roster-head .c-jr { font-size: 12px; font-weight: 500; color: var(--text-3); }
.c-senior { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.c-senior .prof { font-size: 15px; }
.c-senior .mid { font-size: 13px; color: var(--text-2); }
.c-senior span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.c-cur { font-size: 14px; color: var(--text-3); white-space: nowrap; position: relative; }
.roster-row:not(.roster-head) .c-cur::after { content: "→"; position: absolute; right: -4px; color: var(--text-3); }
.c-jr { display: flex; justify-content: flex-end; }
.roster.is-compare .c-jr { justify-content: flex-start; }

.dot {
  width: 18px; height: 18px; border-radius: 50%; border: 0; padding: 0; flex: none;
  display: inline-grid; place-items: center; font-size: 11px; font-weight: 700; color: #fff;
}
.dot::after { content: "!"; }
.dot-error { background: var(--err); }
.dot-warn { background: var(--warn); }

/* ---------- 人名标签 ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 38px; padding: 0 12px; border-radius: 10px;
  border: 1.5px solid transparent; background: var(--surface-2);
  font-weight: 600; font-size: 15px; white-space: nowrap; justify-content: center; min-width: 76px;
  transition: transform .08s, background .15s;
}
button.chip:active { transform: scale(.96); }
.chip.is-static { cursor: default; }
.chip.is-empty { color: var(--text-3); border-style: dashed; border-color: var(--line); background: none; }
.chip.is-changed { background: var(--accent-soft); color: var(--accent-text); }
.chip.is-selected { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.chip.is-blocked { opacity: .35; }
.chip.is-absent .chip-name { color: var(--text-3); text-decoration: line-through; }
.chip.is-target { border: 1.5px dashed var(--accent); background: none; color: var(--accent-text); font-weight: 500; }
.chip-fill { font-size: 13px; color: var(--ok-text); font-weight: 600; }
.chip-wrap { display: inline-flex; gap: 6px; align-items: center; }
.tag { font-size: 11px; padding: 1px 6px; border-radius: 6px; font-weight: 600; }
.tag-out { background: var(--warn-soft); color: var(--warn); }
.fill-btn {
  min-height: 32px; padding: 0 10px; border-radius: 9px; border: 0;
  background: var(--surface-2); color: var(--text-2); font-size: 13px; font-weight: 600;
}
.fill-btn.need { background: var(--err); color: #fff; }

/* ---------- 放疗中心 / 科外 ---------- */
.pools { display: grid; gap: 12px; margin-top: 12px; }
@media (min-width: 640px) { .pools { grid-template-columns: 1fr 1fr; } }
.pool {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px 14px;
}
.pool h3 { font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 10px; display: flex; gap: 6px; align-items: center; }
.count { font-size: 12px; color: var(--text-3); font-weight: 500; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; min-height: 38px; align-items: center; }
.chips.is-drag-over { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 8px; }
.muted { color: var(--text-3); font-size: 14px; }
.center { text-align: center; }

/* ---------- 底部操作栏 ---------- */
.selection-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; gap: 8px; align-items: center; justify-content: center;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(14px);
  -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-top: 1px solid var(--line);
}
.selection-bar[hidden] { display: none; }
.selection-bar .btn { flex: 1; max-width: 160px; min-height: 44px; padding: 0 10px; }
.selection-bar .btn.primary { flex: 1.4; }
.bar-text { flex: 2; font-size: 14px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-text b { color: var(--text); }

/* ---------- 弹窗 ---------- */
.modal {
  border: 0; padding: 0; border-radius: 18px;
  width: min(440px, calc(100vw - 24px)); max-height: 86vh;
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
}
.modal::backdrop { background: rgba(10, 12, 16, .45); }
.modal-inner { padding: 16px; display: grid; gap: 14px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 17px; margin: 0; }
.modal-list { display: grid; gap: 8px; max-height: 50vh; overflow: auto; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }
.candidate-btn {
  display: flex; justify-content: space-between; align-items: center;
  min-height: 46px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); font-weight: 600;
}
.candidate-btn.is-current { border-color: var(--accent); background: var(--accent-soft); }
.issue-item { padding: 10px 12px; border-radius: 10px; font-size: 14px; }
.issue-item.error { background: var(--err-soft); }
.issue-item.warn { background: var(--warn-soft); }
.shot { width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.empty-text { color: var(--text-3); margin: 0; }

.form-grid { display: grid; gap: 12px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }
.field input, .field select, input[type="text"], input[type="password"], select {
  min-height: 44px; padding: 0 12px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface-2); font-size: 16px; width: 100%;
}

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 40; padding: 10px 16px; border-radius: 999px;
  background: var(--text); color: var(--bg); font-size: 14px; font-weight: 600;
}
.toast[hidden] { display: none; }

/* ---------- 人员页 ---------- */
.subtabs { display: flex; gap: 3px; padding: 3px; background: var(--surface-2); border-radius: 12px; margin: 6px 0 14px; }
.pill { flex: 1; min-height: 38px; border: 0; border-radius: 10px; background: none; color: var(--text-2); font-weight: 600; }
.pill.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.actions-row { display: flex; gap: 8px; margin-bottom: 12px; }
.panel {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 4px 14px; margin-bottom: 12px;
}
.panel > h3, .panel > h2 { font-size: 13px; color: var(--text-2); font-weight: 600; padding: 12px 0 4px; }
.list-row, .group-edit-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  min-height: 52px; border-top: 1px solid var(--line);
}
.panel > h3 + .list-row, .panel > h2 + .list-row { border-top: 0; }
.list-main { display: flex; flex-direction: column; min-width: 0; }
.list-actions { display: flex; gap: 6px; }
.group-edit-row { flex-wrap: wrap; padding: 8px 0; }
.group-edit-row select { flex: 1; min-width: 120px; }
.key { font-weight: 600; }

/* ---------- 登录页 ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-box {
  width: min(360px, 100%); background: var(--surface); border-radius: 20px;
  box-shadow: var(--shadow); padding: 28px 22px; display: grid; gap: 16px;
}
.login-box h1 { margin: 0; font-size: 22px; }
.login-form { display: grid; gap: 12px; }
.login-form .btn { min-height: 46px; }
.login-error { color: var(--err); font-size: 14px; min-height: 1em; margin: 0; }
