:root {
  --bg: #f2f5f9;
  --surface: #ffffff;
  --ink: #212529;
  --muted: #5d6672;
  --line: rgba(10, 30, 61, 0.12);
  --navy: #0a1e3d;
  --amber: #b9862f;
  --amber-soft: #faf1da;
  --green-soft: #e3f2e9;
  --green-line: #2e7d5e;
  --blue-soft: #e3ecf7;
  --blue-line: #2b5ea7;
  --purple-soft: #ece6f5;
  --purple-line: #6a4fa3;
  --red-soft: #fbe5e5;
  --red-line: #b3382f;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 9px;
  --shadow: 0 10px 30px rgba(10, 30, 61, 0.1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: "Source Serif 4", Georgia, serif; margin: 0; }

button {
  font-family: inherit;
  font-size: 1rem;
  border: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

input, select, textarea {
  font-family: inherit;
  font-size: 1rem;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--ink);
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--blue-line);
  outline-offset: 1px;
}

.hidden { display: none !important; }

/* ------------------------- login ------------------------- */

.login-wrap {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--navy);
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.login-card .brand {
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.8rem;
  color: var(--amber);
  margin-bottom: 6px;
}

.login-card h1 { font-size: 1.5rem; margin-bottom: 4px; }

.login-card .sub { color: var(--muted); margin: 0 0 20px; font-size: 0.95rem; }

