/* ============ Design tokens ============
   Palette: "cantina" — pietra chiara / inchiostro con sfumatura oliva,
   accento oro-olio (EVO) e ruggine smorzata per gli scostamenti.
   Tipografia: system stack (SF Pro su iOS) — offline-first, nessun
   font esterno da scaricare, coerente con l'identità nativa iOS. */
:root {
  --ink: #171A16;
  --ink-soft: #454A41;
  --paper: #EEEDE4;
  --paper-dim: #E3E1D3;
  --card: #F7F6EF;
  --accent: #8A6A1F;
  --accent-soft: #EADFC2;
  --good: #5C6E43;
  --good-soft: #E3E9D8;
  --warn: #A2472F;
  --warn-soft: #F1DCD4;
  --line: rgba(23, 26, 22, 0.12);
  --line-strong: rgba(23, 26, 22, 0.22);
  --shadow: 0 1px 2px rgba(23,26,22,0.06);
  --radius: 14px;
  --radius-sm: 9px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #EDEBE0;
    --ink-soft: #B7B6A9;
    --paper: #15171A;
    --paper-dim: #1B1D20;
    --card: #1E2023;
    --accent: #D2AC55;
    --accent-soft: #3A331E;
    --good: #93AC77;
    --good-soft: #2A3324;
    --warn: #E08A6E;
    --warn-soft: #3B2621;
    --line: rgba(237, 235, 224, 0.10);
    --line-strong: rgba(237, 235, 224, 0.18);
    --shadow: 0 1px 2px rgba(0,0,0,0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font-family: inherit; }
h1, h2, h3, p { margin: 0; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100%;
  padding-bottom: calc(78px + var(--safe-bottom));
}

.screen { padding: calc(18px + var(--safe-top)) 20px 24px; animation: fadein .18s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px);} to { opacity: 1; transform: none; } }

.screen-title {
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.screen-sub { color: var(--ink-soft); font-size: 14px; margin-bottom: 20px; }

/* ---------- Bottom nav ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  display: flex;
  backdrop-filter: blur(20px) saturate(1.6);
  -webkit-backdrop-filter: blur(20px) saturate(1.6);
  background: color-mix(in srgb, var(--paper) 78%, transparent);
  border-top: 1px solid var(--line);
  padding: 8px 4px calc(6px + var(--safe-bottom));
  z-index: 40;
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: none; border: none; color: var(--ink-soft);
  padding: 4px 0; min-height: 44px;
  font-size: 11px; font-weight: 500;
}
.tab svg { width: 24px; height: 24px; }
.tab.active { color: var(--accent); }
.tab:active { transform: scale(0.94); }

/* ---------- Hero (Oggi) ---------- */
.day-banner {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-radius: var(--radius-sm);
  background: var(--card); border: 1px solid var(--line); margin-bottom: 18px;
  font-size: 13px;
}
.day-banner .pill { font-weight: 600; }
.pill-rest { color: var(--good); }
.pill-training { color: var(--accent); }

.hero { margin-bottom: 22px; }
.hero-num {
  font-size: 52px; font-weight: 700; letter-spacing: -0.03em; line-height: 1;
}
.hero-num small { font-size: 20px; font-weight: 500; color: var(--ink-soft); margin-left: 6px; }
.hero-label { color: var(--ink-soft); font-size: 14px; margin-top: 4px; }
.hero-bar { height: 4px; background: var(--line); border-radius: 3px; margin-top: 14px; overflow: hidden; }
.hero-bar-fill { height: 100%; background: var(--accent); border-radius: 3px; transition: width .3s ease; }
.hero-bar-fill.over { background: var(--warn); }
.macro-row { display: flex; gap: 18px; margin-top: 16px; }
.macro { flex: 1; }
.macro-val { font-size: 17px; font-weight: 600; }
.macro-label { font-size: 12px; color: var(--ink-soft); margin-top: 1px; }

/* ---------- Deviation prompt ---------- */
.deviation {
  background: var(--warn-soft); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 18px;
}
.deviation p { font-size: 14px; line-height: 1.4; }
.deviation .actions { display: flex; gap: 10px; margin-top: 10px; }

/* ---------- Meal timeline ---------- */
.timeline { position: relative; }
.meal-row {
  position: relative;
  display: flex; gap: 14px;
  padding: 16px 0;
  border-bottom: 1px solid var(--line);
}
.meal-row:last-child { border-bottom: none; }
.meal-dot-col { display: flex; flex-direction: column; align-items: center; width: 14px; flex-shrink: 0; padding-top: 3px; }
.meal-dot {
  width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--line-strong); background: var(--paper);
}
.meal-dot.done { background: var(--good); border-color: var(--good); }
.meal-dot.skipped { background: var(--paper); border-color: var(--warn); }
.meal-dot.modified { background: var(--accent); border-color: var(--accent); }
.meal-thread { flex: 1; width: 1.5px; background: var(--line); margin-top: 2px; }
.meal-body { flex: 1; min-width: 0; }
.meal-head { display: flex; justify-content: space-between; align-items: baseline; }
.meal-name { font-size: 16px; font-weight: 600; }
.meal-time { font-size: 12px; color: var(--ink-soft); }
.meal-kcal { font-size: 13px; color: var(--ink-soft); margin-top: 2px; }
.meal-items { margin-top: 6px; font-size: 13px; color: var(--ink-soft); line-height: 1.5; }
.meal-items .skipped-item { text-decoration: line-through; opacity: .55; }
.meal-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  border-radius: 999px; padding: 8px 14px; font-size: 13px; font-weight: 500;
  min-height: 36px; display: inline-flex; align-items: center; gap: 6px;
}
.btn:active { transform: scale(0.96); }
.btn-primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
@media (prefers-color-scheme: dark) { .btn-primary { background: var(--accent); color: #15171A; border-color: var(--accent); } }
.btn-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.btn-warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.btn-ghost { background: transparent; border-color: transparent; padding-left: 4px; padding-right: 4px; }
.btn-block { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 11px; font-size: 12px; min-height: 30px; }

/* ---------- Suggestion / What can I eat ---------- */
.suggest-cta {
  margin-top: 22px; padding: 16px; border-radius: var(--radius); background: var(--card);
  border: 1px solid var(--line); text-align: center;
}
.suggest-cta p { font-size: 13px; color: var(--ink-soft); margin-bottom: 10px; }

/* ---------- Sheet (bottom modal) ---------- */
.sheet-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0); z-index: 100;
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s ease, background .2s ease;
}
.sheet-overlay.open { opacity: 1; pointer-events: auto; background: rgba(10,10,8,0.4); }
.sheet {
  background: var(--paper); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; padding: 8px 20px calc(20px + var(--safe-bottom));
  max-height: 82vh; overflow-y: auto;
  transform: translateY(100%); transition: transform .26s cubic-bezier(.32,.72,0,1);
}
.sheet--tall { max-height: 90vh; }
.sheet-overlay.open .sheet { transform: translateY(0); }
.sheet-handle { width: 36px; height: 5px; background: var(--line-strong); border-radius: 3px; margin: 6px auto 14px; }
.sheet h3 { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.sheet .sheet-sub { color: var(--ink-soft); font-size: 13px; margin-bottom: 16px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; border: 1px solid var(--line-strong); background: var(--card); color: var(--ink);
  border-radius: var(--radius-sm); padding: 11px 12px; font-size: 16px; font-family: inherit;
}
.qty-stepper { display: flex; align-items: center; gap: 12px; }
.qty-stepper input { text-align: center; flex: 1; }
.qty-stepper button { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line-strong); background: var(--card); font-size: 18px; }

