﻿/* ============================================================
   Quiz PWA — UI styles M4
   - CSS variables + dark mode (data-theme="dark")
   - Responsive (mobile-first)
   - Sticky topbar + sticky progress
   - Subtle animation
   ============================================================ */

:root {
  --primary: #1a73e8;
  --primary-hover: #1557b0;
  --primary-soft: #e8f0fe;

  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --border: #e1e4e8;

  --text: #1f2328;
  --text-muted: #57606a;

  --success: #2e7d32;
  --success-bg: #e8f5e9;
  --danger: #c62828;
  --danger-bg: #ffebee;
  --warning: #f9a825;
  --warning-bg: #fff8e1;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.10);
  --radius: 10px;
  --radius-sm: 6px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;

  --transition: 180ms ease;
}

[data-theme="dark"] {
  --primary: #8ab4f8;
  --primary-hover: #aecbfa;
  --primary-soft: #1a2233;

  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232b;
  --border: #30363d;

  --text: #e6edf3;
  --text-muted: #8b949e;

  --success: #4ade80;
  --success-bg: #14301c;
  --danger: #f87171;
  --danger-bg: #3a1818;
  --warning: #fbbf24;
  --warning-bg: #3a2a05;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  margin: 0;
  padding: 0 var(--space-4) var(--space-6);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  transition: background var(--transition), color var(--transition);
}

main,
.container {
  max-width: 960px;
  margin: 0 auto;
}

/* ===== Top bar (sticky) ===== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  background: var(--bg);
  padding: var(--space-3) 0;
  margin-bottom: var(--space-3);
  border-bottom: 1px solid transparent;
  transition: border-color var(--transition);
}

.topbar.scrolled {
  border-bottom-color: var(--border);
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.topbar-actions {
  display: flex;
  gap: var(--space-2);
}

/* ===== Login Modal ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-content {
  background: var(--surface);
  padding: var(--space-4);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 400px;
  width: 90%;
  border: 1px solid var(--border);
}

.modal-content h2 {
  margin-top: 0;
  margin-bottom: var(--space-2);
  color: var(--text);
}

.modal-content p {
  margin-bottom: var(--space-3);
  color: var(--text-muted);
}

.modal-content input {
  width: 100%;
  padding: var(--space-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
}

.modal-content input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

/* ===== Tabs Navigation ===== */
.tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  background: var(--surface);
  padding: var(--space-2);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  min-width: 100px;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  white-space: nowrap;
}

.tab-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

.tab-btn.active {
  background: var(--primary);
  color: white;
}

.tab-content {
  display: none !important;
  animation: fadeIn 200ms ease;
}

.tab-content.active {
  display: block !important;
}

/* ===== Timer Display ===== */
.timer-display {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  padding: var(--space-3);
  background: var(--primary-soft);
  border-radius: var(--radius);
  margin-bottom: var(--space-3);
  border: 2px solid var(--primary);
}

.timer-display.warning {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger);
  animation: pulse 1s infinite;
}

@keyframes pulse {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.7;
  }
}

/* ===== Review List ===== */
#reviewList {
  max-height: 500px;
  overflow-y: auto;
  margin: var(--space-3) 0;
}

.review-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}

.review-item h4 {
  margin: 0 0 var(--space-2);
  font-size: 0.95rem;
  color: var(--text);
}

.review-item .correct-answer {
  color: var(--success);
  font-weight: 600;
  margin-top: var(--space-2);
}

.review-item .your-answer {
  color: var(--danger);
  font-weight: 600;
}

/* ===== Buttons ===== */
button,
.btn {
  font: inherit;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: var(--primary);
  color: white;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  font-weight: 500;
}

button:hover,
.btn:hover {
  background: var(--primary-hover);
}

button:active,
.btn:active {
  transform: translateY(1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.ghost {
  background: transparent;
  color: var(--primary);
  border-color: var(--primary);
}

button.ghost:hover {
  background: var(--primary-soft);
}

button.icon-only {
  padding: 6px;
  width: 36px;
  height: 36px;
  justify-content: center;
}

button .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

select,
input[type="file"] {
  font: inherit;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

select:focus,
input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

/* ===== Banner / Cards ===== */
.banner {
  background: var(--warning-bg);
  border: 1px solid var(--warning);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.banner span {
  flex: 1;
  min-width: 200px;
  font-size: 14px;
  color: var(--text);
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

#status {
  color: var(--text-muted);
  font-size: 13px;
  margin: var(--space-2) 0;
  min-height: 18px;
}

label {
  color: var(--text);
}

.row {
  margin: var(--space-3) 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

#sheetSelector,
#settings {
  display: none;
}

#sheetSelector.show,
#settings.show {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

#examSheetSelector,
#examSettings,
#examTimerSettings {
  display: none;
}

#examSheetSelector.show,
#examSettings.show,
#examTimerSettings.show {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  align-items: center;
}

/* ===== History panel ===== */
#historyPanel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
  max-height: 360px;
  overflow-y: auto;
}

#historyPanel table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

#historyPanel th,
#historyPanel td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
}

