:root {
  --slate-950: #06080f;
  --slate-900: #0b0e1a;
  --slate-800: #111827;
  --slate-700: #1a2235;
  --slate-300: #64748b;
  --slate-100: #cbd5e1;
  --white: #ffffff;
  --emerald: #10b981;
  --emerald-soft: rgba(16, 185, 129, .15);
  --amber: #f59e0b;
  --danger: #f43f5e;
  --glass: linear-gradient(145deg, rgba(255,255,255,.07), rgba(255,255,255,.025));
  --border: 1px solid rgba(255,255,255,.09);
  --shadow: 0 18px 60px rgba(0,0,0,.32);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "DM Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--slate-100);
  background:
    radial-gradient(at 20% 20%, rgba(16,185,129,.13), transparent 34%),
    radial-gradient(at 80% 0%, rgba(245,158,11,.08), transparent 28%),
    linear-gradient(145deg, #06080f, #0b1224 60%, #08111f);
  background-attachment: fixed;
  overflow-x: hidden;
}

a {
  color: var(--emerald);
  text-decoration: none;
}

.page {
  width: min(1180px, calc(100% - 48px));
  margin: 0 auto;
  padding: 28px 24px 56px;
}

.hero,
.card {
  margin-left: auto;
  margin-right: auto;
}

.field {
  margin-bottom: 14px;
}

.field:last-child {
  margin-bottom: 0;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 48px;
  margin-bottom: 28px;
  padding: 14px 56px 14px 32px;
  background: rgba(255,255,255,.05);
  border: var(--border);
  border-radius: 24px;
  backdrop-filter: blur(18px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--white);
  font-weight: 800;
  letter-spacing: .3px;
  flex-shrink: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--emerald), #06b6d4);
  color: #00110b;
  font-weight: 900;
}

.mobile-menu-toggle {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 44px;
  height: 44px;
  background: rgba(255,255,255,.08);
  border: var(--border);
  border-radius: 50%;
  cursor: pointer;
  gap: 5px;
  padding: 0;
}

.mobile-menu-toggle span {
  width: 20px;
  height: 2px;
  background: var(--white);
  border-radius: 1px;
  transition: all 0.3s ease;
}

.mobile-menu-toggle:hover {
  background: rgba(255,255,255,.12);
}

.nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.nav-links .btn,
.nav-links button {
  padding: 8px 16px;
  min-height: 36px;
  font-size: 0.85rem;
  flex: 0 0 auto;
  width: auto;
  font-weight: 700;
}

.nav-links .btn.secondary,
.nav-links button.secondary {
  padding: 6px 12px;
  font-weight: 500;
  background: transparent;
  border-color: transparent;
  color: var(--slate-100);
  box-shadow: none;
}

.nav-links .btn.secondary:hover,
.nav-links button.secondary:hover {
  background: rgba(255,255,255,.08);
  color: var(--white);
  transform: translateY(-1px);
}

.nav-links form {
  margin-left: 16px;
}

.hero, .card {
  background: var(--glass);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.hero {
  padding: clamp(28px, 5vw, 56px);
  margin-bottom: 24px;
}

.eyebrow {
  display: inline-flex;
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--emerald);
  background: var(--emerald-soft);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: 2px;
  text-transform: uppercase;
}

h1, h2, h3 {
  color: var(--white);
  line-height: 1.12;
}

h1 {
  font-size: clamp(2rem, 5vw, 3.7rem);
  margin: 18px 0 10px;
}

.muted {
  color: var(--slate-100);
  opacity: .74;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  justify-items: center;
}

.card {
  padding: 22px;
  width: 100%;
  max-width: 560px;
}

.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--emerald), #06b6d4);
  color: #00110b;
  font-weight: 800;
  cursor: pointer;
  transition: transform .2s ease, box-shadow .2s ease;
  white-space: nowrap;
}

.btn:hover, button:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 28px rgba(16,185,129,.24);
}

.btn.secondary {
  color: var(--white);
  background: rgba(255,255,255,.08);
  border: var(--border);
}

