/*
 * MaGestion sur telephone et sur tablette (moins de 1024 px de large) : la meme logique que la barre de navigation du bas.
 * Avant, les tablettes (768 a 1023 px) avaient le menu du telephone mais les tableaux de l'ordinateur, coupes a droite.
 *
 *  - Les listes (tableaux de donnees) deviennent des cartes : une carte par ligne,
 *    avec le libelle de chaque information a gauche et sa valeur a droite.
 *    Les libelles sont poses par theme.js (attribut data-mg-label).
 *  - Les boutons et les champs prennent la taille du doigt.
 *  - Les formulaires passent sur une colonne.
 */

@media (max-width: 1023px) {

    /* ---------- Page ---------- */
    section.content { padding-left: 12px !important; padding-right: 12px !important; }
    section.content-header { padding-left: 12px !important; padding-right: 12px !important; }
    section.content-header h1 { font-size: 22px !important; line-height: 1.2 !important; }
    .box, .box-primary, .box-solid, .mg-card, .mgd-card { border-radius: 14px !important; }

    /* ---------- Listes : barre d'outils ---------- */
    .dataTables_wrapper > .row.margin-bottom-20 { display: flex !important; flex-direction: column; align-items: stretch !important; gap: 8px !important; margin-bottom: 10px !important; }
    .dataTables_wrapper > .row.margin-bottom-20 > div { width: 100% !important; }
    .dataTables_wrapper .dataTables_length { display: none !important; }
    .dataTables_wrapper .dataTables_filter { order: -1; }
    .dataTables_wrapper .dataTables_filter label { display: block !important; width: 100%; }
    .dataTables_wrapper .dataTables_filter input { width: 100% !important; min-width: 0 !important; margin: 0 !important; height: 46px !important; font-size: 16px !important; }
    /* Exports et colonnes : replies derriere un seul bouton (ajoute par theme.js). */
    .dataTables_wrapper .dt-buttons { display: none !important; }
    .dataTables_wrapper.mg-tools-open .dt-buttons { display: flex !important; flex-direction: column; align-items: stretch; gap: 6px; }
    .dataTables_wrapper.mg-tools-open .dt-buttons .btn { margin: 0 !important; width: 100%; justify-content: center; text-align: center; }
    .mg-tools-toggle { display: inline-flex !important; }

    /* ---------- Listes : une carte par ligne ---------- */
    .dataTables_scrollHead { display: none !important; }
    .dataTables_scrollBody { overflow: visible !important; max-height: none !important; height: auto !important; border: 0 !important; }
    .dataTables_scroll { border: 0 !important; }
    .dataTables_wrapper table.dataTable,
    .dataTables_scrollFoot table { display: block !important; width: 100% !important; min-width: 0 !important; margin: 0 !important; }
    .dataTables_wrapper table.dataTable > thead,
    .dataTables_scrollBody table.dataTable > tfoot { display: none !important; }
    .dataTables_wrapper table.dataTable > tbody,
    .dataTables_scrollFoot table > tfoot { display: block !important; }

    .dataTables_wrapper table.dataTable > tbody > tr,
    .dataTables_scrollFoot table > tfoot > tr {
        display: flex !important;
        flex-direction: column;
        background: #fff !important;
        border: 1px solid var(--mg-line);
        border-radius: 14px;
        padding: 10px 14px;
        margin: 0 0 10px;
        height: auto !important;
    }
    .dataTables_wrapper table.dataTable > tbody > tr > td,
    .dataTables_scrollFoot table > tfoot > tr > td {
        display: flex !important;
        align-items: baseline;
        justify-content: space-between;
        gap: 14px;
        width: auto !important;
        min-width: 0 !important;
        max-width: none !important;
        border: 0 !important;
        padding: 4px 0 !important;
        background: transparent !important;
        text-align: right;
        white-space: normal !important;
        overflow-wrap: anywhere;
        font-size: 14.5px;
    }
    .dataTables_wrapper table.dataTable > tbody > tr > td::before,
    .dataTables_scrollFoot table > tfoot > tr > td::before {
        content: attr(data-mg-label);
        flex: 0 0 auto;
        max-width: 46%;
        text-align: left;
        color: var(--mg-muted);
        font-size: 13px;
        font-weight: 400;
    }
    .dataTables_wrapper table.dataTable > tbody > tr > td:not([data-mg-label])::before,
    .dataTables_wrapper table.dataTable > tbody > tr > td[data-mg-label=""]::before { content: none; }
    /* Une case vide n'apporte rien dans une carte. */
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-empty,
    .dataTables_scrollFoot table > tfoot > tr > td.mg-cell-empty { display: none !important; }
    .dataTables_wrapper table.dataTable > tbody > tr:hover > td { background: transparent !important; }

    /* Le titre de la carte : numero de facture, nom du client, nom du produit... */
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-title {
        order: -2;
        justify-content: flex-start;
        text-align: left;
        font-size: 16px;
        font-weight: 600;
        padding-bottom: 8px !important;
        margin-bottom: 4px;
        border-bottom: 1px solid var(--mg-line) !important;
    }
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-title::before { content: none; }
    /* Le montant de la ligne ressort. */
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-total { font-size: 16px; font-weight: 700; color: var(--mg-ink); }
    /* Les actions : en bas de la carte, sur toute la largeur. */
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-action { order: 99; padding-top: 10px !important; justify-content: stretch; }
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-action::before { content: none; }
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-action .btn-group { display: block; width: 100%; }
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-action .btn-group > .dropdown-toggle,
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-action .btn-group > button { width: 100% !important; min-height: 42px !important; height: 42px !important; justify-content: center; }
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-action .dropdown-menu { left: 0 !important; right: 0 !important; width: 100%; }
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-action .dropdown-menu > li > a { padding: 12px 12px !important; font-size: 15px; }
    /* Case a cocher de selection : discrete, en haut a droite. */
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-check { order: -3; justify-content: flex-end; padding: 0 !important; }
    .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-check::before { content: none; }
    /* Ligne "aucune donnee" */
    .dataTables_wrapper table.dataTable > tbody > tr > td.dataTables_empty { justify-content: center; text-align: center; color: var(--mg-muted); }
    .dataTables_wrapper table.dataTable > tbody > tr > td.dataTables_empty::before { content: none; }

    /* Totaux de la liste : une carte a part, sur fond vert pale. */
    .dataTables_scrollFoot { overflow: visible !important; display: block !important; }
    .dataTables_scrollFootInner { width: 100% !important; padding: 0 !important; }
    .dataTables_scrollFoot table > tfoot > tr { background: var(--mg-green-soft) !important; border-color: transparent; font-weight: 600; }

    .dataTables_info { text-align: center !important; float: none !important; padding: 4px 0 !important; }
    .dataTables_paginate { padding-top: 6px !important; }
    .pagination > li > a, .pagination > li > span { min-width: 42px; min-height: 42px; display: inline-flex !important; align-items: center; justify-content: center; }

    /* ---------- Boutons et champs a la taille du doigt ---------- */
    .btn, .tw-dw-btn, .mg-btn { min-height: 44px; }
    .tw-dw-btn.tw-dw-btn-xs, .btn-xs, .btn-sm, .tw-dw-btn-sm { min-height: 40px !important; height: auto !important; padding: 8px 14px !important; font-size: 14px !important; }
    .mg-btn-sm { min-height: 40px; }
    .form-control, select.form-control,
    .select2-container--default .select2-selection--single,
    .select2-container--default .select2-selection--multiple { min-height: 46px !important; font-size: 16px !important; }
    .select2-container--default .select2-selection--single .select2-selection__rendered { line-height: 44px !important; }
    .select2-container--default .select2-selection--single .select2-selection__arrow { height: 44px !important; }
    textarea.form-control { font-size: 16px !important; }
    .input-group-addon { min-width: 44px; }
    .mgd-period select { min-height: 44px; font-size: 16px; }
    .nav-tabs-custom > .nav-tabs > li > a, .mg-sf-tabs button, .mg-chip, .mgd-tabs button { min-height: 42px; display: inline-flex !important; align-items: center; }
    .mgd-card > header a:not(.mg-btn) { padding: 8px 0 8px 8px; }

    /* ---------- Formulaires : une colonne ---------- */
    section.content form [class*="col-md-"],
    section.content form [class*="col-sm-"],
    section.content form [class*="col-lg-"] { width: 100% !important; float: none !important; }
    .modal-dialog { margin: 8px !important; width: auto !important; }
    .modal-body [class*="col-md-"], .modal-body [class*="col-sm-"] { width: 100% !important; float: none !important; }

    /* ---------- Fiches MaGestion ---------- */
    .mg-fiche-head { align-items: stretch !important; }
    .mg-fiche-actions { width: 100%; }
    .mg-fiche-actions .mg-btn { flex: 1 1 auto; }
    .mg-fiche-title { font-size: 21px !important; }
    .mgd-hello h1 { font-size: 18px; }
    .mgd-head { align-items: stretch; }
    .mgd-period, .mgd-period select { width: 100%; }

    /* ---------- Editeur de texte : sa barre d'outils reste dans l'ecran ---------- */
    .tox.tox-tinymce { max-width: 100% !important; }
    .tox .tox-toolbar, .tox .tox-toolbar__primary, .tox .tox-menubar { flex-wrap: wrap !important; }
    .tox .tox-toolbar-overlord, .tox .tox-editor-header { max-width: 100% !important; overflow: hidden; }
}

