/* =============================================
   NIHONGO TEST APP - Global Styles
   ============================================= */

:root {
  --primary: #2E7D32;
  --primary-dark: #1B5E20;
  --primary-light: #E8F5E9;
  --primary-mid: #66BB6A;
  --accent: #E53935;
  --success: #43A047;
  --warning: #FB8C00;
  --info: #039BE5;
  --danger: #E53935;
  --bg: #F5F5F7;
  --surface: #FFFFFF;
  --border: #E0E0E0;
  --text: #212121;
  --text-muted: #757575;
  --text-light: #9E9E9E;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.10);
  --shadow: 0 2px 10px rgba(0,0,0,0.10);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.15);
  --radius: 8px;
  --radius-lg: 14px;
  --radius-xl: 24px;
  --radius-full: 9999px;
  --transition: all 0.2s ease;
  --header-h: 60px;
  --sidebar-w: 240px;
}

/* Reset */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}
a { text-decoration: none; color: inherit; }
img, video, audio { max-width: 100%; display: block; }
button { cursor: pointer; border: none; outline: none; font-family: inherit; }
input, textarea, select { font-family: inherit; outline: none; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c5c5c5; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #a0a0a0; }

/* =============================================
   TYPOGRAPHY
   ============================================= */
h1 { font-size: 2rem; font-weight: 700; }
h2 { font-size: 1.5rem; font-weight: 600; }
h3 { font-size: 1.2rem; font-weight: 600; }
h4 { font-size: 1rem; font-weight: 600; }
p { line-height: 1.6; }

/* =============================================
   BUTTONS
   ============================================= */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 20px; border-radius: var(--radius);
  font-size: 0.9rem; font-weight: 500;
  transition: var(--transition); cursor: pointer;
  border: none; white-space: nowrap;
}
.btn-sm { padding: 6px 14px; font-size: 0.82rem; }
.btn-lg { padding: 13px 28px; font-size: 1rem; }
.btn-icon { padding: 8px; border-radius: var(--radius); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: 0 3px 10px rgba(46,125,50,0.35); transform: translateY(-1px); }

