/* ── Reset & Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { overflow-x: hidden; }

body {
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: #f3f4f6;
  color: #111827;
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  max-width: 100vw;
}

/* ── Nav ──────────────────────────────────────────────────────── */
.navbar {
  background: #1e3a5f;
  color: white;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  height: 56px;
  gap: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: 0 1px 4px rgba(0,0,0,.3);
}
.nav-brand a {
  color: white;
  text-decoration: none;
  font-size: 1.05rem;
  font-weight: 700;
  white-space: nowrap;
}
.nav-links {
  display: flex;
  gap: .25rem;
  flex: 1;
}
.nav-links a {
  color: rgba(255,255,255,.8);
  text-decoration: none;
  font-size: .875rem;
  padding: .3rem .65rem;
  border-radius: 5px;
  transition: background .15s;
}
.nav-links a:hover { background: rgba(255,255,255,.15); color: white; }
.nav-user {
  display: flex;
  align-items: center;
  gap: .75rem;
  font-size: .875rem;
  white-space: nowrap;
}
.nav-user > span { color: rgba(255,255,255,.85); }
.nav-user a { color: rgba(255,255,255,.6); text-decoration: none; }
.nav-user a:hover { color: white; }
.badge-admin {
  background: #f59e0b;
  color: white;
  font-size: .7rem;
  font-weight: 700;
  padding: .15rem .45rem;
  border-radius: 9999px;
  letter-spacing: .03em;
}

