/* KcalAdvisor, direzione A "Dispensa". Token: spec §8 e mockup in docs/design/mockups. */

:root {
    --ground: #F4F5F2;
    --surface: #FFFFFF;
    --line: #DADDD6;          /* bordo delle superfici */
    --line-strong: #C9CDC5;   /* bordo di pulsanti e campi */
    --hairline: #EEF0EC;      /* separatori tra righe */
    --track: #E4E7E1;         /* barre di avanzamento, chip neutri */
    --field: #F7F8F6;

    --ink: #1B2620;
    --ink-2: #56605A;         /* testo secondario */
    --ink-3: #3D4640;         /* testo corrente nei paragrafi */
    --on-dark-2: #B9C2BB;

    --accent: #C2412D;        /* pomodoro: eccezioni, azioni di scambio */
    --accent-tint: #FBEAE6;
    --accent-ink: #7E2617;
    --accent-line: #E8B4A8;

    --ok: #2F6B4F;            /* basilico: regole rispettate, avanzi */
    --ok-tint: #E3EFE8;
    --ok-ink: #1F4D38;

    --font-display: 'Bricolage Grotesque', sans-serif;
    --font-body: 'Figtree', sans-serif;
    --font-mono: 'IBM Plex Mono', monospace;

    --radius-s: 10px;
    --radius-m: 12px;
    --radius-l: 14px;
    --page-width: 560px;
    --tap: 44px;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--font-body);
    font-size: 16px;
    line-height: 1.4;
}

/* Sfondo bloccato mentre un pannello dal basso è aperto. */
body:has(.sheet) { overflow: hidden; }

h1, h2, h3 { margin: 0; font-family: var(--font-display); }
h1 { font-weight: 800; font-size: 34px; line-height: 1.05; letter-spacing: -0.02em; text-wrap: balance; }
h2 { font-weight: 600; font-size: 20px; line-height: 1.2; text-wrap: balance; }
p { margin: 0; text-wrap: pretty; }
h1:focus { outline: none; }  /* FocusOnNavigate sposta il focus sul titolo: non è un controllo */

a { color: var(--ink); }
a:not([class]):hover { color: var(--accent); }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible {
    outline: 2px solid var(--ink);
    outline-offset: 2px;
}

::selection { background: var(--accent-tint); color: var(--accent-ink); }

/* ---------- Struttura ---------- */

.app {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
}

.page {
    flex: 1;
    width: 100%;
    max-width: var(--page-width);
    margin: 0 auto;
    padding: 20px;
}

@supports (padding: max(0px)) {
    .page {
        padding-left: max(20px, env(safe-area-inset-left));
        padding-right: max(20px, env(safe-area-inset-right));
    }
}

/* ---------- Barra di navigazione in basso ---------- */

.bottom-nav {
    position: sticky;
    bottom: 0;
    z-index: 10;
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    padding: 8px 8px 16px;
    background: var(--surface);
    border-top: 1px solid var(--line);
}

@supports (padding: max(0px)) {
    .bottom-nav {
        /* su schermi larghi le voci restano nella colonna della pagina */
        padding-left: max(8px, calc((100% - var(--page-width)) / 2 + 8px));
        padding-right: max(8px, calc((100% - var(--page-width)) / 2 + 8px));
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}

.nav-item {
    min-height: 52px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    border-radius: var(--radius-s);
    color: var(--ink-2);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
}

.nav-item[aria-current="page"] {
    color: var(--ink);
    font-weight: 600;
}

/* ---------- Componenti ---------- */

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    padding: 16px;
}

.btn {
    min-height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 16px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-m);
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none;
}

.btn-primary { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }
.btn-accent { background: var(--accent); color: #FFFFFF; border-color: var(--accent); }

.btn:disabled,
.btn[aria-disabled="true"] {
    background: var(--line-strong);
    color: var(--ink-3);
    border-color: var(--line-strong);
    cursor: not-allowed;
}

.btn-block { display: flex; width: 100%; min-height: 52px; border-radius: var(--radius-l); font-size: 16px; }

/* Pulsante con sola icona: 44 x 44. */
.icon-btn {
    width: var(--tap);
    height: var(--tap);
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-m);
    text-decoration: none;
}

/* Nelle schede: senza bordo né fondo; premuto (es. pasto bloccato) = fondo scuro. */
.icon-btn-quiet {
    background: transparent;
    color: var(--ink-2);
    border-color: transparent;
    border-radius: var(--radius-s);
}

