/* ============================================================
   MasterChef — palette arancio + bianco
   ============================================================ */
:root {
  --orange: #f07326;
  --orange-dark: #d75c14;
  --orange-deep: #a8410a;
  --orange-100: #fde3cf;
  --orange-50: #fff3e9;

  --white: #ffffff;
  --bg: #fbf7f3;
  --line: #efe4da;
  --line-strong: #e2d3c6;

  --ink: #241a13;
  --muted: #83705f;
  --green: #3f7d58;
  --danger: #c4392b;

  --radius: 16px;
  --radius-sm: 11px;
  --tap: 44px;
  --shadow-sm: 0 1px 2px rgba(70, 42, 20, .05), 0 4px 12px rgba(70, 42, 20, .05);
  --shadow-fab: 0 6px 18px rgba(240, 115, 38, .38);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --gut: 16px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, p, ul, figure { margin: 0; }
ul { list-style: none; padding: 0; }
button, input { font: inherit; color: inherit; }

.view { min-height: 100dvh; display: flex; flex-direction: column; }

.page {
  flex: 1;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 18px calc(var(--gut) + var(--safe-r)) calc(96px + var(--safe-b)) calc(var(--gut) + var(--safe-l));
}
.page--week { padding-bottom: calc(112px + var(--safe-b)); }
/* In sola lettura non c'è la barra di salvataggio: niente spazio da lasciare. */
.is-lettura .page--week { padding-bottom: calc(28px + var(--safe-b)); }

/* ---------------- Schermata di accesso ---------------- */
.view--lock {
  justify-content: center;
  padding: 24px calc(var(--gut) + var(--safe-r)) 24px calc(var(--gut) + var(--safe-l));
}

.lock {
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  text-align: center;
}

.lock__mark {
  display: grid;
  place-items: center;
  width: 68px;
  height: 68px;
  margin: 0 auto 18px;
  border-radius: 22px;
  background: var(--orange);
  color: var(--white);
}
.lock__mark svg { width: 34px; height: 34px; }

.lock__title { font-size: 26px; font-weight: 800; letter-spacing: -.02em; }
.lock__text { margin-top: 8px; font-size: 15px; line-height: 1.45; color: var(--muted); }

.lock__form { display: grid; gap: 10px; margin-top: 22px; }

.lock__input {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--white);
  font-size: 16px;
  text-align: center;
  letter-spacing: .08em;
}
.lock__input:focus { outline: 2px solid var(--orange); outline-offset: -1px; }

.lock__error { margin-top: 12px; font-size: 14px; color: var(--danger); }

/* ---------------- App bar ---------------- */
.app-bar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + var(--safe-t)) calc(var(--gut) + var(--safe-r)) 14px calc(var(--gut) + var(--safe-l));
  background: var(--orange);
  color: var(--white);
}

.app-bar--week { position: static; background: var(--white); color: var(--ink); }

/* Barra + giorni: un unico blocco sticky, così non servono offset a mano. */
.week-head {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--white);
  border-bottom: 1px solid var(--line);
}

.mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  border-radius: 12px;
  background: rgba(255, 255, 255, .18);
}
.mark svg { width: 22px; height: 22px; }

.app-bar__text { flex: 1; min-width: 0; }

