/* ============ Base / tema (mobile-first) ============
   Palette 60-30-10:
   60%  #F7F8F8  superfici / sfondo (neutro dominante)
   30%  #F0072E  brand (topbar, azioni, totali, accenti)
   10%  antracite  testo e dettagli scuri
*/
:root {
  --bg: #f7f8f8;
  --surface: #ffffff;
  --surface-2: #f0f1f2;
  --border: #e3e5e7;

  --text: #1c1f22; /* antracite */
  --muted: #6a7075;

  --brand: #f0072e;
  --brand-press: #c80626;
  --brand-tint: rgba(240, 7, 46, 0.1);
  --on-brand: #ffffff;

  --danger: #c80626;
  --shadow: 0 1px 2px rgba(28, 31, 34, 0.06), 0 1px 3px rgba(28, 31, 34, 0.08);
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 16px;
  overflow-x: hidden;
}

/* ============ Topbar (brand, sticky) ============ */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--brand);
  color: var(--on-brand);
  padding: calc(var(--safe-top) + 12px) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  box-shadow: 0 1px 4px rgba(240, 7, 46, 0.25);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar .right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.user {
  color: rgba(255, 255, 255, 0.85);
  font-size: 0.8rem;
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.back {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  margin-left: -6px;
  border-radius: 10px;
  color: var(--on-brand);
  text-decoration: none;
  font-size: 1.4rem;
}

.back:active {
  background: rgba(255, 255, 255, 0.18);
}

button.link {
  min-height: 40px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.5);
  color: var(--on-brand);
  font-size: 0.85rem;
  font-weight: 550;
  border-radius: 10px;
  cursor: pointer;
}

button.link:active {
  background: rgba(255, 255, 255, 0.28);
}

/* ---- Burger + menu a scomparsa ---- */
.menu-btn {
  width: 40px;
  height: 40px;
  margin-left: -6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--on-brand);
  cursor: pointer;
  border-radius: 10px;
}

.menu-btn:active {
  background: rgba(255, 255, 255, 0.18);
}

.burger,
.burger::before,
.burger::after {
  content: "";
  display: block;
  width: 20px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
}

.burger {
  position: relative;
}

.burger::before {
  position: absolute;
  left: 0;
  top: -6px;
}

.burger::after {
  position: absolute;
  left: 0;
  top: 6px;
}

.menu-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 22, 25, 0.45);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s ease;
  z-index: 20;
}

.menu-open .menu-overlay {
  opacity: 1;
  visibility: visible;
}

.menu-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 78%;
  max-width: 300px;
  background: var(--surface);
  z-index: 21;
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 18px) 0 calc(var(--safe-bottom) + 18px);
  transform: translateX(-100%);
  transition: transform 0.28s ease;
  box-shadow: 2px 0 18px rgba(20, 22, 25, 0.18);
}

.menu-open .menu-drawer {
  transform: translateX(0);
}

.menu-head {
  padding: 6px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.menu-brand {
  font-size: 1.25rem;
  font-weight: 750;
}

.menu-email {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.menu-list {
  flex: 1;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.menu-item {
  display: block;
  padding: 14px;
  border-radius: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 1rem;
}

.menu-item:active {
  background: var(--surface-2);
}

.menu-item.active {
  background: var(--brand-tint);
  color: var(--brand);
}

.menu-logout {
  margin: 8px 20px 0;
  padding: 14px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--brand);
  font-weight: 650;
  font-size: 0.95rem;
  cursor: pointer;
}

.menu-logout:active {
  background: var(--surface-2);
}

/* ============ Layout ============ */
.container {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--safe-bottom) + 32px);
}

/* ============ Home: riquadro macro ============ */
.macro-total {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 18px;
  margin-bottom: 16px;
}

.macro-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 16px;
}

.macro-heading h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

/* Anello di progresso */
.ring {
  position: relative;
  width: 156px;
  height: 156px;
  margin: 4px auto 2px;
}

.ring-svg {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 12;
}

.ring-prog {
  fill: none;
  stroke: var(--brand);
  stroke-width: 12;
  stroke-linecap: round;
  transition: stroke-dashoffset 0.45s ease;
}