/* Bouton "Exporter et colonnes" : visible sur telephone seulement. */
.mg-tools-toggle {
    display: none;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    width: 100%;
    border: 1px solid var(--mg-line);
    border-radius: 10px;
    background: #fff;
    color: var(--mg-ink);
    font: inherit;
    font-size: 14.5px;
    font-weight: 500;
    cursor: pointer;
}
.mg-tools-toggle[aria-expanded="true"] { background: var(--mg-orange-soft); border-color: var(--mg-orange); color: var(--mg-orange-dark); }
.mg-tools-toggle:focus-visible { outline: 2px solid var(--mg-orange); outline-offset: 2px; }

@media (max-width: 1023px) {
    .dataTables_scrollFoot table > tfoot > tr::before { content: "Totaux"; font-size: 13px; font-weight: 500; color: var(--mg-green-dark); padding-bottom: 4px; }
    .dataTables_scrollFoot table > tfoot > tr > td { justify-content: flex-start; text-align: left; font-weight: 600; }
    .dataTables_scrollFoot table > tfoot > tr > td::before { content: none !important; }
}

@media (max-width: 1023px) {
    /* Barre d'outils des listes, quelle que soit sa structure d'origine. */
    .dataTables_wrapper > div:not(.dataTables_scroll) > [class*="col-"] { width: 100% !important; float: none !important; padding-left: 0 !important; padding-right: 0 !important; }
    .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_filter label { width: 100% !important; float: none !important; text-align: left !important; }
    .dataTables_wrapper .mg-tools-toggle { margin-bottom: 8px; }
    /* Actions groupees sous une liste (supprimer la selection, etc.) : elles passent a la ligne. */
    .dataTables_scrollFoot table > tfoot > tr > td { flex-wrap: wrap; }
    .dataTables_scrollFoot table > tfoot form, .dataTables_scrollFoot table > tfoot td > div { display: flex; flex-wrap: wrap; gap: 6px; width: 100%; }
    .dataTables_scrollFoot table > tfoot .tw-dw-btn, .dataTables_scrollFoot table > tfoot .btn, .dataTables_scrollFoot table > tfoot input[type=submit] { flex: 1 1 100%; width: 100% !important; white-space: normal; }
    /* Boutons de tete de bloc (Ajouter, Telecharger) : sur toute la largeur, l'un sous l'autre. */
    .box-tools { float: none !important; position: static !important; display: flex; flex-direction: column; gap: 8px; width: 100%; margin: 8px 0; }
    .box-tools > a, .box-tools > button { width: 100%; float: none !important; margin: 0 !important; justify-content: center; }
}

@media (max-width: 1023px) {
    .dataTables_wrapper > div:not(.dataTables_scroll) [class*="col-sm-"],
    .dataTables_wrapper > div:not(.dataTables_scroll) [class*="col-md-"] { width: 100% !important; float: none !important; padding-left: 0 !important; padding-right: 0 !important; }
    .dataTables_wrapper > div:not(.dataTables_scroll) { display: flex; flex-direction: column; gap: 8px; }
    .dataTables_wrapper > .dataTables_info, .dataTables_wrapper > .dataTables_paginate { display: block; }
}