.btn.danger {
  color: var(--white);
  background: linear-gradient(135deg, var(--danger), #dc2626);
}

.btn.disabled {
  color: var(--slate-300);
  background: rgba(255,255,255,.04);
  border: var(--border);
  cursor: not-allowed;
  opacity: 0.6;
}

.btn.disabled:hover {
  transform: none;
  box-shadow: none;
}

input, select, textarea {
  width: 100%;
  padding: 13px 14px;
  border: var(--border);
  border-radius: 14px;
  color: var(--white);
  background: rgba(255,255,255,.06);
  outline: none;
}

textarea {
  min-height: 94px;
  resize: vertical;
}

label {
  display: block;
  margin: 0 0 8px;
  color: var(--white);
  font-weight: 700;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.performance-grid {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(360px, 1.4fr);
  gap: 20px;
  margin-bottom: 24px;
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 430px;
}

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 18px;
}

.chart-shell {
  position: relative;
  min-height: 260px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 14px;
}

.stat-card {
  background: rgba(255,255,255,.06);
  border: var(--border);
  border-radius: 18px;
  padding: 16px 18px;
}

.stat-label {
  display: block;
  margin-bottom: 8px;
  color: var(--slate-300);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .08em;
}

.stat-value {
  font-size: 1.9rem;
  font-weight: 900;
  color: var(--white);
}

.stat-subtext {
  font-size: 0.75rem;
  color: var(--emerald);
  margin-top: 8px;
}

.filter-actions {
  margin-top: 18px;
  display: flex;
  justify-content: flex-end;
}

.table-summary {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 18px;
}

.empty-state {
  padding: 22px;
  border: var(--border);
  border-radius: 18px;
  background: rgba(255,255,255,.04);
  color: var(--slate-300);
  text-align: center;
}

.table-compact th,
.table-compact td {
  padding: 12px 14px;
  font-size: .92rem;
}

.table-compact tbody tr:hover {
  background: rgba(255,255,255,.04);
}

/* Student Portal Styles */
.tests-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 18px;
  margin-bottom: 28px;
}

.test-card {
  background: var(--glass);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
  transition: all .2s ease;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.test-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 24px 72px rgba(0,0,0,.4);
  border-color: rgba(16,185,129,.2);
}

.test-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

/* Layout columns for Test Header to isolate wrapping title from badges */
.test-title-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  flex: 1;
}

.test-badge-col {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.subject-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 7px 14px;
  border-radius: 999px;
  color: var(--emerald);
  background: var(--emerald-soft);
  font-size: .75rem;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
  line-height: 1;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .5px;
  text-transform: uppercase;
  line-height: 1;
}

.status-badge.completed {
  background: rgba(16,185,129,.2);
  color: #6ee7b7;
}

.status-badge.in-progress {
  background: rgba(245,158,11,.2);
  color: #fbbf24;
}

.status-badge.published,
.status-pill.published {
  background: rgba(16,185,129,.15);
  color: #34d399;
}

.status-badge.unpublished,
.status-pill.unpublished {
  background: rgba(100,116,139,.15);
  color: #94a3b8;
}

.test-card h2 {
  margin: 0;
  font-size: 1.4rem;
  line-height: 1.2;
}

.test-meta {
  display: flex;
  gap: 18px;
  font-size: .92rem;
  color: var(--slate-300);
}

.score-display {
  background: rgba(16,185,129,.12);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
}

.score-value {
  font-size: 2rem;
  font-weight: 900;
  color: #6ee7b7;
}

.score-total {
  font-size: 1.2rem;
  color: var(--slate-300);
}

.test-card button,
.test-card a {
  margin-top: auto;
}

/* Result Page Styles */
.result-summary {
  margin-bottom: 24px;
}

.score-card {
  background: var(--glass);
  border: var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(180px, 200px) 1fr;
  gap: 28px;
  align-items: center;
}

.score-circle {
  display: grid;
  place-items: center;
  width: 180px;
  height: 180px;
  border-radius: 50%;
  background: conic-gradient(from 0deg, rgba(16,185,129,1), rgba(16,185,129,.3));
  box-shadow: inset 0 0 20px rgba(16,185,129,.2);
}

.score-inner {
  display: grid;
  place-items: center;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: var(--slate-900);
  border: 2px solid rgba(16,185,129,.3);
}

.score-num {
  font-size: 3.2rem;
  font-weight: 900;
  color: #6ee7b7;
}

.score-max {
  font-size: 1rem;
  color: var(--slate-300);
}

.result-info h2 {
  margin: 0 0 12px;
}

