/* ===========================================================================
   Tema fedele all'applicazione WinForms Tofu
   =========================================================================== */

:root {
    --tofu-teal: #1a94ad;
    --tofu-teal-dark: #127d93;
    --tofu-lightblue: #bfe4ea;
    --tofu-yellow: #ffff00;
    --tofu-yellow-border: #cccc00;
    --tofu-navy: #27374d;
    --tofu-accent: #6b3fa0;
    --tofu-accent-dark: #5a3488;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: "Segoe UI", Tahoma, sans-serif;
    background-color: var(--tofu-teal);
    height: 100%;
}

/* ---- Barra a tab in alto (stile dashboard scuro) ---- */
.tofu-tabbar {
    display: flex;
    align-items: stretch;
    background-color: var(--tofu-navy);
    padding: 0 8px;
    gap: 0;
}

.tofu-tab {
    background-color: transparent;
    color: #cdd6e4;
    border: none;
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0;
    padding: 14px 24px;
    font-size: 0.82rem;
    font-weight: 600;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s ease, color 0.15s ease;
    display: inline-flex;
    align-items: center;
    gap: 7px;
}

.tofu-tab-icon {
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    vertical-align: middle;
}

.tofu-data-listino {
    color: #e8f3f3;
    font-size: 0.72rem;
    letter-spacing: 0.2px;
    padding: 4px 12px;
    white-space: nowrap;
}

.tofu-tab:first-child {
    border-left: 1px solid rgba(255, 255, 255, 0.08);
}

.tofu-tab:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: #fff;
    text-decoration: none;
}

.tofu-tab.active {
    background-color: #fff;
    color: var(--tofu-navy);
    font-weight: 700;
}

/* ---- Blocco a destra della tabbar: utente + logout ---- */
.tofu-tabbar-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 0 6px;
}

.tofu-utente {
    color: #cdd6e4;
    font-size: 0.85rem;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.tofu-utente-icon {
    opacity: 0.9;
}

.tofu-tab-logout {
    background-color: var(--tofu-accent);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-weight: 700;
    letter-spacing: 0.6px;
    text-transform: uppercase;
    font-size: 0.82rem;
    padding: 10px 20px;
    cursor: pointer;
    transition: background-color 0.15s ease;
}

.tofu-tab-logout:hover {
    background-color: var(--tofu-accent-dark);
    color: #fff;
}

/* ---- Contenitore pagina ---- */
.tofu-page {
    background-color: var(--tofu-teal);
    min-height: 100vh;
    padding: 4px;
    box-sizing: border-box;
}

.tofu-frame {
    border: 2px solid #fff;
    padding: 6px;
    background-color: var(--tofu-teal);
}

/* ---- Header cliente + logo ---- */
.tofu-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    color: #fff;
    margin-bottom: 4px;
}

.tofu-header .cliente-info {
    text-align: right;
    line-height: 1.15;
    font-size: 0.85rem;
}

.tofu-header .cliente-info .rs {
    font-weight: 700;
    text-transform: uppercase;
}

