/* ================================================================
   TABLE RESPONSIVE - Table/list view widget
   ================================================================ */

/* View control --------------------------------------------------- */
.table-view-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    width: 100%;
    margin: 0 0 var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--gray-100);
}

.table-view-toggle__label {
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.table-view-toggle__group {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    min-width: 0;
    padding: var(--space-1);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--surface-card);
}

.table-view-toggle button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    min-height: 36px;
    padding: var(--space-2) var(--space-3);
    border: 0;
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: var(--text-xs);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    transition: background-color 150ms ease, color 150ms ease;
}

.table-view-toggle button:hover {
    background: var(--gray-50);
    color: var(--text-primary);
}

.table-view-toggle button.active {
    background: var(--primary-500);
    color: var(--text-inverse);
}

.table-view-toggle button:focus-visible {
    outline: 2px solid var(--accent-500);
    outline-offset: 2px;
}

.table-view-toggle svg {
    width: 16px;
    height: 16px;
    flex: 0 0 auto;
    stroke: currentColor;
    stroke-width: 1.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* List view ------------------------------------------------------ */
.table-container.is-list-view,
.table-wrap.is-list-view {
    width: 100%;
    overflow: visible;
    border-radius: 0;
    box-shadow: none;
}

.table-container.is-list-view table,
.table-wrap.is-list-view table {
    display: block;
    width: 100%;
    min-width: 0 !important;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
    table-layout: auto;
}

.table-container.is-list-view thead,
.table-wrap.is-list-view thead {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.table-container.is-list-view tbody,
.table-wrap.is-list-view tbody {
    display: grid;
    width: 100%;
    gap: var(--space-3);
    padding: 0;
    background: transparent;
}

.table-container.is-list-view tbody tr,
.table-wrap.is-list-view tbody tr {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: var(--space-4);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    background: var(--surface-card);
    transition: border-color 150ms ease, box-shadow 150ms ease;
}

.table-container.is-list-view tbody tr:hover,
.table-wrap.is-list-view tbody tr:hover {
    border-color: var(--surface-border-strong);
    box-shadow: var(--shadow-sm);
}

.table-container.is-list-view tbody tr:hover td,
.table-wrap.is-list-view tbody tr:hover td {
    background: transparent;
}

.table-container.is-list-view th,
.table-container.is-list-view td,
.table-wrap.is-list-view th,
.table-wrap.is-list-view td {
    width: auto !important;
    min-width: 0 !important;
    box-sizing: border-box;
}

.table-container.is-list-view td,
.table-wrap.is-list-view td {
    display: grid !important;
    grid-template-columns: minmax(6rem, 30%) minmax(0, 1fr);
    column-gap: var(--space-4);
    align-items: center;
    width: 100%;
    padding: var(--space-3) 0 !important;
    border-bottom: 1px solid var(--gray-100);
    color: var(--text-primary);
    font-size: var(--text-sm);
    line-height: 1.4;
    overflow-wrap: anywhere;
    white-space: normal !important;
}

.table-container.is-list-view td:first-child,
.table-wrap.is-list-view td:first-child {
    padding-top: 0 !important;
}

.table-container.is-list-view td:last-child:not(.is-actions),
.table-wrap.is-list-view td:last-child:not(.is-actions) {
    border-bottom: 0;
}

.table-container.is-list-view td::before,
.table-wrap.is-list-view td::before {
    content: attr(data-col-label);
    grid-column: 1;
    grid-row: 1;
    align-self: center;
    min-width: 0;
    color: var(--text-secondary);
    font-size: var(--text-xs);
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1.3;
    text-transform: uppercase;
}

/* Contenido de la celda: se apila en la columna 2 (cada hijo en su propia fila).
   No fijar grid-row: los hijos con grid-row: 1 fijo se superponen (bug: celdas
   con 2+ elementos, ej. <strong> + <br> + <small>, quedaban "montadas"). */
.table-container.is-list-view td > *,
.table-wrap.is-list-view td > * {
    grid-column: 2;
    min-width: 0;
    max-width: 100%;
}

.table-container.is-list-view td:first-child strong,
.table-wrap.is-list-view td:first-child strong {
    color: var(--text-primary);
    font-size: var(--text-base);
    font-weight: 700;
}

.table-container.is-list-view td.is-actions,
.table-wrap.is-list-view td.is-actions {
    display: flex !important;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-2);
    flex-wrap: wrap;
    padding-top: var(--space-3) !important;
    border-bottom: 0;
}

.table-container.is-list-view td.is-actions::before,
.table-wrap.is-list-view td.is-actions::before {
    display: none;
}

.table-container.is-list-view td.is-actions > *,
.table-wrap.is-list-view td.is-actions > * {
    max-width: none;
}

.table-container.is-list-view td.is-actions .btn-icon,
.table-wrap.is-list-view td.is-actions .btn-icon {
    min-width: 44px;
    min-height: 44px;
}

/* Mobile --------------------------------------------------------- */
@media (max-width: 768px) {
    .table-view-toggle {
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .table-view-toggle__group {
        max-width: 100%;
        overflow-x: auto;
    }

    .table-view-toggle button {
        flex: 0 0 auto;
        min-height: 40px;
        padding-inline: var(--space-2);
    }

    .table-container.is-list-view tbody tr,
    .table-wrap.is-list-view tbody tr {
        padding: var(--space-3);
    }

    .table-container.is-list-view td,
    .table-wrap.is-list-view td {
        grid-template-columns: minmax(5.5rem, 30%) minmax(0, 1fr);
        column-gap: var(--space-3);
    }
}

/* Dark mode ------------------------------------------------------ */
[data-theme="dark"] .table-view-toggle__group {
    border-color: var(--gray-700);
    background: var(--surface-card);
}

[data-theme="dark"] .table-view-toggle button:hover {
    background: var(--gray-700);
}
