:root {
  --bg: #f1f4f7;
  --card: #ffffff;
  --ink: #17222f;
  --text: #2b3644;
  --muted: #64707d;
  --pine: #2f6b52;
  --pine-2: #27583f;
  --pine-soft: #e4efe9;
  --clay: #c46a3c;
  --clay-2: #a5542b;
  --clay-soft: #f9ede4;
  --blue: #3d6a9e;
  --blue-soft: #e6eef7;
  --amber: #9a6b1f;
  --amber-soft: #f7efdd;
  --plum: #7d5285;
  --plum-soft: #f1e9f3;
  --teal: #2b7280;
  --teal-soft: #e2f0f2;
  --line: #e3e8ee;
  --line-2: #d2d9e1;
  --shadow: 0 1px 2px rgba(23, 34, 47, 0.05), 0 6px 20px rgba(23, 34, 47, 0.05);
  --shadow-lift: 0 2px 6px rgba(23, 34, 47, 0.07), 0 14px 34px rgba(23, 34, 47, 0.1);
  --focus: #2f6b52;
  --danger: #a83a2c;
  --ok: #2f6b52;
  --radius: 16px;
  --nav: 240px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 "Segoe UI Variable Text", "Segoe UI", Inter, Roboto, system-ui, -apple-system, sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--pine);
}

#app {
  min-height: 100vh;
}

/* ---- Шапка ---- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--pine);
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: 0.02em;
}

.brand h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.brand span {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
}

.top-actions,
.row,
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* ---- Кнопки ---- */

.btn {
  border: 1px solid var(--line-2);
  background: var(--card);
  border-radius: 12px;
  padding: 9px 14px;
  min-height: 40px;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.btn:hover {
  border-color: var(--pine);
  box-shadow: var(--shadow);
}

.btn-primary {
  background: var(--pine);
  border-color: var(--pine);
  color: #fff;
}

.btn-primary:hover {
  background: var(--pine-2);
  border-color: var(--pine-2);
}

.btn-clay {
  background: var(--clay);
  border-color: var(--clay);
  color: #fff;
}

.btn-clay:hover {
  background: var(--clay-2);
  border-color: var(--clay-2);
}

.btn-ghost {
  background: transparent;
}

.btn-danger {
  color: var(--danger);
  border-color: #e5c4bd;
  background: #fff;
}

.btn-danger:hover {
  border-color: var(--danger);
}

/* ---- Каркас страницы ---- */

.wrap {
  width: min(1240px, calc(100% - 36px));
  margin: 0 auto;
  padding: 26px 0 72px;
}

.main-tabs {
  margin-bottom: 18px;
}

.main-tabs .btn {
  border-radius: 999px;
  padding: 9px 20px;
}

.hero {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  margin-bottom: 20px;
}

.hero h2,
.panel h2,
.section-title {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--ink);
}

.muted {
  color: var(--muted);
}

.search {
  width: min(420px, 100%);
  border: 1px solid var(--line-2);
  background: var(--card);
  border-radius: 12px;
  padding: 10px 14px;
  outline: none;
  box-shadow: var(--shadow);
}

.search:focus,
.control:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(47, 107, 82, 0.15);
}

/* ---- Плитки детей ---- */

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.child-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  text-align: left;
  width: 100%;
  padding: 18px;
  justify-content: space-between;
  transition: box-shadow 0.15s, transform 0.15s, border-color 0.15s;
}

.child-card:hover {
  box-shadow: var(--shadow-lift);
  transform: translateY(-2px);
  border-color: #c6d4cb;
}

.child-head {
  display: flex;
  gap: 14px;
  align-items: center;
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  border-radius: 16px;
  font-size: 19px;
  font-weight: 700;
  color: #fff;
}

