/* =============================================
   Tables et Tableaux
   ============================================= */

/* Container de table */
.table-container {
    overflow: auto;
    /* Hauteur par défaut pour pages sans layout spécifique */
    max-height: 600px;
    position: relative;
    border-radius: var(--border-radius-md);
    background: white;
    box-shadow: var(--shadow-sm);
}

/* Pages split-view : hauteur contrôlée par flex layout dans layout.css */
main.split-view-tab .table-container {
    max-height: none; /* Pas de limite - le flex gère la hauteur */
}

/* Footer vide pour protéger les coins arrondis du scroll */
.table-container::after {
    content: '';
    display: block;
    height: 8px;
    background: white;
    border-bottom-left-radius: var(--border-radius-md);
    border-bottom-right-radius: var(--border-radius-md);
}

/* Table de base */
table {
    width: 100%;
    border-collapse: collapse;
    background: white;
}

/* Header sticky */
thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

thead th {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-light));
    color: white;
    padding: var(--spacing-md) var(--spacing-lg);
    text-align: left;
    font-weight: 600;
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

thead th:hover {
    cursor: pointer;
    background: var(--primary-dark);
}

/* Lignes du tableau */
tbody tr {
    border-bottom: 1px solid #e0e0e0;
    transition: var(--transition-fast);
}

tbody tr:hover {
    background: #f8f9fa;
}

tbody td {
    padding: var(--spacing-md) var(--spacing-lg);
    color: var(--text-dark);
    font-size: 14px;
}

/* Lignes de séparation de dates */
.date-separator-row {
    background: linear-gradient(135deg, #E3F2FD, #BBDEFB) !important;
}

.date-separator-row:hover {
    background: linear-gradient(135deg, #BBDEFB, #E3F2FD) !important;
}

.date-separator-row td {
    color: #1565C0;
    font-weight: bold;
    text-align: center;
    padding: var(--spacing-md);
    font-size: 15px;
}

/* Lignes vides */
tbody tr.empty {
    background: #f9f9f9;
    text-align: center;
    color: #999;
}

/* Actions dans les tableaux */
.actions {
    display: flex;
    gap: var(--spacing-xs);
    justify-content: flex-end;
}

.actions button {
    padding: 6px 12px;
    font-size: 12px;
    border-radius: var(--border-radius-sm);
}

/* States des lignes */
tr.success {
    background: #e8f5e9 !important;
}

tr.warning {
    background: #fff8e1 !important;
}

tr.error {
    background: #ffebee !important;
}

/* Responsive */
@media (max-width: 768px) {
    /* Tableaux mobiles: format compact 2 colonnes + actions */
    .table-container {
        overflow-x: hidden; /* Pas de scroll horizontal en mode compact */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        width: 100%;
    }

    table.mobile-table {
        width: 100%;
    }

    /* Masquer les colonnes non essentielles en mobile (garder colonnes 1, 2 et dernière) */
    table.mobile-table thead th:not(:nth-child(1)):not(:nth-child(2)):not(:last-child) {
        display: none;
    }

    table.mobile-table tbody td:not(:nth-child(1)):not(:nth-child(2)):not(:last-child) {
        display: none;
    }

    /* Si la dernière colonne est "Actions", la garder visible et compacte */
    table.mobile-table thead th:last-child,
    table.mobile-table tbody td:last-child {
        width: 70px;
        min-width: 70px;
    }

    /* Lignes expandables */
    .mobile-row.mobile-expandable {
        cursor: pointer;
        position: relative;
    }

    .mobile-row.mobile-expandable:hover {
        background: rgba(46, 204, 113, 0.05);
    }

    .mobile-expand-icon {
        display: inline-block;
        margin-right: 6px;
        font-size: 10px;
        color: var(--primary-color);
        transition: transform 0.2s;
        width: 12px;
        font-weight: bold;
    }

    .mobile-row.expanded .mobile-expand-icon {
        transform: rotate(90deg);
    }

    /* Ligne de détails */
    .mobile-details-row {
        background: #f8f9fa !important;
        border-top: 2px solid var(--primary-color) !important;
    }

    .mobile-details-row td {
        padding: var(--spacing-sm) !important;
    }

    .mobile-details-content {
        display: flex;
        flex-direction: column;
        gap: 6px;
    }

    .mobile-detail-item {
        display: flex;
        justify-content: space-between;
        align-items: start;
        padding: 6px 0;
        border-bottom: 1px solid #e0e0e0;
        gap: 10px;
    }

    .mobile-detail-item:last-child {
        border-bottom: none;
    }

    .mobile-detail-label {
        font-weight: 600;
        color: var(--text-dark);
        font-size: 11px;
        min-width: 90px;
        flex-shrink: 0;
    }

    .mobile-detail-value {
        font-size: 11px;
        color: #666;
        text-align: right;
        flex: 1;
        word-break: break-word;
    }

    /* Ajustements généraux */
    thead th, tbody td {
        padding: 8px 6px;
        font-size: 11px;
    }

    .date-separator-row td {
        font-size: 12px;
    }

    /* Actions plus compactes en mobile */
    .actions {
        gap: 3px;
        flex-wrap: nowrap;
        flex-direction: column;
    }

    .actions button {
        padding: 3px 6px;
        font-size: 9px;
        width: 100%;
        white-space: nowrap;
    }
}
