/**
 * Tables Optimized - Styles DSFR améliorés
 * Pour Formajes - Amélioration visuelle des tableaux
 */

/* ========================================
   MENU DROPDOWN ACTIONS (tous écrans)
   ======================================== */

.table-actions-dropdown {
    position: relative;
    display: inline-block;
}

.table-actions-dropdown__toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    cursor: pointer;
    background: none;
    border: 1px solid var(--text-action-high-blue-france);
    border-radius: 0;
    padding: 0.25rem 0.5rem;
    font-weight: 500;
    color: var(--text-action-high-blue-france);
    transition: all 0.2s ease;
    min-height: 28px;
    white-space: nowrap;
}

.table-actions-dropdown__toggle:hover {
    background: var(--background-alt-blue-france);
    border-color: var(--border-action-high-blue-france);
    box-shadow: 0 2px 4px rgba(0, 0, 145, 0.08);
}

.table-actions-dropdown__toggle:focus {
    outline: 2px solid var(--border-action-high-blue-france);
    outline-offset: 2px;
}

/* Flèche indicatrice */
.table-actions-dropdown__toggle::after {
    content: '';
    display: inline-block;
    width: 0;
    height: 0;
    border-left: 4px solid transparent;
    border-right: 4px solid transparent;
    border-top: 4px solid currentColor;
    transition: transform 0.2s ease;
    margin-left: 0.25rem;
}

.table-actions-dropdown.is-open .table-actions-dropdown__toggle {
    background: var(--background-alt-blue-france);
    border-color: var(--border-action-high-blue-france);
}

.table-actions-dropdown.is-open .table-actions-dropdown__toggle::after {
    transform: rotate(180deg);
}

.table-actions-dropdown__menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    z-index: 999;
    display: none;
    padding: 0;
    background: var(--background-default-grey);
    border: 1px solid var(--border-default-grey);
    border-radius: 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12), 0 2px 8px rgba(0, 0, 0, 0.08);
}

.table-actions-dropdown.dropdown-left .table-actions-dropdown__menu {
    right: auto;
    left: 0;
}

.table-actions-dropdown__menu form {
    margin: 0;
}

/* Ouvrir vers le haut si proche du bas du tableau */
.table-actions-dropdown.is-open.dropdown-up .table-actions-dropdown__menu {
    top: auto;
    bottom: calc(100% + 4px);
}

.table-actions-dropdown.is-open .table-actions-dropdown__menu {
    display: block;
    animation: dropdownFadeIn 0.15s ease forwards;
}

.table-actions-dropdown__item {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--text-default-grey);
    background: none;
    border: none;
    cursor: pointer;
    text-align: left;
    text-decoration: none;
    transition: all 0.15s ease;
    gap: 0.625rem;
    white-space: nowrap;
}

.table-actions-dropdown__item:hover {
    background: var(--background-alt-blue-france);
    color: var(--text-action-high-blue-france);
}

.table-actions-dropdown__item:focus {
    outline: none;
    background: var(--background-alt-blue-france);
    color: var(--text-action-high-blue-france);
}

.table-actions-dropdown__item [class^="fr-icon-"],
.table-actions-dropdown__item [class*=" fr-icon-"] {
    font-size: 1rem;
    flex-shrink: 0;
}

.table-actions-dropdown__item--danger {
    color: var(--text-default-error);
}

.table-actions-dropdown__item--danger:hover {
    background: var(--background-alt-red-marianne);
    color: var(--text-default-error);
}

.table-actions-dropdown__item[disabled] {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.table-actions-dropdown__divider {
    height: 1px;
    background: var(--border-default-grey);
    margin: 0.375rem 0.75rem;
}

/* ========================================
   ACTIONS DE TABLE (tous écrans)
   ======================================== */

.table-actions-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: nowrap;
}

.table-actions-group .fr-btn--primary-action {
    white-space: nowrap;
}

.table-actions-cell {
    text-align: right;
    white-space: nowrap;
}

/* ========================================
   ANIMATION DROPDOWN (tous écrans)
   ======================================== */

@keyframes dropdownFadeIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ========================================
   MOBILE - Optimisations bords
   ======================================== */

@media (max-width: 767px) {
    /* Réduire padding des tableaux sur mobile */
    .fr-table--optimized th,
    .fr-table--optimized td {
        padding: 0.375rem 0.25rem;
    }
    
    /* Dropdown menu position mobile */
    .table-actions-dropdown__menu {
        right: 0;
        left: auto;
        min-width: 180px;
    }
    
    /* Réduire taille des items dropdown */
    .table-actions-dropdown__item {
        padding: 0.5rem 0.75rem;
        font-size: 0.8125rem;
    }
}

/* ========================================
   DESKTOP ONLY - Styles tableaux optimisés
   ======================================== */

