/* Mobile card layout for comparison tables.

   Below 768px each row of a `table.mcard-table` becomes a stacked card: the
   row's first cell is the card heading (`.parameter`, or any first cell
   without a data-label), and every other cell prints its
   column name (from its `data-label` attribute) above its value. Desktop markup
   and styling are untouched.

   Shared by every page with card tables (company, OPC, trademark pages):
     <link rel="stylesheet" href="optimisecss/table-cards.css" media="(max-width: 767.98px)">
     <table class="table comparison-table mcard-table"> … <td data-label="Taxation"> …

   Selectors start with `table.` so they outrank optimisecss/table.css, which
   most pages load asynchronously and therefore after this file. */

@media (max-width: 767.98px) {
    :has(> table.mcard-table) {
        overflow-x: visible !important;
    }

    /* a styled wrapper around the table (shadow, rounded corners) would frame
       the whole stack of cards; each card carries its own border instead.
       Specificity beats table.css's `body.dark-mode .comparison-table-wrapper`. */
    :is(body, body.dark-mode) div.mcard-wrapper {
        margin: 24px 0;
        border-radius: 0;
        overflow: visible;
        background: transparent;
        box-shadow: none;
    }

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

    table.mcard-table {
        min-width: 0 !important;
        table-layout: auto !important;
        border-spacing: 0;
    }

    /* header row: in <thead>, or a row of <th> cells in a table without one */
    table.mcard-table colgroup,
    table.mcard-table thead,
    table.mcard-table tr:has(> th) {
        display: none !important;
    }

    table.mcard-table tbody tr {
        margin-bottom: 16px;
        border: 1px solid #cbd5e0;
        border-radius: 14px;
        overflow: hidden;
        background: #fff;
        box-shadow: 0 4px 14px rgba(12, 60, 99, 0.06);
    }

    table.mcard-table tbody tr:last-child {
        margin-bottom: 0;
    }

    table.mcard-table tbody td {
        border: 0 !important;
        padding: 10px 16px;
        font-size: 14px;
        line-height: 1.6;
        background: #fff;
    }

    /* the even-row tint is for scanning a wide table; each card stands alone */
    table.mcard-table tbody tr:nth-child(even) td {
        background: #fff;
    }

    table.mcard-table tbody td:is(.parameter, :first-child:not([data-label])) {
        padding: 12px 16px;
        font-size: 16px;
        font-weight: 700;
        color: #0c3c63;
        background: #eef5fb !important;
        border-bottom: 1px solid #cbd5e0 !important;
    }

    table.mcard-table tbody td[data-label]::before {
        content: attr(data-label);
        display: block;
        margin-bottom: 2px;
        color: #0c3c63;
        font-size: 12px;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
    }

    table.mcard-table tbody td[data-label] + td[data-label] {
        border-top: 1px dashed #dde5ee !important;
    }

    /* coloured cells (green/red/orange) keep their tint as a highlighted band */
    table.mcard-table tbody td:is(.green-cell, .red-cell, .orange-cell) {
        border-top-style: solid !important;
    }

    table.mcard-table tbody td.green-cell::before { color: #18794e; }
    table.mcard-table tbody td.red-cell::before { color: #b42318; }
    table.mcard-table tbody td.orange-cell::before { color: #b76e00; }

    body.dark-mode table.mcard-table tbody tr {
        border-color: #374151;
        background: #1f2937;
        box-shadow: none;
    }

    body.dark-mode table.mcard-table tbody td,
    body.dark-mode table.mcard-table tbody tr:nth-child(even) td {
        background: #1f2937;
    }

    body.dark-mode table.mcard-table tbody td:is(.parameter, :first-child:not([data-label])) {
        color: #fff;
        background: #102a43 !important;
        border-bottom-color: #374151 !important;
    }

    body.dark-mode table.mcard-table tbody td[data-label]::before {
        color: #93c5fd;
    }

    body.dark-mode table.mcard-table tbody td[data-label] + td[data-label] {
        border-top-color: #374151 !important;
    }

    body.dark-mode table.mcard-table tbody td.green-cell::before { color: #86efac; }
    body.dark-mode table.mcard-table tbody td.red-cell::before { color: #fca5a5; }
    body.dark-mode table.mcard-table tbody td.orange-cell::before { color: #fcd34d; }
}
