:root {
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f0efec;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #ffffff;
  --water: #2a78d6;
  --deficit: #2a78d6;
  --surplus: #e34948;
  --good: #006300;
  --bad: #c22e2d;
  --carbo: #eda100;
  --proteine: #e34948;
  --grassi: #1baf7a;
  --verdure: #008300;
  --zuccheri: #e87ba4;
  --frutta: #eb6834;
  --altro: #898781;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #262624;
    --ink: #ffffff;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5;
    --water: #3987e5;
    --deficit: #3987e5;
    --surplus: #e66767;
    --good: #0ca30c;
    --bad: #e66767;
    --carbo: #c98500;
    --proteine: #e66767;
    --grassi: #199e70;
    --zuccheri: #d55181;
    --frutta: #d95926;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body { margin: 0; }

body {
  background: var(--page);
  color: var(--ink);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
  overscroll-behavior-y: none;
}

button, input, select, textarea { font: inherit; color: inherit; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  padding: calc(env(safe-area-inset-top) + 10px) 16px 10px;
  background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
.topbar-inner { max-width: 608px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar h1 { margin: 0; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; }

.view { padding: 4px 16px 24px; max-width: 640px; margin: 0 auto; }

/* Tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.tabbar button {
  border: 0; background: none; padding: 4px 0; display: flex; flex-direction: column;
  align-items: center; gap: 2px; font-size: 11px; color: var(--muted); cursor: pointer;
}
.tabbar svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button.active { color: var(--accent); }

/* Cards */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 17px; font-weight: 650; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card h2 .sub { font-size: 14px; font-weight: 500; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin: 18px 4px 8px; font-weight: 600; }

/* Date nav */
.datenav { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 8px; }
.datenav .label { text-align: center; flex: 1; }
.datenav .label strong { display: block; font-size: 17px; text-transform: capitalize; }
.datenav .label button { border: 0; background: none; color: var(--accent); font-size: 13px; padding: 0; cursor: pointer; }
.iconbtn {
  width: 40px; height: 40px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; cursor: pointer; flex: none;
}
.iconbtn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.iconbtn:disabled { opacity: 0.35; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border-radius: 10px; padding: 10px; min-width: 0; }
.stat .k { font-size: 12px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat .v { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.stat .v small { font-size: 12px; font-weight: 500; color: var(--ink-2); }
.stat .note { font-size: 11px; color: var(--muted); }
.stat.hero { grid-column: 1 / -1; display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px; }
.stat.hero .v { font-size: 30px; }
.pos { color: var(--good); }
.neg { color: var(--bad); }

.macros { display: flex; gap: 6px; margin-top: 10px; height: 8px; border-radius: 4px; overflow: hidden; background: var(--surface-2); }
.macros span { display: block; height: 100%; }
.macro-legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); margin-top: 8px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }

/* Water */
.water-bar { height: 12px; border-radius: 6px; background: var(--surface-2); overflow: hidden; margin: 4px 0 12px; }
.water-bar span { display: block; height: 100%; background: var(--water); border-radius: 6px; transition: width 0.3s; }
.water-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.water-log { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  border: 1px solid var(--border); background: var(--surface-2); border-radius: 999px;
  padding: 4px 10px; font-size: 13px; color: var(--ink-2); cursor: pointer; font-variant-numeric: tabular-nums;
}
.chip.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }

/* Buttons */
.btn {
  border: 1px solid var(--border); background: var(--surface-2); color: var(--ink);
  border-radius: 10px; padding: 10px 12px; font-weight: 600; font-size: 15px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.ghost { background: none; border-color: transparent; color: var(--accent); padding: 6px 8px; }
.btn.block { width: 100%; }
.btn:active { transform: scale(0.98); }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { flex: 1; }

/* Meals */
.meal-items { list-style: none; margin: 0; padding: 0; }
.meal-items li {
  display: flex; align-items: center; gap: 10px; padding: 9px 0;
  border-top: 1px solid var(--border); cursor: pointer;
}
.meal-items li:first-child { border-top: 0; }
.meal-items .name { flex: 1; min-width: 0; }
.meal-items .name div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meal-items .name small { color: var(--muted); font-size: 13px; }
.meal-items .kcal { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 14px; }
.meal-footer { display: flex; gap: 8px; margin-top: 8px; }
.meal-footer .btn { flex: 1; padding: 8px; font-size: 14px; }
.empty { color: var(--muted); font-size: 14px; padding: 4px 0 2px; }

/* Health */
.health-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 10px; }

/* Forms */
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; }
input[type="text"], input[type="number"], input[type="search"], input[type="date"], input[type="email"], input[type="password"], select, textarea {
  width: 100%; padding: 11px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); font-size: 16px; outline: none; -webkit-appearance: none; appearance: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 110px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grid4 label.field input { padding: 10px 8px; }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0 12px; }

