/* =============================================================
   CSS-переменные: светлая и тёмная тема
   ============================================================= */
:root {
  --bg: #f0f4f8;
  --surface: #ffffff;
  --surface2: #e8edf3;
  --surface3: #dde3eb;
  --text: #1a202c;
  --text-muted: #718096;
  --text-light: #a0aec0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --primary-text: #1e40af;
  --success: #16a34a;
  --success-light: #dcfce7;
  --success-border: #86efac;
  --error: #dc2626;
  --error-light: #fee2e2;
  --error-border: #fca5a5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --warning-border: #fcd34d;
  --border: #cbd5e0;
  --border-light: #e2e8f0;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.05);
  --header-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface2: #263147;
    --surface3: #2d3a52;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --text-light: #64748b;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-light: #1e3a5f;
    --primary-text: #93c5fd;
    --success: #22c55e;
    --success-light: #14532d;
    --success-border: #166534;
    --error: #ef4444;
    --error-light: #7f1d1d;
    --error-border: #991b1b;
    --warning: #f59e0b;
    --warning-light: #78350f;
    --warning-border: #92400e;
    --border: #334155;
    --border-light: #1e293b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.3);
  }
}

/* =============================================================
   СБРОС И БАЗОВЫЕ СТИЛИ
   ============================================================= */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

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

h1, h2, h3 { line-height: 1.3; font-weight: 600; }

button {
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  border: none;
  background: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--primary); }

.hidden { display: none !important; }

.visually-hidden {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

/* =============================================================
   ЭКРАН ВХОДА
   ============================================================= */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}

.login-brand {
  font-size: 1.6rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.03em;
  margin-bottom: 4px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 0.93rem;
  margin-bottom: 28px;
}

/* =============================================================
   ШАПКА ПРИЛОЖЕНИЯ
   ============================================================= */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
  height: var(--header-h);
  flex-wrap: nowrap;
  min-width: 0;
}

.app-brand {
  font-size: 1rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.02em;
  flex-shrink: 0;
  white-space: nowrap;
}

.app-brand span { color: var(--text); font-weight: 400; }

.app-nav {
  display: flex;
  gap: 0;
  flex: 1;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
  height: 100%;
  align-items: stretch;
}

.app-nav::-webkit-scrollbar { display: none; }

.nav-tab {
  padding: 0 16px;
  font-size: 0.87rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 3px solid transparent;
  white-space: nowrap;
  transition: all 0.15s;
  height: 100%;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.nav-tab:hover { color: var(--text); background: var(--surface2); }

.nav-tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  font-weight: 600;
}

.nav-tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header-username {
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: nowrap;
  max-width: 140px;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (max-width: 600px) {
  .header-username { display: none; }
  .app-brand { font-size: 0.9rem; }
  .nav-tab { padding: 0 10px; font-size: 0.8rem; }
}

/* =============================================================
   ОБЛАСТИ ПРЕДСТАВЛЕНИЙ
   ============================================================= */
.view {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* =============================================================
   КНОПКИ
   ============================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-weight: 500;
  font-size: 0.95rem;
  transition: all 0.15s;
  cursor: pointer;
  border: none;
  text-decoration: none;
}

.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--surface3); }

.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); color: var(--text); }

.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }

.btn-sm { padding: 6px 14px; font-size: 0.85rem; }
.btn-lg { padding: 13px 28px; font-size: 1rem; }

.btn-link {
  background: none; border: none; padding: 0;
  color: var(--primary); font-size: inherit;
  cursor: pointer; text-decoration: underline;
}

/* =============================================================
   ФОРМЫ
   ============================================================= */
.form-group { margin-bottom: 18px; }

.form-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-input {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  transition: border-color 0.15s;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* =============================================================
   АЛЕРТЫ
   ============================================================= */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-top: 12px;
  margin-bottom: 12px;
}

.alert-error { background: var(--error-light); border: 1px solid var(--error-border); color: var(--error); }
.alert-warning { background: var(--warning-light); border: 1px solid var(--warning-border); color: var(--warning); }
.alert-success { background: var(--success-light); border: 1px solid var(--success-border); color: var(--success); }
.alert-info { background: var(--primary-light); border: 1px solid var(--border); color: var(--primary-text); }

