:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --border: #e3e8f0;
  --text: #1f2937;
  --muted: #6b7280;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --accent: #0ea5e9;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --radius: 14px;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: linear-gradient(120deg, var(--primary), var(--accent));
  color: #fff;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

header.topbar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 18px;
}

header.topbar .brand small {
  display: block;
  font-weight: 400;
  font-size: 12px;
  opacity: 0.85;
}

nav.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 58px;
  z-index: 19;
}

nav.tabs button {
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
}

nav.tabs button:hover { border-color: var(--primary); color: var(--primary); }

nav.tabs button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

main {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 80px;
}

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

.card h2 {
  margin-top: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary);
}
.badge.closed { background: #fee2e2; color: var(--danger); }
.badge.open { background: #dcfce7; color: var(--success); }

button.btn {
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}
button.btn:hover { background: var(--primary-dark); }
button.btn.secondary { background: #fff; color: var(--primary); border: 1px solid var(--primary); }
button.btn.secondary:hover { background: #eef2ff; }
button.btn.danger { background: var(--danger); }
button.btn.danger:hover { background: #b91c1c; }
button.btn:disabled { background: #cbd5e1; cursor: not-allowed; }

.locked-panel {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.locked-panel .icon { font-size: 40px; margin-bottom: 10px; }

.quiz-question { margin-bottom: 18px; padding-bottom: 14px; border-bottom: 1px dashed var(--border); }
.quiz-question:last-child { border-bottom: none; }
.quiz-options label {
  display: block;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin: 6px 0;
  cursor: pointer;
}
.quiz-options label:hover { border-color: var(--primary); }

select, input[type=text], input[type=password], input[type=email], textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
}

.chart-block { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--border); }
.chart-block:first-of-type { margin-top: 10px; padding-top: 0; border-top: none; }
.chart-question { margin-bottom: 10px; }

/* Горизонтальные полосы */
.chart-bars { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 110px 1fr 90px; align-items: center; gap: 10px; }
.bar-row-label { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row-track { background: #f1f5f9; border-radius: 999px; overflow: hidden; height: 16px; }
.bar-row-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; }
.bar-row-value { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }

/* Вертикальные столбцы */
.chart-columns { display: flex; align-items: flex-end; gap: 14px; min-height: 60px; padding: 10px 4px 0; }
.chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; min-width: 0; }
.chart-col-bar { width: 100%; max-width: 46px; border-radius: 8px 8px 3px 3px; transition: height 0.5s ease; }
.chart-col-count { font-size: 12px; font-weight: 700; margin-bottom: 4px; }
.chart-col-label { margin-top: 8px; font-size: 12px; color: var(--muted); text-align: center; }

/* Кольцевая диаграмма */
.chart-pie-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; margin-top: 4px; }
.chart-donut {
  position: relative;
  width: 150px;
  height: 150px;
  border-radius: 50%;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.1);
}
.chart-donut-hole {
  position: absolute;
  inset: 26%;
  background: var(--surface);
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 0 0 1px var(--border);
}
.chart-donut-total { font-size: 20px; font-weight: 800; line-height: 1.1; }
.chart-donut-total-label { font-size: 10px; color: var(--muted); }
.chart-legend { display: flex; flex-direction: column; gap: 8px; }
.chart-legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.chart-legend-swatch { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.chart-col-legend { margin-top: 14px; }
.chart-col-legend .chart-legend-item { align-items: flex-start; }
.chart-col-legend .chart-legend-swatch { margin-top: 4px; }

/* Рейтинг (лидерборд) */
.chart-leaderboard { display: flex; flex-direction: column; gap: 12px; }
.lb-row { display: flex; align-items: center; gap: 12px; }
.lb-rank { width: 28px; flex-shrink: 0; text-align: center; font-size: 16px; font-weight: 700; color: var(--muted); }
.lb-row-top .lb-rank { font-size: 20px; }
.lb-body { flex: 1; min-width: 0; }
.lb-label { font-size: 13px; font-weight: 600; margin-bottom: 4px; display: flex; justify-content: space-between; gap: 8px; }
.lb-track { background: #f1f5f9; border-radius: 999px; overflow: hidden; height: 12px; }
.lb-fill { height: 100%; border-radius: 999px; transition: width 0.5s ease; }
.lb-row-top .lb-track { height: 16px; }

/* Таблица */
table.chart-table { width: 100%; border-collapse: collapse; margin-top: 4px; font-size: 13px; }
table.chart-table th, table.chart-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
table.chart-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
table.chart-table tr.chart-table-top { background: #f5f3ff; }
table.chart-table tr.chart-table-top td { font-weight: 700; color: var(--primary); }

.pill-list { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { padding: 4px 10px; background: #f1f5f9; border-radius: 999px; font-size: 12px; }

footer.site-footer {
  text-align: center;
  padding: 20px;
  color: var(--muted);
  font-size: 12px;
}

.flex-between { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--text);
  color: #fff;
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 100;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

.name-gate {
  max-width: 420px;
  margin: 60px auto;
  text-align: center;
}

.progress-track { background: #e5e7eb; border-radius: 999px; height: 8px; overflow: hidden; margin: 10px 0 20px; }
.progress-fill { background: linear-gradient(90deg, var(--primary), var(--accent)); height: 100%; transition: width 0.3s; }

.switch { position: relative; display: inline-block; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; cursor: pointer; transition: 0.2s; }
.switch .slider:before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider:before { transform: translateX(18px); }

.qb-question { border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; background: #fafbfe; }
.qb-question input, .qb-question textarea { margin-bottom: 6px; }
.small-btn { font-size: 12px; padding: 4px 10px; border-radius: 8px; }
.muted { color: var(--muted); font-size: 13px; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.module-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
}

.module-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  transition: transform 0.15s, box-shadow 0.15s;
}
.module-card.open { border-color: var(--primary); }
.module-card.open:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(79, 70, 229, 0.12); }
.module-card.locked { opacity: 0.6; }
.module-num {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #eef2ff;
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
}
.module-icon { font-size: 22px; flex-shrink: 0; }
.module-body { flex: 1; min-width: 0; }
.module-title { font-weight: 600; font-size: 14px; line-height: 1.3; }

.scale-row { display: flex; gap: 8px; }
.scale-option { flex: 1; text-align: center; border: 1px solid var(--border); border-radius: 8px; padding: 8px 4px; cursor: pointer; }
.scale-option:hover { border-color: var(--primary); }

.material-list { display: flex; flex-direction: column; gap: 8px; }
.material-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
}
.material-item:hover { border-color: var(--primary); background: #f9fafe; }

/* ---------- Мобильная адаптация ---------- */
@media (max-width: 640px) {
  header.topbar { padding: 12px 16px; }
  header.topbar .brand { font-size: 16px; }
  header.topbar .brand small { font-size: 11px; }

  nav.tabs { padding: 8px 16px; top: 0; }
  .breadcrumb { padding: 8px 16px; flex-wrap: wrap; }

  main { padding: 16px 12px 60px; }

  .card { padding: 16px; margin-bottom: 14px; }
  .card h2 { font-size: 19px; flex-wrap: wrap; }
  .card h3 { font-size: 16px; }

  .module-card { padding: 12px; gap: 10px; }
  .module-title { font-size: 13px; }
  .module-icon { font-size: 18px; }

  .quiz-options label { padding: 10px; font-size: 14px; }
  .scale-row { gap: 4px; }
  .scale-option { padding: 8px 2px; font-size: 13px; }

  /* Подпись варианта — отдельной строкой над полосой, целиком, без обрезки */
  .bar-row { grid-template-columns: 1fr 66px; gap: 4px 6px; }
  .bar-row-label { grid-column: 1 / -1; font-size: 12px; white-space: normal; overflow: visible; }
  .bar-row-value { font-size: 11px; }

  .chart-columns { gap: 6px; }
  .chart-col-label { font-size: 10px; }
  .chart-col-bar { max-width: 32px; }
  .chart-donut { width: 110px; height: 110px; }
  .chart-donut-total { font-size: 16px; }

  .lb-label { font-size: 12px; flex-wrap: wrap; }

  table.chart-table { display: block; overflow-x: auto; white-space: nowrap; }

  form[data-survey] > button.btn,
  .name-gate button.btn { width: 100%; }

  div[style*="display:flex"] { flex-wrap: wrap; }

  .name-gate { margin: 30px auto; }
}

@media (max-width: 420px) {
  .scale-row { flex-wrap: wrap; }
  .scale-option { min-width: 30%; }
}
