/* ─────────────────────────────────────────────────────────────────────────────
   Knowledge base — reading.

   Documentation, not dashboard: a measured column, generous line height, and
   headings you can find at a glance. Uses the CRM's own theme variables, so it
   follows light and dark with everything else.
   ───────────────────────────────────────────────────────────────────────────── */

.kb-page {
    max-width: 72rem;
    margin: 0 auto;
    padding-bottom: 3rem;
}

/* ── Masthead and search ── */

.kb-masthead {
    padding: 0.5rem 0 1.75rem;
}

.kb-masthead-tight {
    padding-bottom: 1.25rem;
}

.kb-masthead h1 {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin: 0 0 0.35rem;
    font-size: clamp(1.6rem, 3vw, 2.1rem);
}

.kb-masthead h1 .lni {
    color: var(--text-muted);
    font-size: 0.85em;
}

.kb-masthead p {
    max-width: 44rem;
    margin: 0;
    color: var(--text-muted);
}

.kb-search {
    position: relative;
    max-width: 34rem;
    margin-top: 1.25rem;
}

.kb-search > .lni {
    position: absolute;
    top: 50%;
    left: 0.9rem;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
}

.kb-search .form-control {
    height: 3rem;
    padding-left: 2.6rem;
    padding-right: 2.6rem;
    border-radius: 999px;
}

.kb-search-clear {
    position: absolute;
    top: 50%;
    right: 0.6rem;
    transform: translateY(-50%);
    padding: 0.35rem 0.5rem;
    border: 0;
    border-radius: 50%;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
}

.kb-search-clear:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* ── Sections, cards and lists ── */

.kb-section {
    margin-bottom: 2.25rem;
}

.kb-section > h2 {
    margin: 0 0 0.85rem;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.kb-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
    gap: 0.85rem;
}

.kb-card {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    padding: 1.15rem 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: 0.9rem;
    background: var(--bg-card, var(--bg-elevated));
    color: var(--text-primary);
    text-decoration: none;
    transition: border-color 120ms ease, transform 120ms ease;
}

.kb-card:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.kb-card > .lni {
    margin-bottom: 0.35rem;
    color: var(--text-muted);
    font-size: 1.4rem;
}

.kb-card-title {
    font-size: 1.05rem;
    font-weight: 600;
    line-height: 1.3;
}

.kb-card-text {
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.45;
}

