/* ============================================
   CFA QBank — Prometric Testing Center Style
   Brutalist, institutional, functional.
   ============================================ */

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

:root {
  /* Prometric palette — muted blues, grays, off-whites */
  --header-bg: #1a3a5c;
  --header-text: #d9e2ec;
  --body-bg: #e8ecf1;
  --panel-bg: #ffffff;
  --border: #c5cdd8;
  --border-light: #dce3eb;
  --text-primary: #1f2937;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --correct: #166534;
  --correct-bg: #dcfce7;
  --correct-border: #86efac;
  --incorrect: #991b1b;
  --incorrect-bg: #fee2e2;
  --incorrect-border: #fca5a5;
  --selected-bg: #dbeafe;
  --selected-border: #60a5fa;
  --flagged: #d97706;
  --option-hover: #f1f5f9;
  --btn-bg: #334155;
  --btn-text: #f1f5f9;
  --sidebar-bg: #f3f4f6;
  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

html { font-size: 14px; }
body {
  font-family: var(--font-main);
  background: var(--body-bg);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.55;
}

/* ---------- Screen switching ---------- */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; }

/* ---------- Prometric Header ---------- */
.prometric-header {
  background: var(--header-bg);
  border-bottom: 3px solid #0f2640;
  flex-shrink: 0;
}
.header-bar {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-title {
  color: var(--header-text);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 0.3px;
}
.header-right {
  color: #93a8c1;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.header-controls {
  display: flex;
  align-items: center;
  gap: 20px;
}
.header-timer {
  color: #fbbf24;
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.header-progress {
  color: #93a8c1;
  font-size: 12px;
}

/* ============================================
   SUBJECT SELECTION SCREEN
   ============================================ */
.subject-body {
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 28px;
  align-items: start;
  width: 100%;
}
.subject-panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 24px;
}
.panel-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.panel-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.subject-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.subject-item {
  padding: 12px 16px;
  border: 1px solid var(--border-light);
  margin: -0.5px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: background 0.1s;
  user-select: none;
}
.subject-item:hover { background: var(--option-hover); }
.subject-item.selected {
  background: var(--selected-bg);
  border-color: var(--selected-border);
  z-index: 1;
  position: relative;
}
.subject-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}
.subject-count {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--sidebar-bg);
  padding: 2px 8px;
  border-radius: 2px;
}

/* Session config panel */
.session-config {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 24px;
}
.config-title {
  font-size: 14px;
  font-weight: 700;
  margin-bottom: 18px;
  color: var(--text-primary);
}
.config-group { margin-bottom: 20px; }
.config-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
  display: block;
  margin-bottom: 8px;
}
.radio-group { display: flex; flex-direction: column; gap: 6px; }
.radio-option {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 2px;
  transition: background 0.1s;
}
.radio-option:hover { background: var(--option-hover); }
.radio-option input[type="radio"] {
  appearance: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-radius: 50%;
  flex-shrink: 0;
  position: relative;
  cursor: pointer;
}
.radio-option input[type="radio"]:checked {
  border-color: var(--accent);
}
.radio-option input[type="radio"]:checked::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
}
.radio-desc {
  color: var(--text-muted);
  font-size: 11px;
}

.btn-start {
  width: 100%;
  padding: 11px 0;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.3px;
  transition: background 0.15s, opacity 0.15s;
}
.btn-start:hover:not(:disabled) { background: var(--accent-hover); }
.btn-start:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ============================================
   QUIZ SCREEN
   ============================================ */
.quiz-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 200px 1fr;
  max-width: 1400px;
  margin: 0 auto;
  width: 100%;
}

