/**
 * Globalne style tabel — treść WP, blok Table, edytor.
 * Wykluczenia: porównywarka (.np-pko__), tabele admina (.form-table, .np-cfg__).
 */

:root {
    --np-table-border: rgb(10 10 10 / 0.08);
    --np-table-border-strong: rgb(10 10 10 / 0.12);
    --np-table-head-bg: #f3f6f2;
    --np-table-stripe: rgb(57 115 45 / 0.045);
    --np-table-hover: rgb(57 115 45 / 0.07);
    --np-table-radius: 12px;
    --np-table-cell-pad-y: clamp(0.65rem, 1.4vw, 0.85rem);
    --np-table-cell-pad-x: clamp(0.75rem, 1.8vw, 1.1rem);
}

/* --- Kontener bloku / przewijanie poziome --- */
.wp-block-table,
.single-post-content > table,
.entry-content > table,
.site-main .wp-block-post-content > table,
main .wp-block-group > table {
    width: 100%;
    max-width: var(--article-content-width, min(1240px, calc(100vw - 48px)));
    margin: clamp(1.35rem, 3.2vw, 2rem) auto;
    padding: 0;
    box-sizing: border-box;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--np-table-radius);
    border: 1px solid var(--np-table-border);
    background: var(--palette-paper, #fff);
    box-shadow:
        0 1px 0 rgb(255 255 255 / 0.9) inset,
        0 8px 28px -18px rgb(10 10 10 / 0.18);
    scrollbar-width: thin;
    scrollbar-color: rgb(57 115 45 / 0.35) transparent;
}

.wp-block-table::-webkit-scrollbar,
.single-post-content > table::-webkit-scrollbar {
    height: 6px;
}

.wp-block-table::-webkit-scrollbar-thumb,
.single-post-content > table::-webkit-scrollbar-thumb {
    background: rgb(57 115 45 / 0.35);
    border-radius: 999px;
}

/* Wyrównania bloku Gutenberg */
.wp-block-table.alignwide {
    max-width: var(--article-content-width, min(1240px, calc(100vw - 48px)));
    margin-left: auto;
    margin-right: auto;
}

.wp-block-table.alignfull {
    max-width: none;
    border-radius: 0;
    border-left: none;
    border-right: none;
}

.wp-block-table.aligncenter {
    margin-left: auto;
    margin-right: auto;
}

.wp-block-table.alignleft {
    margin-right: auto;
}

.wp-block-table.alignright {
    margin-left: auto;
}

