/* ============================================================
   Barock Academy – Responsive Tabellen-Karten (nur Smartphone)
   ------------------------------------------------------------
   ZIEL: Lange Datentabellen auf dem Handy NICHT mehr horizontal
   scrollen lassen, sondern jede Tabellenzeile in eine übersichtliche
   Karte verwandeln ("Label … Wert" je Spalte).

   WICHTIG:
   - Greift AUSSCHLIESSLICH unterhalb 767.98px (Smartphone). Auf dem
     Desktop/Tablet ist KEINE einzige Regel aktiv – das Desktop-Design
     und alle Funktionen bleiben unverändert.
   - Wird nur auf Tabellen mit der Klasse `.has-mobile-cards` angewandt.
     Diese Klasse setzt `responsive-tables.js` automatisch – aber nur
     bei "sauberen" Listentabellen (einzeilige Kopfzeile, passende
     Spaltenzahl). Alles andere fällt auf das bisherige Verhalten
     (horizontal scrollbar) zurück – keine kaputten Layouts.
   - Die Spaltennamen kommen aus `data-label` (vom JS aus der Kopfzeile
     befüllt). Manuell gesetzte `data-label` werden respektiert.
   ============================================================ */

@media (max-width: 767.98px) {

    /* Wrapper darf im Kartenmodus nicht mehr scrollen */
    .table-responsive:has(> table.has-mobile-cards),
    .table-responsive:has(> .dataTables_wrapper table.has-mobile-cards) {
        overflow-x: visible;
    }

    /* Tabelle + Body als Block, damit Zeilen zu Karten werden */
    table.has-mobile-cards,
    table.has-mobile-cards > tbody {
        display: block;
        width: 100%;
    }

    /* Kopfzeile ausblenden – Spaltennamen stehen per data-label an den Zellen */
    table.has-mobile-cards > thead {
        display: none;
    }

    /* Jede Zeile = eine Karte */
    table.has-mobile-cards > tbody > tr {
        display: block;
        background: var(--e-surface, #fff);
        border: 1px solid var(--e-border, #e7eaef);
        border-radius: var(--e-r, 12px);
        box-shadow: var(--e-shadow-sm, 0 1px 3px rgba(16, 24, 40, .06));
        padding: 4px 6px 6px;
        margin-bottom: 14px;
        overflow: hidden;
    }

    /* Zebra-/Hover-Hintergründe im Kartenmodus neutralisieren */
    table.has-mobile-cards.table-striped > tbody > tr:nth-of-type(odd),
    table.has-mobile-cards.table-hover > tbody > tr:hover {
        background: var(--e-surface, #fff);
    }

    /* Jede Zelle = eine Zeile "Label … Wert" */
    table.has-mobile-cards > tbody > tr > td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 14px;
        width: 100%;
        min-height: 44px;                 /* angenehme Touch-Höhe */
        padding: 10px 14px;
        text-align: right;
        border: none !important;
        border-bottom: 1px solid var(--e-border, #f1f2f4) !important;
        word-break: break-word;
    }

    table.has-mobile-cards > tbody > tr > td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        max-width: 45%;
        font-weight: 600;
        font-size: .78rem;
        letter-spacing: .02em;
        color: var(--e-muted, #6a7383);
        text-align: left;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Zellen ohne Label (z.B. Spacer) bekommen keinen leeren Doppelpunkt */
    table.has-mobile-cards > tbody > tr > td:not([data-label])::before,
    table.has-mobile-cards > tbody > tr > td[data-label=""]::before {
        content: none;
    }

    table.has-mobile-cards > tbody > tr > td:last-child {
        border-bottom: none !important;
    }

    /* Volle-Breite-Zeilen (z.B. "Keine Daten"-Zeile mit colspan) sauber zentrieren */
    table.has-mobile-cards > tbody > tr > td[colspan] {
        display: block;
        text-align: center;
        justify-content: center;
    }
    table.has-mobile-cards > tbody > tr > td[colspan]::before {
        content: none;
    }

    /* ---------- Optionale Aufwertungen (nur wenn die Zelle die Klasse trägt) ---------- */

    /* Titel-Spalte als hervorgehobener Karten-Kopf (z.B. Name) */
    table.has-mobile-cards > tbody > tr > td.td-title {
        display: block;
        text-align: left;
        padding: 12px 14px 10px;
        border-bottom: 2px solid var(--e-border, #eef0f2) !important;
    }
    table.has-mobile-cards > tbody > tr > td.td-title::before {
        content: none;
    }
    table.has-mobile-cards > tbody > tr > td.td-title strong,
    table.has-mobile-cards > tbody > tr > td.td-title a {
        font-size: 1.05rem;
        font-weight: 700;
        color: var(--e-ink, #1b2536);
        line-height: 1.3;
    }

    /* Aktions-Spalte: Buttons komfortabel groß und rechtsbündig */
    table.has-mobile-cards > tbody > tr > td.td-actions {
        padding-top: 12px;
        padding-bottom: 12px;
    }
    table.has-mobile-cards > tbody > tr > td.td-actions .btn-group,
    table.has-mobile-cards > tbody > tr > td.td-actions .btn-group-sm {
        gap: 8px;
        flex-wrap: wrap;
        justify-content: flex-end;
    }
    table.has-mobile-cards > tbody > tr > td.td-actions .btn {
        padding: .4rem .9rem;
        font-size: 1rem;
    }

    /* Auswahl-Checkbox-Spalte */
    table.has-mobile-cards > tbody > tr > td.td-select .form-check-input {
        margin: 0;
    }
}

/* ---------- Dark-Mode ---------- */
@media (max-width: 767.98px) {
    body.dark-mode table.has-mobile-cards > tbody > tr {
        background: var(--e-surface, #1b2130);
        border-color: var(--e-border, #2b3446);
    }
    body.dark-mode table.has-mobile-cards.table-striped > tbody > tr:nth-of-type(odd),
    body.dark-mode table.has-mobile-cards.table-hover > tbody > tr:hover {
        background: var(--e-surface, #1b2130);
    }
}
