/* ==================================================================
   Протокол тестирования по 3 модулю — styles
   Aesthetic: «module 3» — academic-clinical, calm & refined. Royal violet
   (from the school logo) on warm ivory ground; eucalyptus = positive,
   wine-rose = negative, regal gold = neutral. Domain colors (barometer
   floors red/blue/yellow, meridian ЯН/ИНЬ blue/pink) kept distinct.
   Display: Spectral (literary serif). Body/UI: Manrope (modern grotesque).
   Token names like --teal/--sage/--clay are legacy aliases of the brand
   palette (see :root) — values changed, names kept to avoid churn.
   ================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Manrope:wght@400;500;600;700;800&family=Spectral:ital,wght@0,400;0,500;0,600;1,500&display=swap');

/* ---------------------------------------------------------------- *
   Design tokens
   ---------------------------------------------------------------- */
:root {
  /* ===== Палитра 3 модуля (снято с логотипа школы + курсовой графики) ===== */
  --brand:        #5b2d82;   /* роял-фиолетовый — «Модуль #3» */
  --brand-d:      #46215f;   /* баклажан — заголовки / ховер */
  --brand-2:      #7a4ea3;   /* светлее — энергия / фокус */
  --mauve:        #856188;   /* пыльная мальва логотипа — мягкие акценты */
  --brand-l:      #efe6f3;   /* фиолетовый тинт — фон выбранного */
  --brand-l2:     #e4d6ee;   /* глубже — рамки выбранного */

  /* ground — тёплая слоновая кость под кремовой «Ш» */
  --paper:        #f3eee7;
  --paper-2:      #ebe3d9;
  --surface:      #fffdf9;   /* card */
  --surface-2:    #f8f2ec;

  /* ink — баклажан-графит */
  --ink:          #29232f;
  --ink-soft:     #574e5e;
  --ink-faint:    #8c8392;
  --line:         #e8dee2;   /* hairline (тёплый лилово-серый) */
  --line-2:       #d8ccd2;

  /* ===== Семантика (доменный смысл) ===== */
  --positive:     #5e8c63;   /* ресурс / «да» — эвкалиптовый (комплемент к фиолетовому) */
  --positive-l:   #e6efe4;
  --negative:     #a8475f;   /* травма / негатив — винно-розовый (в фиолетовой семье) */
  --negative-l:   #f5e3e8;
  --neutral:      #b8923f;   /* «по умолчанию» — регальный золотой */
  --neutral-l:    #f1e7cf;

  --male:         #4a6db0;   /* Янь (мужская) */
  --male-bg:      #e7edf7;
  --female:       #a85291;   /* Инь (женская) */
  --female-bg:    #f6e7f0;
  --link:         #2f7f78;   /* барометр: связь травма↔ресурс (отдельный от бренда тон) */
  --link-bg:      #e1eeec;

  --focus:        var(--brand-2);

  /* ===== Легаси-псевдонимы: существующие правила ссылаются на эти имена ===== */
  --teal:   var(--brand);     --teal-d: var(--brand-d);  --teal-l: var(--brand-l);
  --sage:   var(--positive);  --sage-l: var(--positive-l);
  --clay:   var(--negative);  --clay-l: var(--negative-l);
  --gold:   var(--neutral);   --gold-l: var(--neutral-l);

  /* typography scale */
  --font-display: 'Spectral', Georgia, 'Times New Roman', serif;
  --font-body:    'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --fs-xs:  0.78rem;
  --fs-sm:  0.875rem;
  --fs-base: 1rem;
  --fs-lg:  1.18rem;
  --fs-xl:  1.5rem;
  --fs-2xl: 2rem;
  --lh-prose: 1.72;

  /* spacing */
  --sp-1: 0.25rem;
  --sp-2: 0.5rem;
  --sp-3: 0.75rem;
  --sp-4: 1rem;
  --sp-5: 1.5rem;
  --sp-6: 2rem;
  --sp-8: 3rem;

  /* radii + shadow */
  --r-sm: 7px;
  --r-md: 12px;
  --r-lg: 18px;
  --shadow-sm: 0 1px 2px rgba(41, 35, 47, .07), 0 1px 3px rgba(41, 35, 47, .06);
  --shadow-md: 0 6px 20px rgba(70, 33, 95, .10);
  --shadow-lg: 0 16px 44px rgba(70, 33, 95, .16);

  --maxw-prose: 68ch;
  --maxw-app: 1480px;   /* shared right boundary: header content + layout container */
  --gutter: clamp(var(--sp-4), 4vw, var(--sp-8)); /* horizontal padding for both */
  --toc-w: 280px;       /* navigation column width */
  --header-h: 68px;
  --transition: 160ms cubic-bezier(.4, 0, .2, 1);
}