.icon-btn-quiet[aria-pressed="true"] {
    background: var(--ink);
    color: #FFFFFF;
}

.icon-btn-accent { color: var(--accent); }

/* Disattivato (salvataggio in corso, copia offline in sola lettura). */
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

@media (hover: hover) {
    .btn:not(:disabled):not([aria-disabled="true"]):hover,
    .icon-btn:not(:disabled):hover { border-color: var(--ink); }
    .icon-btn-quiet:not([aria-pressed="true"]):not(:disabled):hover { background: var(--hairline); border-color: transparent; }
}

/* Etichetta tipo "didascalia": IBM Plex Mono 12 px maiuscolo spaziato. */
.label {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-2);
}

.mono { font-family: var(--font-mono); }

/* Chip: tag non interattivi; con <button>/<a> diventano filtri da 36 px (area di tocco 44 px). */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--track);
    color: var(--ink-3);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.3;
}

:where(button, a).chip {
    position: relative;
    min-height: 36px;
    padding: 0 14px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    font-size: 14px;
    text-decoration: none;
}

:where(button, a).chip::after {
    content: "";
    position: absolute;
    inset: -4px 0;
}

.chip[aria-pressed="true"] { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }

.tint-accent { background: var(--accent-tint); color: var(--accent-ink); }
.tint-ok { background: var(--ok-tint); color: var(--ok-ink); }

/* ---------- Campi ---------- */

.field { display: flex; flex-direction: column; gap: 6px; }

.field-label { font-size: 13px; font-weight: 500; color: var(--ink-2); }

.input {
    width: 100%;
    min-height: 48px;
    padding: 0 14px;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-m);
    font-size: 16px; /* sotto i 16 px iOS ingrandisce la pagina al tocco */
}

.input:focus-visible { outline-offset: 0; border-color: var(--ink); }

/* Campo con un pulsante a icona dentro, a destra (mostra/nascondi password). */
.input-wrap { position: relative; display: flex; }
.input-wrap .input { padding-right: 52px; }
.input-wrap .icon-btn { position: absolute; top: 2px; right: 2px; }

/* ---------- Accesso ---------- */

.login {
    display: flex;
    flex-direction: column;
    gap: 24px;
    padding-top: clamp(16px, 10vh, 80px);
}

.login-form { display: flex; flex-direction: column; gap: 16px; }
.login-note { font-size: 14px; color: var(--ink-2); }

.load-error { margin-bottom: 16px; }

/* ---------- Banner ---------- */

.banner {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 12px 14px;
    border-radius: var(--radius-m);
    font-size: 14px;
    line-height: 1.45;
    align-self: stretch; /* a tutta larghezza anche dentro un contenitore flex */
}

.banner > svg { flex-shrink: 0; margin-top: 1px; }
.banner-text { flex: 1; min-width: 0; }

.banner-close {
    position: relative;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    margin: -4px -6px -4px 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 999px;
    color: inherit;
}

.banner-close::after { content: ""; position: absolute; inset: -8px; } /* area di tocco 44 px */

/* Esito delle azioni sul piano: resta in vista mentre si scorre fino alla scheda toccata. */
.notices { position: sticky; top: 12px; z-index: 5; display: flex; flex-direction: column; gap: 8px; }
.notices .banner { box-shadow: 0 6px 20px rgba(27, 38, 32, 0.14); }
.banner-info { background: var(--track); color: var(--ink-3); }
.banner-error { background: var(--accent-tint); color: var(--accent-ink); }
.banner-ok { background: var(--ok-tint); color: var(--ok-ink); }

/* ---------- Pannello dal basso ---------- */

.sheet-scrim {
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(18, 26, 21, 0.55);
}

.sheet {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    width: 100%;
    max-width: var(--page-width);
    max-height: 90vh;
    max-height: 90dvh;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 10px 20px max(28px, env(safe-area-inset-bottom));
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--surface);
    border-radius: 22px 22px 0 0;
}

.sheet:focus { outline: none; }

.sheet-grip {
    flex-shrink: 0;
    align-self: center;
    width: 40px;
    height: 4px;
    background: var(--line-strong);
    border-radius: 2px;
}

.sheet-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.sheet-header .icon-btn { margin: -8px -12px 0 0; }  /* il segno x sta a filo con il bordo del contenuto */

.sheet-title { font-weight: 800; font-size: 26px; line-height: 1.1; text-wrap: balance; }