.alt-list { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.alt-item {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: 14px;
}
.alt-item span.name { flex: 1; }

/* ---------- Diary ---------- */
.diary-day {
  display: flex; justify-content: space-between; align-items: center;
  padding: 14px 0; border-bottom: 1px solid var(--line);
}
.diary-day-date { font-weight: 600; font-size: 15px; }
.diary-day-sub { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
.diary-day-kcal { font-size: 15px; font-weight: 600; }

/* ---------- Diet screen ---------- */
.day-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 18px; }
.day-tabs::-webkit-scrollbar { display: none; }
.day-tab {
  border: 1px solid var(--line-strong); border-radius: 999px; padding: 7px 13px; font-size: 13px; white-space: nowrap;
  background: var(--card); color: var(--ink-soft); flex-shrink: 0;
}
.day-tab.active { background: var(--ink); color: var(--paper); border-color: var(--ink); }
@media (prefers-color-scheme: dark) { .day-tab.active { background: var(--accent); color: #15171A; } }

.diet-meal { padding: 16px 0; border-bottom: 1px solid var(--line); }
.diet-meal-head { display: flex; justify-content: space-between; margin-bottom: 8px; }
.diet-meal-name { font-weight: 600; font-size: 15px; }
.diet-meal-kcal { color: var(--ink-soft); font-size: 13px; }
.diet-item-row { display: flex; justify-content: space-between; font-size: 13.5px; padding: 4px 0; }
.diet-item-row .qty { color: var(--ink-soft); }
.diet-alt-toggle { font-size: 12px; color: var(--accent); margin-top: 6px; }

.rel-dot { display: inline-block; width: 6px; height: 6px; border-radius: 50%; margin-right: 5px; vertical-align: middle; }
.dot-verified { background: var(--good); }
.dot-generic { background: var(--accent); }
.dot-uncertain { background: var(--warn); }

/* ---------- Progress ---------- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 22px; }
.stat-box { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat-box .val { font-size: 22px; font-weight: 700; }
.stat-box .lbl { font-size: 12px; color: var(--ink-soft); margin-top: 2px; }
canvas { width: 100%; height: 140px; display: block; }

/* ---------- More / list menu ---------- */
.menu-list { border-top: 1px solid var(--line); }
.menu-item {
  display: flex; align-items: center; justify-content: space-between; width: 100%;
  padding: 15px 2px; border-bottom: 1px solid var(--line); background: none; border-left: none; border-right: none; border-top: none;
  font-size: 15px; color: var(--ink); text-align: left;
}
.menu-item .chev { color: var(--ink-soft); }
.menu-item:active { opacity: .6; }
.section-label { font-size: 12px; text-transform: none; color: var(--ink-soft); margin: 22px 0 6px; font-weight: 500; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--ink-soft); }
.empty-state p { font-size: 14px; line-height: 1.5; }

#toast-host {
  position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom));
  transform: translate(-50%, 10px); background: var(--ink); color: var(--paper);
  padding: 10px 18px; border-radius: 999px; font-size: 13px; opacity: 0; pointer-events: none;
  transition: opacity .2s ease, transform .2s ease; z-index: 200; max-width: 80%; text-align: center;
}
#toast-host.show { opacity: 1; transform: translate(-50%, 0); }

.shopping-cat { margin-bottom: 20px; }
.shopping-cat h4 { font-size: 13px; color: var(--ink-soft); margin-bottom: 8px; font-weight: 500; }
.shopping-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 14.5px; }
.shopping-row .need { font-weight: 600; }
.shopping-row.satisfied .need { color: var(--good); }

.water-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

::selection { background: var(--accent-soft); }