/* Food list */
.food-list { list-style: none; margin: 0; padding: 0; }
.food-list li {
  display: flex; align-items: center; gap: 10px; padding: 11px 2px; border-top: 1px solid var(--border); cursor: pointer;
}
.food-list li:first-child { border-top: 0; }
.food-list .name { flex: 1; min-width: 0; }
.food-list .name small { display: block; color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.food-list .qty { font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 14px; white-space: nowrap; }
.cat-chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; scrollbar-width: none; }
.cat-chips::-webkit-scrollbar { display: none; }
.cat-chips .chip { white-space: nowrap; }

/* Sheet */
.backdrop {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 20;
  animation: fade 0.18s ease-out;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 21;
  max-height: 90dvh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface); border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  max-width: 640px; margin: 0 auto;
  animation: up 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}
.sheet .grabber { width: 36px; height: 5px; border-radius: 3px; background: var(--axis); margin: 0 auto 10px; }
.sheet h3 { margin: 0 0 14px; font-size: 19px; display: flex; justify-content: space-between; align-items: center; }
.sheet h3 .btn { font-size: 15px; }
@keyframes up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

.preview { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; margin-bottom: 12px; font-variant-numeric: tabular-nums; font-size: 14px; color: var(--ink-2); }
.preview strong { color: var(--ink); font-size: 18px; }

/* Toast */
#toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom)); z-index: 30;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--page); padding: 10px 16px; border-radius: 999px;
  font-size: 14px; transition: all 0.2s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* History */
.chart-wrap { position: relative; }
.chart-wrap svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart-wrap .bar { cursor: pointer; }
.chart-readout { min-height: 40px; font-size: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; margin-bottom: 6px; }
.chart-readout strong { color: var(--ink); }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--ink-2); margin-top: 8px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