.avatar.a1 { background: #4d7d63; }
.avatar.a2 { background: #5b7ea6; }
.avatar.a3 { background: #b07a4a; }
.avatar.a4 { background: #8a6a9d; }
.avatar.a5 { background: #4d8391; }
.avatar.a6 { background: #a4685e; }

.child-card h3 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  color: var(--ink);
  line-height: 1.3;
}

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  color: var(--muted);
  font-size: 13px;
  align-items: center;
}

.pill {
  background: var(--pine-soft);
  color: var(--pine-2);
  border-radius: 999px;
  padding: 2px 10px;
  font-weight: 600;
}

.empty {
  text-align: center;
  padding: 56px 20px;
}

.empty h2 {
  font-size: 20px;
  color: var(--ink);
}

/* ---- Панели ---- */

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

/* ---- Плитки-кнопки создания карт ---- */

.tile-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
  gap: 10px;
  margin: 10px 0 4px;
}

.tile-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 12px 14px;
  border: 1px solid var(--line-2);
  border-radius: 14px;
  background: var(--card);
  text-align: left;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s, background 0.15s;
}

.tile-btn:hover {
  border-color: var(--pine);
  box-shadow: var(--shadow-lift);
  transform: translateY(-2px);
}

.tile-btn .tile-num {
  font-size: 21px;
  font-weight: 750;
  color: var(--ink);
  line-height: 1.15;
}

.tile-btn .tile-cap {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.3;
}

.tile-btn.vpf .tile-num { color: var(--teal); }
.tile-btn.mrr .tile-num { color: var(--blue); }

/* ---- Плитки карт ---- */

.list {
  display: grid;
  gap: 10px;
}

.map-item,
.map-tile {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  border-left: 4px solid var(--line-2);
  transition: box-shadow 0.15s, border-color 0.15s;
}

.map-item:hover,
.map-tile:hover {
  box-shadow: var(--shadow-lift);
}

.map-tile.t-speech { border-left-color: var(--pine); }
.map-tile.t-vpf { border-left-color: var(--teal); }
.map-tile.t-mrr { border-left-color: var(--blue); }

.map-tile-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.map-tile-main b {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.35;
}

.badge {
  display: inline-block;
  align-self: flex-start;
  border-radius: 999px;
  padding: 1px 9px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge.b-speech { background: var(--pine-soft); color: var(--pine-2); }
.badge.b-vpf { background: var(--teal-soft); color: var(--teal); }
.badge.b-mrr { background: var(--blue-soft); color: var(--blue); }

/* ---- Редактор ---- */

.editor {
  display: grid;
  grid-template-columns: var(--nav) minmax(0, 1fr);
  min-height: calc(100vh - 62px);
}

.editor-main {
  min-width: 0;
  padding: 20px 26px 90px;
}

.side {
  position: sticky;
  top: 62px;
  height: calc(100vh - 62px);
  overflow: auto;
  padding: 14px 10px;
  border-right: 1px solid var(--line);
  background: #fbfcfd;
}

.side button.nav-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text);
  font-weight: 550;
  font-size: 14px;
  margin-bottom: 2px;
}

.side button.nav-item.active {
  background: var(--pine);
  color: #fff;
}

.side button.nav-item:hover:not(.active) {
  background: #edf1f4;
  color: var(--ink);
}

.editor-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 16px;
}

.editor-head h2 {
  margin: 0;
  font-size: 20px;
  color: var(--ink);
}

.save-state {
  font-size: 13px;
  color: var(--ok);
  background: var(--pine-soft);
  border-radius: 999px;
  padding: 4px 12px;
  font-weight: 600;
}

.save-state.is-error {
  color: var(--danger);
  background: #f8e7e3;
}

.save-error {
  position: sticky;
  top: 0;
  z-index: 50;
  padding: 10px 16px;
  background: var(--danger);
  color: #fff;
  font-size: 14px;
  line-height: 1.4;
}

/* ---- Поля ---- */

.fields {
  display: grid;
  gap: 14px;
}

.fields.two {
  grid-template-columns: 1fr 1fr;
}

.fields.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.field-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}

.control,
textarea.control {
  width: 100%;
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 11px;
  padding: 9px 11px;
  outline: none;
  color: var(--ink);
}