.app-bar__title {
  font-size: 21px;
  font-weight: 800;
  letter-spacing: -.015em;
}
.app-bar__title--sm {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-bar__sub {
  font-size: 13px;
  opacity: .85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.app-bar--week .app-bar__sub { color: var(--muted); opacity: 1; }

.icon-btn {
  display: grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  flex: 0 0 auto;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.icon-btn svg { width: 22px; height: 22px; }
.icon-btn:active { background: rgba(0, 0, 0, .06); }
.icon-btn--danger { color: var(--danger); }

/* ---------------- Home: elenco settimane ---------------- */
.weeks { display: grid; gap: 12px; }

.week-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.week-card__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 8px 14px 16px;
}

/* Settimane già passate: stesso layout, tono più spento. */
.week-card--passata {
  background: #f5efe9;
  border-color: var(--line);
  box-shadow: none;
}
.week-card--passata .week-card__date { background: #eae0d7; color: var(--muted); }
.week-card--passata .week-card__title { color: var(--muted); font-weight: 600; }
.week-card--passata .week-card__toggle { color: var(--muted); }
.week-card--passata .week-card__shop { background: #efe7e0; }
.week-card--passata .week-card__shop li::before { background: var(--line-strong); }

.week-card__main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
}

.week-card__date {
  flex: 0 0 auto;
  width: 48px;
  height: 52px;
  display: grid;
  place-content: center;
  gap: 1px;
  border-radius: 12px;
  background: var(--orange-50);
  color: var(--orange-deep);
  text-align: center;
}
.week-card__day { font-size: 19px; font-weight: 800; line-height: 1; }
.week-card__mon { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; }

.week-card__body { min-width: 0; }

.week-card__title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.3;
}

/* Riga "cose da comprare": apre la lista senza entrare nella settimana */
.week-card__toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 42px;
  padding: 0 14px 12px 16px;
  border: 0;
  background: none;
  color: var(--orange-deep);
  font: 600 13.5px/1.3 inherit;
  text-align: left;
  cursor: pointer;
}
.week-card__toggle svg { width: 16px; height: 16px; }
.week-card__toggle .ico { flex: 0 0 auto; }
.week-card__toggle-label { flex: 1; min-width: 0; }

.week-card__chev { color: var(--muted); transition: transform .18s; }
.week-card__toggle[aria-expanded="true"] .week-card__chev { transform: rotate(180deg); }

.week-card__shop {
  display: grid;
  gap: 8px;
  margin: 0 14px 14px 16px;
  padding: 12px 14px;
  background: var(--orange-50);
  border-radius: var(--radius-sm);
}
.week-card__shop li {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14.5px;
}
.week-card__shop li::before {
  content: "";
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
}
.week-card__shop li.is-done { color: var(--muted); }
.week-card__shop li.is-done::before { background: var(--line-strong); }
.week-card__shop li.is-done span { text-decoration: line-through; }

.pill-now {
  display: inline-block;
  margin-bottom: 4px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--orange);
  color: var(--white);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ---------------- Empty state ---------------- */
.empty { padding: 48px 20px; text-align: center; }
.empty__icon {
  width: 76px;
  height: 76px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 24px;
  background: var(--orange-50);
  color: var(--orange);
}
.empty__icon svg { width: 38px; height: 38px; }
.empty__title { font-size: 18px; font-weight: 700; }
.empty__text { margin-top: 6px; font-size: 15px; color: var(--muted); }

/* ---------------- FAB ---------------- */
.fab {
  position: fixed;
  right: calc(18px + var(--safe-r));
  bottom: calc(22px + var(--safe-b));
  z-index: 30;
  width: 60px;
  height: 60px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--orange);
  color: var(--white);
  box-shadow: var(--shadow-fab);
  cursor: pointer;
  transition: transform .12s;
}
.fab svg { width: 28px; height: 28px; }
.fab:active { transform: scale(.93); background: var(--orange-dark); }

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--orange);
  color: var(--white);
  font-size: 11px;
  font-weight: 800;
  line-height: 1;
}

/* ---------------- Day pills ---------------- */
.days {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 4px calc(var(--gut) + var(--safe-r)) 12px calc(var(--gut) + var(--safe-l));
}
.days::-webkit-scrollbar { display: none; }

.day-pill {
  flex: 0 0 auto;
  min-width: 58px;
  min-height: var(--tap);
  padding: 5px 11px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--white);
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  transition: transform .1s;
}
.day-pill:active { transform: scale(.96); }
.day-pill__name { display: block; font-size: 13px; font-weight: 700; }
.day-pill__date { display: block; font-size: 11px; color: var(--muted); }
.day-pill__dot {
  display: block;
  width: 5px;
  height: 5px;
  margin: 3px auto 0;
  border-radius: 50%;
  background: var(--orange);
}

.day-pill[aria-selected="true"] {
  background: var(--orange);
  border-color: var(--orange);
  color: var(--white);
}
.day-pill[aria-selected="true"] .day-pill__date { color: rgba(255, 255, 255, .82); }
.day-pill[aria-selected="true"] .day-pill__dot { background: var(--white); }
.day-pill--today:not([aria-selected="true"]) { border-color: var(--orange); color: var(--orange-deep); }

