/*
 * kb-article.css - shared styles for baza-wiedzy/*.php full-article pages.
 * Distilled from kredyt-dla-it.php's layout (grid/TOC/scroll-spy/callouts),
 * with the redundant left-sidebar TOC duplicate + broken mobile-drawer
 * trigger dropped in favor of a working collapsible "Spis treści" box on
 * mobile (docs/baza-wiedzy-plan.md §4, variant A).
 */

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    scroll-padding-top: 100px;
}

/* ---------- Layout grid: content + sticky right TOC ---------- */

#kb-main-grid {
    display: grid;
    grid-template-columns: minmax(0, 760px) 260px;
    gap: 3rem;
    justify-content: center;
    align-items: start;
}

@media (max-width: 1023px) {
    #kb-main-grid {
        display: block;
    }

    #kb-col-right {
        display: none !important;
    }
}

#kb-col-right {
    position: sticky;
    top: 8rem;
    max-height: calc(100vh - 9rem);
    overflow-y: auto;
}

#kb-col-right.kb-collapsed {
    display: none !important;
}

/* ---------- Right TOC (desktop, scroll-spy) ---------- */

.toc-link {
    border-left-width: 2px;
    border-left-color: transparent;
    padding-left: 1rem;
}

.toc-link:hover {
    border-left-color: #93c5fd;
}

.toc-link.active {
    color: #2563eb;
    border-left-color: #2563eb;
}

/* Wing-expand button that re-shows a collapsed right TOC column */
#wing-expand-right {
    display: none;
}

/* ---------- Mobile collapsible TOC ("Spis treści") ---------- */

#kb-mobile-toc-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
}

#kb-mobile-toc-panel.kb-open {
    max-height: 32rem;
}

#kb-mobile-toc-toggle .kb-toc-chevron {
    transition: transform 0.2s ease;
}

#kb-mobile-toc-toggle[aria-expanded="true"] .kb-toc-chevron {
    transform: rotate(180deg);
}

/* ---------- Reading progress bar ---------- */

.read-progress-bar {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0%;
    background: #2563eb;
    z-index: 70;
    transition: width 0.1s linear;
}

/* ---------- Fade-up-on-scroll ----------
 * NOTE: content always starts fully visible (no opacity:0 default). An
 * earlier version hid callouts/checklist items until an IntersectionObserver
 * flipped an `.is-visible` class - a full-page capture in testing showed
 * this can leave real content (a red/yellow callout with bank names)
 * permanently invisible if the observer callback races the render. Since
 * these boxes carry real information, not decoration, they must never
 * depend on JS to become visible. `.is-visible` still adds a subtle lift-in
 * transition when JS *does* fire in time, but nothing is hidden without it.
 */

.fade-up-element {
    transform: translateY(6px);
    transition: transform 0.4s ease;
}

.fade-up-element.is-visible {
    transform: translateY(0);
}

/* ---------- Checklist cascade reveal (same guarantee as above) ---------- */

.checklist-item {
    transform: translateY(6px);
    transition: transform 0.3s ease;
}

.checklist-item.is-visible {
    transform: translateY(0);
}

/* ---------- Comparison / data tables ---------- */

.article-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.article-table th {
    text-align: left;
    padding: 0.75rem 1rem;
    background: #f8fafc;
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    color: #475569;
    border-bottom: 1px solid #e2e8f0;
}

.article-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: top;
}

.article-table tr:last-child td {
    border-bottom: none;
}

.article-table tr:hover td {
    background: #f8fafc;
}

@media (max-width: 640px) {
    .article-table {
        display: block;
        overflow-x: auto;
        white-space: nowrap;
    }
}

/* ============================================================
   MOBILE ARTICLE CHROME (<=767px) - wzorzec jak baza wiedzy /faq:
   niski przyklejony pasek u góry z wystającym logo (klik -> /faq)
   i rozwijanym "Spis treści" (na start zwinięty), oraz dolny
   przyklejony pasek CTA (Zadzwoń / Umów spotkanie) przy scrollu.
   Desktop nietknięty (nav-sub + prawy sticky TOC).
   ============================================================ */

/* Górny pasek: domyślnie ukryty (desktop go nie używa) */
#kb-article-bar {
    display: none;
}

/* Breadcrumb "← Baza wiedzy" tylko na mobile - na desktopie zbędny (w nav-sub
   jest link "Baza wiedzy"). Na mobile zostaje jako czytelna droga powrotu. */
@media (min-width: 768px) {
    .kb-breadcrumb {
        display: none;
    }
}

