/* ==========================================================================
   cbt.css - Stylesheet Ujian CBT Multi-Type V1.6.6
   Update: Dynamic CSS Variables Font, Clean Soft Badges, & Grid Auto Actions
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. GLOBAL VARIABLES & RESET
   -------------------------------------------------------------------------- */
:root {
  --brand-primary: #1e293b;
  --accent-blue: #2563eb;
  --bg-main: #f8fafc;
  --text-dark: #334155;
  --text-muted: #64748b;
  --border-light: 1px solid #e2e8f0;
  --shadow-card: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  
  /* Status Warna Grid Soal */
  --color-unanswered: #94a3b8;
  --color-answered: #16a34a;
  --color-doubt: #f59e0b;
  --color-active: #2563eb;
  --color-danger: #ef4444;

  /* Font-Size Variable Dinamis */
  --cbt-font-size: 16px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-main);
  color: var(--text-dark);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

/* --------------------------------------------------------------------------
   2. ARENA SOAL CBT (Page Layout)
   -------------------------------------------------------------------------- */
.cbt-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Header Atas Ujian */
.top-bar {
  background: #ffffff;
  border-bottom: 2px solid #e2e8f0;
  color: var(--text-dark);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 25px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  z-index: 20;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 15px;
}

.logo-img {
  height: 42px;
  width: auto;
}

.title-box h2 {
  font-size: 1.1rem;
  letter-spacing: 0.5px;
  color: var(--brand-primary);
  text-transform: uppercase;
}

.title-box small {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  background: #dbeafe;
  border: 1px solid #93c5fd;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  color: var(--brand-primary);
}

.user-details {
  display: flex;
  flex-direction: column;
  font-size: 0.8rem;
}

.u-name {
  font-weight: 700;
  color: var(--text-dark);
}

.u-id {
  color: var(--text-muted);
}

.btn-keluar {
  color: var(--color-danger);
  text-decoration: none;
  font-size: 0.7rem;
  font-weight: bold;
  margin-top: 2px;
  cursor: pointer;
}

.btn-keluar:hover {
  text-decoration: underline;
}

.cbt-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  background: var(--bg-main);
}

/* Area Soal (Kiri) */
.question-area {
  flex: 1;
  padding: 25px 30px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sub-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px dashed #cbd5e1;
  padding-bottom: 12px;
  margin-bottom: 16px;
}

