/* =========================================================
   STYLE.CSS - THIẾT KẾ HIỆN ĐẠI, MOBILE-FIRST CHO WEB ÔN TẬP
   ========================================================= */

:root {
  --primary: #3b82f6;
  --primary-dark: #1d4ed8;
  --primary-light: #eff6ff;
  --success: #10b981;
  --success-light: #ecfdf5;
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --border-focus: #93c5fd;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* =================== LAYOUT & CONTAINERS =================== */
.container {
  width: 100%;
  max-width: 880px;
  margin-left: auto;
  margin-right: auto;
  padding: 1rem;
}

.container-sm {
  max-width: 540px;
}

.container-md {
  max-width: 760px;
}

.screen {
  display: none;
  opacity: 0;
  transition: opacity 0.25s ease-in-out;
}

.screen.active {
  display: block;
  opacity: 1;
}

/* =================== CARDS & BUTTONS =================== */
.card {
  background: var(--bg-card);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  padding: 1.5rem;
  margin-bottom: 1.25rem;
}

.badge-tag {
  display: inline-block;
  background: var(--primary-light);
  color: var(--primary-dark);
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 12px;
  border-radius: var(--radius-full);
  margin-bottom: 0.75rem;
}

.exam-pill-badge {
  display: inline-block;
  background: #1e293b;
  color: #fbbf24;
  font-size: 0.75rem;
  font-weight: 800;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  letter-spacing: 0.05em;
  margin-left: 0.5rem;
  vertical-align: middle;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s ease;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

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

.btn-next-exam {
  background: #6366f1;
  box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.btn-next-exam:hover {
  background: #4f46e5;
}

.btn-success {
  background: var(--success);
  color: #fff;
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.3);
}

.btn-success:hover {
  background: #059669;
}

.btn-secondary {
  background: #475569;
  color: #fff;
}

.btn-secondary:hover {
  background: #334155;
}

.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  background: #f1f5f9;
}

.btn-block {
  width: 100%;
}

.btn-lg {
  padding: 0.9rem 1.75rem;
  font-size: 1.1rem;
}

/* =================== MÀN HÌNH 1: ĐĂNG NHẬP & CHỌN ĐỀ =================== */
.intro-card {
  margin-top: 1.5rem;
  text-align: center;
  padding: 2.25rem 1.75rem;
}

.title-primary {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1rem;
  margin-bottom: 1.25rem;
}

/* Hộp chọn đề thi */
.exam-selector-box {
  background: #f0fdf4;
  border: 1.5px solid #bbf7d0;
  border-radius: var(--radius-md);
  padding: 1rem;
  margin-bottom: 1.25rem;
  text-align: left;
}

.exam-selector-label {
  display: block;
  font-size: 0.85rem;
  color: #166534;
  margin-bottom: 0.4rem;
}

.selector-wrapper select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
  background: #ffffff;
  border: 1.5px solid #86efac;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.selector-wrapper select:focus {
  outline: none;
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

.selector-note {
  display: block;
  font-size: 0.8rem;
  color: #15803d;
  margin-top: 0.4rem;
  font-style: italic;
}

.exam-rules {
  background: #f8fafc;
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  text-align: left;
  margin-bottom: 1.5rem;
  font-size: 0.95rem;
}

.exam-rules h3 {
  font-size: 1rem;
  margin-bottom: 0.5rem;
  color: var(--text-main);
}

.exam-rules ul {
  padding-left: 1.25rem;
  margin-bottom: 1rem;
}

.exam-rules li {
  margin-bottom: 0.35rem;
}

.exam-meta-pill {
  display: flex;
  justify-content: space-between;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.85rem;
  border: 1px solid var(--border-color);
}

.login-form {
  text-align: left;
}

.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 0.35rem;
}

.required {
  color: var(--danger);
}

.form-group input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-family: inherit;
  transition: border-color 0.2s;
}

.form-group input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.error-msg {
  color: var(--danger);
  font-size: 0.8rem;
  margin-top: 0.25rem;
  display: block;
  min-height: 1.1rem;
}

/* =================== MÀN HÌNH 2: LÀM BÀI =================== */
.exam-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
}

.student-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.avatar-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: var(--primary-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
}

.chip-name {
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.2;
}

.chip-class {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.timer-box {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--warning-light);
  color: #b45309;
  border: 1px solid #fde68a;
  padding: 0.4rem 0.85rem;
  border-radius: var(--radius-full);
  font-weight: 700;
  font-size: 0.95rem;
}

.timer-box.urgent {
  background: var(--danger-light);
  color: var(--danger);
  border-color: #fecaca;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.progress-box {
  min-width: 130px;
  text-align: right;
}