#historyPanel th {
  background: var(--surface-2);
  font-weight: 600;
  position: sticky;
  top: 0;
}

.history-good {
  color: var(--success);
  font-weight: 600;
}

.history-bad {
  color: var(--danger);
  font-weight: 600;
}

/* ===== Round info & progress ===== */
#roundInfo {
  font-weight: 600;
  color: var(--text-muted);
  margin: var(--space-2) 0;
  font-size: 14px;
}

/* progress cũ — đã chuyển vào .quiz-sidebar */
#progress-legacy {
  display: none;
}

.progress-item {
  min-width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  font-weight: 600;
  font-size: 13px;
  user-select: none;
  transition: transform var(--transition);
}

.progress-item:hover {
  transform: scale(1.06);
}

.progress-item.answered {
  background: var(--warning-bg);
  border-color: var(--warning);
  color: #6b4f00;
}

.progress-item.correct {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.progress-item.incorrect {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}

[data-theme="dark"] .progress-item.answered {
  color: var(--warning);
}

/* ===== Question card ===== */
.question {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--space-4);
  margin-bottom: var(--space-3);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  border-left: 4px solid transparent;
  animation: fadeIn 200ms ease;
}

.question.correct {
  border-left-color: var(--success);
}

.question.incorrect {
  border-left-color: var(--danger);
}

.question h3 {
  margin: 0 0 var(--space-3);
  font-size: 1rem;
  line-height: 1.55;
  font-weight: 600;
  color: var(--text);
}

.option {
  display: block;
  margin: 6px 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: var(--surface-2);
  border: 1px solid transparent;
  transition: background var(--transition), border-color var(--transition);
}

.option:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
}

.option input {
  margin-right: 10px;
  accent-color: var(--primary);
}

.feedback {
  font-weight: 600;
  margin-top: var(--space-3);
  font-size: 14px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
}

.feedback:empty {
  display: none;
}

.feedback.correct {
  color: var(--success);
  background: var(--success-bg);
}

.feedback.incorrect {
  color: var(--danger);
  background: var(--danger-bg);
}

#result {
  margin-top: var(--space-4);
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--primary);
  padding: var(--space-3) var(--space-4);
  background: var(--primary-soft);
  border-radius: var(--radius);
}

#result:empty {
  display: none;
}

/* ===== Action bar (Submit / Next) ===== */
.actions {
  display: flex;
  gap: var(--space-2);
  margin: var(--space-3) 0;
  flex-wrap: wrap;
}

/* ===== Exam Result Box ===== */
.exam-result-box {
  padding: var(--space-6);
  text-align: center;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  margin-top: var(--space-4);
}

.exam-result-box h2 {
  margin: 0 0 var(--space-3);
  font-size: 1.5rem;
  color: var(--primary);
}

.exam-result-box p {
  margin: var(--space-2) 0;
  font-size: 1rem;
}

.exam-result-box p strong {
  font-size: 1.1em;
}

.exam-result-box .time-up-notice {
  color: var(--danger);
  font-weight: 600;
}

.exam-result-box .hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: var(--space-4);
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ===== Responsive ===== */
@media (max-width: 600px) {
  body {
    padding: 0 var(--space-3) var(--space-4);
    font-size: 14.5px;
  }

  .topbar h1 {
    font-size: 1rem;
  }

  .topbar {
    padding: var(--space-2) 0;
  }

  #progress {
    top: 50px;
  }

  .progress-item {
    min-width: 28px;
    height: 28px;
    font-size: 12px;
    padding: 0 6px;
  }

  .question {
    padding: var(--space-3);
  }

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

@media (min-width: 1024px) {
  .topbar h1 {
    font-size: 1.3rem;
  }
}

/* Hide visually but keep accessible */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Auth Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  animation: fadeIn 150ms ease;
}

.modal-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: var(--space-6);
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--border);
  position: relative;
}

.modal-close {
  position: absolute;
  top: var(--space-3);
  right: var(--space-3);
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.modal-tabs {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  border-bottom: 2px solid var(--border);
  padding-bottom: var(--space-2);
}

.modal-tab {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.modal-tab.active {
  color: var(--primary);
  background: var(--primary-soft);
}

.modal-tab:hover:not(.active) {
  background: var(--surface-2);
}

.form-group {
  margin-bottom: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.form-group label {
  font-weight: 600;
  font-size: 14px;
}

.form-group input {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  transition: border-color var(--transition);
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
}

button.full-width {
  width: 100%;
  justify-content: center;
  margin-bottom: var(--space-2);
  padding: 11px;
  font-size: 15px;
}

button.full-width img {
  margin-right: var(--space-2);
}

.divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
  margin: var(--space-2) 0;
  position: relative;
}

.divider::before,
.divider::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 42%;
  height: 1px;
  background: var(--border);
}

.divider::before {
  left: 0;
}

.divider::after {
  right: 0;
}

.auth-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: var(--space-2);
  min-height: 18px;
}