.sheet-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

@media (prefers-reduced-motion: no-preference) {
    .sheet { animation: sheet-in 0.2s ease-out; }
    .sheet-scrim { animation: scrim-in 0.2s ease-out; }
}

@keyframes sheet-in { from { transform: translateY(24px); opacity: 0; } }
@keyframes scrim-in { from { opacity: 0; } }

/* ---------- Avvio e errori di Blazor ---------- */

/* Blazor imposta display:block quando mostra l'avviso, quindi niente flex: il pulsante è in posizione assoluta. */
#blazor-error-ui {
    color-scheme: light only;
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 1000;
    width: 100%;
    display: none;
    padding: 14px 64px 14px 20px;
    background: var(--accent-tint);
    color: var(--accent-ink);
    border-top: 1px solid var(--accent-line);
    font-size: 14px;
    line-height: 1.45;
}

#blazor-error-ui .reload { margin-left: 4px; color: var(--accent-ink); font-weight: 600; }

#blazor-error-ui .dismiss {
    position: absolute;
    top: 50%;
    right: 8px;
    width: var(--tap);
    height: var(--tap);
    margin-top: calc(var(--tap) / -2);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    color: inherit;
    border: 0;
    border-radius: var(--radius-s);
}

.blazor-error-boundary {
    padding: 14px 16px;
    background: var(--accent);
    border-radius: var(--radius-m);
    color: #FFFFFF;
}

.blazor-error-boundary::after { content: "Si è verificato un errore."; }

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: var(--track);
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

.loading-progress circle:last-child {
    stroke: var(--ink);
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
}

@media (prefers-reduced-motion: no-preference) {
    .loading-progress circle:last-child { transition: stroke-dasharray 0.05s ease-in-out; }
}

.loading-progress-text {
    position: absolute;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--ink-2);
}

.loading-progress-text::after { content: var(--blazor-load-percentage-text, "Caricamento"); }

/* ---------- Famiglia e Persona ---------- */

.screen { display: flex; flex-direction: column; gap: 18px; }

.section { display: flex; flex-direction: column; gap: 12px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

.back-link {
    align-self: flex-start;
    min-height: var(--tap);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: -8px;
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
}

/* Il nome della persona come nel mockup (38 px); i nomi lunghi vanno a capo invece di uscire dalla pagina. */
.person-name { font-size: 38px; overflow-wrap: anywhere; }

/* Elenco in un unico riquadro (Famiglia, Ricette). */
.list {
    margin: 0;
    padding: 0;
    list-style: none;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-l);
    overflow: hidden;
}

.list > li + li { border-top: 1px solid var(--hairline); }

.list-row {
    min-height: 64px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    color: var(--ink);
    text-decoration: none;
}

.list-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.list-title { font-size: 16px; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.list-meta { font-size: 13px; color: var(--ink-2); }
.list-value { font-family: var(--font-mono); font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.list-row > svg { flex-shrink: 0; color: var(--ink-2); }

@media (hover: hover) {
    .list-row:hover { background: var(--field); }
}

.account-email { font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }

.field-note { min-height: 1.4em; font-size: 13px; color: var(--ink-2); }
.field-error { font-size: 13px; font-weight: 500; color: var(--accent-ink); }

.btn-danger { background: transparent; color: var(--accent-ink); border-color: var(--accent-line); }

/* Interruttore a due voci (Al giorno / A settimana): due radio dentro etichette. */
.segmented {
    margin: 0;
    padding: 4px;
    border: 0;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    background: var(--hairline);
    border-radius: var(--radius-m);
}

.segmented label {
    position: relative;
    min-height: var(--tap);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 9px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
}

.segmented label:has(input:checked) { background: var(--ink); color: #FFFFFF; font-weight: 600; }
.segmented label:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }

/* Campi numerici: niente freccette del browser. */
.kcal-box input, .pct-box input { -moz-appearance: textfield; appearance: textfield; }
.kcal-box input::-webkit-outer-spin-button, .kcal-box input::-webkit-inner-spin-button,
.pct-box input::-webkit-outer-spin-button, .pct-box input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.kcal-box {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 0 14px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-m);
}

.kcal-box input {
    flex: 1;
    min-width: 0;
    padding: 6px 0;
    background: transparent;
    border: 0;
    font-family: var(--font-mono);
    font-size: 32px;
    font-weight: 500;
    line-height: 1.3;
}

.kcal-box > span { font-size: 15px; color: var(--ink-2); }

.kcal-box:focus-within, .pct-box:focus-within { border-color: var(--ink); outline: 2px solid var(--ink); }
.kcal-box input:focus-visible, .pct-box input:focus-visible { outline: none; }

.share-total { font-size: 13px; }
.share-total-ok { color: var(--ok-ink); }
.share-total-bad { color: var(--accent-ink); }

.meal-row { min-height: 52px; display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--hairline); }