.q-title {
  font-size: 1.2rem;
  color: var(--brand-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.timer-display {
  background: #f0fdf4;
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid #86efac;
  font-weight: 700;
  color: #166534;
  letter-spacing: 1px;
}

/* --------------------------------------------------------------------------
   3. OVERRIDE CONTAINER & BADGE METADATA DINAMIS (V1.6.6)
   -------------------------------------------------------------------------- */
/* Strip total background/border bawaan elemen #q-level */
#q-level {
  background: transparent !important;
  background-color: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 0 !important;
  margin-bottom: 12px;
}

.question-badges-wrapper {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
  background: transparent !important;
  padding: 0 !important;
  border: none !important;
  box-shadow: none !important;
}

.badge-tag {
  font-size: 0.75rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  line-height: 1.2;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  transition: all 0.2s ease;
}

/* 1. Section (Mata Pelajaran) - Soft Sky Blue */
.badge-section {
  background-color: #e0f2fe;
  color: #0369a1;
  border: 1px solid #bae6fd;
}

/* 2. Subtest (Materi / Topik) - Soft Purple */
.badge-subtest {
  background-color: #f3e8ff;
  color: #6b21a8;
  border: 1px solid #e9d5ff;
}

/* 3. Level Kesulitan Soal */
.badge-level {
  background-color: #fef9c3;
  color: #a16207;
  border: 1px solid #fde047;
}

.badge-level.easy,
.badge-level.e {
  background-color: #dcfce7;
  color: #15803d;
  border: 1px solid #86efac;
}

.badge-level.medium,
.badge-level.m {
  background-color: #fef9c3;
  color: #a16207;
  border: 1px solid #fde047;
}

.badge-level.hard,
.badge-level.h {
  background-color: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

/* 4. Tipe Soal (1A, 1B, 1C, 2A, 3A, 3B, 4A, 5A) - Soft Indigo */
.badge-tipe {
  background-color: #e0e7ff;
  color: #3730a3;
  border: 1px solid #c7d2fe;
}

/* --------------------------------------------------------------------------
   4. TOOLBAR UKURAN FONT & CONTENT CONTAINER
   -------------------------------------------------------------------------- */
.font-size-toolbar {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  margin-bottom: 14px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #f9fafb;
  border: 1px solid #e5e7eb;
}

.btn-font-size {
  background-color: #ffffff;
  color: #374151;
  border: 1px solid #d1d5db;
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.15s ease-in-out;
}

.btn-font-size:hover {
  background-color: #eff6ff;
  border-color: #93c5fd;
  color: #2563eb;
}

.question-content {
  background: #ffffff;
  padding: 25px;
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  border: var(--border-light);
  flex: 1;
  position: relative;
  z-index: 10;
}

.img-box img,
.img-soal {
  max-width: 100%;
  max-height: 320px;
  border-radius: 10px;
  margin-bottom: 20px;
  border: 1px solid #e2e8f0;
  display: block;
  object-fit: contain;
}

.q-text {
  font-size: var(--cbt-font-size, 1rem);
  line-height: 1.6;
  color: var(--text-dark);
  margin-bottom: 25px;
  white-space: pre-line;
  word-break: break-word;
  transition: font-size 0.2s ease;
}

/* --------------------------------------------------------------------------
   5. OPSI PILIHAN GANDA (Tipe 1A, 1B, 1C, 2A, 5A)
   -------------------------------------------------------------------------- */
.options-group,
#options-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
  z-index: 10;
  font-size: var(--cbt-font-size, 1rem);
  transition: font-size 0.2s ease;
}

.option-row {
  display: flex;
  align-items: flex-start;
  padding: 12px 18px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(0, 0, 0, 0.05);
  user-select: none;
}

.option-row:hover {
  background: #eff6ff;
  border-color: #93c5fd;
  transform: translateX(4px);
}

.option-row.selected {
  background: #dbeafe;
  border-color: var(--accent-blue);
  box-shadow: inset 0 0 5px rgba(37, 99, 235, 0.1);
}

.option-row input[type="radio"],
.option-row input[type="checkbox"] {
  margin-right: 15px;
  margin-top: 4px;
  accent-color: var(--accent-blue);
  transform: scale(1.2);
}

.opt-key {
  font-weight: 700;
  margin-right: 8px;
  color: var(--brand-primary);
  line-height: 1.5;
}

.opt-val {
  font-size: inherit;
  line-height: 1.5;
  color: var(--text-dark);
  white-space: pre-line;
  word-break: break-word;
}

/* --------------------------------------------------------------------------
   6. INPUT ISIAN SINGKAT & ESAI (Tipe 3A & 3B)
   -------------------------------------------------------------------------- */
.essay-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 15px;
}

.essay-input-single {
  width: 100%;
  padding: 12px 16px;
  font-size: var(--cbt-font-size, 1rem);
  color: var(--text-dark);
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.essay-input-single:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

.essay-input-multi {
  width: 100%;
  min-height: 140px;
  padding: 14px 16px;
  font-size: var(--cbt-font-size, 1rem);
  line-height: 1.5;
  color: var(--text-dark);
  border: 2px solid #cbd5e1;
  border-radius: 10px;
  outline: none;
  resize: vertical;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

.essay-input-multi:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.15);
}

/* --------------------------------------------------------------------------
   7. TABEL MATRIKS BENAR / SALAH (Tipe 4A)
   -------------------------------------------------------------------------- */
.matrix-container {
  width: 100%;
  overflow-x: auto;
  margin-top: 15px;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.matrix-table {
  width: 100%;
  border-collapse: collapse;
  background-color: #ffffff;
}

.matrix-table th {
  background-color: #f1f5f9;
  color: var(--brand-primary);
  font-weight: 700;
  padding: 12px 16px;
  text-align: center;
  border-bottom: 2px solid #cbd5e1;
  font-size: var(--cbt-font-size, 0.95rem);
}

.matrix-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}

.matrix-table tr:last-child td {
  border-bottom: none;
}

.matrix-table tr:hover {
  background-color: #f8fafc;
}

.matrix-statement {
  font-size: var(--cbt-font-size, 0.95rem);
  color: var(--text-dark);
  line-height: 1.5;
}

.matrix-radio-cell {
  text-align: center;
  width: 90px;
}