@media (max-width: 767px) {
    /* Współdzielony pasek nav-sub (logo 80px + "Umów rozmowę") off na artykule -
       zastępuje go niższy pasek artykułu. Zakres: TYLKO strony z klasą
       .kb-article-page (nowy szablon). Stare artykuły bez tej klasy zostają
       nietknięte (mają swój pasek nav-sub, dopóki nie zostaną wymienione).
       Celujemy w bezpośrednie dziecko body, NIE w <nav> panelu spisu (też bez id). */
    body.kb-article-page > nav:not([id]) {
        display: none !important;
    }

    #kb-article-bar {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        z-index: 55;
        padding: 0.4rem 0.75rem;
        background: #fff;
        border-bottom: 1px solid #e2e8f0;
        box-shadow: 0 1px 3px rgb(15 23 42 / 8%);
    }

    /* Logo-medalion, wystaje ~16px pod pasek; klik -> baza wiedzy */
    #kb-artbar-logo {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex-shrink: 0;
        position: relative;
        z-index: 2;
        width: 50px;
        height: 50px;
        border-radius: 50%;
        background: rgb(255 255 255 / 95%);
        box-shadow: 0 3px 8px rgb(37 99 235 / 15%);
        margin: -2px 0 -16px;
    }

    #kb-artbar-logo img {
        width: 44px;
        height: 44px;
        object-fit: contain;
    }

    /* Przycisk "Spis treści" = pigułka jak "Filtry" na /faq */
    #kb-article-bar #kb-mobile-toc-toggle {
        flex: 1 1 auto;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0.5rem;
        padding: 0.5rem 1rem;
        border-radius: 9999px;
        border: 1px solid #cfe0fd;
        background: #fff;
        font-size: 0.875rem;
        font-weight: 600;
        color: #1e3a5f;
    }

    /* Panel spisu: pełna szerokość pod paskiem; reużywa #kb-mobile-toc-panel
       (max-height:0 -> .kb-open). Tu tylko rozmiar/scroll i wygląd linków. */
    #kb-article-bar #kb-mobile-toc-panel {
        flex-basis: 100%;
    }

    #kb-article-bar #kb-mobile-toc-panel.kb-open {
        max-height: 70vh;
        overflow-y: auto;
    }

    #kb-article-bar #kb-mobile-toc-panel nav {
        display: flex;
        flex-direction: column;
        gap: 0.15rem;
        padding: 0.5rem 0.25rem 0.25rem;
        border-top: 1px solid #f1f5f9;
        margin-top: 0.4rem;
    }

    #kb-article-bar #kb-mobile-toc-panel nav a {
        padding: 0.5rem;
        border-radius: 0.5rem;
        font-size: 0.9rem;
        font-weight: 500;
        color: #334155;
        text-decoration: none;
    }

    #kb-article-bar #kb-mobile-toc-panel nav a:hover,
    #kb-article-bar #kb-mobile-toc-panel nav a:active {
        background: #eff6ff;
        color: #2563eb;
    }

    /* Hero nie chowa się pod pasek, ale bez nadmiaru pustki (pt-40 = 10rem za dużo) */
    section.kb-hero {
        padding-top: 5rem;
    }
}

/* ---------- Dolny przyklejony pasek CTA (mobile) ---------- */
.kb-mobile-cta {
    display: none;
}

.kb-cta-call {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 12px;
    border: 2px solid #2563eb;
    color: #2563eb;
    font-weight: 700;
    font-size: 15px;
    text-decoration: none;
    background: #fff;
}

.kb-cta-book {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border-radius: 12px;
    background: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
    border: none;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-family: inherit;
    text-decoration: none;
}

.kb-cta-call svg,
.kb-cta-book svg {
    width: 18px;
    height: 18px;
}

@media (max-width: 767px) {
    .kb-article-page .kb-mobile-cta {
        display: flex;
        gap: 10px;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 60;
        padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
        background: rgb(255 255 255 / 96%);
        backdrop-filter: blur(8px);
        /* stylelint-disable-next-line property-no-vendor-prefix -- iOS <16.4 wymaga prefiksu, brak autoprefixera w projekcie */
        -webkit-backdrop-filter: blur(8px);
        box-shadow: 0 -4px 20px rgb(15 23 42 / 12%);
        visibility: hidden;
        transform: translateY(110%);
        transition: transform 0.3s ease, visibility 0.3s;
    }

    .kb-article-page .kb-mobile-cta.visible {
        visibility: visible;
        transform: translateY(0);
    }
}
