:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --border: #dde3ea;
  --text: #16232e;
  --muted: #64748b;
  --brand: #0f766e;
  --brand-dark: #0b544e;
  --brand-tint: #e6f4f2;
  --green: #15803d;
  --green-tint: #e7f6ec;
  --amber: #b45309;
  --amber-tint: #fdf3e3;
  --red: #b91c1c;
  --red-tint: #fdeceb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 35, 46, .06), 0 6px 20px rgba(16, 35, 46, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Arabic", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ------------------------------------------------------------- structure */

.topbar {
  background: var(--brand);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand {
  font-weight: 700;
  letter-spacing: .3px;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar .brand small {
  font-weight: 400;
  opacity: .85;
  font-size: 12px;
  letter-spacing: .2px;
}

.topbar .spacer { flex: 1; }

.topbar a, .topbar button.linklike {
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  opacity: .9;
  background: none;
  border: 0;
  cursor: pointer;
  font-family: inherit;
  padding: 6px 8px;
  border-radius: 8px;
}

.topbar a:hover, .topbar button.linklike:hover {
  opacity: 1;
  background: rgba(255, 255, 255, .12);
}

.wrap {
  max-width: 1040px;
  margin: 0 auto;
  padding: 20px 16px 64px;
}

.wrap.narrow { max-width: 460px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 12px; }
.sub { color: var(--muted); font-size: 14px; margin: 0 0 18px; }

/* ---------------------------------------------------------------- forms */

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

input[type=text], input[type=password], input[type=date], select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px; /* 16px stops iOS zooming on focus */
  font-family: inherit;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}

textarea { min-height: 160px; resize: vertical; font-size: 14px; }

.field { margin-bottom: 16px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 140px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: var(--brand);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.full { width: 100%; }

.btn.secondary {
  background: #fff;
  color: var(--text);
  border-color: var(--border);
}
.btn.secondary:hover { background: #f1f5f8; }

.btn.danger { background: var(--red); }
.btn.danger:hover { background: #991b1b; }

.btn.small { padding: 7px 12px; font-size: 13px; }

/* -------------------------------------------------------------- messages */

.msg {
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}
.msg.error { background: var(--red-tint); color: var(--red); border-color: #f5c6c4; }
.msg.ok { background: var(--green-tint); color: var(--green); border-color: #bfe3cc; }
.msg.info { background: var(--brand-tint); color: var(--brand-dark); border-color: #b9ddd8; }
.msg:empty { display: none; }

/* ---------------------------------------------------------------- table */

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

th, td {
  text-align: left;
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  background: #f7f9fb;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--muted);
  position: sticky;
  top: 0;
}

td.name { white-space: normal; min-width: 180px; font-weight: 500; }
tbody tr:hover { background: #fafcfd; }
tbody tr.is-absent td.name { color: var(--muted); }

.pill {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .2px;
}
.pill.present { background: var(--green-tint); color: var(--green); }
.pill.absent { background: #eef1f4; color: var(--muted); }
.pill.extra { background: var(--amber-tint); color: var(--amber); }

/* ---------------------------------------------------------------- stats */

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

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}

.stat .n { font-size: 26px; font-weight: 700; line-height: 1.1; }
.stat .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; margin-top: 4px; }
.stat.present .n { color: var(--green); }
.stat.absent .n { color: var(--muted); }
.stat.rate .n { color: var(--brand); }

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

.scanner {
  position: relative;
  background: #0b1620;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 3 / 4;
  max-height: 62vh;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.scanner video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scanner .reticle {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: 62%;
  aspect-ratio: 1;
  border: 3px solid rgba(255, 255, 255, .85);
  border-radius: 18px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35);
  pointer-events: none;
}

.scanner .placeholder {
  color: #93a4b3;
  font-size: 14px;
  padding: 24px;
  text-align: center;
  position: absolute;
}

.feedback {
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 15px;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}

.feedback .icon { font-size: 22px; line-height: 1; }
.feedback .who { font-weight: 700; color: var(--text); display: block; font-size: 16px; }
.feedback .note { font-size: 13px; }

.feedback.marked { background: var(--green-tint); border-color: #bfe3cc; color: var(--green); }
.feedback.already { background: var(--amber-tint); border-color: #f0d9b0; color: var(--amber); }
.feedback.unknown { background: var(--red-tint); border-color: #f5c6c4; color: var(--red); }

.recent { list-style: none; margin: 0; padding: 0; font-size: 14px; }
.recent li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.recent li:last-child { border-bottom: 0; }
.recent .t { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.recent:empty::after {
  content: "Scans will appear here.";
  color: var(--muted);
  font-size: 14px;
}

/* ---------------------------------------------------------------- misc */

.session-list { list-style: none; margin: 0; padding: 0; }
.session-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.session-list li:last-child { border-bottom: 0; }
.session-list .meta { flex: 1; min-width: 0; }
.session-list .code { font-weight: 700; }
.session-list .when { color: var(--muted); font-size: 13px; }

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 16px;
}
.toolbar .grow { flex: 1; min-width: 160px; }

.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 12px;
  font-size: 14px;
}

.hint { font-size: 13px; color: var(--muted); margin-top: 6px; }

.hidden { display: none !important; }

/* --------------------------------------------------------------- dialog */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 40px rgba(16, 35, 46, .22);
  padding: 22px;
  max-width: 420px;
  width: calc(100% - 32px);
  color: var(--text);
  background: var(--surface);
}

dialog::backdrop { background: rgba(16, 35, 46, .45); }
dialog h2 { font-size: 18px; }

/* Buttons sit side by side in the dialog rather than stretching. */
dialog .toolbar > .btn { flex: 0 0 auto; }

@media (max-width: 560px) {
  .wrap { padding: 14px 12px 56px; }
  .card { padding: 16px; }
  .btn { padding: 12px 14px; }

  /* The nav does not fit beside the logo on a phone, so let it wrap onto its
     own line rather than running off the edge of the screen. */
  .topbar {
    flex-wrap: wrap;
    gap: 2px;
    padding: 10px 12px;
  }
  .topbar .brand { flex: 1 0 100%; margin-bottom: 4px; }
  .topbar .spacer { display: none; }
  .topbar a, .topbar button.linklike { padding: 6px 10px; font-size: 13px; }
}