/* ---------------------------------------------------------------- *
   Reset / base
   ---------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--fs-base);
  color: var(--ink);
  background:
    radial-gradient(1150px 640px at 88% -12%, var(--brand-l) 0%, transparent 56%),
    radial-gradient(840px 500px at -8% 108%, #efe6ee 0%, transparent 52%),
    var(--paper);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  line-height: 1.55;
}

/* Бренд-подложка: крупный, едва различимый глобус из логотипа (как на курсовых страницах). */
body::before {
  content: "";
  position: fixed;
  z-index: -1;
  right: -70px;
  bottom: -80px;
  width: 620px;
  height: 620px;
  background: url("images/favicon-512.png") center / contain no-repeat;
  opacity: .06;
  pointer-events: none;
}
/* На узких экранах глобус не нужен (мешал бы контенту). */
@media (max-width: 1100px) {
  body::before { display: none; }
}

h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; line-height: 1.18; margin: 0; letter-spacing: -.005em; }

.is-hidden { display: none !important; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

/* ---------------------------------------------------------------- *
   Header
   ---------------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
  background: rgba(246, 243, 236, .82);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
/* Inner content shares the layout's max-width + gutter, so the actions' right edge
   lines up exactly with the TOC's right edge below. The bar itself stays full-bleed. */
.app-header-inner {
  height: 100%;
  max-width: var(--maxw-app);
  margin: 0 auto;
  padding: 0 var(--gutter);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
}

/* Бренд: логотип школы (глобус с «III») + название протокола. */
.app-brand { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.app-logo {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: block;
  box-shadow: var(--shadow-sm);
}
.app-title { font-size: var(--fs-xl); letter-spacing: -.01em; color: var(--brand-d); cursor: pointer; user-select: none; }
.app-title:hover { color: var(--brand); }

.app-actions { display: flex; gap: var(--sp-2); flex-wrap: wrap; }

.btn {
  font-family: var(--font-body);
  font-size: var(--fs-sm);
  font-weight: 600;
  padding: .55rem 1.05rem;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform var(--transition), background var(--transition),
              box-shadow var(--transition), border-color var(--transition);
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: linear-gradient(180deg, var(--brand-2) 0%, var(--brand) 72%); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: linear-gradient(180deg, var(--brand) 0%, var(--brand-d) 100%); box-shadow: var(--shadow-md); transform: translateY(-1px); }

.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line-2); }
.btn-ghost:hover { background: var(--surface); color: var(--ink); border-color: var(--ink-faint); }

.btn-lg { font-size: var(--fs-lg); padding: .8rem 2rem; }
.btn:disabled { opacity: .65; cursor: progress; }

/* «Получить результат» в конце чек-листа */
.result-cta { display: flex; justify-content: center; padding-top: var(--sp-2); }
.result-cta .btn { min-width: 16rem; }

/* ---------------------------------------------------------------- *
   Layout: content + sticky TOC
   ---------------------------------------------------------------- */
.screen { display: block; }

.layout {
  display: grid;
  /* Wide content column + fixed nav column. Same max-width + gutter as the header,
     so the nav's right edge aligns with the header actions' right edge. */
  grid-template-columns: minmax(0, 1fr) var(--toc-w);
  gap: clamp(var(--sp-5), 4vw, var(--sp-8));
  max-width: var(--maxw-app);
  margin: 0 auto;
  padding: clamp(var(--sp-5), 4vw, var(--sp-8)) var(--gutter) var(--sp-8);
  align-items: start;
}

.content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: var(--sp-6);
}

/* ---------------------------------------------------------------- *
   TOC
   ---------------------------------------------------------------- */
.toc {
  position: sticky;
  top: calc(var(--header-h) + var(--sp-4));
  align-self: start;
  max-height: calc(100vh - var(--header-h) - var(--sp-6));
  overflow: auto;
}
.toc-details {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.toc-summary {
  list-style: none;
  cursor: pointer;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: var(--fs-sm);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--teal-d);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.toc-summary::-webkit-details-marker { display: none; }
.toc-chev { transition: transform var(--transition); color: var(--ink-faint); }
.toc-details[open] .toc-chev { transform: rotate(180deg); }

.toc-nav { display: flex; flex-direction: column; padding: var(--sp-2); }
.toc-link {
  display: block;
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  text-decoration: none;
  padding: .4rem .6rem;
  border-radius: var(--r-sm);
  border-left: 2px solid transparent;
  line-height: 1.3;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.toc-top { font-weight: 600; color: var(--ink); }
.toc-sub { padding-left: 1.25rem; font-size: var(--fs-xs); }
.toc-link:hover { background: var(--surface-2); color: var(--teal-d); }
.toc-link.is-current {
  background: var(--teal-l);
  color: var(--teal-d);
  border-left-color: var(--teal);
  font-weight: 600;
}
.toc-empty { display: block; padding: var(--sp-3); color: var(--ink-faint); font-size: var(--fs-sm); }

/* ---------------------------------------------------------------- *
   Session card (старт + финал) + шкала стресса
   ---------------------------------------------------------------- */
.session-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  scroll-margin-top: calc(var(--header-h) + var(--sp-4));
}
.session-summary {
  list-style: none; cursor: pointer;
  font-family: var(--font-display); font-weight: 600; font-size: var(--fs-lg);
  color: var(--teal-d);
  padding: var(--sp-4) var(--sp-5);
  display: flex; align-items: center; justify-content: space-between;
  border-top: 3px solid var(--teal);
}
.session-summary::-webkit-details-marker { display: none; }
.session-details[open] .toc-chev { transform: rotate(180deg); }
.session-body { padding: var(--sp-4) var(--sp-5) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-5); }

