:root {
  --blue: #2f6fed;
  --blue-dark: #2557c7;
  --blue-bg: #eef3fc;
  --green-bg: #16a34a;
  --grey-bg: #e5e7eb;
  --grey-text: #6b7280;
  --text: #1f2937;
  --text-light: #6b7280;
  --border: #e6e9ef;
  --bg: #faf7f6;
  --danger: #dc2626;
  --warn-bg: #fff1e6;
  --warn-text: #c2610a;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: linear-gradient(180deg, #fdf4ee 0%, #faf7f6 220px, #faf7f6 100%);
  color: var(--text);
  min-height: 100vh;
}

.page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
  flex-wrap: wrap;
}

.page-header-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  height: 34px;
  width: auto;
  display: block;
  border-radius: 8px;
}

.page-header h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0;
}

.page-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .15s ease, border-color .15s ease, transform .12s ease, box-shadow .15s ease;
}
.btn:active { transform: scale(.96); }

.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { background: #a9c0f0; cursor: not-allowed; transform: none; }

.btn-secondary { background: #fff; color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f5f5f5; border-color: #d7dbe3; }

.btn-text { background: none; color: var(--blue); padding: 6px 4px; font-weight: 600; }
.btn-text:hover { text-decoration: underline; }

.btn-danger-text { background: none; color: var(--danger); padding: 6px 4px; font-weight: 600; }

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; min-width: 640px; border-collapse: collapse; font-size: 14px; }

thead tr { background: var(--blue-bg); }
th {
  text-align: left;
  padding: 12px 20px;
  font-weight: 600;
  color: #33415c;
  font-size: 13px;
}
td { padding: 14px 20px; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background-color .15s ease; }
tbody tr:hover { background: #fbfbfd; }

.badge {
  display: inline-block;
  padding: 3px 12px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .3px;
  transition: background-color .25s ease, color .25s ease;
}
.badge-active { background: var(--green-bg); color: #fff; }
.badge-inactive { background: var(--grey-bg); color: #4b5563; }

.progress-cell { min-width: 160px; }
.progress-track {
  height: 6px;
  border-radius: 999px;
  background: #dbe4f7;
  overflow: hidden;
  margin-bottom: 4px;
}
.progress-fill { height: 100%; background: var(--blue); border-radius: 999px; transition: width .4s ease; }
.progress-text { font-size: 12px; color: var(--text-light); }

.actions-cell { text-align: right; position: relative; }
.icon-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-light);
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
  transition: background-color .15s ease, transform .1s ease;
}
.icon-btn:hover { background: #f1f1f1; }
.icon-btn:active { transform: scale(.9); }

.dropdown-menu {
  /* position: fixed (не absolute) - чтобы меню не обрезалось overflow:hidden
     родительской .card, когда открывается у нижних строк таблицы. Точные
     top/left проставляются из JS при открытии (см. app.js). */
  position: fixed;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, .12);
  min-width: 180px;
  z-index: 30;
  padding: 6px;
  display: block;
  opacity: 0;
  transform: translateY(-4px) scale(.98);
  pointer-events: none;
  transition: opacity .15s ease, transform .15s ease;
}
.dropdown-menu.open { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  border: none;
  background: none;
  font-size: 14px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--text);
  transition: background-color .12s ease;
}
.dropdown-menu button:hover { background: #f3f4f6; }
.dropdown-menu button.danger { color: var(--danger); }

.table-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  font-size: 13px;
  color: var(--text-light);
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}
.pager { display: flex; gap: 6px; }
.pager button {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 6px;
  width: 28px;
  height: 28px;
  cursor: pointer;
  transition: background-color .15s ease, transform .1s ease;
}
.pager button:active:not(:disabled) { transform: scale(.9); }
.pager button:disabled { opacity: .4; cursor: not-allowed; }

/* ---- Modal shell ---- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  display: none;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 100;
}
.overlay.open { display: flex; animation: overlay-fade-in .18s ease; }
@keyframes overlay-fade-in { from { background: rgba(15, 23, 42, 0); } to { background: rgba(15, 23, 42, .45); } }
@keyframes modal-pop-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }

/* Активация/деактивация и ссылка могут открываться поверх уже открытого
   конструктора теста — держим их выше в стеке независимо от порядка в DOM. */
#overlayConfirm, #overlayLink { z-index: 110; }

.modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 620px;
  padding: 20px 22px;
  box-shadow: 0 20px 60px rgba(16, 24, 40, .25);
  animation: modal-pop-in .2s ease;
}
.modal.modal-wide { max-width: 720px; }
.modal.modal-small { max-width: 400px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.modal-header h2 { font-size: 17px; margin: 0; font-weight: 700; }
.modal-close { border: none; background: none; font-size: 20px; cursor: pointer; color: var(--text-light); line-height: 1; }

.modal-toprow {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.modal-toprow input[type=text] {
  flex: 1;
  min-width: 160px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
}
.modal-toprow input[type=text]:focus { outline: 2px solid #cddcfb; border-color: var(--blue); }

.spacer-grow { flex: 1; }

.answers-flag {
  font-size: 12px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 999px;
  transition: background-color .25s ease, color .25s ease;
}
.answers-flag.incomplete { background: var(--warn-bg); color: var(--warn-text); }
.answers-flag.complete { background: #dcfce7; color: #15803d; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-bottom: 14px;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
}
.tab-btn:hover { border-color: #c7cedb; }
.tab-btn:active { transform: scale(.96); }
.tab-btn.active { background: var(--blue); border-color: var(--blue); color: #fff; }

.section-title { font-weight: 700; font-size: 14px; margin: 4px 0 2px; }
.section-hint { font-size: 12px; color: var(--text-light); margin-bottom: 12px; }

.subject-pills {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}
.subject-pills-label { font-size: 13px; color: var(--text-light); margin-right: 2px; white-space: nowrap; }
.subject-pill {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
  font-weight: 600;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease, transform .1s ease;
}
.subject-pill:hover { border-color: #c7cedb; }
.subject-pill:active { transform: scale(.96); }
.subject-pill.active { background: var(--blue); border-color: var(--blue); color: #fff; }

.q-list { display: flex; flex-direction: column; gap: 10px; max-height: 46vh; overflow-y: auto; padding-right: 4px; }
.q-row { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.q-num { width: 34px; color: var(--text-light); flex-shrink: 0; }
.opt-group { display: flex; gap: 6px; }
.opt-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  transition: background-color .18s ease, border-color .18s ease, color .18s ease, transform .1s ease;
}
.opt-btn:hover { border-color: #c7d2e6; }
.opt-btn:active { transform: scale(.9); }
.opt-btn.selected { background: var(--blue); border-color: var(--blue); color: #fff; transform: scale(1.05); }
.opt-btn.selected.multi { background: #16a34a; border-color: #16a34a; }
.subpoint-label { color: var(--text-light); font-size: 13px; margin: 0 2px 0 6px; }
.multi-counter { font-size: 12px; color: var(--text-light); width: 30px; text-align: center; flex-shrink: 0; }

.section-divider { border: none; border-top: 1px dashed var(--border); margin: 14px 0; }

.btn-icon-delete {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-light);
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  transition: background-color .15s ease, border-color .15s ease, color .15s ease;
}
.btn-icon-delete:hover { background: #fef2f2; border-color: #fca5a5; color: #dc2626; }

.general-add-row { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.general-add-row select {
  flex-shrink: 0;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
  background: #fff;
}
.general-add-row .btn { flex-shrink: 0; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.autosave-hint { font-size: 12px; color: var(--text-light); }

.field-label { font-size: 13px; color: var(--text-light); margin-bottom: 6px; display: block; }
.confirm-text { font-size: 14px; color: var(--text); line-height: 1.5; margin-bottom: 18px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

.link-box {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  margin-bottom: 16px;
}
.link-box input {
  flex: 1;
  border: none;
  font-size: 13px;
  color: var(--text);
  background: none;
}
.link-box input:focus { outline: none; }

.qr-wrap { display: flex; justify-content: center; margin-bottom: 16px; }
.qr-wrap img { border: 1px solid var(--border); border-radius: 10px; padding: 8px; width: 220px; height: 220px; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2937;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease;
}
.toast.show { opacity: 1; }

.empty-state { padding: 60px 20px; text-align: center; color: var(--text-light); }

.new-test-row { display:flex; gap:10px; margin-bottom: 14px; }
.new-test-row input { flex:1; padding: 9px 12px; border:1px solid var(--border); border-radius:8px; font-size:14px; }

.kind-choice { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.kind-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
  gap: 3px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  padding: 10px 14px;
  cursor: pointer;
  transition: border-color .15s ease, background-color .15s ease;
}
.kind-option:hover { border-color: #c7cedb; }
.kind-option.active { border-color: var(--blue); background: var(--blue-bg); }
.kind-option-title { font-size: 14px; font-weight: 700; color: var(--text); }
.kind-option.active .kind-option-title { color: var(--blue); }
.kind-option-desc { font-size: 12px; color: var(--text-light); }

.kind-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--bg-alt, #f7f8fa);
  font-size: 12.5px;
  color: var(--text-light);
}

.kind-tag {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  vertical-align: middle;
}
.kind-tag-ent { background: var(--blue-bg); color: var(--blue); }
.kind-tag-general { background: #f3e8ff; color: #7e22ce; }
.kind-tag-subject { background: #fff7ed; color: #c2610a; }

/* ===================== Левый сайдбар ===================== */
.app-shell {
  display: flex;
  align-items: stretch;
  min-height: 100vh;
}

.sidebar {
  flex: 0 0 240px;
  width: 240px;
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 8px 20px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  height: 42px;
  width: auto;
  border-radius: 8px;
  flex-shrink: 0;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
  transition: background-color .12s ease, color .12s ease;
}

.sidebar-link svg {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  opacity: .75;
}

.sidebar-link:hover { background: var(--blue-bg); }

.sidebar-link.active {
  background: var(--blue-bg);
  color: var(--blue-dark);
}
.sidebar-link.active svg { opacity: 1; }

.sidebar .page {
  flex: 1 1 auto;
}

/* Внутри app-shell .page больше не центрируется по всей ширине экрана
   (margin:auto) - занимает оставшееся место рядом с сайдбаром, но
   сохраняет тот же max-width, чтобы контент не растягивался на весь
   широкий монитор. */
.app-shell > .page {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    position: static;
    height: auto;
    width: 100%;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    padding: 12px 14px;
    overflow-x: auto;
  }
  .sidebar-brand { border-bottom: none; padding: 0 12px 0 0; margin: 0; }
  .sidebar-nav { flex-direction: row; gap: 4px; }
  .sidebar-link span { display: none; }
  .sidebar-link { padding: 10px; }
}

.sidebar-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  margin-left: auto;
}