.tofu-logo {
    font-weight: 800;
    font-size: 1.6rem;
    color: #fff;
    letter-spacing: 1px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.tofu-logo .tofu-logo-img {
    width: 72px;
    height: auto;
    display: block;
}

/* ---- Campi di ricerca gialli ---- */
.tofu-search-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.tofu-search {
    position: relative;
    display: flex;
    align-items: center;
}

.tofu-search input {
    background-color: var(--tofu-yellow);
    border: 1px solid var(--tofu-yellow-border);
    height: 30px;
    padding: 2px 28px 2px 8px;
    font-size: 0.9rem;
    outline: none;
}

.tofu-search .lente {
    position: absolute;
    right: 6px;
    color: var(--tofu-teal-dark);
    pointer-events: none;
}

/* ---- Griglia listino ---- */
.tofu-grid-wrapper {
    background-color: var(--tofu-lightblue);
    border: 1px solid #fff;
    height: 38vh;
    overflow-y: auto;
}

.tofu-grid {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.tofu-grid thead th {
    position: sticky;
    top: 0;
    background-color: var(--tofu-lightblue);
    color: #000;
    text-align: left;
    font-weight: 600;
    padding: 4px 8px;
    border-bottom: 1px solid #8fc4ce;
    white-space: nowrap;
}

/* ---- Riga filtri in stile Excel allineati alle colonne ---- */
.tofu-grid thead tr.tofu-grid-filters th {
    position: sticky;
    top: 27px;
    padding: 2px 4px;
    background-color: var(--tofu-lightblue);
    border-bottom: 1px solid #8fc4ce;
}

.tofu-grid thead tr.tofu-grid-filters th input {
    width: 100%;
    box-sizing: border-box;
    background-color: var(--tofu-yellow);
    border: 1px solid var(--tofu-yellow-border);
    height: 24px;
    padding: 1px 6px;
    font-size: 0.8rem;
    outline: none;
}

.tofu-search-ean input {
    font-size: 1rem;
}

.tofu-search-ean .lente {
    font-size: 1.1rem;
    display: flex;
    align-items: center;
}

.tofu-grid tbody td {
    padding: 3px 8px;
    border-bottom: 1px solid #d3eef2;
    white-space: nowrap;
}

.tofu-grid tbody tr:hover {
    background-color: #a9d8e0;
}

.tofu-grid tbody tr.promo {
    background-color: #c9f0c9;
}

.tofu-grid input.qta {
    width: 60px;
    border: 1px solid var(--tofu-yellow-border);
    background-color: var(--tofu-yellow);
}

/* ---- Carrello ---- */
.tofu-cart-area {
    display: flex;
    align-items: stretch;
    gap: 10px;
    margin-top: 6px;
}

.tofu-cart-wrapper {
    background-color: #fff;
    border: 1px solid #fff;
    flex: 1 1 auto;
    height: 200px;
    overflow-y: auto;
}

.tofu-cart {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.tofu-cart thead th {
    position: sticky;
    top: 0;
    z-index: 1;
    background-color: #eef7f9;
    text-align: left;
    padding: 4px 8px;
    border-bottom: 1px solid #c5c5c5;
    white-space: nowrap;
}

.tofu-cart tbody td {
    padding: 3px 8px;
    border-bottom: 1px solid #ececec;
}

.tofu-cart input.qta {
    width: 50px;
    border: 1px solid var(--tofu-yellow-border);
    background-color: var(--tofu-yellow);
}

/* ---- Totali: fissi in basso a destra accanto al carrello ---- */
.tofu-totali {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: flex-end;
    gap: 6px;
    color: #fff;
    flex: 0 0 auto;
    min-width: 260px;
}

.tofu-totali .riga {
    display: flex;
    align-items: center;
    gap: 8px;
}

.tofu-totali label {
    font-weight: 600;
}

.tofu-totali .valore {
    background-color: var(--tofu-yellow);
    border: 1px solid var(--tofu-yellow-border);
    color: #000;
    min-width: 120px;
    text-align: right;
    padding: 2px 8px;
    font-weight: 600;
}

/* ---- Cart header bar (icona carrello + filtro) ---- */
.tofu-cart-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 6px;
}

.tofu-cart-bar .cart-icon {
    color: #fff;
    font-size: 1.4rem;
}

/* ---- Loader di navigazione tra le tab ---- */
.tofu-loader-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: rgba(255, 255, 255, 0.55);
    z-index: 2000;
}

.tofu-loader-spinner {
    width: 48px;
    height: 48px;
    border: 5px solid var(--tofu-lightblue);
    border-top-color: var(--tofu-teal);
    border-radius: 50%;
    animation: tofu-spin 0.8s linear infinite;
}

@keyframes tofu-spin {
    to {
        transform: rotate(360deg);
    }
}

/* ---- Modale dettaglio ordine ---- */
.tofu-dettaglio-modal {
    background: rgba(0, 0, 0, 0.55);
}

.tofu-dettaglio-content {
    border: none;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.tofu-dettaglio-header {
    background: linear-gradient(135deg, var(--tofu-teal), var(--tofu-teal-dark));
    color: #fff;
    border-bottom: none;
    padding: 14px 20px;
}

.tofu-dettaglio-table {
    font-size: 0.88rem;
}

.tofu-dettaglio-table thead th {
    background-color: var(--tofu-lightblue);
    color: #0b3a42;
    font-weight: 600;
    border-bottom: 2px solid var(--tofu-teal);
    padding: 8px 12px;
    position: sticky;
    top: 0;
}

.tofu-dettaglio-table tbody td {
    padding: 6px 12px;
    vertical-align: middle;
}

.tofu-dettaglio-table tbody tr:hover {
    background-color: #eaf6f8;
}

.tofu-dettaglio-footer {
    background-color: #f5fafb;
    border-top: 1px solid #d9eef1;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: flex-end;
    padding: 14px 20px;
}

.tofu-totale-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 110px;
    padding: 8px 14px;
    background-color: #fff;
    border: 1px solid #d9eef1;
    border-radius: 8px;
}

.tofu-totale-box .label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #6b8a90;
    margin-bottom: 2px;
}

.tofu-totale-box .value {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0b3a42;
}

.tofu-totale-box--highlight {
    background: linear-gradient(135deg, var(--tofu-teal), var(--tofu-teal-dark));
    border-color: var(--tofu-teal-dark);
}

.tofu-totale-box--highlight .label {
    color: rgba(255, 255, 255, 0.8);
}