.meal-check {
    flex: 1;
    min-width: 0;
    align-self: stretch;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 15px;
    cursor: pointer;
}

.meal-check input { flex-shrink: 0; width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }

.pct-box {
    min-height: var(--tap);
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 10px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
}

.pct-box input {
    align-self: stretch; /* tutto il riquadro (44 px) è area di tocco */
    width: 40px;
    padding: 0;
    background: transparent;
    border: 0;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 16px; /* sotto i 16 px iOS ingrandisce la pagina al tocco */
}

.pct-box > span { font-size: 13px; color: var(--ink-2); }
.pct-box:has(input:disabled) { background: var(--field); color: var(--ink-2); }

.meal-kcal { width: 64px; text-align: right; font-family: var(--font-mono); font-size: 13px; color: var(--ink-2); }

.pref-group { display: flex; flex-direction: column; gap: 8px; }
.pref-head { display: flex; flex-direction: column; gap: 2px; }
.pref-title { font-size: 15px; font-weight: 600; }
.pref-hint { font-size: 13px; color: var(--ink-2); text-wrap: pretty; }
.pref-chips { display: flex; flex-wrap: wrap; gap: 6px; }

.tint-neutral { background: var(--hairline); color: var(--ink); }

.pref-chip { min-height: 36px; gap: 2px; padding: 0 4px 0 12px; font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }

.chip-remove {
    position: relative;
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    margin-right: -6px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 999px;
    color: inherit;
}

.chip-remove::after { content: ""; position: absolute; inset: -8px; } /* area di tocco 44 px */

.chip-add {
    position: relative;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 0 12px;
    background: transparent;
    border: 1px dashed #A9B0AA;
    border-radius: 999px;
    color: var(--ink);
    font-size: 14px;
}

.chip-add::after { content: ""; position: absolute; inset: -4px 0; }
.chip-add:disabled { color: var(--ink-2); opacity: 0.6; cursor: not-allowed; }

.pref-add { display: flex; flex-direction: column; gap: 8px; padding-top: 4px; }

.form-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }

/* ---------- Settimana ---------- */

.week-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.week-heading { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.week-actions { flex-shrink: 0; display: flex; gap: 8px; }
.week-nav { display: flex; align-items: center; gap: 2px; margin: -8px 0 0 -12px; }
.week-step { color: var(--ink); }

.member-chips { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 8px; }

.member-chip {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 999px;
}

.member-chip-name { font-size: 14px; font-weight: 600; }
.member-chip .mono { font-size: 12px; color: var(--ink-2); }

.day-tabs { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }

.day-tab {
    min-height: 56px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    padding: 0;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--radius-m);
}

.day-tab[aria-pressed="true"] { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }
.day-tab-letter { font-size: 12px; font-weight: 500; }
.day-tab-number { font-size: 15px; font-weight: 500; }

@media (hover: hover) {
    .day-tab:not([aria-pressed="true"]):hover { border-color: var(--ink); }
}

