:root {
  --paper: #FBF8F2; --paper2: #F4EEE2; --card: #FFFFFF; --ink: #1F2A24; --ink2: #4A564F; --muted: #78837C;
  --line: #E6DFD1; --sage: #5E7D63; --sage-l: #E6EEE5; --terra: #C2643C; --terra-l: #F7E5DC;
  --ocre: #B4842A; --ocre-l: #F6ECD6; --blue: #3F6F8F; --blue-l: #E1EBF2;
  --ok: #4F8A5B; --warn: #C98A1B; --low: #C23B32; --vhigh: #8E1F1A;
  --serif: Georgia, "Lora", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --r: 18px; --shadow: 0 1px 2px rgba(31,42,36,.06), 0 4px 14px rgba(31,42,36,.05);
  --tabh: 68px; --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 17px/1.5 var(--sans); }
@media (min-width: 560px) { body { background: #EFE8DA; } }
h1, h2, h3, .serif { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; line-height: 1.2; margin: 0 0 .3rem; }
h2 { font-size: 1.3rem; line-height: 1.25; margin: 0 0 .6rem; }
h3 { font-size: 1.1rem; margin: 0 0 .4rem; }
p { margin: 0 0 .7rem; }
a { color: var(--blue); }
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .88rem; }
.center { text-align: center; }

#app { max-width: 520px; margin: 0 auto; min-height: 100vh; background: var(--paper); position: relative;
  padding-bottom: calc(var(--tabh) + var(--safe-b) + 16px); }
@media (min-width: 560px) { #app { box-shadow: 0 0 40px rgba(31,42,36,.08); } }

/* Header */
.top { position: sticky; top: 0; z-index: 20; background: rgba(251,248,242,.94); backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); display: flex; align-items: center;
  gap: 8px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); min-height: 60px; }
