/* ============================================================
   Правовые документы — общие стили
   Направление: «архивный документ» / бумага + чернила + печать
   ============================================================ */

/* --- 1. Токены ------------------------------------------------ */
:root {
  /* поверхности */
  --paper: #f6f3ec;
  --paper-raised: #fffdf8;
  --paper-sunken: #efebe1;

  /* чернила */
  --ink: #17181b;
  --ink-2: #4a4b4f;
  --ink-3: #6e6d68;

  /* акцент — печатный оксблад */
  --seal: #8e2f1f;
  --seal-wash: rgba(142, 47, 31, 0.08);

  /* линии */
  --rule: rgba(23, 24, 27, 0.12);
  --rule-strong: rgba(23, 24, 27, 0.26);

  /* типографика */
  --font-display: "Unbounded", "Golos Text", system-ui, sans-serif;
  --font-text: "Golos Text", -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  /* ритм */
  --gutter: 4.25rem; /* левый жёлоб под номера — differentiator */
  --rail: 15.5rem;
  --measure: 68ch;
  --shell: 74rem;

  --radius: 4px;
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

/* --- 2. Сброс ------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 6.5rem;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-text);
  font-size: 1.0625rem;
  line-height: 1.62;
  font-feature-settings: "ss01";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* тонкая бумажная текстура: две сетки волокон, без картинок */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.5;
  background-image:
    repeating-linear-gradient(90deg, rgba(23, 24, 27, 0.022) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(0deg, rgba(23, 24, 27, 0.018) 0 1px, transparent 1px 4px);
}

p,
h1,
h2,
h3,
ul,
ol {
  margin: 0;
}

ul,
ol {
  padding: 0;
  list-style: none;
}

a {
  color: inherit;
  text-decoration: none;
}

svg {
  display: block;
  flex: none;
}

::selection {
  background: var(--seal);
  color: var(--paper-raised);
}

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

/* --- 3. Служебное -------------------------------------------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  top: 0.75rem;
  left: 0.75rem;
  z-index: 100;
  padding: 0.6rem 1rem;
  background: var(--ink);
  color: var(--paper);
  font-size: 0.875rem;
  border-radius: var(--radius);
  transform: translateY(-160%);
  transition: transform 0.2s var(--ease);
}

.skip-link:focus-visible {
  transform: translateY(0);
}

/* --- 4. Индикатор чтения ------------------------------------- */
.progress {
  position: fixed;
  inset: 0 0 auto 0;
  height: 2px;
  z-index: 60;
  background: var(--seal);
  transform: scaleX(0);
  transform-origin: 0 50%;
  will-change: transform;
}

/* --- 5. Шапка ------------------------------------------------ */
.masthead {
  position: sticky;
  top: 0;
  z-index: 50;
  border-bottom: 1px solid var(--rule);
  background: rgba(246, 243, 236, 0.86);
  backdrop-filter: blur(14px) saturate(1.4);
}

.masthead__inner {
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  justify-content: space-between;
}

.brand {
  display: inline-flex;
  align-items: center;
  min-width: 0;
}

.brand__seal {
  width: 32px;
  height: 32px;
  color: var(--seal);
  transition: color 0.18s var(--ease);
}

.brand:hover .brand__seal {
  color: var(--ink);
}

.brand__seal circle:nth-of-type(2) {
  transform-origin: 16px 16px;
  animation: seal-spin 34s linear infinite;
}

@keyframes seal-spin {
  to {
    transform: rotate(360deg);
  }
}

/* переключатель документов: current state доминирует */
.switch {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  border: 1px solid var(--rule);
  border-radius: 999px;
  background: var(--paper-sunken);
}

.switch__link {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.95rem;
  border-radius: 999px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
  transition: background 0.18s var(--ease), color 0.18s var(--ease);
}

.switch__link svg {
  width: 15px;
  height: 15px;
  opacity: 0.65;
}

.switch__link:hover {
  background: var(--paper-raised);
  color: var(--ink);
}

.switch__link[aria-current="page"] {
  background: var(--ink);
  color: var(--paper);
}

.switch__link[aria-current="page"] svg {
  opacity: 1;
}

.switch__label--short {
  display: none;
}

/* --- 6. Каркас страницы -------------------------------------- */
.shell {
  position: relative;
  z-index: 1;
  max-width: var(--shell);
  margin: 0 auto;
  padding: 0 1.5rem 6rem;
  display: grid;
  grid-template-columns: var(--rail) minmax(0, 1fr);
  gap: 0 4rem;
  align-items: start;
}

/* --- 7. Рельс с оглавлением ---------------------------------- */
.rail {
  position: sticky;
  top: 5.5rem;
  padding-top: 4.5rem;
  max-height: calc(100vh - 7rem);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.rail__toggle {
  display: none;
}

.rail__head {
  padding-bottom: 0.7rem;
  border-bottom: 1px solid var(--rule-strong);
  font-family: var(--font-mono);
  font-size: 0.625rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.toc {
  overflow-y: auto;
  padding: 0.5rem 0 1rem;
  margin: 0;
  scrollbar-width: thin;
}

.toc__link {
  display: grid;
  grid-template-columns: 1.75rem 1fr;
  gap: 0.35rem;
  padding: 0.4rem 0 0.4rem 0.6rem;
  border-left: 2px solid transparent;
  font-size: 0.875rem;
  line-height: 1.35;
  color: var(--ink-3);
  transition: color 0.18s var(--ease), border-color 0.18s var(--ease);
}

.toc__link span:first-child {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  padding-top: 0.1em;
}

.toc__link:hover {
  color: var(--ink);
  border-left-color: var(--rule-strong);
}

.toc__link.is-active {
  color: var(--ink);
  font-weight: 600;
  border-left-color: var(--seal);
}

.toc__link.is-active span:first-child {
  color: var(--seal);
}

/* --- 8. Заголовок документа ---------------------------------- */
.doc {
  min-width: 0;
  padding-top: 4.5rem;
}

.doc__head {
  max-width: var(--measure);
  padding-bottom: 2.5rem;
  border-bottom: 1px solid var(--rule-strong);
}

.doc__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(2.05rem, 5.6vw, 3.5rem);
  line-height: 1.02;
  letter-spacing: -0.04em;
  text-wrap: balance;
}

.doc__lede {
  margin-top: 1.35rem;
  font-size: 1.1875rem;
  line-height: 1.55;
  color: var(--ink-2);
  text-wrap: pretty;
}

/* --- 9. Разделы: сетка «жёлоб + текст» ----------------------- */
.section {
  padding: 3.25rem 0 0.5rem;
  border-bottom: 1px solid var(--rule);
  scroll-margin-top: 6rem;
}

.section:last-of-type {
  border-bottom: 0;
}

.section__title {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  align-items: start;
  gap: 0;
  margin-bottom: 0.5rem;
  font-family: var(--font-display);
  font-weight: 500;
  font-size: clamp(1.2rem, 2.4vw, 1.5rem);
  line-height: 1.2;
  letter-spacing: -0.025em;
  text-wrap: balance;
}

/* крупная цифра раздела в жёлобе — ledger-мотив */
.section__num {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: 0.75rem;
  letter-spacing: 0.06em;
  color: var(--seal);
  padding-top: 0.45em;
  font-variant-numeric: tabular-nums;
}

.section__num::after {
  content: "";
  display: block;
  width: 1.4rem;
  height: 1px;
  margin-top: 0.55rem;
  background: var(--seal);
  opacity: 0.45;
}

/* --- 10. Пункты (ledger) ------------------------------------- */
.clauses {
  display: grid;
}

.clause {
  display: grid;
  grid-template-columns: var(--gutter) minmax(0, 1fr);
  padding: 0.9rem 0;
  border-top: 1px solid transparent;
}

.clause + .clause {
  border-top-color: var(--rule);
}

.clause__num {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-3);
  padding-top: 0.25em;
  align-self: start;
  position: relative;
  transition: color 0.15s var(--ease);
}

.clause__num::before {
  content: "§";
  position: absolute;
  right: 100%;
  margin-right: -0.9rem;
  opacity: 0;
  color: var(--seal);
  transition: opacity 0.15s var(--ease), margin-right 0.15s var(--ease);
}

.clause:hover .clause__num,
.clause__num:focus-visible {
  color: var(--seal);
}

.clause:hover .clause__num::before {
  opacity: 1;
  margin-right: 0.25rem;
}

.clause__body {
  max-width: var(--measure);
}

.clause__body > * + * {
  margin-top: 0.85rem;
}

.clause__body p {
  text-wrap: pretty;
}

/* вложенные перечисления */
.terms-list {
  display: grid;
  gap: 0.55rem;
  padding-left: 0.1rem;
}

.terms-list li {
  position: relative;
  padding-left: 1.4rem;
  color: var(--ink-2);
}

.terms-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0.72em;
  width: 0.6rem;
  height: 1px;
  background: var(--seal);
  opacity: 0.75;
}

