:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-muted: #f0f2f5;
  --border: #e1e4e9;
  --text: #1c2330;
  --text-muted: #5f6b7c;
  --accent: #2f6fde;
  --accent-hover: #255bb9;
  --accent-soft: #e7effc;
  --danger: #c93b3b;
  --danger-soft: #fbeaea;
  --success: #1f8a4c;
  --success-soft: #e5f5ec;
  --warning-soft: #fdf4e3;
  --warning: #9a6a0b;
  --sidebar-bg: #1d2533;
  --sidebar-text: #c8d0dc;
  --sidebar-text-active: #ffffff;
  --sidebar-hover: #2a3445;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 2px 8px rgba(20, 30, 50, .04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --surface: #1a2029;
    --surface-muted: #222a35;
    --border: #2c3542;
    --text: #e4e8ee;
    --text-muted: #97a2b2;
    --accent: #5b92f0;
    --accent-hover: #7aa7f3;
    --accent-soft: #1f2d45;
    --danger: #ec6b6b;
    --danger-soft: #3a2224;
    --success: #4cc27f;
    --success-soft: #1b3326;
    --warning-soft: #372d17;
    --warning: #e2b556;
    --sidebar-bg: #0d1117;
    --sidebar-hover: #1b2330;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
h2 { font-size: 1.15rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--text-muted); }
.small { font-size: .85rem; }

/* --- Каркас ------------------------------------------------------------- */

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

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  color: var(--sidebar-text-active);
  font-weight: 700;
  font-size: 1.15rem;
  padding: 0 12px 20px;
  letter-spacing: .01em;
}

.nav-section {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #7c8798;
  padding: 16px 12px 6px;
}

.nav a {
  display: block;
  padding: 8px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav a:hover { background: var(--sidebar-hover); color: var(--sidebar-text-active); text-decoration: none; }
.nav a.active { background: var(--accent); color: #fff; }

.sidebar-footer {
  margin-top: auto;
  padding: 16px 12px 0;
  border-top: 1px solid rgba(255, 255, 255, .08);
  font-size: .85rem;
}
.sidebar-footer .who { color: var(--sidebar-text-active); font-weight: 600; }
.sidebar-footer form { margin-top: 8px; }
.link-button {
  background: none;
  border: 0;
  padding: 0;
  color: var(--sidebar-text);
  cursor: pointer;
  font: inherit;
}
.link-button:hover { color: var(--sidebar-text-active); text-decoration: underline; }

.content { flex: 1; min-width: 0; padding: 32px 40px; max-width: 1100px; }

.page-header { margin-bottom: 24px; }
.page-header .actions { margin-top: 12px; }

/* --- Карточки и таблицы ------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 24px;
  margin-bottom: 20px;
}

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

.tile {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  color: var(--text);
  box-shadow: var(--shadow);
}
.tile:hover { border-color: var(--accent); text-decoration: none; }
.tile .title { font-weight: 600; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
td.actions { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; margin: 0 -12px; }

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: .78rem;
  background: var(--surface-muted);
  color: var(--text-muted);
  border: 1px solid var(--border);
  margin: 1px 2px 1px 0;
  white-space: nowrap;
}
.badge.accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }

.empty { color: var(--text-muted); padding: 12px 0; }

/* --- Формы -------------------------------------------------------------- */

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 4px; font-size: .92rem; }
.field input, .field select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field input[readonly] { background: var(--surface-muted); color: var(--text-muted); }
.field .help { font-size: .82rem; color: var(--text-muted); margin-top: 4px; }
.field .help ul { margin: 4px 0 0; padding-left: 18px; }
.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--danger); font-size: .85rem; }
.form-errors { background: var(--danger-soft); color: var(--danger); border-radius: 8px; padding: 10px 14px; margin-bottom: 16px; }
.form-errors .errorlist { margin: 0; }