.result-meta {
  margin-bottom: 12px;
  color: var(--slate-300);
}

.result-warnings {
  margin: 12px 0 18px;
  color: var(--slate-300);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  line-height: 1;
}

.status-pill.submitted {
  background: rgba(16,185,129,.2);
  color: #6ee7b7;
}

.status-pill.expired {
  background: rgba(244,63,94,.2);
  color: #fca5ac;
}

.status-pill.in_progress {
  background: rgba(245,158,11,.2);
  color: #fbbf24;
}

/* Answer Review */
.review-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 18px;
  margin-bottom: 20px;
}

.questions-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.question-review {
  background: rgba(255,255,255,.04);
  border: var(--border);
  border-radius: 14px;
  padding: 18px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 16px;
}

.question-number {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(16,185,129,.15);
  color: var(--emerald);
  font-weight: 800;
  flex-shrink: 0;
}

.question-content h3 {
  margin: 0 0 14px;
}

.answer-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.answer-row span:first-child {
  color: var(--slate-300);
  font-size: .9rem;
}

.answer-value {
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
}

.answer-value.correct {
  color: #6ee7b7;
  background: rgba(16,185,129,.15);
}

.answer-value.incorrect {
  color: #fca5ac;
  background: rgba(244,63,94,.15);
}

.explanation {
  margin-top: 14px;
  padding: 14px;
  border-radius: 10px;
  background: rgba(16,185,129,.1);
  border-left: 3px solid rgba(16,185,129,.4);
}

.explanation p {
  margin: 8px 0 0;
  font-size: .92rem;
  line-height: 1.6;
}

/* Student Performance Grid */
.student-perf-grid {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(350px, 1.3fr);
  gap: 20px;
  margin-bottom: 24px;
}

.filter-card {
  min-height: 280px;
}

.chart-card {
  min-height: 380px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 14px 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  text-align: left;
}

th {
  color: var(--white);
  font-size: .82rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}



.alert {
  margin: 0 0 18px;
  padding: 13px 16px;
  border-radius: 16px;
  border: var(--border);
}

.alert.success {
  color: #a7f3d0;
  background: rgba(16,185,129,.11);
}

.alert.error {
  color: #fecdd3;
  background: rgba(244,63,94,.12);
}

.login-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

.login-card {
  width: min(460px, 100%);
}

.optional-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--slate-300);
  margin-top: 2px;
}

.question-card {
  margin-bottom: 18px;
}

.options {
  display: grid;
  gap: 10px;
}

.option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border: var(--border);
  border-radius: 14px;
  background: rgba(255,255,255,.04);
  word-break: break-word;
}

.option input {
  width: auto;
}