/* врезка-акцент для важных оговорок */
.note {
  margin-top: 1rem;
  padding: 0.9rem 1.1rem;
  border-left: 2px solid var(--seal);
  background: var(--seal-wash);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.9375rem;
  color: var(--ink-2);
}

.note strong {
  color: var(--ink);
  font-weight: 600;
}

/* ссылки внутри текста документа */
.note a,
.attest a,
.clause__body p > a {
  color: var(--seal);
  border-bottom: 1px solid rgba(142, 47, 31, 0.35);
  padding-bottom: 1px;
  transition: border-color 0.15s var(--ease);
}

.note a:hover,
.attest a:hover,
.clause__body p > a:hover {
  border-bottom-color: var(--seal);
}

/* подсветка пункта по прямой ссылке */
:target {
  animation: flash 1.6s var(--ease);
}

@keyframes flash {
  0%,
  35% {
    background: var(--seal-wash);
  }
  100% {
    background: transparent;
  }
}

/* --- 11. Финальный блок и подвал ----------------------------- */
.attest {
  margin-top: 3.5rem;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 1.1rem;
  align-items: center;
  max-width: var(--measure);
  padding: 1.4rem 1.5rem;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius);
  background: var(--paper-raised);
}

.attest svg {
  width: 34px;
  height: 34px;
  color: var(--seal);
}