.top h1 { font-size: 1.25rem; margin: 0; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iconbtn { width: 44px; height: 44px; border-radius: 12px; border: 0; background: transparent; display: grid;
  place-items: center; cursor: pointer; color: var(--ink); flex: none; }
.iconbtn:active { background: var(--paper2); }
.iconbtn svg { width: 24px; height: 24px; }

main { padding: 16px; }
.view-enter { animation: fadeIn .22s ease-out; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* Tab bar */
.tabs { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 520px; z-index: 30;
  background: #fff; border-top: 1px solid var(--line); display: grid; grid-template-columns: repeat(5, 1fr);
  padding-bottom: var(--safe-b); box-shadow: 0 -4px 18px rgba(31,42,36,.05); }
.tabs button { border: 0; background: none; height: var(--tabh); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 3px; font-size: .78rem; color: var(--muted); cursor: pointer; font-weight: 500; }
.tabs button svg { width: 26px; height: 26px; }
.tabs button.on { color: var(--sage); font-weight: 700; }
.tabs button.on svg { stroke-width: 2.2; }

/* Cards */
.card { background: var(--card); border-radius: var(--r); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; border: 1px solid #EFE9DD; }
.card.tint-sage { background: var(--sage-l); border-color: transparent; }
.card.tint-terra { background: var(--terra-l); border-color: transparent; }
.card.tint-ocre { background: var(--ocre-l); border-color: transparent; }
.card.tint-blue { background: var(--blue-l); border-color: transparent; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.card-h h2, .card-h h3 { margin: 0; }
.eyebrow { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; margin-bottom: 4px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--card); border-radius: 16px; padding: 12px; border: 1px solid #EFE9DD; box-shadow: var(--shadow); }
.stat .v { font-family: var(--serif); font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat .l { font-size: .82rem; color: var(--muted); line-height: 1.3; margin-top: 2px; }
.stat .u { font-size: .85rem; font-weight: 500; color: var(--muted); font-family: var(--sans); }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 20px;
  border-radius: 14px; border: 0; background: var(--sage); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: transform .08s, filter .15s; font-size: 1rem; }
.btn:active { transform: scale(.98); filter: brightness(.95); }
.btn.block { width: 100%; }
.btn.terra { background: var(--terra); } .btn.blue { background: var(--blue); } .btn.ocre { background: var(--ocre); }
.btn.ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn.danger { background: var(--low); }
.btn.sm { min-height: 44px; padding: 0 14px; font-size: .92rem; border-radius: 12px; }
.btn svg { width: 20px; height: 20px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }
.fab { position: fixed; z-index: 25; right: max(16px, calc(50% - 260px + 16px)); bottom: calc(var(--tabh) + var(--safe-b) + 16px);
  width: 60px; height: 60px; border-radius: 50%; border: 0; background: var(--terra); color: #fff; box-shadow: 0 8px 22px rgba(194,100,60,.35);
  display: grid; place-items: center; cursor: pointer; }
.fab svg { width: 30px; height: 30px; }

/* Forms */
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-weight: 600; font-size: .95rem; margin-bottom: 6px; }
.inp, select.inp, textarea.inp { width: 100%; min-height: 50px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
  padding: 10px 14px; font-size: 1.05rem; outline: none; -webkit-appearance: none; appearance: none; }
select.inp { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2378837C' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 40px; }
textarea.inp { min-height: 90px; resize: vertical; line-height: 1.45; }
.inp:focus { border-color: var(--sage); box-shadow: 0 0 0 3px rgba(94,125,99,.18); }
.inp.big { font-size: 2rem; font-family: var(--serif); text-align: center; font-weight: 700; min-height: 70px; }
.err { color: var(--low); font-size: .9rem; margin-top: 6px; font-weight: 600; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 44px; padding: 8px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; cursor: pointer;
  font-size: .95rem; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; }
.chip.on { background: var(--sage); border-color: var(--sage); color: #fff; }
.seg { display: flex; background: var(--paper2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; min-height: 42px; border: 0; background: transparent; border-radius: 9px; cursor: pointer; font-weight: 600; color: var(--ink2); }
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.08); }

/* Status */
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.st-ok { --c: var(--ok); } .st-alto { --c: var(--warn); } .st-sotto { --c: var(--warn); } .st-basso { --c: var(--low); } .st-moltoalto { --c: var(--vhigh); }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .82rem; font-weight: 700;
  background: color-mix(in srgb, var(--c) 14%, white); color: var(--c); }
.badge .dot { background: var(--c); width: 8px; height: 8px; }
.bigread { display: flex; align-items: center; gap: 16px; }
.bigread .num { font-family: var(--serif); font-size: 3rem; font-weight: 700; line-height: 1; color: var(--c); }
.bigread .num small { font-size: 1rem; font-family: var(--sans); color: var(--muted); font-weight: 500; }

/* Lists */
.list { list-style: none; margin: 0; padding: 0; }
.li { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.li:last-child { border-bottom: 0; }
.li .main { flex: 1; min-width: 0; }
.li .t { font-weight: 600; }
.li .s { font-size: .88rem; color: var(--muted); }
.reading-v { font-family: var(--serif); font-size: 1.5rem; font-weight: 700; color: var(--c); min-width: 64px; text-align: right; }
.day-sep { font-size: .82rem; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 14px 0 0; }

/* Checklist */
.check { display: flex; align-items: center; gap: 14px; min-height: 52px; padding: 8px 4px; cursor: pointer; border-bottom: 1px solid var(--line); user-select: none; }
.check:last-child { border-bottom: 0; }
.check .box { width: 30px; height: 30px; border-radius: 9px; border: 2px solid #CFC6B4; flex: none; display: grid; place-items: center; background: #fff; transition: all .15s; }
.check .box svg { width: 18px; height: 18px; color: #fff; opacity: 0; transform: scale(.6); transition: all .15s; }
.check.on .box { background: var(--sage); border-color: var(--sage); }
.check.on .box svg { opacity: 1; transform: none; }
.check.on .lbl { color: var(--muted); text-decoration: line-through; text-decoration-color: rgba(0,0,0,.25); }
.check .lbl { flex: 1; }
.check .x { width: 40px; height: 40px; border: 0; background: none; color: var(--muted); border-radius: 10px; cursor: pointer; font-size: 1.3rem; }

/* Progress */
.bar { height: 10px; background: var(--paper2); border-radius: 999px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--sage); border-radius: 999px; transition: width .4s; }
.ring { position: relative; display: inline-grid; place-items: center; }
.ring svg { transform: rotate(-90deg); }
.ring .lbl { position: absolute; text-align: center; line-height: 1.1; }
.ring .lbl b { font-family: var(--serif); font-size: 1.5rem; display: block; }

/* Altro grid */
.menu-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tile { background: #fff; border: 1px solid #EFE9DD; border-radius: 16px; padding: 14px 8px; min-height: 104px; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-align: center; font-size: .88rem; font-weight: 600; box-shadow: var(--shadow); color: var(--ink); }
.tile:active { transform: scale(.98); }
.tile .ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; }
.tile .ic svg { width: 26px; height: 26px; }
.c-sage { background: var(--sage-l); color: var(--sage); } .c-terra { background: var(--terra-l); color: var(--terra); }
.c-ocre { background: var(--ocre-l); color: var(--ocre); } .c-blue { background: var(--blue-l); color: var(--blue); }

/* Modal / sheet */
.backdrop { position: fixed; inset: 0; background: rgba(31,42,36,.45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .2s; }
@keyframes fade { from { opacity: 0; } }
.sheet { background: var(--paper); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 20px 18px calc(20px + var(--safe-b));
  animation: up .25s ease-out; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }
@media (min-width: 560px) { .backdrop { align-items: center; } .sheet { border-radius: 22px; } }
.sheet .grab { width: 44px; height: 5px; background: #D8D0C0; border-radius: 9px; margin: -8px auto 14px; }
.alert-box { border-radius: 16px; padding: 16px; margin-bottom: 14px; }
.alert-box.low { background: #FBE4E1; border: 2px solid var(--low); }
.alert-box.high { background: var(--ocre-l); border: 2px solid var(--ocre); }
.alert-box ol { margin: 8px 0 0; padding-left: 22px; } .alert-box li { margin-bottom: 6px; }

/* Toast */
#toast { position: fixed; left: 50%; transform: translateX(-50%); top: calc(14px + env(safe-area-inset-top, 0px)); z-index: 80; display: flex; flex-direction: column; gap: 8px; width: calc(100% - 32px); max-width: 480px; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.2); display: flex; align-items: center; gap: 12px; animation: toastIn .3s; font-weight: 500; }
.toast.medal { background: #fff; color: var(--ink); border: 2px solid var(--ocre); }
.toast svg { width: 44px; height: 44px; flex: none; }
@keyframes toastIn { from { transform: translateY(-16px); opacity: 0; } }

/* Chart */
.chart { width: 100%; height: auto; display: block; }
.chart text { font-family: var(--sans); font-size: 11px; fill: var(--muted); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: .82rem; color: var(--muted); margin-top: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }

/* Table */
.tbl { width: 100%; border-collapse: collapse; font-size: .93rem; }
.tbl th, .tbl td { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.tbl th { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.tbl td.n, .tbl th.n { text-align: right; font-variant-numeric: tabular-nums; }

/* Plate */
.plate-wrap { display: flex; gap: 16px; align-items: center; }
.plate-wrap svg { width: 150px; height: 150px; flex: none; }
.food-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.food-row .main { flex: 1; min-width: 0; }
.stepper { display: flex; align-items: center; gap: 4px; }
.stepper button { width: 40px; height: 40px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; font-size: 1.2rem; cursor: pointer; }
.stepper input { width: 64px; text-align: center; min-height: 40px; border: 1.5px solid var(--line); border-radius: 10px; font-size: 1rem; }
.semaforo { border-radius: 16px; padding: 14px; display: flex; gap: 12px; align-items: flex-start; }
.semaforo.ok { background: var(--sage-l); } .semaforo.medio { background: var(--ocre-l); } .semaforo.alto { background: var(--terra-l); }
.semaforo .lights { display: flex; flex-direction: column; gap: 4px; background: var(--ink); padding: 6px; border-radius: 10px; flex: none; }
.semaforo .lights i { width: 14px; height: 14px; border-radius: 50%; background: #3a453f; display: block; }
.semaforo.alto .lights i:nth-child(1) { background: #E2553F; } .semaforo.medio .lights i:nth-child(2) { background: #E8B23A; } .semaforo.ok .lights i:nth-child(3) { background: #6DBA78; }
.search { position: relative; }
.food-pick { max-height: 46vh; overflow: auto; border: 1px solid var(--line); border-radius: 14px; background: #fff; margin-top: 8px; }
.food-pick .grp { position: sticky; top: 0; background: var(--paper2); padding: 6px 12px; font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); }
.food-pick button { display: flex; width: 100%; text-align: left; border: 0; background: #fff; padding: 12px; min-height: 48px; border-bottom: 1px solid #F2ECE0; cursor: pointer; gap: 8px; }
.food-pick button:active { background: var(--sage-l); }
.food-pick button .m { flex: 1; }

/* Program */
.weekbar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin: 10px 0; }
.daydot { aspect-ratio: 1; border-radius: 12px; border: 2px solid var(--line); background: #fff; display: grid; place-items: center; font-weight: 700; font-size: .95rem; cursor: pointer; color: var(--ink2); min-height: 40px; }
.daydot.on { background: var(--sage); border-color: var(--sage); color: #fff; }
.daydot.today { border-color: var(--terra); box-shadow: 0 0 0 3px rgba(194,100,60,.18); }
.week-tag { display: inline-block; font-size: .78rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--terra-l); color: var(--terra); }

/* Heatmap */
.heat { display: grid; grid-template-columns: repeat(10, 1fr); gap: 5px; }
.heat i { aspect-ratio: 1; border-radius: 6px; background: var(--paper2); display: block; }
.heat i.today { outline: 2px solid var(--terra); outline-offset: 1px; }

/* Mood */
.moods { display: flex; justify-content: space-between; gap: 6px; }
.mood { flex: 1; border: 2px solid transparent; background: #fff; border-radius: 14px; padding: 8px 2px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: .72rem; color: var(--muted); }
.mood svg { width: 42px; height: 42px; }
.mood.on { border-color: var(--sage); background: var(--sage-l); color: var(--ink); font-weight: 700; }
.energy { display: flex; gap: 8px; }
.energy button { flex: 1; min-height: 46px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-weight: 700; cursor: pointer; }
.energy button.on { background: var(--ocre); border-color: var(--ocre); color: #fff; }

/* Quiz */
.opt { display: block; width: 100%; text-align: left; padding: 14px 16px; min-height: 54px; border-radius: 14px; border: 2px solid var(--line); background: #fff; margin-bottom: 10px; cursor: pointer; font-size: 1rem; line-height: 1.35; }
.opt.right { border-color: var(--ok); background: var(--sage-l); }
.opt.wrong { border-color: var(--low); background: #FBE4E1; }
.opt:disabled { cursor: default; color: var(--ink); }

/* Wheel */
.wheel-box { position: relative; width: min(84vw, 340px); margin: 6px auto 12px; }
.wheel-box svg.w { width: 100%; height: auto; display: block; transition: transform 4.2s cubic-bezier(.17,.67,.12,1); }
.wheel-pointer { position: absolute; top: -6px; left: 50%; transform: translateX(-50%); width: 34px; height: 40px; z-index: 2; filter: drop-shadow(0 2px 3px rgba(0,0,0,.25)); }

/* Medals */
.medals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.medal { text-align: center; padding: 10px 4px; border-radius: 16px; background: #fff; border: 1px solid #EFE9DD; }
.medal svg { width: 72px; height: 72px; }
.medal .t { font-size: .82rem; font-weight: 700; line-height: 1.2; margin-top: 4px; }
.medal .d { font-size: .72rem; color: var(--muted); line-height: 1.25; margin-top: 2px; }
.medal.locked svg { filter: grayscale(1); opacity: .35; }
.medal.locked .t { color: var(--muted); }

/* Book */
.tomo-card { display: flex; gap: 14px; align-items: center; cursor: pointer; }
.tomo-num { width: 52px; height: 64px; border-radius: 8px 12px 12px 8px; display: grid; place-items: center; color: #fff; font-family: var(--serif); font-size: 1.5rem; font-weight: 700; flex: none; box-shadow: inset 5px 0 0 rgba(0,0,0,.12); }
.chapter { border-left: 4px solid var(--sage); padding: 4px 0 4px 14px; margin: 18px 0; }
.chapter .num { font-family: var(--serif); color: var(--terra); font-weight: 700; font-size: .95rem; }
.chapter ul, .card ul.pts { margin: 8px 0 0; padding-left: 20px; } .chapter li, .card ul.pts li { margin-bottom: 4px; }
.prose { font-size: 1.02rem; line-height: 1.6; }

/* Onboarding */
.onb { min-height: 100vh; padding: 28px 20px 40px; display: flex; flex-direction: column; }
.onb .logo { width: 84px; height: 84px; margin: 10px 0 18px; }
.onb h1 { font-size: 2rem; }
.privacy { display: flex; gap: 12px; align-items: flex-start; background: var(--sage-l); border-radius: 14px; padding: 14px; font-size: .95rem; }
.privacy svg { width: 26px; height: 26px; color: var(--sage); flex: none; margin-top: 2px; }
.steps-ind { display: flex; gap: 6px; margin-bottom: 18px; }
.steps-ind i { flex: 1; height: 5px; border-radius: 9px; background: var(--line); }
.steps-ind i.on { background: var(--sage); }
.disclaimer { font-size: .85rem; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; margin-top: 8px; }

/* Shopping */
.shop-grp h3 { font-family: var(--sans); font-size: .82rem; text-transform: uppercase; letter-spacing: .07em; color: var(--sage); margin: 16px 0 2px; }
.plan-day { display: grid; grid-template-columns: 54px 1fr; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.plan-day .d { font-weight: 700; font-family: var(--serif); }
.plan-day select { min-height: 44px; font-size: .92rem; padding: 6px 34px 6px 10px; }
.plan-slots { display: grid; gap: 6px; }

/* Print */
#print-area { display: none; }
@media print {
  @page { size: A4; margin: 14mm; }
  body { background: #fff !important; font-size: 11pt; }
  #app, .tabs, .fab, #toast, .backdrop { display: none !important; }
  #print-area { display: block !important; color: #000; }
  #print-area h1 { font-size: 20pt; margin-bottom: 4pt; }
  #print-area h2 { font-size: 13pt; margin: 14pt 0 6pt; color: #3F5A44; border-bottom: 1px solid #ccc; padding-bottom: 3pt; }
  #print-area .tbl { font-size: 9.5pt; } #print-area .tbl th, #print-area .tbl td { padding: 3pt 4pt; }
  #print-area .kpis { display: flex; gap: 8pt; } #print-area .kpis div { flex: 1; border: 1px solid #ccc; border-radius: 6pt; padding: 6pt; }
  #print-area .kpis b { font-size: 15pt; display: block; }
  #print-area tr { page-break-inside: avoid; }
}