/* Галочки памяти (внести / вынести) */
.memory-card { border-top: 3px solid var(--ink-faint); }
.memory-card.is-on { border-color: var(--teal); }
.memory-toggle {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5); cursor: pointer;
}
.memory-toggle input { accent-color: var(--teal); width: 1.25rem; height: 1.25rem; flex: none; cursor: pointer; }
.memory-label { font-family: var(--font-display); font-weight: 600; font-size: var(--fs-lg); color: var(--ink); }
.memory-card.is-on .memory-label { color: var(--teal-d); }
.text-area { max-width: none; width: 100%; resize: vertical; font-family: var(--font-body); line-height: 1.5; }

.stress-scale { display: flex; flex-wrap: wrap; gap: var(--sp-2); }
.stress-btn {
  font-family: var(--font-body); font-weight: 700; font-size: var(--fs-base);
  min-width: 2.4rem; height: 2.4rem; padding: 0 .4rem;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink-soft); cursor: pointer;
  transition: transform var(--transition), background var(--transition), color var(--transition), border-color var(--transition);
}
.stress-btn:hover { border-color: var(--teal); color: var(--teal-d); transform: translateY(-1px); }
.stress-btn.is-selected { background: var(--teal); color: #fff; border-color: var(--teal); box-shadow: var(--shadow-sm); }

/* Финал-карта */
.session-final { margin-top: var(--sp-5); }
.session-final-head { padding: var(--sp-4) var(--sp-5) var(--sp-2); border-top: 3px solid var(--gold); }
.ses-block { display: flex; flex-direction: column; gap: var(--sp-3); padding-top: var(--sp-4); border-top: 1px dashed var(--line); }
.ses-block:first-of-type { border-top: none; padding-top: 0; }
.ses-conditional { display: flex; flex-direction: column; gap: var(--sp-3); padding-left: var(--sp-4); border-left: 2px solid var(--line); }
.ses-conditional[hidden] { display: none; }
.yn-group { display: flex; gap: var(--sp-2); }
.yn-btn {
  font-family: var(--font-body); font-weight: 600; font-size: var(--fs-sm);
  padding: .5rem 1.2rem; border-radius: 999px; border: 1px solid var(--line-2);
  background: var(--surface); color: var(--ink-soft); cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.yn-btn:hover { border-color: var(--teal); color: var(--teal-d); }
.yn-btn.is-selected { background: var(--teal); color: #fff; border-color: var(--teal); }
.time-field { display: flex; gap: var(--sp-2); flex-wrap: wrap; align-items: center; }
.num-input { max-width: 8rem; }
.select-input {
  font-family: var(--font-body); font-size: var(--fs-base); color: var(--ink);
  padding: .55rem .8rem; border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--surface); cursor: pointer;
}
.select-input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(122, 78, 163, .20); }
.inst-checks { display: flex; flex-direction: column; gap: var(--sp-3); }
.inst-row { display: flex; flex-direction: column; gap: var(--sp-2); }
.inst-content {
  padding: var(--sp-3) var(--sp-4);
  margin-left: var(--sp-3);
  border-left: 2px solid var(--sage);
  background: var(--surface-2);
  border-radius: var(--r-sm);
}
.inst-content[hidden] { display: none; }
/* Справочные списки в «Что ещё необходимо» */
.corr-group + .corr-group { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--line); }
.corr-group-title { font-size: var(--fs-base); color: var(--ink); margin-bottom: var(--sp-2); }
.res-item + .res-item { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--line); }
/* Чип «№ N» в раскрытых списках финала не должен прилипать к блоку текста снизу. */
.inst-content .chips, .res-item .chips { margin-bottom: var(--sp-3); }
.ses-date { font-size: var(--fs-sm); color: var(--teal-d); font-weight: 600; margin: 0; }
.ses-date:empty { display: none; }
.ses-inline { max-width: 14rem; }
.stress-delta { margin: var(--sp-1) 0 0; font-size: var(--fs-base); color: var(--ink-soft); }
.stress-delta:empty { display: none; }
/* Запрос клиента вверху результата — тёплый (clay) акцент, не золотой как у финала. */
.session-request .session-final-head { border-top-color: var(--clay); }
.session-request .phase-kicker { color: var(--clay); }

/* ---------------------------------------------------------------- *
   Blocks (selection)
   ---------------------------------------------------------------- */
.block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  scroll-margin-top: calc(var(--header-h) + var(--sp-4));
}
.block-head {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
}
.block-1 .block-head { border-top: 3px solid var(--clay); }
.block-2 .block-head { border-top: 3px solid var(--teal); }
.block-3 .block-head { border-top: 3px solid var(--sage); }

