:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #1a2233;
  --ink-soft: #5b6472;
  --border: #e3e7ee;
  --brand: #3457d5;
  --brand-dark: #263f9e;
  --accent: #16a34a;
  --accent-dark: #128a3e;
  --danger: #dc2626;
  --danger-dark: #b91c1c;
  --warn-bg: #fffbeb;
  --warn-border: #fde68a;
  --warn-ink: #92400e;
  --ghost: #eef1f6;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 25, 40, 0.04), 0 8px 24px rgba(20, 25, 40, 0.06);
  font-synthesis: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 { margin: 0 0 4px; }
h2 { font-size: 17px; }
p { margin: 0; }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  padding: 11px 16px;
  transition: transform .05s ease, opacity .15s ease, background .15s ease;
}
button:active { transform: scale(0.98); }
button:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-dark); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: var(--accent-dark); }
.btn-danger { background: var(--danger); color: #fff; width: 100%; }
.btn-danger:hover:not(:disabled) { background: var(--danger-dark); }
.btn-ghost { background: var(--ghost); color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: #e2e6ee; }
.btn-sm { width: auto; padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }
.btn-danger.btn-sm { width: auto; }

.field-row { display: flex; align-items: flex-end; gap: 10px; }
.field-row .btn-primary { flex-shrink: 0; }
@media (max-width: 500px) {
  .field-row { flex-direction: column; align-items: stretch; }
}

input, select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--ink);
  background: #fff;
}
input:focus, select:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

.error-msg { color: var(--danger); font-size: 13px; min-height: 1em; margin-top: 10px; }
.localhost-warning {
  background: var(--warn-bg);
  border-bottom: 1px solid var(--warn-border);
  color: var(--warn-ink);
  font-size: 13.5px;
  line-height: 1.5;
  padding: 12px 20px;
  text-align: center;
}
.localhost-warning code {
  background: rgba(0, 0, 0, 0.06);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12.5px;
}
.card-sub { color: var(--ink-soft); font-size: 13px; margin: 4px 0 16px; }
.empty-state { color: var(--ink-soft); font-size: 13.5px; text-align: center; padding: 18px 8px; }
.mt-16 { margin-top: 16px; }

/* ---------- Auth (index.html) ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 32px 28px;
}
.auth-eyebrow {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand);
  margin-bottom: 10px;
}
.auth-sub { color: var(--ink-soft); font-size: 13.5px; margin: 4px 0 22px; }
.role-toggle {
  display: flex;
  background: var(--ghost);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 22px;
}
.role-toggle button {
  flex: 1;
  background: transparent;
  color: var(--ink-soft);
  padding: 9px 10px;
  border-radius: 8px;
}
.role-toggle button.active { background: #fff; color: var(--ink); box-shadow: var(--shadow); }
.auth-switch { text-align: center; font-size: 13.5px; color: var(--ink-soft); margin-top: 18px; }
.auth-switch button {
  background: none;
  color: var(--brand);
  padding: 0 0 0 4px;
  font-weight: 700;
}

/* ---------- App shell (lecturer.html / student.html) ---------- */
.app-shell { min-height: 100vh; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}
.brand-name { font-weight: 700; font-size: 15px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.pill {
  background: var(--ghost);
  color: var(--ink);
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
}

.container { max-width: 1080px; margin: 0 auto; padding: 22px; }

.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  margin-bottom: 22px;
}
.tab {
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }
.tab-panel { animation: fadeIn .15s ease; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .container { padding: 16px; }
  .topbar { padding: 12px 16px; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card.stat { text-align: center; }
.flex-between { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

table { width: 100%; border-collapse: collapse; margin-top: 6px; font-size: 13.5px; }
thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
}
tbody td { padding: 9px 6px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }

.stat-num { font-size: 30px; font-weight: 800; color: var(--brand); line-height: 1.1; }
.stat-label { color: var(--ink-soft); font-size: 12.5px; margin-top: 4px; }

.badge-present, .badge-absent {
  display: inline-block;
  font-size: 12px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
}
.badge-present { background: #dcfce7; color: #15803d; }
.badge-absent { background: #fee2e2; color: #b91c1c; }

.progress-bar { height: 10px; background: var(--ghost); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s ease; }

/* ---------- Live session / QR ---------- */
.session-live { display: flex; flex-direction: column; align-items: center; gap: 14px; text-align: center; }
.qr-ring-wrap { position: relative; width: 240px; height: 240px; }
.qr-ring-wrap svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.qr-ring-bg { fill: none; stroke: var(--ghost); stroke-width: 6; }
.qr-ring-fg { fill: none; stroke: var(--brand); stroke-width: 6; stroke-linecap: round; }
#qr-canvas-holder {
  position: absolute;
  inset: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
}
#qr-canvas-holder canvas { width: 100%; height: 100%; }
.session-meta { display: flex; flex-direction: column; gap: 2px; }
.code {
  font-family: "SFMono-Regular", Consolas, Menlo, monospace;
  font-size: 13px;
  letter-spacing: 0.03em;
  color: var(--ink-soft);
  word-break: break-all;
}

/* ---------- Check-in (student.html) ---------- */
#reader { border-radius: 12px; overflow: hidden; margin-top: 10px; }
#scan-result { margin-top: 14px; display: flex; flex-direction: column; gap: 10px; }

/* ---------- Toasts ---------- */
#toast-host {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 50;
  width: min(92vw, 380px);
}
.toast {
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s ease, transform .2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { background: var(--accent-dark); }
.toast-error { background: var(--danger-dark); }