.balance { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; }
.balance-title { font-size: 11px; line-height: 1.4; }
.rules { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 12px; }
.rule { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.rule-name { font-size: 13px; font-weight: 600; }
.rule-value { font-size: 12px; color: var(--ink-2); }
.rule-bar { height: 4px; background: var(--track); border-radius: 2px; overflow: hidden; }
.rule-bar > div { height: 4px; background: var(--ok); }
.rule-off .rule-name, .rule-off .rule-value { color: var(--accent); }
.rule-off .rule-bar > div { background: var(--accent); }
.rule-hint { font-size: 12px; line-height: 1.3; color: var(--accent-ink); text-wrap: pretty; }

.day-title { margin-top: 2px; }

.meal-card { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px 16px; }
.meal-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.meal-card-actions { display: flex; gap: 4px; margin: -6px -8px -6px 0; }
.meal-card-title { display: flex; flex-direction: column; gap: 4px; }

.meal-name {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 21px;
    line-height: 1.2;
    text-decoration: none;
    text-wrap: balance;
    overflow-wrap: anywhere;
}

a.meal-name:hover { color: var(--accent); }
.meal-name-empty { color: var(--ink-2); }
.meal-tags { font-size: 13px; color: var(--ink-2); }

.meal-people {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    padding-top: 10px;
    border-top: 1px dashed var(--line);
}

.meal-person { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.meal-person-name { font-size: 12px; color: var(--ink-2); overflow-wrap: anywhere; }
.meal-person-kcal { font-size: 15px; font-weight: 500; }
.meal-person-kcal .unit { font-size: 11px; color: var(--ink-2); }
.meal-person-kcal.is-exception { color: var(--accent); }

/* Avviso dentro una scheda (eccezione, avanzi, slot vuoto). */
.note {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 12px;
    border-radius: var(--radius-s);
    font-size: 13px;
    line-height: 1.4;
}

.note > svg { flex-shrink: 0; margin-top: 1px; }
.note-accent { background: var(--accent-tint); color: var(--accent-ink); }
.note-ok { background: var(--ok-tint); color: var(--ok-ink); }
/* Conflitto con un «Mai» arrivato dopo il menù: stesso tono dell'eccezione, ma bordato perché va risolto. */
.note-alert { box-shadow: inset 0 0 0 1px var(--accent); font-weight: 500; }
.conflict-notes { display: grid; gap: 8px; }

.day-total {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
    background: var(--ink);
    color: var(--ground);
    border-radius: var(--radius-l);
}

.day-total-title {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 400;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--on-dark-2);
}

.day-total-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.day-total-person { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.day-total-name { font-size: 12px; color: var(--on-dark-2); overflow-wrap: anywhere; }
.day-total-kcal { font-size: 15px; font-weight: 500; }
/* L'obiettivo va sotto l'effettivo: con tre persone "2.194 / 2.200" non sta su una riga a 390 px. */
.day-total-target { display: block; font-size: 12px; font-weight: 400; color: var(--on-dark-2); }

/* Casella con titolo e spiegazione (Avanzi). */
.check-row { display: flex; align-items: flex-start; gap: 12px; min-height: var(--tap); padding: 4px 0; cursor: pointer; }
.check-row input { flex-shrink: 0; width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--ink); }
.check-text { display: flex; flex-direction: column; gap: 2px; }
.check-title { font-size: 15px; font-weight: 600; }

/* ---------- Dettaglio pasto ---------- */

.meal-head { display: flex; flex-direction: column; gap: 10px; }
.meal-title { font-size: 38px; overflow-wrap: anywhere; }
.tag-row { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }

.action-row { display: flex; flex-wrap: wrap; gap: 8px; }
.action-row .btn { flex: 1 1 auto; }
.btn-compact { min-height: var(--tap); padding: 0 14px; font-size: 14px; }
.btn-toggle[aria-pressed="true"] { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }

.ingredients { width: 100%; border-collapse: collapse; font-size: 15px; }
.ingredients th { padding: 6px 0; font-size: 12px; font-weight: 500; color: var(--ink-2); text-align: left; }
.ingredients td { padding: 6px 0; line-height: 1.3; vertical-align: middle; }
.ingredients tbody tr { border-top: 1px solid var(--track); }
.ingredients .num { width: 54px; padding-left: 4px; text-align: right; white-space: nowrap; }
.ingredients td.num { font-size: 14px; }
.ingredients .food { overflow-wrap: break-word; hyphens: auto; }
.ingredients .swap-col { width: 44px; padding: 0; text-align: right; }
.ingredients .swap-col .icon-btn { margin-left: auto; }
.ingredients tfoot tr { border-top: 2px solid var(--ink); }
.ingredients tfoot th { padding: 10px 0; font-size: 15px; font-weight: 600; color: var(--ink); }
.ingredients tfoot td { padding: 10px 0 10px 4px; font-weight: 500; }
.pieces { display: block; font-size: 11px; color: var(--ink-2); white-space: nowrap; }

.exception-card { border-color: var(--accent-line); }
.exception-kcal { font-size: 14px; color: var(--ink-2); }
.exception-recipe { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; color: var(--accent-ink); }
.exception-recipe > svg { flex-shrink: 0; margin-top: 2px; }
/* Link dentro la frase: area di tocco alta 44 px senza spostare il testo. */
.exception-link { display: inline-block; padding-block: 14px; margin-block: -14px; color: inherit; text-decoration: underline; text-underline-offset: 3px; }

.item-list { margin: 0; padding: 0; list-style: none; }
.item-list li { display: flex; justify-content: space-between; gap: 12px; padding: 6px 0; border-top: 1px solid var(--track); font-size: 15px; }
.item-list .mono { flex-shrink: 0; font-size: 14px; text-align: right; }

.steps { margin: 0; font-size: 15px; line-height: 1.5; text-wrap: pretty; }
ol.steps { padding-left: 20px; display: flex; flex-direction: column; gap: 8px; }

.source-note { font-size: 12px; color: var(--ink-2); }

/* ---------- Pannelli Scambia ed Eccezione ---------- */

.sheet-intro { margin-top: -8px; font-size: 14px; line-height: 1.45; color: var(--ink-2); }

.options { margin: 0; padding: 0; border: 0; min-width: 0; display: flex; flex-direction: column; }
.options-legend { padding: 0 0 6px; }

.option {
    min-height: 56px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 4px;
    border-top: 1px solid var(--track);
    cursor: pointer;
}

.option input { flex-shrink: 0; width: 20px; height: 20px; margin: 0; accent-color: var(--accent); }
.option:has(input:disabled) { cursor: default; }
.option-on { margin: 0 -8px; padding: 8px 12px; background: var(--accent-tint); border-top-color: transparent; border-radius: var(--radius-s); }
.option-on + .option { border-top-color: transparent; }
.option-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.option-name { font-size: 16px; font-weight: 600; overflow-wrap: anywhere; }
.option-hint { font-size: 12px; color: var(--ink-2); }
.option-grams { flex-shrink: 0; display: flex; flex-direction: column; align-items: flex-end; font-size: 13px; line-height: 1.5; text-align: right; }

/* I pulsanti restano visibili in fondo anche con un elenco lungo. */
.sheet .sheet-actions {
    position: sticky;
    bottom: calc(-1 * max(28px, env(safe-area-inset-bottom)));
    margin: 0 -20px calc(-1 * max(28px, env(safe-area-inset-bottom)));
    padding: 12px 20px max(28px, env(safe-area-inset-bottom));
    background: var(--surface);
    border-top: 1px solid var(--line);
}

/* ---------- Spesa ---------- */

.shop-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.shop-heading { min-width: 0; display: flex; flex-direction: column; gap: 4px; }

.shop-progress { display: flex; flex-direction: column; gap: 6px; font-size: 14px; }
.shop-progress strong { font-weight: 600; }
.shop-bar { height: 6px; background: var(--track); border-radius: 3px; overflow: hidden; }
.shop-bar > div { height: 6px; background: var(--ok); }

.shop-aisle { padding: 12px 16px 6px; }
.shop-aisle > h2 { margin-bottom: 4px; }
.shop-list { margin: 0; padding: 0; list-style: none; }

.shop-row {
    min-height: var(--tap);
    display: flex;
    align-items: center;
    gap: 12px;
    border-top: 1px solid var(--hairline);
    cursor: pointer;
}

.shop-row input { flex-shrink: 0; width: 20px; height: 20px; margin: 0; accent-color: var(--ok); }
.shop-name { flex: 1; min-width: 0; font-size: 15px; overflow-wrap: anywhere; }
.shop-qty { flex-shrink: 0; font-size: 14px; text-align: right; white-space: nowrap; }
.shop-row.is-done { color: #646D67; text-decoration: line-through; }
.shop-row.is-busy { opacity: 0.55; cursor: progress; }
.shop-row:has(input:disabled):not(.is-busy) { cursor: default; }

/* ---------- Ricette ---------- */

.recipe-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.recipe-actions .btn { padding: 0 8px; }

.search-box {
    min-height: 48px;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 14px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-m);
}

.search-box:focus-within { border-color: var(--ink); outline: 2px solid var(--ink); }
.search-box > svg { flex-shrink: 0; color: var(--ink-2); }

.search-box input {
    flex: 1;
    min-width: 0;
    min-height: 46px;
    padding: 0;
    background: transparent;
    border: 0;
    font-size: 16px; /* sotto i 16 px iOS ingrandisce la pagina al tocco */
}

.search-box input:focus-visible { outline: none; }

.filters { display: flex; flex-wrap: wrap; gap: 6px; }

.list-title-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.badge { padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: 0.02em; }

/* ---------- Ricetta ---------- */

.recipe-title { font-size: 38px; overflow-wrap: anywhere; }
.recipe-kcal { font-size: 14px; color: var(--ink-2); }

.field-hint { font-size: 13px; color: var(--ink-2); text-wrap: pretty; }
.id-note { font-size: 13px; color: var(--ink-2); overflow-wrap: anywhere; }

.check-list { display: flex; flex-direction: column; }
.check-list .check-row { border-top: 1px solid var(--hairline); align-items: center; padding: 0; }
.check-list .check-row:first-child { border-top: 0; }

.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; }

