/* =====================================================================
   ПОТОК: листы дела. Шапка, меню, наезд листов, номер листа.
   Файл ведёт js/flow.js. Свои переменные с префиксом --flow-, --fi-.
   Только палитра заказчика: серый, белый, светло-серый.
   ===================================================================== */

:root {
  --flow-ease: cubic-bezier(.22, 1, .36, 1);
  --flow-lh: 16px;           /* высота строки в номере листа */
}

/* Свою плавную прокрутку к якорям ведёт flow.js: нативная её только мешает */
html.js { scroll-behavior: auto; }
html.menu-open { overflow: hidden; }

/* ---------- Листы: наезд ---------- */
/* Включается классом .flow (его ставит flow.js, если нет reduced-motion).
   Лист липнет к верху окна, следующий накрывает его. У высокого листа
   top отрицательный (100svh − высота): прилипает не верх, а низ, и весь
   контент достижим. --flow-h пишет flow.js. */
.flow main > .screen {
  position: sticky;
  top: 0;
  top: min(0px, calc(100vh - var(--flow-h, 0px)));
  top: min(0px, calc(100svh - var(--flow-h, 0px)));
}
.flow main > .screen:last-child { position: relative; top: auto; }

/* Кромка листа: линия в 1 px цвета палитры, не тень */
.flow main > .screen { --flow-edge: var(--fg, var(--gray)); }
.flow main > .screen[data-theme="gray"] { --flow-edge: var(--mist); }
.flow main > .screen + .screen { border-top: 1px solid var(--flow-edge); }

/* Лист получает фокус после перехода по якорю: обводка секции не нужна */
main > section:focus { outline: none; }

/* ---------- Шапка ---------- */
.site-header {
  position: fixed; inset: 0 0 auto 0; z-index: 50;
  height: var(--header-h);
  display: flex; align-items: center;
  padding: 0 var(--gutter);
  background: var(--bg); color: var(--fg);
  /* Цвет меняется мгновенно: шапка это полоса того листа, что под ней */
  transition: none;
}
.site-header[data-theme="gray"]  { --bg: var(--gray);  --fg: var(--white); --line: var(--mist); }
.site-header[data-theme="white"] { --bg: var(--white); --fg: var(--gray);  --line: var(--mist); }
.site-header[data-theme="mist"]  { --bg: var(--mist);  --fg: var(--gray);  --line: var(--gray); }
/* Меню открыто: шапка продолжает лист меню. Цвет меняется, когда кромка листа дошла до шапки */
.site-header.menu-open { --bg: var(--gray); --fg: var(--white); --line: var(--mist); transition: background-color 0s linear .24s, color 0s linear .24s; }

.header-inner {
  width: 100%; max-width: var(--max); margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 24px;
}
.brand {
  position: relative; z-index: 2;
  font-size: .8125rem; font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  text-decoration: none; white-space: nowrap;
}
.nav ul { display: flex; gap: clamp(20px, 2.8vw, 44px); }
.nav a {
  position: relative; display: inline-block; padding: 10px 0;
  font-size: .75rem; font-weight: 500; letter-spacing: .14em; text-transform: uppercase;
  text-decoration: none;
}
/* Линия рисуется слева направо, стирается вправо */
.nav a::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 4px; height: 1.5px;
  background: currentColor;
  transform: scaleX(0); transform-origin: right center;
  transition: transform .7s var(--flow-ease);
}
.nav a:hover::after, .nav a:focus-visible::after, .nav a[aria-current="true"]::after {
  transform: scaleX(1); transform-origin: left center;
}

/* ---------- Бургер ---------- */
.burger {
  display: none; position: relative; z-index: 2;
  width: 44px; height: 44px; margin-right: -10px; padding: 0; border: 0; background: transparent; cursor: pointer;
}
.burger span {
  position: absolute; left: 10px; top: 50%; width: 24px; height: 2px; margin-top: -1px;
  background: currentColor;
  transition: transform .45s var(--flow-ease);
}
.burger span:nth-child(1) { transform: translateY(-4px); transform-origin: center; }
.burger span:nth-child(2) { transform: translateY(4px) scaleX(.6); transform-origin: right center; }
.burger[aria-expanded="true"] span:nth-child(1) { transform: rotate(45deg); }
.burger[aria-expanded="true"] span:nth-child(2) { transform: rotate(-45deg) scaleX(1); transform-origin: center; }