.login-card input {
  text-align: center;
  font-size: 1.3rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

.login-error {
  color: var(--red-line);
  font-size: 0.9rem;
  min-height: 1.3em;
  margin: 0 0 10px;
}

.btn-primary {
  background: var(--navy);
  color: #ffffff;
  font-weight: 600;
  padding: 14px 18px;
  width: 100%;
  border-radius: var(--radius-sm);
}

.btn-primary:active { transform: scale(0.985); }

.btn-primary:disabled { opacity: 0.5; cursor: default; }

.btn-green { background: var(--green-line); }

.btn-secondary {
  background: #eef1f6;
  color: var(--navy);
  font-weight: 600;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
}

.btn-danger-link {
  background: none;
  color: var(--red-line);
  font-size: 0.9rem;
  padding: 8px;
}

/* ------------------------- crew app shell ------------------------- */

.app-shell {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.app-top {
  background: var(--navy);
  color: #ffffff;
  padding: 14px 16px 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.app-top .row1 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}

.app-top .brand {
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--amber);
}

.app-top .who {
  font-size: 0.78rem;
  color: #b8c2d4;
  white-space: nowrap;
}

.app-top .who button {
  background: none;
  color: #b8c2d4;
  text-decoration: underline;
  font-size: 0.78rem;
  padding: 0 0 0 6px;
}

.app-top h1 { font-size: 1.15rem; color: #ffffff; margin-top: 2px; }

.app-top .day-sub { font-size: 0.82rem; color: #b8c2d4; margin-top: 1px; }

.offline-banner {
  background: var(--red-line);
  color: #ffffff;
  text-align: center;
  font-size: 0.85rem;
  padding: 6px 10px;
}

.toolbar {
  padding: 12px 14px 8px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}

.searchbox { position: relative; }

.searchbox input { padding-left: 38px; border-radius: 999px; }

.searchbox .mag {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.5;
}

.filters {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 10px 2px 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.filters::-webkit-scrollbar { display: none; }

.filters button {
  flex: 0 0 auto;
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 999px;
}

.filters button.on {
  background: var(--navy);
  border-color: var(--navy);
  color: #ffffff;
}

.roster { flex: 1; padding: 4px 14px 90px; }

.sec-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 4px 6px;
  cursor: pointer;
  user-select: none;
}

.sec-head .sec-name { font-weight: 700; font-size: 0.95rem; color: var(--navy); }

.sec-head .sec-count {
  font-size: 0.78rem;
  color: var(--muted);
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}

.sec-head .tri { font-size: 0.7rem; color: var(--muted); margin-right: 6px; }

.stu {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.stu:active { background: #f6f8fb; }

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

.stu-room { font-size: 0.82rem; color: var(--muted); }

.chip-status {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

.st-waiting { background: #eef1f6; color: var(--muted); }
.st-pickup { background: var(--amber-soft); color: var(--amber); }
.st-bins { background: var(--blue-soft); color: var(--blue-line); }
.st-staging { background: var(--purple-soft); color: var(--purple-line); }
.st-room { background: var(--green-soft); color: var(--green-line); }

.empty-note {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: 0.95rem;
}

.progress-strip {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--navy);
  color: #ffffff;
  display: flex;
  justify-content: space-around;
  padding: 10px 8px calc(10px + env(safe-area-inset-bottom));
  z-index: 20;
}

.progress-strip .pcell { text-align: center; }

.progress-strip .pnum { font-weight: 700; font-size: 1.05rem; }

.progress-strip .plab {
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #b8c2d4;
}

/* ------------------------- student detail ------------------------- */

.detail-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 40;
  overflow-y: auto;
}

.detail-inner { max-width: 640px; margin: 0 auto; padding-bottom: 40px; }

.detail-head {
  background: var(--navy);
  color: #ffffff;
  padding: 14px 16px 16px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.detail-head .backbtn {
  background: none;
  color: #b8c2d4;
  font-size: 0.9rem;
  padding: 0 0 8px;
}

.detail-head h2 { color: #ffffff; font-size: 1.3rem; }

.detail-head .meta { font-size: 0.85rem; color: #b8c2d4; margin-top: 3px; }

.detail-head .meta a { color: #d8b45f; text-decoration: none; }

.detail-body { padding: 16px 14px; }

.det-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
}

.steps { display: flex; flex-direction: column; gap: 0; }

.step {
  position: relative;
  padding: 0 0 18px 26px;
}

.step::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d7dde6;
}

.step::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 20px;
  bottom: 2px;
  width: 2px;
  background: #e3e8ef;
}

.step:last-child { padding-bottom: 0; }

.step:last-child::after { display: none; }

.step.done::before { background: var(--green-line); }

.step.now::before { background: var(--amber); box-shadow: 0 0 0 4px var(--amber-soft); }

.step-name { font-weight: 700; font-size: 0.95rem; }

.step-info { font-size: 0.82rem; color: var(--muted); }

.sms-sent {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--green-line);
  background: var(--green-soft);
  border-radius: 999px;
  padding: 2px 9px;
  margin-top: 3px;
}

.bin-pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; }

.bin-pills span {
  background: var(--blue-soft);
  color: var(--blue-line);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 3px 10px;
  border-radius: 999px;
}

.bin-pills span .x {
  margin-left: 6px;
  cursor: pointer;
  opacity: 0.7;
}

.action-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }

.btn-row { display: flex; gap: 10px; }

.btn-row > * { flex: 1; }

.auto-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 13px 16px;
  margin-bottom: 14px;
}

.auto-label { font-weight: 700; font-size: 0.92rem; }

.auto-note { font-size: 0.78rem; color: var(--muted); }

.toggle-pill {
  width: 46px;
  height: 27px;
  border-radius: 999px;
  background: var(--green-line);
  position: relative;
  cursor: pointer;
  flex: 0 0 auto;
}

.toggle-pill::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #ffffff;
}

.toggle-pill.off { background: #cdd4de; }

.toggle-pill.off::after { right: auto; left: 3px; }

.detail-log { font-size: 0.8rem; color: var(--muted); }

.detail-log .logrow { padding: 5px 0; border-top: 1px solid var(--line); }

.undo-row { text-align: center; margin-top: 6px; }

/* ------------------------- scanner ------------------------- */

.scan-overlay {
  position: fixed;
  inset: 0;
  background: var(--navy);
  z-index: 60;
  display: flex;
  flex-direction: column;
  color: #ffffff;
}

.scan-head {
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.scan-head h3 { color: #ffffff; font-size: 1.05rem; }

.scan-head button { background: none; color: #b8c2d4; font-size: 0.95rem; }

#qr-reader { width: 100%; max-width: 480px; margin: 0 auto; }

.scan-body { flex: 1; overflow-y: auto; padding: 0 16px 20px; }

.scan-feedback {
  text-align: center;
  min-height: 1.5em;
  font-size: 0.95rem;
  padding: 10px;
}

.scan-feedback.ok { color: #7fd8a8; }

.scan-feedback.bad { color: #f2a0a0; }

.scan-manual { display: flex; gap: 8px; margin: 10px auto; max-width: 480px; }

.scan-manual button { flex: 0 0 auto; }

.scan-list { max-width: 480px; margin: 6px auto 14px; }

.scan-list .bin-pills span { background: rgba(255, 255, 255, 0.15); color: #ffffff; }

.scan-done-wrap { max-width: 480px; margin: 0 auto; }

/* ------------------------- toast ------------------------- */

.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: #ffffff;
  padding: 11px 20px;
  border-radius: 999px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  z-index: 80;
  max-width: 90vw;
  text-align: center;
}

.toast.bad { background: var(--red-line); }

/* ------------------------- admin ------------------------- */

.admin-shell { max-width: 1100px; margin: 0 auto; padding: 20px 18px 60px; }

.admin-mast {
  background: var(--navy);
  color: #ffffff;
  border-radius: var(--radius-lg);
  padding: 20px 26px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  box-shadow: var(--shadow);
}

.admin-mast h1 { color: #ffffff; font-size: 1.4rem; }

.admin-mast .eyebrow {
  margin: 0 0 4px;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #d8b45f;
}

.admin-mast .who { color: #b8c2d4; font-size: 0.9rem; }

.admin-mast .who button {
  background: none;
  color: #b8c2d4;
  text-decoration: underline;
  padding: 0 0 0 6px;
  font-size: 0.9rem;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 18px 0;
}

.admin-tabs button {
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600;
  padding: 10px 18px;
  border-radius: 999px;
}

.admin-tabs button.on {
  background: var(--navy);
  border-color: var(--navy);
  color: #ffffff;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  margin-bottom: 18px;
}

.panel h2 { font-size: 1.15rem; margin-bottom: 12px; }

.panel h3 { font-size: 1rem; margin: 16px 0 8px; }

.panel .note { color: var(--muted); font-size: 0.9rem; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 6px;
}

.stat-tile {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  text-align: center;
}

.stat-tile .num { font-size: 1.7rem; font-weight: 700; color: var(--navy); }

.stat-tile .lab {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.bar-outer {
  background: #eef1f6;
  border-radius: 999px;
  height: 12px;
  overflow: hidden;
  margin: 6px 0 2px;
}

.bar-inner { background: var(--green-line); height: 100%; border-radius: 999px; }

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.data th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  padding: 8px 10px;
  border-bottom: 2px solid var(--line);
}

table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }

table.data tr:hover td { background: #f6f8fb; }

.pill { font-size: 0.72rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; }

.pill-ok { background: var(--green-soft); color: var(--green-line); }
.pill-warn { background: var(--amber-soft); color: var(--amber); }
.pill-bad { background: var(--red-soft); color: var(--red-line); }
.pill-mut { background: #eef1f6; color: var(--muted); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.form-grid label {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
}

.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }

.inline-form > div { flex: 1; min-width: 160px; }

.inline-form button { flex: 0 0 auto; }

.map-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.map-grid .maprow { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }

.map-grid .csv-col { font-weight: 700; font-size: 0.88rem; margin-bottom: 5px; }

.map-grid .csv-sample { font-size: 0.75rem; color: var(--muted); margin-bottom: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.code-big {
  font-family: ui-monospace, Menlo, monospace;
  font-weight: 700;
  letter-spacing: 0.12em;
  background: var(--amber-soft);
  color: var(--navy);
  border-radius: var(--radius-sm);
  padding: 3px 10px;
  display: inline-block;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 30, 61, 0.5);
  z-index: 90;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: #ffffff;
  border-radius: var(--radius-lg);
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}

.modal-card h3 { margin-bottom: 14px; font-size: 1.1rem; }

/* ------------------------- QR print sheet ------------------------- */

.qr-sheet { display: none; }

@media print {
  body * { visibility: hidden; }
  .qr-sheet, .qr-sheet * { visibility: visible; }
  .qr-sheet {
    display: grid !important;
    position: absolute;
    inset: 0;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
  }
  .qr-cell {
    border: 1px dashed #999999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 18px 8px;
    page-break-inside: avoid;
    height: 3.4in;
  }
  .qr-cell .qr-code-label {
    font-family: ui-monospace, Menlo, monospace;
    font-weight: 700;
    font-size: 20px;
    margin-top: 10px;
  }
  .qr-cell .qr-brand { font-size: 11px; color: #555555; margin-top: 2px; }

  .crew-print, .crew-print * { visibility: visible; }
  .crew-print { display: block !important; position: absolute; inset: 0; padding: 30px; }
}

.crew-print { display: none; }

@media (max-width: 640px) {
  .admin-shell { padding: 12px 10px 40px; }
  .panel { padding: 16px 14px; }
}
