:root {
  --bg: #f3f6f4;
  --surface: #ffffff;
  --border: #e1e7e3;
  --text: #18211d;
  --muted: #6b7670;
  --accent: #0d8a58;
  --accent-strong: #0a6e46;
  --accent-soft: #e6f4ec;
  --danger: #c2392f;
  --danger-soft: #fdecea;
  --warning-bg: #fff7e6;
  --warning-text: #8a5a00;
  --sidebar: #1b2421;
  --sidebar-text: #c9d5ce;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.05), 0 8px 24px rgba(16, 24, 20, 0.05);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.shell {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 230px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 18px 12px;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 18px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex: none;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  font-size: 14px;
  cursor: pointer;
  border: 0;
  background: transparent;
  text-align: left;
  width: 100%;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255, 255, 255, 0.09);
  color: #fff;
}

.nav-item svg {
  flex: none;
}

.sidebar-foot {
  margin-top: auto;
  padding: 10px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 12px;
  color: #8fa198;
}

.main {
  margin-left: 230px;
  flex: 1;
  padding: 24px 30px;
  min-width: 0;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0;
}

.page-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.panel-highlight {
  border-color: var(--accent);
  background: #fbfefc;
  box-shadow: 0 0 0 3px var(--accent-soft), var(--shadow);
}

.panel-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 14px;
  letter-spacing: 0;
}

.training-plan-panel {
  margin-bottom: 14px;
}

.training-plan-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.training-plan-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.training-plan-current {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--accent-soft);
  margin-bottom: 12px;
}

.training-plan-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 13px;
  color: var(--muted);
}

.training-plan-name {
  font-weight: 600;
}

.training-plan-empty {
  color: var(--muted);
  padding: 2px 0 10px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  align-items: start;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 12px;
  color: var(--muted);
}

.stat-value {
  font-size: 28px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: 0;
}

.stat-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:hover {
  background: #f6f9f7;
  border-color: #cdd6d0;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

.btn-danger {
  background: var(--danger-soft);
  border-color: #f0c8c4;
  color: var(--danger);
}

.btn-danger:hover {
  background: #f9d9d6;
  border-color: #e7aaa4;
}

.btn-sm {
  padding: 5px 9px;
  font-size: 12px;
  border-radius: 6px;
}

.btn-lg {
  padding: 13px 18px;
  font-size: 16px;
  width: 100%;
}

.btn-icon {
  width: 34px;
  height: 34px;
  padding: 0;
}

.field {
  display: block;
  min-width: 0;
}

.field > label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.input,
.select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  color: inherit;
}

.time-picker {
  display: flex;
  align-items: center;
  gap: 6px;
}

.time-picker .select {
  flex: 1;
  min-width: 0;
  text-align: center;
  padding: 8px 6px;
}

.time-colon {
  color: var(--muted);
  font-weight: 600;
  flex: none;
}

.input:focus,
.select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 138, 88, 0.12);
}

.toolbar {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.toolbar .field {
  min-width: 140px;
}

.toolbar .spacer {
  flex: 1;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.table th,
.table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table th {
  background: #f8faf9;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.table tr:last-child td {
  border-bottom: none;
}

.table .muted {
  color: var(--muted);
}

.row-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  line-height: 18px;
}

.badge-green {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.badge-amber {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.badge-gray {
  background: #eef2f0;
  color: #59635d;
}

.badge-blue {
  background: #e8f1fb;
  color: #2456a6;
}

.roster-sync-summary {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  padding: 10px 12px;
  background: #f4f7f5;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 14px;
}

.roster-name-list {
  color: var(--muted);
  line-height: 1.9;
}

.roster-candidate-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 5px 0;
}

.roster-name {
  font-weight: 600;
  min-width: 80px;
}

.candidate-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}

.candidate-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
}

.pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 14px;
}

.page-info {
  color: var(--muted);
  font-size: 13px;
  margin-right: auto;
}

.alert {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.alert-warn {
  background: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid #f2dda8;
}

.alert-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid #f0c8c4;
}

