:root {
  --bg: #ecf7f1;
  --surface: #ffffff;
  --surface-soft: #f4fbf7;
  --text: #18212f;
  --muted: #61708a;
  --line: #dbe3ee;
  --primary: #1f4e78;
  --primary-hover: #173c5d;
  --accent: #2f7d6d;
  --danger: #b42318;
  --warning: #a15c00;
  --success: #1f7a4d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

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

h1 { font-size: 26px; line-height: 1.2; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 14px; }
p { margin: 0 0 10px; }

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 13px; margin-top: 6px; }
.steps { margin: 12px 0 0; padding-left: 22px; color: var(--text); }
.steps li { margin-bottom: 8px; line-height: 1.45; }
.nowrap { white-space: nowrap; }
.mono { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }

/* --- Верхня панель --- */
.topbar {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .15);
  position: sticky;
  top: 0;
  z-index: 40;
}
.topbar-inner {
  max-width: 1240px;
  margin: 0 auto;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: #fff;
  color: var(--primary);
  font-weight: 800;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  letter-spacing: .5px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: #c9d7e6; font-size: 11px; }

.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a {
  color: #dce7f2;
  padding: 7px 12px;
  border-radius: 9px;
  font-size: 14px;
}
.nav a:hover { background: rgba(255, 255, 255, .12); text-decoration: none; }
.nav a.active { background: rgba(255, 255, 255, .18); color: #fff; font-weight: 600; }

.userbox { display: flex; align-items: center; gap: 10px; font-size: 13px; color: #e4edf6; }
.user-name { max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge {
  background: rgba(255, 255, 255, .16);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.link-muted { color: #c9d7e6; }
.nav-toggle {
  display: none;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  border: 0;
  padding: 8px 12px;
  border-radius: 9px;
  cursor: pointer;
}

/* --- Контейнер --- */
.container { max-width: 1240px; margin: 0 auto; padding: 26px 20px 60px; }
.footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12.5px;
  text-align: center;
  padding: 18px 20px 30px;
}
.footer-legal { margin-top: 6px; font-size: 11.5px; }
.footer-legal a, .public-footer a { color: var(--muted); text-decoration: underline; }
.footer-legal a:hover, .public-footer a:hover { color: var(--text); }
.license-text {
  white-space: pre-wrap;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 12.5px;
  line-height: 1.55;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 16px;
  overflow-x: auto;
}

/* --- Картки --- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
  overflow-x: auto;
}
.narrow { max-width: 520px; }
.narrow-form { max-width: 560px; }
.page-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.two-col > .card { margin-bottom: 0; }

.cards-grid { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 22px;
  min-width: 160px;
  flex: 1;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.stat-card:hover { text-decoration: none; box-shadow: 0 2px 6px rgba(16,24,40,.10), 0 10px 30px rgba(16,24,40,.08); }
.stat-value { font-size: 30px; font-weight: 700; color: var(--primary); line-height: 1.1; }
.stat-label { color: var(--muted); font-size: 13px; }

/* --- Кнопки --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: #e8eef6;
  color: var(--text);
  border: 0;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: #dde6f1; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--surface-soft); }
.btn-danger { background: #b42318; color: #fff; }
.btn-danger:hover { background: #971f15; }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-lg { padding: 14px 20px; font-size: 17px; }
.btn-block { width: 100%; }

/* --- Форми --- */
.stack { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 13.5px; font-weight: 600; color: #344256; }
.checkbox-row { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.checkbox-row input { width: 16px; height: 16px; }
input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 400;
  color: var(--text);
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(31, 78, 120, .25);
  border-color: var(--primary);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 18px;
}
.span-2 { grid-column: span 2; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.inline-form { display: inline; margin: 0; }
.inline-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.actions-cell { display: flex; gap: 6px; flex-wrap: wrap; }
.actions-cell form { margin: 0; }

.fieldset { border: 1px solid var(--line); border-radius: 11px; padding: 14px 16px; }
.fieldset legend { font-weight: 700; font-size: 13.5px; padding: 0 6px; }
.check-list { display: grid; gap: 8px; margin-top: 10px; }
.check-item {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font-weight: 400;
  cursor: pointer;
}
.check-item:hover { background: var(--surface-soft); }
.check-item input { margin-top: 3px; }
.check-item span { display: flex; flex-direction: column; gap: 2px; }
.check-item small { font-weight: 400; }

/* --- Масове призначення --- */
.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.mode-card {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 11px;
  padding: 12px 14px;
  font-weight: 400;
  cursor: pointer;
  background: #fff;
}
.mode-card:hover { background: var(--surface-soft); }
.mode-card:has(input:checked) { border-color: var(--primary); background: #eaf2fb; }
.mode-card input { width: 18px; height: 18px; margin-top: 2px; }
.mode-card span { display: flex; flex-direction: column; gap: 2px; }
.mode-panel { margin-top: 6px; }
.mode-panel .hint { margin-top: 0; }
.selected-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.selected-toolbar .grow { flex: 1; min-width: 200px; }
.scroll-list { max-height: 380px; overflow-y: auto; padding: 2px; }
.is-hidden { display: none !important; }

.inline-group-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.inline-group-form .grow { flex: 1; min-width: 180px; }
.rename-form { display: flex; align-items: center; gap: 8px; margin: 0; }
.rename-form input { min-width: 160px; }

.filters { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.filters .grow { flex: 1; min-width: 200px; }
.filter-actions { display: flex; gap: 8px; }

.mono-input { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; }
.code-block {
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
}
.code-inline { background: var(--surface-soft); padding: 2px 6px; border-radius: 6px; }

/* --- Таблиці --- */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 700; }
.table tbody tr:hover { background: var(--surface-soft); }
.table-compact td, .table-compact th { padding: 6px 8px; }

/* --- Повідомлення --- */
.alert { border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; border: 1px solid transparent; }
.alert-success { background: #e7f6ed; border-color: #bfe3cd; color: #175c39; }
.alert-error { background: #fdecea; border-color: #f5c2bd; color: #8d2118; }
.alert-warning { background: #fff6e5; border-color: #f3d9a8; color: #7a4a00; }
.alert-info { background: #eaf2fb; border-color: #c6dbf3; color: #1c4b7a; }

/* --- Пілюлі --- */
.pill { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.pill-success { background: #e2f4ea; color: #17663f; }
.pill-warning { background: #fdf0d5; color: #8a5200; }
.pill-danger { background: #fdecea; color: #8d2118; }
.pill-muted { background: #e9edf3; color: #56647a; }
.text-danger { color: #8d2118; }
.actions-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* --- Сторінки входу --- */
.auth-wrap { display: flex; justify-content: center; padding-top: 40px; }
.auth-card { width: 100%; max-width: 420px; padding: 30px; }
.auth-card h1 { margin-bottom: 4px; }

/* --- Картка респондента --- */
.back-link { display: inline-block; font-size: 13px; margin-bottom: 6px; color: var(--muted); }
.info-list { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; margin: 0; font-size: 14px; }
.info-list dt { color: var(--muted); }
.info-list dd { margin: 0; }

.code-banner {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  background: linear-gradient(135deg, #1f4e78, #2f7d6d);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.code-label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: #d6e4f0; }
.code-value { display: block; font-size: 38px; letter-spacing: .18em; line-height: 1.2; margin: 2px 0 6px; }
.code-banner .hint { color: #d6e4f0; }
.code-link { display: flex; flex-direction: column; gap: 8px; justify-content: center; min-width: 280px; flex: 1; }
.code-link input { background: rgba(255,255,255,.14); border-color: rgba(255,255,255,.35); color: #fff; }

.result-list { display: flex; flex-direction: column; gap: 14px; }
.result-item { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
.result-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.interpretation { border-left: 4px solid var(--line); padding: 8px 12px; margin-top: 10px; border-radius: 0 8px 8px 0; background: var(--surface-soft); }
.interpretation p { margin: 4px 0 0; font-size: 13.5px; }
.level-low { border-left-color: #2f7d6d; }
.level-medium { border-left-color: #c98a00; }
.level-high { border-left-color: #b42318; }
.level-critical { border-left-color: #7a1c13; }
.level-info { border-left-color: #6b7a90; }

.range-chip {
  display: inline-block; font-size: 11px; line-height: 1.6;
  padding: 1px 7px; border-radius: 999px; margin: 1px 3px 1px 0;
  background: #e9edf3; color: #4c5b70; white-space: nowrap;
}
.range-low { background: #e2f4ea; color: #17663f; }
.range-medium { background: #fdf0d5; color: #8a5200; }
.range-high { background: #fde3d6; color: #8a3b00; }
.range-critical { background: #fbe0de; color: #8a1c13; }
.range-info { background: #e9edf3; color: #56647a; }
.rule-text { font-size: 13px; color: var(--muted); margin-top: 3px; }

.text-answer textarea { width: 100%; min-height: 76px; resize: vertical; }

/* --- Публічна частина --- */
.public-body { background: #ecf7f1; }
.public-top { background: var(--primary); color: #fff; }
.public-top-inner {
  max-width: 760px; margin: 0 auto; padding: 14px 18px;
  display: flex; align-items: center; gap: 12px;
}
.public-brand { display: flex; flex-direction: column; line-height: 1.2; }
.public-brand small { color: #c9d7e6; font-size: 12px; }
.public-container { max-width: 760px; margin: 0 auto; padding: 22px 16px 48px; }
.public-footer { max-width: 760px; margin: 0 auto; padding: 0 18px 30px; color: var(--muted); font-size: 12px; }
.public-card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 24px 22px; margin-bottom: 18px;
}
.public-card h1 { font-size: 23px; }
.public-head { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; margin-bottom: 14px; }
.eyebrow { text-transform: uppercase; letter-spacing: .06em; font-size: 11px; color: var(--muted); margin: 0 0 2px; }
.instruction { background: var(--surface-soft); border-left: 4px solid var(--primary); padding: 10px 12px; border-radius: 0 8px 8px 0; }

.search-label { margin-bottom: 4px; }
.person-list { display: grid; gap: 8px; max-height: 340px; overflow-y: auto; padding: 2px; }
.person-item {
  flex-direction: row; align-items: center; justify-content: space-between; gap: 12px;
  border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px;
  font-weight: 400; cursor: pointer; background: #fff;
}
.person-item:hover { border-color: var(--primary); }
.person-item input { width: 18px; height: 18px; }
.person-name { font-weight: 600; flex: 1; }
.person-meta { color: var(--muted); font-size: 12.5px; }
.person-item.hidden { display: none; }
.code-label input { font-size: 20px; letter-spacing: .25em; text-align: center; }

.empty-state { text-align: center; padding: 30px 10px; }
.privacy-note { color: var(--muted); font-size: 12px; margin-top: 18px; }

.question-list { display: flex; flex-direction: column; gap: 14px; }
.question { border: 1px solid var(--line); border-radius: 12px; padding: 16px; margin: 0; }
.question legend { display: flex; gap: 10px; align-items: flex-start; font-weight: 600; font-size: 15px; padding: 0; margin-bottom: 12px; }
.qnum {
  background: var(--primary); color: #fff; border-radius: 8px;
  min-width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; flex: none;
}
.options { display: grid; gap: 8px; }
.option {
  flex-direction: row; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: 9px; padding: 11px 12px;
  font-weight: 400; cursor: pointer;
}
.option:hover { background: var(--surface-soft); }
.option input { width: 18px; height: 18px; }
.option:has(input:checked) { border-color: var(--primary); background: #eaf2fb; }

.test-submit {
  position: sticky; bottom: 0;
  display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap;
  background: rgba(255,255,255,.96); border-top: 1px solid var(--line);
  padding: 14px 4px; margin-top: 8px;
}
.progress-text { font-size: 13px; color: var(--muted); }

.test-list { display: flex; flex-direction: column; gap: 10px; }
.test-item { display: flex; justify-content: space-between; gap: 14px; align-items: center; border: 1px solid var(--line); border-radius: 11px; padding: 14px 16px; }
.test-item.test-done { background: var(--surface-soft); }
.test-info { display: flex; flex-direction: column; gap: 2px; }
.test-action { flex: none; }

/* --- Дрібниці --- */
.copy-row { display: flex; gap: 8px; flex-wrap: wrap; }
.copy-row input { flex: 1; min-width: 240px; background: var(--surface-soft); }
.simple-list { margin: 0; padding-left: 20px; }
.simple-list li { margin-bottom: 6px; }
.question-preview { padding-left: 22px; }
.question-preview li { margin-bottom: 14px; }
.option-preview { margin: 6px 0 0; padding-left: 18px; color: var(--muted); font-size: 13.5px; }

@media (max-width: 860px) {
  .two-col { grid-template-columns: 1fr; }
  .mode-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .info-list { grid-template-columns: 1fr; gap: 2px; }
  .info-list dt { margin-top: 8px; }

  .nav-toggle { display: inline-block; margin-left: auto; }
  .nav { display: none; width: 100%; order: 4; padding-top: 6px; }
  .nav.open { display: flex; }
  .userbox { width: 100%; order: 3; justify-content: flex-start; flex-wrap: wrap; }
  .topbar-inner { gap: 10px; }
}

@media (max-width: 520px) {
  body { font-size: 15px; }
  .container { padding: 18px 12px 40px; }
  .card { padding: 16px; }
  .public-card { padding: 20px 16px; }
  .code-value { font-size: 32px; }
  .test-item { flex-direction: column; align-items: stretch; }
  .test-action .btn { width: 100%; }
  .stat-card { min-width: 120px; padding: 14px 16px; }
  .stat-value { font-size: 24px; }
}