.ring-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.ring-value {
  font-size: 1.9rem;
  font-weight: 780;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.ring-target {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 3px;
}

.ring-pct {
  font-size: 0.8rem;
  color: var(--brand);
  font-weight: 700;
  margin-top: 4px;
}

/* Barre macro */
.macro-bars {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.mbar-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.mbar-label {
  font-weight: 600;
}

.mbar-val {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.mbar-track {
  height: 8px;
  background: var(--surface-2);
  border-radius: 99px;
  overflow: hidden;
}

.mbar-fill {
  height: 100%;
  background: var(--brand);
  border-radius: 99px;
  transition: width 0.45s ease;
}

/* Dettaglio per pasto */
.section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  font-weight: 700;
  margin: 4px 6px 10px;
}

.meals {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  margin-bottom: 8px;
}

.meal {
  border-bottom: 1px solid var(--border);
}

.meal:last-child {
  border-bottom: none;
}

.meal-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 19px 16px;
  background: none;
  border: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.meal-header:active {
  background: var(--surface-2);
}

.meal-name {
  font-weight: 650;
}

.meal-head-right {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.meal-kcal {
  color: var(--brand);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.meal-chevron {
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.25s ease;
  position: relative;
  top: -2px;
}

.meal.open .meal-chevron {
  transform: rotate(-135deg);
  top: 2px;
}

/* Corpo collassabile: anima l'altezza con grid-template-rows 0fr -> 1fr */
.meal-body {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 0.28s ease;
}

.meal.open .meal-body {
  grid-template-rows: 1fr;
}

.meal-bars {
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 11px;
  padding: 2px 16px 16px;
}

/* ============ Home: lista di componenti ============ */
.grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.tile {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
}

.tile:active {
  background: var(--surface-2);
}

.tile-body {
  min-width: 0;
  flex: 1;
}

.tile-title {
  display: block;
  font-weight: 650;
  font-size: 1.02rem;
}

.tile-desc {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
}

.tile-chevron {
  flex-shrink: 0;
  color: var(--brand);
  font-size: 1.4rem;
  font-weight: 700;
}

/* ============ Lista spesa ============ */
.summary {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.summary .stat {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}

.stat.brand {
  background: var(--brand);
  border-color: var(--brand);
}

.stat .stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.stat.brand .stat-label {
  color: rgba(255, 255, 255, 0.85);
}

.stat .stat-value {
  display: block;
  font-size: 1.35rem;
  font-weight: 750;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}

.stat.brand .stat-value {
  color: var(--on-brand);
}

.group {
  margin-bottom: 18px;
}

.group-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 6px 10px;
}

.group-name {
  font-weight: 700;
  font-size: 0.98rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-name .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--brand);
  flex-shrink: 0;
}

.group-subtotal {
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.items {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

.item:last-child {
  border-bottom: none;
}

.item-main {
  min-width: 0;
  flex: 1;
}

.item-name {
  font-weight: 550;
  overflow-wrap: anywhere;
}

.item-qty {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 1px;
}

.item-price {
  flex-shrink: 0;
  font-weight: 700;
  color: var(--brand);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.state {
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  padding: 48px 20px;
}

.state.error {
  color: var(--danger);
}

/* ============ Login ============ */
.login-wrap {
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bottom) + 24px);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 28px 24px calc(28px + var(--safe-bottom));
}

.login-card h1 {
  margin: 0 0 4px;
  font-size: 1.5rem;
}

.login-card h1 .accent {
  color: var(--brand);
}

.login-card .subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 0.92rem;
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 7px;
}

.field input {
  width: 100%;
  padding: 14px;
  font-size: 16px; /* evita lo zoom automatico su iOS */
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface-2);
  color: var(--text);
}

.field input:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-tint);
}

button.primary {
  width: 100%;
  min-height: 50px;
  font-size: 1rem;
  font-weight: 650;
  color: var(--on-brand);
  background: var(--brand);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

button.primary:active {
  background: var(--brand-press);
}

button.primary:disabled {
  opacity: 0.6;
}

.message {
  margin-top: 14px;
  font-size: 0.88rem;
  min-height: 1.2em;
}

.message.error {
  color: var(--danger);
}

/* ============ Desktop / tablet ============ */
@media (min-width: 680px) {
  .grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  }
  .topbar {
    padding-left: 24px;
    padding-right: 24px;
  }
  .container {
    padding-left: 24px;
    padding-right: 24px;
  }
}