.alert-success {
  background: var(--accent-soft);
  color: var(--accent-strong);
  border: 1px solid #b9dfca;
}

.qr-layout {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.qr-box {
  flex: 0 0 380px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
}

.qr-image {
  width: min(340px, 100%);
  height: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
}

.qr-meta {
  flex: 1;
  min-width: 280px;
}

.qr-url {
  background: #f6f8f7;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
  margin: 12px 0;
}

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

.daily-period-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
  padding: 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

.daily-period-row .remove-daily-period {
  white-space: nowrap;
}

.period-days-field {
  grid-column: 1 / -1;
}

.day-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.day-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  user-select: none;
}

.day-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.day-chip span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
}

.day-chip input:checked + span {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  align-items: center;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fbfdfc;
}

.switch-row .switch-label {
  font-size: 14px;
  font-weight: 600;
}

.switch-row .switch-sub {
  font-size: 12px;
  color: var(--muted);
}

.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex: none;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: #ccd4cf;
  border-radius: 999px;
  transition: background 0.15s ease;
  cursor: pointer;
}

.switch-track::after {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(18px);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 19, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.modal {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: 8px;
  padding: 20px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.18);
}

.modal-wide {
  max-width: 620px;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 16px;
}

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}

.login-title {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.login-sub {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #18211d;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  z-index: 80;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.22);
  font-size: 13px;
  max-width: 340px;
  animation: toast-in 0.18s ease;
}

.toast.success {
  border-left: 3px solid #39c987;
}

.toast.error {
  border-left: 3px solid #f07a70;
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* 公开二维码大屏 */
.qr-page {
  min-height: 100vh;
  background: #f7faf8;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.qr-card {
  width: min(920px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-columns: 1.08fr 0.92fr;
}

.qr-card-left {
  padding: 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
}

.qr-card-title {
  font-size: 24px;
  font-weight: 700;
  margin: 0;
  letter-spacing: 0;
}

.qr-card-sub {
  color: var(--muted);
  margin: 0;
}

.qr-card-right {
  background: #fbfdfc;
  border-left: 1px solid var(--border);
  padding: 26px;
}

.recent-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 12px;
}

.recent-list {
  display: flex;
  flex-direction: column;
}

.recent-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}

.recent-item:last-child {
  border-bottom: none;
}

.recent-name {
  font-weight: 600;
}

.recent-time {
  color: var(--muted);
  font-size: 12px;
}

/* 扫码页 */
.scan-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f2f6f3;
  padding: 18px;
}

.scan-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 26px;
  box-shadow: var(--shadow);
  text-align: center;
}

.scan-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  padding: 34px 12px;
  color: var(--muted);
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--accent-soft);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.result-icon {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  margin: 0 auto 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.result-icon.success {
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.result-icon.duplicate {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.result-icon.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.scan-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 6px;
}

.scan-message {
  color: var(--muted);
  margin: 0 0 20px;
}

.scan-detail {
  background: #f6f8f7;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 20px;
}

@media (max-width: 1100px) {
  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .grid-2 {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    width: 100%;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 4px;
    overflow-x: auto;
    padding: 10px 12px;
  }

  .brand {
    padding: 0 8px 0 0;
    flex: none;
  }

  .brand-name {
    display: none;
  }

  .nav-item {
    width: auto;
    padding: 8px 10px;
    flex: none;
  }

  .nav-item span {
    display: none;
  }

  .sidebar-foot {
    display: none;
  }

  .main {
    margin-left: 0;
    padding: 18px 16px;
  }

  .qr-card {
    grid-template-columns: 1fr;
  }

  .qr-card-right {
    border-left: none;
    border-top: 1px solid var(--border);
  }
}

@media (max-width: 640px) {
  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }

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

  .form-grid {
    grid-template-columns: 1fr;
  }

  .daily-period-row {
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .toolbar .field {
    min-width: 100%;
  }

  .qr-box {
    flex-basis: 100%;
  }

  .qr-layout {
    flex-direction: column;
  }
}
