:root {
  /* Brand colours: set these to match the Shalom portal exactly */
  --navy: #0b2351;
  --navy-2: #163266;
  --gold: #cba226;
  --bg: #f6f7fb;
  --card: #fff;
  --text: #1c2433;
  --muted: #6b7587;
  --line: #e3e6eb;
  --green: #1f9d55;
  --red: #d64545;
  --amber: #e08a00;
  --blue: #2563c9;
  --radius: 12px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { margin: 0 0 .5rem; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
a { color: var(--blue); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.right { text-align: right; }
.center { text-align: center; }
.hidden, [hidden] { display: none !important; }

/* ---------- Layout ---------- */
.topbar {
  background: var(--navy); color: #fff; padding: 10px 14px; display: flex; align-items: center; gap: 10px;
  position: sticky; top: 0; z-index: 20;
}
.topbar .brand { font-weight: 700; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .brand span { color: var(--gold); }
.topbar .who { font-size: .8rem; opacity: .85; text-align: right; }
.nav {
  background: var(--navy-2); display: flex; gap: 2px; overflow-x: auto; padding: 0 8px;
  position: sticky; top: 46px; z-index: 19; scrollbar-width: none;
}
.nav::-webkit-scrollbar { display: none; }
.nav a {
  color: #dbe6f7; text-decoration: none; padding: 11px 13px; white-space: nowrap; font-weight: 600; font-size: .92rem;
  border-bottom: 3px solid transparent;
}
.nav a.active { color: #fff; border-bottom-color: var(--gold); }
main { max-width: 1100px; margin: 0 auto; padding: 14px; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin-bottom: 14px;
}
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 140px; }
.grid { display: grid; gap: 12px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.stat .n { font-size: 1.8rem; font-weight: 800; color: var(--navy); line-height: 1.1; }
.stat .l { color: var(--muted); font-size: .82rem; }
.stat.warn .n { color: var(--red); }
.stat.good .n { color: var(--green); }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: 4px; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 11px; border: 1px solid #c9d1de; border-radius: 9px; background: #fff; color: var(--text);
}
input[type=checkbox], input[type=radio] { width: auto; }
textarea { min-height: 120px; resize: vertical; }
.field { margin-bottom: 12px; }
button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 9px; padding: 10px 14px; cursor: pointer;
  background: var(--navy); color: #fff; text-decoration: none; display: inline-block;
}
button:hover { filter: brightness(1.1); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary { background: #e7ecf5; color: var(--navy); }
button.danger { background: var(--red); }
button.good { background: var(--green); }
button.gold { background: var(--gold); color: #3a2c00; }
button.sm { padding: 6px 10px; font-size: .82rem; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; background: #fff; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #f8fafc; white-space: nowrap; }
td.num, th.num { text-align: right; }
.thumb { width: 38px; height: 46px; object-fit: cover; border-radius: 6px; background: #e5e9f0; display: block; }
.thumb.empty { display: grid; place-items: center; color: #9aa6ba; font-size: .7rem; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; }
.badge.green { background: #dff5e8; color: #14753f; }
.badge.red { background: #fde4e4; color: #a82828; }
.badge.amber { background: #fff0d4; color: #9a5d00; }
.badge.gray { background: #e8ecf3; color: #4a566b; }
.bar { height: 8px; background: #e8ecf3; border-radius: 99px; overflow: hidden; min-width: 70px; }
.bar > i { display: block; height: 100%; background: var(--green); }
.code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--navy), var(--navy-2)); }
.login-card { background: #fff; border-radius: 16px; padding: 26px; width: 100%; max-width: 380px; }
.login-card h1 { color: var(--navy); font-size: 1.4rem; }
.err { color: var(--red); font-size: .9rem; margin: 8px 0 0; min-height: 1.2em; }

/* ---------- Scanner ---------- */
.scan-wrap { max-width: 560px; margin: 0 auto; }
.mode-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.mode-toggle button { background: #dfe6f2; color: var(--navy); padding: 14px; font-size: 1.05rem; }
.mode-toggle button.active { background: var(--navy); color: #fff; box-shadow: 0 0 0 3px var(--gold) inset; }
#reader { width: 100%; border-radius: var(--radius); overflow: hidden; background: #000; min-height: 220px; }
#reader video { width: 100% !important; }
.result {
  margin-top: 12px; border-radius: var(--radius); padding: 16px; text-align: center; border: 2px solid var(--line); background: #fff;
  min-height: 110px; display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 4px;
}
.result .photo { width: 96px; height: 116px; object-fit: cover; border-radius: 10px; background: #e5e9f0; }
.result .name { font-size: 1.35rem; font-weight: 800; }
.result .msg { font-weight: 700; }
.result .tm { color: var(--muted); font-size: .9rem; }
.result.ok-in { background: #e5f7ec; border-color: var(--green); }
.result.ok-out { background: #e6effc; border-color: var(--blue); }
.result.dup, .result.queued { background: #fff3da; border-color: var(--amber); }
.result.bad { background: #fde8e8; border-color: var(--red); }
.result.late { background: #fde8e8; border-color: var(--red); }
.manual { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- Misc ---------- */
.toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%); background: #1c2433; color: #fff;
  padding: 11px 16px; border-radius: 10px; z-index: 99; max-width: 90vw; font-weight: 600; box-shadow: 0 6px 24px rgba(0,0,0,.25);
}
.toast.err { background: var(--red); }
dialog#modal { border: 0; border-radius: 14px; padding: 18px; width: min(94vw, 480px); max-height: 90vh; overflow: auto; }
dialog#modal::backdrop { background: rgba(10, 20, 40, .55); }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.tabs button { background: #e7ecf5; color: var(--navy); }
.tabs button.active { background: var(--navy); color: #fff; }
.seg { display: inline-flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.seg label { display: inline-flex; gap: 5px; align-items: center; margin: 0; font-weight: 600; }

/* ---------- Attendance sheet ---------- */
.sheet-head { text-align: center; margin-bottom: 10px; }
.sheet-head h2 { margin: 0; }
table.sheet { font-size: .82rem; }
table.sheet th, table.sheet td { padding: 4px 5px; text-align: center; border: 1px solid #cfd6e2; }
table.sheet td.name, table.sheet th.name { text-align: left; white-space: nowrap; }
table.sheet th.day { writing-mode: vertical-rl; transform: rotate(180deg); height: 58px; font-size: .7rem; padding: 4px 2px; }
.sign-row { display: none; }

/* ---------- ID cards ---------- */
.idgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86mm, 1fr)); gap: 6mm; }
.idcard {
  width: 85.6mm; height: 54mm; border: 1px solid #333; border-radius: 3mm; overflow: hidden; background: #fff; color: #111;
  display: flex; flex-direction: column; page-break-inside: avoid; break-inside: avoid;
}
.ic-head { background: var(--navy); color: #fff; text-align: center; font-weight: 800; font-size: 9pt; padding: 1.6mm 2mm; border-bottom: 1.2mm solid var(--gold); -webkit-print-color-adjust: exact; print-color-adjust: exact; }
.ic-body { display: flex; gap: 3mm; padding: 2mm 3mm 0; flex: 1; min-height: 0; }
.ic-photo { width: 20mm; height: 25mm; object-fit: cover; border: 1px solid #999; background: #eee; }
.ic-info { display: flex; flex-direction: column; justify-content: center; gap: .8mm; font-size: 8.5pt; min-width: 0; }
.ic-info b { font-size: 10pt; line-height: 1.15; }
.ic-bc { text-align: center; padding: 0 3mm 1.6mm; }
.ic-bc svg { max-width: 100%; height: 11mm; }
.sticker { width: 62mm; border: 1px dashed #999; padding: 2mm; text-align: center; font-size: 8pt; page-break-inside: avoid; break-inside: avoid; background: #fff; }
.sticker b { display: block; font-size: 9pt; }
.sticker svg { width: 40mm; height: 20mm; display: block; margin: 1mm auto 0; }
.stickergrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(62mm, 1fr)); gap: 4mm; }

@media (max-width: 600px) {
  main { padding: 10px; }
  .topbar .who { display: none; }
}

@media print {
  body { background: #fff; }
  .topbar, .nav, .noprint, .toast { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; margin: 0; }
  .sign-row { display: block; margin-top: 18mm; }
  .sign-row span { display: inline-block; width: 60mm; border-top: 1px solid #000; margin-right: 20mm; padding-top: 2px; font-size: 9pt; }
  table.sheet { font-size: 8pt; }
  table.sheet th, table.sheet td { padding: 2px 3px; }
  .idgrid, .stickergrid { gap: 4mm; }
  tr { page-break-inside: avoid; }
}

/* ---------- Logo ---------- */
.logo { height: 34px; width: 34px; object-fit: contain; background: #fff; border-radius: 6px; padding: 1px; }
.logo-lg { height: 72px; width: 72px; object-fit: contain; display: block; margin: 0 auto 10px; }
.gold-text { color: #b98a00; font-weight: 700; text-align: center; }
.login-card h1 { text-align: center; }
.ic-head { display: flex; align-items: center; justify-content: center; gap: 2mm; }
.ic-logo { height: 7mm; width: 7mm; object-fit: contain; background: #fff; border-radius: 1mm; }


/* ======== Shalom portal look (matches the school website/portal) ======== */
:root { --serif: "Noto Serif", Georgia, "Times New Roman", serif; --title: #0f224a; }
h1, h2, h3 { font-family: var(--serif); color: var(--title); }
.topbar { background: var(--navy); border-bottom: 3px solid #c4a236; padding: 9px 14px; gap: 12px; position: static; }
.topbar .logo { height: 46px; width: 46px; padding: 3px; border-radius: 50%; background: #fff; object-fit: contain; border: 2px solid #fff; flex: none; }
.topbar .brand { font-family: var(--serif); line-height: 1.15; white-space: normal; }
.brand .b1 { display: block; font-weight: 700; font-size: 1.12rem; letter-spacing: .04em; text-transform: uppercase; color: #fff; }
.brand .b2 { display: block; font-family: system-ui, sans-serif; font-weight: 700; font-size: .62rem; letter-spacing: .2em; text-transform: uppercase; color: var(--gold); }
.topbar .who { color: #cfd8ea; }
.topbar button.secondary { background: var(--gold); color: #fff; border-radius: 999px; padding: 8px 16px; font-size: .85rem; }
.nav { background: transparent; position: static; padding: 14px 14px 2px; max-width: 1100px; margin: 0 auto; gap: 8px; }
.nav a { background: #fff; color: var(--navy); border: 1px solid var(--line); border-radius: 999px; padding: 9px 16px; font-size: .88rem; border-bottom: 1px solid var(--line); }
.nav a.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.card, .stat { border: 0; border-radius: 16px; box-shadow: 0 2px 12px rgba(11, 35, 81, .07); }
.stat .n { font-family: var(--serif); font-weight: 500; }
button, .btn { border-radius: 999px; padding: 10px 18px; }
button.sm { padding: 6px 13px; }
button.secondary { background: #fff; color: var(--navy); border: 1px solid #d5dcea; }
button.gold { background: var(--gold); color: #fff; }
input, select, textarea { border-radius: 10px; border-color: #d5dcea; }
th { background: #f6f7fb; }
.tabs button { background: #fff; color: var(--navy); border: 1px solid var(--line); }
.tabs button.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.mode-toggle button { border-radius: 14px; background: #fff; border: 1px solid #d5dcea; }
.mode-toggle button.active { background: var(--navy); border-color: var(--navy); box-shadow: 0 0 0 3px var(--gold) inset; }
.login-wrap { background: linear-gradient(170deg, var(--navy), #163266); }
.login-card { border-radius: 20px; border-top: 4px solid var(--gold); }
.login-card h1 { font-size: 1.3rem; }
.logo-lg { height: 92px; width: 92px; }
@media (max-width: 600px) { .topbar .who { display: none; } }
@media print {
  .topbar, .nav { display: none !important; }
  .stickergrid { grid-template-columns: repeat(3, 62mm); justify-content: space-between; gap: 5mm 2mm; }
}

.result .detail { font-size: 1.05rem; margin: 2px 0; }
