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

:root {
  --sidebar-w: 250px;
  --navy: #0f172a;
  --navy-mid: #1e293b;
  --navy-light: #334155;
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --success: #22c55e;
  --success-bg: #dcfce7;
  --success-text: #166534;
  --danger: #ef4444;
  --danger-bg: #fee2e2;
  --danger-text: #991b1b;
  --warning: #f59e0b;
  --warning-bg: #fef3c7;
  --warning-text: #92400e;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --radius: 8px;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ─── Auth layout ─────────────────────────────────────────── */

.auth-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--navy);
  padding: 24px;
}

.auth-card {
  background: var(--card);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--navy);
}

.auth-logo h1 span {
  color: var(--primary);
}

.auth-logo p {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

.auth-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 20px;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 13px;
  color: var(--muted);
}

.auth-footer a {
  color: var(--primary);
  text-decoration: none;
}

/* ─── App layout ──────────────────────────────────────────── */

.app-layout {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  padding: 24px 20px 0;
}

.sidebar-brand h1 {
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  line-height: 1.2;
}

.sidebar-brand h1 span {
  color: var(--primary);
}

.sidebar-brand small {
  font-size: 11px;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sidebar-logo {
  max-width: 100%;
  max-height: 60px;
  height: auto;
  margin: 12px auto;
  display: block;
}

.sidebar-logo-wrapper {
  padding: 0 20px 0px;
  border-bottom: 1px solid var(--navy-mid);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
}

.nav-section-label {
  padding: 12px 20px 4px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: #475569;
}

.nav-item {
  display: block;
  padding: 10px 20px;
  color: #94a3b8;
  text-decoration: none;
  font-size: 14px;
  transition: background 0.12s, color 0.12s;
}

.nav-item:hover {
  background: var(--navy-mid);
  color: #fff;
}

.nav-item.active {
  background: var(--navy-mid);
  color: #fff;
  border-left: 3px solid var(--primary);
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--navy-mid);
}

.sidebar-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.sidebar-user {
  font-size: 13px;
  color: #fff;
  font-weight: 500;
  min-width: 0;
}

.sidebar-user small {
  display: block;
  color: #64748b;
  font-size: 11px;
  font-weight: 400;
}

.dark-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  flex-shrink: 0;
}

.dark-toggle input {
  display: none;
}

.dark-toggle-track {
  width: 34px;
  height: 18px;
  background: #334155;
  border-radius: 9px;
  position: relative;
  transition: background 0.2s;
}

.dark-toggle-track::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  background: #94a3b8;
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.dark-toggle input:checked ~ .dark-toggle-track {
  background: var(--primary);
}

.dark-toggle input:checked ~ .dark-toggle-track::after {
  transform: translateX(16px);
  background: #fff;
}

.dark-toggle-icon {
  color: #94a3b8;
  flex-shrink: 0;
}

.dark-toggle-icon--moon {
  display: none;
}

html.dark .dark-toggle-icon--sun {
  display: none;
}

html.dark .dark-toggle-icon--moon {
  display: block;
  color: #f59e0b;
}

.main {
  margin-left: var(--sidebar-w);
  padding: 32px;
  width: calc(100vw - var(--sidebar-w));
  max-width: calc(100vw - var(--sidebar-w));
  min-height: 100vh;
}

/* ─── Page header ─────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 12px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
}

.page-header-actions {
  display: flex;
  gap: 8px;
}

/* ─── Cards ───────────────────────────────────────────────── */

.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.card + .card,
.card-gap {
  margin-top: 20px;
}

.card h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ─── Course grid ─────────────────────────────────────────── */

.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.course-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.15s, transform 0.15s;
}

.course-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(-1px);
}

.course-card--done {
  border-left: 3px solid var(--success);
}

.course-card-title {
  font-size: 16px;
  font-weight: 600;
  margin-top: 4px;
}

.course-card-desc {
  font-size: 13px;
  color: var(--muted);
  flex: 1;
}

.course-card-score {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
}

