/* Explain: Styles for the food table, controls, portion calculation, and mobile view. */
.tabella-hero {
    padding-top: clamp(10rem, 13vw, 12rem);
}

.alimenti-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--sage-dark);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.alimenti-control {
    width: 100%;
    min-height: 3rem;
    padding: 0.6rem 1rem;
    border: 1px solid var(--glass-border);
    border-radius: 0.85rem;
    background: var(--field-bg);
    color: var(--text-color);
    font-family: var(--font-body);
    font-size: 0.9rem;
}

select.alimenti-control {
    background: var(--background-color);
}

.alimenti-control:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.alimenti-reset {
    min-height: 3rem;
    padding: 0.6rem 1.3rem;
    border: 1px solid var(--pastel-terracotta);
    border-radius: 999px;
    background: rgba(239, 201, 166, 0.35);
    color: var(--text-color);
    font-weight: 600;
    white-space: nowrap;
    transition: background-color 250ms ease, border-color 250ms ease, transform 250ms ease;
}

.alimenti-reset:hover {
    border-color: var(--pastel-terracotta-strong);
    background: rgba(239, 201, 166, 0.7);
    transform: translateY(-1px);
}

.table-scroll-container {
    max-height: 65vh;
    overflow: auto;
    border-radius: 1rem;
    border: 1px solid var(--glass-border);
    scrollbar-width: thin;
    scrollbar-color: var(--accent-color) transparent;
}
.table-scroll-container::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}
.table-scroll-container::-webkit-scrollbar-track {
    background: rgba(250, 249, 246, 0.4);
    border-radius: 1rem;
}
.table-scroll-container::-webkit-scrollbar-thumb {
    background-color: var(--accent-color);
    border-radius: 1rem;
    border: 2px solid rgba(250, 249, 246, 0.9);
}

.alimenti-table {
    width: 100%;
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.82rem;
    table-layout: auto;
}

.alimenti-table th,
.alimenti-table td {
    padding: 0.65rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: top;
    text-align: left;
}

.alimenti-table thead th {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--surface-color);
    color: var(--text-color);
    font-size: 0.66rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    white-space: normal;
    border-bottom: none;
    box-shadow: inset 0 -2px 0 var(--glass-border);
}

.alimenti-table thead th[data-sort] {
    cursor: pointer;
    user-select: none;
}

.alimenti-table thead th[data-sort]:hover {
    color: var(--accent-color);
}

.alimenti-table thead th .sort-icon {
    margin-left: 0.35rem;
    color: var(--accent-color);
    font-size: 0.7rem;
}

.alimenti-table tbody tr:nth-child(odd) {
    background: rgba(250, 249, 246, 0.55);
}

.alimenti-table tbody tr:hover {
    background: var(--sage-soft);
}

.alimenti-name {
    min-width: 7rem;
    font-weight: 600;
    color: var(--text-color);
}

.alimenti-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.alimenti-micro {
    min-width: 9rem;
    color: var(--text-muted);
    font-size: 0.78rem;
}

.ig-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.65rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

.ig-basso {
    background: rgba(156, 189, 132, 0.35);
    color: var(--sage-dark);
}

.ig-medio {
    background: rgba(239, 201, 166, 0.5);
    color: var(--logo-subtitle-color);
}

.ig-alto {
    background: rgba(155, 74, 61, 0.22);
    color: var(--error-color);
}

.alimenti-reset.is-active {
    border-color: var(--pastel-sage-strong);
    background: linear-gradient(135deg, var(--pastel-lime), var(--pastel-sage));
    color: var(--sage-dark);
    box-shadow: 0 16px 34px rgba(156, 189, 132, 0.35);
}

.alimenti-dup-row td {
    background: rgba(155, 74, 61, 0.08);
}

.alimenti-dup-row:hover td {
    background: rgba(155, 74, 61, 0.14);
}

.alimenti-table tbody tr.alimenti-ig-row td {
    background: rgba(155, 74, 61, 0.06);
}

.alimenti-table tbody tr.alimenti-ig-row:hover td {
    background: rgba(155, 74, 61, 0.13);
}

.ig-incoerente {
    background: rgba(155, 74, 61, 0.22);
    color: var(--error-color);
}

/* I controlli di manutenzione esistono solo nella pagina gestione-tabella.html:
   senza la classe admin-gestione sul body non vengono mai mostrati. */
.admin-only {
    display: none !important;
}
body.admin-gestione .admin-only {
    display: block !important;
}

/* Colonna "Porzione da valutare (g)": campo numerico per ricalcolare i valori. */
.alimenti-portion {
    width: 5.5rem;
}