.day-pill:disabled {
  background: var(--bg);
  border-color: var(--line);
  color: #b6a294;
  cursor: default;
}
.day-pill:disabled .day-pill__date { color: #c7b6a8; }
.day-pill:disabled:active { transform: none; }

/* ---------------- Meal cards ---------------- */
.day-title {
  margin-bottom: 12px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.01em;
}
.day-title span { font-size: 14px; font-weight: 400; color: var(--muted); }

.meal {
  margin-bottom: 14px;
  padding: 14px 14px 10px;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.meal__head { display: flex; align-items: center; gap: 9px; margin-bottom: 8px; }

.meal__icon { display: block; flex: 0 0 auto; }
.meal__icon svg { display: block; width: 24px; height: 24px; }
.meal__icon--pranzo { color: var(--orange); }
.meal__icon--cena { color: var(--orange-deep); }
.meal__title {
  font-size: 12px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}
.meal__count { margin-left: auto; font-size: 12px; color: var(--muted); }

/* Righe in sola lettura */
.dish-lettura {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
  font-size: 16px;
}
.dish-lettura:first-of-type { border-top: 0; }
.dish-lettura::before {
  content: "";
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--orange);
}

.meal__empty {
  padding: 4px 0 6px;
  font-size: 15px;
  font-style: italic;
  color: var(--muted);
}

.check--statico { cursor: default; }

.shop__testo {
  flex: 1;
  min-width: 0;
  padding: 11px 0;
  font-size: 16px;
}
.shop__row.is-done .shop__testo { color: var(--muted); text-decoration: line-through; }

.dish-row {
  display: flex;
  align-items: center;
  gap: 6px;
  border-top: 1px solid var(--line);
}
.dish-row:first-child { border-top: 0; }

.dish-row__input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 6px 2px;
  border: 0;
  background: transparent;
  font-size: 16px;
}
.dish-row__input:focus { outline: 0; }
.dish-row__input::placeholder { color: #bda893; }

.row-del {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #b9a390;
  cursor: pointer;
}
.row-del svg { width: 17px; height: 17px; }
.row-del:active { background: var(--orange-50); color: var(--danger); }

.add-dish {
  display: flex;
  align-items: center;
  gap: 7px;
  width: 100%;
  min-height: 42px;
  margin-top: 2px;
  padding: 0;
  border: 0;
  border-top: 1px solid var(--line);
  background: none;
  color: var(--orange-deep);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.add-dish svg { width: 17px; height: 17px; }

/* ---------------- Lista della spesa ---------------- */
.shop-block {
  margin-top: 26px;
  padding-top: 22px;
  border-top: 1px solid var(--line-strong);
}

.block-title {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.01em;
}

/* Intestazione cliccabile: apre e chiude la lista */
.block-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: var(--tap);
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}
.block-toggle__label { flex: 0 0 auto; }

.block-title__icon { display: block; color: var(--orange); }
.block-title__icon svg { display: block; width: 22px; height: 22px; }
.block-title .badge { margin-left: -2px; }

.block-chev {
  margin-left: auto;
  color: var(--muted);
  transition: transform .18s;
}
.block-chev svg { display: block; width: 20px; height: 20px; }
.block-toggle[aria-expanded="true"] .block-chev { transform: rotate(180deg); }

.block-sub {
  margin: 2px 0 14px;
  font-size: 13.5px;
  color: var(--muted);
}

.add-row {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.add-row__input {
  flex: 1;
  min-width: 0;
  min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--white);
  font-size: 16px;
}
.add-row__input:focus { outline: 2px solid var(--orange); outline-offset: -1px; }
.add-row__btn {
  flex: 0 0 auto;
  width: var(--tap);
  height: var(--tap);
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: var(--orange);
  color: var(--white);
  cursor: pointer;
}
.add-row__btn svg { width: 22px; height: 22px; }
.add-row__btn:active { background: var(--orange-dark); }

.shop {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.shop:empty { display: none; }

.shop__row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 12px;
  border-top: 1px solid var(--line);
}
.shop__row:first-child { border-top: 0; }

.check {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 2px solid var(--line-strong);
  border-radius: 8px;
  background: var(--white);
  color: transparent;
  cursor: pointer;
}
.check svg { width: 14px; height: 14px; }
.shop__row.is-done .check { background: var(--green); border-color: var(--green); color: var(--white); }

.shop__input {
  flex: 1;
  min-width: 0;
  min-height: 42px;
  padding: 6px 0;
  border: 0;
  background: transparent;
  font-size: 16px;
}
.shop__input:focus { outline: 0; }
.shop__row.is-done .shop__input { color: var(--muted); text-decoration: line-through; }

.shop__empty { padding: 26px 0; text-align: center; color: var(--muted); font-size: 15px; }

/* ---------------- Bottoni ---------------- */
.btn {
  min-height: var(--tap);
  padding: 11px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--white);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s;
}
.btn:active { transform: scale(.98); }
.btn--primary { background: var(--orange); border-color: var(--orange); color: var(--white); }
.btn--primary:active { background: var(--orange-dark); }
.btn--wide { display: block; width: 100%; }
.btn--quiet {
  display: block;
  margin: 16px auto 0;
  border-color: transparent;
  background: transparent;
  color: var(--danger);
  font-weight: 600;
}