/* ---------- Меню на телефоне: лист ---------- */
@media (max-width: 860px) {
  .burger { display: inline-block; }

  .nav {
    position: fixed; inset: 0; z-index: 1;
    display: flex; flex-direction: column; justify-content: flex-end;
    padding: calc(var(--header-h) + 3vh) var(--gutter) max(28px, env(safe-area-inset-bottom));
    background: var(--gray); color: var(--white);
    border-top: 1px solid var(--mist);
    overflow-y: auto; overscroll-behavior: contain;
    visibility: hidden; transform: translate3d(0, 100%, 0);
    transition: transform .7s var(--flow-ease), visibility 0s linear .7s, border-color 0s;
  }
  /* Кромка видна, пока лист едет; на месте её не видно */
  .nav.open {
    visibility: visible; transform: none; border-top-color: var(--gray);
    transition: transform .7s var(--flow-ease), visibility 0s, border-color 0s linear .7s;
  }

  .nav ul { flex-direction: column; gap: 0; counter-reset: flow-nav; }
  .nav li { position: relative; overflow: hidden; counter-increment: flow-nav; }
  .nav li:nth-child(1) { --flow-i: 0; }
  .nav li:nth-child(2) { --flow-i: 1; }
  .nav li:nth-child(3) { --flow-i: 2; }
  .nav li:nth-child(4) { --flow-i: 3; }
  .nav li:nth-child(5) { --flow-i: 4; }
  .nav li:nth-child(n+6) { --flow-i: 5; }

  /* Линия под пунктом на месте, пункты просто проявляются */
  .nav li::after {
    content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 1px;
    background: var(--mist);
  }
  .nav a {
    display: flex; align-items: baseline; gap: 18px;
    padding: clamp(10px, 2.6vh, 22px) 0;
    font-family: var(--font-display); font-size: min(11.5vw, 7.6vh, 3.75rem); font-weight: 500;
    line-height: 1.08; letter-spacing: -.02em; text-transform: none;
    opacity: 0; transition: opacity .15s linear;
  }
  .nav.open a { opacity: 1; transition: opacity .25s linear .2s; }
  .nav a::before {
    content: counter(flow-nav, decimal-leading-zero);
    content: counter(flow-nav, decimal-leading-zero) / "";
    flex: none; min-width: 2.2ch;
    font-family: var(--font); font-size: .75rem; font-weight: 500; letter-spacing: .14em;
    font-variant-numeric: tabular-nums;
  }
  .nav a::after { display: none; }
}

/* Альбомный телефон: меню в два столбца, чтобы пункты не уходили за экран */
@media (max-width: 860px) and (max-height: 520px) {
  .nav { justify-content: flex-start; padding-top: calc(var(--header-h) + 8px); }
  .nav ul { display: grid; grid-template-columns: 1fr 1fr; column-gap: clamp(20px, 5vw, 48px); }
  .nav a { font-size: min(8.5vh, 2.4rem); padding: 8px 0; }
}

/* ---------- Номер листа: корешок справа ---------- */
.flow-ind {
  position: fixed; z-index: 40;
  right: clamp(0px, calc(var(--gutter) - 28px), 6px); top: 50%;
  display: grid; transform: translateY(-50%);
  pointer-events: none; user-select: none;
  font-family: var(--font); font-size: 10.5px; font-weight: 500; line-height: var(--flow-lh);
  letter-spacing: .16em; text-transform: uppercase; font-variant-numeric: tabular-nums;
  animation: flow-ind-in 1s var(--flow-ease) 1.1s both;
}
html:not(.js) .flow-ind { display: none; }

