:root {
  color-scheme: light;
  --bg: #f5f7f8;
  --surface: #fff;
  --surface-2: #edf2f4;
  --ink: #172026;
  --muted: #66737c;
  --line: #d9e1e5;
  --blue: #1466d9;
  --blue-2: #e8f1ff;
  --green: #16805d;
  --red: #b93d38;
  --shadow: 0 18px 48px rgba(30, 45, 55, 0.08);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
}
button, input { font: inherit; }
select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .58; }

.student-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0;
}
.admin-shell {
  display: grid;
  grid-template-columns: 244px 1fr;
  min-height: 100vh;
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 18px;
  background: #172026;
  color: #eef5f7;
}
.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 8px;
  background: #6ee7b7;
  color: #10201a;
  font-weight: 900;
}
.brand-row strong, .brand-row small { display: block; }
.brand-row small { margin-top: 2px; color: #8ea0a8; }

.auth-panel {
  display: grid;
  gap: 18px;
  width: min(480px, 100%);
  margin: 8vh auto;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.admin-login { align-self: start; }
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}
.tabs button, .nav-stack button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}
.tabs button { height: 38px; }
.tabs button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 4px rgba(20, 35, 45, .12);
}
.form-grid {
  display: grid;
  gap: 12px;
}
label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}
input {
  width: 100%;
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: #fff;
  outline: 0;
}
select {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: #fff;
  outline: 0;
}
input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(20, 102, 217, .12);
}
select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(20, 102, 217, .12);
}
input[type="file"] {
  height: auto;
  padding: 10px;
}
.primary, .secondary {
  min-height: 40px;
  border-radius: 7px;
  padding: 0 14px;
  font-weight: 900;
}
.primary {
  border: 1px solid var(--blue);
  background: var(--blue);
  color: #fff;
}
.secondary {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}
.full { width: 100%; }
.message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}
.message.error { color: var(--red); }
.message.ok { color: var(--green); }

.workspace, .admin-main {
  display: grid;
  gap: 18px;
}
.admin-main {
  padding: 24px;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0;
}
h1, h2, p { margin: 0; }
h1 { font-size: 28px; line-height: 1.2; }
h2 { font-size: 18px; }
.grid-two {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, .8fr);
  gap: 18px;
}
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}
.panel-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}
.inline-form {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) auto;
  gap: 10px;
  padding: 18px;
}
.padded-form { padding: 18px; }
.qr-panel { overflow: hidden; }
.qr-box {
  display: grid;
  min-height: 310px;
  place-items: center;
  padding: 18px;
  text-align: center;
  background: #fbfcfd;
}
.qr-box img,
.qr-canvas {
  width: 240px;
  height: 240px;
  border: 8px solid #fff;
  box-shadow: 0 8px 24px rgba(20, 35, 45, .14);
}
.qr-canvas {
  display: block;
  image-rendering: pixelated;
}
.qr-box.empty {
  color: var(--muted);
  font-weight: 800;
}
.qr-text {
  max-width: 100%;
  overflow-wrap: anywhere;
  color: var(--muted);
  font-size: 12px;
}
.list, .review-list {
  display: grid;
  gap: 10px;
  padding: 14px;
}
.row-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}
.row-card strong, .row-card span, .row-card small { display: block; }
.row-card small { margin-top: 3px; color: var(--muted); }
.status {
  display: inline-grid;
  place-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 10px;
  background: var(--blue-2);
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
}
.status.checked_in { background: #e7f8f0; color: var(--green); }
.status.rejected, .status.cancelled { background: #fff0ee; color: var(--red); }

.nav-stack {
  display: grid;
  gap: 6px;
  margin: 26px 0;
}
.nav-stack button {
  height: 42px;
  padding: 0 12px;
  color: #b8c7cd;
  text-align: left;
}
.nav-stack button.active {
  background: #26333a;
  color: #fff;
}
.metrics {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.metrics span {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 12px;
  background: #fff;
  color: var(--muted);
  font-weight: 800;
}
.metrics strong { color: var(--ink); }
.admin-section { display: none; }
.admin-section.active { display: block; }
.scanner {
  width: calc(100% - 36px);
  aspect-ratio: 4 / 3;
  margin: 18px 18px 0;
  border-radius: 8px;
  background: #0b1116;
  object-fit: cover;
}
#manualScanForm {
  grid-template-columns: minmax(0, 1fr) auto;
}
.empty-state {
  display: grid;
  min-height: 280px;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  text-align: center;
  font-weight: 800;
}
.person-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}
.photo-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 14px;
}
.photo-grid img {
  width: 100%;
  max-height: 260px;
  border: 1px solid var(--line);
  border-radius: 7px;
  object-fit: cover;
  background: #f8fafb;
}
.info-table {
  display: grid;
  gap: 8px;
  color: var(--muted);
}
.info-table b { color: var(--ink); }
.review-card {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
}
.review-card img {
  width: 120px;
  height: 90px;
  border: 1px solid var(--line);
  border-radius: 6px;
  object-fit: cover;
}
.button-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 820px) {
  .admin-shell { display: block; }
  .sidebar {
    position: static;
    height: auto;
  }
  .admin-main, .student-shell { padding: 16px; width: 100%; }
  .grid-two, .inline-form, .photo-grid, .review-card {
    grid-template-columns: 1fr;
  }
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  body {
    background: #fff;
  }

  .student-shell {
    width: 100%;
    padding: 12px 12px calc(22px + env(safe-area-inset-bottom));
  }

  .auth-panel {
    width: 100%;
    min-height: calc(100vh - 24px);
    margin: 0;
    padding: 18px;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .student-shell .workspace {
    gap: 12px;
  }

  .student-shell .topbar {
    position: sticky;
    top: 0;
    z-index: 4;
    margin: -12px -12px 0;
    padding: 14px 12px 10px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, .96);
    backdrop-filter: blur(12px);
  }

  .student-shell .topbar h1 {
    font-size: 22px;
  }

  .student-shell .grid-two {
    gap: 12px;
  }

  .panel {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }

  .panel-head {
    padding: 14px 12px;
  }

  .inline-form,
  .list,
  .review-list,
  .person-card,
  .padded-form {
    padding: 12px;
  }

  input,
  select,
  .primary,
  .secondary {
    min-height: 48px;
    font-size: 16px;
  }

  .tabs button {
    height: 44px;
  }

  .row-card {
    grid-template-columns: 1fr;
    align-items: stretch;
    padding: 12px;
  }

  .button-row {
    width: 100%;
  }

  .button-row button,
  .row-card .secondary,
  .row-card .primary {
    flex: 1;
  }

  .qr-box {
    min-height: auto;
    padding: 16px 12px;
  }

  .qr-box img,
  .qr-canvas {
    width: min(72vw, 270px);
    height: min(72vw, 270px);
  }

  .qr-text {
    max-height: 42px;
    overflow: hidden;
  }

  .admin-main {
    padding: 12px;
  }

  .sidebar {
    padding: 14px 12px;
  }

  .nav-stack {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 14px 0;
  }

  .nav-stack button {
    height: 38px;
    padding: 0 8px;
    text-align: center;
    font-size: 13px;
  }

  .scanner {
    width: calc(100% - 24px);
    margin: 12px 12px 0;
  }
}
