:root {
  --bg: #f5f7fb;
  --text: #1f2937;
  --muted: #687386;
  --line: #dbe2ee;
  --panel: #ffffff;
  --primary: #1769aa;
  --primary-dark: #0e4f86;
  --ok: #138a52;
  --warn: #b86b00;
  --bad: #b42318;
  --pending: #64748b;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background:
    linear-gradient(180deg, #eef4fb 0, #f7f9fc 220px, var(--bg) 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}
a { color: var(--primary); text-decoration: none; }
h1, h2 { margin: 0 0 14px; }
h1 { font-size: 28px; }
h2 { font-size: 19px; }
button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  background: var(--primary);
  color: white;
  font-weight: 700;
  cursor: pointer;
}
button:hover, .button:hover { background: var(--primary-dark); color: white; }
button.secondary, .button.secondary { background: #e8eef7; color: #1f3d5f; }
button:disabled { background: #cbd5e1; cursor: not-allowed; }
.button.wide { width: 100%; }
.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  margin: 16px 0;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line);
}
input, select, textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  font: inherit;
  background: white;
}
textarea { resize: vertical; }
label { display: grid; gap: 6px; font-weight: 700; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: var(--muted); font-size: 13px; }

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  background: white;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 16px; }
.link-button { background: transparent; color: var(--primary); padding: 0; min-height: auto; }
.link-button:hover { background: transparent; color: var(--primary-dark); }
.container { max-width: 1280px; margin: 28px auto; padding: 0 22px; }
.container.narrow { max-width: 520px; }
.page-title, .section-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.panel, .metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 10px 30px rgba(28, 46, 74, .05);
}
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.grid.no-margin { margin-bottom: 0; }
.stack { display: grid; gap: 14px; }
.muted { color: var(--muted); }
.metric span { display: block; color: var(--muted); }
.metric strong { display: block; margin-top: 8px; font-size: 32px; }
.table-panel { overflow-x: auto; }
.inline-form { display: flex; align-items: center; gap: 8px; }
.quick-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.quick-form.code-form { margin-top: 12px; }
.quick-form.code-form input[name="shortCode"] { max-width: 150px; }
.inline-form.compact input { max-width: 160px; }
.inline-form.compact select { max-width: 98px; }
.row-actions { gap: 8px; }
.checkbox-label {
  width: auto;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
  font-weight: 700;
}
.checkbox-label input {
  width: auto;
  min-height: auto;
}
.student-select-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  max-height: 460px;
  overflow: auto;
}
.choice-card {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
  font-weight: 400;
}
.choice-card input {
  width: auto;
  min-height: auto;
  flex: 0 0 auto;
}
.choice-card span { min-width: 0; }
.choice-card strong, .choice-card small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.choice-card small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}
.alert { margin: 12px 0; padding: 10px 12px; border-radius: 6px; font-weight: 700; }
.alert.success { background: #e8f6ef; color: var(--ok); }
.alert.warning { background: #fff4df; color: var(--warn); }
.alert.error { background: #fdecec; color: var(--bad); }
.pill, .status {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 10px;
  font-weight: 800;
}
.status { font-size: 18px; }
.present { background: #e8f6ef; color: var(--ok); }
.late { background: #fff4df; color: var(--warn); }
.absent { background: #fdecec; color: var(--bad); }
.manual { background: #e7f0ff; color: var(--primary); }
.leave { background: #f3e8ff; color: #7e22ce; }
.pending { background: #eef2f7; color: var(--pending); }
.not-required { background: #e6fffb; color: #0f766e; }
.qr { width: min(320px, 100%); height: auto; background: white; border-radius: 6px; }
.qr.small { width: 220px; }
.scanner {
  width: 100%;
  min-height: 280px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0f172a;
}
.scan-status {
  min-height: 24px;
  margin: 0;
}
.scan-controls {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 10px;
}
.scan-controls[hidden] { display: none; }
.scan-controls label { font-weight: 800; }
.scan-controls select { width: 100%; }
.scan-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.scan-actions button { width: auto; }
.scan-tip { margin: 0; }
.map-panel {
  width: 100%;
  min-height: 320px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f7;
}
.auth-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 28px;
}
.auth-panel {
  width: min(420px, 100%);
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}

.screen {
  min-height: 100vh;
  padding: 22px;
  background: #eef3f8;
  color: #172033;
}
.screen a { color: var(--primary); font-weight: 800; }
.screen-clock {
  display: block;
  width: 100%;
  margin: 5px 0 0;
  padding: 0;
  color: #0f172a;
  font-size: 28px;
  font-weight: 500;
  line-height: 1.15;
  letter-spacing: 0;
  text-align: center;
}
.screen-layout {
  height: calc(100vh - 44px);
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(460px, 620px) minmax(300px, 1fr);
  gap: 16px;
  align-items: stretch;
}
.screen-left {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.screen-left .commuter-panel {
  flex: 0 0 auto;
}
.screen-left .resident-panel {
  flex: 1 1 auto;
  min-height: 0;
}
.screen-panel {
  min-height: 0;
  background: #ffffff;
  border: 1px solid #d8e1ec;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 10px 28px rgba(35, 58, 84, .08);
}
.screen-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.screen-panel-head h2 { margin: 0; color: #172033; font-size: 18px; }
.screen-panel-head strong { color: var(--primary); font-size: 20px; }
.setting-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}
.setting-toggle-row h2,
.setting-toggle-row p { margin: 0; }
.switch-control {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}
.switch-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}
.switch-track {
  position: relative;
  width: 48px;
  height: 26px;
  flex: 0 0 auto;
  border-radius: 13px;
  background: #aab5c3;
  transition: background-color 180ms ease;
}
.switch-track::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 1px 4px rgba(15, 23, 42, .28);
  content: "";
  transition: transform 180ms ease;
}
.switch-control input:checked + .switch-track { background: #1687e8; }
.switch-control input:checked + .switch-track::after { transform: translateX(22px); }
.switch-control input:focus-visible + .switch-track {
  outline: 3px solid rgba(22, 135, 232, .28);
  outline-offset: 2px;
}
.screen-scroll {
  max-height: calc(100vh - 128px);
  overflow: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.screen-scroll::-webkit-scrollbar {
  width: 0;
  height: 0;
}
.screen-center {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 16px;
}
.qr-stage {
  position: sticky;
  top: 22px;
  z-index: 2;
  text-align: center;
  background: #ffffff;
  border: 1px solid #d8e1ec;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 10px 28px rgba(35, 58, 84, .08);
}
.important-countdown {
  width: min(560px, 100%);
  min-height: 62px;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 4px;
  margin: 0 auto 10px;
  padding: 7px 12px;
  overflow: hidden;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: linear-gradient(135deg, #eff6ff, #ecfeff);
  color: #174b78;
  font-size: 26px;
  font-weight: 800;
  line-height: 1.1;
  white-space: nowrap;
}
.important-countdown[hidden] { display: none; }
.important-countdown strong {
  max-width: 48%;
  overflow: hidden;
  color: #0e4f86;
  font-size: 30px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.important-countdown b {
  color: #dc2626;
  font-size: 34px;
  font-variant-numeric: tabular-nums;
}
.qr-cluster {
  position: relative;
  width: min(560px, 100%);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #ffffff;
  box-shadow: none;
  box-sizing: border-box;
}
.qr-stage .qr-main {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  aspect-ratio: 1;
  object-fit: contain;
  border: 0;
  border-radius: 6px;
}
.short-code {
  margin: 6px auto 2px;
  width: min(560px, 100%);
  padding: 6px 12px;
  border-radius: 8px;
  background: #eef6ff;
  color: #0e4f86;
  font-size: 40px;
  font-weight: 900;
  line-height: 1.1;
  letter-spacing: 6px;
  text-align: center;
}
.code-bounce-track {
  position: relative;
  width: min(560px, 100%);
  height: 3px;
  margin: 5px auto;
}
.code-bounce-track::after {
  position: absolute;
  top: 0;
  left: 0;
  width: 28px;
  height: 3px;
  border-radius: 2px;
  background: #66cfff;
  content: "";
  will-change: left, width;
  animation: code-bounce-slide 2s linear infinite;
}
@keyframes code-bounce-slide {
  0%, 100% {
    left: 0;
    width: 28px;
  }
  25%, 75% {
    left: calc(50% - 24px);
    width: 48px;
  }
  50% {
    left: calc(100% - 28px);
    width: 28px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .code-bounce-track::after {
    left: 50%;
    transform: translateX(-50%);
    animation: none;
  }
}
.qr-countdown {
  margin-top: 2px;
  padding-top: 5px;
  padding-bottom: 5px;
  background: #ecfdf5;
  color: #0f766e;
  font-size: 24px;
  letter-spacing: 0;
}
.qr-stage p { min-height: 18px; margin: 3px 0; color: #64748b; font-size: 14px; font-weight: 700; line-height: 1.25; }
.commuter-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 5px;
}
.ranking {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 6px;
  align-content: start;
  margin: 0;
  padding: 0;
  list-style: none;
}
.ranking li {
  position: relative;
  min-width: 0;
  display: grid;
  grid-template-columns: 27px minmax(0, 1fr);
  grid-template-rows: auto auto;
  column-gap: 5px;
  padding: 4px 5px 7px;
  overflow: hidden;
  border: 1px solid #dbe5f1;
  border-radius: 6px;
  background: #f8fbff;
  will-change: transform;
  transition: border-color 180ms ease, background-color 180ms ease, box-shadow 180ms ease;
}
.ranking li.ranking-enter {
  opacity: 0;
  transform: translateY(14px);
}
.ranking li.ranking-changed { animation: ranking-flash 680ms ease; }
.ranking li.ranking-up { border-color: #34d399; box-shadow: inset 3px 0 #10b981; }
.ranking li.ranking-down { border-color: #fbbf24; box-shadow: inset 3px 0 #f59e0b; }
.ranking-number { grid-row: 1 / 3; align-self: center; color: #2563eb; font-size: 11px; font-variant-numeric: tabular-nums; }
.ranking-person { min-width: 0; display: flex; align-items: baseline; gap: 3px; }
.ranking strong { overflow: hidden; font-size: 13px; line-height: 1.05; text-overflow: ellipsis; white-space: nowrap; }
.ranking span { color: #64748b; font-size: 9px; line-height: 1.05; white-space: nowrap; }
.ranking dl {
  grid-column: 2;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
  margin: 2px 0 0;
}
.ranking dl div {
  display: grid;
  gap: 1px;
  min-width: 0;
  padding: 2px;
  border-radius: 4px;
  background: #ffffff;
}
.ranking dt {
  overflow: hidden;
  color: #64748b;
  font-size: 8px;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ranking dd { margin: 0; font-size: 10px; font-weight: 900; color: #172033; line-height: 1; white-space: nowrap; }
.ranking-progress { position: absolute; inset: auto 0 0; width: var(--rank-progress); height: 3px; background: linear-gradient(90deg, #3b82f6, #22c55e); transition: width 520ms cubic-bezier(.2,.8,.2,1); }
@keyframes ranking-flash { 45% { background-color: #ecfdf5; } }
@media (prefers-reduced-motion: reduce) {
  .ranking li, .ranking-progress { animation: none !important; transition: none !important; }
}
.ranking-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px;
}
.ranking-panel .screen-panel-head { margin-bottom: 6px; }
.ranking-panel .ranking {
  flex: 1 1 auto;
  max-height: none;
  overflow: hidden;
}
.resident-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 8px;
}
.student-chip, .resident-item button {
  width: 100%;
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 4px;
  border-radius: 8px;
  padding: 9px;
  text-align: left;
}
.commuter-grid .student-chip {
  min-height: 44px;
  gap: 2px;
  padding: 5px 6px;
  border-radius: 6px;
  border: 1px solid currentColor;
}
.commuter-grid .student-chip strong { font-size: 14px; line-height: 1.1; }
.commuter-grid .student-chip span { font-size: 11px; font-weight: 800; line-height: 1.1; }
.student-chip span, .resident-item span { color: inherit; opacity: .86; font-size: 13px; }
.student-chip strong, .resident-item strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.resident-item { margin: 0; }
.resident-item button { background: var(--primary); }
.resident-item.done button { background: #cbd5e1; color: #334155; }
.empty-state {
  display: grid;
  place-items: center;
  min-height: 260px;
  color: #64748b;
  font-weight: 800;
}

@media (max-width: 820px) {
  .topbar, .page-title, .section-head { align-items: flex-start; flex-direction: column; }
  .topbar { height: auto; padding: 16px; }
  .topbar nav { flex-wrap: wrap; }
  .grid.two, .grid.four, .grid.five, .screen-layout, .ranking { grid-template-columns: 1fr; }
  .screen-layout { height: auto; }
  .screen-scroll, .commuter-panel .screen-scroll { max-height: 360px; }
  .ranking-panel { overflow: visible; }
  .ranking-panel .ranking { max-height: 360px; overflow: auto; }
  .screen-clock { min-width: 0; width: 100%; font-size: 24px; }
  .setting-toggle-row { align-items: flex-start; flex-direction: column; }
  .inline-form { align-items: stretch; flex-direction: column; }
}
html.partial-loading { cursor: progress; }
html.partial-loading button, html.partial-loading input, html.partial-loading select, html.partial-loading textarea { cursor: progress; }

.map-picker { display: grid; gap: 8px; }
.map-picker-tools { display: flex; gap: 8px; align-items: center; }
.map-picker-tools input { flex: 1; min-width: 0; }
.map-picker-canvas {
  height: 320px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #eef2f7;
}
.map-picker.is-disabled .map-picker-canvas { display: none; }
.map-picker-hint { font-size: 13px; }
.map-picker-results {
  list-style: none;
  margin: 0;
  padding: 4px;
  max-height: 200px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
}
.map-picker-results li + li { border-top: 1px solid var(--line); }
.map-picker-results .link-button {
  display: block;
  width: 100%;
  padding: 8px;
  text-align: left;
}
.map-picker-results .link-button:hover { background: #f1f5fb; }
.map-picker-results strong { display: block; }
.map-picker-results span { display: block; font-size: 12px; }