.fi-layer {
  grid-area: 1 / 1;
  display: flex; align-items: stretch; gap: 7px;
  color: var(--gray);
}
.fi-layer[data-ft="gray"]  { color: var(--white); }
.fi-layer[data-ft="white"] { color: var(--gray); }
.fi-layer[data-ft="mist"]  { color: var(--gray); }
.fi-layer.is-off { visibility: hidden; }

/* Текст идёт сверху вниз, как на корешке папки */
.fi-text { writing-mode: vertical-rl; display: flex; flex: none; align-items: flex-start; gap: .7em; white-space: nowrap; }
.fi-text > * { flex: none; }
.fi-win { display: block; overflow: hidden; block-size: var(--flow-lh); }
.fi-roll { display: grid; }
.fi-roll > span { grid-area: 1 / 1; display: block; block-size: var(--flow-lh); white-space: nowrap; opacity: 0; transition: opacity .25s linear; }
.fi-roll > span.is-on { opacity: 1; }

/* Линия прогресса: пунктир, поверх неё сплошная, растёт сверху вниз (scaleY) */
.fi-line { position: relative; flex: none; width: 5px; }
.fi-line::before {
  content: ""; position: absolute; top: 0; bottom: 0; right: 0; width: 0;
  border-right: 1px dotted currentColor;
}
.fi-fill {
  position: absolute; top: 0; bottom: 0; right: 0; width: 1px;
  background: currentColor; transform: scaleY(0); transform-origin: center top;
}
.fi-line i { position: absolute; right: 0; width: 5px; height: 1px; background: currentColor; }

@keyframes flow-ind-in { from { opacity: 0; } to { opacity: 1; } }

/* Телефон: корешок целиком помещается в поле 20 px справа от текста */
@media (max-width: 600px) {
  .flow-ind { --flow-lh: 13px; right: 0; font-size: 9.5px; letter-spacing: .13em; }
  .fi-layer { gap: 3px; }
  .fi-line { width: 3px; }
  .fi-line i { width: 3px; }
}
/* Узкий телефон: только линия прогресса, текст у края поля не прилипает */
@media (max-width: 480px) {
  .flow-ind { right: 3px; }
  .fi-text { display: none; }
  .fi-layer { height: 150px; }
}
@media (max-height: 560px) {
  .fi-win--name, .fi-of + .fi-win--name { display: none; }
  .fi-text { gap: .5em; }
}

/* ---------- Без JS: шапка в строку, меню видно ---------- */
@media (max-width: 860px) {
  html:not(.js) .site-header { position: absolute; height: auto; min-height: var(--header-h); padding-top: 8px; padding-bottom: 8px; }
  html:not(.js) .header-inner { flex-wrap: wrap; gap: 4px 20px; }
  html:not(.js) .burger { display: none; }
  html:not(.js) .nav {
    position: static; visibility: visible; transform: none; padding: 0; background: none; color: inherit;
    border: 0; flex-direction: row; overflow: visible; width: 100%;
  }
  html:not(.js) .nav ul { flex-direction: row; flex-wrap: wrap; gap: 0 18px; }
  html:not(.js) .nav li { overflow: visible; }
  html:not(.js) .nav a { display: inline-block; padding: 6px 0; font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; transform: none; opacity: 1; font-family: var(--font); }
  html:not(.js) .nav a::before, html:not(.js) .nav li::after { display: none; }
}

/* Пока меняется размер окна, переходы меню отключены */
.flow-resizing .nav, .flow-resizing .nav a { transition: none !important; }

/* ---------- Без анимаций ---------- */
@media (prefers-reduced-motion: reduce) {
  .site-header, .site-header.menu-open, .burger span, .nav, .nav a, .nav a::after, .fi-roll > span { transition: none !important; }
  .nav.open a { transition: none !important; }
  .flow-ind { animation: none; }
}

/* Корешок «Л. 02 / 06» убран как декоративная нумерация (unslop-ui U2); скрипт остаётся, элемент скрыт */
.flow-ind { display: none !important; }
