.kb-page {
    padding-top: 96px;
}

.kb-index-hero {
    padding: 64px 0 32px;
}

.kb-index-hero h1 {
    color: var(--text, #1e293b);
    font-size: clamp(36px, 5vw, 52px);
    font-weight: 800;
    line-height: 1.12;
    margin-bottom: 16px;
}

.kb-index-hero p {
    color: var(--text-secondary, #64748b);
    font-size: 18px;
    max-width: 720px;
}

.kb-index-content {
    padding: 0 0 96px;
}

.kb-search {
    display: flex;
    max-width: 680px;
    margin-bottom: 40px;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: var(--radius, 16px);
    background: var(--card-bg, #fff);
    box-shadow: var(--card-shadow, 0 4px 24px rgba(15, 23, 42, 0.06));
    overflow: hidden;
}

.kb-search input {
    flex: 1;
    min-width: 0;
    border: 0;
    background: transparent;
    color: var(--text, #1e293b);
    font: inherit;
    padding: 16px 18px;
}

.kb-search input:focus {
    outline: none;
}

.kb-search button {
    border: 0;
    background: var(--primary, #2563eb);
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
    padding: 0 24px;
}

.kb-result-note,
.kb-empty {
    color: var(--text-secondary, #64748b);
    margin-bottom: 20px;
}

.kb-category {
    margin-bottom: 48px;
}

.kb-category h2 {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text, #1e293b);
    font-size: 24px;
    font-weight: 800;
    margin-bottom: 18px;
}

.kb-card-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.kb-article-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 132px;
    padding: 22px;
    color: var(--text, #1e293b);
    background: var(--card-bg, #fff);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: var(--radius, 16px);
    box-shadow: var(--card-shadow, 0 4px 24px rgba(15, 23, 42, 0.06));
    transition: transform var(--transition, 0.2s ease), box-shadow var(--transition, 0.2s ease), border-color var(--transition, 0.2s ease);
}

.kb-article-card:hover {
    color: var(--text, #1e293b);
    border-color: transparent;
    box-shadow: var(--card-shadow-hover, 0 12px 40px rgba(15, 23, 42, 0.12));
    transform: translateY(-3px);
}

.kb-article-card strong {
    font-size: 18px;
    line-height: 1.35;
}

.kb-article-card span {
    color: var(--text-secondary, #64748b);
    font-size: 15px;
    line-height: 1.55;
}

.kb-article-category {
    color: var(--primary, #2563eb) !important;
    font-family: var(--font-mono, monospace);
    font-size: 12px !important;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.kb-breadcrumbs {
    padding: 112px 0 0;
    color: var(--text-light, #94a3b8);
    font-size: 14px;
}

.kb-breadcrumbs .container {
    display: flex;
    gap: 8px;
}

.kb-breadcrumbs a {
    color: var(--text-secondary, #64748b);
}

.kb-article-shell {
    padding: 30px 0 96px;
}

.kb-article-layout {
    display: grid;
    grid-template-columns: minmax(218px, 250px) minmax(0, 760px);
    gap: 56px;
    align-items: start;
    max-width: 1120px;
}

/* ===== Оглавление (§4.1 поле листа, §5 линия вместо тени, §6.3 шкала ступенями) ===== */
.kb-toc {
    position: sticky;
    top: 104px;
    max-height: calc(100vh - 128px);
}

.kb-toc:empty,
.kb-toc.is-empty {
    display: none;
}

/* Оглавление скрыто (в статье нет h2–h4) — колонок остаётся одна. Иначе текст
   статьи, став первым элементом грида, падает в узкую колонку оглавления
   (250px), а широкая (760px) пустует. */
.kb-article-layout:has(> .kb-toc.is-empty) {
    grid-template-columns: minmax(0, 760px);
}

.kb-toc-inner {
    position: relative;
    padding: 0 0 0 var(--s-4);
    background: transparent;
    border-left: 1px solid var(--border);
    border-radius: 0;
    box-shadow: none;
}

/* Шкала прочитанного поверх волосяной линии. Заполняется ступенями (--e-step
   в JS: доля округляется до 1/12), непрерывная заливка выглядит нарисованной. */
.kb-toc-inner::before {
    content: "";
    position: absolute;
    left: -1px;
    top: 0;
    width: 1px;
    height: var(--kb-toc-progress, 0%);
    background: var(--p-500);
    transition: height var(--d-base) var(--e-out);
}

.kb-toc-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: var(--s-3);
    margin-bottom: var(--s-3);
    padding-bottom: var(--s-3);
    border-bottom: 1px solid var(--border-faint);
}

.kb-toc-title {
    font-family: var(--font-mono);
    font-size: var(--t-label);
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    line-height: 1.2;
    color: var(--text-muted);
}

.kb-toc-count {
    font-family: var(--font-mono);
    font-size: var(--t-label);
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    line-height: 1.2;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.kb-toc nav {
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 232px);
    overflow: auto;
    counter-reset: kb-toc;
    /* Своя полоса прокрутки скрыта: список ведёт текст, а не пользователь.
       Обрез сверху/снизу растворяется — §1.1, «уходит за обрез». */
    scrollbar-width: none;
    -ms-overflow-style: none;
    mask-image: linear-gradient(180deg, transparent 0, #000 20px, #000 calc(100% - 28px), transparent 100%);
}

.kb-toc nav::-webkit-scrollbar {
    display: none;
}

.kb-toc a {
    position: relative;
    display: grid;
    grid-template-columns: 26px minmax(0, 1fr);
    align-items: baseline;
    gap: var(--s-2);
    padding: 7px var(--s-2) 7px var(--s-2);
    border-radius: 0;
    color: var(--text-muted);
    font-size: var(--t-sm);
    font-weight: 400;
    line-height: 1.4;
    transition: color var(--d-fast) var(--e-out), background-color var(--d-fast) var(--e-out);
}

/* Две строки максимум: реестр разделов, а не пересказ статьи. */
.kb-toc a span {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Номер раздела — mono, как на поле чертёжного листа. */
.kb-toc a::before {
    counter-increment: kb-toc;
    content: counter(kb-toc, decimal-leading-zero);
    font-family: var(--font-mono);
    font-size: var(--t-label);
    font-weight: 500;
    letter-spacing: 0.08em;
    color: var(--text-faint);
    font-variant-numeric: tabular-nums;
    transition: color var(--d-fast) var(--e-out);
}

/* Курсор на шкале: 3px охры поверх линии, прямой угол. Единственное пятно охры. */
.kb-toc a::after {
    content: "";
    position: absolute;
    left: calc(-1 * var(--s-4) - 2px);
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--a-500);
    opacity: 0;
    transition: opacity var(--d-fast) var(--e-out);
}

.kb-toc a:hover {
    background: var(--bg-sunken);
    color: var(--text);
}

.kb-toc a.is-active {
    color: var(--text);
    font-weight: 600;
}

.kb-toc a.is-active::before {
    color: var(--text);
}

.kb-toc a.is-active::after {
    opacity: 1;
}

.kb-toc a[data-level="3"],
.kb-toc a[data-level="4"] {
    color: var(--text-faint);
}

.kb-toc a[data-level="3"] {
    padding-left: var(--s-5);
}

.kb-toc a[data-level="4"] {
    padding-left: var(--s-6);
}

/* Вложенные заголовки номера не получают — нумеруются только разделы h2. */
.kb-toc a[data-level="3"]::before,
.kb-toc a[data-level="4"]::before {
    counter-increment: none;
    content: "—";
    letter-spacing: 0;
}

.kb-article {
    min-width: 0;
}

.kb-article-lead {
    max-width: 70ch;
    color: #334155;
    font-size: 20px;
    font-weight: 520;
    line-height: 1.55;
    margin: -18px 0 36px;
}

.kb-article-header {
    max-width: 760px;
    margin-bottom: 42px;
}

.kb-article-header h1 {
    color: var(--text, #1e293b);
    font-size: clamp(32px, 4vw, 44px);
    font-weight: 760;
    line-height: 1.16;
    margin: 0 0 16px;
}

.kb-article-header p {
    color: #334155;
    font-size: clamp(21px, 2vw, 26px);
    font-weight: 520;
    line-height: 1.45;
    max-width: 720px;
}

.kb-article-content {
    padding: 0;
}

.kb-body {
    max-width: 760px;
    color: var(--text, #1e293b);
    font-size: 19px;
    line-height: 1.78;
}

.kb-body h2,
.kb-body h3,
.kb-body h4 {
    color: var(--text, #1e293b);
    font-weight: 800;
    line-height: 1.25;
    scroll-margin-top: 96px;
}

.kb-body h2 {
    font-size: 28px;
    margin: 44px 0 14px;
}

.kb-body h3 {
    font-size: 22px;
    margin: 36px 0 14px;
}

.kb-body h4 {
    font-size: 18px;
    margin: 28px 0 12px;
}

.kb-body p,
.kb-body ul,
.kb-body ol,
.kb-body blockquote,
.kb-body table,
.kb-body figure {
    margin-bottom: 20px;
}

.kb-body ul,
.kb-body ol {
    padding-left: 26px;
}

.kb-body li {
    margin-bottom: 8px;
}

.kb-body a {
    color: var(--primary, #2563eb);
    text-decoration: underline;
    text-decoration-color: var(--primary-light, #dbeafe);
}

.kb-body blockquote {
    color: var(--text-secondary, #64748b);
    background: var(--bg-alt, #f1f5f9);
    border-left: 3px solid var(--accent, #f59e0b);
    border-radius: 0 var(--radius-sm, 10px) var(--radius-sm, 10px) 0;
    padding: 16px 22px;
}

.kb-body img,
.ck-content img {
    display: block;
    max-width: 100%;
    height: auto;
}

.kb-body figure.image,
.ck-content figure.image,
.kb-body .image,
.ck-content .image {
    clear: both;
    display: table;
    margin: 28px 0;
    max-width: 100%;
}

.kb-body figure.image img,
.ck-content figure.image img,
.kb-body .image img,
.ck-content .image img {
    border-radius: var(--radius-sm, 10px);
}

.kb-body figure.image-style-align-center,
.ck-content figure.image-style-align-center,
.kb-body .image-style-align-center,
.ck-content .image-style-align-center {
    margin-left: auto;
    margin-right: auto;
}

.kb-body figure.image-style-align-left,
.ck-content figure.image-style-align-left,
.kb-body .image-style-align-left,
.ck-content .image-style-align-left {
    float: left;
    margin: 6px 24px 18px 0;
}

.kb-body figure.image-style-align-right,
.ck-content figure.image-style-align-right,
.kb-body .image-style-align-right,
.ck-content .image-style-align-right {
    float: right;
    margin: 6px 0 18px 24px;
}

.kb-body figcaption,
.ck-content figcaption {
    caption-side: bottom;
    color: var(--text-secondary, #64748b);
    display: table-caption;
    font-size: 14px;
    padding-top: 8px;
    text-align: left;
}

.kb-body iframe,
.ck-content iframe {
    display: block;
    width: 100%;
    max-width: 820px;
    min-height: 360px;
    margin: 28px 0;
    border: 0;
    border-radius: var(--radius-sm, 10px);
}

.ck-content {
    min-height: 320px;
}

@media (max-width: 1080px) {
    .kb-article-layout {
        grid-template-columns: minmax(0, 1fr);
        gap: 26px;
    }

    .kb-toc {
        top: 72px;
        z-index: 5;
        max-height: none;
    }

    /* Мобильный — горизонтальная лента разделов. Непрозрачная (§5: blur убран). */
    .kb-toc-inner {
        padding: 0;
        background: var(--bg);
        border-left: 0;
        border-bottom: 1px solid var(--border);
        border-radius: 0;
        box-shadow: none;
    }

    /* Шкала прочитанного разворачивается в горизонталь по той же линии. */
    .kb-toc-inner::before {
        left: 0;
        top: auto;
        bottom: -1px;
        width: var(--kb-toc-progress, 0%);
        height: 1px;
        transition: width var(--d-base) var(--e-out);
    }

    .kb-toc-head {
        display: none;
    }

    .kb-toc nav {
        flex-direction: row;
        max-height: none;
        overflow-x: auto;
        scroll-snap-type: x proximity;
        -webkit-overflow-scrolling: touch;
        mask-image: linear-gradient(90deg, #000 calc(100% - 32px), transparent 100%);
    }

    .kb-toc a span {
        -webkit-line-clamp: 1;
    }

    .kb-toc a,
    .kb-toc a[data-level="3"],
    .kb-toc a[data-level="4"] {
        flex: 0 0 auto;
        grid-template-columns: auto minmax(0, 1fr);
        align-items: center;
        max-width: min(68vw, 320px);
        overflow: hidden;
        padding: 10px var(--s-3);
        scroll-snap-align: start;
        white-space: nowrap;
    }

    .kb-toc a span {
        min-width: 0;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Засечка активного — снизу, вдоль ленты. */
    .kb-toc a::after {
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        width: auto;
        height: 2px;
    }
}

@media (max-width: 720px) {
    .kb-page {
        padding-top: 80px;
    }

    .kb-index-hero {
        padding-top: 48px;
    }

    .kb-card-list {
        grid-template-columns: 1fr;
    }

    .kb-search {
        flex-direction: column;
    }

    .kb-search button {
        padding: 14px 18px;
    }

    .kb-breadcrumbs {
        padding-top: 96px;
    }

    .kb-body,
    .kb-article-header p,
    .kb-article-lead {
        font-size: 17px;
    }

    .kb-body figure.image-style-align-left,
    .ck-content figure.image-style-align-left,
    .kb-body .image-style-align-left,
    .ck-content .image-style-align-left,
    .kb-body figure.image-style-align-right,
    .ck-content figure.image-style-align-right,
    .kb-body .image-style-align-right,
    .ck-content .image-style-align-right {
        float: none;
        margin: 24px 0;
    }

    .kb-body iframe,
    .ck-content iframe {
        min-height: 220px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .kb-toc a,
    .kb-toc a::before,
    .kb-article-card {
        transition-duration: 0ms;
    }

    .kb-toc a.is-active,
    .kb-article-card:hover {
        transform: none;
    }
}

@media (prefers-reduced-transparency: reduce) {
    .kb-toc-inner {
        backdrop-filter: none;
    }
}
