/*
 * AESV Responsive Tables
 * ------------------------------------------------------------
 * Scope: every selector is namespaced under `.aesv-rwd-wrap` or
 * `.aesv-rwd-table` so it never bleeds into theme tables.
 *
 * Desktop (>760px): a normal comparison table with header
 * band, zebra rows, and clean padding.
 *
 * Mobile (<=760px): the table re-flows into a stacked card
 * list. Each <td> gets a small label above its value
 * (the corresponding <th> text, injected server-side as
 * data-label="..." by the plugin). No horizontal scroll.
 *
 * The transform is CSS-only and works without JavaScript.
 * ------------------------------------------------------------
 */

/* ---------- Outer wrapper: keeps the table inside the article column ---------- */
.aesv-rwd-wrap {
    width: 100%;
    max-width: 100%;
    margin: 1.5em 0;
    /* No horizontal scroll on the page either: if a single cell is wider than
     * the viewport (rare for our short labels) we let it wrap onto the next
     * line rather than overflow. */
    overflow-wrap: anywhere;
    word-break: break-word;
}

/* Hard-override parent theme / article styles that may force a horizontal
 * scroll behavior on tables. Any parent rule like
 *   .aesv-article-2026 table { display: block; overflow-x: auto; }
 * is overridden here because our wrapper + scoped class give this rule
 * higher specificity. We only touch tables inside our own wrapper, so
 * we never bleed into unrelated theme tables. */
.aesv-rwd-wrap table.aesv-rwd-table {
    display: table;
    overflow: visible;
}

/* ---------- Desktop: normal table ---------- */
.aesv-rwd-wrap > table.aesv-rwd-table {
    width: 100%;
    border-collapse: collapse;
    border-spacing: 0;
    background: #ffffff;
    color: #0f172a;
    font-size: 15px;
    line-height: 1.45;
    border: 1px solid #dbe5de;
    border-radius: 12px;
    overflow: hidden;
    table-layout: auto;
}

.aesv-rwd-wrap > table.aesv-rwd-table thead th {
    background: #0f5132;
    color: #ffffff;
    font-weight: 700;
    text-align: left;
    padding: 12px 14px;
    border-bottom: 1px solid #0a3d24;
    white-space: normal;
    font-size: 14px;
    letter-spacing: 0.01em;
}

.aesv-rwd-wrap > table.aesv-rwd-table tbody td {
    padding: 12px 14px;
    border-top: 1px solid #e2e8f0;
    vertical-align: top;
    background: #ffffff;
    color: #0f172a;
}

.aesv-rwd-wrap > table.aesv-rwd-table tbody tr:nth-child(even) td {
    background: #f8fafc;
}

.aesv-rwd-wrap > table.aesv-rwd-table tbody tr:first-child td {
    border-top: 0;
}

/* Make sure link buttons inside a price cell don't get squished */
.aesv-rwd-wrap > table.aesv-rwd-table a {
    color: #0f5132;
    text-decoration: underline;
    font-weight: 600;
}
.aesv-rwd-wrap > table.aesv-rwd-table a:hover,
.aesv-rwd-wrap > table.aesv-rwd-table a:focus {
    color: #12b76a;
}

/* ---------- Mobile: stacked cards ---------- */
@media (max-width: 760px) {

    .aesv-rwd-wrap {
        margin: 1.25em 0;
    }

    /* Hide the duplicate header row on mobile; the injected data-label
     * attributes on each <td> replace the visual role of the header. */
    .aesv-rwd-wrap > table.aesv-rwd-table thead {
        display: none;
    }

    .aesv-rwd-wrap > table.aesv-rwd-table,
    .aesv-rwd-wrap > table.aesv-rwd-table tbody,
    .aesv-rwd-wrap > table.aesv-rwd-table tbody tr,
    .aesv-rwd-wrap > table.aesv-rwd-table tbody td {
        display: block;
        width: 100% !important;
        max-width: 100%;
    }

    /* Each <tr> becomes a card */
    .aesv-rwd-wrap > table.aesv-rwd-table tbody tr {
        background: #ffffff;
        border: 1px solid #dbe5de;
        border-radius: 12px;
        margin-bottom: 14px;
        padding: 6px 12px;
        box-shadow: 0 4px 14px rgba(15, 23, 42, 0.05);
    }

    .aesv-rwd-wrap > table.aesv-rwd-table tbody td {
        border-top: 1px solid #f1f5f9;
        padding: 10px 0;
        background: transparent !important;
        text-align: left;
    }

    .aesv-rwd-wrap > table.aesv-rwd-table tbody td:first-child {
        border-top: 0;
        padding-top: 12px;
    }

    .aesv-rwd-wrap > table.aesv-rwd-table tbody td:last-child {
        padding-bottom: 12px;
    }

    /* The injected mobile label, rendered as a small uppercase eyebrow
     * above each cell's value. Uses attr(data-label) so the label text
     * comes from the corresponding <th> automatically. */
    .aesv-rwd-wrap > table.aesv-rwd-table tbody td::before {
        content: attr(data-label);
        display: block;
        font-size: 11px;
        font-weight: 800;
        letter-spacing: 0.08em;
        text-transform: uppercase;
        color: #0f5132;
        margin-bottom: 4px;
    }

    /* If a <td> has no data-label (shouldn't happen for our tables,
     * but the legacy content might miss one), show a fallback so we
     * never leave a value un-labeled. */
    .aesv-rwd-wrap > table.aesv-rwd-table tbody td:not([data-label])::before {
        content: "\00a0";
    }

    /* Last value in a card gets a touch of emphasis if it's a link */
    .aesv-rwd-wrap > table.aesv-rwd-table tbody td a {
        display: inline-block;
        margin-top: 2px;
    }
}

/* ---------- Accessibility ---------- */
/* Respect users who request reduced motion: the transform is static,
 * but we still turn off any transitions/animations just in case a
 * future revision adds them. */
@media (prefers-reduced-motion: reduce) {
    .aesv-rwd-wrap *,
    .aesv-rwd-wrap *::before,
    .aesv-rwd-wrap *::after {
        animation: none !important;
        transition: none !important;
    }
}

/* High-contrast / forced-colors mode: keep the labels visible */
@media (forced-colors: active) {
    .aesv-rwd-wrap > table.aesv-rwd-table thead th,
    .aesv-rwd-wrap > table.aesv-rwd-table tbody td {
        border: 1px solid CanvasText;
    }
}

/* ---------- Print ---------- */
@media print {
    .aesv-rwd-wrap {
        overflow: visible;
    }
    .aesv-rwd-wrap > table.aesv-rwd-table {
        border: 1px solid #000;
    }
    .aesv-rwd-wrap > table.aesv-rwd-table thead {
        display: table-header-group;
    }
    .aesv-rwd-wrap > table.aesv-rwd-table tbody td::before {
        display: none;
    }
}