.alimenti-portion-input {
    width: 100%;
    max-width: 6.5rem;
    min-height: 2.6rem;
    padding: 0.4rem 0.5rem;
    border: 1px solid var(--glass-border);
    border-radius: 0.7rem;
    background: var(--field-bg);
    color: var(--text-color);
    font-family: var(--font-body);
    font-size: 0.9rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.alimenti-portion-input:focus {
    outline: 2px solid var(--accent-color);
    outline-offset: 2px;
}

.alimenti-table tbody tr td.is-scaled {
    color: var(--sage-dark);
    font-weight: 700;
    background: rgba(156, 189, 132, 0.16);
}

.alimenti-table tbody tr:hover td.is-scaled {
    background: rgba(156, 189, 132, 0.26);
}

/* Colonna "Fibre" e controllo delle larghezze: la tabella resta entro la
   larghezza del contenitore, senza scorrimento orizzontale. */
.alimenti-table {
    table-layout: fixed;
    width: 100%;
    font-size: 0.78rem;
}

.alimenti-name,
.alimenti-micro {
    min-width: 0;
}

.alimenti-micro {
    font-size: 0.72rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.alimenti-portion {
    width: auto;
}

.alimenti-portion-input {
    max-width: 100%;
}

.ig-badge {
    justify-content: center;
    white-space: normal;
    text-align: center;
}

/* --- Vista da smartphone: la tabella si apre in schede verticali leggibili --- */
@media (max-width: 767px) {
    .table-scroll-container {
        max-height: 72vh;
        padding: 0.75rem;
    }

    .alimenti-table {
        table-layout: auto;
        width: 100%;
        font-size: 0.9rem;
    }

    .alimenti-table colgroup,
    .alimenti-table thead {
        display: none;
    }

    .alimenti-table,
    .alimenti-table tbody,
    .alimenti-table tr,
    .alimenti-table td {
        display: block;
        width: auto;
    }

    .alimenti-table tbody tr {
        margin: 0 0 0.9rem;
        padding: 0.9rem 1rem;
        border: 1px solid var(--glass-border);
        border-radius: 1.35rem;
        background: rgba(250, 249, 246, 0.75);
        box-shadow: 0 12px 28px rgba(31, 46, 35, 0.06);
    }

    .alimenti-table tbody tr:last-child {
        margin-bottom: 0;
    }

    .alimenti-table tbody tr:nth-child(odd),
    .alimenti-table tbody tr:hover {
        background: rgba(250, 249, 246, 0.75);
    }

    .alimenti-table tbody td {
        display: flex;
        align-items: baseline;
        justify-content: space-between;
        gap: 1rem;
        padding: 0.55rem 0;
        border-bottom: 1px dashed var(--border-color);
        text-align: left;
    }

    .alimenti-table tbody tr td:last-child {
        border-bottom: none;
    }

    .alimenti-table tbody td::before {
        flex: 0 0 auto;
        max-width: 55%;
        color: var(--text-muted);
        font-size: 0.68rem;
        font-weight: 700;
        letter-spacing: 0.05em;
        line-height: 1.5;
        text-transform: uppercase;
    }

    /* Intestazione della scheda: nome dell'alimento */
    .alimenti-table tbody td:nth-child(1) {
        display: block;
        margin-bottom: 0.35rem;
        padding-bottom: 0.6rem;
        border-bottom: 1px solid var(--glass-border);
        color: var(--text-color);
        font-family: var(--font-heading);
        font-size: 1.15rem;
        font-weight: 600;
        line-height: 1.4;
    }

    .alimenti-table tbody td:nth-child(1)::before {
        content: none;
    }

    .alimenti-table tbody td:nth-child(2)::before { content: "Categoria"; }
    .alimenti-table tbody td:nth-child(3)::before { content: "Porzione"; }
    .alimenti-table tbody td:nth-child(4)::before { content: "Porzione da valutare (g)"; }
    .alimenti-table tbody td:nth-child(5)::before { content: "Calorie (kcal)"; }
    .alimenti-table tbody td:nth-child(6)::before { content: "Carboidrati (g)"; }
    .alimenti-table tbody td:nth-child(7)::before { content: "Proteine (g)"; }
    .alimenti-table tbody td:nth-child(8)::before { content: "Grassi (g)"; }
    .alimenti-table tbody td:nth-child(9)::before { content: "Fibre (g)"; }
    .alimenti-table tbody td:nth-child(10)::before { content: "Indice glicemico"; }
    .alimenti-table tbody td:nth-child(11)::before { content: "Micronutrienti principali"; }

    /* I valori numerici restano allineati a destra */
    .alimenti-table tbody td.alimenti-num {
        text-align: right;
    }

    /* La colonna del peso da valutare: campo piu' compatto */
    .alimenti-table tbody td.alimenti-portion {
        align-items: center;
    }

    .alimenti-table tbody td.alimenti-portion .alimenti-portion-input {
        width: 7rem;
        max-width: 45%;
        text-align: right;
    }

    /* I micronutrienti possono essere lunghi: etichetta sopra, testo sotto */
    .alimenti-table tbody td:nth-child(11) {
        display: block;
    }

    .alimenti-table tbody td:nth-child(11)::before {
        display: block;
        max-width: 100%;
        margin-bottom: 0.35rem;
    }

    .alimenti-table tbody td .ig-badge {
        margin-left: auto;
    }
}