.block-title { font-size: var(--fs-lg); color: var(--ink); letter-spacing: -.01em; }
.block-body { padding: var(--sp-4) var(--sp-5) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3); }

/* ---------------------------------------------------------------- *
   Block 1 — paths
   ---------------------------------------------------------------- */
.path {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition), background var(--transition);
}
.path.is-open { border-color: var(--clay); box-shadow: var(--shadow-sm); background: var(--surface-2); }
.path-head { margin: 0; padding: var(--sp-3) var(--sp-4); }
.path-body { padding: var(--sp-3) var(--sp-4) var(--sp-4); display: flex; flex-direction: column; gap: var(--sp-3); }
/* Nested block already gets top spacing from .path-body — avoid doubling it there. */
.path-body > .nested { padding-top: 0; }

.nested { display: flex; flex-direction: column; gap: var(--sp-4); padding: var(--sp-3) 0 0; }
.subfield { display: flex; flex-direction: column; gap: var(--sp-2); }

.field { display: flex; flex-direction: column; gap: var(--sp-2); }
.field-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.text-input {
  font-family: var(--font-body);
  font-size: var(--fs-base);
  color: var(--ink);
  padding: .6rem .8rem;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  max-width: 32rem;
}
.text-input:focus {
  outline: none;
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(122, 78, 163, .20);
}

/* ---------------------------------------------------------------- *
   Options (radio / checkbox)
   ---------------------------------------------------------------- */
.opts { display: flex; flex-direction: column; gap: var(--sp-2); }

.opt {
  display: flex;
  align-items: flex-start;
  gap: var(--sp-3);
  padding: .6rem .85rem;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
  line-height: 1.4;
}
.opt:not(.is-selected):hover { border-color: var(--brand); background: var(--surface-2); }
.opt.is-selected:hover { border-color: var(--brand-d); }
.opt input { margin-top: .15rem; accent-color: var(--teal); width: 1.05rem; height: 1.05rem; flex: none; cursor: pointer; }
.opt-label { color: var(--ink); }
.opt.is-selected {
  border-color: var(--teal);
  background: var(--teal-l);
  box-shadow: inset 3px 0 0 var(--teal);
}
.opt.is-selected .opt-label { color: var(--teal-d); font-weight: 600; }
/* Чекбоксы выбора наследуют ту же фиолетовую подсветку, что и радио (.opt.is-selected).
   Зелёный закреплён только за смыслом «позитив/ресурс» в результатах. */

/* Пункт-путь Блока 1 — заголовочная строка, как имена инструментов в Блоках 2/3:
   та же антиква (Spectral), чтобы главные строки-пункты были единообразны во всех блоках. */
.path-head.opt { font-weight: 600; }
.path-head .opt-label { font-family: var(--font-display); }
.hint { font-size: var(--fs-sm); color: var(--ink-soft); margin: 0 0 var(--sp-1); font-style: italic; }
.note {
  font-size: var(--fs-sm);
  color: var(--ink-soft);
  background: var(--gold-l);
  border-radius: var(--r-sm);
  padding: .5rem .75rem;
  margin: var(--sp-2) 0 0;
}
.note strong { color: var(--clay); }

/* number grid (essences) */
.num-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
  gap: var(--sp-2);
  max-width: 34rem;
}
.num-btn {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: var(--fs-base);
  aspect-ratio: 1;
  border: 1px solid var(--line-2);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-soft);
  cursor: pointer;
  transition: transform var(--transition), background var(--transition),
              color var(--transition), border-color var(--transition), box-shadow var(--transition);
}
.num-btn:hover { border-color: var(--teal); color: var(--teal-d); transform: translateY(-1px); }
.num-btn.is-selected { background: var(--teal); color: #fff; border-color: var(--teal); box-shadow: var(--shadow-md); }

/* ---------------------------------------------------------------- *
   Tools (block 2 / 3 cards)
   ---------------------------------------------------------------- */
.tool {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
  scroll-margin-top: calc(var(--header-h) + var(--sp-4));
}
.tool.is-on { border-color: var(--teal); box-shadow: var(--shadow-sm); }

.tool-toggle {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  cursor: pointer;
  flex-wrap: wrap;
}
.tool-toggle input { accent-color: var(--teal); width: 1.15rem; height: 1.15rem; flex: none; cursor: pointer; }
.tool-name { font-family: var(--font-display); font-weight: 600; font-size: var(--fs-base); color: var(--ink); flex: 1 1 auto; }
.tool-flag {
  font-size: var(--fs-xs);
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-faint);
  opacity: 0;
  transition: opacity var(--transition);
}
.tool.is-on .tool-flag { opacity: 1; color: var(--teal); }
/* Enabled but not yet completed — warn the therapist it will be skipped in the result. */
.tool.is-incomplete { border-color: var(--clay); }
.tool.is-on.is-incomplete .tool-flag--warn,
.tool.is-incomplete .tool-flag--warn { opacity: 1; color: var(--clay); font-weight: 700; }