/* =============================================================
   ТОСТ
   ============================================================= */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: var(--radius);
  font-size: 0.93rem;
  font-weight: 500;
  z-index: 9999;
  box-shadow: var(--shadow-md);
  max-width: 90vw;
  text-align: center;
  background: var(--text);
  color: var(--surface);
  animation: slideUp 0.2s ease;
}

.toast-error { background: var(--error); color: #fff; }
.toast-success { background: var(--success); color: #fff; }
.toast-warning { background: var(--warning); color: #fff; }

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* =============================================================
   МОДАЛЬНОЕ ОКНО
   ============================================================= */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
}

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

.modal-title { font-size: 1.1rem; }

.modal-close {
  font-size: 1.4rem;
  color: var(--text-muted);
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.15s;
}

.modal-close:hover { background: var(--surface2); color: var(--text); }
.modal-close:focus-visible { outline: 2px solid var(--primary); }

#modal-body { padding: 20px 24px 24px; }

/* =============================================================
   ФИЛЬТРЫ
   ============================================================= */
.filter-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}

.filter-select, .filter-input {
  padding: 8px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
  transition: border-color 0.15s;
}

.filter-select:focus, .filter-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.filter-select { min-width: 160px; cursor: pointer; }
.filter-input { flex: 1; min-width: 180px; }

.filter-checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: all 0.15s;
  user-select: none;
}

.filter-checkbox-label:hover { background: var(--surface2); }
.filter-checkbox-label input[type="checkbox"] { accent-color: var(--primary); }

/* =============================================================
   ТЕГИ
   ============================================================= */
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 4px;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em;
}

.tag-id { background: var(--surface2); color: var(--text-muted); font-family: 'Courier New', monospace; }
.tag-axis { background: var(--primary-light); color: var(--primary-text); }
.tag-topic { background: var(--surface2); color: var(--text-muted); }