table.hist { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
table.hist th, table.hist td { padding: 8px 4px; text-align: right; border-top: 1px solid var(--border); white-space: nowrap; }
table.hist th { color: var(--muted); font-weight: 600; border-top: 0; font-size: 12px; }
table.hist th:first-child, table.hist td:first-child { text-align: left; }
table.hist tr[data-date] { cursor: pointer; }
.table-scroll { overflow-x: auto; margin: 0 -4px; }

/* Settings */
.list-btn {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  border: 0; background: none; padding: 12px 2px; border-top: 1px solid var(--border); cursor: pointer; text-align: left;
}
.list-btn:first-of-type { border-top: 0; }
.list-btn .chev { color: var(--muted); }
.steps { padding-left: 20px; margin: 0; font-size: 15px; }
.steps li { margin-bottom: 10px; }
.steps code, .mono { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }

/* Gruppi del pasto (piano) */
.slot { border-top: 1px solid var(--border); padding: 2px 0; }
.slot:first-child { border-top: 0; }
.slot-head {
  display: flex; width: 100%; align-items: center; justify-content: space-between;
  border: 0; background: none; padding: 10px 0; cursor: pointer; font-size: 15px; font-weight: 600; text-align: left;
}
.slot-head.static { cursor: default; }
.slot-cta { font-weight: 500; font-size: 14px; color: var(--accent); }
.slot.filled .slot-cta { color: var(--muted); font-size: 13px; }
.slot .meal-items { margin: -4px 0 6px 13px; }
.slot .meal-items li { border-top: 0; padding: 5px 0; }
.slot .meal-items .dot { display: none; }
.plan-note { margin-top: 8px; font-size: 14px; color: var(--ink-2); }
.plan-note summary { cursor: pointer; color: var(--accent); font-size: 14px; }
.plan-note p { margin: 8px 0 0; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; gap: 2px; padding: 2px; background: var(--surface-2); border-radius: 10px; margin-bottom: 12px; }
.segmented button { border: 0; background: none; padding: 8px; border-radius: 8px; font-weight: 600; font-size: 14px; color: var(--ink-2); cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.badge { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: color-mix(in srgb, var(--carbo) 22%, transparent); color: var(--ink-2); white-space: nowrap; }

.opt-item { display: grid; grid-template-columns: 1fr 84px auto; gap: 8px; align-items: end; }
.opt-item .rm { margin-bottom: 12px; font-size: 14px; }
textarea.plain { font-family: inherit; font-size: 15px; min-height: 90px; }

/* Obiettivo proteine */
.goal-row { margin-top: 12px; }
.goal-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 14px; font-variant-numeric: tabular-nums; }
.goal-head .btn.ghost { padding: 0; font-size: 14px; }
.protein-bar { margin: 6px 0 0; height: 8px; }
.protein-bar span { background: var(--proteine); }
.muted { color: var(--muted); }
.goal-row + .macros { margin-top: 14px; }

/* Versioni del piano */
.badge.ok { background: color-mix(in srgb, var(--good) 18%, transparent); }
.check { display: flex; gap: 8px; align-items: center; font-size: 14px; margin: 0 0 12px; color: var(--ink-2); }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
.bulk-list { border-top: 1px solid var(--border); }
.bulk-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.bulk-row span { flex: 1; min-width: 0; }
.bulk-row small { display: block; color: var(--muted); font-size: 12px; }
.bulk-row input { width: 84px; flex: none; text-align: right; }
.change-meal { margin-bottom: 8px; }
.change-meal:last-child { margin-bottom: 0; }
.change { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.change span { white-space: nowrap; }
.version-tag { display: block; margin: 0; }
table.prog td, table.prog th { padding: 6px 4px; }
select {
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23898781' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}

/* Ricerca fissa in cima al foglio */
.sheet-search { position: sticky; top: -8px; z-index: 1; background: var(--surface); padding: 4px 0 8px; margin-top: -4px; }

/* Peso */
.weight-row { display: flex; align-items: center; gap: 14px; }
.weight-val { font-size: 30px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; white-space: nowrap; }
.weight-val small { font-size: 14px; font-weight: 500; color: var(--ink-2); }
.weight-meta { font-size: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.card h2 .btn.ghost { padding: 0; font-size: 15px; font-weight: 600; }
.legend .dotsw { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-2); }

/* ---------- Stato del salvataggio ---------- */
.sync { font-size: 12px; color: var(--muted); white-space: nowrap; transition: opacity 0.3s; }
.sync:empty { display: none; }
.sync.saved { opacity: 0.7; }
.sync.saved::before { content: '✓ '; }
.sync.error { color: var(--bad); font-weight: 600; }

/* ---------- Accesso ---------- */
.brand { display: none; }
#auth-root:empty { display: none; }
body.logged-out .tabbar, body.logged-out .view, body.logged-out .topbar { display: none; }
.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; padding: 28px 22px; box-shadow: var(--shadow); text-align: center;
}
.auth-card img { border-radius: 14px; }
.auth-card h1 { font-size: 24px; margin: 10px 0 18px; }
.auth-card .field { text-align: left; }
.auth-error { color: var(--bad); font-size: 14px; min-height: 1.4em; margin: 0 0 8px; }
.auth-card.loading p { color: var(--ink-2); margin: 14px 0 0; }
.spinner {
  width: 28px; height: 28px; margin: 0 auto; border-radius: 50%;
  border: 3px solid var(--surface-2); border-top-color: var(--accent); animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Desktop ---------- */
.hist-grid, .settings-grid, .foods-grid { display: contents; }

@media (min-width: 1024px) {
  body { padding-bottom: 0; padding-left: 232px; }

  .tabbar {
    top: 0; right: auto; width: 232px; display: flex; flex-direction: column; gap: 2px;
    padding: 20px 12px; border-top: 0; border-right: 1px solid var(--border);
  }
  .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 22px; font-weight: 700; font-size: 17px; }
  .brand img { border-radius: 7px; }
  .tabbar button {
    flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 12px;
    border-radius: 10px; font-size: 15px; font-weight: 500; color: var(--ink-2);
  }
  .tabbar button:hover { background: var(--surface-2); }
  .tabbar button.active { background: color-mix(in srgb, var(--accent) 12%, transparent); color: var(--accent); }
  .tabbar svg { width: 20px; height: 20px; }

  .topbar { padding: 22px 32px 14px; }
  .topbar-inner { max-width: 1240px; }
  .view { max-width: 1240px; padding: 4px 32px 40px; }

  /* Diario: fascia di riepilogo e pasti in una colonna */
  /* Data al centro della colonna dei contenuti, frecce accanto */
  .view > .datenav { justify-content: center; gap: 14px; max-width: 1000px; }
  .view > .datenav .label { flex: none; text-align: center; min-width: 240px; }
  .view > .datenav .label strong { font-size: 19px; }
  .kpis { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
  .kpi {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 14px 16px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px; min-width: 0;
  }
  .kpi-k { font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 600; }
  .kpi-v { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; white-space: nowrap; }
  .kpi-v small { font-size: 14px; font-weight: 500; color: var(--ink-2); }
  .kpi-n { font-size: 13px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
  .kpi-n:empty { display: none; }
  .kpi-bar { height: 6px; border-radius: 3px; background: var(--surface-2); overflow: hidden; margin: 2px 0; }
  .kpi-bar span { display: block; height: 100%; border-radius: 3px; }
  .kpi-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; padding-top: 6px; }
  .btn.sm { padding: 5px 9px; font-size: 13px; border-radius: 8px; }
  .linkbtn { border: 0; background: none; padding: 0; color: var(--accent); font-size: 13px; cursor: pointer; text-align: left; }

  .meals-d { max-width: 1000px; }
  .meals-d .card { padding: 16px 18px; }
  .meals-d .slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
  .meals-d .slot { border: 0; background: var(--surface-2); border-radius: 10px; padding: 4px 12px 8px; }
  .meals-d .slot-head { padding: 8px 0 4px; font-size: 14px; }
  .meals-d .slot .meal-items { margin: 0; }
  .meals-d .slot .meal-items li { padding: 4px 6px; margin: 0 -6px; }
  .meals-d .slot .meal-items .kcal { font-size: 13px; }
  .meals-d .card { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; column-gap: 12px; }
  .meals-d .card > h2, .meals-d .card > .slots, .meals-d .card > .empty, .meals-d .card > .meal-items { grid-column: 1 / -1; }
  .meals-d .plan-note { margin-top: 10px; align-self: start; }
  .meals-d .meal-footer { grid-column: 2; margin-top: 10px; justify-content: flex-end; }
  .meals-d .meal-footer .btn { flex: none; padding: 6px 12px; font-size: 14px; }
  .meals-d .plan-note[open] { grid-column: 1 / -1; }
  .health-d { max-width: 1000px; }
  .health-row { display: flex; align-items: center; gap: 28px; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
  .health-row b { font-size: 18px; margin-left: 4px; }
  .health-actions { margin-left: auto; display: flex; gap: 8px; }

  /* Storico: grafici affiancati */
  .hist-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; align-items: start; }

  /* Piano: elenco pasti e dettaglio */
  .plan-grid { display: grid; grid-template-columns: 360px minmax(0, 1fr); gap: 24px; align-items: start; }
  .plan-list { position: sticky; top: 76px; }
  .plan-detail .datenav .iconbtn, .plan-detail .datenav > span { display: none; }
  .plan-detail .datenav { max-width: none; }
  .plan-detail .datenav .label { text-align: left; }
  .plan-detail .datenav .label strong { font-size: 22px; }
  .food-list li.selected { background: color-mix(in srgb, var(--accent) 10%, transparent); border-radius: 8px; }
  .food-list li { padding-left: 8px; padding-right: 8px; margin: 0 -8px; }
  .segmented { max-width: 360px; }

  /* Alimenti e impostazioni: su più colonne */
  .foods-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; align-items: start; }
  .settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; align-items: start; }
  .settings-grid > .card:first-child { grid-row: span 3; }

  /* Interazioni col mouse */
  .meal-items li:hover, .food-list li:hover, table.hist tbody tr:hover, .list-btn:hover { background: var(--surface-2); }
  .meal-items li, .list-btn { border-radius: 8px; }
  .btn:hover { filter: brightness(0.97); }

  /* Finestre al centro invece che dal basso */
  .sheet {
    left: 50%; right: auto; top: 50%; bottom: auto; transform: translate(-50%, -50%);
    width: min(580px, calc(100vw - 48px)); max-height: 86vh; border-radius: 18px;
    padding: 20px 24px 24px; animation: pop 0.18s ease-out; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
  }
  .sheet .grabber { display: none; }
  .sheet-search { top: -20px; }
  .kpis, .meals-d, .health-d { max-width: 1000px; }
  #toast { bottom: 28px; margin-left: 116px; }
}


@keyframes pop { from { opacity: 0; transform: translate(-50%, -48%) scale(0.98); } to { opacity: 1; transform: translate(-50%, -50%); } }