/* ─── Buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  white-space: nowrap;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

.btn-danger:hover {
  background: #dc2626;
}

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

.btn-outline:hover {
  background: var(--bg);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 13px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
}

/* ─── Forms ───────────────────────────────────────────────── */

.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  outline: none;
  font-family: inherit;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

select.form-control {
  cursor: pointer;
}

.form-hint {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

.form-actions {
  display: flex;
  gap: 8px;
  margin-top: 24px;
}

/* ─── Alerts ──────────────────────────────────────────────── */

.alert {
  padding: 12px 16px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 14px;
  border: 1px solid transparent;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: #fca5a5;
}

.alert-success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: #86efac;
}

/* ─── Badges ──────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-success {
  background: var(--success-bg);
  color: var(--success-text);
}

.badge-warning {
  background: var(--warning-bg);
  color: var(--warning-text);
}

.badge-info {
  background: #dbeafe;
  color: #1e40af;
}

.badge-admin {
  background: #ede9fe;
  color: #5b21b6;
}

/* ─── Tables ──────────────────────────────────────────────── */

.table-toolbar {
  padding-bottom: 0.75rem;
}

.table-wrap {
  overflow-x: auto;
}

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

.table th {
  background: #f8fafc;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 12px 14px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

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

.table tbody tr:hover td {
  background: #f8fafc;
}

/* ─── Course content (read view) ──────────────────────────── */

.section-block {
  margin-bottom: 32px;
}

.section-block h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}

.section-text {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text);
  overflow-x: hidden;
}

.section-text p { margin-bottom: 12px; }
.section-text h3 { font-size: 16px; margin: 16px 0 8px; }
.section-text ul, .section-text ol { margin: 8px 0 12px 20px; }
.section-text li { margin-bottom: 4px; }
.section-text img { max-width: 100% !important; height: auto !important; width: auto !important; }
.section-text table { max-width: 100% !important; width: 100% !important; table-layout: fixed !important; word-break: break-word; }
.section-text div, .section-text figure, .section-text pre { max-width: 100% !important; }

.video-wrapper {
  position: relative;
  padding-top: 56.25%;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
}

.video-wrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.course-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.course-nav h1 {
  font-size: 20px;
  font-weight: 700;
}

.quiz-cta {
  background: var(--card);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  margin-top: 32px;
}

.quiz-cta h3 {
  font-size: 16px;
  margin-bottom: 8px;
}

.quiz-cta p {
  font-size: 14px;
  color: var(--muted);
  margin-bottom: 16px;
}

.completion-banner {
  background: var(--success-bg);
  border: 1px solid #86efac;
  border-radius: var(--radius);
  padding: 20px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 32px;
}

/* ─── Quiz view ───────────────────────────────────────────── */

.quiz-progress {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 24px;
}

.question-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
}

.question-num {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--primary);
  margin-bottom: 8px;
}

.question-text {
  font-size: 16px;
  font-weight: 500;
  margin-bottom: 16px;
}

.answers {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.answer-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.1s, border-color 0.1s;
}

.answer-option:hover {
  background: #f8fafc;
  border-color: var(--primary);
}

.answer-option input[type="radio"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: var(--primary);
}

/* ─── Result view ─────────────────────────────────────────── */

.result-card {
  text-align: center;
  padding: 40px;
  max-width: 520px;
  margin: 0 auto;
}

.result-score {
  font-size: 56px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  margin: 16px 0 8px;
}

.result-max {
  font-size: 18px;
  color: var(--muted);
  margin-bottom: 8px;
}

.result-pct {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 20px;
}

.result-message {
  font-size: 15px;
  color: var(--muted);
  margin-bottom: 28px;
}

/* ─── Quiz answer review ──────────────────────────────────── */

.review-section {
  max-width: 680px;
  margin: 28px auto 0;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.review-block {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.review-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 18px;
  border-bottom: 1px solid var(--border);
}

.review-block-header--correct {
  background: #f0fdf4;
  border-bottom-color: #bbf7d0;
}

.review-block-header--wrong {
  background: #fff1f2;
  border-bottom-color: #fecdd3;
}

.review-block-body {
  padding: 18px 20px;
}

.review-question-num {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
}

.review-question-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 14px;
  line-height: 1.5;
}

