/* =====================================================================
   Vista móvil (legacy) — <= 767px
   Listados en formato LISTA multílínea (no tarjetas):
     [ dato izquierdo ] [ título + 2 líneas ] [ acciones ]
   ===================================================================== */
@media (max-width: 767px) {

    /* --- Header de página --- */
    .headers {
        width: calc(100% - 16px) !important;
        left: 8px !important;
        transform: none !important;
    }

    .headers > .row {
        padding: 6px 10px;
        flex-wrap: nowrap;
        margin: 0;
    }

    .headers h3 {
        font-size: 17px;
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .headers .btn {
        padding: 6px 10px;
        font-size: 13px;
        white-space: nowrap;
    }

    .content-wrapper .content.pt-80 {
        padding-top: 55px !important;
    }

    /* --- Lista multílínea (sustituye a la tabla en móvil) --- */
    .table-mobile-compact {
        display: block !important;
        width: 100% !important;
        margin: 0 !important;
        border-collapse: collapse;
    }

    .table-mobile-compact thead {
        display: none !important;
    }

    .table-mobile-compact tbody {
        display: block !important;
    }

    .table-mobile-compact tbody tr {
        display: grid !important;
        grid-template-columns: 62px 1fr 76px;
        column-gap: 10px;
        row-gap: 2px;
        align-items: start;
        padding: 8px 6px;
        border-bottom: 1px solid #e9e9e9;
        background: #fff;
    }

    .table-mobile-compact tbody tr:nth-child(odd) {
        background: #f8f9fa;
    }

    .table-mobile-compact tbody td {
        display: block !important;
        min-width: 0;
        padding: 0 !important;
        border: 0 !important;
        font-size: 13px;
        line-height: 1.25;
        text-align: left;
        vertical-align: top;
        white-space: normal !important;
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    .table-mobile-compact small {
        font-size: 11px;
    }

    /* Etiquetas/estados */
    .table-mobile-compact td .label {
        display: inline-block;
        max-width: 100%;
        font-size: 9px !important;
        line-height: 1.15;
        padding: 2px 6px !important;
        border-radius: 999px !important;
        white-space: nowrap !important;
        overflow: hidden;
        text-overflow: ellipsis;
        vertical-align: middle;
    }

    .table-mobile-compact .buttons-icons {
        display: flex;
        gap: 4px;
        justify-content: flex-end;
        align-items: center;
    }

    .table-mobile-compact .buttons-icons a,
    .table-mobile-compact .buttons-icons button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 22px !important;
        height: 22px !important;
        padding: 0 !important;
        border-radius: 8px !important;
    }

    .table-mobile-compact .buttons-icons a i,
    .table-mobile-compact .buttons-icons button i {
        font-size: 15px !important;
    }

    /* Líneas secundarias atenuadas */
    .table-mobile-compact .linea2,
    .table-mobile-compact .linea3 {
        color: #6b7280;
        font-size: 12px;
    }

    /* --- Clientes: [Estado] [Nombre / Email / Teléfono] [acciones] --- */
    #tb_clientes tbody td:nth-child(1),
    #tb_clientes tbody td:nth-child(6),
    #tb_clientes tbody td:nth-child(7) { display: none !important; }
    #tb_clientes tbody td:nth-child(2) { grid-column: 1; grid-row: 1 / span 3; align-self: start; }
    #tb_clientes tbody td:nth-child(3) { grid-column: 2; grid-row: 1; font-weight: 700; }
    #tb_clientes tbody td:nth-child(4) { grid-column: 2; grid-row: 2; color: #6b7280; font-size: 12px; }
    #tb_clientes tbody td:nth-child(5) { grid-column: 2; grid-row: 3; color: #6b7280; font-size: 12px; }
    #tb_clientes tbody td:nth-child(8) { grid-column: 3; grid-row: 1 / span 3; align-self: center; }

    /* --- Comunidades: [Estado] [Nombre / Dirección / Población] [acciones] --- */
    #tb_comunidades tbody td:nth-child(1),
    #tb_comunidades tbody td:nth-child(6) { display: none !important; }
    #tb_comunidades tbody td:nth-child(2) { grid-column: 1; grid-row: 1 / span 3; align-self: start; }
    #tb_comunidades tbody td:nth-child(3) { grid-column: 2; grid-row: 1; font-weight: 700; }
    #tb_comunidades tbody td:nth-child(4) { grid-column: 2; grid-row: 2; color: #6b7280; font-size: 12px; }
    #tb_comunidades tbody td:nth-child(5) { grid-column: 2; grid-row: 3; color: #6b7280; font-size: 12px; }
    #tb_comunidades tbody td:nth-child(7) { grid-column: 3; grid-row: 1 / span 3; align-self: center; }

    /* --- Profesionales: [Estado] [Nombre / Email / Teléfono] [acciones] --- */
    #tb_profesionales tbody td:nth-child(5),
    #tb_profesionales tbody td:nth-child(6) { display: none !important; }
    #tb_profesionales tbody td:nth-child(1) { grid-column: 1; grid-row: 1 / span 3; align-self: start; }
    #tb_profesionales tbody td:nth-child(2) { grid-column: 2; grid-row: 1; font-weight: 700; }
    #tb_profesionales tbody td:nth-child(3) { grid-column: 2; grid-row: 2; color: #6b7280; font-size: 12px; }
    #tb_profesionales tbody td:nth-child(4) { grid-column: 2; grid-row: 3; color: #6b7280; font-size: 12px; }
    #tb_profesionales tbody td:nth-child(7) { grid-column: 3; grid-row: 1 / span 3; align-self: center; }

    /* --- Usuarios: [Estado] [Nombre / Email / Usuario] [acciones] --- */
    #tb_usuarios tbody td:nth-child(1),
    #tb_usuarios tbody td:nth-child(6) { display: none !important; }
    #tb_usuarios tbody td:nth-child(2) { grid-column: 1; grid-row: 1 / span 3; align-self: start; }
    #tb_usuarios tbody td:nth-child(3) { grid-column: 2; grid-row: 1; font-weight: 700; }
    #tb_usuarios tbody td:nth-child(4) { grid-column: 2; grid-row: 2; color: #6b7280; font-size: 12px; }
    #tb_usuarios tbody td:nth-child(5) { grid-column: 2; grid-row: 3; color: #6b7280; font-size: 12px; }
    #tb_usuarios tbody td:nth-child(7) { grid-column: 3; grid-row: 1 / span 3; align-self: center; }

    /* --- Incidencias procesadas: [Prioridad+Estado+Fecha] [Asunto / Cliente / Comunidad] [acciones] --- */
    #tb_tickets tbody tr { grid-template-columns: 92px 1fr 52px; }
    #tb_tickets tbody td:nth-child(1),
    #tb_tickets tbody td:nth-child(7),
    #tb_tickets tbody td:nth-child(9),
    #tb_tickets tbody td:nth-child(10) { display: none !important; }
    #tb_tickets tbody td:nth-child(2) { grid-column: 1; grid-row: 1; }
    #tb_tickets tbody td:nth-child(3) { grid-column: 1; grid-row: 2; }
    #tb_tickets tbody td:nth-child(3) .label { white-space: normal !important; }
    #tb_tickets tbody td:nth-child(8) { grid-column: 1; grid-row: 3; color: #6b7280; font-size: 11px; }
    #tb_tickets tbody td:nth-child(4) { grid-column: 2; grid-row: 1; font-weight: 700; }
    #tb_tickets tbody td:nth-child(5) { grid-column: 2; grid-row: 2; color: #6b7280; font-size: 12px; }
    #tb_tickets tbody td:nth-child(6) { grid-column: 2; grid-row: 3; color: #6b7280; font-size: 12px; }
    #tb_tickets tbody td:nth-child(11) { grid-column: 3; grid-row: 1 / span 3; align-self: center; }

    /* --- Sin procesar: [checkbox+Fecha] [Remitente / Asunto / Mensaje] [acciones] --- */
    #tb_nuevos tbody tr { grid-template-columns: 58px 1fr 90px; }
    #tb_nuevos tbody td:nth-child(5),
    #tb_nuevos tbody td:nth-child(7) { display: none !important; }
    #tb_nuevos tbody td:nth-child(1) { grid-column: 1; grid-row: 1; }
    #tb_nuevos tbody td:nth-child(6) { grid-column: 1; grid-row: 2; color: #6b7280; font-size: 11px; }
    #tb_nuevos tbody td:nth-child(2) { grid-column: 2; grid-row: 1; font-weight: 700; }
    #tb_nuevos tbody td:nth-child(3) { grid-column: 2; grid-row: 2; color: #6b7280; font-size: 12px; }
    #tb_nuevos tbody td:nth-child(4) { grid-column: 2; grid-row: 3; color: #6b7280; font-size: 12px; }
    #tb_nuevos tbody td:nth-child(8) { grid-column: 3; grid-row: 1 / span 3; align-self: center; }
    #tb_nuevos .buttons-icons .aprobar_ticket {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: 34px !important;
        height: 34px !important;
        padding: 0 !important;
        border-radius: 50% !important;
        background: var(--base2, #005639);
    }
    #tb_nuevos .buttons-icons .aprobar_ticket i { color: #fff !important; font-size: 17px !important; }
    #tb_nuevos .buttons-icons .rechazar_ticket { color: #6b7280 !important; }
    #tb_nuevos .buttons-icons .eliminar_correo { color: #ff4c52 !important; }

    /* --- Papelera (rechazadas): [Fecha] [Remitente / Asunto] [acciones] --- */
    #tb_rechazadas tbody td:nth-child(3),
    #tb_rechazadas tbody td:nth-child(4),
    #tb_rechazadas tbody td:nth-child(6) { display: none !important; }
    #tb_rechazadas tbody td:nth-child(5) { grid-column: 1; grid-row: 1 / span 2; align-self: start; color: #6b7280; font-size: 11px; }
    #tb_rechazadas tbody td:nth-child(1) { grid-column: 2; grid-row: 1; font-weight: 700; }
    #tb_rechazadas tbody td:nth-child(2) { grid-column: 2; grid-row: 2; color: #6b7280; font-size: 12px; }
    #tb_rechazadas tbody td:nth-child(7) { grid-column: 3; grid-row: 1 / span 2; align-self: center; }

    /* --- Papelera: [Fecha] [Asunto / Cliente / Comunidad] [acciones] --- */
    #tb_papelera tbody td:nth-child(1),
    #tb_papelera tbody td:nth-child(5),
    #tb_papelera tbody td:nth-child(7) { display: none !important; }
    #tb_papelera tbody td:nth-child(6) { grid-column: 1; grid-row: 1 / span 3; align-self: start; color: #6b7280; font-size: 11px; }
    #tb_papelera tbody td:nth-child(2) { grid-column: 2; grid-row: 1; font-weight: 700; }
    #tb_papelera tbody td:nth-child(3) { grid-column: 2; grid-row: 2; color: #6b7280; font-size: 12px; }
    #tb_papelera tbody td:nth-child(4) { grid-column: 2; grid-row: 3; color: #6b7280; font-size: 12px; }
    #tb_papelera tbody td:nth-child(8) { grid-column: 3; grid-row: 1 / span 3; align-self: center; }

    /* --- Filtros de Incidencias: rejilla + buscador a ancho completo --- */
    #tbfiltros,
    .tbfiltros {
        position: static !important;
        top: auto !important;
        left: auto !important;
        width: 100% !important;
        display: grid !important;
        grid-template-columns: 72px 1fr;
        align-items: end;
        gap: 8px 10px;
        margin: 0 0 8px !important;
    }

    #tbfiltros > div,
    .tbfiltros > div {
        display: block;
        width: auto !important;
        padding: 0 !important;
        margin: 0 !important;
        text-align: left !important;
        flex: none !important;
    }

    #tbfiltros label,
    .tbfiltros label {
        display: block;
        margin: 0 0 2px 2px !important;
        font-size: 10px;
        font-weight: 600;
        color: #6b7280;
        text-transform: uppercase;
        letter-spacing: .03em;
        white-space: nowrap;
    }

    #tbfiltros select,
    .tbfiltros select {
        width: 100% !important;
    }

    .dataTables_filter {
        float: none !important;
        width: calc(100% + 15px) !important;
        text-align: left !important;
        padding: 0 !important;
        margin: 0 0 8px -15px !important;
    }

    .dataTables_filter label {
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100% !important;
        margin: 0 !important;
        font-size: 10px;
        font-weight: 600;
        color: #6b7280;
        text-transform: uppercase;
        letter-spacing: .03em;
    }

    .dataTables_filter input {
        flex: 1 1 auto;
        width: auto !important;
        margin: 0 !important;
    }

    /* --- Info y paginación de DataTables --- */
    .dataTables_info,
    .dataTables_paginate {
        float: none !important;
        width: calc(100% + 15px) !important;
        margin-left: -15px !important;
        text-align: center !important;
        padding: 0 !important;
    }

    .dataTables_info {
        margin-top: 8px !important;
        margin-bottom: 8px !important;
    }

    .dataTables_paginate {
        white-space: normal !important;
        margin-top: 0 !important;
        margin-bottom: 8px !important;
    }

    .dataTables_paginate .pagination {
        display: flex !important;
        flex-wrap: wrap !important;
        justify-content: center !important;
        width: 100% !important;
        gap: 5px;
        margin: 0 !important;
        padding: 0 !important;
    }

    .dataTables_paginate .pagination .page-item {
        margin: 0 !important;
        float: none !important;
    }

    .dataTables_paginate .pagination .page-link {
        padding: 4px 9px;
        font-size: 12px;
        border-radius: 6px !important;
    }

    /* 4 números por página en móvil (ocultamos el 5.º) para que quepan las flechas */
    .dataTables_paginate .pagination > .page-item:nth-child(6) {
        display: none !important;
    }

    /* Recortar asunto/mensaje para filas compactas */
    #tb_nuevos tbody td:nth-child(3) {
        display: -webkit-box !important;
        -webkit-line-clamp: 1;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    #tb_nuevos tbody td:nth-child(4),
    #tb_tickets tbody td:nth-child(4) {
        display: -webkit-box !important;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
}