.progress-text {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.progress-bar-bg {
  width: 100%;
  height: 6px;
  background: #e2e8f0;
  border-radius: var(--radius-full);
  overflow: hidden;
  margin-top: 4px;
}

.progress-bar-fill {
  width: 0%;
  height: 100%;
  background: var(--primary);
  transition: width 0.3s ease;
}

.exam-main {
  padding-top: 1.5rem;
  padding-bottom: 4rem;
}

/* Nhãn phân loại phần thi */
.section-header-banner {
  background: #1e293b;
  color: #fff;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  margin: 1.75rem 0 1rem 0;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-header-banner:first-of-type {
  margin-top: 0;
}

/* Card câu hỏi */
.question-card {
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 1.25rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: border-color 0.2s;
}

.question-card.answered {
  border-left: 4px solid var(--primary);
}

.question-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.question-number {
  font-weight: 800;
  color: var(--primary-dark);
  font-size: 0.95rem;
}

.question-points {
  font-size: 0.75rem;
  background: #f1f5f9;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  color: var(--text-muted);
}

.question-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 1rem;
  line-height: 1.5;
}

/* DẠNG 1: LỰA CHỌN PHƯƠNG ÁN */
.options-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.option-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all 0.15s ease;
}

.option-item:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.option-item.selected {
  background: var(--primary-light);
  border-color: var(--primary);
}

.option-item input[type="radio"] {
  margin-top: 0.25rem;
  accent-color: var(--primary);
  cursor: pointer;
}

.option-label {
  font-size: 0.95rem;
  line-height: 1.45;
  cursor: pointer;
  flex: 1;
}

/* DẠNG 2: ĐÚNG / SAI (SEGMENTED BUTTONS) */
.tf-items-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.tf-item {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

@media (min-width: 640px) {
  .tf-item {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.tf-text {
  font-size: 0.95rem;
  flex: 1;
}

.tf-sub-id {
  font-weight: 700;
  color: var(--primary);
  margin-right: 0.25rem;
}

/* Nút Đúng / Sai */
.tf-btn-group {
  display: inline-flex;
  gap: 0.5rem;
  background: #e2e8f0;
  padding: 4px;
  border-radius: var(--radius-md);
  align-self: flex-start;
}

.tf-btn {
  padding: 0.45rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
  color: #475569;
  transition: all 0.15s ease;
}

.tf-btn:hover {
  background: rgba(255, 255, 255, 0.6);
}

.tf-btn.selected-true {
  background: #10b981;
  color: #fff;
  box-shadow: var(--shadow-sm);
}

.tf-btn.selected-false {
  background: #ef4444;
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* DẠNG 3: TỰ LUẬN */
.essay-textarea {
  width: 100%;
  min-height: 120px;
  padding: 0.85rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: 0.95rem;
  resize: vertical;
  line-height: 1.5;
  transition: border-color 0.2s;
}

.essay-textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.exam-footer {
  text-align: center;
  margin-top: 2rem;
}

/* =================== MÀN HÌNH 3: KẾT QUẢ =================== */
.result-card {
  text-align: center;
  padding: 2rem 1.5rem;
}

.trophy-badge {
  font-size: 3rem;
  margin-bottom: 0.5rem;
}

.result-meta-line {
  margin-top: 0.25rem;
  margin-bottom: 1rem;
}

.score-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.score-card {
  background: #f8fafc;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  text-align: center;
}

.score-total {
  grid-column: 1 / -1;
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-color: #bfdbfe;
}

.score-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.score-val {
  font-size: 2.75rem;
  font-weight: 800;
  color: var(--primary-dark);
  line-height: 1.1;
  margin: 0.25rem 0;
}

.score-val-sm {
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main);
  margin-top: 0.25rem;
}

.score-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Trạng thái gửi Google Sheets */
.sync-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

.sync-loading {
  background: var(--warning-light);
  color: #b45309;
}

.sync-success {
  background: var(--success-light);
  color: #065f46;
}

.sync-failed {
  background: var(--danger-light);
  color: #991b1b;
}

.action-buttons {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  flex-wrap: wrap;
}

/* Xem lại bài làm */
.review-heading {
  font-size: 1.3rem;
  margin: 2rem 0 1rem 0;
  color: var(--text-main);
}

.review-item {
  background: #fff;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.review-item.status-correct {
  border-left: 4px solid var(--success);
}

.review-item.status-wrong {
  border-left: 4px solid var(--danger);
}

.review-item.status-essay {
  border-left: 4px solid var(--warning);
}

.review-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.badge-correct {
  background: var(--success-light);
  color: var(--success);
}

.badge-wrong {
  background: var(--danger-light);
  color: var(--danger);
}

.badge-essay {
  background: var(--warning-light);
  color: #b45309;
}

.explanation-box {
  background: #f8fafc;
  border-left: 3px solid var(--primary);
  padding: 0.75rem 1rem;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  margin-top: 0.75rem;
  font-size: 0.9rem;
}

.explanation-box strong {
  color: var(--primary-dark);
}

.essay-compare-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-top: 0.75rem;
}

@media (min-width: 640px) {
  .essay-compare-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.essay-box-student {
  background: #f1f5f9;
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

.essay-box-suggested {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
}

/* =================== MODAL =================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  backdrop-filter: blur(4px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal-box {
  background: #fff;
  border-radius: var(--radius-lg);
  max-width: 440px;
  width: 100%;
  padding: 1.75rem;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.modal-box h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
}

.modal-box p {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-bottom: 1.5rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
}

/* =================== PRINT STYLES =================== */
@media print {
  .exam-header, .action-buttons, .btn, .modal-overlay, .sync-banner {
    display: none !important;
  }
  body {
    background: #fff;
  }
  .card, .review-item {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}