/* --- Tabela --- */
.wp-block-table table,
.single-post-content > table,
.entry-content > table,
.site-main .wp-block-post-content > table,
main .wp-block-group > table,
.single-post-content table:not(.np-pko__table):not(.form-table),
.entry-content table:not(.np-pko__table):not(.form-table),
.wp-block-post-content table:not(.np-pko__table):not(.form-table) {
    width: 100%;
    min-width: 28rem;
    max-width: none;
    margin: 0;
    padding: 0;
    border-collapse: separate;
    border-spacing: 0;
    border: none;
    background: transparent;
    color: var(--palette-ink, #0a0a0a);
    font-size: clamp(0.8125rem, 1.35vw, 0.9375rem);
    line-height: 1.45;
    table-layout: auto;
}

.wp-block-table table {
    min-width: 100%;
    padding-left: 0;
    padding-right: 0;
    width: 100%;
}

/* Nagłówek */
.wp-block-table thead,
.single-post-content table:not(.np-pko__table) thead,
.entry-content table:not(.np-pko__table) thead,
.wp-block-post-content table:not(.np-pko__table) thead {
    background: var(--np-table-head-bg);
}

.wp-block-table th,
.single-post-content table:not(.np-pko__table) th,
.entry-content table:not(.np-pko__table) th,
.wp-block-post-content table:not(.np-pko__table) th {
    padding: var(--np-table-cell-pad-y) var(--np-table-cell-pad-x);
    font-weight: 600;
    font-size: clamp(0.72rem, 1.2vw, 0.8125rem);
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: left;
    color: var(--palette-brand, #39732d);
    background: var(--np-table-head-bg);
    border: none;
    border-bottom: 2px solid var(--palette-brand, #39732d);
    vertical-align: middle;
    white-space: nowrap;
}

.wp-block-table thead th:first-child,
.single-post-content table:not(.np-pko__table) thead th:first-child {
    border-top-left-radius: calc(var(--np-table-radius) - 1px);
}

.wp-block-table thead th:last-child,
.single-post-content table:not(.np-pko__table) thead th:last-child {
    border-top-right-radius: calc(var(--np-table-radius) - 1px);
}

/* Komórki */
.wp-block-table td,
.single-post-content table:not(.np-pko__table) td,
.entry-content table:not(.np-pko__table) td,
.wp-block-post-content table:not(.np-pko__table) td {
    padding: var(--np-table-cell-pad-y) var(--np-table-cell-pad-x);
    border: none;
    border-bottom: 1px solid var(--np-table-border);
    color: var(--palette-ink-muted, #222);
    vertical-align: top;
    background: transparent;
}

.wp-block-table tbody tr:last-child td,
.single-post-content table:not(.np-pko__table) tbody tr:last-child td,
.entry-content table:not(.np-pko__table) tbody tr:last-child td {
    border-bottom: none;
}

.wp-block-table tbody tr:last-child td:first-child,
.single-post-content table:not(.np-pko__table) tbody tr:last-child td:first-child {
    border-bottom-left-radius: calc(var(--np-table-radius) - 1px);
}

.wp-block-table tbody tr:last-child td:last-child,
.single-post-content table:not(.np-pko__table) tbody tr:last-child td:last-child {
    border-bottom-right-radius: calc(var(--np-table-radius) - 1px);
}

/* Hover wierszy */
.wp-block-table tbody tr:hover td,
.single-post-content table:not(.np-pko__table) tbody tr:hover td,
.entry-content table:not(.np-pko__table) tbody tr:hover td,
.wp-block-post-content table:not(.np-pko__table) tbody tr:hover td {
    background: var(--np-table-hover);
}

/* Paski (styl Gutenberg + domyślnie co drugi wiersz) */
.wp-block-table.is-style-stripes,
.wp-block-table.is-style-stripes table {
    border: 1px solid var(--np-table-border);
}

.wp-block-table.is-style-stripes tbody tr:nth-child(odd) td,
.single-post-content table:not(.np-pko__table) tbody tr:nth-child(even) td,
.entry-content table:not(.np-pko__table) tbody tr:nth-child(even) td,
.wp-block-post-content table:not(.np-pko__table) tbody tr:nth-child(even) td {
    background: var(--np-table-stripe);
}

.wp-block-table.is-style-stripes tbody tr:nth-child(odd):hover td,
.single-post-content table:not(.np-pko__table) tbody tr:nth-child(even):hover td {
    background: var(--np-table-hover);
}

/* Wyrównanie kolumn (klasy Gutenberg) */
.wp-block-table .has-text-align-left,
.wp-block-table th.has-text-align-left,
.wp-block-table td.has-text-align-left {
    text-align: left;
}

.wp-block-table .has-text-align-center,
.wp-block-table th.has-text-align-center,
.wp-block-table td.has-text-align-center {
    text-align: center;
}

.wp-block-table .has-text-align-right,
.wp-block-table th.has-text-align-right,
.wp-block-table td.has-text-align-right {
    text-align: right;
}

/* Pierwsza kolumna jako etykieta wiersza (częsty wzorzec) */
.wp-block-table tbody th,
.single-post-content table:not(.np-pko__table) tbody th,
.entry-content table:not(.np-pko__table) tbody th {
    font-weight: 600;
    text-transform: none;
    letter-spacing: -0.01em;
    font-size: inherit;
    color: var(--palette-ink, #0a0a0a);
    background: rgb(57 115 45 / 0.04);
    border-bottom: 1px solid var(--np-table-border);
    white-space: normal;
}

/* Stopka tabeli */
.wp-block-table tfoot td,
.wp-block-table tfoot th,
.single-post-content table:not(.np-pko__table) tfoot td,
.single-post-content table:not(.np-pko__table) tfoot th {
    padding: var(--np-table-cell-pad-y) var(--np-table-cell-pad-x);
    font-weight: 600;
    background: var(--np-table-head-bg);
    border-top: 1px solid var(--np-table-border-strong);
    border-bottom: none;
    color: var(--palette-ink, #0a0a0a);
}

/* Podpis */
.wp-block-table figcaption,
.wp-block-table caption,
.single-post-content table caption,
.entry-content table caption {
    caption-side: bottom;
    padding: 0.75rem 1rem 0.85rem;
    margin: 0;
    font-size: clamp(0.75rem, 1.25vw, 0.8125rem);
    line-height: 1.4;
    color: rgb(10 10 10 / 0.55);
    text-align: left;
    background: rgb(10 10 10 / 0.02);
    border-top: 1px solid var(--np-table-border);
}

.wp-block-table figcaption {
    border-radius: 0 0 var(--np-table-radius) var(--np-table-radius);
}

/* Linki w komórkach */
.wp-block-table a,
.single-post-content table:not(.np-pko__table) a,
.entry-content table:not(.np-pko__table) a {
    color: var(--palette-brand, #39732d);
    text-decoration: underline;
    text-decoration-color: rgb(57 115 45 / 0.35);
    text-underline-offset: 0.15em;
}

.wp-block-table a:hover,
.single-post-content table:not(.np-pko__table) a:hover {
    text-decoration-color: var(--palette-brand, #39732d);
}

/* Kod / liczby w komórkach */
.wp-block-table code,
.single-post-content table:not(.np-pko__table) code {
    font-size: 0.9em;
    padding: 0.12em 0.35em;
    border-radius: 4px;
    background: rgb(10 10 10 / 0.05);
}

/* --- Mobile --- */
@media (max-width: 640px) {
    .wp-block-table,
    .single-post-content > table,
    .entry-content > table {
        margin-top: 1.15rem;
        margin-bottom: 1.15rem;
        border-radius: 10px;
    }

    .wp-block-table th,
    .wp-block-table td,
    .single-post-content table:not(.np-pko__table) th,
    .single-post-content table:not(.np-pko__table) td {
        padding: 0.6rem 0.75rem;
    }

    .wp-block-table th,
    .single-post-content table:not(.np-pko__table) th {
        white-space: normal;
    }
}

/* --- Wykluczenia komponentów (własne style) --- */
.np-pko__table-wrap.wp-block-table,
.np-pko .wp-block-table {
    border: none;
    box-shadow: none;
    background: transparent;
    border-radius: 0;
    overflow: visible;
}

/* Edytor blokowy — te same reguły w .editor-styles-wrapper */
.editor-styles-wrapper .wp-block-table {
    width: 100%;
    max-width: var(--article-content-width, min(1240px, calc(100vw - 48px)));
    margin: 1.5rem auto;
    padding: 0;
    box-sizing: border-box;
    overflow-x: auto;
    border-radius: var(--np-table-radius);
    border: 1px solid var(--np-table-border);
    background: #fff;
    box-shadow: 0 8px 28px -18px rgb(10 10 10 / 0.18);
}

.editor-styles-wrapper .wp-block-table table {
    width: 100%;
    padding-left: 0;
    padding-right: 0;
    border-collapse: separate;
    border-spacing: 0;
    border: none;
}

.editor-styles-wrapper .wp-block-table th {
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    text-align: left;
    color: #39732d;
    background: #f3f6f2;
    border: none;
    border-bottom: 2px solid #39732d;
}

.editor-styles-wrapper .wp-block-table td {
    padding: 0.75rem 1rem;
    border: none;
    border-bottom: 1px solid rgb(10 10 10 / 0.08);
    color: #222;
}

.editor-styles-wrapper .wp-block-table tbody tr:last-child td {
    border-bottom: none;
}

.editor-styles-wrapper .wp-block-table.is-style-stripes tbody tr:nth-child(odd) td {
    background: rgb(57 115 45 / 0.045);
}

.editor-styles-wrapper .wp-block-table figcaption {
    padding: 0.75rem 1rem;
    font-size: 0.8125rem;
    color: rgb(10 10 10 / 0.55);
    border-top: 1px solid rgb(10 10 10 / 0.08);
}