.tofu-totale-box--highlight .value {
    color: #fff;
}

/* ---- Log invio ordini ---- */
.tofu-log-card {
    border: none;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}

.tofu-log-header {
    background: linear-gradient(135deg, var(--tofu-teal), var(--tofu-teal-dark));
    color: #fff;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.tofu-log-header .btn-close {
    filter: invert(1) grayscale(100%) brightness(200%);
}

.tofu-log-body {
    max-height: 220px;
    overflow-y: auto;
    padding: 8px 12px;
    background-color: #fafcfd;
}

.tofu-log-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 6px;
    margin-bottom: 6px;
    font-size: 0.88rem;
    border-left: 4px solid transparent;
}

.tofu-log-row--incorso {
    background-color: #fff6e0;
    border-left-color: #e0a800;
    color: #7a5c00;
}

.tofu-log-row--successo {
    background-color: #e4f6e9;
    border-left-color: #2e9e4f;
    color: #1d6b36;
}

.tofu-log-row--errore {
    background-color: #fbe3e4;
    border-left-color: #d14b52;
    color: #8a2a2f;
}

.tofu-log-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    font-weight: 700;
}

.tofu-log-ora {
    font-family: monospace;
    opacity: 0.75;
    font-size: 0.8rem;
}

.tofu-log-testo {
    flex: 1 1 auto;
}

/* Barra filtri rapidi mobile: nascosta su desktop (la griglia ha i suoi filtri). */
.tofu-mobile-filtri {
    display: none;
}

/* ===========================================================================
   Responsive mobile (orientamento verticale) - il desktop resta invariato.
   Tutte le regole qui sotto si applicano solo a schermi stretti.
   =========================================================================== */
