/* ============================================================
   KB System – Frontend Styles
   ============================================================ */

/* Wrapper */
.kb-grid-wrap {
    width: 100%;
    box-sizing: border-box;
}

/* ── CSS Grid layout ─────────────────────────────────────────── */
.kb-layout-grid {
    display: grid;
    grid-template-columns: repeat(var(--kb-cols, 3), 1fr);
    gap: 24px;
}

/* Set CSS variable from data attribute via a small trick:
   We use attribute selectors for common column counts. */
.kb-layout-grid[data-columns="1"] { --kb-cols: 1; }
.kb-layout-grid[data-columns="2"] { --kb-cols: 2; }
.kb-layout-grid[data-columns="3"] { --kb-cols: 3; }
.kb-layout-grid[data-columns="4"] { --kb-cols: 4; }
.kb-layout-grid[data-columns="5"] { --kb-cols: 5; }
.kb-layout-grid[data-columns="6"] { --kb-cols: 6; }

/* ── Masonry layout ──────────────────────────────────────────── */
/* Masonry positioning is handled by the inline JS */
.kb-layout-masonry {
    /* position:relative set by JS */
}

/* ── Card ────────────────────────────────────────────────────── */
.kb-card {
    background: #ffffff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 4px rgba(0,0,0,.06);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
    display: flex;
    flex-direction: column;
}

.kb-card:hover {
    box-shadow: 0 6px 20px rgba(0,0,0,.10);
    transform: translateY(-2px);
}

/* ── Card header (colored band) ──────────────────────────────── */
.kb-card-header {
    padding: 18px 20px 16px;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

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

.kb-card-title a {
    text-decoration: none;
}

.kb-card-title a:hover {
    text-decoration: underline;
    text-underline-offset: 3px;
}

/* ── Badge (article count) ───────────────────────────────────── */
.kb-badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    margin-top: 2px;
}

/* ── Card body ───────────────────────────────────────────────── */
.kb-card-body {
    padding: 16px 20px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.kb-card-desc {
    margin: 0 0 14px;
    font-size: 0.88rem;
    color: #4b5563;
    line-height: 1.55;
}

/* ── Article list ────────────────────────────────────────────── */
.kb-article-list {
    list-style: none;
    margin: 0 0 14px;
    padding: 0;
    flex: 1;
}

.kb-article-list li {
    border-bottom: 1px solid #f3f4f6;
    padding: 6px 0;
}

.kb-article-list li:first-child {
    padding-top: 0;
}

.kb-article-list li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.kb-article-link {
    font-size: 0.875rem;
    color: #374151;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.15s;
}

.kb-article-link::before {
    content: '›';
    font-size: 1rem;
    color: #9ca3af;
    flex-shrink: 0;
}

.kb-article-link:hover {
    color: #111827;
}

.kb-no-articles {
    font-size: 0.85rem;
    color: #9ca3af;
    margin: 0 0 14px;
}

/* ── View all link ───────────────────────────────────────────── */
.kb-view-all {
    display: inline-block;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    margin-top: auto;
    padding-top: 4px;
    transition: opacity 0.15s;
}

.kb-view-all:hover {
    opacity: 0.75;
}

/* ── Empty state ─────────────────────────────────────────────── */
.kb-empty {
    color: #6b7280;
    font-style: italic;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 900px) {
    .kb-layout-grid[data-columns="4"],
    .kb-layout-grid[data-columns="5"],
    .kb-layout-grid[data-columns="6"] {
        --kb-cols: 3;
    }
}

@media (max-width: 640px) {
    .kb-layout-grid {
        --kb-cols: 1 !important;
    }

    .kb-layout-masonry .kb-card {
        position: static !important;
        width: 100% !important;
        margin-bottom: 20px;
    }

    .kb-layout-masonry {
        height: auto !important;
    }
}

/* ── Tabs layout ─────────────────────────────────────────────── */
.kb-tabs-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.kb-tab-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    border-radius: 8px;
    text-decoration: none;
    transition: opacity .15s, transform .15s;
    position: relative;
}

.kb-tab-item:hover {
    opacity: .92;
    transform: translateX(3px);
}

.kb-tab-number {
    font-size: 0.78rem;
    font-weight: 800;
    opacity: .55;
    min-width: 20px;
    flex-shrink: 0;
}

.kb-tab-title {
    font-size: 0.95rem;
    font-weight: 600;
    flex: 1;
}

.kb-tab-viewall {
    font-size: 0.78rem;
    font-weight: 500;
    opacity: 0;
    transition: opacity .15s;
    flex-shrink: 0;
}

