/* =============================================================================
   CSS RESPONSIVE MOBILE - Captain Repair
   FOCUS sur un affichage cart mobile vraiment propre et simple
   ============================================================================= */

@media (max-width: 991.98px) {

    /* ===== AMÉLIORATION GÉNÉRALE DE L'UX MOBILE ===== */

    /* Headers de pages plus compacts */
    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column;
        align-items: flex-start !important;
        gap: 1rem;
    }

    .d-flex.justify-content-between.align-items-center.mb-4 h2 {
        font-size: 1.5rem;
        margin-bottom: 0;
    }

    .d-flex.justify-content-between.align-items-center.mb-4 .badge {
        align-self: flex-end;
    }

    /* Boutons de navigation pleine largeur */
    .btn-outline-secondary,
    .btn-outline-primary {
        width: 100%;
        margin-bottom: 1rem;
    }

    /* ===== CART MOBILE SPÉCIAL - SYSTÈME ACCORDÉON ===== */

    /* Groupes fournisseurs adaptés */
    .supplier-group .card-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 0.75rem;
        padding: 0.75rem;
    }

    .supplier-group .card-header h5 {
        width: 100%;
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 0.5rem;
        font-size: 1rem;
    }

    .supplier-group .card-header .d-flex {
        width: 100%;
        justify-content: space-between !important;
        flex-wrap: wrap;
        gap: 0.75rem;
    }

    .supplier-group .card-header .create-po-btn {
        width: 100%;
        margin-top: 0.25rem;
        font-size: 0.9rem;
        padding: 0.5rem;
    }

    /* ===== TRANSFORMATION CART TABLE - ACCORDÉON ===== */

    /* Cache l'en-tête du tableau cart */
    .cart-table thead {
        display: none;
    }

    /* Chaque ligne devient un accordéon */
    .cart-table tbody tr {
        display: block;
        background: var(--bs-body-bg);
        border: 1px solid var(--bs-border-color);
        border-radius: 0.5rem;
        margin-bottom: 0.75rem;
        padding: 0;
        box-shadow: 0 2px 4px rgba(0,0,0,0.08);
        overflow: hidden;
        cursor: pointer;
        transition: all 0.3s ease;
    }

    .cart-table tbody tr:hover {
        box-shadow: 0 4px 8px rgba(0,0,0,0.12);
        transform: translateY(-1px);
    }

    /* Reset des cellules */
    .cart-table td {
        display: block;
        border: none !important;
        padding: 0 !important;
        width: 100% !important;
    }

    /* === HEADER ACCORDÉON (toujours visible) === */
    .cart-table td:nth-child(1) {
        background: var(--bs-primary);
        color: white;
        padding: 1rem !important;
        position: relative;
        cursor: pointer;
    }

    /* Indicateur d'expansion */
    .cart-table td:nth-child(1):after {
        content: "⌄";
        position: absolute;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
        font-size: 1.2rem;
        transition: transform 0.3s ease;
        opacity: 0.8;
    }

    .cart-table tbody tr.expanded .cart-table td:nth-child(1):after,
    .cart-table tbody tr.expanded td:nth-child(1):after {
        transform: translateY(-50%) rotate(180deg);
    }

    /* Layout en 3 colonnes dans le header */
    .cart-table td:nth-child(1) .mobile-summary {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        gap: 0.75rem;
        padding-right: 2rem; /* Espace pour l'indicateur ⌄ */
    }

    .cart-table td:nth-child(1) .product-info {
        flex: 1;
        min-width: 0;
        max-width: 60%;
    }

    .cart-table td:nth-child(1) .product-name {
        font-size: 0.9rem;
        font-weight: 600;
        margin-bottom: 0.25rem;
        line-height: 1.2;
        word-break: break-word;
        overflow-wrap: break-word;
        white-space: normal;
    }

    .cart-table td:nth-child(1) .product-ref {
        font-size: 0.7rem;
        opacity: 0.9;
        background: rgba(255,255,255,0.15);
        padding: 0.125rem 0.375rem;
        border-radius: 0.25rem;
        display: inline-block;
        word-break: break-word;
    }

    .cart-table td:nth-child(1) .quantity-info {
        text-align: center;
        min-width: 40px;
        flex-shrink: 0;
    }

    .cart-table td:nth-child(1) .quantity-value {
        font-size: 1.2rem;
        font-weight: 600;
        color: rgba(255,255,255,0.95);
    }

    .cart-table td:nth-child(1) .total-info {
        text-align: right;
        min-width: 70px;
        flex-shrink: 0;
    }

    .cart-table td:nth-child(1) .total-value {
        font-size: 1rem;
        font-weight: 600;
        color: rgba(255,255,255,0.95);
    }

    /* === SECTIONS DÉTAIL (cachées par défaut) === */
    .cart-table td:nth-child(2),
    .cart-table td:nth-child(3),
    .cart-table td:nth-child(4),
    .cart-table td:nth-child(5),
    .cart-table td:nth-child(6),
    .cart-table td:nth-child(7),
    .cart-table td:nth-child(8) {
        display: none;
        opacity: 0;
        max-height: 0;
        overflow: hidden;
        transition: all 0.3s ease;
    }

    /* Quand la ligne est expandée */
    .cart-table tbody tr.expanded td:nth-child(2),
    .cart-table tbody tr.expanded td:nth-child(3),
    .cart-table tbody tr.expanded td:nth-child(4),
    .cart-table tbody tr.expanded td:nth-child(5),
    .cart-table tbody tr.expanded td:nth-child(6),
    .cart-table tbody tr.expanded td:nth-child(7),
    .cart-table tbody tr.expanded td:nth-child(8) {
        display: block;
        opacity: 1;
        max-height: 200px;
        animation: slideDown 0.3s ease;
    }

    @keyframes slideDown {
        from {
            opacity: 0;
            max-height: 0;
        }
        to {
            opacity: 1;
            max-height: 200px;
        }
    }

    /* === SECTION QUANTITÉ (dans le détail) === */
    .cart-table tbody tr.expanded td:nth-child(2) {
        padding: 1rem !important;
        background: var(--bs-light);
        border-bottom: 1px solid var(--bs-border-color);
        display: flex !important;
        justify-content: center;
        align-items: center;
        gap: 1rem;
    }

    .cart-table tbody tr.expanded td:nth-child(2):before {
        content: "Ajuster la quantité";
        font-weight: 600;
        color: var(--bs-secondary);
        font-size: 0.9rem;
        margin-right: 1rem;
    }

    .cart-table tbody tr.expanded td:nth-child(2) .input-group {
        max-width: 120px !important;
        margin: 0 !important;
    }

    /* === SECTIONS PRIX (dans le détail) === */
    .cart-table tbody tr.expanded td:nth-child(3),
    .cart-table tbody tr.expanded td:nth-child(4),
    .cart-table tbody tr.expanded td:nth-child(5),
    .cart-table tbody tr.expanded td:nth-child(6) {
        padding: 0.75rem 1rem !important;
        border-bottom: 1px solid var(--bs-border-color);
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        background: rgba(248, 249, 250, 0.5);
    }

    .cart-table tbody tr.expanded td:nth-child(3):before { content: "Prix unitaire HT"; }
    .cart-table tbody tr.expanded td:nth-child(4):before { content: "Prix unitaire TTC"; }
    .cart-table tbody tr.expanded td:nth-child(5):before { content: "Sous-total HT"; }
    .cart-table tbody tr.expanded td:nth-child(6):before { content: "Sous-total TTC"; }

    .cart-table tbody tr.expanded td:nth-child(3):before,
    .cart-table tbody tr.expanded td:nth-child(4):before,
    .cart-table tbody tr.expanded td:nth-child(5):before,
    .cart-table tbody tr.expanded td:nth-child(6):before {
        font-weight: 600;
        color: var(--bs-secondary);
        font-size: 0.85rem;
    }

    /* Mise en évidence des totaux */
    .cart-table tbody tr.expanded td:nth-child(5),
    .cart-table tbody tr.expanded td:nth-child(6) {
        background: rgba(25, 135, 84, 0.1);
        font-weight: 600;
    }

    /* === SECTION STOCK === */
    .cart-table tbody tr.expanded td:nth-child(7) {
        padding: 0.75rem 1rem !important;
        border-bottom: 1px solid var(--bs-border-color);
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        background: rgba(13, 202, 240, 0.1);
    }

    .cart-table tbody tr.expanded td:nth-child(7):before {
        content: "Stock fournisseur";
        font-weight: 600;
        color: var(--bs-secondary);
        font-size: 0.85rem;
    }

    /* === SECTION ACTIONS === */
    .cart-table tbody tr.expanded td:nth-child(8) {
        padding: 1rem !important;
        background: var(--bs-light);
        text-align: center;
    }

    .cart-table tbody tr.expanded td:nth-child(8):before {
        content: "Actions";
        display: block;
        font-weight: 600;
        color: var(--bs-secondary);
        margin-bottom: 0.75rem;
        font-size: 0.9rem;
    }

    .cart-table tbody tr.expanded td:nth-child(8) .btn {
        width: 100%;
        margin-bottom: 0.5rem;
        font-size: 0.9rem;
        padding: 0.75rem;
    }

    /* ===== AUTRES TABLEAUX (suggestions, po, etc.) ===== */

    .suggestions-table thead,
    .po-table thead,
    .po-details-table thead {
        display: none;
    }

    .suggestions-table tbody tr,
    .po-table tbody tr,
    .po-details-table tbody tr {
        display: block;
        background: var(--bs-body-bg);
        border: 1px solid var(--bs-border-color);
        border-radius: 0.5rem;
        margin-bottom: 1rem;
        padding: 1rem;
        box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    }

    .suggestions-table td,
    .po-table td,
    .po-details-table td {
        display: block;
        border: none !important;
        padding: 0.5rem 0 !important;
        position: relative;
        padding-left: 45% !important;
        min-height: 1.5rem;
    }

    .suggestions-table td:before,
    .po-table td:before,
    .po-details-table td:before {
        content: attr(data-label);
        position: absolute;
        left: 0;
        top: 0.5rem;
        font-weight: 600;
        color: var(--bs-secondary);
        width: 40%;
        text-align: left;
        font-size: 0.85rem;
    }

    /* Labels pour les autres tables */
    .suggestions-table td:nth-child(1):before { content: "Produit"; }
    .suggestions-table td:nth-child(2):before { content: "Type"; }
    .suggestions-table td:nth-child(3):before { content: "Stock"; }
    .suggestions-table td:nth-child(4):before { content: "Commandes"; }
    .suggestions-table td:nth-child(5):before { content: "Min/Max"; }
    .suggestions-table td:nth-child(6):before { content: "À commander"; }
    .suggestions-table td:nth-child(7):before { content: "Statut"; }
    .suggestions-table td:nth-child(8):before { content: "Fournisseurs"; }
    .suggestions-table td:nth-child(9):before { content: "Action"; }

    .po-table td:nth-child(1):before { content: "N° Commande"; }
    .po-table td:nth-child(2):before { content: "Fournisseur"; }
    .po-table td:nth-child(3):before { content: "Date"; }
    .po-table td:nth-child(4):before { content: "Statut"; }
    .po-table td:nth-child(5):before { content: "Total"; }
    .po-table td:nth-child(6):before { content: "Actions"; }

    .po-details-table td:nth-child(1):before { content: "Produit"; }
    .po-details-table td:nth-child(2):before { content: "Quantité"; }
    .po-details-table td:nth-child(3):before { content: "Prix unitaire"; }
    .po-details-table td:nth-child(4):before { content: "Total"; }
    .po-details-table td:nth-child(5):before { content: "Statut"; }

    /* ===== AMÉLIORATIONS GÉNÉRALES ===== */
    .price-ht {
        color: var(--bs-success) !important;
        font-weight: 600;
    }

    .price-ttc {
        color: var(--bs-primary) !important;
        font-weight: 600;
    }

    .total-amount {
        font-size: 1.2rem !important;
        font-weight: bold !important;
    }

    .btn {
        min-height: 44px;
        touch-action: manipulation;
    }

    .form-control, .form-select {
        min-height: 44px;
    }
}

/* ===== BREAKPOINT TRÈS PETIT ===== */
@media (max-width: 575.98px) {
    .d-flex.justify-content-between.align-items-center.mb-4 h2 {
        font-size: 1.25rem !important;
    }

    .cart-table td:nth-child(1) {
        padding: 0.75rem !important;
    }

    .cart-table td:nth-child(1) .item-name {
        font-size: 1.1rem;
    }

    .suggestions-table tbody tr,
    .po-table tbody tr,
    .po-details-table tbody tr {
        padding: 0.75rem;
    }
}

/* ===== DARK MODE ===== */
html.dark-mode .cart-table tbody tr,
html.dark-mode .suggestions-table tbody tr,
html.dark-mode .po-table tbody tr,
html.dark-mode .po-details-table tbody tr {
    background: var(--bs-dark);
    border-color: var(--bs-border-color-translucent);
}

html.dark-mode .cart-table td:nth-child(2),
html.dark-mode .cart-table td:nth-child(8) {
    background: var(--bs-gray-dark) !important;
}