.review-answers {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.verdict-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.verdict-badge--correct {
  background: var(--success-bg);
  color: var(--success-text);
  border: 1px solid #86efac;
}

.verdict-badge--wrong {
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid #fca5a5;
}

.answer-review-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  border: 1.5px solid transparent;
  transition: none;
}

.answer-review-neutral {
  background: #f8fafc;
  border-color: var(--border);
  color: var(--muted);
}

.answer-review-correct {
  background: var(--success-bg);
  border-color: #86efac;
  color: var(--success-text);
  font-weight: 500;
}

.answer-review-wrong {
  background: var(--danger-bg);
  border-color: #fca5a5;
  color: var(--danger-text);
  font-weight: 500;
}

.answer-review-missed {
  background: #f0fdf4;
  border-color: #bbf7d0;
  color: var(--success-text);
}

.answer-review-text {
  flex: 1;
  line-height: 1.4;
}

.answer-review-icon {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.icon-correct {
  background: var(--success);
  color: #fff;
}

.icon-wrong {
  background: var(--danger);
  color: #fff;
}

.icon-missed {
  background: transparent;
  border: 2px solid var(--success);
  color: var(--success);
}

.icon-neutral {
  background: var(--border);
}

/* ─── Admin course editor ─────────────────────────────────── */

.editor-block {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 12px;
  background: #fafbfc;
}

.editor-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.editor-block-header span {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.editor-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.editor-section-header h2 {
  margin-bottom: 0;
}

.answers-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 8px 0 12px;
}

.answer-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.answer-row input[type="radio"] {
  flex-shrink: 0;
  accent-color: var(--success);
  width: 16px;
  height: 16px;
}

.answer-row .form-control {
  flex: 1;
}

/* ─── Stats grid ──────────────────────────────────────────── */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
}

.stat-value {
  font-size: 36px;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
  margin-top: 4px;
}

/* ─── Image gallery modal ─────────────────────────────────── */

.img-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.img-modal {
  background: var(--card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 760px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.img-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.img-modal-header h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}

.img-gallery {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

.img-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.img-thumb {
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #f8fafc;
  display: flex;
  flex-direction: column;
}

.img-thumb img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  display: block;
}

.img-thumb-name {
  padding: 4px 8px;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.img-thumb-actions {
  display: flex;
  gap: 4px;
  padding: 0 6px 6px;
}

.img-thumb-actions .btn {
  flex: 1;
  justify-content: center;
}

/* ─── Utilities ───────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 40px;
  color: var(--muted);
  font-size: 15px;
}

.text-muted { color: var(--muted); }
.text-sm { font-size: 13px; }
.mb-0 { margin-bottom: 0 !important; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.mt-4 { margin-top: 16px; }
.mt-6 { margin-top: 24px; }
.flex { display: flex; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.font-semibold { font-weight: 600; }

/* ─── Dark mode ───────────────────────────────────────────── */

html.dark {
  --bg: #0f172a;
  --card: #1e293b;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --border: #334155;
}

html.dark body {
  background: var(--bg);
  color: var(--text);
}

html.dark .form-control {
  background: #1e293b;
  color: var(--text);
  border-color: var(--border);
}

html.dark .btn-outline {
  color: var(--text);
  border-color: var(--border);
}

html.dark .btn-outline:hover {
  background: var(--navy-mid);
}

html.dark .table th {
  background: #1e293b;
  color: var(--muted);
  border-bottom-color: var(--border);
}

html.dark .table td {
  border-bottom-color: var(--border);
}

html.dark .table tbody tr:hover td {
  background: #1e293b;
}

html.dark .editor-block {
  background: #1e293b;
}

html.dark .answer-review-neutral {
  background: #1e293b;
  border-color: var(--border);
}

html.dark .answer-option:hover {
  background: #1e293b;
}

html.dark label {
  color: var(--text);
}