.attest p {
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--ink-2);
}

.doc__foot {
  margin-top: 3rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 1rem 2rem;
  align-items: center;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.6875rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.doc__foot a {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--ink);
  border-bottom: 1px solid var(--rule-strong);
  padding-bottom: 2px;
  transition: border-color 0.15s var(--ease), color 0.15s var(--ease);
}

.doc__foot a:hover {
  color: var(--seal);
  border-bottom-color: var(--seal);
}

.doc__foot a svg {
  width: 13px;
  height: 13px;
}

/* --- 12. Наверх ---------------------------------------------- */
.to-top {
  position: fixed;
  right: 1.5rem;
  bottom: 1.5rem;
  z-index: 55;
  width: 2.875rem;
  height: 2.875rem;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule-strong);
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  opacity: 0;
  transform: translateY(0.75rem) scale(0.9);
  pointer-events: none;
  transition: opacity 0.22s var(--ease), transform 0.22s var(--ease);
}

.to-top.is-visible {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.to-top:hover {
  background: var(--seal);
}

.to-top svg {
  width: 17px;
  height: 17px;
}

/* --- 13. Адаптив --------------------------------------------- */
@media (max-width: 60rem) {
  :root {
    --gutter: 3.5rem;
  }

  .shell {
    grid-template-columns: minmax(0, 1fr);
    gap: 0;
    padding-bottom: 4rem;
  }

  .rail {
    position: static;
    max-height: none;
    padding-top: 2.5rem;
    order: -1;
  }

  .rail__head {
    display: none;
  }

  /* оглавление превращается в раскрывающийся блок */
  .rail__toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    width: 100%;
    padding: 0.9rem 1.1rem;
    border: 1px solid var(--rule-strong);
    border-radius: var(--radius);
    background: var(--paper-raised);
    color: var(--ink);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    cursor: pointer;
  }

  .rail__toggle svg {
    width: 16px;
    height: 16px;
    transition: transform 0.22s var(--ease);
  }

  .rail__toggle[aria-expanded="true"] svg {
    transform: rotate(180deg);
  }

  .toc {
    display: grid;
    overflow: hidden;
    padding: 0;
    border: 1px solid var(--rule);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    background: var(--paper-raised);
  }

  .toc[hidden] {
    display: none;
  }

  .toc__link {
    padding: 0.7rem 1.1rem;
    border-left: 0;
    border-top: 1px solid var(--rule);
    grid-template-columns: 1.9rem 1fr;
  }

  .toc__link.is-active {
    border-left: 0;
    background: var(--seal-wash);
  }

  .doc {
    padding-top: 2.5rem;
  }
}

@media (max-width: 40rem) {
  body {
    font-size: 1rem;
  }

  .masthead__inner {
    padding: 0.7rem 1.1rem;
    gap: 0.75rem;
  }

  .switch {
    flex: 1;
  }

  .switch__link {
    flex: 1;
    justify-content: center;
    padding: 0.55rem 0.7rem;
  }

  .switch__label--full {
    display: none;
  }

  .switch__label--short {
    display: inline;
  }

  .shell {
    padding-inline: 1.1rem;
  }

  /* на узких экранах номер уходит над текстом */
  .section__title,
  .clause {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.3rem;
  }

  .section__num::after {
    display: none;
  }

  .clause__num::before {
    display: none;
  }

  .attest {
    grid-template-columns: minmax(0, 1fr);
  }

  .to-top {
    right: 1rem;
    bottom: 1rem;
  }
}

/* --- 14. Доступность и печать -------------------------------- */
@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@media print {
  :root {
    --paper: #fff;
    --paper-raised: #fff;
    --rule: #bbb;
    --rule-strong: #888;
    --ink: #000;
    --ink-2: #222;
    --ink-3: #444;
    --seal: #000;
  }

  body::before,
  .masthead,
  .rail,
  .progress,
  .to-top,
  .skip-link {
    display: none !important;
  }

  .shell {
    display: block;
    max-width: none;
    padding: 0;
  }

  .doc {
    padding-top: 0;
  }

  .section {
    break-inside: avoid;
  }

  .doc__foot a::after {
    content: " (" attr(href) ")";
    font-size: 0.7em;
  }
}
