/* Solo los listados habilitados explícitamente adoptan las tarjetas. */
.tabla-card__label,
.tabla-card-empty,
.tabla-card-loading,
.tabla-card-sort[hidden] {
    display: none !important;
}

/* Al salir de las tarjetas, el zoom no debe dejar los controles móviles visibles. */
.tabla-card-sort {
    display: none;
}

/* El asunto extenso se resume igual en la tabla de escritorio y en las tarjetas. */
.tabla-adaptable--ready .tabla-card__subject-toggle {
    display: flex;
    align-items: center;
    gap: 7px;
    width: max-content;
    margin: 4px 0 0 auto;
    padding: 2px 1px;
    border: 0;
    border-radius: 2px;
    background: transparent;
    color: #475569;
    font-size: 0.78rem;
    font-weight: 600;
    line-height: 1.3;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
}

.tabla-adaptable--ready .tabla-card__subject-toggle::after {
    content: '';
    width: 6px;
    height: 6px;
    margin-top: -3px;
    border-right: 1.5px solid currentColor;
    border-bottom: 1.5px solid currentColor;
    transform: rotate(45deg);
}

.tabla-adaptable--ready .tabla-card__subject-toggle[aria-expanded="true"]::after {
    margin-top: 3px;
    transform: rotate(225deg);
}

.tabla-adaptable--ready .tabla-card__subject-toggle:hover {
    color: #1e293b;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.tabla-adaptable--ready .tabla-card__subject-toggle:focus {
    outline: 0;
}

.tabla-adaptable--ready .tabla-card__subject-toggle:focus-visible {
    outline: 3px solid #2266a8;
    outline-offset: 3px;
}

.tabla-adaptable--ready .tabla-card__value:not(.is-expanded) > .tabla-card__subject-full,
.tabla-adaptable--ready .tabla-card__value.is-expanded > .tabla-card__subject-preview {
    display: none;
}