.kb-tab-item:hover .kb-tab-viewall {
    opacity: .75;
}

/* Always visible on mobile */
@media (max-width: 640px) {
    .kb-tab-viewall {
        opacity: .65 !important;
    }
}

/* ── Minimal layout ──────────────────────────────────────────── */
.kb-minimal-wrap {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
}

.kb-minimal-wrap[data-columns="1"] { grid-template-columns: repeat(1, 1fr); }
.kb-minimal-wrap[data-columns="2"] { grid-template-columns: repeat(2, 1fr); }
.kb-minimal-wrap[data-columns="3"] { grid-template-columns: repeat(3, 1fr); }
.kb-minimal-wrap[data-columns="4"] { grid-template-columns: repeat(4, 1fr); }

.kb-minimal-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /*height: 160px;*/
    height: 220px;
    border-radius: 10px;
    text-decoration: none;
    padding: 20px;
    text-align: center;
    overflow: hidden;
    transition: transform .2s ease, box-shadow .2s ease;
    
}

.kb-minimal-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 10px 28px rgba(0,0,0,.15);
}

.kb-minimal-number {
    /*font-size: 0.7rem;*/
    font-size: 2.7rem;
    /*font-weight: 800;*/
    font-weight: 300;
    opacity: .45;
    letter-spacing: .08em;
    margin-bottom: 6px;
    
}

.kb-minimal-title {
    /*font-size: 1rem;*/
    font-size: 1.5rem;
    /*font-weight: 700;*/
    font-weight: 500;
    line-height: 1.3;
    
}

.kb-minimal-viewall {
    position: absolute;
    bottom: 14px;
    left: 0;
    right: 0;
    text-align: center;
    font-size: 0.75rem;
    font-weight: 600;
    opacity: 0;
    transform: translateY(4px);
    transition: opacity .2s ease, transform .2s ease;
    
}

.kb-minimal-card:hover .kb-minimal-viewall {
    opacity: .8;
    transform: translateY(0);
}

/* Always visible on mobile */
@media (max-width: 640px) {
    .kb-minimal-wrap {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .kb-minimal-viewall {
        opacity: .7 !important;
        transform: translateY(0) !important;
    }
}



/* ── Search form shortcode ──────────────────────────────────────────── */
/* ── Wrapper ─────────────────────────────────────────────────── */
.kb-search-wrap {
    position: relative;
    display: inline-block;
}

/* ── Trigger button ──────────────────────────────────────────── */
.kb-search-trigger {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: none;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
    font-size: 0.9rem;
    color: #374151;
    transition: border-color .15s, background .15s;
}
.kb-search-trigger:hover {
    border-color: #9ca3af;
    background: #f9fafb;
}

/* ── Panel ───────────────────────────────────────────────────── */
.kb-search-panel {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    z-index: 9999;
    width: 360px;
    background: #fff;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    box-shadow: 0 8px 30px rgba(0,0,0,.12);
    overflow: hidden;
}

/* ── Input row ───────────────────────────────────────────────── */
.kb-search-input-wrap {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #f3f4f6;
}
.kb-search-input-icon {
    flex-shrink: 0;
    color: #9ca3af;
}
.kb-search-field {
    flex: 1;
    border: none;
    outline: none;
    font-size: 0.93rem;
    color: #111827;
    background: transparent;
}
.kb-search-field::placeholder { color: #9ca3af; }
.kb-search-close {
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    color: #9ca3af;
    line-height: 1;
    border-radius: 4px;
    transition: color .15s, background .15s;
}
.kb-search-close:hover { color: #374151; background: #f3f4f6; }

/* ── Results list ────────────────────────────────────────────── */
.kb-search-results {
    list-style: none;
    margin: 0;
    padding: 6px 0;
    max-height: 340px;
    overflow-y: auto;
}

/* ── Result item ─────────────────────────────────────────────── */
.kb-sr-item { margin: 0; }
.kb-sr-link {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 2px 8px;
    padding: 10px 14px;
    text-decoration: none;
    color: inherit;
    transition: background .12s;
}
.kb-sr-link:hover,
.kb-sr-item.is-active .kb-sr-link {
    background: #f9fafb;
}
.kb-sr-title {
    grid-column: 1;
    grid-row: 1;
    font-size: 0.9rem;
    font-weight: 600;
    color: #111827;
    line-height: 1.35;
}
.kb-sr-title mark {
    background: #fef08a;
    color: inherit;
    border-radius: 2px;
    padding: 0 1px;
}
.kb-sr-cat {
    grid-column: 2;
    grid-row: 1;
    font-size: 0.7rem;
    font-weight: 600;
    border: 1px solid;
    border-radius: 20px;
    padding: 2px 8px;
    white-space: nowrap;
    align-self: start;
}
.kb-sr-excerpt {
    grid-column: 1 / -1;
    grid-row: 2;
    font-size: 0.78rem;
    color: #6b7280;
    line-height: 1.45;
}

/* ── States ──────────────────────────────────────────────────── */
.kb-sr-empty,
.kb-sr-loading {
    padding: 14px 16px;
    font-size: 0.875rem;
    color: #9ca3af;
    display: flex;
    align-items: center;
    gap: 8px;
}
.kb-sr-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid #e5e7eb;
    border-top-color: #6b7280;
    border-radius: 50%;
    animation: kb-spin .6s linear infinite;
    flex-shrink: 0;
}
@keyframes kb-spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 480px) {
    .kb-search-panel {
        width: calc(100vw - 32px);
        left: 50%;
        transform: translateX(-50%);
    }
}


/* ── KB Archive ──────────────────────────────────────────────── */
.kb-archive-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px 60px;
    min-height: 100vh;
}