.inline-form { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.inline-form .field { margin-bottom: 0; flex: 1; min-width: 220px; }

fieldset { border: 0; padding: 0; margin: 0 0 8px; }
legend { font-weight: 700; font-size: 1.05rem; margin-bottom: 12px; padding: 0; }

.btn {
  display: inline-block;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  line-height: 1.3;
}
.btn:hover { background: var(--accent-hover); text-decoration: none; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { border-color: var(--accent); }
.btn.danger { background: var(--surface); color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.btn.small { padding: 5px 12px; font-size: .85rem; font-weight: 500; }
.btn.block { width: 100%; }

/* --- Сообщения ---------------------------------------------------------- */

.messages { list-style: none; padding: 0; margin: 0 0 20px; }
.messages li { padding: 10px 14px; border-radius: 8px; margin-bottom: 8px; background: var(--accent-soft); }
.messages li.success { background: var(--success-soft); color: var(--success); }
.messages li.error { background: var(--danger-soft); color: var(--danger); }

.notice { padding: 12px 16px; border-radius: 8px; background: var(--accent-soft); margin-bottom: 16px; }
.notice.warning { background: var(--warning-soft); color: var(--warning); }

/* --- Страницы входа ----------------------------------------------------- */

.auth {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}
.auth-card { width: 100%; max-width: 440px; }
.auth-card .brand-line { font-weight: 700; color: var(--accent); margin-bottom: 16px; letter-spacing: .02em; }
.auth-card .divider { text-align: center; color: var(--text-muted); font-size: .85rem; margin: 16px 0; }

/* --- Доска обучения ----------------------------------------------------- */

.content.wide { max-width: none; }

.icon { width: 1em; height: 1em; vertical-align: -0.14em; flex-shrink: 0; }

.board-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }

.board {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  overflow-x: auto;
  padding-bottom: 12px;
}

.column {
  flex: 0 0 300px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-margin: 24px;
}
.column.status-locked { opacity: .78; }
.column-new { background: transparent; border-style: dashed; }

.column-head { display: flex; flex-direction: column; gap: 6px; }
.column-title { font-weight: 700; font-size: 1.02rem; overflow-wrap: anywhere; }

.progress { height: 6px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); border-radius: 999px; transition: width .3s; }
.status-completed .progress-bar { background: var(--success); }

.topics { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.topic {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  scroll-margin: 24px;
}
.topic.status-locked { border-left-color: var(--border); }
.topic.status-locked .topic-title, .topic.status-locked .topic-icon { color: var(--text-muted); }
.topic.status-needs_quiz { border-left-color: var(--warning); }
.topic.status-needs_quiz .topic-icon { color: var(--warning); }
.topic.status-completed { border-left-color: var(--success); }
.topic.status-completed .topic-icon { color: var(--success); }
.topic-icon { color: var(--accent); display: inline-flex; }

.topic-main { display: flex; gap: 8px; align-items: flex-start; }
.topic-title { color: var(--text); font-weight: 500; overflow-wrap: anywhere; }
a.topic-title:hover { color: var(--accent); }
.topic-badges:not(:empty) { margin-top: 6px; }
.topic-badges:empty { display: none; }

.column-quiz {
  border-radius: 8px;
  padding: 10px 12px;
  font-size: .9rem;
  display: flex;
  gap: 8px;
  align-items: center;
  background: var(--surface);
  border: 1px dashed var(--border);
  color: var(--text-muted);
}
.column-quiz.status-completed { color: var(--success); border-style: solid; }
.column-quiz.status-available { padding: 0; border: 0; background: none; }

.tools { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; margin-top: 8px; }
.tools form { margin: 0; }
.tool-group { display: inline-flex; gap: 4px; }
.btn:disabled { opacity: .4; cursor: default; }

.editor { margin-top: 8px; font-size: .9rem; }
.editor summary { cursor: pointer; color: var(--accent); font-weight: 500; }
.editor[open] summary { margin-bottom: 8px; }
.editor .field { margin-bottom: 10px; }
.editor .field input { padding: 6px 10px; }
.editor.add { margin-top: 0; }
.check { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; font-weight: 400; cursor: pointer; }
.check.inline { display: inline-flex; margin: 0 0 0 8px; }
.notice.small { padding: 8px 12px; font-size: .85rem; margin: 0; }

/* --- Тема --------------------------------------------------------------- */

.doc-frame { width: 100%; height: 75vh; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.topic-actions p:last-child { margin-bottom: 0; }

/* --- Тесты -------------------------------------------------------------- */

.quiz, #quiz-editor { max-width: 760px; }
.question { margin-bottom: 16px; }
.question legend { float: left; width: 100%; font-weight: 600; font-size: 1rem; margin-bottom: 4px; }
.question legend + * { clear: both; }
.question.wrong { border-color: var(--danger); }
.wrong-note { color: var(--danger); margin: 6px 0 0; }
.answer {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.answer:hover { background: var(--surface-muted); }
.answer input { margin-top: 4px; }

.question-editor .question-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.question-editor textarea, .question-editor select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  resize: vertical;
}
.choices { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.choice-row { display: flex; gap: 8px; align-items: center; }
.choice-row input[type=radio], .choice-row input[type=checkbox] { width: 18px; height: 18px; flex-shrink: 0; accent-color: var(--success); }
.choice-text {
  flex: 1;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.editor-actions { display: flex; gap: 10px; flex-wrap: wrap; max-width: 760px; }

/* --- Отчёты о прогрессе ------------------------------------------------- */

.board-header .actions { display: flex; gap: 8px; flex-wrap: wrap; margin: 0; }
.nowrap { white-space: nowrap; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.2; }
.stat-label { color: var(--text-muted); font-size: .85rem; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  display: inline-flex; gap: 6px; align-items: center;
  padding: 5px 12px; border-radius: 999px; font-size: .88rem;
  border: 1px solid var(--border); color: var(--text); background: var(--surface);
}
.chip:hover { border-color: var(--accent); text-decoration: none; }
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip-count { opacity: .7; font-size: .8rem; }

th a.sort { color: inherit; }
th a.sort.active { color: var(--accent); }
th a.sort.active::after { content: " ▾"; }

.progress-cell { display: flex; align-items: center; gap: 8px; min-width: 150px; margin-bottom: 4px; }
.progress-cell .progress { flex: 1; }
.progress-cell.large .progress { height: 10px; }
.progress-cell.large strong { font-size: 1.2rem; }

.segments { display: flex; gap: 3px; min-width: 120px; margin-bottom: 4px; }
.seg {
  flex: 1; height: 8px; border-radius: 3px; min-width: 10px;
  background: linear-gradient(to right, var(--accent) var(--p), var(--border) var(--p));
}
.seg-completed { background: var(--success); }
.seg-locked { background: var(--border); opacity: .6; }

.status-inline { display: inline-flex; gap: 6px; align-items: center; }
.status-inline.status-completed { color: var(--success); }
.status-inline.status-needs_quiz { color: var(--warning); }
.status-inline.status-available { color: var(--accent); }
.status-inline.status-locked { color: var(--text-muted); }
.quiz-row td { background: var(--surface-muted); }

.details { display: grid; grid-template-columns: max-content 1fr; gap: 8px 20px; margin: 0; }
.details dt { color: var(--text-muted); }
.details dd { margin: 0; }

/* --- Мобильная версия --------------------------------------------------- */

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: auto; height: auto; position: static; padding: 12px; }
  .brand { padding-bottom: 8px; }
  .nav-section { padding-top: 8px; }
  .content { padding: 20px 16px; }
  .card { padding: 16px; }
  .board { flex-direction: column; overflow-x: visible; }
  .column { flex: none; width: 100%; }
  .doc-frame { height: 60vh; }
}
