/* ERP — impaginazione mobile compatta (righe ingredienti, pannelli, margini) */
@media (max-width: 768px) {
    .layout-erp-wide,
    .gt-main,
    .ricon-main,
    .isp-main,
    .ca-main,
    .cm-main,
    .db-main-wrap,
    .erp-mobile-main-wrap {
        padding-left: max(0.45rem, env(safe-area-inset-left)) !important;
        padding-right: max(0.45rem, env(safe-area-inset-right)) !important;
    }

    /* Titoli categorie su griglia home — fino a 3 righe leggibili */
    .card-cat-titolo,
    .card-categoria .card-cat-titolo,
    .nome-cat,
    .card-cat-giacenza .nome-cat,
    .card-cat-inventario .nome-cat,
    .card-cat-ricon .nome-cat,
    .card-cat-master .nome-cat,
    .card-cat-prev .nome-cat,
    .card-cat-ordini .nome-cat,
    .card-cat-indice .nome-cat,
    .nome-cat-funnel,
    .nome-forn-cat {
        font-size: 0.72rem !important;
        line-height: 1.2 !important;
        display: -webkit-box;
        -webkit-line-clamp: 3;
        -webkit-box-orient: vertical;
        overflow: hidden;
        word-break: break-word;
        hyphens: auto;
        text-align: center;
    }

    /* Piatti / articoli in griglia reparto */
    .btn-piatto-grid,
    .btn-articolo-gt,
    .btn-ingrediente-grid,
    .btn-articolo-grid-ricon,
    .btn-articolo-prev,
    .btn-articolo-ordini,
    .btn-master-grid,
    .btn-articolo-funnel {
        font-size: 0.68rem !important;
        line-height: 1.18 !important;
        padding: 0.38rem 0.32rem !important;
        min-height: 2.85rem;
        display: flex !important;
        align-items: center;
        justify-content: center;
        text-align: center;
        word-break: break-word;
        hyphens: auto;
    }

    /* Pannelli dettaglio — più larghi */
    .pannello-laterale-piatto,
    .pannello-laterale-gt,
    .pannello-laterale-ing,
    .pannello-laterale-ricon,
    .pannello-laterale-prev,
    .pannello-laterale-ord,
    .pannello-laterale-ca,
    .pannello-laterale-master,
    .erp-mobile-panel-compatto {
        padding: 0.45rem 0.4rem !important;
        width: 100%;
    }
    .pannello-sub-box,
    .erp-mobile-sub-box {
        padding: 0.42rem 0.45rem !important;
        margin-bottom: 0.55rem !important;
    }
    .pannello-sub-box-title {
        font-size: 0.66rem !important;
        margin-bottom: 0.35rem !important;
    }
    .pannello-sub-box .table-responsive,
    .pannello-laterale-piatto .table-responsive {
        margin-left: -0.1rem;
        margin-right: -0.1rem;
        overflow-x: visible;
    }

    /* Tabella distinta semplice: nome (+ id) | quantità */
    .erp-mobile-righe {
        font-size: 0.72rem;
        margin-bottom: 0 !important;
    }
    .erp-mobile-righe thead {
        display: none;
    }
    .erp-mobile-righe tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "nome qty"
            "id   qty";
        column-gap: 0.45rem;
        row-gap: 0.04rem;
        align-items: center;
        padding: 0.32rem 0;
        border-bottom: 1px solid rgba(128, 128, 128, 0.28);
    }
    .erp-mobile-righe tbody tr:last-child {
        border-bottom: none;
    }
    .erp-mobile-righe tbody td {
        display: block;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
    }
    .erp-mobile-righe tbody td:nth-child(1) {
        grid-area: nome;
        min-width: 0;
        font-size: 0.72rem;
        line-height: 1.22;
        font-weight: 600;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        word-break: break-word;
    }
    .erp-mobile-righe tbody td:nth-child(2) {
        grid-area: id;
        font-size: 0.62rem;
        line-height: 1.15;
        opacity: 0.82;
        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .erp-mobile-righe tbody td:nth-child(3) {
        grid-area: qty;
        align-self: center;
        font-size: 0.68rem;
        line-height: 1.15;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        text-align: right !important;
    }

    /* Food cost — righe ingredienti con metriche sotto */
    .erp-mobile-righe-fc thead {
        display: none;
    }
    .erp-mobile-righe-fc tbody tr {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        grid-template-areas:
            "nome qty1"
            "id   qty1"
            "m1   m2"
            "m3   m4"
            "act  act";
        column-gap: 0.4rem;
        row-gap: 0.12rem;
        padding: 0.38rem 0;
        border-bottom: 1px solid rgba(128, 128, 128, 0.28);
        align-items: start;
    }
    .erp-mobile-righe-fc tbody tr:last-child {
        border-bottom: none;
    }
    .erp-mobile-righe-fc tbody td {
        display: block;
        padding: 0 !important;
        border: none !important;
        background: transparent !important;
        font-size: 0.68rem;
        line-height: 1.15;
    }
    .erp-mobile-righe-fc tbody td:nth-child(1) {
        grid-area: id;
        font-size: 0.6rem;
        font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
        opacity: 0.8;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }
    .erp-mobile-righe-fc tbody td:nth-child(2) {
        grid-area: nome;
        font-size: 0.72rem;
        font-weight: 600;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
        word-break: break-word;
    }
    .erp-mobile-righe-fc tbody td:nth-child(3) {
        grid-area: qty1;
        font-weight: 700;
        font-variant-numeric: tabular-nums;
        white-space: nowrap;
        text-align: right !important;
    }
    .erp-mobile-righe-fc tbody td:nth-child(4) { grid-area: m1; white-space: nowrap; }
    .erp-mobile-righe-fc tbody td:nth-child(5) { grid-area: m2; white-space: nowrap; text-align: right; }
    .erp-mobile-righe-fc tbody td:nth-child(6) { grid-area: m3; white-space: nowrap; }
    .erp-mobile-righe-fc tbody td:nth-child(7) { grid-area: m4; white-space: nowrap; text-align: right; font-weight: 600; }
    .erp-mobile-righe-fc tbody td:nth-child(4)::before { content: "Tot "; font-size: 0.58rem; opacity: 0.75; }
    .erp-mobile-righe-fc tbody td:nth-child(5)::before { content: "€/udm "; font-size: 0.58rem; opacity: 0.75; }
    .erp-mobile-righe-fc tbody td:nth-child(6)::before { content: "FC×1 "; font-size: 0.58rem; opacity: 0.75; }
    .erp-mobile-righe-fc tbody td:nth-child(7)::before { content: "FC tot "; font-size: 0.58rem; opacity: 0.75; }
    .erp-mobile-righe-fc tbody td:nth-child(8) {
        grid-area: act;
        margin-top: 0.15rem;
    }

    /* Carousel inventario / giacenza — card più compatte, qty sempre una riga */
    .card-ingrediente-inv {
        padding: 0.75rem 0.65rem !important;
        min-height: 0 !important;
        gap: 0.65rem !important;
    }
    .card-ingrediente-inv .nome-ing {
        font-size: 1.05rem !important;
        line-height: 1.22 !important;
    }
    .card-ingrediente-inv .meta-ing,
    .card-ingrediente-inv .meta-ing span,
    .card-ingrediente-inv .meta-ing strong {
        font-size: 0.78rem !important;
        white-space: nowrap;
    }
    .card-articolo-gt {
        padding: 0.65rem 0.6rem !important;
    }
    .card-articolo-gt .gt-card-nome {
        font-size: 0.95rem !important;
        line-height: 1.22 !important;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }
    .card-articolo-gt .gt-card-row .val,
    .card-articolo-gt .gt-qty {
        white-space: nowrap;
        font-size: 0.82rem !important;
    }
    .card-ricon-articolo .ricon-card-header .nome {
        font-size: 0.95rem !important;
        line-height: 1.22 !important;
    }
    .ricon-metrica-row .val {
        white-space: nowrap;
        font-size: 0.82rem !important;
    }
}