/* ================= Accueil sur telephone : le chiffre d'abord ================= */
.mgm { display: none; }
@media (max-width: 1023px) {
    .mgm { display: block; margin-bottom: 6px; }
    /* Sur telephone, les raccourcis de periode remplacent la liste deroulante. */
    .mgd-head .mgd-period { display: none; }
    .mgd-head { margin-bottom: 10px; }

    .mgm-chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
    .mgm-chips::-webkit-scrollbar { display: none; }
    .mgm-chips a { flex: 0 0 auto; min-height: 40px; display: inline-flex; align-items: center; padding: 0 16px; border-radius: 999px; background: #fff; border: 1px solid var(--mg-line); color: #3F4354 !important; font-size: 14px; font-weight: 500; text-decoration: none !important; }
    .mgm-chips a.on { background: var(--mg-ink); border-color: var(--mg-ink); color: #fff !important; }

    .mgm-hero { background: #fff; border: 1px solid var(--mg-line); border-radius: 18px; padding: 18px 18px 20px; display: flex; flex-direction: column; gap: 4px; }
    .mgm-cap { font-size: 12px; letter-spacing: .04em; text-transform: uppercase; color: var(--mg-muted); }
    .mgm-hero b { font-size: 38px; line-height: 1.1; font-weight: 600; letter-spacing: -0.02em; color: var(--mg-ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
    .mgm-sub { font-size: 14px; color: var(--mg-green-dark); font-weight: 500; }

    .mgm-tiles { display: flex; gap: 10px; overflow-x: auto; padding: 10px 0 4px; scroll-snap-type: x proximity; scrollbar-width: none; }
    .mgm-tiles::-webkit-scrollbar { display: none; }
    .mgm-tiles a { flex: 0 0 46%; min-width: 150px; scroll-snap-align: start; background: #fff; border: 1px solid var(--mg-line); border-radius: 16px; padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; text-decoration: none !important; color: var(--mg-ink) !important; }
    .mgm-tiles span { font-size: 12px; letter-spacing: .03em; text-transform: uppercase; color: var(--mg-muted); }
    .mgm-tiles b { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
    .mgm-tiles small { font-size: 12px; color: var(--mg-muted); }

    .mgm-actions { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin: 10px 0 4px; }
    .mgm-actions a { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 10px 4px; border-radius: 14px; background: #fff; border: 1px solid var(--mg-line); color: var(--mg-ink) !important; font-size: 12px; font-weight: 500; text-align: center; text-decoration: none !important; line-height: 1.2; }
    .mgm-actions a span { width: 42px; height: 42px; border-radius: 50%; background: var(--mg-orange-soft); color: var(--mg-orange-dark); display: flex; align-items: center; justify-content: center; }
    .mgm-actions a:first-child span { background: var(--mg-orange); color: #fff; }
    .mgm-actions svg { width: 22px; height: 22px; }
    .mgm-actions a:active { background: var(--mg-orange-soft); }
    .mgm-title { margin: 16px 2px 8px; font-size: 16px; font-weight: 600; color: var(--mg-ink); }

    /* L'en-tete d'accueil se resserre : le chiffre doit apparaitre sans faire defiler. */
    .mgd-hello-ico { width: 38px; height: 38px; font-size: 16px; }
    .mgd-hello h1 { font-size: 17px; }
}

/* ================= Liste des ventes sur telephone (sells-mobile.js) ================= */
.mgl, .mgc-btns, td.mg-mcard { display: none; }
@media (max-width: 1023px) {
    .mgl { display: block; margin-bottom: 10px; }
    .mgl-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; margin-bottom: 10px; }
    .mgl-count { font-size: 14px; color: var(--mg-muted); }
    .mgl-new { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; padding: 0 16px; border-radius: 12px; background: var(--mg-orange); color: #fff !important; font-size: 15px; font-weight: 600; text-decoration: none !important; }
    .mgl-new svg { width: 18px; height: 18px; }
    .mgl-new:active { background: var(--mg-orange-dark); }
    /* Le bouton "Nouvelle" de l'en-tete remplace le grand bouton et le titre en double. */
    html.mg-sells-new section.content .box-header { display: none !important; }
    section.content-header h1 small { display: block; margin-top: 2px; font-size: 13px !important; }

    .mgl-due { width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left; padding: 14px 16px; margin-bottom: 10px; border: 1px solid #F9D9B8; border-radius: 16px; background: var(--mg-orange-soft); font: inherit; color: var(--mg-ink); cursor: pointer; -webkit-tap-highlight-color: transparent; }
    .mgl-due[hidden] { display: none; }
    .mgl-due-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
    .mgl-due small { font-size: 11.5px; letter-spacing: .05em; text-transform: uppercase; color: #A2531A; font-weight: 600; }
    .mgl-due b { font-size: 24px; line-height: 1.15; font-weight: 600; font-variant-numeric: tabular-nums; }
    .mgl-due-txt > span { font-size: 13px; color: #A2531A; }
    .mgl-due-go { flex: 0 0 auto; min-height: 38px; display: inline-flex; align-items: center; padding: 0 14px; border-radius: 999px; background: #fff; border: 1px solid #F9D9B8; font-size: 14px; font-weight: 600; color: var(--mg-orange-dark); }
    .mgl-due[aria-pressed="true"] { border-color: var(--mg-orange); }
    .mgl-due[aria-pressed="true"] .mgl-due-go { background: var(--mg-orange); border-color: var(--mg-orange); color: #fff; }
    .mgl-due:focus-visible, .mgl-chip:focus-visible, .mgl-new:focus-visible, .mgc-btn:focus-visible, .mgc-round:focus-visible { outline: 2px solid var(--mg-orange); outline-offset: 2px; }

    .mgl-chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0; scrollbar-width: none; }
    .mgl-chips::-webkit-scrollbar { display: none; }
    .mgl-chip { flex: 0 0 auto; min-height: 40px; padding: 0 16px; border-radius: 999px; background: #fff; border: 1px solid var(--mg-line); color: #3F4354; font: inherit; font-size: 14px; font-weight: 500; cursor: pointer; }
    .mgl-chip[aria-pressed="true"] { background: var(--mg-ink); border-color: var(--mg-ink); color: #fff; }

    /* La carte remplace les lignes "libelle : valeur". */
    .dataTables_wrapper table.dataTable > tbody > tr.mg-has-card { padding: 14px; gap: 0; }
    .dataTables_wrapper table.dataTable > tbody > tr.mg-has-card > td:not(.mg-mcard):not(.mg-cell-action) { display: none !important; }
    .dataTables_wrapper table.dataTable > tbody > tr.mg-has-card > td.mg-mcard { display: block !important; order: -5; padding: 0 !important; text-align: left; }
    .dataTables_wrapper table.dataTable > tbody > tr.mg-has-card > td.mg-mcard::before { content: none; }

    .mgc-top { display: flex; align-items: flex-start; gap: 10px; }
    .mgc-av { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px; background: #F1F3F6; color: #3F4354; font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: center; }
    .mgc-who { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }
    .mgc-who b { font-size: 16px; font-weight: 600; color: var(--mg-ink); overflow-wrap: anywhere; }
    .mgc-who small { font-size: 12.5px; color: var(--mg-muted); }
    .mgc-amt { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; text-align: right; }
    .mgc-amt b { font-size: 16px; font-weight: 600; color: var(--mg-ink); font-variant-numeric: tabular-nums; white-space: nowrap; }
    .mgc-amt small { font-size: 12.5px; color: var(--mg-orange-dark); white-space: nowrap; }

    .mgc-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin-top: 10px; font-size: 13px; color: var(--mg-muted); }
    .mgc-pill { display: inline-flex; align-items: center; gap: 6px; font-weight: 500; }
    .mgc-pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
    .mgc-ok { color: var(--mg-green-dark); }
    .mgc-mid { color: var(--mg-orange-dark); }
    .mgc-ko { color: #D64545; }

    .mgc-tel { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
    .mgc-telnum { display: inline-flex; align-items: center; gap: 6px; min-height: 36px; padding: 0 12px 0 10px; border-radius: 999px; background: #F7F8FA; color: #3F4354 !important; font-size: 13.5px; text-decoration: none !important; }
    .mgc-telnum svg, .mgc-round svg { width: 16px; height: 16px; }
    .mgc-round { width: 36px; height: 36px; border-radius: 50%; background: var(--mg-green-soft); color: var(--mg-green-dark) !important; display: inline-flex; align-items: center; justify-content: center; }

    /* Actions : Encaisser, Details, puis le menu d'origine, sur une ligne. */
    .dataTables_wrapper table.dataTable > tbody > tr.mg-has-card > td.mg-cell-action { display: flex !important; flex-direction: row; align-items: stretch; gap: 8px; position: relative; margin-top: 12px; padding: 12px 0 0 !important; border-top: 1px solid var(--mg-line) !important; }
    .mgc-btns { display: flex; gap: 8px; flex: 0 0 auto; }
    .mgc-btn { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 0 14px; border-radius: 10px; border: 1px solid #E1E4EA; background: #fff; color: var(--mg-ink) !important; font-size: 14.5px; font-weight: 500; text-decoration: none !important; white-space: nowrap; }
    .mgc-btn-main { background: var(--mg-ink); border-color: var(--mg-ink); color: #fff !important; }
    .dataTables_wrapper table.dataTable > tbody > tr.mg-has-card > td.mg-cell-action .btn-group { flex: 1 1 0; min-width: 0; width: auto; position: static; display: block; }
}
/* ================= Liste des produits sur telephone (products-mobile.js) ================= */
@media (max-width: 1023px) {
    /* Barre d'outils des listes : toute la largeur, quelle que soit la page. */
    .dataTables_wrapper > .row { width: auto !important; margin-left: 0 !important; margin-right: 0 !important; }
    .dataTables_wrapper > .row > [class*="col-"] { width: 100% !important; }

    .mgp-top.mgl-top { display: flex; margin-bottom: 10px; }
    html.mg-products-mobile #product_list_tab > br { display: none; }
    html.mg-products-mobile #product_list_tab > a.tw-dw-btn { float: none !important; display: flex !important; width: 100%; margin: 0 0 10px !important; justify-content: center; }
    html.mg-products-mobile #product_list_tab > a.mgp-hide-mobile { display: none !important; }

    /* Deux cartes par ligne. */
    .dataTables_wrapper table.dataTable.mgp-grid > tbody { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr { margin: 0; padding: 10px; position: relative; min-width: 0; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr:not(.mg-has-card) { grid-column: 1 / -1; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr.mg-has-card > td.mgp-card { display: flex !important; flex-direction: column; align-items: stretch; gap: 2px; flex: 1 1 auto; }
    /* La case de selection reste disponible, dans le coin de la photo. */
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr.mg-has-card > td.mg-cell-check { display: flex !important; position: absolute; top: 16px; right: 16px; z-index: 2; padding: 0 !important; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr.mg-has-card > td.mg-cell-check input { width: 22px; height: 22px; margin: 0; }

    .mgp-pic { position: relative; aspect-ratio: 4 / 3; border-radius: 10px; background: #F4F5F7; color: #B6BBC6; display: flex; align-items: center; justify-content: center; overflow: hidden; margin-bottom: 8px; }
    .mgp-pic img { width: 100%; height: 100%; object-fit: cover; }
    .mgp-pic svg { width: 34px; height: 34px; }
    .mgp-flag { position: absolute; left: 6px; bottom: 6px; padding: 2px 8px; border-radius: 999px; background: rgba(27, 29, 40, .78); color: #fff; font-size: 11.5px; font-weight: 500; }
    .mgp-name { font-size: 15px; font-weight: 600; color: var(--mg-ink); line-height: 1.25; overflow-wrap: anywhere; text-align: left; }
    .mgp-cat { font-size: 12.5px; color: var(--mg-muted); text-align: left; }
    .mgp-price { margin-top: 6px; font-size: 15px; font-weight: 600; color: var(--mg-ink); font-variant-numeric: tabular-nums; text-align: left; }
    .mgp-stock { font-size: 12.5px; color: var(--mg-green-dark); text-align: left; }
    .mgp-stock.mgp-low { color: #D64545; font-weight: 500; }
    .mgp-stock.mgp-nostock { color: var(--mg-muted); }

    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr.mg-has-card > td.mg-cell-action { gap: 6px; margin-top: 10px; padding-top: 10px !important; position: static; }
    .mgp-grid .mgc-btns { gap: 6px; }
    .mgc-btn.mgc-ico { width: 42px; padding: 0; }
    .mgc-btn.mgc-ico svg { width: 18px; height: 18px; }
    /* Le menu Actions prend la largeur de la carte, et s'elargit vers l'interieur de l'ecran. */
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action .btn-group > .dropdown-toggle { padding: 0 6px !important; font-size: 13.5px !important; min-width: 0; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action .dropdown-menu { width: 250px; max-width: calc(100vw - 48px); top: 100% !important; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr:nth-child(odd) > td.mg-cell-action .dropdown-menu { left: 0 !important; right: auto !important; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr:nth-child(even) > td.mg-cell-action .dropdown-menu { left: auto !important; right: 0 !important; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action .dropdown-menu > li > a { white-space: normal !important; }
}@media (max-width: 1023px) {
    /* Dans une demi-carte, "Actions" ne tient pas : le bouton dit "Plus". */
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action .btn-group > .dropdown-toggle { font-size: 0 !important; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action .btn-group > .dropdown-toggle::after { content: "Plus"; font-size: 14px; font-weight: 500; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action .btn-group > .dropdown-toggle .caret { display: none; }
    /* Le telechargement Excel reste disponible, sans concurrencer "Nouveau". */
    html.mg-products-mobile #product_list_tab > a.tw-dw-btn:not(.mgp-hide-mobile) { background: #fff !important; background-image: none !important; color: var(--mg-ink) !important; border: 1px solid var(--mg-line) !important; font-weight: 500 !important; }
}@media (max-width: 1023px) {
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action .btn-group > .dropdown-toggle { display: flex !important; align-items: center; justify-content: center; width: 100% !important; overflow: hidden; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action .btn-group > .dropdown-toggle::after { line-height: 1; white-space: nowrap; border: 0 !important; margin: 0 !important; width: auto !important; height: auto !important; position: static !important; transform: none !important; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action .btn-group > .dropdown-toggle .sr-only { display: none; }
}
/* ================= Formulaires de vente et d'achat sur telephone : une carte par ligne ================= */
@media (max-width: 1023px) {
    html:not(.mg-pos) #pos_table,
    #purchase_entry_table { display: block !important; width: 100% !important; min-width: 0 !important; border: 0 !important; }
    html:not(.mg-pos) #pos_table > thead,
    #purchase_entry_table > thead { display: none !important; }
    html:not(.mg-pos) #pos_table > tbody,
    #purchase_entry_table > tbody { display: block !important; }
    html:not(.mg-pos) .pos_product_div .table-responsive,
    html:not(.mg-pos) #pos_table,
    #purchase_entry_table { overflow: visible !important; }
    .table-responsive:has(> #pos_table), .table-responsive:has(> #purchase_entry_table) { overflow-x: hidden !important; border: 0 !important; }

    html:not(.mg-pos) #pos_table > tbody > tr.product_row,
    #purchase_entry_table > tbody > tr {
        display: grid !important; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 10px 12px;
        position: relative; padding: 14px 4px; border-bottom: 1px solid var(--mg-line); background: none !important;
    }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td,
    #purchase_entry_table > tbody > tr > td {
        display: block !important; width: auto !important; min-width: 0 !important; padding: 0 !important; border: 0 !important;
        text-align: left !important; background: none !important;
    }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td.hide,
    #purchase_entry_table > tbody > tr > td.hide,
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td:first-child,
    #purchase_entry_table > tbody > tr > td:first-child { display: none !important; }
    /* Le nom du produit sur toute la largeur, la corbeille dans le coin. */
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td:nth-child(2),
    #purchase_entry_table > tbody > tr > td:nth-child(2) { grid-column: 1 / -1; padding-right: 46px !important; font-weight: 600; overflow-wrap: anywhere; }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td:last-child,
    #purchase_entry_table > tbody > tr > td:last-child { position: absolute; top: 10px; right: 0; }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td:last-child > *,
    #purchase_entry_table > tbody > tr > td:last-child > * { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; font-size: 18px; }

    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td::before,
    #purchase_entry_table > tbody > tr > td::before { display: block; margin-bottom: 4px; font-size: 12.5px; font-weight: 400; color: var(--mg-muted); }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td:nth-child(3)::before { content: "Quantité"; }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td:nth-child(4)::before { content: "Prix unitaire"; }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td:nth-child(5)::before { content: "Remise"; }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td:nth-child(8)::before { content: "Total"; }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td:nth-child(8) { font-size: 16px; font-weight: 600; align-self: center; }

    #purchase_entry_table > tbody > tr > td:nth-child(3)::before { content: "Quantité"; }
    #purchase_entry_table > tbody > tr > td:nth-child(4)::before { content: "Coût unitaire"; }
    #purchase_entry_table > tbody > tr > td:nth-child(5)::before { content: "Remise (%)"; }
    #purchase_entry_table > tbody > tr > td:nth-child(6)::before { content: "Coût après remise"; }
    #purchase_entry_table > tbody > tr > td:nth-child(10)::before { content: "Total de la ligne"; }
    #purchase_entry_table > tbody > tr > td:nth-child(11)::before { content: "Marge (%)"; }
    #purchase_entry_table > tbody > tr > td:nth-child(12)::before { content: "Prix de vente"; }
    #purchase_entry_table > tbody > tr > td:nth-child(10) { font-size: 16px; font-weight: 600; }

    html:not(.mg-pos) #pos_table > tbody > tr.product_row .form-control,
    html:not(.mg-pos) #pos_table > tbody > tr.product_row .input-group,
    #purchase_entry_table > tbody > tr .form-control,
    #purchase_entry_table > tbody > tr .input-group { width: 100% !important; min-width: 0 !important; max-width: none !important; }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row select.form-control,
    #purchase_entry_table > tbody > tr select.form-control { margin-top: 6px; }
}@media (max-width: 1023px) {
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td small,
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td p,
    html:not(.mg-pos) #pos_table > tbody > tr.product_row > td span,
    #purchase_entry_table > tbody > tr > td small { white-space: normal !important; overflow-wrap: anywhere; }
    html:not(.mg-pos) #pos_table > tbody > tr.product_row textarea { width: 100% !important; }
    /* Totaux sous les lignes d'achat : un montant ne se coupe pas. */
    #purchase_entry_table ~ * table td, .pos_product_div table.table-condensed td { white-space: nowrap; }
    #total_subtotal, #total_quantity, .display_currency { white-space: nowrap; }
}
/* Tableaux MaGestion en fiches sur telephone (chaque cellule porte son libelle dans data-l). */
@media (max-width: 1023px) {
    .mg-table-plain .mg-table.mg-cards-sm { min-width: 0; }
    .mg-table.mg-cards-sm, .mg-table.mg-cards-sm tbody, .mg-table.mg-cards-sm tr, .mg-table.mg-cards-sm td { display: block; width: 100%; }
    .mg-table.mg-cards-sm thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .mg-table.mg-cards-sm tr { padding: 12px 14px; border-bottom: 1px solid var(--mg-line); }
    .mg-table.mg-cards-sm tr:last-child { border-bottom: 0; }
    .mg-table.mg-cards-sm td { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 4px 0; border: 0; text-align: right; }
    .mg-table.mg-cards-sm td[data-l]::before { content: attr(data-l); flex: 0 0 auto; color: var(--mg-muted); font-weight: 400; font-size: 13.5px; text-align: left; }
    .mg-table.mg-cards-sm td.mg-empty { justify-content: center; text-align: center; }
    /* Etiquettes et import : les tableaux du logiciel d'origine defilent dans leur cadre. */
    body.mg-page-labels table.table, body.mg-page-import-sales table.table { display: block; max-width: 100%; overflow-x: auto; }
}

/* ================= Telephone : boutons en icones seules =================
   Sur un petit ecran, "icone + texte" en pleine largeur mange la place du contenu.
   Les boutons qui ont une icone ne gardent qu'elle ; leur texte reste lu par les lecteurs d'ecran. */
@media (max-width: 1023px) {
    /* Titre du bloc et bouton(s) d'ajout sur une seule ligne. */
    section.content .box-header { display: flex !important; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: nowrap; }
    section.content .box-header > .box-title { margin: 0 !important; flex: 1 1 auto; min-width: 0; float: none !important; }
    section.content .box-header > .box-tools { position: static !important; float: none !important; display: flex; gap: 8px; flex: 0 0 auto; width: auto !important; margin: 0 !important; padding: 0 !important; }
    section.content .box-header > .box-tools > .tw-dw-btn:has(svg),
    section.content .box-header > .box-tools > .tw-dw-btn:has(i),
    section.content .box-header > .box-tools > a.btn:has(i) {
        width: 44px !important; min-width: 44px; height: 44px !important; min-height: 44px; padding: 0 !important; margin: 0 !important;
        font-size: 0 !important; line-height: 0; border-radius: 12px !important; display: inline-flex !important; align-items: center; justify-content: center; gap: 0; float: none !important;
    }
    section.content .box-header > .box-tools > .tw-dw-btn svg { width: 22px; height: 22px; margin: 0; }
    section.content .box-header > .box-tools > .tw-dw-btn i, section.content .box-header > .box-tools > a.btn i { font-size: 18px; margin: 0; }

    /* Recherche et "Exporter, imprimer" sur une seule ligne : le champ prend la place, le bouton n'est qu'une icone. */
    .row:has(> .mg-tools-host) { display: flex !important; flex-direction: row !important; flex-wrap: nowrap !important; align-items: center; gap: 8px; margin: 0 0 10px !important; }
    .row:has(> .mg-tools-host) > [class*="col-"] { width: auto !important; float: none !important; padding: 0 !important; margin: 0 !important; }
    .row:has(> .mg-tools-host) > [class*="col-"]:has(.dataTables_length) { display: none !important; }
    .row:has(> .mg-tools-host) > [class*="col-"]:has(.dataTables_filter) { flex: 1 1 0 !important; width: 0 !important; min-width: 0; max-width: none !important; order: 1; }
    .row:has(> .mg-tools-host) > .mg-tools-host { flex: 0 0 44px !important; width: 44px !important; max-width: 44px !important; order: 2; position: relative; overflow: visible; }
    .dataTables_wrapper .dataTables_filter, .dataTables_wrapper .dataTables_filter label { width: 100%; margin: 0 !important; display: block; }
    .dataTables_wrapper .dataTables_filter input { width: 100% !important; margin: 0 !important; }
    .mg-tools-toggle { width: 44px !important; min-width: 44px; height: 44px !important; padding: 0 !important; font-size: 0 !important; line-height: 0; display: inline-flex !important; align-items: center; justify-content: center; gap: 0 !important; border-radius: 12px !important; }
    .mg-tools-toggle svg { width: 20px; height: 20px; margin: 0 !important; }

    /* Actions d'une ligne (Modifier, Parametres, Desactiver, Effacer...) : une icone par action. */
    .mg-cards-sm td .tw-dw-btn.tw-dw-btn-xs:has(i), table.dataTable td .tw-dw-btn.tw-dw-btn-xs:has(i), table.dataTable td .tw-dw-btn.tw-dw-btn-xs:has(svg),
    table.dataTable td a.btn.btn-xs:has(i), table.dataTable td button.btn.btn-xs:has(i) {
        width: 40px !important; min-width: 40px; height: 40px !important; min-height: 40px; padding: 0 !important; margin: 2px 6px 2px 0 !important;
        font-size: 0 !important; line-height: 0; border-radius: 10px !important; display: inline-flex !important; align-items: center; justify-content: center; gap: 0;
    }
    table.dataTable td .tw-dw-btn.tw-dw-btn-xs i, table.dataTable td a.btn.btn-xs i, table.dataTable td button.btn.btn-xs i { font-size: 16px; margin: 0 !important; }
    table.dataTable td .tw-dw-btn.tw-dw-btn-xs svg { width: 18px; height: 18px; margin: 0 !important; }
    /* Le menu deroulant "Actions" garde son texte : sans lui, on ne saurait pas ce qu'il ouvre. */
    table.dataTable td .dropdown-toggle, table.dataTable td .btn-group > .tw-dw-btn { width: auto !important; font-size: 13px !important; padding: 0 12px !important; line-height: 1.2; }
}

/* Telephone : le menu d'export s'ouvre en panneau sous l'icone, a sa vraie largeur. */
@media (max-width: 1023px) {
    .dataTables_wrapper.mg-tools-open .mg-tools-host .dt-buttons {
        position: absolute; top: 50px; right: 0; z-index: 30; width: 230px; max-width: calc(100vw - 32px);
        background: #fff; border: 1px solid var(--mg-line); border-radius: 14px; padding: 8px; box-shadow: 0 14px 34px rgba(27, 29, 40, .16);
    }
    .dataTables_wrapper.mg-tools-open .mg-tools-host .dt-buttons .btn,
    .dataTables_wrapper.mg-tools-open .mg-tools-host .dt-buttons > button { justify-content: flex-start !important; text-align: left !important; min-height: 44px; font-size: 14.5px !important; white-space: nowrap; }
}

/* ================= Telephone : fenetres de detail =================
   Plein ecran, titre fixe en haut, boutons fixes en bas, contenu qui defile entre les deux.
   Les tableaux deviennent des fiches "libelle : valeur" (voir theme.js) : plus de defilement de cote. */
@media (max-width: 1023px) {
    .modal:not(.mgpay-simple) { padding: 0 !important; }
    .modal .modal-dialog:not(.modal-sm) { margin: 0 !important; width: 100% !important; max-width: none !important; height: 100%; transform: none !important; }
    .modal .modal-dialog:not(.modal-sm) > .modal-content { height: 100%; min-height: 100%; border: 0 !important; border-radius: 0 !important; box-shadow: none !important; display: flex; flex-direction: column; overflow: hidden; }
    /* Beaucoup de fenetres enveloppent tout dans un formulaire. */
    .modal .modal-dialog:not(.modal-sm) > .modal-content > form { display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; height: 100%; margin: 0; }
    .modal .modal-header { flex: 0 0 auto; position: relative; padding: 14px 54px 12px 16px !important; background: #fff; border-bottom: 1px solid var(--mg-line); }
    .modal .modal-header .modal-title { margin: 0; font-size: 17px !important; font-weight: 600; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
    .modal .modal-header .close { position: absolute; top: 8px; right: 8px; width: 42px; height: 42px; margin: 0 !important; padding: 0; font-size: 28px; line-height: 1; opacity: .65; display: flex; align-items: center; justify-content: center; float: none; }
    .modal .modal-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; padding: 14px 16px !important; }
    .modal .modal-body img { max-width: 100%; height: auto; }
    .modal .modal-footer { flex: 0 0 auto; display: flex; flex-wrap: nowrap; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)) !important; background: #fff; border-top: 1px solid var(--mg-line); text-align: left; }
    .modal .modal-footer > .btn, .modal .modal-footer > .tw-dw-btn, .modal .modal-footer > a, .modal .modal-footer > button {
        flex: 1 1 0; min-width: 0; margin: 0 !important; min-height: 46px; padding: 0 10px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; float: none !important; display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-size: 15px;
    }
    .modal .modal-footer::before, .modal .modal-footer::after { display: none; }

    /* Tableaux en fiches. */
    .modal .mg-fiches-wrap { overflow: visible !important; border: 0 !important; margin-bottom: 12px; }
    .modal table.mg-fiches { display: block; width: 100% !important; border: 0 !important; background: none !important; margin: 0 0 10px; }
    .modal table.mg-fiches > thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
    .modal table.mg-fiches > tbody, .modal table.mg-fiches > tfoot { display: block; width: 100%; }
    .modal table.mg-fiches > tbody > tr, .modal table.mg-fiches > tfoot > tr { display: block; width: 100%; margin: 0 0 8px; padding: 8px 12px; border: 1px solid var(--mg-line); border-radius: 12px; background: #fff !important; }
    .modal table.mg-fiches > tbody > tr > td, .modal table.mg-fiches > tfoot > tr > td, .modal table.mg-fiches > tfoot > tr > th {
        display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; width: 100% !important; padding: 5px 0 !important; border: 0 !important; background: none !important; text-align: right; font-size: 14.5px; line-height: 1.35; overflow-wrap: anywhere;
    }
    .modal table.mg-fiches td > .mg-v > * + * { margin-left: 4px; }
    .modal table.mg-fiches > tbody > tr > td.mg-long { display: block; text-align: left; }
    .modal table.mg-fiches > tbody > tr > td.mg-long::before { display: block; max-width: none; margin-bottom: 3px; }
    .modal table.mg-fiches > tbody > tr > td.mg-long > .mg-v { display: block; text-align: left; font-weight: 400; font-size: 13.5px; color: var(--mg-ink); }
    /* Trois boutons ou plus : le texte peut passer sur deux lignes plutot que d'etre coupe. */
    .modal .modal-footer > :nth-last-child(n+3), .modal .modal-footer > :nth-last-child(n+3) ~ * { white-space: normal !important; font-size: 13px !important; line-height: 1.15; text-align: center; padding: 4px 6px !important; height: auto !important; flex-wrap: nowrap !important; flex-direction: row !important; }
    .modal table.mg-fiches > tbody > tr > td[data-l]::before { content: attr(data-l); flex: 0 1 auto; max-width: 55%; color: var(--mg-muted); font-size: 13px; font-weight: 400; text-align: left; overflow-wrap: anywhere; }
    .modal table.mg-fiches > tbody > tr > td:first-child { font-weight: 600; color: var(--mg-ink); }
    .modal table.mg-fiches td.mg-vide, .modal table.mg-fiches tr.mg-fiche-tete { display: none !important; }
    .modal table.mg-fiches td > .mg-v { flex: 1 1 auto; min-width: 0; white-space: normal !important; text-align: right; overflow-wrap: anywhere; }
    .modal table.mg-fiches td:not([data-l]) > .mg-v { text-align: left; }
    /* Tableaux laisses tels quels : ils defilent dans leur cadre, jamais la fenetre entiere. */
    .modal .modal-body .table-responsive { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
    /* Lignes de total (cases fusionnees) : sur une ligne, sans libelle. */
    .modal table.mg-fiches tr.mg-fiche-libre { background: #FAFAFB !important; }
    .modal table.mg-fiches tr.mg-fiche-libre > td, .modal table.mg-fiches tr.mg-fiche-libre > th { display: block; text-align: left; }
    .modal table.mg-fiches > tbody > tr > td > .table, .modal table.mg-fiches td table { font-size: 13px; }
}

/* ================= Telephone : l'application ne bouge plus =================
   Le contenu depassait de quelques pixels sur le cote : toute la page glissait a gauche et a droite.
   La page est maintenant tenue en largeur, a la hauteur reelle de l'ecran, sans rebond. */
@media (max-width: 1023px) {
    html, body { overscroll-behavior: none; }
    html.mg-nav, html.mg-nav body { max-width: 100%; overflow-x: hidden !important; }
    html.mg-nav #scrollable-container { overflow-x: hidden !important; overscroll-behavior-y: contain; height: 100vh; height: 100dvh; -webkit-overflow-scrolling: touch; }
    html.mg-nav section.content, html.mg-nav section.content-header { max-width: 100%; overflow-x: clip; }
    html.mg-nav a, html.mg-nav button, html.mg-nav .btn, html.mg-nav .tw-dw-btn, html.mg-nav label, html.mg-nav summary { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
    html.mg-nav section.content img, html.mg-nav section.content canvas, html.mg-nav section.content iframe { max-width: 100%; }
}

/* ================= Telephone : le menu "Actions" monte du bas de l'ecran =================
   Grandes lignes faciles a toucher, la page derriere est assombrie ; on ferme en touchant a cote. */
@media (max-width: 1023px) {
    html.mg-theme section.content .open > ul.dropdown-menu,
    html.mg-theme section.content-header .open > ul.dropdown-menu,
    html.mg-theme .dataTables_wrapper table.dataTable > tbody > tr > td.mg-cell-action .open > ul.dropdown-menu,
    html.mg-theme .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action .open > ul.dropdown-menu {
        position: fixed !important; top: auto !important; left: 0 !important; right: 0 !important; bottom: 0 !important;
        width: 100% !important; max-width: none !important; min-width: 0 !important; max-height: 78vh; overflow-y: auto; overscroll-behavior: contain;
        margin: 0 !important; padding: 6px 12px calc(16px + env(safe-area-inset-bottom, 0px)) !important; float: none !important; transform: none !important;
        border: 0 !important; border-radius: 22px 22px 0 0 !important; background: #fff !important;
        box-shadow: 0 0 0 100vmax rgba(27, 29, 40, .45) !important; z-index: 1060 !important;
        animation: mg-sheet-in .18s ease-out;
    }
    html.mg-theme section.content .open > ul.dropdown-menu::before,
    html.mg-theme section.content-header .open > ul.dropdown-menu::before { content: ""; display: block; width: 42px; height: 4px; margin: 6px auto 10px; border-radius: 2px; background: #D8DCE3; }
    html.mg-theme section.content .open > ul.dropdown-menu > li > a,
    html.mg-theme section.content-header .open > ul.dropdown-menu > li > a {
        display: flex !important; align-items: center; gap: 14px; min-height: 52px; padding: 6px 10px !important; border-radius: 12px;
        font-size: 16px !important; font-weight: 500; line-height: 1.25; white-space: normal !important; text-align: left;
    }
    html.mg-theme section.content .open > ul.dropdown-menu > li > a > i,
    html.mg-theme section.content .open > ul.dropdown-menu > li > a > svg,
    html.mg-theme section.content-header .open > ul.dropdown-menu > li > a > i { flex: 0 0 36px; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; margin: 0 !important; border-radius: 10px; background: #F3F4F7; font-size: 16px; color: #4A4F60; top: 0; }
    html.mg-theme section.content .open > ul.dropdown-menu > li > a[class*="delete"] > i { background: #FDECEC; color: var(--mg-red); }
    html.mg-theme section.content .open > ul.dropdown-menu > li.divider { height: 1px; margin: 6px 4px !important; background: var(--mg-line); }
    html.mg-theme section.content .open > ul.dropdown-menu > li.dropdown-header { padding: 8px 10px 2px; font-size: 12.5px; color: var(--mg-muted); }
    /* Pendant que le panneau est ouvert, la page derriere ne defile pas. */
    html.mg-actions-on #scrollable-container { overflow-y: hidden !important; }
}

/* ================= Telephone : listes avec tuiles (ventes, achats, depenses) ================= */
@media (max-width: 1023px) {
    .mgrc-tiles { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px; }
    .mgrc-tiles > .mgrc-tile { width: auto !important; min-width: 0; margin: 0 !important; }
    .mgrc-tiles > .mgrc-tile:first-child:nth-last-child(odd) { grid-column: 1 / -1; }
    /* Les totaux sont deja dans les tuiles : la ligne "Total" du tableau fait double emploi. */
    section.content:has(.mgrc-tiles) .dataTables_wrapper table.dataTable > tfoot { display: none !important; }
    /* Titre de la liste et boutons sur une seule ligne. */
    section.content .box-header > .box-tools { flex-direction: row !important; flex-wrap: nowrap; align-items: center; }
    section.content .box-header > .box-tools > a, section.content .box-header > .box-tools > button { width: auto !important; margin: 0 !important; }
}
/* Bouton "Importer" : secondaire, pour ne pas le confondre avec "Ajouter". */
section.content .box-tools > a.mg-btn-import { background: #fff !important; background-image: none !important; color: var(--mg-ink) !important; border: 1px solid #E1E4EA !important; box-shadow: none !important; }
/* ================= Notifications ================= */
.notifications-menu > ul.dropdown-menu { height: auto !important; max-height: 70vh; overflow-y: auto !important; padding: 8px !important; border-radius: 16px !important; }
.notifications-menu > ul.dropdown-menu::before { content: "Notifications"; display: block; padding: 8px 10px 10px; font-size: 16px; font-weight: 600; color: var(--mg-ink); border-bottom: 1px solid var(--mg-line); margin-bottom: 6px; }
#notifications_list { margin: 0; padding: 0; list-style: none; }
#notifications_list > li.notification-li { display: block !important; padding: 0 !important; margin: 0 0 2px; border-radius: 12px; }
#notifications_list > li.notification-li > a { display: grid !important; grid-template-columns: 36px minmax(0, 1fr); column-gap: 12px; row-gap: 2px; align-items: start; padding: 10px !important; border-radius: 12px; white-space: normal !important; color: var(--mg-ink) !important; text-decoration: none !important; }
#notifications_list > li.notification-li > a > .notif-icon { grid-row: 1 / span 2; width: 36px; height: 36px; display: inline-flex; align-items: center; justify-content: center; border-radius: 10px; background: #F3F4F7; color: #4A4F60; font-size: 15px; }
#notifications_list > li.notification-li > a > .notif-info { grid-column: 2; font-size: 14px; font-weight: 400; line-height: 1.35; overflow-wrap: anywhere; }
#notifications_list > li.notification-li > a > .time { grid-column: 2; font-size: 12.5px; color: var(--mg-muted); }
#notifications_list > li.notification-li.unread { background: var(--mg-orange-soft); }
#notifications_list > li.notification-li.unread > a > .notif-info { font-weight: 600; }
#notifications_list > li.no-notification { padding: 28px 12px !important; color: var(--mg-muted); font-size: 14.5px; font-weight: 400; text-align: center; }
@media (max-width: 1023px) {
    /* Sur telephone : un panneau sur toute la largeur, sous la barre du haut. */
    .notifications-menu.open > ul.dropdown-menu {
        position: fixed !important; top: 62px !important; right: 8px !important; bottom: auto !important; width: calc(100vw - 16px) !important; max-width: none !important; margin: 0 !important; max-height: calc(100vh - 160px); max-height: calc(100dvh - 160px);
        overscroll-behavior: contain; box-shadow: 0 0 0 100vmax rgba(27, 29, 40, .35), 0 18px 40px rgba(27, 29, 40, .18) !important; z-index: 1060 !important; transform: none !important;
    }
}
/* ================= Telephone : fiche d'une vente / facture ================= */
@media (max-width: 640px) {
    section.mg-fiche .mg-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 14px; }
    section.mg-fiche .mg-field .mg-value { overflow-wrap: anywhere; }
    /* Boutons : l'action principale sur toute la largeur, les autres deux par deux. */
    section.mg-fiche .mg-fiche-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    section.mg-fiche .mg-fiche-actions > * { min-width: 0; margin: 0; }
    section.mg-fiche .mg-fiche-actions > form { display: block !important; }
    section.mg-fiche .mg-fiche-actions > form > .mg-btn { width: 100%; }
    section.mg-fiche .mg-fiche-actions .mg-btn { justify-content: center; text-align: center; white-space: nowrap; min-height: 44px; }
    section.mg-fiche .mg-fiche-actions > .mg-btn-primary:first-child, section.mg-fiche .mg-fiche-actions > form:first-child,
    section.mg-fiche .mg-fiche-actions > :last-child:nth-child(even) { grid-column: 1 / -1; }
    /* Lignes et paiements : une fiche par ligne, plus de defilement de cote. */
    section.mg-fiche .mg-table-wrap:has(> .mg-table-fiches) { overflow: visible; border: 0; border-radius: 0; }
    table.mg-table-fiches, table.mg-table-fiches > tbody { display: block; width: 100% !important; min-width: 0 !important; max-width: 100%; }
    table.mg-table-fiches > tbody > tr > td { min-width: 0 !important; width: auto !important; }
    table.mg-table-fiches > thead { display: none; }
    table.mg-table-fiches > tbody > tr { display: block; margin: 0 0 8px; padding: 10px 12px; border: 1px solid var(--mg-line); border-radius: 12px; background: #fff; }
    table.mg-table-fiches > tbody > tr > td { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0 !important; border: 0 !important; text-align: right; white-space: normal !important; }
    table.mg-table-fiches > tbody > tr > td[data-l]::before { content: attr(data-l); flex: 0 0 auto; color: var(--mg-muted); font-size: 13px; font-weight: 400; text-align: left; }
    table.mg-table-fiches > tbody > tr > td:not([data-l]) { display: block; text-align: left; padding-bottom: 6px !important; }
    table.mg-table-fiches > tbody > tr > td.mg-sans { display: none; }
    table.mg-table-fiches > tbody > tr > td.mg-empty { text-align: center; color: var(--mg-muted); padding: 8px 0 !important; }
}
/* ================= Telephone : facture en ligne (lien envoye au client) ================= */
@media screen and (max-width: 1023px) {
    body > .container:has(#invoice_content) { width: 100%; max-width: 100%; padding: 0 10px 24px; overflow-x: hidden; }
    body > .container:has(#invoice_content) > .row { margin-left: 0; margin-right: 0; }
    body > .container:has(#invoice_content) > .row > [class*="col-"] { padding-left: 0; padding-right: 0; }
    body > .container:has(#invoice_content) > .row > .text-right { display: flex; gap: 8px; justify-content: flex-end; padding: 10px 0; }
    body > .container:has(#invoice_content) > .row > .text-right > .tw-dw-btn { min-height: 44px; padding: 0 16px; font-size: 15px; }
    body > .container:has(#invoice_content) > .row > [class*="col-"]:has(> #invoice_content) { border: 1px solid var(--mg-line) !important; border-radius: 14px; background: #fff; padding: 12px !important; overflow: hidden; }
}
.mg-cadre { max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain; }

/* ================= Telephone : fenetres de saisie (corriger le stock, livraison, commission...) =================
   Elles montent du bas, sur toute la largeur ; le contenu defile et les boutons restent visibles, meme clavier ouvert. */
.mgs-long { display: none; }
@media (max-width: 640px) {
    dialog.mgo-dialog { position: fixed; inset: auto 0 0 0; width: 100% !important; max-width: none; margin: 0; max-height: calc(100vh - 20px); max-height: calc(100dvh - 20px); border-radius: 22px 22px 0 0; overflow: hidden; }
    dialog.mgo-dialog[open] { display: flex; flex-direction: column; animation: mg-sheet-in .18s ease-out; }
    dialog.mgo-dialog > form, dialog.mgo-dialog > .mgo-dlg-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px 16px 0; }
    dialog.mgo-dialog .mgo-dlg-btns { position: sticky; bottom: 0; margin: 12px -16px 0; padding: 10px 16px calc(12px + env(safe-area-inset-bottom, 0px)); background: #fff; border-top: 1px solid var(--mg-line); }
    dialog.mgo-dialog .mgo-dlg-btns > .mg-btn { flex: 1 1 0; min-height: 48px; justify-content: center; font-size: 15.5px; }
    /* Stock par produit : le bouton de correction se voit et se touche facilement. */
    .mgs-long { display: inline; }
    .mgs .mgs-act { gap: 8px; }
    .mgs .mgs-act > .mg-btn { flex: 1 1 auto; min-height: 44px; justify-content: center; border-color: var(--mg-orange); color: var(--mg-orange-dark); background: var(--mg-orange-soft); font-weight: 600; }
    .mgs .mgs-act > .mgs-ico { width: 44px; height: 44px; flex: 0 0 44px; }
}
/* ================= Telephone : rapports =================
   Totaux en tete dans un encadre vert, puis une carte compacte par ligne (deux informations cote a cote). */
@media (max-width: 1023px) {
    .dataTables_wrapper table.dataTable > tfoot { display: block !important; width: 100%; margin: 0 0 10px; }
    .dataTables_wrapper table.dataTable > tfoot > tr { display: flex !important; flex-direction: column; gap: 2px; width: 100%; padding: 12px 14px; border: 0 !important; border-radius: 14px; background: var(--mg-green-soft, #EAF7F0) !important; }
    .dataTables_wrapper table.dataTable > tfoot > tr::before { content: "Totaux"; font-size: 13px; font-weight: 600; color: var(--mg-green-dark, #1E6B47); padding-bottom: 4px; }
    .dataTables_wrapper table.dataTable > tfoot > tr > td, .dataTables_wrapper table.dataTable > tfoot > tr > th {
        display: flex !important; justify-content: space-between; align-items: baseline; gap: 12px; width: 100% !important; padding: 3px 0 !important; border: 0 !important; background: none !important; text-align: right !important; font-size: 15px; font-weight: 700; color: var(--mg-ink);
    }
    .dataTables_wrapper table.dataTable > tfoot > tr > td[data-mg-label]:not([data-mg-label=""])::before { content: attr(data-mg-label) !important; flex: 0 1 auto; font-size: 13px; font-weight: 400; color: #3F4354; text-align: left; }
    .dataTables_wrapper table.dataTable > tfoot > tr > td.mg-cell-empty { display: none !important; }
    .dataTables_wrapper table.dataTable > tfoot > tr > td p { margin: 0; text-align: right !important; }
    .dataTables_wrapper table.dataTable > tfoot > tr > td small { font-size: inherit; }

    /* Cartes compactes des rapports. */
    .dataTables_wrapper table.dataTable.mg-dense > tbody > tr { display: grid !important; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px 14px; align-items: start; }
    .dataTables_wrapper table.dataTable.mg-dense > tbody > tr > td { display: block !important; width: auto !important; min-width: 0; padding: 0 !important; text-align: left !important; font-size: 14px; line-height: 1.3; overflow-wrap: anywhere; }
    .dataTables_wrapper table.dataTable.mg-dense > tbody > tr > td[data-mg-label]::before { display: block; max-width: none; margin-bottom: 1px; font-size: 12px; color: var(--mg-muted); }
    .dataTables_wrapper table.dataTable.mg-dense > tbody > tr > td.mg-cell-title { grid-column: 1 / -1; padding-bottom: 8px !important; margin-bottom: 0; font-size: 15.5px; }
    .dataTables_wrapper table.dataTable.mg-dense > tbody > tr > td.mg-cell-action, .dataTables_wrapper table.dataTable.mg-dense > tbody > tr > td.dataTables_empty { grid-column: 1 / -1; }
    .dataTables_wrapper table.dataTable.mg-dense > tbody > tr > td.mg-cell-total { font-size: 15.5px; }
    .dataTables_wrapper table.dataTable.mg-dense > tbody > tr > td br { display: none; }
    .dataTables_wrapper table.dataTable.mg-dense .mg-sel { display: none !important; }
}@media (max-width: 1023px) {
    .dataTables_wrapper table.dataTable.mg-dense > tbody > tr > td.mg-cell-empty { display: none !important; }
    .dataTables_wrapper table.dataTable > tfoot > tr { text-align: left !important; }
}@media (max-width: 1023px) {
    /* Tableaux a defilement : seule la ligne de totaux visible (celle du bas) est affichee, pas sa copie de mesure. */
    .dataTables_wrapper .dataTables_scrollBody table.dataTable > tfoot { display: none !important; }
    .dataTables_wrapper .dataTables_scrollFoot table > tfoot > tr > td[data-mg-label]:not([data-mg-label=""]) { justify-content: space-between !important; text-align: right !important; }
    .dataTables_wrapper .dataTables_scrollFoot table > tfoot > tr > td[data-mg-label]:not([data-mg-label=""])::before { content: attr(data-mg-label) !important; font-size: 13px; font-weight: 400; color: #3F4354; }
}
/* ================= Notifications : presentation plus nette, surtout sur ordinateur ================= */
.notifications-menu > ul.dropdown-menu { padding: 0 !important; box-shadow: 0 18px 50px rgba(27, 29, 40, .18) !important; border: 1px solid var(--mg-line) !important; scrollbar-width: thin; }
.notifications-menu > ul.dropdown-menu::before { position: sticky; top: 0; z-index: 2; margin: 0; padding: 14px 16px 12px; background: #fff; border-radius: 16px 16px 0 0; }
.notifications-menu > ul.dropdown-menu > li { list-style: none; }
#notifications_list { padding: 6px 8px 8px; }
#notifications_list > li.notification-li { position: relative; margin: 0 0 2px; background: transparent; transition: background .12s ease; }
#notifications_list > li.notification-li:hover { background: #F6F7F9 !important; }
#notifications_list > li.notification-li > a { grid-template-columns: 38px minmax(0, 1fr); padding: 10px 12px !important; }
#notifications_list > li.notification-li > a > .notif-icon { width: 38px; height: 38px; border-radius: 50%; background: #EEF0F4 !important; color: #4A4F60 !important; font-size: 15px; }
#notifications_list > li.notification-li > a > .notif-icon.bg-yellow, #notifications_list > li.notification-li > a > .notif-icon.bg-orange { background: var(--mg-orange-soft) !important; color: var(--mg-orange-dark) !important; }
#notifications_list > li.notification-li > a > .notif-icon.bg-green { background: #E3F4EA !important; color: #137A45 !important; }
#notifications_list > li.notification-li > a > .notif-icon.bg-red { background: #FDECEA !important; color: #C0392B !important; }
#notifications_list > li.notification-li > a > .notif-icon.bg-blue, #notifications_list > li.notification-li > a > .notif-icon.bg-aqua, #notifications_list > li.notification-li > a > .notif-icon.bg-light-blue { background: #EAF1FE !important; color: #1D4ED8 !important; }
#notifications_list > li.notification-li > a > .notif-info { font-size: 14px; line-height: 1.4; color: var(--mg-ink); }
#notifications_list > li.notification-li > a > .notif-info i { font-style: normal; font-weight: 600; }
#notifications_list > li.notification-li > a > .time { display: block; float: none !important; justify-self: start; text-align: left !important; margin: 0 !important; padding: 0 !important; font-size: 12.5px; font-weight: 400; color: var(--mg-muted) !important; }
#notifications_list > li.notification-li.unread { background: var(--mg-orange-soft); }
#notifications_list > li.notification-li.unread::after { content: ""; position: absolute; top: 16px; right: 12px; width: 8px; height: 8px; border-radius: 50%; background: var(--mg-orange); }
#notifications_list > li.notification-li.unread > a { padding-right: 28px !important; }
.notifications-menu li.load_more_li { position: sticky; bottom: 0; padding: 8px; background: #fff; border-top: 1px solid var(--mg-line); border-radius: 0 0 16px 16px; }
.notifications-menu li.load_more_li > a { display: flex !important; align-items: center; justify-content: center; min-height: 40px; padding: 0 12px !important; border-radius: 10px; background: #F3F4F7 !important; color: var(--mg-ink) !important; font-size: 13.5px; font-weight: 500; text-decoration: none !important; }
.notifications-menu li.load_more_li > a:hover { background: #E9EBF0 !important; }
@media (min-width: 1024px) {
    .notifications-menu > ul.dropdown-menu { width: 420px !important; max-width: calc(100vw - 32px) !important; max-height: min(620px, calc(100vh - 110px)) !important; margin-top: 10px !important; }
}
@media (prefers-reduced-motion: reduce) { #notifications_list > li.notification-li { transition: none; } }

/* Cartes produit sur telephone : les trois boutons (voir, modifier, plus) se partagent la largeur de la carte.
   Le troisieme debordait de la carte et se trouvait coupe. */
@media (max-width: 1023px) {
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr.mg-has-card > td.mg-cell-action { display: flex !important; flex-wrap: nowrap; align-items: stretch; width: 100%; min-width: 0; box-sizing: border-box; border-top: 1px solid var(--mg-line); }
    .mgp-grid td.mg-cell-action > .mgc-btns { flex: 2 1 0; min-width: 0; display: flex; }
    .mgp-grid td.mg-cell-action > .mgc-btns > .mgc-btn.mgc-ico { flex: 1 1 0; width: auto; min-width: 0; min-height: 42px; }
    .mgp-grid td.mg-cell-action > .btn-group { flex: 1 1 0; min-width: 0; display: flex; float: none; margin: 0; position: static; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action > .btn-group > .dropdown-toggle { flex: 1 1 auto; width: 100% !important; min-width: 0; min-height: 42px; height: 42px; padding: 0 2px !important; border-radius: 10px !important; border: 1px solid #E1E4EA !important; background: #fff !important; color: var(--mg-ink) !important; font-size: 13px !important; font-weight: 500; justify-content: center; overflow: hidden; }
    .mgp-grid td.mg-cell-action > .btn-group > .dropdown-toggle .caret, .mgp-grid td.mg-cell-action > .btn-group > .dropdown-toggle svg, .mgp-grid td.mg-cell-action > .btn-group > .dropdown-toggle i { display: none; }
    .mgp-grid td.mg-cell-action .mgc-btn:active, .mgp-grid td.mg-cell-action .dropdown-toggle:active { background: #F4F5F8 !important; }
}
@media (max-width: 359px) { .dataTables_wrapper table.dataTable.mgp-grid > tbody { grid-template-columns: minmax(0, 1fr) !important; } }
@media (max-width: 1023px) {
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr.mg-has-card > td.mg-cell-action { align-items: center; }
    .mgp-grid td.mg-cell-action > .mgc-btns > .mgc-btn.mgc-ico { height: 42px; min-height: 42px; }
    /* Le libelle du menu ("Actions") ne tient pas dans un tiers de carte : il devient "Plus", sur une ligne. */
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action > .btn-group > .dropdown-toggle { font-size: 0 !important; white-space: nowrap; line-height: 1; display: flex; align-items: center; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action > .btn-group > .dropdown-toggle::after { content: "Plus"; font-size: 13px; font-weight: 500; }
}
@media (max-width: 1023px) {
    .mgp-grid td.mg-cell-action > .mgc-btns, .mgp-grid td.mg-cell-action > .btn-group { height: 42px; margin: 0 !important; padding: 0 !important; align-self: center; vertical-align: top; top: 0; }
    .dataTables_wrapper table.dataTable.mgp-grid > tbody > tr > td.mg-cell-action > .btn-group > .dropdown-toggle { height: 42px !important; min-height: 42px !important; margin: 0 !important; box-sizing: border-box; }
}

/* Listes en cartes sur telephone : la barre « actions sur la selection » ne s'affiche que si quelque chose est coche
   (elle apparaissait en bas de la liste des produits, avec « 0 selectionne » illisible). */
html.mg-theme body .dataTables_wrapper:not(.mg-has-selection) table.dataTable > tfoot > tr.mg-bulk-foot,
html.mg-theme body .dataTables_wrapper:not(.mg-has-selection) table.dataTable > tfoot:has(> tr.mg-bulk-foot):not(:has(> tr:not(.mg-bulk-foot))) { display: none !important; }

/* ================= Tablette (768 a 1023 px) : les memes fiches que sur telephone, sur deux colonnes ================= */
@media (min-width: 768px) and (max-width: 1023px) {
    section.content, section.content-header { padding-left: 20px !important; padding-right: 20px !important; }
    .dataTables_wrapper table.dataTable:not(.mgp-grid) > tbody { display: grid !important; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; align-items: start; }
    .dataTables_wrapper table.dataTable:not(.mgp-grid) > tbody > tr { margin: 0 !important; }
    /* Une ligne seule (liste vide, message) prend toute la largeur. */
    .dataTables_wrapper table.dataTable > tbody > tr:only-child, .dataTables_wrapper table.dataTable > tbody > tr:has(> td.dataTables_empty) { grid-column: 1 / -1; }
    /* La grille de produits : plus de fiches par ligne que sur telephone. */
    .dataTables_wrapper table.dataTable.mgp-grid > tbody { grid-template-columns: repeat(4, minmax(0, 1fr)) !important; }
    /* Barre d'outils des listes : la recherche et le bouton d'export sur une ligne. */
    /* Fenetres : sur tablette, une feuille centree aux coins arrondis (le plein ecran est reserve au telephone). */
    .modal:not(.mgpay-simple) { padding: 28px 24px !important; }
    .modal .modal-dialog:not(.modal-sm) { width: min(760px, 100%) !important; margin: 0 auto !important; height: auto !important; max-height: calc(100vh - 56px); display: flex; flex-direction: column; }
    .modal .modal-dialog:not(.modal-sm) > .modal-content { height: auto !important; min-height: 0 !important; max-height: calc(100vh - 56px); width: 100%; border-radius: 18px !important; box-shadow: 0 24px 60px rgba(27, 29, 40, .28) !important; }
    .modal .modal-dialog:not(.modal-sm) > .modal-content > form { height: auto !important; }
    .modal .modal-footer { padding-bottom: 12px !important; }
    .mgrc-tiles { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)) !important; gap: 10px !important; }
    .mgrc-tiles > .mgrc-tile:first-child:nth-last-child(odd) { grid-column: auto !important; }
    .dataTables_wrapper > .row.margin-bottom-20 { flex-direction: row !important; align-items: center !important; }
    .dataTables_wrapper > .row.margin-bottom-20 > div { width: auto !important; flex: 1 1 0; }
}
/* ================= Accueil telephone et tablette : choix de la periode =================
   Un bandeau a quatre cases au-dessus des chiffres (pas de defilement de cote), et une feuille qui monte du bas
   avec toutes les periodes de la version ordinateur, dates au choix comprises. */
.mgf { display: none; }
dialog.mgf-feuille:not([open]) { display: none; }
@media (max-width: 1023px) {
    .mgf { display: block; margin: 0 0 12px; }
    .mgf-seg { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 14px; background: #E6E9EF; }
    .mgf-seg > a, .mgf-seg > button { min-width: 0; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 0 6px; border: 0; border-radius: 10px; background: transparent; color: #4A5060 !important; font: inherit; font-size: 13.5px; font-weight: 500; text-decoration: none !important; white-space: nowrap; cursor: pointer; -webkit-tap-highlight-color: transparent; }
    .mgf-seg > button span { overflow: hidden; text-overflow: ellipsis; }
    .mgf-seg > button svg { width: 16px; height: 16px; flex: 0 0 auto; }
    .mgf-seg > .on { background: #fff; color: var(--mg-ink) !important; font-weight: 600; box-shadow: 0 1px 3px rgba(27, 29, 40, .14); }
    .mgf-seg > a:focus-visible, .mgf-seg > button:focus-visible { outline: 2px solid var(--mg-orange); outline-offset: 1px; }
    .mgf-plage { margin: 8px 2px 0; font-size: 13px; color: var(--mg-muted); }
    /* Le libelle « Chiffres aujourd'hui » redit la periode : inutile juste sous le bandeau. */
    .mgd .mgf ~ .mgt-cap { display: none; }

    dialog.mgf-feuille { position: fixed; inset: auto 0 0 0; margin: 0; width: 100%; max-width: 100%; max-height: 86vh; max-height: 86dvh; padding: 0; border: 0; border-radius: 20px 20px 0 0; background: #fff; color: var(--mg-ink); box-shadow: 0 -12px 40px rgba(27, 29, 40, .22); overflow: hidden; }
    dialog.mgf-feuille[open] { display: flex; flex-direction: column; animation: mgf-monte .22s ease-out; }
    dialog.mgf-feuille::backdrop { background: rgba(20, 24, 33, .45); }
    .mgf-tete { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; padding: 16px 12px 10px 18px; }
    .mgf-tete h2 { margin: 0; font-size: 17px; font-weight: 600; }
    .mgf-tete button { width: 42px; height: 42px; border: 0; border-radius: 50%; background: #F1F2F5; color: #4A5060; font-size: 24px; line-height: 1; cursor: pointer; }
    .mgf-corps { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 0 12px calc(16px + env(safe-area-inset-bottom, 0px)); }
    .mgf-liste { display: flex; flex-direction: column; }
    .mgf-liste a { display: flex; align-items: center; justify-content: space-between; min-height: 48px; padding: 0 12px; border-radius: 12px; color: var(--mg-ink) !important; font-size: 15.5px; text-decoration: none !important; }
    .mgf-liste a:active { background: #F4F5F8; }
    .mgf-liste a.on { background: var(--mg-orange-soft); color: var(--mg-orange-dark) !important; font-weight: 600; }
    .mgf-liste a.on::after { content: ""; width: 7px; height: 13px; margin-right: 6px; border: solid var(--mg-orange-dark); border-width: 0 2.5px 2.5px 0; transform: rotate(45deg) translateY(-2px); }
    .mgf-perso { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 0; padding: 14px 12px 4px; border-top: 1px solid var(--mg-line); }
    .mgf-perso > b { font-size: 15.5px; font-weight: 600; }
    .mgf-deux { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .mgf-deux label { display: flex; flex-direction: column; gap: 4px; margin: 0; font-size: 13px; font-weight: 500; color: var(--mg-muted); }
    .mgf-deux input { width: 100%; min-width: 0; min-height: 46px; padding: 6px 10px; border: 1px solid #D5D9E0; border-radius: 12px; background: #fff; font: inherit; font-size: 16px; color: var(--mg-ink); }
    .mgf-deux input:focus { outline: none; border-color: var(--mg-orange); box-shadow: 0 0 0 3px var(--mg-orange-soft); }
    .mgf-erreur { margin: 0; font-size: 13.5px; color: #C8372D; }
    .mgf-perso .mg-btn { min-height: 48px; justify-content: center; font-size: 15.5px; }
}
/* Tablette : la feuille devient une fenetre centree, et le bandeau ne s'etire pas sur toute la largeur. */
@media (min-width: 641px) and (max-width: 1023px) {
    .mgf-seg { max-width: 520px; }
    dialog.mgf-feuille { inset: 0; margin: auto; width: 440px; height: fit-content; border-radius: 20px; }
}
@keyframes mgf-monte { from { transform: translateY(24px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { dialog.mgf-feuille[open] { animation: none; } }
/* Une autre periode est choisie : sa case s'elargit pour que son nom se lise en entier. */
@media (max-width: 1023px) {
    .mgf-seg:has(> button.on) { grid-template-columns: minmax(0, 1fr) minmax(0, .72fr) minmax(0, .8fr) minmax(0, 1.5fr); }
    .mgf-seg > button.on { font-size: 13px; }
}
@media (max-width: 380px) { .mgf-seg > button.on svg { display: none; } .mgf-seg > a, .mgf-seg > button { font-size: 13px; padding: 0 4px; } }
