:root {
  --green-600: #16a34a;
  --green-700: #15803d;
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Inter', system-ui, sans-serif; background: var(--gray-50); color: var(--gray-800); min-height: 100vh; }
a { color: var(--green-600); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Nav */
#portal-nav { background: #fff; border-bottom: 1px solid var(--gray-200); position: sticky; top: 0; z-index: 100; }
.nav-inner { max-width: 1100px; margin: 0 auto; padding: 0 1rem; display: flex; align-items: center; gap: 1.5rem; height: 60px; }
.nav-logo { font-weight: 700; font-size: 1.1rem; color: var(--green-700); text-decoration: none; flex: 0 0 auto; }
.nav-links { display: flex; gap: 1rem; flex: 1; }
.nav-links a { font-size: 0.875rem; font-weight: 500; color: var(--gray-600); padding: 0.25rem 0.5rem; border-radius: 6px; text-decoration: none; transition: background 0.15s; }
.nav-links a:hover, .nav-links a.active { background: var(--green-50); color: var(--green-700); }
.nav-user { font-size: 0.8rem; color: var(--gray-600); display: flex; align-items: center; gap: 0.75rem; }
.nav-logout { background: none; border: 1px solid var(--gray-200); border-radius: 6px; padding: 0.3rem 0.75rem; cursor: pointer; font-size: 0.8rem; color: var(--gray-600); }
.nav-logout:hover { border-color: #ef4444; color: #ef4444; }
/* Mobile nav: links drop to second row */
@media(max-width:640px){
  .nav-inner { flex-wrap: wrap; height: auto; padding: 0.5rem 0.75rem; gap: 0.25rem; min-height: 48px; }
  .nav-logo { flex: 1; font-size: 0.95rem; }
  .nav-user { flex: 0 0 auto; }
  .nav-links { flex: 0 0 100%; order: 3; border-top: 1px solid var(--gray-100); padding-top: 0.4rem; padding-bottom: 0.25rem; gap: 0.1rem; }
  .nav-links a { font-size: 0.78rem; padding: 0.35rem 0.5rem; }
  #nav-email { display: none; }
  .nav-logout { padding: 0.25rem 0.6rem; font-size: 0.75rem; }
}

/* Layout */
.page-wrapper { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--gray-900); margin-bottom: 1.5rem; }

/* Cards */
.card { background: #fff; border-radius: 12px; border: 1px solid var(--gray-200); padding: 1.25rem 1.5rem; }
.card-title { font-size: 0.875rem; font-weight: 600; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.75rem; }
.card-value { font-size: 2rem; font-weight: 700; color: var(--gray-900); }
.card-sub { font-size: 0.8rem; color: var(--gray-600); margin-top: 0.25rem; }

/* Grid */
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
@media(max-width: 768px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }
@media(max-width: 900px) and (min-width: 641px) { .grid-3 { grid-template-columns: 1fr 1fr; } }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 0.4rem; padding: 0.6rem 1.25rem; border-radius: 8px; font-weight: 600; font-size: 0.9rem; cursor: pointer; border: none; transition: all 0.15s; text-decoration: none; }
.btn-primary { background: var(--green-600); color: #fff; }
.btn-primary:hover { background: var(--green-700); }
.btn-outline { background: #fff; color: var(--green-600); border: 1.5px solid var(--green-600); }
.btn-outline:hover { background: var(--green-50); }
.btn-gray { background: var(--gray-100); color: var(--gray-700); }
.btn-gray:hover { background: var(--gray-200); }
.btn-danger { background: #ef4444; color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-lg { padding: 0.8rem 2rem; font-size: 1rem; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 1.1rem; }
label { display: block; font-size: 0.875rem; font-weight: 500; color: var(--gray-700); margin-bottom: 0.4rem; }
input[type=text], input[type=email], input[type=password], select, textarea {
  width: 100%; padding: 0.65rem 0.875rem; border: 1.5px solid var(--gray-200); border-radius: 8px;
  font-size: 0.9rem; color: var(--gray-900); background: #fff; transition: border 0.15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--green-600); }
.form-error { color: #ef4444; font-size: 0.8rem; margin-top: 0.35rem; display: none; }
.form-error.show { display: block; }

/* Auth box */
.auth-box { max-width: 420px; margin: 3rem auto; }
.auth-box .card { padding: 2rem; }
.auth-logo { text-align: center; margin-bottom: 1.5rem; }
.auth-logo a { font-size: 1.25rem; font-weight: 800; color: var(--green-700); }
.auth-title { font-size: 1.3rem; font-weight: 700; color: var(--gray-900); margin-bottom: 0.4rem; text-align: center; }
.auth-sub { font-size: 0.875rem; color: var(--gray-600); margin-bottom: 1.5rem; text-align: center; }

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: 8px; font-size: 0.875rem; margin-bottom: 1rem; display: none; }
.alert.show { display: block; }
.alert-error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: var(--green-50); color: #166534; border: 1px solid var(--green-100); }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; padding: 0.75rem 1rem; font-size: 0.75rem; font-weight: 600; color: var(--gray-600); text-transform: uppercase; letter-spacing: 0.04em; border-bottom: 1px solid var(--gray-200); }
td { padding: 0.75rem 1rem; border-bottom: 1px solid var(--gray-100); color: var(--gray-700); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--gray-50); }

/* Badges */
.badge { display: inline-block; padding: 0.2rem 0.6rem; border-radius: 99px; font-size: 0.7rem; font-weight: 600; }
.badge-green { background: var(--green-100); color: #166534; }
.badge-red { background: #fef2f2; color: #991b1b; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* Quiz */
.quiz-container { max-width: 800px; margin: 0 auto; }
.quiz-header { background: #fff; border-radius: 12px; border: 1px solid var(--gray-200); padding: 1rem 1.5rem; margin-bottom: 1rem; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.75rem; }
.quiz-progress-bar { height: 6px; background: var(--gray-200); border-radius: 99px; overflow: hidden; flex: 1; min-width: 120px; }
.quiz-progress-fill { height: 100%; background: var(--green-600); transition: width 0.3s; }
.quiz-timer { font-size: 1.1rem; font-weight: 700; color: var(--gray-800); font-variant-numeric: tabular-nums; }
.quiz-timer.warning { color: #f59e0b; }
.quiz-timer.danger { color: #ef4444; }
.question-card { background: #fff; border-radius: 12px; border: 1px solid var(--gray-200); padding: 1.5rem 2rem; margin-bottom: 1rem; }
.question-number { font-size: 0.75rem; font-weight: 600; color: var(--gray-500); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 0.75rem; }
.question-text { font-size: 1.05rem; color: var(--gray-900); line-height: 1.6; margin-bottom: 1.5rem; font-weight: 500; }
.answer-options { display: flex; flex-direction: column; gap: 0.6rem; }
.answer-btn { text-align: left; background: #fff; border: 1.5px solid var(--gray-200); border-radius: 8px; padding: 0.8rem 1rem; cursor: pointer; font-size: 0.9rem; color: var(--gray-700); transition: all 0.15s; display: flex; align-items: center; gap: 0.75rem; }
.answer-btn:hover:not(:disabled) { border-color: var(--green-600); background: var(--green-50); color: var(--green-700); }
.answer-btn.selected { border-color: var(--green-600); background: var(--green-50); color: var(--green-700); font-weight: 500; }
.answer-btn .option-letter { width: 24px; height: 24px; border-radius: 50%; border: 1.5px solid currentColor; display: flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 700; flex-shrink: 0; }
.answer-btn.selected .option-letter { background: var(--green-600); border-color: var(--green-600); color: #fff; }
.quiz-nav { display: flex; align-items: center; justify-content: space-between; gap: 0.75rem; }
.quiz-nav-pills { display: flex; flex-wrap: wrap; gap: 0.35rem; max-width: 600px; }
.nav-pill { width: 32px; height: 32px; border-radius: 6px; border: 1.5px solid var(--gray-200); background: #fff; cursor: pointer; font-size: 0.75rem; font-weight: 600; color: var(--gray-600); display: flex; align-items: center; justify-content: center; transition: all 0.1s; }
.nav-pill.answered { background: var(--green-100); border-color: var(--green-600); color: var(--green-700); }
.nav-pill.flagged { background: #fef9c3; border-color: #f59e0b; color: #92400e; }
.nav-pill.current { border-color: var(--green-600); border-width: 2px; }
.flag-btn { display: flex; align-items: center; gap: 0.4rem; font-size: 0.8rem; color: var(--gray-500); background: none; border: none; cursor: pointer; padding: 0.4rem 0.75rem; border-radius: 6px; }
.flag-btn:hover { background: var(--gray-100); }
.flag-btn.flagged { color: #f59e0b; }

/* Review */
.review-answer { border-radius: 8px; border: 1.5px solid var(--gray-200); padding: 0.75rem 1rem; margin-bottom: 0.5rem; font-size: 0.9rem; display: flex; align-items: center; gap: 0.75rem; }
.review-answer.correct { border-color: var(--green-600); background: var(--green-50); color: #166534; }
.review-answer.wrong { border-color: #ef4444; background: #fef2f2; color: #991b1b; }
.review-answer.correct-indicator { border-color: var(--green-600); background: var(--green-50); color: #166534; }
.explanation-box { background: #fffbeb; border: 1px solid #fde68a; border-radius: 8px; padding: 1rem; margin-top: 1rem; font-size: 0.875rem; color: #78350f; }

/* Loading */
.loading { display: flex; align-items: center; justify-content: center; padding: 3rem; color: var(--gray-500); gap: 0.75rem; font-size: 0.95rem; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--gray-200); border-top-color: var(--green-600); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Score display */
.score-circle { width: 120px; height: 120px; border-radius: 50%; border: 6px solid var(--green-600); display: flex; flex-direction: column; align-items: center; justify-content: center; margin: 0 auto 1rem; }
.score-circle.fail { border-color: #ef4444; }
.score-pct { font-size: 1.75rem; font-weight: 800; color: var(--gray-900); line-height: 1; }
.score-label { font-size: 0.75rem; color: var(--gray-500); font-weight: 500; }

/* Table scroll wrapper — add class="table-scroll" to any table parent */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ============================================================
   MOBILE OPTIMIZATIONS
   ============================================================ */
@media(max-width:640px) {
  /* Layout */
  .page-wrapper { padding: 1rem 0.75rem 2.5rem; }
  .page-title { font-size: 1.2rem; margin-bottom: 1rem; }
  .card { padding: 1rem 1rem; }
  .card-value { font-size: 1.6rem; }
  .auth-box { margin: 1.25rem auto; }
  .auth-box .card { padding: 1.5rem 1.25rem; }

  /* Buttons — full width in stacked column contexts */
  .btn-lg { width: 100%; text-align: center; }

  /* Quiz header — stack into two rows */
  .quiz-header { flex-direction: column; align-items: flex-start; padding: 0.75rem 1rem; gap: 0.5rem; }
  .quiz-progress-bar { width: 100%; max-width: 100%; }
  #submit-quiz-btn { align-self: flex-end; }

  /* Question card */
  .question-card { padding: 1rem; }
  .question-text { font-size: 0.95rem; margin-bottom: 1rem; }
  .answer-btn { padding: 0.85rem 0.75rem; font-size: 0.875rem; }
  .answer-btn .option-letter { width: 22px; height: 22px; font-size: 0.7rem; flex-shrink: 0; }

  /* Quiz navigation row */
  .quiz-nav { gap: 0.4rem; }
  .quiz-nav button { flex: 1; font-size: 0.8rem; padding: 0.5rem 0.5rem; }
  .flag-btn { flex: 0 0 auto; font-size: 0.75rem; }

  /* Question navigator pills — cap height and scroll */
  .quiz-nav-pills { max-height: 108px; overflow-y: auto; gap: 0.25rem; }
  .nav-pill { width: 28px; height: 28px; font-size: 0.65rem; border-radius: 5px; }

  /* Review page */
  .review-answer { padding: 0.6rem 0.75rem; font-size: 0.85rem; }
  .explanation-box { font-size: 0.82rem; padding: 0.75rem; }
}
