/* ==========================================================================
   Каталог-оглавление (ТЗ «Каталог / Категория», 12.11.2026)
   Двухуровневое оглавление по образцу бумажного каталога.
   Нумерация 1. / 1.1. — CSS-счётчиками, CMS выводит обычные <ol>.
   Подключать после main.css. Используется и на странице каталога,
   и в сайдбаре категории (модификатор .toc--compact).
   ========================================================================== */

/* --- Шапка страницы: крошки + заголовок на светлом фоне --- */
.page-head {
    padding: 40px 0 8px;
}

.page-head__title {
    font-size: 34px;
    line-height: 1.2;
    font-weight: 800;
    letter-spacing: -0.02em;
    color: var(--text-color);
    text-wrap: balance;
}

.page-head__lead {
    margin-top: 10px;
    font-size: 17px;
    color: var(--text-secondary);
}

/* --- Страница каталога: узкая колонка для чтения --- */
.toc-page {
    max-width: 880px;
    margin: 0 auto;
    padding: 24px 2rem 80px;
}

/* --- Оглавление --- */
.toc__list,
.toc__sublist {
    list-style: none;
    margin: 0;
    padding: 0;
}

.toc__list { counter-reset: toc-sec; }
.toc__section { counter-increment: toc-sec; border-bottom: 1px solid var(--border-color); }
.toc__section:first-child { border-top: 2px solid var(--text-color); }
.toc__sublist { counter-reset: toc-item; padding: 0 0 18px; }
.toc__item { counter-increment: toc-item; }

/* Номер — отдельная колонка фиксированной ширины: перенос строк заголовка
   идёт ровно под текст, а не под номер (hanging indent как в книге). */
.toc__num {
    flex: 0 0 3.25rem;
    font-variant-numeric: tabular-nums;
    color: var(--dark-gray);
}

.toc__heading .toc__num::before { content: counter(toc-sec) "."; }
.toc__item .toc__num::before { content: counter(toc-sec) "." counter(toc-item) "."; }

/* Строка 1-го уровня: кнопка (есть подпункты) или просто текст (пусто) */
.toc__heading {
    margin: 0;
    font-size: 21px;
    line-height: 1.35;
    font-weight: 700;
}

.toc__toggle,
.toc__static {
    display: flex;
    align-items: baseline;
    gap: 0;
    width: 100%;
    padding: 18px 4px;
    font: inherit;
    color: var(--text-color);
    text-align: left;
    background: none;
    border: 0;
}

.toc__toggle { cursor: pointer; transition: color 0.2s; }
.toc__toggle:hover,
.toc__toggle[aria-expanded="true"] { color: var(--primary-color); }
.toc__toggle:focus-visible,
.toc__link:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Раздел без подпунктов: не кликается, приглушён */
.toc__static { color: var(--dark-gray); font-weight: 600; }

.toc__title {
    flex: 1 1 auto;
    min-width: 0;
    overflow-wrap: break-word;
}

.toc__chevron {
    flex: 0 0 auto;
    align-self: center;
    margin-left: 8px;
    font-size: 26px;
    transition: transform 0.3s;
}

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

/* Пункт 2-го уровня: номер · название · отточие · стрелка (как в книге) */
.toc__link {
    display: flex;
    align-items: baseline;
    padding: 9px 4px 9px 3.25rem;
    font-size: 17px;
    line-height: 1.45;
    color: var(--text-color);
}

.toc__link .toc__num { flex-basis: 3.75rem; }

.toc__link .toc__title { flex: 0 1 auto; }

.toc__leader {
    flex: 1 1 2rem;
    min-width: 2rem;
    margin: 0 10px;
    border-bottom: 2px dotted #cbd5e0;
    transform: translateY(-0.3em);
}

.toc__arrow {
    flex: 0 0 auto;
    align-self: center;
    font-size: 20px;
    color: var(--dark-gray);
    transition: transform 0.2s, color 0.2s;
}

.toc__link:hover { color: var(--primary-color); }
.toc__link:hover .toc__arrow { color: var(--primary-color); transform: translateX(4px); }
.toc__link:hover .toc__leader { border-color: var(--primary-color); }

.toc__link[aria-current="page"] { color: var(--primary-color); font-weight: 600; }

/* Сворачивание: только при включённом JS (класс .js на <html>),
   без JS всё раскрыто — ссылки видны и пользователю, и роботу. */
.js .toc__panel {
    display: grid;
    grid-template-rows: 0fr;
    visibility: hidden;
    transition: grid-template-rows 0.3s ease, visibility 0s 0.3s;
}

.js .toc__section.is-open .toc__panel {
    grid-template-rows: 1fr;
    visibility: visible;
    transition: grid-template-rows 0.3s ease;
}

.toc__panel > .toc__sublist { min-height: 0; overflow: hidden; }

/* --- Компактный вариант для сайдбара категории --- */
.toc--compact .toc__heading { font-size: 16px; line-height: 1.4; }
.toc--compact .toc__toggle,
.toc--compact .toc__static { padding: 12px 2px; }
.toc--compact .toc__num { flex-basis: 2.25rem; font-size: 14px; }
.toc--compact .toc__chevron { font-size: 22px; }
.toc--compact .toc__sublist { padding-bottom: 10px; }
.toc--compact .toc__link { padding: 6px 2px 6px 2.25rem; font-size: 15px; }
.toc--compact .toc__link .toc__num { flex-basis: 2.75rem; }
.toc--compact .toc__leader,
.toc--compact .toc__arrow { display: none; }

@media (max-width: 768px) {
    .page-head { padding-top: 28px; }
    .page-head__title { font-size: 26px; }
    .toc-page { padding: 16px 1rem 56px; }
    .toc__heading { font-size: 18px; }
    .toc__num { flex-basis: 2.5rem; }
    .toc__link { padding-left: 2.5rem; font-size: 16px; }
    .toc__link .toc__num { flex-basis: 3rem; }
    .toc__leader { display: none; }
    .toc__arrow { margin-left: auto; padding-left: 8px; }
}

@media (prefers-reduced-motion: reduce) {
    .js .toc__panel,
    .toc__chevron,
    .toc__arrow { transition: none; }
}
