/*
    Adaptations mobiles du module Gestion des articles.

    Règles uniquement sous @media (max-width: 1023px) : le bureau n'est pas modifié.
    Ce fichier peut être retiré sans impact sur le fonctionnement desktop.
*/

@media (max-width: 1023px) {
    .item-management-page.matrix-container {
        height: calc(100dvh - var(--matrix-top-bar-height, 56px));
        padding-bottom: env(safe-area-inset-bottom);
    }

    .item-management-page .im-mobile-pane-switch {
        display: flex;
    }

    .item-management-page .matrix-header-content {
        flex-direction: row;
        align-items: center;
        padding: 0.5rem 0.75rem;
        gap: 0.5rem;
    }

    .item-management-page .matrix-header-actions,
    .item-management-page .sp-header-actions,
    .item-management-page .finished-product-header-options {
        width: auto;
        margin-left: auto;
        flex-shrink: 0;
    }

    .item-management-page .matrix-header-actions .btn,
    .item-management-page .finished-product-header-options .btn,
    .item-management-page .sp-header-actions .btn {
        width: auto;
        min-height: 44px;
    }

    .item-management-page .matrix-header-bar:has(.catalog-us-page-tabs) .matrix-header-content {
        flex-direction: column;
        align-items: stretch;
    }

    .item-management-page .catalog-us-page-tabs {
        width: 100%;
    }

    .item-management-page .catalog-us-page-tabs .btn {
        flex: 1;
        min-height: 44px;
    }

    /* ── Panneaux : un seul visible à la fois ── */
    .item-management-page .matrix-scrollable-content:has(.im-mobile-panes) {
        overflow: hidden;
        display: flex;
        flex-direction: column;
        flex: 1;
        min-height: 0;
    }

    .item-management-page .im-mobile-panes {
        flex: 1;
        min-height: 0;
        height: auto !important;
        min-height: 0 !important;
        display: flex !important;
        flex-direction: column;
        grid-template-columns: none !important;
    }

    .item-management-page .im-mobile-panes > * {
        display: none !important;
        width: 100% !important;
        min-width: 0 !important;
        height: 100% !important;
        flex: 1;
        border-right: none !important;
        border-bottom: none !important;
    }

    .item-management-page .im-mobile-panes[data-mobile-pane="list"] > .catalog-list-pane,
    .item-management-page .im-mobile-panes[data-mobile-pane="params"] > .catalog-params-pane,
    .item-management-page .im-mobile-panes[data-mobile-pane="docs"] > .catalog-docs-pane,
    .item-management-page .im-mobile-panes[data-mobile-pane="items"] > .sp-items-pane,
    .item-management-page .im-mobile-panes[data-mobile-pane="variants"] > .sp-variants-pane,
    .item-management-page .im-mobile-panes[data-mobile-pane="prices"] > .sp-detail-pane,
    .item-management-page .im-mobile-panes[data-mobile-pane="list"] > .variant-desc-list-pane,
    .item-management-page .im-mobile-panes[data-mobile-pane="detail"] > .variant-desc-detail-pane {
        display: flex !important;
        flex-direction: column;
    }

    .item-management-page .im-mobile-panes .scroll-auto,
    .item-management-page .im-mobile-panes .phasing-card-body,
    .item-management-page .im-mobile-panes .catalog-pane-body {
        max-height: none;
        flex: 1;
        min-height: 0;
    }

    .item-management-page .sp-detail-pane,
    .item-management-page .variant-desc-detail-pane {
        padding: 0.75rem;
        overflow-y: auto;
    }

    .item-management-page .sp-filters-grid {
        grid-template-columns: 1fr;
    }

    .item-management-page .catalog-checkboxes-grid {
        grid-template-columns: 1fr;
    }

    /* Zones de tap assez grandes pour le doigt. */
    .item-management-page .resource-item,
    .item-management-page .sp-item,
    .item-management-page .variant-desc-item,
    .item-management-page .maintenance-card {
        min-height: 44px;
        padding-top: 0.65rem;
        padding-bottom: 0.65rem;
    }

    .item-management-page .btn-icon-only {
        min-width: 44px;
        min-height: 44px;
    }

    .item-management-page .resource-item:hover,
    .item-management-page .sp-item:hover,
    .item-management-page .variant-desc-item:hover,
    .item-management-page .maintenance-card:hover {
        transform: none;
    }

    /* Onglets de génération : défilement horizontal. */
    .item-management-page .catalog-generation-tabs-list {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .item-management-page .catalog-generation-tabs-list .nav-item {
        flex: 0 0 auto;
        min-width: 4.75rem;
    }

    .item-management-page .catalog-generation-tabs-list .nav-link {
        min-height: 52px;
    }

    /* Produits finis — barre d'info + onglets. */
    .item-management-page .matrix-info-bar {
        padding: 0.65rem 0.75rem;
    }

    .item-management-page .matrix-info-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 0.55rem 0.75rem;
    }

    .item-management-page .matrix-info-item {
        min-width: 0;
    }

    .item-management-page .matrix-info-value {
        word-break: break-word;
    }

    .item-management-page .finished-product-page-header .matrix-tabs {
        overflow: hidden;
    }

    .item-management-page .finished-product-page-header .matrix-tabs-list {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0 0.75rem;
        gap: 0;
    }

    .item-management-page .finished-product-page-header .matrix-tabs-list .nav-link {
        white-space: nowrap;
        min-height: 44px;
        flex-shrink: 0;
        padding: 0.55rem 0.7rem;
    }

    .item-management-page .finished-product-header-options .dropdown-menu {
        min-width: min(280px, calc(100vw - 1.5rem));
    }

    /* Grille produits finis : recherche pleine largeur + défilement horizontal. */
    .item-management-page .matrix-view-controls {
        margin: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }

    .item-management-page .matrix-view-controls .col-3 {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }

    .item-management-page .matrix-view-controls .d-flex {
        flex-wrap: wrap;
    }

    .item-management-page .matrix-grid-section {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0 0.5rem 0.75rem;
    }

    .item-management-page .matrix-form-grid .field-span-2,
    .item-management-page .matrix-form-grid .Matrix_FormField.field-span-2,
    .item-management-page .matrix-info-grid-compact .Matrix_FormField.field-span-2 {
        grid-column: span 1;
    }

    .item-management-page .checkbox-actions-row {
        flex-wrap: wrap;
    }

    /* Descriptions variantes : barre article empilée. */
    .item-management-page .variant-desc-search-bar {
        padding: 0.6rem 0.75rem;
    }

    .item-management-page .variant-desc-search-bar .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .item-management-page .variant-desc-field-with-actions {
        flex-direction: column;
        grid-column: span 1;
    }

    .item-management-page .variant-desc-field-actions {
        flex-direction: row;
        padding-top: 0;
    }

    /* Maintenance : liste des sections, puis contenu plein écran. */
    .item-management-page .catalog-maintenance-layout {
        flex-direction: column;
        padding: 0.75rem;
        gap: 0.75rem;
        height: 100%;
    }

    .item-management-page .catalog-maintenance-nav {
        width: 100%;
        min-width: 0;
        flex-direction: column;
        overflow-x: hidden;
        overflow-y: auto;
        gap: 0.5rem;
    }

    .item-management-page .maintenance-card {
        min-width: 0;
        flex-shrink: 1;
    }

    .item-management-page .catalog-maintenance-layout.has-section .catalog-maintenance-nav {
        display: none;
    }

    .item-management-page .catalog-maintenance-layout:not(.has-section) .catalog-maintenance-content {
        display: none;
    }

    .item-management-page .catalog-maintenance-mobile-back {
        display: block;
        margin-bottom: 0.75rem;
    }

    .item-management-page .catalog-maintenance-content {
        padding: 0.85rem;
    }

    .item-management-page .maintenance-section-header {
        flex-direction: column;
        align-items: stretch;
    }

    /* Tableaux : défilement horizontal plutôt que débordement. */
    .item-management-page .sp-table,
    .item-management-page .maintenance-table,
    .item-management-page .catalog-us-control-table,
    .item-management-page .product-item-upholstery-grid {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .item-management-page .stock-layout {
        flex-direction: column;
    }

    .item-management-page .stock-action-panel {
        min-width: 0;
        max-width: none;
        width: 100%;
    }

    .item-management-page .stock-grid-table {
        width: 100%;
        overflow-x: auto;
    }
}

@media (min-width: 1024px) {
    .item-management-page .catalog-maintenance-mobile-back,
    .item-management-page .im-mobile-pane-switch {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .item-management-page .matrix-info-grid {
        grid-template-columns: 1fr;
    }

    .item-management-page .im-mobile-pane-switch__btn span {
        font-size: 0.75rem;
    }
}