.kb-archive-header {
    margin: 0 -20px 40px;
    padding: 48px 20px;
}

.kb-archive-header-inner {
    max-width: 1060px;
    margin: 0 auto;
}

.kb-archive-title {
    font-size: 2rem;
    font-weight: 800;
    margin: 0 0 10px;
    line-height: 1.2;
}

.kb-archive-desc {
    font-size: 1rem;
    margin: 0 0 16px;
    opacity: .85;
    max-width: 580px;
    line-height: 1.6;
}

.kb-archive-count {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 600;
}

/* ── Sitemap list ────────────────────────────────────────────── */
.kb-sitemap-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 4px 32px;
}

.kb-sitemap-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 6px;
    font-size: 0.9rem;
    color: #374151;
    text-decoration: none;
    border-bottom: 1px solid #f3f4f6;
    transition: color .15s;
}

.kb-sitemap-link svg {
    color: var(--kb-accent, #4f46e5);
    flex-shrink: 0;
    transition: transform .15s;
}

.kb-sitemap-link:hover {
    color: var(--kb-accent, #4f46e5);
}

.kb-sitemap-link:hover svg {
    transform: translateX(2px);
}

.kb-archive-empty {
    color: #9ca3af;
    font-style: italic;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 600px) {
    .kb-sitemap-list {
        grid-template-columns: 1fr;
    }

    .kb-archive-title {
        font-size: 1.5rem;
    }
}

/* ════════════════════════════════════════════════════════════
   KB Single Article
   ════════════════════════════════════════════════════════════ */

.kb-single-wrap {
    display: grid;
    grid-template-columns: 240px 1fr 220px;
    gap: 0 32px;
    max-width: 1140px;
    margin: 0 auto;
    padding: 40px 20px 80px;
    align-items: start;
}

/* ── Sidebars ────────────────────────────────────────────────── */
.kb-sidebar-sticky {
    position: sticky;
    top: 32px;
    max-height: calc(100vh - 64px);
    overflow-y: auto;
}

/* Scrollbar styling */
.kb-sidebar-sticky::-webkit-scrollbar { width: 4px; }
.kb-sidebar-sticky::-webkit-scrollbar-track { background: transparent; }
.kb-sidebar-sticky::-webkit-scrollbar-thumb { background: #e5e7eb; border-radius: 4px; }

/* ── Left sidebar ────────────────────────────────────────────── */
.kb-sidebar-header {
    border-radius: 8px 8px 0 0;
    padding: 12px 16px;
    margin-bottom: 0;
}

.kb-sidebar-cat-link {
    font-size: 0.82rem;
    font-weight: 700;
    text-decoration: none;
    opacity: .9;
    display: block;
}

.kb-sidebar-cat-link:hover { opacity: 1; }

.kb-sidebar-list {
    list-style: none;
    margin: 0;
    padding: 0;
    border: 1px solid #e5e7eb;
    border-top: none;
    border-radius: 0 0 8px 8px;
    overflow: hidden;
}

.kb-sidebar-item {
    margin: 0;
    border-bottom: 1px solid #f3f4f6;
}

.kb-sidebar-item:last-child { border-bottom: none; }

.kb-sidebar-link,
.kb-sidebar-current {
    display: block;
    padding: 9px 14px;
    font-size: 0.85rem;
    line-height: 1.4;
    text-decoration: none;
    color: #374151;
    transition: background .12s, color .12s;
}

.kb-sidebar-link:hover {
    background: #f9fafb;
    color: #111827;
}

.kb-sidebar-current {
    border-left: 3px solid;
    padding-left: 11px;
    font-weight: 600;
    background: #fafafa;
}

/* ── Main content ────────────────────────────────────────────── */
.kb-single-header {
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid #e5e7eb;
}

.kb-single-cat-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
    margin-bottom: 12px;
}

.kb-single-title {
    font-size: 1.9rem;
    font-weight: 800;
    line-height: 1.25;
    color: #111827;
    margin: 0 0 10px;
}

.kb-single-meta {
    font-size: 0.8rem;
    color: #9ca3af;
}

.kb-single-body {
    font-size: 0.975rem;
    line-height: 1.75;
    color: #1f2937;
}

.kb-single-body h2,
.kb-single-body h3,
.kb-single-body h4 {
    margin-top: 2em;
    margin-bottom: .6em;
    font-weight: 700;
    color: #111827;
    scroll-margin-top: 48px;
}

.kb-single-body h2 { font-size: 1.35rem; }
.kb-single-body h3 { font-size: 1.1rem; }
.kb-single-body h4 { font-size: 0.975rem; }

.kb-single-body p { margin-bottom: 1.25em; }

.kb-single-body a {
    color: #4f46e5;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.kb-single-body ul,
.kb-single-body ol {
    padding-left: 1.5em;
    margin-bottom: 1.25em;
}

.kb-single-body li { margin-bottom: .4em; }

.kb-single-body img {
    max-width: 100%;
    height: auto;
    border-radius: 6px;
}

.kb-single-body code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.875em;
}

.kb-single-body pre {
    background: #1f2937;
    color: #f9fafb;
    padding: 16px 20px;
    border-radius: 8px;
    overflow-x: auto;
    margin-bottom: 1.25em;
}

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

.kb-single-body blockquote {
    border-left: 3px solid #e5e7eb;
    margin: 0 0 1.25em;
    padding: 8px 0 8px 20px;
    color: #6b7280;
    font-style: italic;
}

/* ── Post nav ────────────────────────────────────────────────── */
.kb-single-footer {
    margin-top: 48px;
    padding-top: 24px;
    border-top: 1px solid #e5e7eb;
}

.kb-post-nav {
    display: flex;
    justify-content: space-between;
    gap: 16px;
}

.kb-post-nav-link {
    display: flex;
    flex-direction: column;
    gap: 4px;
    text-decoration: none;
    max-width: 45%;
}

.kb-post-nav-next { text-align: right; margin-left: auto; }

.kb-post-nav-label {
    font-size: 0.75rem;
    color: #9ca3af;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
}

.kb-post-nav-title {
    font-size: 0.875rem;
    color: #374151;
    font-weight: 600;
    transition: color .15s;
}

.kb-post-nav-link:hover .kb-post-nav-title { color: #111827; }

/* ── ToC (right sidebar) ─────────────────────────────────────── */
.kb-toc-header {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #9ca3af;
    margin-bottom: 10px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.kb-toc-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.kb-toc-list li { margin: 0; }

.kb-toc-link {
    display: block;
    font-size: 0.82rem;
    color: #6b7280;
    text-decoration: none;
    padding: 5px 0 5px 10px;
    border-left: 2px solid transparent;
    line-height: 1.4;
    transition: color .15s, border-color .15s;
}

.kb-toc-link:hover { color: #111827; }

.kb-toc-link.is-active {
    color: #111827;
    font-weight: 600;
    border-left-color: #4f46e5; /* overridden by JS with category color */
}

.kb-toc-h3 { padding-left: 20px; font-size: 0.78rem; }
.kb-toc-h4 { padding-left: 30px; font-size: 0.75rem; }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .kb-single-wrap {
        grid-template-columns: 200px 1fr;
        grid-template-rows: auto auto;
    }
    .kb-sidebar-right {
        grid-column: 1 / -1;
        order: 3;
    }
    .kb-toc { display: none; } /* hide ToC on tablet, too cluttered */
}

@media (max-width: 680px) {
    .kb-single-wrap {
        grid-template-columns: 1fr;
    }
    .kb-sidebar-left {
        order: 2;
    }
    .kb-single-content {
        order: 1;
    }
    .kb-sidebar-sticky {
        position: static;
        max-height: none;
    }
}