/* ============================================================================
   ЕНМСЭИ-ХРОМОТОГРАФИЯ · Электронный учебник
   Стили. Светлая / тёмная тема через data-theme на <html>.
   ========================================================================== */

/* === ПЕРЕМЕННЫЕ === */
:root {
  --bg: #f6f8fb;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-hover: #f0f4f9;
  --bg-subtle: #f8fafc;
  --text: #1a2332;
  --text-muted: #5a6a7e;
  --text-light: #8a98ab;
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --primary-light: #dbeafe;
  --accent: #0891b2;
  --accent-light: #cffafe;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --border: #e5e9f0;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.05);
  --shadow: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 12px 34px rgba(0,0,0,.14);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 268px;
  --topbar-h: 64px;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-card: #1e293b;
  --bg-sidebar: #172033;
  --bg-hover: #273449;
  --bg-subtle: #1a2436;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-light: #64748b;
  --primary: #60a5fa;
  --primary-dark: #3b82f6;
  --primary-light: #1e3a5f;
  --accent: #22d3ee;
  --accent-light: #164e63;
  --success: #4ade80;
  --success-light: #14532d;
  --danger: #f87171;
  --danger-light: #7f1d1d;
  --warning: #fbbf24;
  --warning-light: #78350f;
  --border: #334155;
  --shadow: 0 4px 12px rgba(0,0,0,.35);
  --shadow-lg: 0 12px 34px rgba(0,0,0,.55);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", "PT Sans", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, h4 { line-height: 1.3; }

/* ======================= TOPBAR ======================= */
.topbar {
  height: var(--topbar-h);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; z-index: 100; box-shadow: var(--shadow-sm);
}
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-icon { font-size: 26px; }
.brand-title { font-size: 16px; font-weight: 700; }
.brand-sub { font-size: 12px; color: var(--text-muted); }
.hamburger { display: none; font-size: 22px; padding: 8px 12px; border-radius: 8px; }
.hamburger:hover { background: var(--bg-hover); }

.progress-block { display: flex; align-items: center; gap: 10px; }
.progress-label { font-size: 12px; color: var(--text-muted); }
.progress-bar { width: 150px; height: 8px; background: var(--border); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .35s ease; }
.progress-percent { font-size: 12px; font-weight: 700; color: var(--primary); min-width: 40px; text-align: right; }

.cabinet-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 12px; border-radius: 8px; font-size: 13px; font-weight: 600;
  background: var(--bg-hover); border: 1px solid var(--border); color: var(--text);
  transition: .2s ease;
}
.cabinet-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.cabinet-ico { font-size: 15px; }

