.table-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--theme-border);
}

[data-table-view-toggle] {
    display: flex;
    gap: 0.25rem;
}

[data-table-pagination] {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

[data-table-pagination] [data-table-page-label] {
    min-width: 6.5rem;
    text-align: center;
}

[data-table-pagination] [data-table-page-size] {
    width: auto;
    min-width: 5.5rem;
}

@media (max-width: 767.98px) {
    .table-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    [data-table-pagination] {
        justify-content: space-between;
        flex-wrap: wrap;
    }

    [data-table-view-toggle] {
        justify-content: flex-end;
    }
}

.table-summary-cell .table-summary-content {
    display: inline-block;
    max-width: 300px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

[data-table-engine="true"][data-active-view="cards"],
[data-table-engine="true"][data-active-view="cards"] .table-responsive {
    overflow: visible !important;
}

[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards thead {
    display: none;
}

/* Auch das table-Element selbst aus dem Tabellenlayout nehmen. Bleibt es
   `display: table`, bestimmt die Shrink-to-fit-Breite der Zellen die Breite der
   Karten - das sprengt auf schmalen Viewports den rechten Rand. */
[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards {
    display: block;
    width: 100%;
    max-width: 100%;
}

[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards tbody,
[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards tr,
[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards td {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}

[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards tr {
    border: 1px solid var(--theme-border);
    border-radius: 0.75rem;
    margin: 0.75rem;
    padding: 0.5rem;
    background: #fff;
    width: calc(100% - 1.5rem);
    box-sizing: border-box;
}

/* Label und Wert sind Flex-Geschwister statt Prozent-Padding plus absolut
   positioniertem ::before. Prozent-Padding wird gegen den Containing Block
   aufgelöst und blähte die Zelle beim Shrink-to-fit auf; als Flex-Item darf das
   Label stattdessen umbrechen und schrumpfen. */
[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards td {
    text-align: right;
    border: none;
    border-bottom: 1px solid var(--theme-border);
    padding: 0.65rem 0.5rem;
    min-height: 48px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem 0.75rem;
    overflow-wrap: anywhere;
}

[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards td::before {
    content: attr(data-label);
    flex: 1 1 7rem;
    min-width: 0;
    margin-right: auto;
    font-weight: 600;
    color: var(--theme-text-muted);
    text-align: left;
    overflow-wrap: anywhere;
}

/* Zellen ohne data-label (z. B. reine Aktionsspalten) sollen keine leere
   Label-Spalte reservieren. */
[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards td:not([data-label])::before {
    content: none;
}

[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards td:last-child {
    border-bottom: none;
}

[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards .text-end,
[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards .text-center {
    text-align: right !important;
}

[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards .btn-group {
    width: 100%;
    justify-content: flex-end;
}

[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards audio,
[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards midi-player {
    max-width: 100%;
}

[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards .table-summary-cell {
    justify-content: flex-start;
    text-align: left;
}

[data-table-engine="true"][data-active-view="cards"] .table-responsive-cards .table-summary-cell .table-summary-content {
    display: block;
    width: 100%;
    max-width: 100%;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
}

th[data-sort-key] {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

th[data-sort-key]:hover {
    background-color: rgba(0, 0, 0, 0.04);
}

.te-sort-icon {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.35rem;
    font-size: 0.8em;
}

.te-sort-order {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.35rem;
    height: 1.35rem;
    border-radius: 999px;
    background: rgba(13, 110, 253, 0.12);
    color: var(--bs-primary, #0d6efd);
    font-size: 0.75rem;
    font-weight: 700;
}

.te-sort-icon.te-sort-inactive {
    opacity: 0.35;
}

.te-sort-icon.te-sort-active {
    opacity: 0.9;
}

.table-sort-panel {
    min-width: 18rem;
    max-width: min(22rem, 90vw);
    padding: 0.875rem;
}

.table-sort-panel-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.table-sort-panel-row {
    display: flex;
    gap: 0.5rem;
    align-items: stretch;
}

.table-sort-panel-main,
.table-sort-panel-add {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    width: 100%;
}

.table-sort-panel-main {
    flex: 1 1 auto;
}

.table-sort-panel-label {
    flex: 1 1 auto;
    text-align: left;
}

.table-sort-order-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.35rem;
    height: 1.35rem;
    border-radius: 999px;
    background: rgba(13, 110, 253, 0.12);
    color: var(--bs-primary, #0d6efd);
    font-size: 0.75rem;
    font-weight: 700;
}

.table-sort-panel-remove {
    flex: 0 0 auto;
}