.month-grid { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 6px; }

.month-btn {
    min-height: var(--tap);
    padding: 0;
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
    font-size: 14px;
    font-weight: 500;
}

.month-btn[aria-pressed="true"] { background: var(--ink); color: #FFFFFF; border-color: var(--ink); }

.ingredient-rows { display: flex; flex-direction: column; gap: 14px; }
.ing-row { display: flex; flex-direction: column; gap: 6px; padding-bottom: 14px; border-bottom: 1px solid var(--hairline); }
.ing-row:last-child { padding-bottom: 0; border-bottom: 0; }
.ing-line { display: flex; align-items: center; gap: 10px; }

.g-box {
    min-width: 0;
    min-height: var(--tap);
    flex: 0 1 112px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
}

.g-box input {
    align-self: stretch;
    flex: 1;
    width: 0; /* senza, la larghezza di base del campo (circa 200 px) allarga il riquadro */
    min-width: 0;
    padding: 0;
    background: transparent;
    border: 0;
    text-align: right;
    font-family: var(--font-mono);
    font-size: 16px;
    -moz-appearance: textfield;
    appearance: textfield;
}

.g-box input::-webkit-outer-spin-button, .g-box input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.g-box input:focus-visible { outline: none; }
.g-box:focus-within { border-color: var(--ink); outline: 2px solid var(--ink); }
.g-box:has(input:disabled) { background: var(--field); color: var(--ink-2); }
.g-box > span { font-size: 13px; color: var(--ink-2); }

.qb-check { min-height: var(--tap); flex: 1; display: flex; align-items: center; gap: 8px; font-size: 15px; cursor: pointer; }
.qb-check input { width: 20px; height: 20px; margin: 0; accent-color: var(--ink); }

.kcal-live {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    padding-top: 12px;
    border-top: 2px solid var(--ink);
}

.kcal-live-label { font-size: 15px; font-weight: 600; }
.kcal-live-value { font-size: 20px; font-weight: 500; }
.kcal-live-value .unit { font-size: 13px; color: var(--ink-2); }

.textarea {
    width: 100%;
    min-height: 140px;
    padding: 12px 14px;
    background: var(--surface);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-m);
    font-size: 16px;
    line-height: 1.5;
    resize: vertical;
}