/* Sidebar */
.quiz-sidebar {
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  max-height: calc(100vh - 48px);
  position: sticky;
  top: 48px;
}
.sidebar-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 10px;
}
.question-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  margin-bottom: 16px;
}
.q-dot {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.1s;
  position: relative;
}
.q-dot:hover { background: var(--option-hover); }
.q-dot.current {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.q-dot.answered {
  background: #d1d5db;
  color: var(--text-primary);
  border-color: #9ca3af;
}
.q-dot.flagged::after {
  content: '';
  position: absolute;
  top: 1px;
  right: 1px;
  width: 5px;
  height: 5px;
  background: var(--flagged);
  border-radius: 50%;
}
.q-dot.correct-dot {
  background: var(--correct-bg);
  border-color: var(--correct-border);
  color: var(--correct);
}
.q-dot.incorrect-dot {
  background: var(--incorrect-bg);
  border-color: var(--incorrect-border);
  color: var(--incorrect);
}

.sidebar-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.legend-item {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid var(--border);
}
.legend-dot.current { background: var(--accent); border-color: var(--accent); }
.legend-dot.answered { background: #d1d5db; border-color: #9ca3af; }
.legend-dot.flagged-dot { position: relative; background: #fff; }
.legend-dot.flagged-dot::after {
  content: '';
  position: absolute;
  top: -1px; right: -1px;
  width: 5px; height: 5px;
  background: var(--flagged);
  border-radius: 50%;
}

/* Main question area */
.quiz-main {
  padding: 24px 32px;
  display: flex;
  flex-direction: column;
  min-height: calc(100vh - 48px);
}
.question-area { flex: 1; max-width: 780px; }
.question-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-light);
}
.question-num {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  font-weight: 600;
}
.btn-flag {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: 1px solid var(--border);
  padding: 4px 10px;
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.1s;
}
.btn-flag:hover { border-color: var(--flagged); color: var(--flagged); }
.btn-flag.flagged {
  background: #fef3c7;
  border-color: var(--flagged);
  color: var(--flagged);
}

.question-text {
  font-size: 14px;
  line-height: 1.65;
  color: var(--text-primary);
  margin-bottom: 20px;
}
.question-text p { margin-bottom: 10px; }
.question-text ul, .question-text ol {
  padding-left: 20px;
  margin-bottom: 10px;
}
.question-text li { margin-bottom: 4px; }
.question-text table {
  border-collapse: collapse;
  margin: 10px 0;
  font-size: 13px;
  width: auto;
}
.question-text table th,
.question-text table td {
  border: 1px solid var(--border);
  padding: 5px 12px;
  text-align: left;
}
.question-text table th {
  background: var(--sidebar-bg);
  font-weight: 600;
}

/* Options */
.options-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 560px;
}
.option-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid #e5ddd4;
  cursor: pointer;
  transition: background 0.1s;
  user-select: none;
}
.option-item:first-child { border-top: 1px solid #e5ddd4; }
.option-item:hover { background: var(--option-hover); }
.option-item.selected {
  background: var(--selected-bg);
}
.option-item.correct-option {
  background: var(--correct-bg);
  border-color: var(--correct-border);
}
.option-item.incorrect-option {
  background: var(--incorrect-bg);
  border-color: var(--incorrect-border);
}
.option-item.disabled { pointer-events: none; }
.option-letter {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  background: #fff;
  margin-top: 1px;
}
.option-item.selected .option-letter {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}
.option-item.correct-option .option-letter {
  background: var(--correct);
  color: #fff;
  border-color: var(--correct);
}
.option-item.incorrect-option .option-letter {
  background: var(--incorrect);
  color: #fff;
  border-color: var(--incorrect);
}
.option-text {
  font-size: 13px;
  line-height: 1.55;
  padding-top: 2px;
}

/* Explanation panel */
.explanation-area {
  max-width: 780px;
  margin-top: 20px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
}
.explanation-area.hidden { display: none; }
.explanation-header {
  padding: 8px 16px;
  border-bottom: 1px solid var(--border-light);
}
.verdict {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.verdict.correct { color: var(--correct); }
.verdict.incorrect { color: var(--incorrect); }
.explanation-text {
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-secondary);
}
.explanation-text p { margin-bottom: 8px; }
.explanation-text ul, .explanation-text ol { padding-left: 18px; margin-bottom: 8px; }
.explanation-text li { margin-bottom: 3px; }
.explanation-text strong { color: var(--text-primary); }

/* Quiz bottom nav */
.quiz-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 0;
  margin-top: 20px;
  border-top: 1px solid var(--border-light);
  max-width: 780px;
}
.btn-nav {
  padding: 8px 18px;
  background: var(--btn-bg);
  color: var(--btn-text);
  border: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  letter-spacing: 0.2px;
}
.btn-nav:hover { background: #1e293b; }
.btn-nav:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-submit-answer {
  padding: 8px 24px;
  background: var(--accent);
  color: #fff;
  border: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-submit-answer:hover { background: var(--accent-hover); }
.btn-submit-answer:disabled { opacity: 0.35; cursor: not-allowed; }
.btn-end-exam {
  margin-left: auto;
  padding: 8px 18px;
  background: #7c2d12;
  color: #fff;
  border: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-end-exam:hover { background: #9a3412; }

/* ============================================
   RESULTS SCREEN
   ============================================ */
.results-body {
  flex: 1;
  max-width: 900px;
  margin: 0 auto;
  padding: 32px 24px;
  width: 100%;
}
.results-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.result-card {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  padding: 20px;
  text-align: center;
}
.result-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.result-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-top: 4px;
}
.results-detail {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.detail-title {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}
.results-list { max-height: 500px; overflow-y: auto; }
.result-row {
  display: flex;
  align-items: flex-start;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border-light);
  gap: 12px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.1s;
}
.result-row:hover { background: var(--option-hover); }
.result-row .r-num {
  flex-shrink: 0;
  width: 30px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 12px;
}
.result-row .r-indicator {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  margin-top: 1px;
}
.r-indicator.r-correct { color: var(--correct); }
.r-indicator.r-incorrect { color: var(--incorrect); }
.r-indicator.r-skipped { color: var(--text-muted); }
.result-row .r-text {
  flex: 1;
  line-height: 1.5;
  color: var(--text-secondary);
}
.result-row .r-answer {
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  min-width: 60px;
}

/* Expanded explanation in results */
.result-explanation {
  display: none;
  padding: 10px 16px 14px 60px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border-light);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-secondary);
}
.result-explanation.show { display: block; }
.result-explanation p { margin-bottom: 6px; }

.results-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* ============================================
   HISTORY SECTION
   ============================================ */
.history-section {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px 32px;
  width: 100%;
}
.history-panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
}
.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-light);
}
.history-header .panel-title { margin-bottom: 0; }
.btn-clear-history {
  padding: 4px 12px;
  background: none;
  border: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-clear-history:hover {
  border-color: var(--incorrect);
  color: var(--incorrect);
}
.history-empty {
  padding: 24px 20px;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
}
.history-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-bottom: 1px solid var(--border-light);
}
.history-stats.hidden { display: none; }
.stat-mini {
  padding: 12px 16px;
  text-align: center;
  border-right: 1px solid var(--border-light);
}
.stat-mini:last-child { border-right: none; }
.stat-mini-value {
  display: block;
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}
.stat-mini-label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-top: 2px;
}
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.history-table.hidden { display: none; }
.history-table thead th {
  padding: 8px 14px;
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  font-weight: 600;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
}
.history-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
}
.history-table tbody tr:hover { background: var(--option-hover); }
.history-table tbody td {
  padding: 9px 14px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
}
.history-table tbody td:nth-child(4) { font-weight: 600; }
.score-high { color: var(--correct) !important; }
.score-mid { color: var(--flagged) !important; }
.score-low { color: var(--incorrect) !important; }
.history-table .mode-badge {
  display: inline-block;
  padding: 1px 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
  .subject-body { grid-template-columns: 1fr; }
  .subject-grid { grid-template-columns: 1fr; }
  .quiz-layout { grid-template-columns: 1fr; }
  .quiz-sidebar {
    position: static;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid var(--border);
    padding: 12px;
  }
  .question-grid { grid-template-columns: repeat(10, 1fr); }
  .quiz-main { padding: 16px; }
  .results-summary { grid-template-columns: repeat(2, 1fr); }
  .history-stats { grid-template-columns: repeat(2, 1fr); }
  .history-table { font-size: 11px; }
}

@media (max-width: 600px) {
  .question-grid { grid-template-columns: repeat(8, 1fr); }
  .header-bar { padding: 10px 12px; }
  .quiz-main { padding: 12px; }
  .options-container { max-width: 100%; }
  .history-stats { grid-template-columns: repeat(2, 1fr); }
}