/* ===== User info topbar ===== */
.user-info {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

#currentUserDisplay {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ===== Cloud sync badge ===== */
.sync-badge {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ===== Code input ===== */
#codeSettings {
  display: none;
}

#codeSettings.show {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin-top: var(--space-2);
}

gap: var(--space-2);
align-items: center;
margin-top: var(--space-2);
}

input[style*="uppercase"] {
  text-transform: uppercase;
}

/* ===== History table ===== */
.history-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.history-table th {
  background: var(--surface-2);
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
}

.history-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}

.history-good {
  color: var(--success);
  font-weight: 600;
}

.history-bad {
  color: var(--danger);
  font-weight: 600;
}

/* ===== Admin link in topbar ===== */
a.ghost.btn-sm {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  border: 1px solid var(--border);
  color: var(--text);
}

a.ghost.btn-sm:hover {
  background: var(--surface-2);
}

/* ===== Load source 2 cột ===== */
.load-source-row {
  display: flex;
  gap: 0;
  align-items: stretch;
}

.load-source-col {
  flex: 1;
  padding: var(--space-3);
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  transition: border-color var(--transition), background var(--transition);
  min-width: 0;
}

.load-source-col.active {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.load-source-label {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
}

.load-source-divider {
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.load-source-divider::before,
.load-source-divider::after {
  content: "";
  display: block;
  width: 1px;
  height: 40px;
  background: var(--border);
  margin: 0 8px;
}

@media (max-width: 500px) {
  .load-source-row {
    flex-direction: column;
  }

  .load-source-divider {
    flex-direction: row;
    padding: 8px 0;
  }

  .load-source-divider::before,
  .load-source-divider::after {
    width: 40px;
    height: 1px;
  }
}

/* ===== Quiz layout 2 cột ===== */
.quiz-layout {
  display: flex;
  gap: var(--space-4);
  align-items: stretch;
  /* sidebar kéo dài bằng main để sticky hoạt động */
}

.quiz-main {
  flex: 1;
  min-width: 0;
}

.quiz-sidebar {
  width: 176px;
  flex-shrink: 0;
  /* Sidebar cao bằng main → sticky mới có không gian scroll */
  position: relative;
}

.sidebar-sticky {
  position: sticky;
  top: calc(var(--topbar-h, 56px) + 12px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  box-shadow: var(--shadow-md);
  max-height: calc(100vh - var(--topbar-h, 56px) - 32px);
  overflow-y: auto;
}

.sidebar-title {
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}

.quiz-sidebar #progress {
  position: static;
  background: transparent;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

.quiz-sidebar .progress-item {
  min-width: unset;
  width: 100%;
  height: 34px;
  font-size: 12px;
  padding: 0;
}

@media (max-width: 700px) {
  .quiz-layout {
    flex-direction: column;
  }

  .quiz-sidebar {
    width: 100%;
    order: -1;
    position: static;
  }

  .sidebar-sticky {
    position: static;
    max-height: none;
    box-shadow: var(--shadow-sm);
  }

  .quiz-sidebar #progress {
    grid-template-columns: repeat(auto-fill, minmax(30px, 1fr));
  }
}
}

/* examProgress dùng chung style với progress trong sidebar */
.quiz-sidebar #examProgress {
  position: static;
  background: transparent;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
}

/* ===== Timer trong sidebar ===== */
.timer-display-sidebar {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  padding: var(--space-2) var(--space-1);
  background: var(--primary-soft);
  border-radius: var(--radius-sm);
  margin-bottom: var(--space-3);
  border: 2px solid var(--primary);
  letter-spacing: 1px;
}

.timer-display-sidebar.warning {
  color: var(--danger);
  background: var(--danger-bg);
  border-color: var(--danger);
  animation: pulse 1s infinite;
}

/* ===== Progress grid trong sidebar ===== */
.progress-grid {
  display: grid !important;
  grid-template-columns: repeat(4, 1fr) !important;
  gap: 5px !important;
  position: static !important;
  background: transparent !important;
  padding: 0 !important;
}

.progress-grid .progress-item {
  min-width: unset !important;
  width: 100% !important;
  height: 44px !important;
  font-size: 14px !important;
  font-weight: 700 !important;
  padding: 0 !important;
  border-radius: 10px !important;
}