.textarea:focus-visible { outline-offset: 0; border-color: var(--ink); }

.readonly-list { margin: 0; padding: 0; list-style: none; }
.readonly-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-top: 1px solid var(--track); font-size: 15px; }
.readonly-list li:first-child { border-top: 0; }
.readonly-list .mono { flex-shrink: 0; font-size: 14px; }

/* ---------- Incolla da AI ---------- */

.lead { font-size: 15px; line-height: 1.5; color: var(--ink-3); }

.step-title { display: flex; align-items: center; gap: 10px; font-size: 19px; }

.step-num {
    flex-shrink: 0;
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ink);
    color: #FFFFFF;
    border-radius: 999px;
    font-size: 13px;
}

.step-text { font-size: 14px; line-height: 1.5; color: var(--ink-3); }
.step-action { align-self: flex-start; }

.paste-box {
    width: 100%;
    height: 300px;
    padding: 12px;
    background: var(--field);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-s);
    font-family: var(--font-mono);
    font-size: 16px; /* sotto i 16 px iOS ingrandisce la pagina al tocco */
    line-height: 1.5;
    resize: vertical;
}

.paste-box:focus-visible { outline-offset: 0; border-color: var(--ink); }
.prompt-copy { height: 160px; font-size: 12px; }

.check-lines { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; font-size: 14px; line-height: 1.45; }
.check-line { display: flex; gap: 10px; align-items: flex-start; }
.check-line > svg { flex-shrink: 0; margin-top: 1px; }
.check-ok > svg { color: var(--ok); }
.check-line b { font-weight: 600; overflow-wrap: anywhere; }