.tool-body {
  padding: var(--sp-4) var(--sp-4) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  border-top: 1px dashed var(--line);
}

/* ================================================================
   RESULT PHASES (протокол: Проработка → Коррекция → Ресурс)
   ================================================================ */
.phase {
  display: flex; flex-direction: column; gap: var(--sp-5);
  scroll-margin-top: calc(var(--header-h) + var(--sp-4));
}
.phase-head { display: flex; flex-direction: column; gap: .15rem; padding-bottom: var(--sp-2); border-bottom: 2px solid var(--line); }
.phase-kicker { font-size: var(--fs-xs); font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--ink-faint); }
.phase-title { font-size: var(--fs-2xl); letter-spacing: -.01em; }
.phase-note { margin: var(--sp-2) 0 0; font-size: var(--fs-sm); color: var(--ink-soft); font-style: italic; max-width: var(--maxw-prose); }
.phase-body { display: flex; flex-direction: column; gap: var(--sp-6); }
.phase-neg .phase-title { color: var(--clay); }
.phase-neg .phase-head { border-bottom-color: var(--clay); }
.phase-corr .phase-title { color: var(--teal-d); }
.phase-corr .phase-head { border-bottom-color: var(--teal); }
.phase-pos .phase-title { color: var(--sage); }
.phase-pos .phase-head { border-bottom-color: var(--sage); }

/* ================================================================
   RESULT SCREEN
   ================================================================ */
.result-block {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  /* overflow visible — иначе тень-подъём «исходной пары»/«ресурса» внутри
     барометра обрезается краем блока. Углы шапки скруглены напрямую (ниже). */
  scroll-margin-top: calc(var(--header-h) + var(--sp-4));
}
.result-head {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface-2) 100%);
  border-radius: calc(var(--r-lg) - 1px) calc(var(--r-lg) - 1px) 0 0;
}
.result-kicker {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--clay);
  margin-bottom: .35rem;
}
.result-title { font-size: var(--fs-lg); color: var(--ink); letter-spacing: -.01em; }
.result-body { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-5); }

.sub-title { font-size: var(--fs-lg); color: var(--teal-d); margin-bottom: var(--sp-2); }

/* prose for long Russian texts */
.prose { max-width: var(--maxw-prose); color: var(--ink); }
.prose p { margin: 0 0 .85em; line-height: var(--lh-prose); }
.prose p:last-child { margin-bottom: 0; }
.muted { color: var(--ink-faint); }
.value-box {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--clay);
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-4);
  font-size: var(--fs-lg);
}

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin: 0; }
.chip {
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--ink-soft);
  background: var(--surface-2);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  padding: .25rem .7rem;
}
.chip-color { background: var(--clay-l); border-color: #e6c2cd; color: var(--clay); }

/* micro labels */
.micro-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-faint);
  margin-bottom: var(--sp-2);
}
.micro-sub { color: var(--ink-soft); margin-bottom: var(--sp-1); }