.kb-card-meta {
    margin-top: 0.35rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.kb-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.kb-item {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1.1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    background: var(--bg-card, var(--bg-elevated));
    color: var(--text-primary);
    text-decoration: none;
}

.kb-item:hover {
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.kb-item-main {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.kb-item-title {
    font-weight: 600;
}

.kb-item-title .lni {
    margin-left: 0.35rem;
    color: var(--text-muted);
    font-size: 0.85em;
}

.kb-item-summary {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.kb-item-path {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.kb-item-date {
    flex: none;
    color: var(--text-muted);
    font-size: 0.82rem;
    white-space: nowrap;
}

.kb-empty {
    color: var(--text-muted);
}

/* ── Breadcrumbs ── */

.kb-crumbs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.4rem;
    margin-bottom: 1rem;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.kb-crumbs a {
    color: var(--text-muted);
    text-decoration: none;
}

.kb-crumbs a:hover {
    color: var(--text-primary);
}

.kb-crumbs .lni {
    font-size: 0.7em;
}

/* ── The article ── */

.kb-article-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1.5rem;
}

.kb-article-headings h1 {
    margin: 0 0 0.4rem;
    font-size: clamp(1.7rem, 3.2vw, 2.3rem);
    line-height: 1.2;
}

.kb-article-summary {
    max-width: 48rem;
    margin: 0;
    color: var(--text-muted);
    font-size: 1.05rem;
}

.kb-article-tools {
    display: flex;
    flex: none;
    gap: 0.5rem;
}

.kb-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 2rem;
    margin: 1.25rem 0 1.5rem;
    padding: 0.85rem 1.1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    background: var(--bg-elevated);
    font-size: 0.88rem;
}

.kb-meta dt {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.kb-meta dd {
    margin: 0.1rem 0 0;
}

.kb-article-body-wrap {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 15rem;
    gap: 2.5rem;
    align-items: start;
}

@media (max-width: 991.98px) {
    .kb-article-body-wrap { grid-template-columns: minmax(0, 1fr); }
    .kb-contents { order: -1; }
}

.kb-contents {
    position: sticky;
    top: 1.5rem;
    padding: 1rem 1.1rem;
    border: 1px solid var(--border-color);
    border-radius: 0.75rem;
    background: var(--bg-elevated);
}

.kb-contents h2 {
    margin: 0 0 0.6rem;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.kb-contents ol {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin: 0;
    padding: 0;
    list-style: none;
    font-size: 0.88rem;
}

.kb-contents a {
    color: var(--text-muted);
    text-decoration: none;
}

.kb-contents a:hover {
    color: var(--text-primary);
}

.kb-contents-sub {
    padding-left: 0.9rem;
}

/* The article itself: what the editor writes, styled to read like a document. */

.kb-body {
    max-width: 48rem;
    font-size: 1rem;
    line-height: 1.7;
}

.kb-body > *:first-child { margin-top: 0; }

.kb-body h2 {
    margin: 2.2rem 0 0.7rem;
    font-size: 1.45rem;
    scroll-margin-top: 1.5rem;
}

.kb-body h3 {
    margin: 1.8rem 0 0.5rem;
    font-size: 1.18rem;
    scroll-margin-top: 1.5rem;
}

.kb-body h4 {
    margin: 1.5rem 0 0.4rem;
    font-size: 1.02rem;
}

.kb-body p,
.kb-body ul,
.kb-body ol {
    margin: 0 0 1rem;
}

.kb-body li + li {
    margin-top: 0.35rem;
}

.kb-body img {
    max-width: 100%;
    height: auto;
    margin: 0.5rem 0 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
}

.kb-body figure {
    margin: 1.25rem 0;
}

.kb-body figcaption {
    color: var(--text-muted);
    font-size: 0.85rem;
    text-align: center;
}

.kb-body blockquote {
    margin: 1.25rem 0;
    padding: 0.85rem 1.1rem;
    border-left: 4px solid var(--border-hover);
    border-radius: 0 0.5rem 0.5rem 0;
    background: var(--bg-elevated);
}

.kb-body blockquote > *:last-child { margin-bottom: 0; }

.kb-body pre {
    margin: 1.25rem 0;
    padding: 0.9rem 1.1rem;
    overflow-x: auto;
    border: 1px solid var(--border-color);
    border-radius: 0.5rem;
    background: var(--bg-elevated);
}

.kb-body code,
.kb-body kbd,
.kb-body samp {
    padding: 0.1rem 0.35rem;
    border-radius: 0.3rem;
    background: var(--bg-elevated);
    font-family: 'JetBrains Mono', Consolas, monospace;
    font-size: 0.88em;
}

.kb-body pre code {
    padding: 0;
    background: none;
}

.kb-body table {
    width: 100%;
    margin: 1.25rem 0;
    border-collapse: collapse;
    font-size: 0.94rem;
}

.kb-body th,
.kb-body td {
    padding: 0.5rem 0.7rem;
    border: 1px solid var(--border-color);
    text-align: left;
    vertical-align: top;
}

.kb-body th {
    background: var(--bg-elevated);
    font-weight: 600;
}

.kb-body hr {
    margin: 2rem 0;
    border: 0;
    border-top: 1px solid var(--border-color);
}

/* ── Printing an article ── */

@media print {
    .sidebar,
    #topNavbar,
    .kb-crumbs,
    .kb-article-tools,
    .kb-contents,
    .toast-container {
        display: none !important;
    }

    .kb-page,
    .kb-body {
        max-width: none;
    }

    .kb-article-body-wrap {
        display: block;
    }

    .kb-body {
        font-size: 11pt;
    }

    /* A heading shouldn't be the last thing on a page, and a screenshot shouldn't be
       split across two. */
    .kb-body h2,
    .kb-body h3,
    .kb-body h4 {
        break-after: avoid;
    }

    .kb-body img,
    .kb-body pre,
    .kb-body table {
        break-inside: avoid;
    }

    .kb-meta {
        border: 0;
        padding-left: 0;
    }

    a[href^="http"]::after {
        content: " (" attr(href) ")";
        font-size: 0.85em;
        word-break: break-all;
    }
}

/* The line of an article that matched a search, with the words picked out. */
.kb-item-snippet {
    margin-top: 0.15rem;
    color: var(--text-secondary);
    font-size: 0.86rem;
    line-height: 1.5;
}

.kb-item-snippet mark {
    padding: 0 0.15rem;
    border-radius: 0.2rem;
    background: var(--accent-primary-muted);
    color: var(--text-primary);
}

/* ── Files that come with an article ── */

.kb-downloads {
    max-width: 48rem;
    margin-top: 2.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}

.kb-downloads h2 {
    margin: 0 0 0.85rem;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.kb-files {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.kb-files > li {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.7rem 0.9rem;
    border: 1px solid var(--border-color);
    border-radius: 0.6rem;
    background: var(--bg-elevated);
}

.kb-file-icon {
    flex: none;
    color: var(--text-muted);
    font-size: 1.2rem;
}

.kb-file-text {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    flex: 1;
    min-width: 0;
}

.kb-file-name {
    overflow: hidden;
    font-weight: 600;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kb-file-note-text {
    color: var(--text-secondary);
    font-size: 0.86rem;
}

.kb-file-size {
    color: var(--text-muted);
    font-size: 0.78rem;
    font-variant-numeric: tabular-nums;
}

/* In the editor the description is written in place, so the list stays one thing
   rather than a list plus a form. */
.kb-files-editing > li {
    align-items: flex-start;
    padding: 0.6rem 0.7rem;
}

.kb-file-note {
    margin: 0.2rem 0;
}