/* ======================= SIDEBAR ======================= */
.sidebar {
  position: fixed; top: var(--topbar-h); bottom: 0; left: 0;
  width: var(--sidebar-w); background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow-y: auto; z-index: 90;
}
.sidebar nav { padding: 16px 12px; flex: 1; }
.nav-section { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-light); margin: 18px 10px 8px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 10px 12px; border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: 14px; font-weight: 500; text-align: left; margin-bottom: 2px; transition: .15s ease;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 700; }
.nav-ico { font-size: 17px; width: 22px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto; font-size: 11px; font-weight: 700; padding: 2px 7px;
  border-radius: 99px; background: var(--bg-hover); color: var(--text-muted); flex-shrink: 0;
}
.nav-item.active .nav-badge { background: var(--primary); color: #fff; }
.nav-badge.done { background: var(--success); color: #fff; }
.sidebar-footer { padding: 14px 20px; border-top: 1px solid var(--border); color: var(--text-light); }

/* ======================= CONTENT ======================= */
.content { margin: var(--topbar-h) 0 0 var(--sidebar-w); padding: 32px 36px 64px; }
.page { display: none; }
.page.active { display: block; animation: fadeIn .25s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.page-header { margin-bottom: 26px; }
.page-header h1 { font-size: 30px; font-weight: 800; margin-bottom: 6px; }
.page-header p { color: var(--text-muted); font-size: 15px; }

/* --- АТРИБУЦИЯ НАД ОБЛОЖКОЙ --- */
.attribution {
  display: flex; align-items: flex-start; gap: 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 22px;
  box-shadow: var(--shadow-sm);
}
.attribution-ico { font-size: 24px; line-height: 1.2; flex-shrink: 0; }
.attribution p {
  margin: 0; font-size: 15px; line-height: 1.6; color: var(--text-muted);
}
.attribution b { color: var(--text); font-weight: 700; }

/* --- HERO --- */
.hero {
  position: relative; overflow: hidden; border-radius: 18px; padding: 40px 36px; margin-bottom: 30px;
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 45%, #0891b2 100%); color: #fff;
}
.hero::before { content: ''; position: absolute; right: -60px; top: -60px; width: 260px; height: 260px; border-radius: 50%; background: rgba(255,255,255,.08); }
.hero h1 { font-size: 34px; font-weight: 800; margin-bottom: 12px; position: relative; }
.hero-sub { font-size: 16px; opacity: .95; margin-bottom: 22px; max-width: 760px; position: relative; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; position: relative; }
.hero .btn-secondary { background: rgba(255,255,255,.16); border-color: rgba(255,255,255,.4); color: #fff; }
.hero .btn-secondary:hover { background: rgba(255,255,255,.28); }

/* --- CARDS --- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 18px; margin-bottom: 32px; }
.card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; cursor: pointer; transition: .2s ease; box-shadow: var(--shadow-sm);
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--primary); }
.card-icon { font-size: 30px; margin-bottom: 10px; }
.card h3 { font-size: 18px; margin-bottom: 8px; }
.card p { font-size: 14px; color: var(--text-muted); margin-bottom: 12px; }
.card-meta { font-size: 12px; color: var(--primary); font-weight: 700; }

/* --- INFO BLOCK --- */
.info-block { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 26px; margin-bottom: 22px; }
.info-block h3 { font-size: 20px; margin-bottom: 14px; }
.info-block p { margin-bottom: 12px; color: var(--text-muted); }
.info-block ul, .info-block ol { margin: 10px 0 0 24px; color: var(--text-muted); }
.info-block li { margin-bottom: 7px; }

/* --- BUTTONS --- */
.btn { padding: 11px 20px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 600; transition: .2s ease; border: 1px solid transparent; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }
.btn-secondary:hover { background: var(--primary); color: #fff; }
.btn-blue { background: var(--accent); color: #fff; }
.btn-blue:hover { filter: brightness(.92); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { filter: brightness(.92); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn-outline:hover { background: var(--bg-hover); color: var(--text); }
.btn-sm { padding: 7px 13px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ======================= ТЕОРИЯ ======================= */
.theory-toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.search-input {
  flex: 1; min-width: 220px; padding: 10px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text); font-size: 14px; font-family: inherit;
}
.search-input:focus { outline: 2px solid var(--primary-light); border-color: var(--primary); }
.toolbar-actions { display: flex; gap: 8px; }

.theory-layout { display: grid; grid-template-columns: 290px 1fr; gap: 24px; align-items: start; }
.theory-toc {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; position: sticky; top: calc(var(--topbar-h) + 20px); max-height: calc(100vh - var(--topbar-h) - 48px); overflow-y: auto;
}
.theory-toc-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 10px; border-radius: var(--radius-sm); color: var(--text-muted); font-size: 13.5px; line-height: 1.35;
  transition: .15s ease; margin-bottom: 2px;
}
.theory-toc-item:hover { background: var(--bg-hover); color: var(--text); }
.theory-toc-item.active { background: var(--primary-light); color: var(--primary); font-weight: 700; }
.theory-toc-num {
  flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--bg-hover); color: var(--text-muted); font-size: 12px; font-weight: 700;
}
.theory-toc-item.active .theory-toc-num { background: var(--primary); color: #fff; }
.theory-toc-item.read .theory-toc-num { background: var(--success); color: #fff; }
.theory-toc-check { margin-left: auto; color: var(--success); font-size: 14px; }

.theory-content { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 30px 34px; min-height: 400px; }
.theory-section { display: none; }
.theory-section.active { display: block; animation: fadeIn .25s ease; }
.theory-section h2 { font-size: 25px; font-weight: 800; margin-bottom: 6px; }
.theory-section h3 { font-size: 18px; margin: 26px 0 10px; color: var(--primary); }
.theory-section h4 { font-size: 15.5px; margin: 18px 0 6px; }
.theory-section p { margin-bottom: 13px; color: var(--text-muted); }
.theory-section ul, .theory-section ol { margin: 8px 0 14px 26px; color: var(--text-muted); }
.theory-section li { margin-bottom: 6px; }
.theory-section strong { color: var(--text); }
.theory-section code {
  background: var(--bg-hover); padding: 2px 6px; border-radius: 4px;
  font-family: "JetBrains Mono", Consolas, monospace; font-size: 13px; color: var(--primary);
}
.theory-section table { width: 100%; border-collapse: collapse; margin: 16px 0 20px; font-size: 14px; }
.theory-section th, .theory-section td { border: 1px solid var(--border); padding: 10px 12px; text-align: left; vertical-align: top; }
.theory-section th { background: var(--bg-subtle); font-weight: 700; color: var(--text); }
.theory-section tbody tr:nth-child(even) td { background: var(--bg-subtle); }

.box { padding: 15px 18px; border-radius: var(--radius-sm); margin: 18px 0; border-left: 4px solid; font-size: 14.5px; color: var(--text-muted); }
.box p { margin-bottom: 8px; }
.box p:last-child { margin-bottom: 0; }
.box--info { background: var(--primary-light); border-color: var(--primary); }
.box--warn { background: var(--warning-light); border-color: var(--warning); }
.box--danger { background: var(--danger-light); border-color: var(--danger); }
.box--ok { background: var(--success-light); border-color: var(--success); }

.theory-meta { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.theory-meta span { font-size: 12.5px; color: var(--text-light); }
.theory-nav { display: flex; gap: 12px; margin-top: 32px; padding-top: 22px; border-top: 1px solid var(--border); justify-content: space-between; }

/* ======================= СПИСОК ТЕСТОВ ======================= */
.test-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.test-card {
  background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; display: flex; flex-direction: column; gap: 10px; box-shadow: var(--shadow-sm);
}
.test-card.passed { border-color: var(--success); }
.test-card-head { display: flex; align-items: flex-start; gap: 12px; }
.test-num { width: 32px; height: 32px; border-radius: 8px; background: var(--primary-light); color: var(--primary); display: grid; place-items: center; font-weight: 800; font-size: 14px; flex-shrink: 0; }
.test-card.passed .test-num { background: var(--success); color: #fff; }
.test-card h3 { font-size: 16px; font-weight: 700; }
.test-card p { font-size: 13.5px; color: var(--text-muted); flex: 1; }
.test-tags { display: flex; gap: 6px; flex-wrap: wrap; }
.tag { font-size: 11.5px; font-weight: 600; padding: 3px 9px; border-radius: 99px; background: var(--bg-hover); color: var(--text-muted); }
.tag--ok { background: var(--success-light); color: var(--success); }
.tag--no { background: var(--danger-light); color: var(--danger); }
.tag--warn { background: var(--warning-light); color: var(--warning); }

/* ======================= ПРОХОЖДЕНИЕ ТЕСТА ======================= */
#page-testrun { max-width: 900px; }
.run-top { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; }
.run-title { font-size: 17px; font-weight: 700; flex: 1; }
.run-counter { font-size: 14px; color: var(--text-muted); font-weight: 600; }
.run-progress { height: 6px; background: var(--border); border-radius: 99px; overflow: hidden; margin-bottom: 26px; }
.run-progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .3s ease; }
.run-body { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 30px; min-height: 300px; }
.run-actions { display: flex; gap: 12px; justify-content: space-between; margin-top: 20px; }
.run-actions .btn:last-child { margin-left: auto; }

.q-num { display: inline-block; font-size: 12px; font-weight: 700; color: var(--primary); background: var(--primary-light); padding: 4px 11px; border-radius: 99px; margin-bottom: 14px; }
.q-text { font-size: 18px; font-weight: 600; margin-bottom: 20px; line-height: 1.45; }
.q-hint { font-size: 13px; color: var(--text-light); margin: -10px 0 16px; }
.opts { display: flex; flex-direction: column; gap: 10px; }
.opt {
  display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; cursor: pointer;
  border: 2px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-subtle); transition: .15s ease;
}
.opt:hover { border-color: var(--primary); background: var(--primary-light); }
.opt.selected { border-color: var(--primary); background: var(--primary-light); }
.opt.correct { border-color: var(--success); background: var(--success-light); }
.opt.wrong { border-color: var(--danger); background: var(--danger-light); }
.opt.disabled { cursor: default; }
.opt.disabled:hover { border-color: var(--border); background: var(--bg-subtle); }
.opt-mark { width: 26px; height: 26px; border-radius: 6px; border: 2px solid var(--border); display: grid; place-items: center; font-size: 13px; font-weight: 800; flex-shrink: 0; background: var(--bg-card); }
.opt.selected .opt-mark { border-color: var(--primary); color: var(--primary); }
.opt.correct .opt-mark { border-color: var(--success); color: var(--success); }
.opt.wrong .opt-mark { border-color: var(--danger); color: var(--danger); }
.opt-text { flex: 1; font-size: 15px; }

.match-grid { display: grid; grid-template-columns: 1fr 34px 1fr; gap: 10px 14px; align-items: center; }
.match-col-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-light); margin-bottom: 4px; }
.match-left { padding: 12px 14px; background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14.5px; }
.match-arrow { text-align: center; color: var(--text-light); }
select.match-select {
  width: 100%; padding: 11px 12px; border-radius: var(--radius-sm); border: 2px solid var(--border);
  background: var(--bg-card); color: var(--text); font-size: 14px; font-family: inherit;
}
select.match-select:focus { outline: none; border-color: var(--primary); }
select.match-select.correct { border-color: var(--success); background: var(--success-light); }
select.match-select.wrong { border-color: var(--danger); background: var(--danger-light); }

.order-list { display: flex; flex-direction: column; gap: 10px; }
.order-item { display: flex; align-items: center; gap: 12px; padding: 13px 15px; border: 2px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-subtle); font-size: 15px; }
.order-item .order-pos { width: 28px; height: 28px; border-radius: 6px; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 13px; flex-shrink: 0; }
.order-item.correct { border-color: var(--success); background: var(--success-light); }
.order-item.wrong { border-color: var(--danger); background: var(--danger-light); }
.order-moves { margin-left: auto; display: flex; gap: 5px; }
.order-moves button { width: 28px; height: 28px; border-radius: 6px; background: var(--bg-card); border: 1px solid var(--border); font-weight: 700; }
.order-moves button:hover { border-color: var(--primary); color: var(--primary); }

.answer-input {
  width: 220px; padding: 14px 16px; font-size: 18px; font-weight: 600; text-align: center;
  border: 2px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg-card); color: var(--text); font-family: inherit;
}
.answer-input:focus { outline: none; border-color: var(--primary); }
.answer-input.correct { border-color: var(--success); background: var(--success-light); }
.answer-input.wrong { border-color: var(--danger); background: var(--danger-light); }
.answer-unit { font-size: 14px; color: var(--text-muted); margin-left: 10px; }
.calc-hint { font-size: 13.5px; color: var(--text-muted); margin-top: 14px; }

.explain { margin-top: 22px; padding: 18px 20px; border-radius: var(--radius-sm); background: var(--bg-subtle); border-left: 4px solid var(--primary); }
.explain h4 { font-size: 14px; margin-bottom: 8px; color: var(--primary); }
.explain p { font-size: 14.5px; color: var(--text-muted); margin-bottom: 8px; }
.explain p:last-child { margin-bottom: 0; }

.result-panel { text-align: center; padding: 30px 20px; }
.result-score { font-size: 54px; font-weight: 800; line-height: 1; margin: 14px 0 6px; }
.result-score.pass { color: var(--success); }
.result-score.fail { color: var(--danger); }
.result-sub { font-size: 15px; color: var(--text-muted); margin-bottom: 22px; }
.result-stats { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; margin-bottom: 26px; }
.result-stat { background: var(--bg-subtle); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 20px; min-width: 110px; }
.result-stat b { display: block; font-size: 22px; }
.result-stat span { font-size: 12px; color: var(--text-muted); }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.result-review { text-align: left; margin-top: 30px; }
.result-review h3 { font-size: 17px; margin-bottom: 14px; }
.review-item { padding: 16px 18px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 12px; background: var(--bg-subtle); }
.review-item .rev-q { font-size: 15px; font-weight: 600; margin-bottom: 8px; }
.review-item .rev-ans { font-size: 13.5px; margin-bottom: 6px; }
.review-item .rev-ans.ok { color: var(--success); }
.review-item .rev-ans.no { color: var(--danger); }

/* ======================= ЗАДАНИЯ ======================= */
.task-list { display: flex; flex-direction: column; gap: 16px; }
.task-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.task-card.solved { border-color: var(--success); }
.task-head { display: flex; align-items: center; gap: 14px; padding: 18px 22px; cursor: pointer; }
.task-head:hover { background: var(--bg-hover); }
.task-num { width: 32px; height: 32px; border-radius: 8px; background: var(--primary-light); color: var(--primary); display: grid; place-items: center; font-weight: 800; font-size: 14px; flex-shrink: 0; }
.task-card.solved .task-num { background: var(--success); color: #fff; }
.task-head h3 { font-size: 16px; font-weight: 700; flex: 1; }
.task-arrow { color: var(--text-light); font-size: 18px; transition: .2s ease; }
.task-card.open .task-arrow { transform: rotate(90deg); }
.task-body { display: none; padding: 4px 22px 22px; border-top: 1px solid var(--border); }
.task-card.open .task-body { display: block; }
.task-text { margin: 18px 0; color: var(--text-muted); }
.task-text p { margin-bottom: 10px; }
.task-fields { display: flex; flex-direction: column; gap: 12px; margin: 18px 0; }
.task-field { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.task-field label { font-size: 14.5px; color: var(--text); flex: 1; min-width: 220px; }
.task-field .answer-input { width: 180px; font-size: 16px; padding: 11px 14px; }
.task-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 18px; }
.task-solution { display: none; margin-top: 20px; }
.task-solution.show { display: block; }
.task-verdict { padding: 14px 18px; border-radius: var(--radius-sm); font-weight: 600; margin-bottom: 6px; font-size: 15px; }
.task-verdict.ok { background: var(--success-light); color: var(--success); }
.task-verdict.no { background: var(--danger-light); color: var(--danger); }
.field-results { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; }
.field-result { font-size: 14px; padding: 8px 12px; border-radius: 6px; }
.field-result.ok { background: var(--success-light); color: var(--success); }
.field-result.no { background: var(--danger-light); color: var(--danger); }

/* ======================= СПРАВОЧНИК ======================= */
.ref-tabs { display: flex; gap: 8px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.ref-tab { padding: 10px 18px; font-size: 14px; font-weight: 600; color: var(--text-muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.ref-tab:hover { color: var(--text); }
.ref-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.ref-body { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 28px 30px; }
.ref-body h3 { font-size: 18px; color: var(--primary); margin: 22px 0 10px; }
.ref-body h3:first-child { margin-top: 0; }
.ref-body table { width: 100%; border-collapse: collapse; font-size: 14px; }
.ref-body th, .ref-body td { border: 1px solid var(--border); padding: 10px 12px; text-align: left; vertical-align: top; }
.ref-body th { background: var(--bg-subtle); }
.glossary-item { padding: 12px 0; border-bottom: 1px solid var(--border); }
.glossary-item:last-child { border-bottom: none; }
.glossary-term { font-weight: 700; color: var(--text); margin-bottom: 3px; }
.glossary-def { font-size: 14px; color: var(--text-muted); }

/* ======================= ПРОГРЕСС / ЭТАПЫ ======================= */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 26px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; text-align: center; }
.stat-card-icon { font-size: 26px; margin-bottom: 8px; }
.stat-card-value { font-size: 26px; font-weight: 800; color: var(--primary); }
.stat-card-label { font-size: 12.5px; color: var(--text-muted); margin-top: 3px; }

.stage-list { display: flex; flex-direction: column; gap: 14px; }
.stage-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 24px; }
.stage-card.done { border-color: var(--success); background: linear-gradient(180deg, var(--success-light) 0%, var(--bg-card) 60%); }
.stage-head { display: flex; align-items: center; gap: 14px; margin-bottom: 10px; }
.stage-num { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; font-weight: 800; font-size: 15px; background: var(--bg-hover); color: var(--text-muted); flex-shrink: 0; }
.stage-card.done .stage-num { background: var(--success); color: #fff; }
.stage-card.current .stage-num { background: var(--primary); color: #fff; }
.stage-head h3 { font-size: 17px; font-weight: 700; flex: 1; }
.stage-pct { font-size: 14px; font-weight: 800; color: var(--primary); }
.stage-card.done .stage-pct { color: var(--success); }
.stage-desc { font-size: 13.5px; color: var(--text-muted); margin-bottom: 12px; }
.stage-bar { height: 9px; background: var(--border); border-radius: 99px; overflow: hidden; }
.stage-fill { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--primary), var(--accent)); transition: width .4s ease; }
.stage-card.done .stage-fill { background: var(--success); }
.stage-detail { font-size: 12.5px; color: var(--text-light); margin-top: 9px; }
.stage-link { margin-top: 12px; }

.history-item { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.history-item:last-child { border-bottom: none; }
.history-when { color: var(--text-light); font-size: 12.5px; min-width: 130px; }
.history-what { flex: 1; }
.history-score { font-weight: 700; }

/* ======================= МОДАЛКИ ======================= */
.modal { position: fixed; inset: 0; background: rgba(15,23,42,.6); display: grid; place-items: center; z-index: 200; padding: 24px; }
.modal[hidden] { display: none; }
.modal-box {
  background: var(--bg-card); border-radius: 16px; padding: 32px; max-width: 640px; width: 100%;
  max-height: 88vh; overflow-y: auto; position: relative; box-shadow: var(--shadow-lg);
}
.modal-box--wide { max-width: 900px; }
.modal-box h2 { font-size: 22px; margin-bottom: 16px; }
.modal-close { position: absolute; top: 14px; right: 16px; font-size: 18px; width: 32px; height: 32px; border-radius: 8px; color: var(--text-light); }
.modal-close:hover { background: var(--bg-hover); color: var(--text); }
.instr-list { margin: 0 0 22px 22px; color: var(--text-muted); font-size: 14.5px; }
.instr-list li { margin-bottom: 10px; }
.cert-toolbar { display: flex; gap: 10px; margin-bottom: 22px; flex-wrap: wrap; align-items: center; }
.cert-toolbar .search-input { flex: 1; min-width: 240px; }

/* ======================= СЕРТИФИКАТ ======================= */
.cert {
  border: 3px double var(--primary); border-radius: 14px; padding: 44px 40px; text-align: center;
  background: var(--bg-card); position: relative;
}
.cert-lock { padding: 40px 30px; }
.cert-lock h3 { font-size: 20px; margin-bottom: 10px; }
.cert-lock p { color: var(--text-muted); font-size: 14.5px; max-width: 560px; margin: 0 auto 20px; }
.cert-inner { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.cert-logo { font-size: 40px; }
.cert-title { font-size: 13px; letter-spacing: .22em; text-transform: uppercase; color: var(--text-light); font-weight: 700; }
.cert-name { font-size: 32px; font-weight: 800; color: var(--text); border-bottom: 2px solid var(--border); padding: 6px 32px 8px; min-width: 320px; }
.cert-sub { font-size: 15px; color: var(--text-muted); max-width: 620px; }
.cert-course { font-size: 17px; font-weight: 700; color: var(--primary); }
.cert-stats { display: flex; gap: 26px; flex-wrap: wrap; justify-content: center; margin: 14px 0 6px; }
.cert-stat b { display: block; font-size: 21px; color: var(--text); }
.cert-stat span { font-size: 11.5px; color: var(--text-light); }
.cert-bottom { display: flex; justify-content: space-between; align-items: flex-end; margin-top: 26px; font-size: 12.5px; color: var(--text-muted); gap: 20px; }
.cert-line { border-top: 1px solid var(--text-muted); padding-top: 5px; min-width: 190px; }
.cert-num { font-family: "JetBrains Mono", Consolas, monospace; font-size: 12px; color: var(--text-light); }

/* ======================= TOAST ======================= */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 13px 22px; border-radius: 10px;
  font-size: 14px; font-weight: 600; z-index: 300; box-shadow: var(--shadow-lg);
  animation: toastIn .25s ease; max-width: 90vw;
}
.toast[hidden] { display: none; }
.toast.ok { background: var(--success); color: #fff; }
.toast.err { background: var(--danger); color: #fff; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 14px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ======================= АДАПТИВНОСТЬ ======================= */
@media (max-width: 1100px) {
  .theory-layout { grid-template-columns: 1fr; }
  .theory-toc { position: static; max-height: 320px; }
}
@media (max-width: 860px) {
  :root { --topbar-h: 56px; }
  .hamburger { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .25s ease; }
  .sidebar.open { transform: none; }
  .content { margin-left: 0; padding: 24px 18px 56px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-left { min-width: 0; flex: 1 1 auto; overflow: hidden; }
  .topbar-right { flex: 0 0 auto; gap: 8px; }
  .brand { min-width: 0; }
  .brand > div { min-width: 0; overflow: hidden; }
  .brand-icon { font-size: 22px; flex-shrink: 0; }
  .brand-title, .brand-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand-title { max-width: 40vw; }
  .brand-sub { max-width: 40vw; }
  .progress-label { display: none; }
  .progress-bar { width: 64px; }
  .cabinet-btn { padding: 7px 9px; }
  .cabinet-label { display: none; }
  .hero { padding: 28px 22px; }
  .hero h1 { font-size: 26px; }
  .attribution { padding: 15px 16px; gap: 11px; }
  .attribution-ico { font-size: 20px; }
  .attribution p { font-size: 14px; }
  .theory-content, .ref-body, .run-body { padding: 22px 18px; }
  .match-grid { grid-template-columns: 1fr; }
  .match-arrow { display: none; }
  .cert-name { font-size: 24px; min-width: 0; }
  .cert { padding: 28px 18px; }
  .run-actions { flex-wrap: wrap; }
  .task-field .answer-input { width: 100%; }
}
@media (max-width: 480px) {
  /* На узких экранах место экономим значками: бургер, логотип, прогресс, три кнопки. */
  .brand-title, .brand-sub { display: none; }
  .brand { gap: 0; }
  .progress-percent { min-width: 32px; }
  .cert-stats { gap: 16px; }
}
@media print {
  .topbar, .sidebar, .content { display: none !important; }
  .modal { position: static; background: none; padding: 0; display: block; }
  .modal[hidden] { display: none; }
  .no-print { display: none !important; }
  .cert { border-color: #1e40af; page-break-inside: avoid; }
  body { background: #fff; }
}
