/* ==========================
   CONTENEDOR DE TABLA
========================== */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    background: var(--bg-card, #ffffff);
    border-radius: var(--radius-lg, 16px);
    box-shadow: var(--shadow-md, 0 4px 6px rgba(0, 0, 0, 0.1));
    margin: 20px 0;
    border: 1px solid #e2e8f0;
    -webkit-overflow-scrolling: touch;
}

.table-wrapper::-webkit-scrollbar {
    height: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 4px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* ==========================
   TABLA BASE
========================== */
table {
    width: 100%;
    border-collapse: collapse;
    background-color: #ffffff;
    font-size: 0.95rem;
    border-spacing: 0;
    table-layout: auto;
}

/* ==========================
   ENCABEZADOS
========================== */
thead {
    background: linear-gradient(135deg, #f8fafc 0%, #f1f5f9 100%);
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

th {
    text-align: left;
    padding: 16px 20px;
    font-weight: 700;
    color: var(--text-primary, #0f172a);
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    user-select: none;
}

th.sortable {
    cursor: pointer;
    transition: background-color var(--transition-fast, 150ms);
}

th.sortable:hover {
    background-color: rgba(99, 102, 241, 0.05);
}

th.sortable::after {
    content: '⇅';
    margin-left: 8px;
    opacity: 0.3;
    font-size: 0.8rem;
}

th.sortable.sort-asc::after {
    content: '↑';
    opacity: 1;
    color: #6366f1;
}

th.sortable.sort-desc::after {
    content: '↓';
    opacity: 1;
    color: #6366f1;
}

th.text-center,
td.text-center {
    text-align: center;
}

th.text-right,
td.text-right {
    text-align: right;
}

/* ==========================
   CUERPO DE LA TABLA
========================== */
tbody tr {
    transition: all var(--transition-fast, 150ms);
    border-bottom: 1px solid #f1f5f9;
}

tbody tr:last-child {
    border-bottom: none;
}

tbody tr:hover {
    background-color: #fafbff;
    transform: scale(1.001);
    box-shadow: 0 2px 4px rgba(99, 102, 241, 0.05);
}

td {
    padding: 14px 20px;
    vertical-align: middle;
    color: var(--text-primary, #0f172a);
    white-space: nowrap;
}

tbody tr:nth-child(even) {
    background-color: #fafbfc;
}

tbody tr:nth-child(even):hover {
    background-color: #fafbff;
}

/* ==========================
   TABLA COMPACTA
========================== */
.table-compact th {
    padding: 10px 14px;
    font-size: 0.85rem;
}

.table-compact td {
    padding: 8px 14px;
    font-size: 0.9rem;
}

/* ==========================
   TABLA ESPACIOSA
========================== */
.table-spacious th {
    padding: 20px 24px;
}

.table-spacious td {
    padding: 18px 24px;
}

/* ==========================
   TABLA CON BORDES
========================== */
.table-bordered {
    border: 1px solid #e2e8f0;
}

.table-bordered th,
.table-bordered td {
    border: 1px solid #e2e8f0;
}

/* ==========================
   TABLA SIN LÍNEAS
========================== */
.table-borderless tbody tr {
    border-bottom: none;
}

.table-borderless td {
    border: none;
}

/* ==========================
   COLUMNA DE ACCIONES
========================== */
td.actions {
    text-align: right;
    white-space: nowrap;
}

td.actions .btn {
    margin-left: 6px;
}

td.actions .btn:first-child {
    margin-left: 0;
}

.action-group {
    display: inline-flex;
    gap: 6px;
    align-items: center;
}

/* ==========================
   BADGES DE ESTADO
========================== */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.status-badge::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    margin-right: 6px;
}

.status-pagado,
.status-success {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.status-pagado::before,
.status-success::before {
    background-color: #10b981;
    box-shadow: 0 0 0 2px #d1fae5;
}

.status-pendiente,
.status-danger {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.status-pendiente::before,
.status-danger::before {
    background-color: #ef4444;
    box-shadow: 0 0 0 2px #fee2e2;
}

.status-parcial,
.status-warning {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
}

.status-parcial::before,
.status-warning::before {
    background-color: #f59e0b;
    box-shadow: 0 0 0 2px #fef3c7;
}

.status-info {
    background-color: #dbeafe;
    color: #1e40af;
    border: 1px solid #bfdbfe;
}

.status-info::before {
    background-color: #3b82f6;
    box-shadow: 0 0 0 2px #dbeafe;
}

.status-neutral {
    background-color: #f1f5f9;
    color: #475569;
    border: 1px solid #e2e8f0;
}

.status-neutral::before {
    background-color: #64748b;
    box-shadow: 0 0 0 2px #f1f5f9;
}

/* ==========================
   AVATAR EN TABLA
========================== */
.table-avatar {
    display: inline-flex;
    align-items: center;
    gap: 12px;
}

.table-avatar img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #e2e8f0;
}

.table-avatar .avatar-placeholder {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.85rem;
}

/* ==========================
   TABLA VACÍA
========================== */
.table-empty {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-secondary, #64748b);
}

.table-empty-icon {
    font-size: 3rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

.table-empty-text {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.table-empty-subtext {
    font-size: 0.9rem;
    color: #94a3b8;
}

/* ==========================
   LOADING STATE
========================== */
.table-loading {
    position: relative;
    opacity: 0.5;
    pointer-events: none;
}

.table-loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 40px;
    height: 40px;
    margin: -20px 0 0 -20px;
    border: 4px solid #e2e8f0;
    border-top-color: #6366f1;
    border-radius: 50%;
    animation: spinner 0.8s linear infinite;
}

@keyframes spinner {
    to {
        transform: rotate(360deg);
    }
}

/* ==========================
   FILTROS Y BÚSQUEDA
========================== */
.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    flex-wrap: wrap;
    gap: 12px;
}

.table-header h3 {
    margin: 0;
    color: var(--text-primary, #0f172a);
}

.table-filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

/* ==========================
   PAGINACIÓN PROFESIONAL
========================== */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 24px;
    padding: 20px 24px;
    background: var(--bg-card, #ffffff);
    border-radius: var(--radius-md, 10px);
    box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
    border: 1px solid #e2e8f0;
    gap: 16px;
    flex-wrap: wrap;
}

.pagination-info {
    font-size: 0.9rem;
    color: var(--text-secondary, #64748b);
    display: flex;
    align-items: center;
    gap: 8px;
}

.pagination-info strong {
    color: var(--text-primary, #0f172a);
    font-weight: 600;
}

/* Controles de paginación */
.pagination {
    display: flex;
    align-items: center;
    gap: 6px;
    list-style: none;
    margin: 0;
    padding: 0;
}

.pagination-item {
    display: inline-flex;
}

.pagination-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 8px 12px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-primary, #0f172a);
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm, 6px);
    text-decoration: none;
    transition: all var(--transition-fast, 150ms);
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.pagination-link::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.1), transparent);
    transition: left var(--transition-base, 250ms);
}

.pagination-link:hover::before {
    left: 100%;
}

.pagination-link:hover {
    border-color: #6366f1;
    color: #6366f1;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.2);
}

.pagination-link:active {
    transform: translateY(0);
}

.pagination-link.active {
    background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    color: white;
    border-color: #6366f1;
    font-weight: 600;
    box-shadow: 0 4px 8px rgba(99, 102, 241, 0.3);
    cursor: default;
    pointer-events: none;
}

.pagination-link.disabled {
    opacity: 0.4;
    cursor: not-allowed;
    pointer-events: none;
}

.pagination-link.arrow {
    font-size: 1.1rem;
}

.pagination-ellipsis {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    color: var(--text-secondary, #64748b);
    font-weight: 600;
}

/* Selector de registros por página */
.pagination-per-page {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-secondary, #64748b);
}

.pagination-per-page label {
    margin-bottom: 0;
    font-weight: 500;
}

.pagination-per-page select {
    padding: 8px 32px 8px 12px;
    font-size: 0.9rem;
    border: 1px solid #e2e8f0;
    border-radius: var(--radius-sm, 6px);
    background-color: #ffffff;
    cursor: pointer;
    transition: all var(--transition-fast, 150ms);
    min-width: 80px;
}

.pagination-per-page select:hover {
    border-color: #cbd5e1;
}

.pagination-per-page select:focus {
    outline: none;
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* ==========================
   RESPONSIVE - MÓVIL
========================== */
@media screen and (max-width: 768px) {
    .table-wrapper {
        border-radius: var(--radius-md, 10px);
        margin: 16px 0;
        box-shadow: var(--shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.05));
    }

    th, td {
        padding: 10px 12px;
        font-size: 0.8rem;
    }

    th {
        padding: 12px;
        font-size: 0.75rem;
    }

    th.hide-mobile,
    td.hide-mobile {
        display: none;
    }

    .status-badge {
        font-size: 0.7rem;
        padding: 3px 8px;
    }

    td.actions .btn {
        padding: 6px 10px;
        font-size: 0.75rem;
    }

    /* Paginación responsive */
    .pagination-container {
        flex-direction: column;
        align-items: stretch;
        gap: 16px;
        padding: 16px;
    }

    .pagination-info {
        justify-content: center;
        text-align: center;
    }

    .pagination {
        justify-content: center;
        flex-wrap: wrap;
    }

    .pagination-link {
        min-width: 36px;
        height: 36px;
        padding: 6px 10px;
        font-size: 0.85rem;
    }

    .pagination-ellipsis {
        min-width: 36px;
        height: 36px;
    }

    .pagination-per-page {
        justify-content: center;
    }

    .pagination-item.hide-mobile {
        display: none;
    }

    .table-wrapper::after {
        content: '← Desliza →';
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
        background: rgba(99, 102, 241, 0.9);
        color: white;
        padding: 4px 12px;
        border-radius: 4px 4px 0 0;
        font-size: 0.7rem;
        pointer-events: none;
        opacity: 0;
        animation: fadeInOut 3s ease-in-out;
    }

    @keyframes fadeInOut {
        0%, 100% { opacity: 0; }
        10%, 90% { opacity: 1; }
    }

    /* Layout de tarjetas para móvil */
    .table-responsive-cards {
        display: block;
        overflow-x: visible;
    }

    .table-responsive-cards thead {
        display: none;
    }

    .table-responsive-cards tbody,
    .table-responsive-cards tr,
    .table-responsive-cards td {
        display: block;
        width: 100%;
    }

    .table-responsive-cards tr {
        margin-bottom: 16px;
        border: 1px solid #e2e8f0;
        border-radius: var(--radius-md, 10px);
        padding: 16px;
        background: white;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    }

    .table-responsive-cards tr:hover {
        transform: none;
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    }

    /* ✅ LÍNEAS SEPARADORAS AGREGADAS */
    .table-responsive-cards td {
        padding: 10px 0;
        border: none;
        border-bottom: 1px solid #f1f5f9;
        position: relative;
        padding-left: 50%;
        text-align: right;
        white-space: normal;
    }

    /* ✅ ÚLTIMO ELEMENTO SIN LÍNEA */
    .table-responsive-cards td:last-child {
        border-bottom: none;
    }

    .table-responsive-cards td::before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        width: 45%;
        padding-right: 10px;
        white-space: normal;
        text-align: left;
        font-weight: 700;
        color: var(--text-secondary, #64748b);
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.3px;
    }

    /* ✅ SEPARADOR MÁS GRUESO PARA ACCIONES */
    .table-responsive-cards td.actions {
        text-align: center;
        padding-left: 0;
        padding-top: 16px;
        margin-top: 12px;
        border-top: 2px solid #e2e8f0;
        border-bottom: none;
    }

    .table-responsive-cards td.actions::before {
        display: none;
    }

    .table-responsive-cards td.actions .btn {
        margin: 4px;
    }
}

@media screen and (max-width: 480px) {
    .pagination-link {
        min-width: 32px;
        height: 32px;
        padding: 4px 8px;
        font-size: 0.8rem;
    }

    .pagination-ellipsis {
        min-width: 32px;
        height: 32px;
    }
}

/* ==========================
   TABLA DESTACADA/SELECCIONADA
========================== */
tbody tr.selected {
    background-color: #ede9fe !important;
    border-left: 4px solid #6366f1;
}

tbody tr.highlighted {
    background-color: #fef3c7 !important;
    animation: highlight-pulse 1.5s ease-in-out;
}

@keyframes highlight-pulse {
    0%, 100% {
        background-color: #fef3c7;
    }
    50% {
        background-color: #fde68a;
    }
}

/* ==========================
   SOMBRA DE SCROLL
========================== */
.table-wrapper {
    position: relative;
}

.table-wrapper.has-scroll-left::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(90deg, rgba(0,0,0,0.1), transparent);
    pointer-events: none;
    z-index: 5;
}

.table-wrapper.has-scroll-right::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 20px;
    height: 100%;
    background: linear-gradient(-90deg, rgba(0,0,0,0.1), transparent);
    pointer-events: none;
    z-index: 5;
}