.bottom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 25;
  padding: 12px calc(var(--gut) + var(--safe-r)) calc(12px + var(--safe-b)) calc(var(--gut) + var(--safe-l));
  background: linear-gradient(to top, var(--bg) 68%, rgba(251, 247, 243, 0));
}
.bottom-bar .btn { max-width: 720px; margin: 0 auto; }

/* ---------------- Calendario ---------------- */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(36, 26, 19, .45);
  animation: fade .18s ease-out;
}

.sheet {
  width: 100%;
  max-width: 460px;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 8px calc(var(--gut) + var(--safe-r)) calc(20px + var(--safe-b)) calc(var(--gut) + var(--safe-l));
  background: var(--white);
  border-radius: 22px 22px 0 0;
  animation: rise .22s ease-out;
}

.sheet__grab {
  width: 40px;
  height: 4px;
  margin: 4px auto 10px;
  border-radius: 999px;
  background: var(--line-strong);
}
.sheet__head { display: flex; align-items: center; gap: 8px; }
.sheet__title { flex: 1; font-size: 18px; font-weight: 800; }
.sheet__hint { margin: 2px 0 14px; font-size: 13.5px; color: var(--muted); }

.cal__nav { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; }
.cal__month {
  flex: 1;
  text-align: center;
  font-size: 16px;
  font-weight: 700;
  text-transform: capitalize;
}

.cal__weekdays, .cal__grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.cal__weekdays {
  margin-bottom: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-align: center;
}

.cal__day {
  aspect-ratio: 1;
  min-height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.cal__day--out { color: #c8b6a6; font-weight: 400; }
.cal__day--today { box-shadow: inset 0 0 0 2px var(--orange); color: var(--orange-deep); }
.cal__day--saved { background: var(--orange-50); color: var(--orange-deep); }
.cal__day:active { background: var(--orange); color: var(--white); }
.cal__row-hi { background: var(--orange-100); }

/* ---------------- Dialogo ---------------- */
.dialog-backdrop { align-items: center; padding: 20px; }

.dialog {
  width: 100%;
  max-width: 360px;
  padding: 26px 22px 20px;
  background: var(--white);
  border-radius: 22px;
  text-align: center;
  animation: pop .2s ease-out;
}

.dialog__icon {
  width: 62px;
  height: 62px;
  margin: 0 auto 14px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: var(--orange-50);
  color: var(--orange);
}
.dialog__icon svg { width: 30px; height: 30px; }

.dialog__title { font-size: 18px; font-weight: 800; letter-spacing: -.01em; }
.dialog__text { margin-top: 7px; font-size: 14.5px; line-height: 1.45; color: var(--muted); }

.dialog__actions { display: grid; gap: 8px; margin-top: 20px; }
.dialog__actions .btn { width: 100%; margin: 0; }

/* Wrapper delle icone inline */
.ico { display: inline-flex; }
.ico svg { display: block; }

@keyframes pop { from { transform: scale(.94); opacity: 0; } }

/* ---------------- Toast ---------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  z-index: 60;
  max-width: min(92vw, 420px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--white);
  font-size: 14px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

@keyframes fade { from { opacity: 0; } }
@keyframes rise { from { transform: translateY(18px); } }

/* ---------------- Schermi larghi ---------------- */
@media (min-width: 720px) {
  .app-bar__title { font-size: 24px; }
  .sheet { align-self: center; border-radius: 22px; margin-bottom: 5dvh; }
  .sheet-backdrop { align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
  *, .sheet, .sheet-backdrop { animation: none !important; transition: none !important; }
}
