: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)); }
.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; }
.inline-form.compact input { max-width: 160px; }
.inline-form.compact select { max-width: 98px; }
.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); }
.pending { background: #eef2f7; color: var(--pending); }
.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;
}
.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: 24px;
  background: #101820;
  color: #f8fafc;
}
.screen a { color: #a6d5ff; }
.screen-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.screen-head h1 { font-size: 38px; }
.screen-grid { display: grid; grid-template-columns: 380px 1fr; gap: 18px; margin-bottom: 18px; }
.screen-card {
  background: #182633;
  border: 1px solid #2b3d4e;
  border-radius: 8px;
  padding: 18px;
}
.screen-card h2 { color: #e7f3ff; }
.qr-card { text-align: center; }
.short-code {
  margin: 12px auto 6px;
  width: min(320px, 100%);
  padding: 12px;
  border-radius: 8px;
  background: #f8fafc;
  color: #101820;
  font-size: 44px;
  font-weight: 900;
  letter-spacing: 6px;
  text-align: center;
}
.ranking { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 22px; margin: 0; padding-left: 22px; }
.ranking li { padding: 6px 0; }
.ranking span { display: block; color: #b6c7d8; font-size: 13px; }
.attendance-wall, .resident-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.student-chip, .resident-item button {
  width: 100%;
  min-height: 64px;
  display: grid;
  align-content: center;
  gap: 4px;
  border-radius: 8px;
  padding: 10px;
  text-align: left;
}
.student-chip span, .resident-item span { color: inherit; opacity: .86; font-size: 13px; }
.resident-item { margin: 0; }
.resident-item button { background: #1f6feb; }
.resident-item.done button { background: #334155; }
.empty-state {
  display: grid;
  place-items: center;
  min-height: 260px;
  color: #d3dfed;
}

@media (max-width: 820px) {
  .topbar, .page-title, .section-head, .screen-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-grid, .ranking { grid-template-columns: 1fr; }
  .inline-form { align-items: stretch; flex-direction: column; }
}