.tag-diff-1 { background: #d1fae5; color: #065f46; }
.tag-diff-2 { background: #fef3c7; color: #92400e; }
.tag-diff-3 { background: #fee2e2; color: #991b1b; }

@media (prefers-color-scheme: dark) {
  .tag-diff-1 { background: #064e3b; color: #6ee7b7; }
  .tag-diff-2 { background: #78350f; color: #fde68a; }
  .tag-diff-3 { background: #7f1d1d; color: #fca5a5; }
}

.tag-multi { background: #ede9fe; color: #5b21b6; }

@media (prefers-color-scheme: dark) {
  .tag-multi { background: #3b0764; color: #c4b5fd; }
}

.tag-draft-verify { background: #fef3c7; color: #78350f; border: 1px solid #fcd34d; }

@media (prefers-color-scheme: dark) {
  .tag-draft-verify { background: #422006; color: #fde68a; border-color: #92400e; }
}

/* =============================================================
   КАРТОЧКИ ВОПРОСОВ (СПИСОК)
   ============================================================= */
.question-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.question-meta {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-bottom: 12px; align-items: center;
}

.question-text {
  font-size: 1rem; font-weight: 500;
  margin-bottom: 14px; max-width: 72ch; line-height: 1.55;
}

.options-list { list-style: none; margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }

.option-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 8px 12px; border-radius: 6px;
  font-size: 0.95rem; line-height: 1.5;
}

.option-letter {
  font-weight: 700; font-size: 0.85rem;
  width: 22px; height: 22px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%; flex-shrink: 0; margin-top: 1px;
  background: var(--surface2); color: var(--text-muted);
}

.option-item.correct .option-letter { background: var(--success); color: #fff; }
.option-item.correct { background: var(--success-light); border: 1px solid var(--success-border); }

.explanation-block {
  background: var(--surface2);
  border-left: 3px solid var(--primary);
  border-radius: 0 6px 6px 0;
  padding: 12px 16px;
  font-size: 0.9rem; color: var(--text); line-height: 1.6;
  margin-top: 4px;
}

.explanation-label {
  font-weight: 600; color: var(--primary-text);
  font-size: 0.8rem; text-transform: uppercase;
  letter-spacing: 0.05em; margin-bottom: 4px;
}

/* =============================================================
   ПАНЕЛЬ ВОПРОСА (ТРЕНАЖЁР / ЭКЗАМЕН)
   ============================================================= */
.question-pane {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 28px 24px;
  box-shadow: var(--shadow-sm);
}

.question-pane .question-text { font-size: 1.05rem; margin-bottom: 20px; }

.option-btn {
  display: flex; align-items: flex-start; gap: 12px;
  width: 100%; text-align: left;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  font-size: 0.95rem; line-height: 1.5;
  cursor: pointer; transition: all 0.15s; margin-bottom: 8px;
}

.option-btn:hover:not(:disabled) { border-color: var(--primary); background: var(--primary-light); }
.option-btn.selected { border-color: var(--primary); background: var(--primary-light); }
.option-btn.correct-reveal { border-color: var(--success); background: var(--success-light); }
.option-btn.wrong-reveal { border-color: var(--error); background: var(--error-light); }
.option-btn:disabled { cursor: default; }
.option-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.option-btn .opt-key {
  font-weight: 700; font-size: 0.82rem;
  width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 5px; background: var(--surface2); color: var(--text-muted);
  flex-shrink: 0; margin-top: 1px; transition: all 0.15s;
}

.option-btn.selected .opt-key { background: var(--primary); color: #fff; }
.option-btn.correct-reveal .opt-key { background: var(--success); color: #fff; }
.option-btn.wrong-reveal .opt-key { background: var(--error); color: #fff; }

.verdict-block { border-radius: var(--radius); padding: 14px 18px; margin-top: 16px; font-size: 0.95rem; }
.verdict-correct { background: var(--success-light); border: 1px solid var(--success-border); }
.verdict-wrong { background: var(--error-light); border: 1px solid var(--error-border); }
.verdict-title { font-weight: 700; margin-bottom: 8px; }
.verdict-explanation {
  font-size: 0.9rem; line-height: 1.6; margin-top: 8px;
  padding-top: 8px; border-top: 1px solid rgba(0,0,0,0.1);
}

.trainer-actions { display: flex; gap: 12px; margin-top: 18px; flex-wrap: wrap; }

.multi-hint {
  font-size: 0.82rem; color: var(--text-muted); margin-bottom: 12px;
  padding: 6px 10px; background: var(--surface2); border-radius: var(--radius);
}

/* =============================================================
   ТРЕНАЖЁР — НАСТРОЙКА И ПРОГРЕСС
   ============================================================= */
.trainer-setup {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px; margin-bottom: 20px;
}

.trainer-setup h2 { font-size: 1.1rem; margin-bottom: 16px; }

.trainer-setup-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.progress-bar-wrap {
  background: var(--surface2);
  border-radius: 99px; height: 6px; margin-bottom: 4px; overflow: hidden;
}

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

.trainer-stats { display: flex; gap: 20px; font-size: 0.9rem; color: var(--text-muted); margin-bottom: 20px; }
.trainer-stat strong { color: var(--text); }

/* =============================================================
   ЭКЗАМЕН — НАСТРОЙКА
   ============================================================= */
.exam-setup-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px; max-width: 520px; margin: 0 auto;
}

.exam-setup-card h2 { font-size: 1.3rem; margin-bottom: 6px; }
.exam-setup-card .subtitle { font-size: 0.9rem; color: var(--text-muted); margin-bottom: 24px; }

.threshold-note {
  background: var(--primary-light);
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: 0.87rem; color: var(--primary-text);
  margin-bottom: 20px; line-height: 1.55;
}

/* =============================================================
   ЭКЗАМЕН — АКТИВНЫЙ
   ============================================================= */
.exam-top-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; margin-bottom: 16px;
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}

.exam-timer {
  font-size: 1.5rem; font-weight: 700;
  font-variant-numeric: tabular-nums; letter-spacing: 0.03em;
  min-width: 80px; color: var(--text); transition: color 0.3s;
}

.exam-timer.warning { color: var(--warning); }
.exam-timer.danger  { color: var(--error); }

.exam-question-counter { flex: 1; font-size: 0.9rem; color: var(--text-muted); }

.exam-body {
  display: grid;
  grid-template-columns: 1fr 200px;
  gap: 20px; align-items: start;
}

@media (max-width: 700px) { .exam-body { grid-template-columns: 1fr; } }

.navigator-label {
  font-size: 0.78rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); margin-bottom: 8px;
}

.navigator-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; }

.nav-cell {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  border-radius: 5px; font-size: 0.78rem; font-weight: 600;
  cursor: pointer; border: 2px solid var(--border);
  background: var(--surface); color: var(--text-muted);
  transition: all 0.1s;
}

.nav-cell:hover { border-color: var(--primary); }
.nav-cell.current { border-color: var(--primary); background: var(--primary); color: #fff; }
.nav-cell.answered { background: var(--surface2); color: var(--text); border-color: var(--border); }
.nav-cell.flagged  { border-color: var(--warning); }
.nav-cell:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.navigator-legend { margin-top: 8px; font-size: 0.75rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 3px; }
.legend-item { display: flex; align-items: center; gap: 5px; }
.legend-dot { width: 10px; height: 10px; border-radius: 2px; border: 2px solid var(--border); }
.legend-dot.answered { background: var(--surface2); border-color: var(--border); }
.legend-dot.flagged  { border-color: var(--warning); }
.legend-dot.current  { background: var(--primary); border-color: var(--primary); }

.exam-flag-btn {
  padding: 6px 12px; font-size: 0.85rem;
  border: 1px solid var(--warning-border);
  border-radius: var(--radius); color: var(--warning);
  background: transparent; transition: all 0.15s; cursor: pointer;
}

.exam-flag-btn:hover { background: var(--warning-light); }
.exam-flag-btn.flagged { background: var(--warning-light); }
.exam-flag-btn:focus-visible { outline: 2px solid var(--warning); outline-offset: 2px; }

.exam-nav-btns { display: flex; gap: 8px; margin-top: 20px; flex-wrap: wrap; }

.unanswered-count { font-size: 0.82rem; color: var(--warning); margin-top: 8px; }

/* =============================================================
   ЭКЗАМЕН — РЕЗУЛЬТАТЫ
   ============================================================= */
.result-hero {
  text-align: center; padding: 32px 20px 24px;
  border-radius: var(--radius-lg); margin-bottom: 24px;
}

.result-hero.passed { background: var(--success-light); border: 2px solid var(--success-border); }
.result-hero.failed { background: var(--error-light);   border: 2px solid var(--error-border); }

.result-verdict { font-size: 2rem; margin-bottom: 6px; }

.result-score-big {
  font-size: 3rem; font-weight: 800; letter-spacing: -0.03em;
  line-height: 1; margin: 12px 0;
}

.result-hero.passed .result-score-big { color: var(--success); }
.result-hero.failed .result-score-big { color: var(--error); }
.result-subtitle { font-size: 1rem; color: var(--text-muted); }

.result-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 24px;
}

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

.result-stat-num { font-size: 1.8rem; font-weight: 700; color: var(--text); }
.result-stat-label { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }

.axis-results-table { width: 100%; border-collapse: collapse; margin-bottom: 24px; font-size: 0.92rem; }
.axis-results-table th {
  text-align: left; padding: 8px 12px;
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); border-bottom: 2px solid var(--border);
}
.axis-results-table td { padding: 10px 12px; border-bottom: 1px solid var(--border-light); }
.axis-results-table tr:last-child td { border-bottom: none; }
.axis-pass { color: var(--success); font-weight: 600; }
.axis-fail { color: var(--error);   font-weight: 600; }

.score-bar-wrap { background: var(--surface2); border-radius: 99px; height: 8px; overflow: hidden; width: 120px; }
.score-bar-fill { height: 100%; border-radius: 99px; }
.score-bar-fill.pass { background: var(--success); }
.score-bar-fill.fail { background: var(--error); }

.result-fail-reasons {
  background: var(--error-light); border: 1px solid var(--error-border);
  border-radius: var(--radius); padding: 12px 16px; font-size: 0.9rem; margin-top: 12px;
}

.result-fail-reasons strong { color: var(--error); }

.review-section { margin-top: 24px; }
.review-section h3 { font-size: 1rem; margin-bottom: 16px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }

.review-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px; margin-bottom: 12px;
}

.review-card.correct-answer { border-left: 4px solid var(--success); }
.review-card.wrong-answer   { border-left: 4px solid var(--error); }
.review-card.no-answer      { border-left: 4px solid var(--text-light); }

.review-q-header { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 10px; }
.review-q-num { font-size: 0.8rem; font-weight: 700; color: var(--text-muted); flex-shrink: 0; margin-top: 2px; }
.review-verdict-icon { font-size: 1rem; flex-shrink: 0; margin-top: 2px; }

.section-divider { height: 1px; background: var(--border); margin: 24px 0; }

/* =============================================================
   МОИ РЕЗУЛЬТАТЫ
   ============================================================= */
.attempts-table { width: 100%; border-collapse: collapse; }
.attempts-table th {
  text-align: left; padding: 10px 14px;
  font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); border-bottom: 2px solid var(--border);
}
.attempts-table td { padding: 12px 14px; border-bottom: 1px solid var(--border-light); font-size: 0.92rem; }
.attempts-table tr:last-child td { border-bottom: none; }
.attempts-table tr:hover td { background: var(--surface2); }
.attempts-table .score-pass { color: var(--success); font-weight: 700; }
.attempts-table .score-fail { color: var(--error); font-weight: 700; }

/* =============================================================
   БАЗА ЗНАНИЙ
   ============================================================= */
.kb-layout {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 24px;
  align-items: start;
  min-height: calc(100vh - var(--header-h) - 80px);
}

@media (max-width: 768px) {
  .kb-layout { grid-template-columns: 1fr; }
  .kb-tree { border-right: none; border-bottom: 1px solid var(--border); padding-right: 0; padding-bottom: 16px; }
}

.kb-tree {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  position: sticky;
  top: calc(var(--header-h) + 24px);
  max-height: calc(100vh - var(--header-h) - 100px);
  overflow-y: auto;
}

.kb-tree-title { font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 12px; }

.kb-tree ul { list-style: none; }
.kb-tree li { margin-bottom: 2px; }

.kb-tree-section > .kb-tree-section-title {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; font-size: 0.9rem; padding: 6px 8px;
  border-radius: var(--radius); cursor: pointer;
  color: var(--text); transition: background 0.1s;
}

.kb-tree-section > .kb-tree-section-title:hover { background: var(--surface2); }

.kb-tree-article {
  display: block; padding: 5px 8px 5px 24px;
  font-size: 0.87rem; color: var(--text-muted);
  border-radius: var(--radius); cursor: pointer;
  transition: all 0.1s; text-decoration: none;
}

.kb-tree-article:hover { background: var(--surface2); color: var(--text); }
.kb-tree-article.active { background: var(--primary-light); color: var(--primary-text); font-weight: 600; }

.kb-article-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px 36px;
  min-height: 400px;
}

.kb-search-bar {
  display: flex; gap: 8px; margin-bottom: 20px;
}

.kb-search-bar .filter-input { flex: 1; }

.kb-article-body { max-width: 72ch; }
.kb-article-body h1 { font-size: 1.5rem; margin-bottom: 16px; }
.kb-article-body h2 { font-size: 1.2rem; margin: 24px 0 12px; }
.kb-article-body h3 { font-size: 1rem; margin: 20px 0 8px; }
.kb-article-body p { margin-bottom: 12px; line-height: 1.7; }
.kb-article-body ul, .kb-article-body ol { padding-left: 24px; margin-bottom: 12px; }
.kb-article-body li { margin-bottom: 4px; line-height: 1.6; }
.kb-article-body code { font-family: 'Courier New', monospace; font-size: 0.88em; background: var(--surface2); padding: 1px 5px; border-radius: 3px; }
.kb-article-body pre { background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; overflow-x: auto; margin-bottom: 12px; }
.kb-article-body pre code { background: none; padding: 0; }
.kb-article-body table { width: 100%; border-collapse: collapse; margin-bottom: 16px; overflow-x: auto; display: block; }
.kb-article-body th { background: var(--surface2); text-align: left; padding: 8px 12px; border: 1px solid var(--border); font-weight: 600; }
.kb-article-body td { padding: 8px 12px; border: 1px solid var(--border); }
.kb-article-body blockquote { border-left: 3px solid var(--primary); padding-left: 16px; color: var(--text-muted); margin-bottom: 12px; }

.kb-search-results .search-hit {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 10px;
  cursor: pointer; transition: border-color 0.15s;
}

.kb-search-results .search-hit:hover { border-color: var(--primary); }
.kb-search-results .search-hit-title { font-weight: 600; margin-bottom: 4px; color: var(--primary-text); }
.kb-search-results .search-hit-snippet { font-size: 0.87rem; color: var(--text-muted); }

/* =============================================================
   АДМИНИСТРИРОВАНИЕ
   ============================================================= */
.admin-tabs { display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 24px; }

.admin-tab {
  padding: 10px 20px; font-size: 0.92rem; font-weight: 500;
  color: var(--text-muted); border-bottom: 3px solid transparent;
  margin-bottom: -2px; white-space: nowrap; transition: all 0.15s;
}

.admin-tab:hover { color: var(--text); }
.admin-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.admin-tab:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

.users-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.users-table th {
  text-align: left; padding: 10px 12px;
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em;
  color: var(--text-muted); border-bottom: 2px solid var(--border); white-space: nowrap;
}
.users-table td { padding: 10px 12px; border-bottom: 1px solid var(--border-light); vertical-align: middle; }
.users-table tr:last-child td { border-bottom: none; }
.users-table tr:hover td { background: var(--surface2); }

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 99px;
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.02em;
}

.badge-admin { background: var(--primary-light); color: var(--primary-text); }
.badge-user  { background: var(--surface2); color: var(--text-muted); }
.badge-active   { background: var(--success-light); color: var(--success); }
.badge-inactive { background: var(--error-light); color: var(--error); }

.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* =============================================================
   ПРОФИЛЬ
   ============================================================= */
.profile-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 28px;
  max-width: 480px; margin-bottom: 24px;
}

.profile-avatar {
  width: 60px; height: 60px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary-text);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700; margin-bottom: 16px;
}

.profile-name { font-size: 1.3rem; font-weight: 700; margin-bottom: 4px; }
.profile-meta { font-size: 0.9rem; color: var(--text-muted); }

/* =============================================================
   ПУСТОЕ СОСТОЯНИЕ
   ============================================================= */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 6px; color: var(--text); }
.empty-state p { font-size: 0.9rem; max-width: 40ch; margin: 0 auto; }

/* =============================================================
   ПОДСКАЗКА КЛАВИШ
   ============================================================= */
.kbd-hint { font-size: 0.78rem; color: var(--text-light); margin-top: 10px; }
.kbd {
  display: inline-block; padding: 1px 5px;
  border: 1px solid var(--border); border-radius: 3px;
  font-size: 0.75rem; font-family: 'Courier New', monospace;
  background: var(--surface2);
}

/* =============================================================
   ЗАМЕЧАНИЯ (LIST / ADMIN)
   ============================================================= */
.note-control { margin-top: 14px; border-top: 1px solid var(--border-light); padding-top: 10px; }

.btn-note-toggle {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.83rem; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 4px 12px; background: var(--surface); cursor: pointer;
  transition: all 0.15s; font-family: inherit;
}

.btn-note-toggle:hover { background: var(--surface2); color: var(--text); }
.btn-note-toggle.has-note { color: var(--primary-text); border-color: var(--primary); background: var(--primary-light); font-weight: 600; }
.btn-note-toggle:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.note-area { margin-top: 8px; }

.note-textarea {
  width: 100%; min-height: 72px; padding: 9px 12px;
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); color: var(--text);
  font-size: 0.9rem; font-family: inherit; resize: vertical; transition: border-color 0.15s;
}

.note-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.note-actions { display: flex; gap: 8px; margin-top: 6px; }

/* =============================================================
   LOADING SPINNER
   ============================================================= */
.spinner-wrap { display: flex; align-items: center; justify-content: center; padding: 48px; }
.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* =============================================================
   СТИЛИ ПЕЧАТИ
   ============================================================= */
@media print {
  .app-header, .filter-bar, #view-kb, #view-admin, #view-results, #view-profile,
  #view-trainer, #view-exam { display: none !important; }

  body { background: white; color: black; font-size: 11pt; }

  .view { padding: 0; max-width: none; }

  .question-card {
    border: 1px solid #ccc; border-radius: 0;
    break-inside: avoid; margin-bottom: 12pt;
    padding: 12pt 14pt; page-break-inside: avoid;
  }

  .option-item.correct .option-letter {
    background: #16a34a; color: white;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }

  .option-item.correct {
    background: #dcfce7;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }

  .explanation-block {
    border-left: 3px solid #2563eb; background: #f0f4f8;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