.control:disabled {
  background: #f0f3f6;
  color: var(--muted);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  border: 1px solid var(--line-2);
  background: #f6f8fa;
  border-radius: 999px;
  padding: 4px 12px;
  min-height: 32px;
  font-size: 13px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.chip:hover {
  border-color: var(--pine);
}

.chip.active {
  background: var(--pine);
  border-color: var(--pine);
  color: #fff;
}

.hint {
  font-size: 13.5px;
  color: var(--muted);
  margin: 0 0 12px;
  line-height: 1.45;
}

/* ---- Таблицы ---- */

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 14px;
  margin: 8px 0;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 14px;
}

table.data th,
table.data td {
  border-bottom: 1px solid var(--line);
  border-right: 1px solid var(--line);
  padding: 8px 10px;
  vertical-align: middle;
}

table.data th {
  background: #f4f6f8;
  font-weight: 650;
  text-align: left;
  color: var(--ink);
  font-size: 13px;
  letter-spacing: 0.01em;
}

table.data tr:last-child td {
  border-bottom: 0;
}

table.data td:last-child,
table.data th:last-child {
  border-right: 0;
}

table.data input {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 6px 4px;
  outline: none;
}

table.data input.selected,
.control.selected {
  background: #e4efe9;
  box-shadow: inset 0 0 0 2px var(--focus);
  border-radius: 6px;
}

@media print {
  table.data input.selected,
  .control.selected {
    background: transparent;
    box-shadow: none;
  }
}

.sound-letter {
  font-weight: 700;
  background: transparent;
  border: 0;
  color: var(--pine-2);
  min-width: 42px;
}

/* ---- Баллы ---- */

.score-grid {
  display: grid;
  gap: 10px;
}

.score-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  background: #fff;
}

.score-card h3 {
  margin: 0 0 8px;
  font-size: 15.5px;
  color: var(--ink);
}

.score-opts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.score-opts label {
  display: flex;
  gap: 6px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  background: #f6f8fa;
  cursor: pointer;
}

.vpf-opts {
  display: flex;
  gap: 12px;
  white-space: nowrap;
}

.vpf-opts label {
  cursor: pointer;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

/* ---- Уведомления ---- */

.backup-note {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 12px 24px 0;
  padding: 10px 16px;
  background: var(--amber-soft);
  border: 1px solid #ead9b8;
  border-radius: 14px;
  color: var(--amber);
  font-size: 14px;
}

.notice {
  background: var(--pine-soft);
  border: 1px solid #cbe2d4;
  color: var(--pine-2);
  border-radius: 14px;
  padding: 12px 14px;
  margin-top: 12px;
  font-size: 14.5px;
}

.hidden-file {
  display: none;
}

.span-2 {
  grid-column: 1 / -1;
}

.cell-chips {
  display: flex;
  align-items: center;
  gap: 4px;
}

.cell-chips .chip {
  min-height: 26px;
  padding: 2px 9px;
}

.field .mark {
  margin-top: 4px;
}

.mark .chips {
  flex-wrap: nowrap;
}

.btn-file.is-on {
  border-color: var(--pine);
  color: var(--pine-2);
  background: var(--pine-soft);
}

.btn-file.is-warn {
  border-color: var(--clay);
  color: var(--clay-2);
  background: var(--clay-soft);
}

.file-note {
  background: var(--pine-soft);
  border-color: #cbe2d4;
  color: var(--pine-2);
}

.cloud-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(560px, 100%);
}

.cloud-form .fields.two {
  grid-template-columns: 1.4fr 1fr;
}

.cloud-error {
  color: var(--danger);
  font-size: 13.5px;
}

/* ---- Экран авторизации ---- */