@media (max-width: 768px) {

    /* Header compatto: logo e intestazione cliente spinti in alto per
       liberare spazio ai filtri sotto l'EAN. */
    .tofu-header {
        align-items: center;
        margin-bottom: 2px;
    }

    /* Intestazione cliente completa, allineata a sinistra e a tutta larghezza
       (occupa lo spazio a sinistra del logo) così non viene tagliata. */
    .tofu-header .cliente-info {
        flex: 1 1 auto;
        font-size: 0.78rem;
        line-height: 1.15;
        text-align: left;
    }

    .tofu-header .cliente-info div {
        white-space: normal;
        overflow: visible;
        text-overflow: clip;
        word-break: break-word;
    }

    .tofu-logo {
        align-self: flex-start;
    }

    .tofu-logo .tofu-logo-img {
        width: 56px;
    }

    /* 1. Tab in alto (Home, Ordini, Clienti...): scorrono in orizzontale
       senza allargare la pagina. */
    .tofu-tabbar {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tofu-tab {
        flex: 0 0 auto;
        padding: 12px 16px;
        font-size: 0.72rem;
    }

    .tofu-tabbar-right {
        flex: 0 0 auto;
    }

    /* 2. Griglia listino: mostra solo descrizione, uvc, giacenza, promo, ordine, listino.
       Ordine colonne: 1 marchio, 2 reparto, 3 articolo, 4 descrizione, 5 iva,
       6 um, 7 peso, 8 uvc, 9 giacenza, 10 promo, 11 ordine, 12 listino. */
    .tofu-grid thead th:nth-child(1),
    .tofu-grid thead th:nth-child(2),
    .tofu-grid thead th:nth-child(3),
    .tofu-grid thead th:nth-child(5),
    .tofu-grid thead th:nth-child(6),
    .tofu-grid thead th:nth-child(7),
    .tofu-grid tbody td:nth-child(1),
    .tofu-grid tbody td:nth-child(2),
    .tofu-grid tbody td:nth-child(3),
    .tofu-grid tbody td:nth-child(5),
    .tofu-grid tbody td:nth-child(6),
    .tofu-grid tbody td:nth-child(7) {
        display: none;
    }

    /* Font ridotto per far entrare tutte le colonne senza sfondare. */
    .tofu-grid {
        font-size: 0.68rem;
        table-layout: fixed;
    }

    .tofu-grid thead th,
    .tofu-grid tbody td {
        padding: 2px 4px;
        white-space: normal;
        word-break: break-word;
    }

    /* La descrizione occupa più spazio; l'header non va a capo. */
    .tofu-grid thead th {
        white-space: nowrap;
    }

    .tofu-grid thead th:nth-child(4),
    .tofu-grid tbody td:nth-child(4) {
        width: 40%;
    }

    .tofu-grid thead tr.tofu-grid-filters th input {
        font-size: 0.68rem;
        height: 22px;
    }

    .tofu-grid input.qta {
        width: 44px;
    }

    /* Nasconde la riga filtri interna alla griglia: su mobile si usano
       i filtri rapidi marchio/descrizione sotto la barra EAN. */
    .tofu-grid thead tr.tofu-grid-filters {
        display: none;
    }

    /* Barra filtri rapidi mobile (marchio + descrizione) sotto l'EAN. */
    .tofu-mobile-filtri {
        display: flex;
        gap: 6px;
        margin-bottom: 6px;
    }

    .tofu-mobile-filtri input {
        flex: 1 1 0;
        min-width: 0;
        box-sizing: border-box;
        background-color: var(--tofu-yellow);
        border: 1px solid var(--tofu-yellow-border);
        height: 32px;
        padding: 2px 8px;
        font-size: 0.85rem;
        outline: none;
    }

    /* La barra ricerca EAN non deve sforare la larghezza schermo. */
    .tofu-search-ean input {
        width: 100% !important;
        box-sizing: border-box;
    }

    .tofu-search-ean {
        width: 100%;
    }

    /* 3. Griglia carrello: più leggibile, nasconde Data e Prezzo cad. per
       lasciare spazio a descrizione/quantità/importo/elimina.
       Colonne: 1 Data, 2 Articolo, 3 Descrizione, 4 Q.tà, 5 Prezzo cad., 6 Importo, 7 Elimina. */
    .tofu-cart thead th:nth-child(1),
    .tofu-cart thead th:nth-child(5),
    .tofu-cart tbody td:nth-child(1),
    .tofu-cart tbody td:nth-child(5) {
        display: none;
    }

    .tofu-cart {
        font-size: 0.7rem;
        table-layout: fixed;
    }

    .tofu-cart thead th,
    .tofu-cart tbody td {
        padding: 3px 4px;
        white-space: normal;
        word-break: break-word;
    }

    .tofu-cart input.qta {
        width: 42px;
    }

    /* Carrello e totali in colonna: prima il carrello, poi i totali compatti. */
    .tofu-cart-area {
        flex-direction: column;
        gap: 6px;
    }

    .tofu-cart-wrapper {
        height: 150px;
    }

    /* 4. Totali compatti in basso: card scura con pillole di sola lettura. */
    .tofu-totali {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
        min-width: 0;
        gap: 6px 8px;
        font-size: 0.72rem;
        background-color: rgba(0, 0, 0, 0.12);
        border: 1px solid rgba(255, 255, 255, 0.25);
        border-radius: 8px;
        padding: 8px 10px;
        margin-top: 4px;
    }

    .tofu-totali .riga {
        flex: 1 1 46%;
        justify-content: space-between;
        gap: 6px;
    }

    .tofu-totali label {
        font-size: 0.72rem;
        text-transform: uppercase;
        letter-spacing: 0.3px;
        white-space: nowrap;
    }

    /* Valori di sola lettura: colore diverso dal giallo dei campi editabili. */
    .tofu-totali .valore {
        flex: 0 0 auto;
        min-width: 64px;
        padding: 3px 8px;
        font-size: 0.78rem;
        font-weight: 700;
        border-radius: 5px;
        background-color: #eef7f9;
        border: 1px solid #a9d8e0;
        color: var(--tofu-navy);
    }

    /* Evidenzia il totale ordine (ultima riga) con un tono più marcato. */
    .tofu-totali .riga:last-child .valore {
        background-color: #d4edda;
        border-color: #9ccfa6;
        color: #1c5a2b;
    }

    /* ---- Pagina Ordini da Inviare: evita lo sforamento orizzontale ---- */
    /* Le card e tabelle Bootstrap non devono superare la larghezza schermo. */
    .card {
        max-width: 100%;
        overflow: hidden;
    }

    .card .table-responsive,
    .card-body {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Tabelle compatte con font ridotto per stare nel viewport verticale. */
    .card .table {
        font-size: 0.72rem;
        margin-bottom: 0;
    }

    .card .table th,
    .card .table td {
        padding: 4px 6px;
        word-break: break-word;
    }

    /* Uniforma le tabelle non-card (Clienti, Comunicazioni) allo stesso
       stile grafico di Ordini e Home: solo font ridotto, senza spezzare le
       parole. Lo scroll orizzontale della .table-responsive resta attivo. */
    .table-responsive .table {
        font-size: 0.72rem;
        margin-bottom: 0;
    }

    .table-responsive .table th,
    .table-responsive .table td {
        padding: 4px 6px;
        white-space: nowrap;
    }

    /* Header card (titolo + pulsanti) impilato su mobile per non sforare. */
    .card-header.d-flex {
        flex-direction: column;
        align-items: stretch !important;
        gap: 6px;
    }

    /* Pulsanti azione più compatti. */
    .card .btn-sm {
        padding: 3px 8px;
        font-size: 0.72rem;
    }
}