.matrix-radio-cell input[type="radio"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent-blue);
  cursor: pointer;
}

/* --------------------------------------------------------------------------
   8. FITUR RAGU-RAGU & KOSONGKAN JAWABAN (V1.6.6)
   -------------------------------------------------------------------------- */
.doubt-container {
  margin-top: 15px;
  padding-top: 12px;
  border-top: 1px dashed #cbd5e1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.btn-doubt-label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
  color: var(--color-doubt);
  transition: color 0.15s ease;
}

.btn-doubt-label:hover {
  color: #b45309;
}

/* MathJax / KaTeX Styling Light Mode */
.q-text .mjx-chtml, .opt-val .mjx-chtml,
.q-text .MathJax, .opt-val .MathJax,
.q-text .katex, .opt-val .katex {
  font-size: 105% !important;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  vertical-align: middle;
  color: var(--brand-primary);
}

/* --------------------------------------------------------------------------
   9. SIDEBAR NAVIGASI GRID SOAL & TOMBOL SELESAI (Kanan)
   -------------------------------------------------------------------------- */
.sidebar-nav {
  width: 240px;
  background: #ffffff;
  border-left: var(--border-light);
  padding: 20px 15px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#grid-top-actions {
  margin-bottom: 14px;
  width: 100%;
}

.circle-grid,
.number-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  justify-items: center;
}

/* Kotak Navigasi Soal Rounded Modern */
.circle-btn,
.grid-item,
.btn-nav-num {
  width: 44px;
  height: 44px;
  border-radius: 8px !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0,0,0,0.08);
  transition: all 0.2s ease;
  user-select: none;
  border: 1px solid transparent;
}

.circle-btn:hover,
.grid-item:hover,
.btn-nav-num:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0,0,0,0.12);
}

/* Status Belum Dijawab */
.circle-btn.unanswered,
.grid-item.unanswered {
  background: var(--color-unanswered);
}

/* Status Sudah Dijawab */
.circle-btn.answered,
.grid-item.answered {
  background: var(--color-answered);
}

/* Status Ragu-Ragu */
.circle-btn.doubt,
.grid-item.doubt {
  background: var(--color-doubt) !important;
  color: #ffffff !important;
}

/* Status Soal Aktif */
.circle-btn.active,
.grid-item.active {
  background: #ffffff !important;
  border: 2px solid var(--color-active) !important;
  color: var(--color-active) !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.25);
}

/* --------------------------------------------------------------------------
   10. BOTTOM BAR FOOTER CBT
   -------------------------------------------------------------------------- */
.bottom-bar {
  background: #ffffff;
  border-top: var(--border-light);
  padding: 12px 25px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}

.btn-footer {
  padding: 10px 18px;
  background: #ffffff;
  color: var(--brand-primary);
  border: 1px solid var(--brand-primary);
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.2s ease;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.btn-footer:hover:not(:disabled) {
  background: #eff6ff;
}

.btn-footer:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-selesai {
  background: #16a34a;
  color: #ffffff;
  border: 1px solid #16a34a;
  box-shadow: 0 2px 6px rgba(22, 163, 74, 0.25);
}

.btn-selesai:hover:not(:disabled) {
  background: #15803d;
  color: #ffffff;
}

.bottom-center {
  display: flex;
  gap: 12px;
}

/* --------------------------------------------------------------------------
   11. RESPONSIF MOBILE CBT
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
  .cbt-body {
    flex-direction: column;
  }
  
  .question-area {
    padding: 15px 18px;
  }
  
  .sidebar-nav {
    width: 100%;
    max-height: 220px;
    border-left: none;
    border-top: var(--border-light);
    padding: 15px;
  }
  
  .circle-grid,
  .number-grid {
    grid-template-columns: repeat(auto-fill, minmax(42px, 1fr));
    gap: 10px;
  }

  .top-bar {
    padding: 10px 15px;
  }

  .bottom-bar {
    padding: 10px 15px;
    flex-wrap: wrap;
    gap: 10px;
  }

  /* Optimasi Tabel Matriks Tipe 4A di Mobile */
  .matrix-table th, 
  .matrix-table td {
    padding: 10px 8px;
    font-size: 0.85rem;
  }

  .matrix-radio-cell {
    width: 65px;
  }

  .matrix-radio-cell input[type="radio"] {
    width: 18px;
    height: 18px;
  }
}