@media (min-width: 768px) {
    /* CELLULES COMPACTES MULTI-LIGNES */
    .table-cell-compact {
        display: flex;
        flex-direction: column;
        gap: 0.125rem;
    }
    
    .table-cell-compact__primary {
        font-weight: 600;
        color: var(--text-default-grey);
        line-height: 1.25;
    }
    
    .table-cell-compact__secondary {
        font-size: 0.75rem;
        color: var(--text-mention-grey);
        line-height: 1.2;
    }
    
    .table-cell-compact__tertiary {
        font-size: 0.6875rem;
        color: var(--text-disabled-grey);
        line-height: 1.2;
    }
    
    /* Lien dans cellule compacte */
    .table-cell-compact__primary a {
        color: inherit;
        text-decoration: none;
    }
    
    .table-cell-compact__primary a:hover {
        text-decoration: underline;
        color: var(--text-action-high-blue-france);
    }
    
    /* Badge inline dans cellule */
    .table-cell-compact .fr-badge {
        font-size: 0.625rem;
        padding: 0.125rem 0.375rem;
        margin-left: 0.25rem;
    }

    /* BADGES STATUT */
    .status-badge-group {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .status-badge-group .fr-badge {
        display: inline-block;
        width: fit-content;
    }
    
    .fr-table--optimized table {
        overflow: visible;
    }
    
    .fr-table--optimized th,
    .fr-table--optimized td {
        padding: 0.5rem 0.75rem;
        vertical-align: middle;
    }
    
    .fr-table--optimized th {
        font-size: 0.75rem;
        text-transform: uppercase;
        letter-spacing: 0.02em;
        white-space: nowrap;
    }
    
    /* Largeurs fixes pour colonnes */
    .fr-table--optimized .col-toggle {
        width: 80px;
        min-width: 80px;
    }
    
    .fr-table--optimized .col-actions {
        width: 140px;
        min-width: 140px;
        text-align: right;
    }
    
    .fr-table--optimized .col-status {
        width: 100px;
        min-width: 100px;
    }
    
    .fr-table--optimized .col-budget {
        width: 100px;
        min-width: 100px;
        text-align: right;
    }
    
    /* Colonne principale extensible */
    .fr-table--optimized .col-main {
        min-width: 200px;
    }
    
    /* LIGNE DE TABLEAU INTERACTIVE */
    .fr-table--optimized tbody tr {
        transition: background 0.1s ease;
    }
    
    .fr-table--optimized tbody tr:hover {
        background: var(--background-alt-grey);
    }	
    
    /* MODALE DÉTAILS */
    .details-modal__grid {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
    
    .details-modal__item {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }
    
    .details-modal__label {
        font-size: 0.75rem;
        font-weight: 600;
        color: var(--text-mention-grey);
        text-transform: uppercase;
        letter-spacing: 0.03em;
    }
    
    .details-modal__value {
        font-size: 0.875rem;
        color: var(--text-default-grey);
    }
    
    /* AMÉLIORATIONS DATATABLES */
    .dataTables_wrapper .fr-table--optimized {
        margin-top: 0 !important;
    }
    
    .dataTables_filter input {
        border: 1px solid var(--border-default-grey) !important;
        border-radius: 0.25rem !important;
        padding: 0.375rem 0.625rem !important;
        font-size: 0.875rem !important;
    }
    
    .dataTables_filter input:focus {
        outline: 2px solid var(--border-action-high-blue-france) !important;
        outline-offset: 2px !important;
    }
}

.fr-table--optimized .fr-table__container,
.fr-table:has(.table-actions-dropdown) .fr-table__wrapper,
.fr-table:has(.table-actions-dropdown) .fr-table__container,
.fr-table:has(.table-actions-dropdown) .fr-table__content {
    overflow: visible;
}

/* Masquer les indicateurs de scroll DSFR (flèches géantes) */
.fr-table .fr-table__wrapper::before,
.fr-table .fr-table__wrapper::after {
    display: none !important;
}

/* ========================================
   TABLETTE - Ajustements
   ======================================== */

@media (min-width: 768px) and (max-width: 991px) {
    .table-actions-group {
        flex-direction: column;
        align-items: flex-end;
        gap: 0.25rem;
    }
    
    .table-actions-dropdown__menu {
        right: 0;
        left: auto;
    }
}

/* ========================================
   TRÈS PETIT ÉCRAN
   ======================================== */

@media (max-width: 576px) {
    .details-modal__grid {
        grid-template-columns: 1fr;
    }
    
    /* Dropdown s'ouvre à gauche sur très petit écran */
    .table-actions-dropdown__menu {
        right: auto;
        left: 0;
    }
}

/* ========================================
   AUTRES STYLES GLOBAUX
   ======================================== */

.fr-translate .fr-menu__list {
    grid-auto-flow: unset!important;
}