@media screen and (max-width: 991.98px) {
    /* El listado se revela cuando su estructura móvil ya está preparada. */
    html.tablas-adaptables--preparing .tabla-card-loading {
        display: block !important;
        margin: 8px 0 10px;
        padding: 20px 12px;
        border: 1px solid #dce5ee;
        border-radius: 12px;
        background: #fff;
        color: #64748b;
        font-size: 0.9rem;
        text-align: center;
    }

    html.tablas-adaptables--preparing table.tabla-adaptable,
    html.tablas-adaptables--preparing .tabla-card-sort {
        display: none !important;
    }

    html.tablas-adaptables--preparing .tabla-paginacion {
        visibility: hidden;
    }

    .tabla-paginas .pagination {
        display: flex;
        flex-wrap: nowrap;
        width: max-content;
        gap: 4px;
        white-space: nowrap;
    }

    .tabla-paginas .pagination > li {
        flex: 0 0 auto;
    }

    .tabla-paginas .pagination > .tabla-page--mobile-hidden {
        display: none !important;
    }

    .tabla-paginas .pagination .page-link {
        min-width: 32px;
        padding-right: 8px;
        padding-left: 8px;
        margin-left: 0;
    }

    .tabla-card-sort {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin: 8px 0 10px;
        padding: 10px;
        border: 1px solid #e2e8f0;
        border-radius: 10px;
        background: #fff;
    }

    .tabla-card-sort__field {
        flex: 2 1 140px;
        min-width: 0;
    }

    .tabla-card-sort__direction {
        flex: 1 1 115px;
        min-width: 0;
    }

    .tabla-card-sort label {
        display: block;
        margin-bottom: 3px;
        color: #475569;
        font-size: 0.8rem;
        font-weight: 600;
    }

    .tabla-card-sort select.form-control:not(.select2-hidden-accessible) {
        width: 100%;
        max-width: 100%;
        height: 38px;
        min-height: 38px;
        padding-left: 8px;
        color: #444;
        border-color: #aaa;
    }

    .tabla-card-sort select.form-control:disabled {
        background-color: #eee;
    }

    .tabla-card-sort .select2-container {
        display: block;
        width: 100% !important;
        max-width: 100% !important;
    }

    .tabla-card-sort .select2-selection--single {
        height: 38px;
    }

    .tabla-card-sort .select2-container .select2-selection--single .select2-selection__rendered {
        padding-top: 0 !important;
        line-height: 36px;
    }

    .tabla-card-sort .select2-container .select2-selection--single .select2-selection__arrow {
        height: 36px;
    }

    /* Mayor especificidad que Site.css, incluidas sus filas alternas y hover. */
    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready {
        display: block;
        width: 100%;
        max-width: 100%;
        overflow: visible;
        border: 0;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        white-space: normal;
    }

    /* Los encabezados siguen asociados a sus celdas para lectores de pantalla. */
    table.tabla-adaptable--ready > thead {
        position: absolute;
        width: 1px !important;
        min-width: 0 !important;
        height: 1px;
        margin: -1px;
        padding: 0;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        clip-path: inset(50%);
        white-space: nowrap;
        border: 0;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 8px 12px;
        width: 100%;
        min-width: 0;
        margin: 0 0 10px;
        padding: 12px;
        border: 1px solid #dce5ee;
        border-radius: 12px;
        background: #fff;
        box-shadow: 0 3px 10px rgba(15, 23, 42, 0.04);
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr.tabla-card--muted {
        background: #edf0f3;
        border-color: #cbd5e1;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr > td {
        display: block;
        float: none;
        order: 3;
        grid-column: 1 / -1;
        width: auto !important;
        min-width: 0;
        max-width: 100%;
        margin: 0;
        padding: 0;
        border: 0;
        background: transparent;
        color: #334155;
        font-size: 0.95rem !important;
        line-height: 1.35;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .tabla-adaptable--ready .tabla-card__label {
        display: block !important;
        margin-bottom: 1px;
        color: #64748b;
        font-size: 0.73rem;
        font-weight: 600;
        line-height: 1.35;
    }

    .tabla-adaptable--ready .tabla-card__value,
    .tabla-adaptable--ready .tabla-card__value > * {
        min-width: 0;
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .tabla-adaptable--ready .tabla-card__value .preline {
        white-space: pre-line;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr > .tabla-card__title {
        order: 0;
        grid-column: 1 / -1;
        font-size: 1.05rem !important;
        font-weight: 700;
        align-self: start;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr.tabla-card--has-status > .tabla-card__title {
        grid-column: 1;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr > .tabla-card__status {
        order: 1;
        grid-column: 2;
        align-self: start;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr > .tabla-card__subject {
        order: 4;
        padding: 8px 0 0;
        border-top: 1px solid #edf2f7;
        color: #475569 !important;
        font-size: 0.78rem !important;
        line-height: 1.45;
    }

    .tabla-adaptable--ready .tabla-card__status .estado-badge {
        gap: 3px;
        padding: 3px 4px;
        font-size: 0.75rem;
        line-height: 1.25;
        letter-spacing: 0;
    }

    .tabla-adaptable--ready .tabla-card__status .estado-asignado {
        margin-top: 3px;
        font-size: 0.82rem;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr > .tabla-card__field {
        grid-column: auto;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr > .tabla-card__field--wide {
        grid-column: 1 / -1;
    }

    /* Área táctil más alta en las tarjetas. */
    .tabla-adaptable--ready .tabla-card__subject-toggle {
        min-height: 32px;
        margin-top: 2px;
        padding: 4px 1px;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr > .tabla-card__actions {
        order: 5;
        padding-top: 8px;
        border-top: 1px solid #e2e8f0;
        min-width: 0;
        max-width: 100%;
    }

    /* Orden de lectura de los expedientes, independiente de sus columnas en escritorio. */
    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready.tabla-adaptable--expedientes > tbody > tr > .tabla-card__field {
        order: 5;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready.tabla-adaptable--expedientes > tbody > tr > td[data-card-field="Fecha"],
    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready.tabla-adaptable--expedientes > tbody > tr > td[data-card-field="FechaRecepcion"] {
        order: 2;
        grid-column: 1;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready.tabla-adaptable--expedientes > tbody > tr > td[data-card-field="TipoDocumento"] {
        order: 2;
        grid-column: 2;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready.tabla-adaptable--expedientes > tbody > tr > td[data-card-field="Documento"] {
        order: 3;
        grid-column: 1 / -1;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready.tabla-adaptable--expedientes > tbody > tr > td[data-card-field="Ubicacion"] {
        order: 4;
        grid-column: 1 / -1;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready.tabla-adaptable--expedientes > tbody > tr > .tabla-card__subject {
        order: 6;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready.tabla-adaptable--expedientes > tbody > tr > .tabla-card__actions {
        order: 7;
    }

    .tabla-adaptable--ready .tabla-card__actions > .tabla-card__value,
    .tabla-adaptable--ready .acciones-tabla__grid {
        display: flex;
        flex-wrap: wrap;
        align-items: stretch;
        justify-content: flex-end;
        gap: 6px;
        width: 100%;
    }

    .tabla-adaptable--ready .tabla-card__actions > .tabla-card__label {
        display: none !important;
    }

    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready .tabla-card__actions .btn {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 0;
        flex: 0 1 auto;
        width: 44px;
        min-width: 44px;
        max-width: 100%;
        min-height: 44px;
        height: auto;
        margin: 0;
        padding: 10px;
        line-height: 1.3;
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .tabla-adaptable--ready .btn:focus-visible,
    .tabla-card-sort .select2-selection:focus-visible,
    .tabla-card-sort select:focus-visible {
        outline: 3px solid #2266a8;
        outline-offset: 3px;
    }

    .tabla-card-empty {
        display: block !important;
        padding: 20px;
        border: 1px solid #dce5ee;
        border-radius: 12px;
        color: #64748b;
        text-align: center;
        background: #fff;
    }
}

@media screen and (max-width: 374.98px) {
    .content-wrapper > table.table.table-bordered.table-hover.tabla-adaptable--ready > tbody > tr.tabla-card--has-status {
        grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr);
    }
}

@media print {
    .tabla-card-sort,
    .tabla-card__subject-preview,
    .tabla-card__subject-toggle {
        display: none !important;
    }

    /* Al imprimir se conserva el asunto completo. */
    .tabla-adaptable--ready .tabla-card__value > .tabla-card__subject-full {
        display: block !important;
    }
}