/* badges */
.badge {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: .03em;
  padding: .2rem .6rem;
  border-radius: 999px;
  white-space: nowrap;
}
.badge-source { background: var(--clay); color: #fff; }
.badge-sel    { background: var(--teal); color: #fff; }
.badge-default{ background: var(--gold); color: #3a2f10; }
.badge-link   { background: var(--link); color: #fff; }

/* ---------------------------------------------------------------- *
   Barometer result
   ---------------------------------------------------------------- */
.triad { display: flex; flex-direction: column; gap: var(--sp-4); }

.bar-entry {
  border: 1px solid var(--line);
  border-left: 4px solid var(--line-2);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  background: var(--surface-2);
}
/* Floor tints — hue = floor, shade = category (matches the Behavioral
   Barometer chart). Each floor has 3 category tiers that deepen 0→1→2. */
.bar-entry.floor-soznanie.tier-0    { background: #fdf0ef; border-left-color: #e08573; }
.bar-entry.floor-soznanie.tier-1    { background: #fbe1de; border-left-color: #d6604c; }
.bar-entry.floor-soznanie.tier-2    { background: #f6d1cb; border-left-color: #c0422e; }

.bar-entry.floor-podsoznanie.tier-0 { background: #eef5fc; border-left-color: #6fa9d3; }
.bar-entry.floor-podsoznanie.tier-1 { background: #e1edf8; border-left-color: #4a90c2; }
.bar-entry.floor-podsoznanie.tier-2 { background: #d2e3f3; border-left-color: #2f74a8; }

.bar-entry.floor-telo.tier-0        { background: #fdf8e5; border-left-color: #e0c163; }
.bar-entry.floor-telo.tier-1        { background: #fbf1d0; border-left-color: #d6a93a; }
.bar-entry.floor-telo.tier-2        { background: #f5e8ba; border-left-color: #bf8f22; }

/* Исходная пара и ресурс — без рамки и без заливки карточки: лёгкий подъём тенью
   + выразительный бейдж-ярлык (он и есть главный сигнал роли). */
.bar-entry.is-source,
.bar-entry.is-linked { box-shadow: 0 14px 32px rgba(70, 33, 95, .30), 0 4px 10px rgba(70, 33, 95, .18); }

/* Бейдж-ярлык барометра — крупнее и «весомее», в стиле пилюль приложения. */
.bar-meta .badge {
  font-size: var(--fs-sm);
  padding: .34rem .85rem;
  box-shadow: var(--shadow-sm);
  letter-spacing: .02em;
}
.bar-meta .badge-source::before { content: "★ "; }
.bar-meta { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; margin-bottom: var(--sp-3); }

/* Метки этажа/категории — заметнее и в цвете своего этажа (усиливает цветовую
   систему: 1-й чип = этаж, сплошной; 2-й чип = категория, в обводке того же тона). */
.bar-meta .chip { font-size: var(--fs-sm); font-weight: 700; padding: .28rem .8rem; letter-spacing: .005em; }
.bar-entry.floor-soznanie    .bar-meta .chip:first-child { background: #c0422e; border-color: #c0422e; color: #fff; }
.bar-entry.floor-podsoznanie .bar-meta .chip:first-child { background: #2f74a8; border-color: #2f74a8; color: #fff; }
.bar-entry.floor-telo        .bar-meta .chip:first-child { background: #8f6a18; border-color: #8f6a18; color: #fff; }
.bar-entry.floor-soznanie    .bar-meta .chip:nth-child(2) { background: #fbeae6; border-color: #e0a596; color: #a5371f; }
.bar-entry.floor-podsoznanie .bar-meta .chip:nth-child(2) { background: #e8f1fa; border-color: #a7cae6; color: #235d86; }
.bar-entry.floor-telo        .bar-meta .chip:nth-child(2) { background: #fbf3da; border-color: #e0c98a; color: #856617; }

.pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.pair-side {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: var(--sp-3) var(--sp-4);
}
.pair-name { font-size: var(--fs-base); color: var(--teal-d); margin-bottom: var(--sp-2); }

/* ---------------------------------------------------------------- *
   Meridian result
   ---------------------------------------------------------------- */
.energy-group { display: flex; flex-direction: column; gap: var(--sp-3); }
.energy-group + .energy-group { margin-top: var(--sp-5); padding-top: var(--sp-5); border-top: 1px solid var(--line); }
.energy-head { display: flex; align-items: baseline; gap: var(--sp-3); }
.energy-text {
  font-size: var(--fs-sm);
  color: var(--ink-faint);
  font-style: italic;
  margin: 0;
  max-width: var(--maxw-prose);
}
.organs { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: var(--sp-4); }
.organ {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  background: var(--surface-2);
  transition: box-shadow var(--transition);
}
.organ.is-selected {
  border-color: var(--teal);
  background: var(--teal-l);
  box-shadow: 0 0 0 1px var(--teal), var(--shadow-md);
}
.organ-head { display: flex; align-items: center; gap: var(--sp-2); margin-bottom: var(--sp-3); flex-wrap: wrap; }
.organ-title { font-size: var(--fs-base); color: var(--ink); }
.organ-field { margin-bottom: var(--sp-3); }
.organ-field:last-child { margin-bottom: 0; }

/* Two-column paired meridian (male ЯН left / female ИНЬ right), aligned row-by-row */
.mer-table { display: flex; flex-direction: column; gap: var(--sp-3); }
.mer-energy-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); }
.mer-energy {
  margin: 0; font-size: var(--fs-sm); color: var(--ink-soft);
  padding: var(--sp-2) var(--sp-3); border-radius: var(--r-sm);
}
.mer-energy.male { background: var(--male-bg); }
.mer-energy.female { background: var(--female-bg); }
.mer-energy.male strong { color: var(--male); }
.mer-energy.female strong { color: var(--female); }

.mer-pair { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-3); align-items: start; }
.mer-cell {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  display: flex; flex-direction: column; gap: var(--sp-2);
}
.mer-cell.male   { background: var(--male-bg); }
.mer-cell.female { background: var(--female-bg); }
.mer-cell.is-selected { box-shadow: 0 0 0 2px var(--teal), var(--shadow-md); }
.mer-cell--img { align-items: stretch; }
.mer-tag {
  font-size: var(--fs-xs); font-weight: 700; letter-spacing: .04em;
  padding: .05rem .4rem; border-radius: 999px;
}
.mer-cell.male .mer-tag   { background: var(--male);   color: #fff; }
.mer-cell.female .mer-tag { background: var(--female); color: #fff; }
.umcm-row { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: var(--sp-2); }
.umcm-card { max-width: 320px; }

/* Periландр — single clean phrase + therapist hint */
.periland {
  border: 1px solid var(--line); border-left: 3px solid var(--teal);
  border-radius: var(--r-md); padding: var(--sp-4); background: var(--surface-2);
}
.periland .micro-label { color: var(--teal); }
.periland-hint {
  margin-top: var(--sp-3); padding: var(--sp-3) var(--sp-4);
  background: var(--teal-l); border-radius: var(--r-md);
  font-size: var(--fs-sm); color: var(--ink-soft);
}
.periland-hint p { margin: 0 0 var(--sp-2); }
.periland-hint p:last-child { margin-bottom: 0; }
.periland-hint ul { margin: 0; padding-left: 1.2rem; display: flex; flex-direction: column; gap: var(--sp-1); }
.periland-hint li { line-height: 1.45; }

/* ---------------------------------------------------------------- *
   Neg / Pos grids (essences, periland)
   ---------------------------------------------------------------- */
.np-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.np-grid.one { grid-template-columns: 1fr; }
.np {
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  background: var(--surface-2);
}
.np-neg { border-top: 3px solid var(--clay); }
.np-pos { border-top: 3px solid var(--sage); }
.np-neg .micro-label { color: var(--clay); }
.np-pos .micro-label { color: var(--sage); }
.np-sub { margin-bottom: var(--sp-3); }
.np-sub:last-child { margin-bottom: 0; }
.np-heading { font-size: var(--fs-base); color: var(--sage); margin-bottom: var(--sp-2); }

/* ---------------------------------------------------------------- *
   Image mocks (result only)
   ---------------------------------------------------------------- */
/* Карточки точек: ширина ограничена сверху, чтобы одиночная картинка не растягивалась
   во всю колонку (детально смотреть — клик-зум). Несколько идут аккуратной сеткой. */
.img-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 360px)); gap: var(--sp-4); justify-content: start; }
.img-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  background: var(--surface-2);
}
.img-card.is-selected { border-color: var(--teal); box-shadow: 0 0 0 1px var(--teal); }
.img-card.is-default  { border-color: var(--gold); }
.img-card .badge { position: absolute; top: var(--sp-2); right: var(--sp-2); z-index: 1; }

.img-mock { margin: 0; }
.img-mock img { width: 100%; height: auto; border-radius: var(--r-sm); display: block; }
.img-mock.has-image:not(.img-failed) { cursor: zoom-in; }

/* Общая схема на весь блок (напр. Реактивные): крупная карточка во всю ширину. */
.code-points { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin-bottom: var(--sp-3); }
.code-point {
  border: 1px solid var(--line-2);
  border-radius: var(--r-md);
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2);
  font-size: var(--fs-sm);
  font-weight: 700;
  color: var(--ink);
}
.img-card--wide { padding: var(--sp-4); }
.img-card--wide .img-mock img { max-height: 70vh; width: auto; max-width: 100%; margin: 0 auto; }

/* Лайтбокс */
.lightbox {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-5);
  background: rgba(20, 20, 18, .86);
}
.lightbox[hidden] { display: none; }
/* Масштабируем под экран (с сохранением пропорций), в т.ч. увеличиваем мелкие
   вертикальные схемы — иначе они показывались бы в свою небольшую натуральную величину. */
.lightbox img {
  width: 96vw; height: 92vh;
  object-fit: contain;
}
.lightbox-close {
  position: absolute; top: var(--sp-3); right: var(--sp-4);
  width: 44px; height: 44px; border-radius: 999px; border: none;
  background: rgba(255, 255, 255, .15); color: #fff;
  font-size: 1.7rem; line-height: 1; cursor: pointer;
  transition: background var(--transition);
}
.lightbox-close:hover { background: rgba(255, 255, 255, .3); }
/* When an image is present, hide the fallback placeholder unless the file fails to load. */
.img-mock.has-image .img-placeholder { display: none; }
.img-mock.has-image.img-failed img { display: none; }
.img-mock.has-image.img-failed .img-placeholder { display: flex; }
.img-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 150px;
  border: 1.5px dashed var(--line-2);
  border-radius: var(--r-sm);
  background:
    repeating-linear-gradient(45deg, transparent, transparent 10px, rgba(207, 199, 182, .12) 10px, rgba(207, 199, 182, .12) 20px),
    var(--surface);
  color: var(--ink-faint);
  font-size: var(--fs-sm);
  text-align: center;
  padding: var(--sp-4);
}
.img-icon { font-size: 1.8rem; opacity: .8; }
/* Подписи-коды точек в блоке коррекции (К 27, ЦМ15 — Сердце, …) — жирные. */
.img-cap { font-size: var(--fs-sm); font-weight: 700; color: var(--ink); margin-top: var(--sp-2); line-height: 1.4; }

/* ---------------------------------------------------------------- *
   Empty state
   ---------------------------------------------------------------- */
.empty-state {
  text-align: center;
  padding: var(--sp-8) var(--sp-4);
  color: var(--ink-soft);
  background: var(--surface);
  border: 1px dashed var(--line-2);
  border-radius: var(--r-lg);
}
.empty-state p { margin: 0 0 var(--sp-2); }

/* ================================================================
   Responsive
   ================================================================ */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .toc {
    position: sticky;
    top: var(--header-h);
    order: -1;          /* TOC collapses above content on narrow screens */
    max-height: none;
    z-index: 30;
  }
  .toc-nav { max-height: 45vh; overflow: auto; }
  .pair { grid-template-columns: 1fr; }
  .np-grid { grid-template-columns: 1fr; }
  /* Meridian pairs: stack male over female but keep each pair visually grouped */
  .mer-energy-row { grid-template-columns: 1fr; gap: var(--sp-2); }
  .mer-pair {
    grid-template-columns: 1fr;
    gap: 0;
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    overflow: hidden;
  }
  .mer-pair .mer-cell { border: none; border-radius: 0; }
  .mer-pair .mer-cell.male { border-bottom: 2px dashed var(--line-2); }
  .time-field { width: 100%; }
  .num-input { max-width: 6rem; }
  .stress-btn { min-width: 2rem; height: 2rem; font-size: var(--fs-sm); }
}

@media (max-width: 560px) {
  :root { --header-h: 0px; }
  .app-header { position: static; height: auto; }
  /* Стэкаем содержимое шапки (флекс теперь на .app-header-inner, не на .app-header). */
  .app-header-inner { flex-direction: column; align-items: stretch; height: auto; padding: var(--sp-3); gap: var(--sp-2); }
  .app-actions { width: 100%; }
  .app-actions .btn { flex: 1 1 auto; text-align: center; }
  .organs { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
}

/* ================================================================
   Печать → «Сохранить как PDF»
   Скрыто на экране; включается только при печати.
   ================================================================ */
.doc-title { display: none; }

@media print {
  @page { size: A4; margin: 16mm; }

  /* Печатаем цвета и фоны (схемы точек, бейджи) */
  html { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { background: #fff; }

  /* Прячем интерфейс, не относящийся к документу */
  .app-header,
  .toc,
  .result-cta,
  .lightbox { display: none !important; }

  /* Раскладка — одна колонка во всю ширину */
  .layout { display: block; max-width: none; margin: 0; padding: 0; }
  .content { display: block; }

  /* Печатный титул документа */
  .doc-title { display: block; margin: 0 0 var(--sp-5); }
  .doc-title h1 { font-size: 1.4rem; margin: 0 0 .25rem; color: #000; }
  .doc-title .doc-date { color: var(--ink-soft); font-size: var(--fs-sm); }

  /* Кнопки-ответы (стресс / Да-Нет): показываем только выбранную */
  .stress-btn:not(.is-selected),
  .yn-btn:not(.is-selected) { display: none !important; }
  .stress-btn.is-selected,
  .yn-btn.is-selected { border-color: #999; }

  /* Чекбоксы: прячем контрол, оставляем подпись; неотмеченные строки убираем */
  .opt-check input[type="checkbox"] { display: none; }
  .opt-check:not(.is-selected) { display: none !important; }
  .memory-card input[type="checkbox"] { display: none; }
  .memory-card:not(.is-on) { display: none !important; }
  .memory-card.is-on .memory-label::before { content: "✓ "; }

  /* Текстовые поля — показать весь введённый текст, без рамки-формы */
  textarea.text-input {
    height: auto !important; min-height: 0; resize: none; overflow: visible;
    border: 1px solid #ccc; background: #fff;
  }

  /* Пустые/неотвеченные поля (класс ставится в beforeprint) */
  .print-hide { display: none !important; }

  /* Разрывы страниц: не рвём карточки и блоки */
  .img-card,
  .result-block,
  .ses-block,
  .corr-group,
  .res-item,
  .mer-cell,
  .code-point,
  .np,
  .np-grid,
  .np-sub,
  .periland,
  .inst-row { break-inside: avoid; }
  .phase-head,
  .result-head,
  .sub-title { break-after: avoid; }

  /* Картинка не больше страницы; чуть меньше — плотнее упаковка, меньше пустот. */
  .img-mock img,
  .img-card--wide .img-mock img {
    max-height: 180mm; width: auto; max-width: 100%;
  }
  /* Парные схемы меридиана: каждая ячейка (ЯН/ИНЬ) держится целиком (.mer-cell выше),
     а картинки ниже, чтобы пара паковалась без пустых цветных блоков. */
  .mer-cell--img .img-mock img { max-height: 120mm; }

  /* Поля «Финала» печатаем как текст, а не как форму (рамки/стрелки убираем). */
  input.num-input,
  select.select-input {
    appearance: none; -webkit-appearance: none;
    border: none; background: none; box-shadow: none;
    padding: 0; margin: 0; width: auto; min-width: 0;
    font: inherit; color: inherit;
  }
  .time-field { gap: var(--sp-1); }
  .ses-inline { max-width: none; }

  /* Каждая фаза и финал — с новой страницы (чище структурно). */
  .phase,
  .session-final { break-before: page; }

  /* Компактнее типографика при печати — больше влезает на страницу. */
  body { font-size: 10.5pt; line-height: 1.4; }
  .prose { line-height: 1.45; }
  .prose p { margin-bottom: .5em; }
}
