:root {
  --primary: #1e3a5f;
  --primary-light: #2d5a8e;
  --accent: #e8a020;
  --success: #27ae60;
  --error: #e74c3c;
  --warn: #f39c12;
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #2c3e50;
  --muted: #7f8c8d;
  --border: #dde3ea;
  --radius: 12px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
.app-header {
  background: var(--primary);
  color: #fff;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 100;
}
.app-header .logo { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.3px; }
.app-header .subtitle { font-size: 0.78rem; opacity: 0.75; margin-top: 1px; }
.app-header .spacer { flex: 1; }

/* ── Main content ── */
.app-main {
  flex: 1;
  padding: 20px 16px;
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* ── Cards ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--primary);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 8px;
  border: none;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-decoration: none;
  width: 100%;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-light); }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover:not(:disabled) { background: #d4911a; }
.btn-success { background: var(--success); color: #fff; }
.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover:not(:disabled) { background: var(--primary); color: #fff; }
.btn-danger { background: var(--error); color: #fff; }
.btn-sm { padding: 8px 14px; font-size: 0.82rem; width: auto; }

/* ── Form inputs ── */
.form-group { margin-bottom: 14px; }
.form-label { font-size: 0.83rem; font-weight: 500; color: var(--muted); margin-bottom: 6px; display: block; }
.form-input {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s;
}
.form-input:focus { outline: none; border-color: var(--primary); }
.form-select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  background: #fff;
  cursor: pointer;
}

/* ── Status badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-success { background: #d4efdf; color: #1e8449; }
.badge-error   { background: #fde8e6; color: #c0392b; }
.badge-warn    { background: #fef5e4; color: #b7770d; }
.badge-info    { background: #dbeafe; color: #1e40af; }

/* ── Alert ── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 14px;
}
.alert-error { background: #fde8e6; color: #c0392b; border-left: 3px solid var(--error); }
.alert-success { background: #d4efdf; color: #1e8449; border-left: 3px solid var(--success); }
.alert-warn { background: #fef5e4; color: #b7770d; border-left: 3px solid var(--warn); }
.alert-info { background: #dbeafe; color: #1e40af; border-left: 3px solid #3b82f6; }

/* ── Step indicator ── */
.steps {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  position: relative;
}
.steps::before {
  content: '';
  position: absolute;
  top: 16px;
  left: 24px;
  right: 24px;
  height: 2px;
  background: var(--border);
  z-index: 0;
}
.step {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  position: relative;
  z-index: 1;
}
.step-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--border);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  transition: all 0.2s;
}
.step.active .step-circle { background: var(--primary); color: #fff; }
.step.done .step-circle { background: var(--success); color: #fff; }
.step-label { font-size: 0.7rem; color: var(--muted); text-align: center; }
.step.active .step-label, .step.done .step-label { color: var(--text); font-weight: 500; }

/* ── Camera ── */
.camera-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  margin-bottom: 16px;
}
.camera-wrapper video,
.camera-wrapper canvas {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.camera-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  padding: 16px;
  background: linear-gradient(transparent 60%, rgba(0,0,0,0.5));
}
.face-guide {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -55%);
  width: 55%;
  aspect-ratio: 3/4;
  border: 3px solid rgba(255,255,255,0.6);
  border-radius: 50% 50% 45% 45%;
  box-shadow: 0 0 0 9999px rgba(0,0,0,0.3);
}
.face-guide.green { border-color: #27ae60; box-shadow: 0 0 0 9999px rgba(0,0,0,0.3), 0 0 20px rgba(39,174,96,0.5); }
.liveness-status {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.6);
  color: #fff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.8rem;
  white-space: nowrap;
}

/* ── QR code container ── */
.qr-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
}
.qr-wrapper canvas, .qr-wrapper img { border-radius: 8px; }
.qr-timer {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.qr-timer .countdown {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}
.qr-timer .countdown.urgent { color: var(--error); }

/* ── Data table ── */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: #f0f4f8;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #f8fafc; }

/* ── Avatar / name display ── */
.student-info {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: linear-gradient(135deg, #f0f4f8, #e8edf3);
  border-radius: 10px;
  margin-bottom: 16px;
}
.avatar {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  font-weight: 700;
  flex-shrink: 0;
}
.student-name { font-weight: 700; font-size: 1rem; }
.student-mssv { font-size: 0.8rem; color: var(--muted); margin-top: 2px; }
.student-email { font-size: 0.78rem; color: var(--primary); margin-top: 2px; }

/* ── Loading spinner ── */
.spinner {
  width: 36px; height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 20px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Tab bar (teacher) ── */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  gap: 0;
}
.tab-btn {
  flex: 1;
  padding: 10px 8px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Countdown ring ── */
.timer-ring {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.timer-ring svg { transform: rotate(-90deg); }
.timer-ring .ring-text {
  position: absolute;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
}

/* ── Utils ── */
.text-center { text-align: center; }
.text-muted { color: var(--muted); font-size: 0.85rem; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none !important; }
.w-full { width: 100%; }

/* ── Toast ── */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #2c3e50;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 0.88rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.25);
  animation: slideUp 0.25s ease;
  max-width: 320px;
  text-align: center;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--error); }
@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* ── Responsive ── */
@media (min-width: 768px) {
  .app-main { padding: 28px 20px; }
}