.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-secondary:hover { background: #D1C4E9; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #C62828; box-shadow: 0 3px 10px rgba(229,57,53,0.35); }

.btn-success { background: #388E3C; color: #fff; }
.btn-success:hover { background: #1B5E20; box-shadow: 0 3px 10px rgba(56,142,60,0.35); }

.btn-outline {
  background: transparent; color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-white { background: #fff; color: var(--primary); box-shadow: var(--shadow-sm); }
.btn-white:hover { box-shadow: var(--shadow); transform: translateY(-1px); }

/* =============================================
   FORM CONTROLS
   ============================================= */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: 0.875rem; font-weight: 500; color: var(--text); }
.form-label span.required { color: var(--accent); margin-left: 3px; }

.form-control {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.9rem;
  color: var(--text);
  background: #fff;
  transition: var(--transition);
  width: 100%;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(46,125,50,0.12); }
.form-control::placeholder { color: var(--text-light); }

textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23757575' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

.form-hint { font-size: 0.78rem; color: var(--text-muted); }
.form-error { font-size: 0.78rem; color: var(--accent); }
.form-control.error { border-color: var(--accent); }

/* Rich text editor (question text) */
.rte-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 8px;
  border: 2px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: #fafafa;
}
.q-text-editor {
  min-height: 110px;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  background: #fff;
  font-size: 1rem;
  line-height: 1.5;
}
.q-text-editor:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(46,125,50,0.12);
}
.q-text-editor p { margin: 0 0 8px; }
.q-text-editor ul, .q-text-editor ol { margin: 6px 0 8px 20px; }
.q-text-editor-sm { min-height: 72px; font-size: 0.95rem; }
.q-text-editor[data-placeholder]:empty:before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

/* Form builder sticky toolbar */
.form-builder-sticky-toolbar {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: rgba(255,255,255,0.95);
  border: 1px solid var(--border);
  backdrop-filter: blur(2px);
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }

/* Radio & Checkbox */
.radio-group, .check-group { display: flex; flex-direction: column; gap: 8px; }
.radio-item, .check-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border: 2px solid var(--border);
  border-radius: var(--radius); cursor: pointer;
  transition: var(--transition);
}
.radio-item:hover, .check-item:hover { border-color: var(--primary-mid); background: var(--primary-light); }
.radio-item.selected, .check-item.selected { border-color: var(--primary); background: var(--primary-light); }
.radio-item input, .check-item input { display: none; }

/* =============================================
   CARDS
   ============================================= */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
}
.card-header { padding: 18px 22px; border-bottom: 1px solid var(--border); }
.card-body { padding: 22px; }
.card-footer { padding: 14px 22px; border-top: 1px solid var(--border); background: #FAFAFA; }

/* =============================================
   BADGES & TAGS
   ============================================= */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: var(--radius-full);
  font-size: 0.75rem; font-weight: 600;
}
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: #E8F5E9; color: #2E7D32; }
.badge-warning { background: #FFF3E0; color: #E65100; }
.badge-danger { background: #FFEBEE; color: #C62828; }
.badge-info { background: #E3F2FD; color: #0277BD; }
.badge-gray { background: #F5F5F5; color: #616161; }
.badge-hiragana { background: #FCE4EC; color: #AD1457; }
.badge-katakana { background: #E8EAF6; color: #283593; }

/* =============================================
   MODALS
   ============================================= */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
  opacity: 0; visibility: hidden; transition: var(--transition);
}
.modal-backdrop.open { opacity: 1; visibility: visible; }

.modal {
  background: var(--surface);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 620px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px) scale(0.97);
  transition: var(--transition);
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }
.modal-lg { max-width: 800px; }
.modal-xl { max-width: 1000px; }
.form-builder-modal-wide {
  max-width: min(1400px, 96vw);
  width: min(1400px, 96vw);
  max-height: 94vh;
}

.modal-header {
  padding: 20px 24px;
  display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-header h3 { font-size: 1.15rem; }
.modal-close {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem; color: var(--text-muted);
  transition: var(--transition);
}
.modal-close:hover { background: #E0E0E0; color: var(--text); }

.modal-body { padding: 24px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 16px 24px;
  display: flex; justify-content: flex-end; gap: 10px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* =============================================
   TOAST NOTIFICATIONS
   ============================================= */
#toast-container {
  position: fixed; bottom: 24px; right: 24px;
  z-index: 9999; display: flex; flex-direction: column; gap: 10px;
}
.toast {
  min-width: 280px; max-width: 380px;
  padding: 14px 18px;
  border-radius: var(--radius-lg);
  display: flex; align-items: flex-start; gap: 12px;
  box-shadow: var(--shadow-lg);
  color: #fff; font-size: 0.9rem;
  animation: slideInToast 0.3s ease forwards;
}
.toast.hide { animation: slideOutToast 0.3s ease forwards; }
.toast-success { background: #2E7D32; }
.toast-error { background: #C62828; }
.toast-warning { background: #E65100; }
.toast-info { background: #0277BD; }
.toast-icon { font-size: 1.2rem; flex-shrink: 0; margin-top: 1px; }
.toast-msg { flex: 1; }
.toast-title { font-weight: 600; margin-bottom: 2px; }
.toast-close { background: none; border: none; color: rgba(255,255,255,0.7); font-size: 1.1rem; cursor: pointer; margin-left: 4px; }

@keyframes slideInToast {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOutToast {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(120%); opacity: 0; }
}

/* =============================================
   CONFIRM DIALOG
   ============================================= */
.confirm-modal { max-width: 420px; }
.confirm-icon { font-size: 3rem; text-align: center; margin-bottom: 12px; }
.confirm-modal .modal-body { text-align: center; }

/* =============================================
   LOADING OVERLAY
   ============================================= */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(255,255,255,0.9);
  display: flex; align-items: center; justify-content: center;
  z-index: 9998; flex-direction: column; gap: 16px;
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid var(--primary-light);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================
   EMPTY STATE
   ============================================= */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px 20px; text-align: center; gap: 14px;
}
.empty-state-icon { font-size: 4rem; opacity: 0.5; }
.empty-state h3 { color: var(--text-muted); font-size: 1.1rem; }
.empty-state p { color: var(--text-light); font-size: 0.9rem; max-width: 300px; }

/* =============================================
   MEDIA PREVIEW
   ============================================= */
.media-preview {
  position: relative; margin-top: 10px;
  border-radius: var(--radius); overflow: hidden;
  border: 2px solid var(--border);
}
.media-preview img { width: 100%; max-height: 300px; object-fit: contain; background: #f9f9f9; }
.media-preview video { width: 100%; max-height: 300px; }
.media-preview audio { width: 100%; }
.media-preview-remove {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.6); color: #fff;
  border: none; border-radius: 50%;
  width: 28px; height: 28px; font-size: 1rem;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* =============================================
   FILE UPLOAD ZONE
   ============================================= */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 30px 20px;
  text-align: center; cursor: pointer;
  transition: var(--transition);
  color: var(--text-muted);
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary); background: var(--primary-light);
  color: var(--primary);
}
.upload-zone-icon { font-size: 2.5rem; margin-bottom: 8px; }
.upload-zone p { font-size: 0.9rem; }
.upload-zone small { font-size: 0.78rem; color: var(--text-light); }

/* =============================================
   TABS
   ============================================= */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid var(--border); margin-bottom: 20px; }
.tab-btn {
  padding: 10px 18px; font-size: 0.9rem; font-weight: 500;
  background: none; border: none; cursor: pointer;
  color: var(--text-muted); border-bottom: 3px solid transparent;
  margin-bottom: -2px; transition: var(--transition);
  border-radius: var(--radius) var(--radius) 0 0;
}
.tab-btn:hover { color: var(--primary); background: var(--primary-light); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* =============================================
   TABLES
   ============================================= */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); }
table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 12px 16px; text-align: left;
  font-size: 0.8rem; font-weight: 600; text-transform: uppercase;
  color: var(--text-muted); background: var(--bg);
  border-bottom: 2px solid var(--border);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 0.9rem; vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFAFA; }
.table-actions { display: flex; gap: 6px; }

/* =============================================
   PAGINATION
   ============================================= */
.pagination { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 20px; }
.page-btn {
  width: 36px; height: 36px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius); border: 1px solid var(--border);
  background: #fff; font-size: 0.875rem; cursor: pointer; transition: var(--transition);
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* =============================================
   STATS CARDS
   ============================================= */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 20px 22px; box-shadow: var(--shadow-sm);
  border: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px;
}
.stat-card-icon { font-size: 2rem; }
.stat-card-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-card-label { font-size: 0.85rem; color: var(--text-muted); }

/* =============================================
   QUESTION CARDS
   ============================================= */
.questions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.question-card {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); overflow: hidden;
  transition: var(--transition); box-shadow: var(--shadow-sm);
}
.question-card:hover { box-shadow: var(--shadow); transform: translateY(-2px); }
.question-card-header { padding: 14px 16px; display: flex; align-items: center; gap: 10px; }
.question-card-number {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; flex-shrink: 0;
}
.question-card-type { font-size: 0.78rem; color: var(--text-muted); }
.question-card-body { padding: 0 16px 14px; }
.question-card-text { font-size: 0.9rem; color: var(--text); margin-bottom: 10px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.question-card-footer { padding: 10px 16px; border-top: 1px solid var(--border); background: #FAFAFA; display: flex; align-items: center; justify-content: space-between; }
.question-card-meta { display: flex; gap: 8px; flex-wrap: wrap; }
.question-card-actions { display: flex; gap: 4px; }

/* =============================================
   TEST CARDS
   ============================================= */
.tests-list { display: flex; flex-direction: column; gap: 12px; }
.test-card {
  background: var(--surface); border-radius: var(--radius-lg);
  border: 1px solid var(--border); padding: 18px 22px;
  display: flex; align-items: center; gap: 16px;
  transition: var(--transition); box-shadow: var(--shadow-sm);
}
.test-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.test-card-icon {
  width: 52px; height: 52px; border-radius: var(--radius-lg);
  background: var(--primary-light); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; flex-shrink: 0;
}
.test-card-info { flex: 1; }
.test-card-title { font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.test-card-meta { display: flex; gap: 12px; flex-wrap: wrap; font-size: 0.82rem; color: var(--text-muted); }
.test-card-meta span { display: flex; align-items: center; gap: 4px; }
.test-card-actions { display: flex; gap: 8px; }

/* =============================================
   MEDIA TABS
   ============================================= */
.media-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
.media-tab-btn {
  padding: 7px 14px; font-size: 0.82rem; font-weight: 500;
  border: 2px solid var(--border); border-radius: var(--radius-full);
  background: #fff; cursor: pointer; color: var(--text-muted);
  transition: var(--transition);
}
.media-tab-btn:hover { border-color: var(--primary-mid); color: var(--primary); }
.media-tab-btn.active { border-color: var(--primary); background: var(--primary); color: #fff; }

/* =============================================
   QUESTION OPTIONS (MC)
   ============================================= */
.options-list { display: flex; flex-direction: column; gap: 8px; }
.option-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border: 2px solid var(--border);
  border-radius: var(--radius); transition: var(--transition);
}
.option-item.correct { border-color: var(--success); background: #E8F5E9; }
.option-letter {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.8rem; font-weight: 700; flex-shrink: 0;
  transition: var(--transition);
}
.option-item.correct .option-letter { background: var(--success); border-color: var(--success); color: #fff; }
.option-input { flex: 1; border: none; background: transparent; font-size: 0.9rem; padding: 0; color: var(--text); }
.option-input:focus { outline: none; }
.option-correct-btn { padding: 5px 10px; font-size: 0.75rem; border-radius: var(--radius-full); }
.option-remove { background: none; border: none; color: var(--text-light); cursor: pointer; font-size: 1rem; padding: 4px; }
.option-remove:hover { color: var(--danger); }

/* =============================================
   ANSWER REVIEW (Result Detail)
   ============================================= */
.answer-review { display: flex; flex-direction: column; gap: 16px; }
.answer-item {
  padding: 16px; border-radius: var(--radius-lg);
  border: 2px solid var(--border);
}
.answer-item.correct { border-color: var(--success); background: #F1F8E9; }
.answer-item.incorrect { border-color: var(--danger); background: #FFEBEE; }
.answer-item.partial { border-color: var(--warning); background: #FFF8E1; }
.answer-item-header { display: flex; justify-content: space-between; margin-bottom: 10px; }
.answer-question-text { font-weight: 500; margin-bottom: 8px; }
.answer-given, .answer-correct { font-size: 0.875rem; margin-top: 4px; }
.answer-given span, .answer-correct span { font-weight: 600; }

/* =============================================
   EXAM INTERFACE
   ============================================= */
.exam-layout { display: grid; grid-template-columns: 1fr 260px; min-height: calc(100vh - var(--header-h)); gap: 0; }
.exam-main { padding: 24px; overflow-y: auto; }
.exam-sidebar {
  background: var(--surface); border-left: 1px solid var(--border);
  padding: 20px 16px; overflow-y: auto;
  position: sticky; top: var(--header-h); max-height: calc(100vh - var(--header-h));
}

.exam-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--primary);
  height: var(--header-h);
  display: flex; align-items: center;
  padding: 0 20px; gap: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}
.exam-header-title { font-size: 1rem; font-weight: 600; color: #fff; flex: 1; }

/* Timer */
.timer-box {
  display: flex; align-items: center; gap: 8px;
  background: rgba(255,255,255,0.2);
  border-radius: var(--radius-lg); padding: 8px 16px;
  color: #fff; font-weight: 600; font-size: 1.1rem;
}
.timer-box.warning { background: #FFA726; animation: pulse 1s infinite; }
.timer-box.danger { background: var(--danger); animation: pulse 0.5s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.7; } }

/* Question Navigator */
.q-navigator { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 16px; }
.q-nav-btn {
  aspect-ratio: 1; border-radius: var(--radius);
  font-size: 0.8rem; font-weight: 600; cursor: pointer;
  border: 2px solid var(--border); background: #fff;
  color: var(--text); transition: var(--transition);
  display: flex; align-items: center; justify-content: center;
}
.q-nav-btn:hover { border-color: var(--primary); color: var(--primary); }
.q-nav-btn.answered { background: var(--primary); color: #fff; border-color: var(--primary); }
.q-nav-btn.current { background: var(--primary-dark); color: #fff; border-color: var(--primary-dark); box-shadow: 0 0 0 3px rgba(46,125,50,0.3); }
.q-nav-btn.flagged { background: #FFF8E1; border-color: var(--warning); color: #E65100; }
.q-nav-btn.answered.flagged { background: #FFE082; border-color: var(--warning); color: #E65100; }

/* Navigator Legend */
.q-nav-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-size: 0.75rem; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 14px; height: 14px; border-radius: 4px; flex-shrink: 0; }
.legend-dot.unanswered { background: #fff; border: 2px solid var(--border); }
.legend-dot.answered { background: var(--primary); }
.legend-dot.current { background: var(--primary-dark); }
.legend-dot.flagged { background: #FFE082; border: 2px solid var(--warning); }

/* Question Display */
.question-display {
  background: var(--surface); border-radius: var(--radius-xl);
  box-shadow: var(--shadow); border: 1px solid var(--border);
  overflow: hidden; max-width: 800px;
}
.question-display-header {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  padding: 18px 24px; color: #fff;
  display: flex; align-items: center; justify-content: space-between;
}
.question-number { font-size: 0.875rem; opacity: 0.85; }
.question-points { font-weight: 600; font-size: 0.9rem; }
.question-display-body { padding: 24px; }
.question-text { font-size: 1.05rem; line-height: 1.7; margin-bottom: 20px; }
.question-text p { margin: 0 0 8px; }
.question-text ul, .question-text ol { margin: 6px 0 10px 20px; }
.question-media { margin-bottom: 20px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); }
.question-media img { width: 100%; max-height: 300px; object-fit: contain; background: #f9f9f9; }
.question-media video, .question-media audio { width: 100%; }

/* Answer Options */
.answer-options { display: flex; flex-direction: column; gap: 10px; }
.answer-opt {
  display: flex; align-items: center; gap: 12px;
  padding: 13px 16px; border: 2px solid var(--border);
  border-radius: var(--radius-lg); cursor: pointer;
  transition: var(--transition); background: #fff;
}
.answer-opt:hover { border-color: var(--primary-mid); background: var(--primary-light); }
.answer-opt.selected { border-color: var(--primary); background: var(--primary-light); }
.answer-opt.correct-reveal { border-color: var(--success); background: #E8F5E9; }
.answer-opt.wrong-reveal { border-color: var(--danger); background: #FFEBEE; }
.answer-opt-letter {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; flex-shrink: 0;
  transition: var(--transition);
}
.answer-opt.selected .answer-opt-letter { background: var(--primary); border-color: var(--primary); color: #fff; }
.answer-opt-text { flex: 1; font-size: 0.95rem; }

/* Short answer input */
.short-answer-input {
  width: 100%; padding: 13px 16px;
  border: 2px solid var(--border); border-radius: var(--radius-lg);
  font-size: 1rem; transition: var(--transition);
}
.short-answer-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(46,125,50,0.12); }

/* Question nav buttons */
.question-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 20px; }
.flag-btn { display: flex; align-items: center; gap: 6px; }
.flag-btn.flagged { color: var(--warning); }

/* =============================================
   EXAM SCREENS (Start, Instructions, Results)
   ============================================= */
.screen {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  padding: 20px; background: var(--bg);
}
.screen-card {
  background: var(--surface); border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg); padding: 40px;
  width: 100%; max-width: 520px;
  border: 1px solid var(--border);
}
.screen-card-lg { max-width: 700px; }
.screen-header { text-align: center; margin-bottom: 32px; }
.screen-icon { font-size: 3.5rem; margin-bottom: 16px; }
.screen-title { font-size: 1.6rem; font-weight: 700; color: var(--primary-dark); margin-bottom: 8px; }
.screen-subtitle { color: var(--text-muted); font-size: 0.95rem; }

/* Test selector */
.test-selector { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.test-select-item {
  padding: 14px 18px; border: 2px solid var(--border);
  border-radius: var(--radius-lg); cursor: pointer;
  transition: var(--transition); background: #fff;
  display: flex; align-items: center; gap: 14px;
}
.test-select-item:hover { border-color: var(--primary-mid); background: var(--primary-light); }
.test-select-item.selected { border-color: var(--primary); background: var(--primary-light); }
.test-select-icon {
  width: 42px; height: 42px; border-radius: var(--radius);
  background: var(--primary-light); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}
.test-select-info { flex: 1; }
.test-select-title { font-weight: 600; font-size: 0.95rem; }
.test-select-meta { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* Result screen */
.result-score-circle {
  width: 160px; height: 160px; border-radius: 50%;
  border: 10px solid var(--primary-light);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  margin: 0 auto 24px;
  position: relative;
}
.result-score-circle.pass { border-color: var(--success); }
.result-score-circle.fail { border-color: var(--danger); }
.result-score-value { font-size: 2.5rem; font-weight: 800; }
.result-score-circle.pass .result-score-value { color: var(--success); }
.result-score-circle.fail .result-score-value { color: var(--danger); }
.result-score-label { font-size: 0.8rem; color: var(--text-muted); }
.result-status-badge {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 20px; border-radius: var(--radius-full);
  font-weight: 700; font-size: 1rem; margin: 0 auto 20px;
}
.result-status-badge.pass { background: #E8F5E9; color: #2E7D32; }
.result-status-badge.fail { background: #FFEBEE; color: #C62828; }
.result-info-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; }
.result-info-item { padding: 12px 16px; background: var(--bg); border-radius: var(--radius-lg); text-align: center; }
.result-info-item .value { font-size: 1.3rem; font-weight: 700; color: var(--primary); }
.result-info-item .label { font-size: 0.78rem; color: var(--text-muted); }

/* Instructions */
.instructions-list { display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px; }
.instruction-item {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 14px; background: var(--bg); border-radius: var(--radius-lg);
}
.instruction-icon { font-size: 1.4rem; flex-shrink: 0; }
.instruction-text { font-size: 0.9rem; }
.instruction-text strong { display: block; margin-bottom: 2px; }

/* Anti-copy mode while exam is running */
body.anti-copy-exam #screenExam .question-display,
body.anti-copy-exam #screenExam .question-text,
body.anti-copy-exam #screenExam .answer-opt-text,
body.anti-copy-exam #screenExam .question-number,
body.anti-copy-exam #screenExam .question-points {
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* =============================================
   LANDING PAGE
   ============================================= */
.landing-bg {
  min-height: 100vh;
  /* Fallback gradient jika gambar belum dimuat */
  background: linear-gradient(135deg, var(--primary-dark) 0%, #2E7D32 50%, #1A3A00 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; position: relative; overflow: hidden;
}
.landing-bg::before {
  content: '';
  position: absolute; inset: 0;
  /* Default subtle overlay — di-override inline di index.html */
  background-image: radial-gradient(circle at 20% 50%, rgba(255,255,255,0.03) 0%, transparent 50%);
}
.landing-kanji-bg {
  position: absolute; inset: 0; overflow: hidden; pointer-events: none;
  display: flex; flex-wrap: wrap; opacity: 0.04; font-size: 6rem;
  font-weight: 900; color: #fff; line-height: 1; gap: 20px; padding: 20px;
  align-content: flex-start; justify-content: center;
}
.landing-card {
  background: rgba(255,255,255,0.97);
  border-radius: 28px;
  padding: 52px 44px;
  width: 100%; max-width: 540px;
  text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
  position: relative; z-index: 1;
}
.landing-logo { font-size: 5rem; margin-bottom: 8px; }
.landing-jp-title {
  font-size: 2.4rem; font-weight: 900;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  margin-bottom: 4px;
}
.landing-subtitle { font-size: 1rem; color: var(--text-muted); margin-bottom: 36px; }
.landing-divider { width: 60px; height: 4px; background: linear-gradient(to right, var(--primary), var(--accent)); border-radius: 2px; margin: 16px auto 32px; }
.landing-btns { display: flex; flex-direction: column; gap: 14px; }
.landing-btn {
  padding: 16px 24px; border-radius: 14px; font-size: 1.05rem; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 12px;
  transition: var(--transition); border: none; cursor: pointer;
}
.landing-btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; }
.landing-btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(46,125,50,0.4); }
.landing-btn-outline { background: transparent; color: var(--primary); border: 2px solid var(--primary); }
.landing-btn-outline:hover { background: var(--primary-light); transform: translateY(-2px); }
.landing-features { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 32px; }
.landing-feature {
  padding: 14px; background: var(--bg); border-radius: 12px;
  display: flex; align-items: center; gap: 10px;
  font-size: 0.85rem; color: var(--text-muted);
}
.landing-feature-icon { font-size: 1.3rem; }

/* =============================================
   ADMIN LAYOUT
   ============================================= */
.admin-layout { display: flex; min-height: 100vh; }

.admin-sidebar {
  width: var(--sidebar-w); background: linear-gradient(180deg, var(--primary-dark) 0%, #2E7D32 100%);
  display: flex; flex-direction: column;
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 200;
  transition: transform 0.3s ease;
}
.admin-sidebar-header { padding: 24px 20px 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.admin-logo { font-size: 2rem; margin-bottom: 8px; }
.admin-app-name { font-size: 1.1rem; font-weight: 700; color: #fff; }
.admin-app-sub { font-size: 0.78rem; color: rgba(255,255,255,0.6); }

.admin-nav { flex: 1; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.admin-nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; border-radius: var(--radius-lg);
  color: rgba(255,255,255,0.75); cursor: pointer;
  transition: var(--transition); font-size: 0.9rem; font-weight: 500;
  border: none; background: none; width: 100%; text-align: left;
}
.admin-nav-item:hover { background: rgba(255,255,255,0.12); color: #fff; }
.admin-nav-item.active { background: rgba(255,255,255,0.2); color: #fff; }
.admin-nav-item .nav-icon { font-size: 1.2rem; flex-shrink: 0; }
.admin-nav-section { font-size: 0.7rem; font-weight: 700; color: rgba(255,255,255,0.4); text-transform: uppercase; letter-spacing: 0.08em; padding: 8px 14px 4px; margin-top: 8px; }

.admin-sidebar-footer { padding: 16px 12px; border-top: 1px solid rgba(255,255,255,0.1); }
.admin-sidebar-user { display: flex; align-items: center; gap: 10px; padding: 8px; }
.admin-user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: rgba(255,255,255,0.2); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 1.1rem;
}
.admin-user-name { font-size: 0.85rem; color: #fff; font-weight: 500; }
.admin-user-role { font-size: 0.72rem; color: rgba(255,255,255,0.6); }

.admin-main {
  flex: 1; margin-left: var(--sidebar-w);
  display: flex; flex-direction: column; min-height: 100vh;
}

.admin-topbar {
  height: 60px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 24px; position: sticky; top: 0; z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}
.admin-page-title { font-size: 1.15rem; font-weight: 700; }
.admin-topbar-right { display: flex; align-items: center; gap: 12px; }

.admin-content { flex: 1; padding: 28px; overflow-y: auto; }

/* =============================================
   LOGIN SCREEN
   ============================================= */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary-dark), #1A3A00);
  padding: 20px;
}
.login-card {
  background: #fff; border-radius: 24px;
  padding: 44px; width: 100%; max-width: 400px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35); text-align: center;
}
.login-logo { font-size: 3rem; margin-bottom: 12px; }
.login-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 6px; }
.login-subtitle { color: var(--text-muted); margin-bottom: 32px; font-size: 0.9rem; }

/* =============================================
   PROGRESS BAR
   ============================================= */
.progress-bar-wrap { background: var(--bg); border-radius: var(--radius-full); height: 8px; overflow: hidden; }
.progress-bar { height: 100%; border-radius: var(--radius-full); background: var(--primary); transition: width 0.3s ease; }
.progress-bar.warning { background: var(--warning); }
.progress-bar.danger { background: var(--danger); }

/* =============================================
   SEARCH & FILTER BAR
   ============================================= */
.search-bar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; border: 2px solid var(--border);
  border-radius: var(--radius-full); background: #fff;
  flex: 1; max-width: 360px; transition: var(--transition);
}
.search-bar:focus-within { border-color: var(--primary); }
.search-bar input { border: none; background: none; font-size: 0.9rem; flex: 1; outline: none; }
.search-bar-icon { color: var(--text-light); font-size: 1rem; }

.page-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.toolbar-left, .toolbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* =============================================
   QUESTION DETAIL PANEL
   ============================================= */
.q-detail-media { margin-bottom: 16px; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: #f9f9f9; }
.q-detail-media img { width: 100%; max-height: 200px; object-fit: contain; }
.q-detail-options { display: flex; flex-direction: column; gap: 6px; }
.q-detail-option {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--radius);
  font-size: 0.875rem;
}
.q-detail-option.correct { background: #E8F5E9; color: #2E7D32; font-weight: 600; }
.q-detail-option.wrong { background: #FFEBEE; color: #C62828; }

/* =============================================
   MISCELLANEOUS
   ============================================= */
.divider { height: 1px; background: var(--border); margin: 20px 0; }
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.text-warning { color: var(--warning); }
.fw-bold { font-weight: 700; }
.fw-600 { font-weight: 600; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }
.mt-24 { margin-top: 24px; }
.mb-4 { margin-bottom: 4px; }
.mb-8 { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.gap-16 { gap: 16px; }
.w-full { width: 100%; }

/* Schedule status in test selector */
.test-select-item.schedule-disabled { opacity: 0.65; cursor: not-allowed !important; }
.test-select-item.schedule-disabled:hover { border-color: var(--border) !important; background: #fff !important; }

.copy-code-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--primary-light); color: var(--primary-dark);
  padding: 8px 14px; border-radius: var(--radius); font-size: 0.875rem;
  border: 1px dashed var(--primary-mid); cursor: pointer; transition: var(--transition);
}
.copy-code-btn:hover { background: var(--primary); color: #fff; }

.access-code-display {
  font-size: 1.6rem; font-weight: 800; letter-spacing: 0.3em;
  color: var(--primary-dark); background: var(--primary-light);
  padding: 12px 20px; border-radius: var(--radius-lg); text-align: center;
  font-family: 'Courier New', monospace;
}

/* Sidebar toggle button - hidden on desktop, visible on mobile */
.admin-sidebar-toggle { display: none; }

/* Sidebar overlay */
#sidebarOverlay { display: none; }
#sidebarOverlay.show { display: block !important; opacity: 1; }

/* Responsive */
@media (max-width: 1024px) {
  .admin-content { padding: 20px; }
  .questions-grid { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
  .exam-main { padding: 16px; }
}

@media (max-width: 768px) {
  .admin-sidebar { transform: translateX(-100%); }
  .admin-sidebar.open { transform: translateX(0); z-index: 300; }
  .admin-main { margin-left: 0; }
  .admin-sidebar-toggle { display: flex; }

  .admin-topbar {
    height: auto;
    min-height: 60px;
    padding: 10px 14px;
    flex-wrap: wrap;
    gap: 10px;
  }
  .admin-topbar-right {
    width: 100%;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
  }
  .admin-page-title { font-size: 1rem; }

  .exam-layout { grid-template-columns: 1fr; }
  .exam-sidebar { display: none; }
  #screenExam { background: var(--bg); min-height: 100vh; }
  .exam-main {
    padding: 12px;
    overflow-x: hidden;
  }
  .question-display {
    width: 100%;
    max-width: 100%;
    border-radius: 14px;
  }
  .question-display-header {
    padding: 14px 16px;
  }
  .question-display-body {
    padding: 14px;
  }
  .question-text {
    font-size: 0.96rem;
    line-height: 1.55;
    margin-bottom: 14px;
    word-break: break-word;
  }
  .answer-opt {
    align-items: flex-start;
    padding: 11px 12px;
    gap: 10px;
  }
  .answer-opt-letter {
    margin-top: 1px;
    width: 28px;
    height: 28px;
    font-size: 0.8rem;
  }
  .answer-opt-text {
    font-size: 0.9rem;
    line-height: 1.4;
    word-break: break-word;
  }
  .form-row, .form-row-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .landing-card { padding: 36px 24px; }
  .screen-card { padding: 28px 22px; }
  .result-info-grid { grid-template-columns: 1fr 1fr; }

  .modal {
    width: calc(100vw - 16px);
    max-height: 92vh;
    border-radius: 16px;
  }
  .modal-body { padding: 16px; }
  .modal-footer {
    padding: 14px 16px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .modal-footer .btn {
    flex: 1;
    min-width: 130px;
  }

  .page-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar-left, .toolbar-right {
    width: 100%;
    justify-content: flex-start;
  }
  .toolbar-left .form-control,
  .toolbar-right .form-control {
    width: 100% !important;
    max-width: none !important;
  }
  .search-bar {
    max-width: none;
    width: 100%;
  }

  #tab-settings > div {
    grid-template-columns: 1fr !important;
  }
  #scheduleFields > div {
    grid-template-columns: 1fr !important;
  }
  #testModal .modal-body > .form-group > div {
    flex-wrap: wrap;
  }
  #testModal .modal-body > .form-group > div > .btn {
    width: 100%;
  }

  #qSelectorList { max-height: 240px !important; }

  /* Force mobile layout for exam bottom navigation */
  #screenExam .question-nav {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 10px !important;
    width: 100% !important;
    max-width: 100% !important;
    overflow: visible !important;
  }
  #screenExam .question-nav > * {
    width: 100% !important;
    max-width: 100% !important;
  }
  #screenExam .question-nav > div {
    display: flex !important;
    justify-content: center !important;
    align-items: center !important;
    gap: 8px !important;
    text-align: center !important;
    flex-wrap: wrap !important;
  }
  #screenExam .question-nav .btn {
    white-space: normal !important;
    justify-content: center !important;
  }
  #screenExam #qProgressText {
    display: block;
    width: 100%;
    text-align: center;
  }
  .question-display-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
}

@media (max-width: 640px) {
  .admin-content { padding: 14px; }
  .login-card { padding: 28px 20px; }
  .screen-card { padding: 22px 16px; }
  .screen-header { margin-bottom: 20px; }
  .test-select-item {
    padding: 12px;
    gap: 10px;
  }
  .test-select-icon {
    width: 36px;
    height: 36px;
    font-size: 1.1rem;
  }
  .test-select-title { font-size: 0.9rem; }
  .test-select-meta { font-size: 0.76rem; line-height: 1.35; }

  .exam-header {
    height: auto;
    min-height: var(--header-h);
    padding: 10px 12px;
    gap: 8px;
    flex-wrap: wrap;
  }
  .exam-header-title {
    flex-basis: 100%;
    font-size: 0.95rem;
  }
  .timer-box {
    padding: 7px 12px;
    font-size: 0.95rem;
  }
  .exam-header .btn {
    margin-left: auto;
  }

  #testModal #qSelectorSearch,
  #testModal #qSelectorCategory,
  #testModal .btn.btn-secondary.btn-sm,
  #testModal .btn.btn-ghost.btn-sm {
    width: 100% !important;
  }
  #testModal .modal-body [style*="display:flex;gap:10px;margin-bottom:10px"] {
    flex-direction: column;
  }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .landing-features { grid-template-columns: 1fr; }
  .result-info-grid { grid-template-columns: 1fr; }
  .landing-jp-title { font-size: 1.8rem; }
  .landing-card { padding: 26px 16px; border-radius: 20px; }
  .screen-title { font-size: 1.35rem; }
  .screen-subtitle { font-size: 0.86rem; }
  .result-score-circle { width: 130px; height: 130px; border-width: 8px; }
  .result-score-value { font-size: 2rem; }
  .btn { padding: 10px 12px; font-size: 0.9rem; }
  .form-control, .short-answer-input { font-size: 16px; }
  .admin-topbar-right .btn {
    width: 100%;
  }
  .admin-topbar-right {
    justify-content: stretch;
  }
  .q-nav-btn { min-height: 34px; }
  .exam-main { padding: 10px; }
  .question-display-header { padding: 12px; }
  .question-display-body { padding: 12px; }
  .question-text { font-size: 0.92rem; }
  .answer-opt {
    padding: 10px;
    border-radius: 10px;
  }
  .answer-opt-letter {
    width: 26px;
    height: 26px;
    font-size: 0.75rem;
  }
  .exam-header-title {
    font-size: 0.9rem;
    line-height: 1.3;
  }
  .timer-box {
    font-size: 0.88rem;
    padding: 6px 10px;
  }
  #screenExam .question-nav {
    margin-top: 14px !important;
  }
  #screenExam .question-nav .btn {
    min-height: 42px;
    font-size: 0.88rem;
  }
}