.gate-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.gate {
  width: min(400px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: var(--shadow-lift);
  padding: 30px 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gate .brand-mark {
  width: 52px;
  height: 52px;
  border-radius: 16px;
  font-size: 22px;
}

.gate h1 {
  margin: 0;
  font-size: 22px;
  color: var(--ink);
  letter-spacing: -0.015em;
}

.gate-fields {
  display: grid;
  gap: 12px;
}

.gate .control {
  padding: 11px 13px;
}

.motor-bar {
  margin-bottom: 8px;
}

/* ---- Адаптив ---- */

@media (max-width: 900px) {
  .wrap {
    width: calc(100% - 24px);
    padding-top: 18px;
  }

  .topbar {
    padding: 10px 14px;
    gap: 10px;
    flex-wrap: wrap;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    font-size: 15px;
  }

  .brand h1 {
    font-size: 16px;
  }

  .brand span {
    font-size: 11.5px;
  }

  .top-actions .btn {
    min-height: 36px;
    padding: 7px 11px;
    font-size: 13px;
  }

  .hero {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin-bottom: 16px;
  }

  .editor {
    grid-template-columns: 1fr;
    min-height: 0;
  }

  .side {
    position: sticky;
    top: 56px;
    z-index: 10;
    height: auto;
    display: flex;
    overflow-x: auto;
    gap: 6px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(8px);
    padding: 8px 10px;
    -webkit-overflow-scrolling: touch;
  }

  .side button.nav-item {
    white-space: nowrap;
    width: auto;
    flex: none;
    padding: 8px 12px;
    font-size: 13.5px;
  }

  .editor-main {
    padding: 14px 14px 70px;
  }

  .fields.two,
  .fields.three {
    grid-template-columns: 1fr;
  }

  .editor-head,
  .map-item,
  .map-tile {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .map-item .toolbar,
  .map-tile .toolbar {
    justify-content: flex-start;
  }

  .tile-row {
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  }

  .child-card {
    padding: 14px;
  }

  .backup-note {
    margin: 10px 12px 0;
  }
}

@media (max-width: 560px) {
  html,
  body {
    font-size: 15px;
  }

  .grid-cards {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .child-head {
    gap: 12px;
  }

  .avatar {
    width: 46px;
    height: 46px;
    font-size: 17px;
    border-radius: 14px;
  }

  .hero h2,
  .panel h2,
  .section-title {
    font-size: 19px;
  }

  /* iOS не зумит страницу, если шрифт поля не меньше 16px */
  .control,
  textarea.control,
  .search,
  table.data input {
    font-size: 16px;
  }

  table.data {
    font-size: 15px;
  }

  .table-wrap {
    margin: 6px -14px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
  }

  .editor-main .table-wrap {
    margin: 6px 0;
  }

  .vpf-opts {
    gap: 12px;
  }

  .score-opts label,
  .chip {
    min-height: 38px;
  }

  .notice,
  .backup-note {
    font-size: 14px;
  }

  .map-tile-main b {
    font-size: 14.5px;
  }
}

@media (hover: none) {
  .btn,
  .chip,
  .tile-btn,
  .nav-item,
  .child-card,
  .map-tile {
    transition: none;
  }

  .btn,
  .chip {
    min-height: 40px;
  }
}

#print-root {
  display: none;
}

table.data tr.part-row td {
  padding-top: 2px;
  padding-bottom: 2px;
  color: var(--muted);
  font-size: 13.5px;
}

table.data tr.part-row input {
  font-size: 14px;
  color: var(--ink);
}

/* Таблица субтестов ВПФ: блоки субтестов (rowspan), сплошная сетка, ответы шире субтеста */
table.data.vpf-table {
  table-layout: fixed;
  min-width: 700px;
}

table.data.vpf-table th:nth-child(1) {
  width: 40px;
}

table.data.vpf-table th:nth-child(2) {
  width: 24%;
}

table.data.vpf-table th:nth-child(3) {
  width: 34%;
}

table.data.vpf-table th:nth-child(4) {
  width: 132px;
}

table.data.vpf-table .slot-cell {
  padding: 4px 10px;
}

/* формулировка критерия по методичке, вписывается автоматически после выставления балла */
table.data.vpf-table .crit-text {
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.35;
  color: var(--teal);
}

/* строки-разделы бланка (1. Личностная сфера и т.п.) */
table.data.vpf-table tr.vpf-section td {
  background: #edf3f5;
  font-weight: 650;
  font-size: 13px;
  letter-spacing: 0.01em;
  color: var(--ink);
}

table.data.vpf-table .slot-label {
  display: block;
  font-size: 12.5px;
  margin: 3px 0 2px;
}

/* у ячейки слота в последней колонке блока своя правая граница — линия Балл/Примечание не должна рваться */
table.data.vpf-table tr.part-row td:last-child {
  border-right: 1px solid var(--line);
}

