/* ──────────────────────────────────────────────────────────────────────────
   Tabele w treści redakcyjnej (artykuły bloga, strony atrakcji).

   Wzorzec przeniesiony z projektu enedom: poniżej 640 px wiersz zamienia się
   w kartę, a każda komórka pokazuje etykietę swojej kolumny. Dzięki temu nie
   trzeba przewijać w bok ani czytać kolumn ściśniętych do kilku pikseli.

   Etykiety wstawia App\Support\Html::stackableTables() do atrybutu data-label.
   Arkusz jest wpięty w layoucie, więc obowiązuje na każdej podstronie.
   Tabele własne stron melexa (.seo-cmp, .mr-compare) mają swoje style
   w szablonach, bo stoją na ciemnym tle.
   ────────────────────────────────────────────────────────────────────────── */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    margin: 22px 0;
}

.table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
    background: #fff;
    margin: 0;
}

.table-wrap caption {
    padding: 12px 16px;
    font-weight: 600;
    text-align: start;
    color: #0f172a;
}

.table-wrap th,
.table-wrap td {
    padding: 12px 16px;
    text-align: start;
    border-bottom: 1px solid #e2e8f0;
    vertical-align: top;
    line-height: 1.55;
}

.table-wrap thead th {
    background: #f8fafc;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
}

.table-wrap tbody tr:last-child td,
.table-wrap tbody tr:last-child th {
    border-bottom: 0;
}

.table-wrap tbody tr:hover {
    background: #fffbeb;
}

/* Poniżej 640 px: wiersze jako karty. Selektor :has() pozwala zdjąć ramkę
   i przewijanie z opakowania tylko wtedy, gdy w środku jest tabela
   przygotowana do składania. Przeglądarki bez :has() (Safari < 15.4)
   zobaczą zwykłą tabelę z przewijaniem w bok, czyli stan sprzed zmiany. */
@media (max-width: 640px) {
    .table-wrap:has(> .table--stack) {
        overflow-x: visible;
        border: 0;
        border-radius: 0;
    }

    table.table--stack,
    .table--stack tbody,
    .table--stack tr,
    .table--stack th,
    .table--stack td {
        display: block;
        width: 100%;
    }

    table.table--stack {
        min-width: 0;
        background: transparent;
        font-size: 0.95rem;
    }

    .table--stack thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0 0 0 0);
        white-space: nowrap;
        border: 0;
    }

    .table--stack caption {
        display: block;
        padding: 0 0 10px;
    }

    .table--stack tbody tr {
        background: #fff;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        padding: 6px 14px 10px;
        margin-bottom: 12px;
    }

    .table--stack tbody tr:last-child { margin-bottom: 0; }
    .table--stack tbody tr:hover { background: #fff; }

    .table--stack td {
        padding: 8px 0;
        border-bottom: 1px solid #f1f5f9;
    }

    .table--stack tr > td:last-child,
    .table--stack tr > th:last-child { border-bottom: 0; }

    .table--stack td[data-label]::before {
        content: attr(data-label);
        display: block;
        font-size: 0.7rem;
        font-weight: 700;
        letter-spacing: 0.05em;
        text-transform: uppercase;
        color: #64748b;
        margin-bottom: 2px;
    }

    /* Pierwsza komórka wiersza to tytuł karty: bez etykiety, wyróżniona. */
    .table--stack tbody tr > th:first-child,
    .table--stack tbody tr > td:first-child {
        padding: 10px 0 8px;
        font-weight: 700;
        font-size: 1.02rem;
        color: #0f172a;
        border-bottom: 1px solid #f1f5f9;
    }

    .table--stack tbody tr > td:first-child::before { content: none; }

    /* Tabela dwukolumnowa (parametr + wartość): etykieta drugiej kolumny
       powielałaby tytuł karty, więc ją chowamy. */
    .table--stack tr > td:nth-child(2):last-child::before { content: none; }
}

[dir="rtl"] .table-wrap th,
[dir="rtl"] .table-wrap td { text-align: start; }