/* Match The Following Select UI */
.options select,
.option select {
  width: auto;
  flex-shrink: 0;
  min-width: 140px;
  max-width: 50%;
  margin-left: auto;
  padding: 10px 34px 10px 14px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--white);
  background-color: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 10px;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23cbd5e1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 14px;
  cursor: pointer;
  transition: all 0.2s ease;
}
.options select:hover,
.option select:hover {
  background-color: rgba(255, 255, 255, 0.1);
  border-color: rgba(16, 185, 129, 0.3);
}
.options select:focus,
.option select:focus {
  border-color: var(--emerald);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

.timer {
  position: sticky;
  top: 14px;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
  padding: 14px 18px;
  border-radius: 18px;
  border: 1px solid rgba(245,158,11,.25);
  background: rgba(245,158,11,.12);
  font-variant-numeric: tabular-nums;
}

.pill {
  display: inline-flex;
  padding: 6px 10px;
  border-radius: 999px;
  color: var(--white);
  background: rgba(255,255,255,.08);
  font-size: .82rem;
  font-weight: 800;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

svg.spin {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  100% { transform: rotate(360deg); }
}

/* Enhanced mobile responsiveness */
@media (max-width: 1024px) {
  .page {
    width: min(100%, calc(100% - 24px));
    padding: 24px 16px 48px;
  }

  .performance-grid,
  .student-perf-grid {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

@media (max-width: 768px) {
  .mobile-menu-toggle {
    display: flex;
  }

  .nav {
    flex-wrap: wrap;
    border-radius: 18px;
  }

  .nav-links {
    width: 100%;
    order: 3;
    flex-direction: column;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
  }

  .nav-links.active {
    max-height: 500px;
  }

  .nav-links .btn,
  .nav-links button {
    width: 100%;
    justify-content: center;
  }

  .nav-links form {
    width: 100%;
    margin-left: 0;
  }

  .nav-links form button {
    width: 100%;
  }

  .page {
    width: min(100%, calc(100% - 32px));
    padding: 16px 16px 36px;
  }

  .nav {
    padding: 14px 16px;
    gap: 12px;
  }

  .brand {
    gap: 8px;
    font-size: 0.95rem;
  }

  .brand-mark {
    width: 32px;
    height: 32px;
    font-size: 0.85rem;
  }

  .hero {
    padding: 20px;
    margin-bottom: 18px;
  }

  h1 {
    font-size: 1.8rem;
    margin: 12px 0 8px;
  }

  h2 {
    font-size: 1.3rem;
  }

  h3 {
    font-size: 1.1rem;
  }

  .eyebrow {
    padding: 6px 12px;
    font-size: 0.7rem;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 14px;
    justify-items: center;
  }

  .card {
    padding: 16px;
    width: 100%;
    max-width: 640px;
    margin: 0 auto;
  }

  .stat {
    font-size: 2rem;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .btn, button {
    padding: 11px 18px;
    min-height: 42px;
    font-size: 0.9rem;
  }

  input, select, textarea {
    padding: 12px 12px;
    font-size: 1rem;
    border-radius: 12px;
  }

  label {
    font-size: 0.9rem;
    margin: 0 0 6px;
  }

  .performance-grid,
  .student-perf-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .chart-card {
    min-height: 300px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .stat-card {
    padding: 12px 14px;
  }

  .stat-label {
    font-size: 0.7rem;
  }

  .stat-value {
    font-size: 1.6rem;
  }

  .table-wrap {
    margin: 0 -16px;
    padding: 0 4px;
  }

  table {
    min-width: 550px;
    font-size: 0.85rem;
  }

  th, td {
    padding: 10px 8px;
    font-size: 0.8rem;
  }

  .tests-grid {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .test-card {
    padding: 16px;
    gap: 12px;
  }

  .test-card h2 {
    font-size: 1.2rem;
  }

  .test-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .test-badge-col {
    align-items: flex-start;
    width: 100%;
  }

  .test-meta {
    flex-direction: column;
    gap: 6px;
    font-size: 0.85rem;
  }

  .score-card {
    grid-template-columns: 1fr;
    gap: 18px;
    text-align: center;
    padding: 20px;
  }

  .score-circle {
    width: 140px;
    height: 140px;
    margin: 0 auto;
  }

  .score-inner {
    width: 120px;
    height: 120px;
  }

  .score-num {
    font-size: 2.4rem;
  }

  .score-max {
    font-size: 0.9rem;
  }

  .question-card {
    margin-bottom: 14px;
  }

  .question-review {
    grid-template-columns: 1fr;
    padding: 14px;
    gap: 12px;
  }

  .question-number {
    width: 36px;
    height: 36px;
    font-size: 0.85rem;
  }

  .question-content h3 {
    font-size: 1.1rem;
    margin: 0 0 10px;
  }

  .answer-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
    margin-bottom: 10px;
    padding: 8px 0;
  }

  .options select,
  .option select {
    padding: 8px 30px 8px 12px;
    font-size: 0.9rem;
    min-width: 120px;
    background-position: right 10px center;
    background-size: 12px;
    border-radius: 8px;
  }

  .answer-value {
    padding: 3px 8px;
    font-size: 0.85rem;
  }

  .explanation {
    margin-top: 12px;
    padding: 12px;
    font-size: 0.85rem;
  }

  .explanation p {
    font-size: 0.85rem;
    margin: 6px 0 0;
  }

  .review-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .timer {
    flex-direction: column;
    text-align: center;
    gap: 8px;
    padding: 12px 16px;
    margin-bottom: 16px;
  }

  .pill {
    padding: 5px 9px;
    font-size: 0.75rem;
  }

  .option {
    padding: 11px;
    gap: 8px;
    border-radius: 12px;
  }

  .actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .actions .btn {
    width: 100%;
    justify-content: center;
    margin: 0;
  }

  .actions form {
    grid-column: 1 / -1;
    width: 100%;
  }

  .alert {
    padding: 12px 14px;
    font-size: 0.9rem;
    margin: 0 0 14px;
  }

  .filter-card {
    min-height: auto;
  }

  .chart-shell {
    min-height: 240px;
  }

  .table-summary {
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .filter-actions {
    justify-content: flex-start;
    margin-top: 12px;
  }

  .filter-actions button {
    width: 100%;
  }

  /* Login page mobile improvements */
  .login-shell {
    padding: 16px;
    min-height: 100vh;
  }

  .login-card {
    width: 100%;
    max-width: 420px;
    padding: 24px;
  }

  .login-card h1 {
    font-size: 1.8rem;
    margin: 16px 0 12px;
  }

  .login-card p {
    font-size: 0.85rem;
    margin: 0 0 20px;
  }

  .login-card .field {
    margin-bottom: 16px;
  }

  .login-card button {
    width: 100%;
    margin-top: 8px;
  }

  .optional-label {
    font-size: 0.7rem;
  }
}

@media (max-width: 640px) {
  .page {
    width: min(100%, calc(100% - 24px));
    padding: 12px 12px 32px;
  }

  .nav {
    padding: 12px 14px;
    gap: 10px;
    border-radius: 18px;
  }

  .brand {
    gap: 6px;
    font-size: 0.9rem;
    flex-shrink: 0;
  }

  .brand-mark {
    width: 30px;
    height: 30px;
  }

  .brand span:last-child {
    display: none;
  }

  .hero {
    padding: 16px;
    margin-bottom: 14px;
  }

  h1 {
    font-size: 1.6rem;
    margin: 10px 0 6px;
  }

  h2 {
    font-size: 1.15rem;
  }

  .eyebrow {
    padding: 5px 10px;
    font-size: 0.65rem;
  }

  .card {
    padding: 14px;
  }

  .grid {
    gap: 12px;
  }

  .stat {
    font-size: 1.8rem;
  }

  .form-grid {
    gap: 10px;
  }

  .btn, button {
    padding: 10px 16px;
    min-height: 40px;
    font-size: 0.85rem;
  }

  input, select, textarea {
    padding: 11px 11px;
    font-size: 1rem;
    border-radius: 10px;
  }

  textarea {
    min-height: 80px;
  }

  label {
    font-size: 0.85rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .stat-card {
    padding: 10px 12px;
  }

  .stat-label {
    font-size: 0.65rem;
  }

  .stat-value {
    font-size: 1.4rem;
  }

  .table-wrap {
    margin: 0 -14px;
  }

  table {
    min-width: 480px;
    font-size: 0.8rem;
  }

  th, td {
    padding: 8px 6px;
    font-size: 0.75rem;
  }

  .tests-grid {
    gap: 12px;
  }

  .test-card {
    padding: 14px;
    gap: 10px;
  }

  .test-card h2 {
    font-size: 1.1rem;
  }

  .test-meta {
    font-size: 0.8rem;
  }

  .score-card {
    gap: 14px;
    padding: 16px;
  }

  .score-circle {
    width: 120px;
    height: 120px;
  }

  .score-inner {
    width: 100px;
    height: 100px;
  }

  .score-num {
    font-size: 2rem;
  }

  .score-max {
    font-size: 0.85rem;
  }

  .result-info h2 {
    font-size: 1.2rem;
  }

  .question-number {
    width: 32px;
    height: 32px;
    font-size: 0.8rem;
  }

  .question-content h3 {
    font-size: 1rem;
  }

  .timer {
    gap: 6px;
    padding: 10px 14px;
    margin-bottom: 14px;
    font-size: 0.9rem;
  }

  .pill {
    padding: 4px 8px;
    font-size: 0.7rem;
  }

  .option {
    padding: 10px;
    gap: 8px;
  }

  .options select,
  .option select {
    padding: 6px 26px 6px 10px;
    font-size: 0.85rem;
    min-width: 100px;
    background-position: right 8px center;
    background-size: 12px;
  }

  .option input {
    margin-top: 2px;
  }

  .alert {
    padding: 10px 12px;
    font-size: 0.85rem;
    border-radius: 12px;
  }

  .login-shell {
    padding: 12px;
    min-height: 100vh;
  }

  .login-card {
    width: 100%;
    max-width: 100%;
    padding: 20px;
  }

  .login-card h1 {
    font-size: 1.6rem;
    margin: 14px 0 10px;
  }

  .login-card p {
    font-size: 0.8rem;
    margin: 0 0 18px;
  }

  .login-card .field {
    margin-bottom: 14px;
  }

  .login-card label {
    font-size: 0.8rem;
  }

  .login-card input,
  .login-card select {
    font-size: 1rem;
    padding: 11px 10px;
  }

  .login-card button {
    width: 100%;
    margin-top: 4px;
  }

  .filter-card {
    padding: 14px;
  }

  .chart-shell {
    min-height: 220px;
  }

  .filter-actions button {
    width: 100%;
    margin-top: 8px;
  }

  .empty-state {
    padding: 14px;
    font-size: 0.85rem;
  }

  .test-header {
    gap: 6px;
  }

  .answer-row span:first-child {
    font-size: 0.85rem;
  }

  .explanation {
    border-radius: 8px;
  }

  .question-card {
    margin-bottom: 12px;
  }
}

@media (max-width: 480px) {
  .page {
    width: 100%;
    padding: 16px 16px 32px;
    box-sizing: border-box;
  }

  .nav {
    padding: 10px 12px;
    gap: 8px;
    border-radius: 16px;
  }

  .nav-links {
    flex-wrap: wrap;
  }

  .hero {
    padding: 14px;
    margin-bottom: 12px;
  }

  h1 {
    font-size: 1.4rem;
    margin: 8px 0 4px;
  }

  h2 {
    font-size: 1.05rem;
  }

  .card {
    padding: 12px;
  }

  .btn, button {
    padding: 9px 14px;
    min-height: 38px;
    font-size: 0.8rem;
  }

  input, select, textarea {
    padding: 10px 10px;
    font-size: 1rem;
  }

  textarea {
    min-height: 70px;
  }

  .table-wrap {
    margin: 0 -12px;
  }

  table {
    min-width: 420px;
    font-size: 0.75rem;
  }

  th, td {
    padding: 6px 4px;
    font-size: 0.7rem;
  }

  .stat {
    font-size: 1.6rem;
  }

  .tests-grid {
    gap: 10px;
  }

  .test-card {
    padding: 12px;
    gap: 8px;
  }

  .score-circle {
    width: 100px;
    height: 100px;
  }

  .score-inner {
    width: 85px;
    height: 85px;
  }

  .score-num {
    font-size: 1.7rem;
  }

  .timer {
    gap: 4px;
    padding: 9px 12px;
    font-size: 0.85rem;
  }

  .pill {
    padding: 3px 7px;
    font-size: 0.65rem;
  }

  .option {
    padding: 9px;
  }

  .form-grid {
    gap: 8px;
  }

  .login-shell {
    padding: 10px;
    min-height: 100vh;
  }

  .login-card {
    width: 100%;
    padding: 16px;
  }

  .login-card h1 {
    font-size: 1.4rem;
    margin: 12px 0 8px;
  }

  .login-card p {
    font-size: 0.75rem;
    margin: 0 0 14px;
    line-height: 1.4;
  }

  .login-card .field {
    margin-bottom: 12px;
  }

  .login-card label {
    font-size: 0.75rem;
    margin: 0 0 4px;
  }

  .login-card input,
  .login-card select {
    font-size: 1rem;
    padding: 10px 9px;
  }

  .login-card button {
    width: 100%;
    padding: 9px 12px;
  }

  .question-card {
    margin-bottom: 10px;
  }

  .chart-shell {
    min-height: 200px;
  }

  .alert {
    margin: 0 0 10px;
  }

  .eyebrow {
    font-size: 0.6rem;
    padding: 4px 9px;
  }

  h3 {
    font-size: 1rem;
  }

  .subject-badge,
  .status-badge {
    padding: 4px 8px;
    font-size: 0.6rem;
  }

  .grid {
    gap: 10px;
  }

  .stat-card {
    padding: 8px 10px;
  }

  .stat-label {
    font-size: 0.6rem;
  }

  .stat-value {
    font-size: 1.2rem;
  }

  label {
    font-size: 0.8rem;
    margin: 0 0 5px;
  }
}

@media (max-width: 360px) {
  .page {
    padding: 8px 0 24px;
  }

  .nav {
    padding: 8px 10px;
    border-radius: 14px;
  }

  h1 {
    font-size: 1.2rem;
  }

  h2 {
    font-size: 1rem;
  }

  .card {
    padding: 10px;
  }

  .btn, button {
    padding: 8px 12px;
    min-height: 36px;
    font-size: 0.75rem;
  }

  .stat {
    font-size: 1.4rem;
  }

  .score-circle {
    width: 90px;
    height: 90px;
  }

  .score-inner {
    width: 75px;
    height: 75px;
  }

  .score-num {
    font-size: 1.5rem;
  }

  .timer {
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  table {
    min-width: 360px;
    font-size: 0.7rem;
  }

  .test-card {
    padding: 10px;
  }

  .login-shell {
    padding: 8px;
  }

  .login-card {
    padding: 14px;
  }

  .login-card h1 {
    font-size: 1.3rem;
    margin: 10px 0 6px;
  }

  .login-card p {
    font-size: 0.7rem;
    margin: 0 0 12px;
  }

  .login-card .field {
    margin-bottom: 10px;
  }

  .login-card label {
    font-size: 0.7rem;
  }

  .login-card input,
  .login-card select {
    padding: 9px 8px;
    font-size: 0.95rem;
  }

  .optional-label {
    font-size: 0.65rem;
  }

  input, select {
    border-radius: 8px;
  }

  .eyebrow {
    font-size: 0.55rem;
    padding: 3px 8px;
  }

  h3 {
    font-size: 0.95rem;
  }

  .muted {
    font-size: 0.85rem;
  }

  label {
    font-size: 0.75rem;
  }

  .subject-badge,
  .status-badge {
    font-size: 0.55rem;
    padding: 3px 6px;
  }

  .alert {
    padding: 8px 10px;
    font-size: 0.8rem;
  }

  .stat-card {
    padding: 8px 9px;
  }

  .stat-label {
    font-size: 0.55rem;
  }

  .stat-value {
    font-size: 1.2rem;
  }

  .hero {
    padding: 12px;
  }

  .question-number {
    width: 28px;
    height: 28px;
    font-size: 0.75rem;
  }

  .pill {
    padding: 2px 6px;
    font-size: 0.6rem;
  }

  .option {
    padding: 8px;
    font-size: 0.85rem;
  }
}

/* Responsive Layout for Teacher Performance Page */
.page-layout {
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 32px;
  align-items: start;
}

.filters-sidebar {
  position: sticky;
  top: 20px;
}

.content-area {
  display: flex;
  flex-direction: column;
  gap: 48px;
}

.analytics-section {
  margin-bottom: 0;
}

.analytics-section h2 {
  margin: 0 0 8px 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--white);
}

.section-description {
  margin: 0 0 24px 0;
  color: var(--slate-300);
  font-size: 0.95rem;
}

/* Mobile Layout */
@media (max-width: 768px) {
  .page-layout {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .filters-sidebar {
    position: static;
    order: -1;
  }

  .content-area {
    gap: 32px;
  }

  .analytics-section h2 {
    font-size: 1.25rem;
  }
}

/* Tab Styles */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: var(--border);
  margin-bottom: 24px;
}

.tab {
  padding: 12px 24px;
  background: transparent;
  border: none;
  color: var(--slate-300);
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s ease;
}

.tab:hover {
  color: var(--emerald);
}

.tab.active {
  color: var(--emerald);
  border-bottom-color: var(--emerald);
}

.clickable {
  cursor: pointer;
  transition: transform 0.2s ease;
}

.clickable:hover {
  transform: translateY(-2px);
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(5px);
}

.modal-content {
  background: var(--slate-900);
  border: var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  padding: 20px;
  border-bottom: var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  color: var(--white);
}

.modal-close {
  background: none;
  border: none;
  color: var(--slate-300);
  font-size: 24px;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.modal-close:hover {
  background-color: var(--slate-800);
  color: var(--white);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}

/* Prevent 1-frame flashing of image controls before JS hydration completes */
.question-card[data-question-locked="true"] .remove-btn,
.question-card[data-question-locked="true"] .remove-img-btn,
.question-card[data-question-locked="true"] .remove-image-btn,
.question-card[data-question-locked="true"] .file-upload-btn {
  display: none !important;
}