.check-issue { flex-direction: column; gap: 8px; padding: 10px 12px; background: var(--accent-tint); color: var(--accent-ink); border-radius: var(--radius-s); }
.check-issue-head { display: flex; gap: 10px; align-items: flex-start; }
.check-issue-head > svg { flex-shrink: 0; margin-top: 1px; }
.check-detail { font-family: var(--font-mono); font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; opacity: 0.85; }
.check-fixes { display: flex; flex-wrap: wrap; gap: 6px; padding-left: 28px; }

.fix-btn {
    position: relative;
    min-height: 36px;
    padding: 0 12px;
    background: var(--surface);
    color: var(--accent-ink);
    border: 1px solid var(--accent-line);
    border-radius: 999px;
    font-family: var(--font-mono);
    font-size: 13px;
}

.fix-btn::after { content: ""; position: absolute; inset: -4px 0; } /* area di tocco 44 px */
.fix-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.save-area { display: flex; flex-direction: column; gap: 6px; }
.save-note { text-align: center; font-size: 13px; color: var(--ink-2); }

/* ---------- Utilità ---------- */

.stack { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

/* ---------- Stampa ---------- */

/* Elementi che esistono solo sulla carta (tabella della settimana, "☐" della spesa). */
.print-only { display: none; }

@page { margin: 12mm; }

@media print {
    /* Il foglio è bianco e nero: niente fondi, ombre, bordi arrotondati. */
    html, body { background: #FFFFFF; }
    body { color: #000000; font-size: 11pt; }
    * { box-shadow: none !important; }

    /* Navigazione, pulsanti, avvisi e pannelli non servono sulla carta. */
    .bottom-nav, .btn, .icon-btn, .banner, .notices, .sheet, .sheet-scrim, #blazor-error-ui, .no-print { display: none !important; }
    .print-only { display: block; }

    .app { min-height: 0; display: block; }
    .page { max-width: none; padding: 0; }
    .screen { gap: 10pt; }
    .card { padding: 0; background: none; border: 0; border-radius: 0; }

    /* Settimana: tabella giorni × pasti. */
    .print-week { color: #000000; }

    .print-table {
        width: 100%;
        table-layout: fixed;
        border-collapse: collapse;
        font-size: 8.5pt;
        line-height: 1.3;
    }

    .print-table caption { padding-bottom: 8pt; text-align: left; }
    .print-kicker { display: block; margin-bottom: 2pt; font-family: var(--font-mono); font-size: 8pt; letter-spacing: 0.08em; text-transform: uppercase; }
    .print-title { display: block; font-family: var(--font-display); font-weight: 800; font-size: 22pt; line-height: 1.1; letter-spacing: -0.02em; }
    .print-legend { display: block; margin-top: 3pt; font-size: 8pt; font-weight: 400; }

    .print-table th, .print-table td { padding: 4pt 5pt; border: 0.75pt solid #777777; text-align: left; vertical-align: top; overflow-wrap: break-word; }
    .print-table thead { display: table-header-group; }
    .print-table thead th { background: #EEEEEE; font-size: 8pt; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
    .print-table tr { break-inside: avoid; }
    .print-table .print-day { width: 13%; font-weight: 600; }

    .print-table td > span { display: block; }
    .print-dish { font-weight: 600; }
    .print-table .print-person { display: flex; flex-wrap: wrap; justify-content: space-between; column-gap: 4pt; margin-top: 1pt; font-size: 8pt; }
    .print-person .mono { white-space: nowrap; }
    .print-note { margin-top: 2pt; font-size: 7pt; font-style: italic; }

    /* Spesa: titolo a tutta larghezza, reparti su due colonne, righe con "☐". */
    .shop-screen { display: block; column-count: 2; column-gap: 12mm; }
    .shop-head { column-span: all; margin-bottom: 8pt; }
    .shop-heading { gap: 2pt; }
    .shop-head h1 { font-size: 24pt; }

    .shop-aisle { margin: 0 0 10pt; padding: 0; break-inside: avoid; }
    .shop-aisle > h2 { margin-bottom: 2pt; font-size: 9pt; color: #000000; }
    .shop-row { min-height: 0; padding: 3pt 0; gap: 8pt; border-top: 0.5pt solid #AAAAAA; }
    .shop-row input { display: none; }
    .print-box { display: inline-block; flex-shrink: 0; font-size: 13pt; line-height: 1; }
    .shop-name { font-size: 10pt; }
    .shop-qty { font-size: 9pt; }
    .shop-qty .pieces { color: #000000; }
    .shop-row.is-done { color: #000000; text-decoration: none; }
}