/* ── Container ────────────────────────────────────────────────── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* ── Page header ──────────────────────────────────────────────── */
.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; color: #1e3a5f; }
.page-header p  { color: #6b7280; margin-top: .25rem; font-size: .875rem; }

/* Flex variant used on lab-section and scores headers */
.page-header-flex {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ── Cards ────────────────────────────────────────────────────── */
.card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.card-title { font-size: .95rem; font-weight: 600; color: #374151; }

/* ── Grid ─────────────────────────────────────────────────────── */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1.5rem; }

/* ── Forms ────────────────────────────────────────────────────── */
.form-group { margin-bottom: 1rem; }
.form-group label {
  display: block;
  font-size: .875rem;
  font-weight: 500;
  color: #374151;
  margin-bottom: .375rem;
}
.form-control {
  width: 100%;
  padding: .5rem .75rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: .875rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.form-control:focus {
  border-color: #1a56db;
  box-shadow: 0 0 0 3px rgba(26,86,219,.1);
}

/* ── Buttons ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s, opacity .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn-primary   { background: #1a56db; color: white; }
.btn-danger    { background: #ef4444; color: white; }
.btn-warning   { background: #f59e0b; color: white; }
.btn-success   { background: #10b981; color: white; }
.btn-secondary { background: #6b7280; color: white; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

/* ── Alerts ───────────────────────────────────────────────────── */
.alert {
  padding: .75rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: .875rem;
}
.alert-success { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.alert-danger  { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-info    { background: #eff6ff; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── Tables ───────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: .875rem; }
th {
  background: #f9fafb;
  border-bottom: 2px solid #e5e7eb;
  padding: .6rem .75rem;
  text-align: left;
  font-weight: 600;
  color: #374151;
  white-space: nowrap;
}
td {
  border-bottom: 1px solid #f3f4f6;
  padding: .5rem .75rem;
  vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td:not(.cp-cell) { background: #fafafa; }

/* ── Checkpoint table layout ──────────────────────────────────── */
.cp-table td {
  padding: .7rem .5rem;
  border-bottom: 2px solid #e2e8f0;
}
.cp-table tr:last-child td { border-bottom: none; }
.cp-table .col-name {
  min-width: 120px;
  max-width: 150px;
  word-break: break-word;
  position: sticky;
  left: 0;
  z-index: 1;
  background: white;
  box-shadow: 2px 0 4px rgba(0,0,0,.06);
}
.cp-table thead .col-name {
  background: #f9fafb;
  z-index: 2;
}
.cp-table tr:hover .col-name { background: #fafafa; }
.cp-table .col-id   { min-width: 110px; }
.cp-table .col-cp   { width: 52px; min-width: 52px; text-align: center; padding: .4rem .3rem; }
.cp-table .col-quiz  { width: 64px; min-width: 64px; text-align: center; }
.cp-table .col-score { width: 70px; min-width: 70px; text-align: right; }

/* ── Credit cells ─────────────────────────────────────────────── */
.cp-cell {
  text-align: center;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  transition: filter .1s;
  user-select: none;
  border-radius: 0;
}
.cp-cell[data-clickable]:hover { filter: brightness(.88); }

.credit-full     { background: #d1fae5; color: #065f46; }
.credit-half     { background: #fef3c7; color: #92400e; }
.credit-none     { background: #fee2e2; color: #991b1b; }
.credit-unmarked { background: #f3f4f6; color: #9ca3af; }

/* ── Quiz cell ────────────────────────────────────────────────── */
.quiz-cell {
  text-align: center;
  color: #374151;
  font-weight: 500;
}
.quiz-editable { cursor: pointer; }
.quiz-editable:hover { background: #eff6ff !important; }
.quiz-input {
  width: 52px;
  padding: .2rem .3rem;
  text-align: center;
  border: 1px solid #1a56db;
  border-radius: 4px;
  font-size: .875rem;
  outline: none;
}

/* ── Score columns ────────────────────────────────────────────── */
.cp-score    { text-align: right; color: #4b5563; font-weight: 500; }
.total-score { text-align: right; color: #1e3a5f; font-weight: 700; }

/* ── Login ────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a5f 0%, #1a56db 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}
.login-card {
  background: white;
  border-radius: 12px;
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-logo { text-align: center; margin-bottom: 1.75rem; }
.login-logo h1 { font-size: 1.35rem; color: #1e3a5f; font-weight: 700; margin-top: .5rem; }
.login-logo p  { color: #6b7280; font-size: .875rem; }

/* ── Status indicators ────────────────────────────────────────── */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: .4rem;
}
.status-active   { background: #10b981; }
.status-inactive { background: #d1d5db; }

/* ── Connection indicator ─────────────────────────────────────── */
.conn-status { display: flex; align-items: center; gap: .4rem; font-size: .8rem; color: #6b7280; }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: #d1d5db; transition: background .3s; }
.conn-dot.connected    { background: #10b981; }
.conn-dot.disconnected { background: #ef4444; }

/* ── Toast ────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: #1f2937;
  color: white;
  padding: .75rem 1.25rem;
  border-radius: 8px;
  font-size: .875rem;
  z-index: 999;
  display: none;
  max-width: 350px;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
  animation: fadeIn .2s ease;
}
.toast.toast-error   { background: #dc2626; }
.toast.toast-success { background: #059669; }
@keyframes fadeIn { from { opacity:0; transform:translateY(6px) } to { opacity:1; transform:translateY(0) } }

/* ── Section tabs ─────────────────────────────────────────────── */
.section-tabs { display: flex; gap: .5rem; margin-bottom: 1rem; }
.section-tab {
  padding: .45rem 1rem;
  border-radius: 6px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid #e5e7eb;
  background: white;
  color: #374151;
  transition: background .15s, color .15s;
}
.section-tab.active { background: #1a56db; color: white; border-color: #1a56db; }

/* ── Stat cards ───────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: .75rem;
  margin-bottom: 1rem;
}
.stat-card {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1rem;
}
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; color: #1e3a5f; }
.stat-card .stat-label { font-size: .8rem; color: #6b7280; margin-top: .2rem; }

/* ── Proctor list ─────────────────────────────────────────────── */
.proctor-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .65rem 0;
  border-bottom: 1px solid #f3f4f6;
}
.proctor-item:last-of-type { border-bottom: none; }
.proctor-name  { font-weight: 500; font-size: .875rem; }
.proctor-email { font-size: .8rem; color: #6b7280; }
.proctor-actions { display: flex; gap: .4rem; flex-shrink: 0; }
.reset-form { background: #f9fafb; border-radius: 6px; padding: .75rem !important; margin-bottom: .5rem; }

/* ── Empty state ──────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 4rem 2rem; }
.empty-state h2 { font-size: 1.25rem; font-weight: 600; color: #374151; }
.empty-state p  { color: #6b7280; margin-top: .5rem; font-size: .875rem; }

/* ── Error page ───────────────────────────────────────────────── */
.error-code {
  font-size: 5rem;
  font-weight: 800;
  color: rgba(255,255,255,.3);
  line-height: 1;
  margin-bottom: .5rem;
}
.error-msg { font-size: 1.5rem; font-weight: 600; }

/* ── Footer ───────────────────────────────────────────────────── */
.footer {
  text-align: center;
  padding: 1.5rem;
  color: #9ca3af;
  font-size: .8rem;
  border-top: 1px solid #e5e7eb;
  background: white;
  margin-top: 2rem;
}

/* ── details/summary ─────────────────────────────────────────── */
details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }

/* ── Mobile ───────────────────────────────────────────────────── */
@media (max-width: 640px) {
  /* Navbar: hide links, keep brand + logout compact */
  .navbar {
    padding: 0 1rem;
    gap: .75rem;
    height: 48px;
  }
  .nav-links { display: none; }
  .nav-brand a { font-size: .95rem; }
  .nav-user { gap: .5rem; font-size: .8rem; }
  .nav-user > span { display: none; } /* hide username, show badge+logout only */
  .badge-admin { font-size: .65rem; padding: .1rem .35rem; }

  /* Container */
  .container { padding: 1rem; }

  /* Page headers */
  .page-header h1 { font-size: 1.25rem; }
  .page-header-flex {
    flex-direction: column;
    align-items: flex-start;
    gap: .75rem;
  }

  /* Grids collapse to single column */
  .grid-2, .grid-3 { grid-template-columns: 1fr; }

  /* Cards */
  .card { padding: 1rem; }

  /* Checkpoint table on mobile */
  .cp-table .col-name { min-width: 90px; max-width: 110px; font-size: .8rem; }
  .cp-table .col-cp   { width: 42px; min-width: 42px; }
  .cp-table td        { padding: .8rem .35rem; } /* taller rows = easier tap targets */
  .cp-cell            { font-size: .9rem; }

  /* Admin stat grid */
  .stat-grid { grid-template-columns: 1fr 1fr; }

  /* Toast: full width at bottom */
  .toast {
    left: 1rem;
    right: 1rem;
    max-width: none;
    bottom: 1rem;
  }
}
