/* ============================================================================
   DieteticAI — design system (vanilla, no build step)
   ----------------------------------------------------------------------------
   Anti-slop pass 2026-09-12. Riferimenti reali:
     · Component Gallery — empty state, segmented control, data table
     · Beautiful UI (beautifului.dev) — chat composer, thinking state, task row
     · 21st.dev — "Input Bar" (slot-based composer), "Model Picker" (context pill),
       "Calendar Planner" (spacing/fill invece di bordi pesanti)
   Regole: superfici a livelli + hairline, tipografia con scala reale,
   micro-label in caps, 4 stati per schermata (loading/empty/error/full).
   Palette: 2 modalita' (dark/light) x 2 accenti (azzurro/rosa) = 4 combinazioni,
   tutte su <html data-mode data-accent>.
   ============================================================================ */

/* ==========================================================================
   1. TOKENS — 4 palette
   ========================================================================== */

:root {
  /* --- Dark / Azzurro (default) --- */
  --bg:        #05080d;
  --bg-wash-1: rgba(56, 189, 248, 0.10);
  --bg-wash-2: rgba(125, 211, 252, 0.05);

  --surface-1: rgba(255, 255, 255, 0.038);   /* card */
  --surface-2: rgba(255, 255, 255, 0.022);   /* inset */
  --surface-3: rgba(255, 255, 255, 0.065);   /* hover */
  --surface-solid: #0b1119;

  --line:        rgba(255, 255, 255, 0.075);
  --line-strong: rgba(255, 255, 255, 0.14);

  --fg:   #e9eff7;
  --fg-2: #93a1b5;
  --fg-3: #64717f;

  --accent:       #38bdf8;
  --accent-2:     #7dd3fc;
  --accent-strong:#7dd3fc;   /* accent leggibile come testo */
  --accent-ink:   #04121c;   /* testo/icona SOPRA l'accent */
  --accent-soft:  rgba(56, 189, 248, 0.13);
  --accent-line:  rgba(56, 189, 248, 0.34);
  --glow:         rgba(56, 189, 248, 0.34);

  --ok:     #34d399;
  --warn:   #fbbf24;
  --danger: #f87171;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 18px 48px -12px rgba(0, 0, 0, 0.75);

  --glass-blur: 16px;
  --glass-sat: 150%;

  /* --- Scala raggi --- */
  --r-xs:  8px;
  --r-sm:  11px;
  --r-md:  15px;
  --r-lg:  22px;
  --r-xl:  30px;
  --r-full: 999px;

  /* --- Scala tipografica --- */
  --fs-micro: 0.6875rem;  /* 11px — micro-label caps */
  --fs-xs:    0.75rem;    /* 12px */
  --fs-sm:    0.8125rem;  /* 13px */
  --fs-base:  0.9375rem;  /* 15px in UI dense */
  --fs-md:    1rem;
  --fs-lg:    1.125rem;
  --fs-xl:    1.375rem;
  --fs-2xl:   1.75rem;
  --fs-hero:  clamp(1.5rem, 1.15rem + 1.6vw, 2.125rem);

  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Inter', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, 'SF Mono', SFMono-Regular, Menlo, Consolas, monospace;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 28px;
  --sp-7: 40px;

  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  --dur:  260ms;
}

/* --- Dark / Rosa --- */
[data-accent='rosa'] {
  --bg-wash-1: rgba(244, 114, 182, 0.10);
  --bg-wash-2: rgba(236, 72, 153, 0.05);
  --accent:        #f472b6;
  --accent-2:      #f9a8d4;
  --accent-strong: #f9a8d4;
  --accent-ink:    #2a0716;
  --accent-soft:   rgba(244, 114, 182, 0.13);
  --accent-line:   rgba(244, 114, 182, 0.34);
  --glow:          rgba(244, 114, 182, 0.32);
}

/* --- Light / Azzurro --- */
[data-mode='light'] {
  --bg:        #f4f7fb;
  --bg-wash-1: rgba(56, 189, 248, 0.16);
  --bg-wash-2: rgba(2, 132, 199, 0.05);

  --surface-1: rgba(255, 255, 255, 0.78);
  --surface-2: rgba(9, 20, 34, 0.028);
  --surface-3: rgba(9, 20, 34, 0.055);
  --surface-solid: #ffffff;

  --line:        rgba(9, 22, 38, 0.085);
  --line-strong: rgba(9, 22, 38, 0.16);

  --fg:   #08131f;
  --fg-2: #55636f;
  --fg-3: #8b97a3;

  --accent:        #0d7cc4;   /* riempimento interattivo */
  --accent-2:      #0ea5e9;
  --accent-strong: #04587f;   /* accent come testo (contrasto AA) */
  --accent-ink:    #ffffff;
  --accent-soft:   rgba(13, 124, 196, 0.10);
  --accent-line:   rgba(13, 124, 196, 0.28);
  --glow:          rgba(13, 124, 196, 0.22);

  --ok:     #0f9d63;
  --warn:   #b45309;
  --danger: #d64545;

  --shadow-1: 0 1px 2px rgba(9, 22, 38, 0.06);
  --shadow-2: 0 16px 40px -16px rgba(9, 22, 38, 0.22);
}

/* --- Light / Rosa --- */
[data-mode='light'][data-accent='rosa'] {
  --bg-wash-1: rgba(219, 39, 119, 0.12);
  --bg-wash-2: rgba(219, 39, 119, 0.04);
  --accent:        #cf2472;
  --accent-2:      #e4559a;
  --accent-strong: #9b1152;
  --accent-ink:    #ffffff;
  --accent-soft:   rgba(207, 36, 114, 0.10);
  --accent-line:   rgba(207, 36, 114, 0.26);
  --glow:          rgba(207, 36, 114, 0.20);
}

/* ==========================================================================
   2. BASE
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  font-size: 16px;
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

/* Rete di sicurezza anti-scroll orizzontale.
   ATTENZIONE: `overflow-x: hidden` su <body> rende body un contenitore di
   scroll e ROMPE `position: sticky` dei figli (la topbar spariva appena si
   scorreva). `clip` non crea un contenitore di scroll: nessun overflow
   orizzontale e sticky funzionante. Fallback per browser vecchi. */
html { overflow-x: clip; }
@supports not (overflow: clip) {
  html, body { overflow-x: hidden; }
}

/* Il colore base vive su <html>: body trasparente per lasciar vedere l'ambient. */
html {
  background-color: var(--bg);
  /* Lavaggio di profondita': due aloni che seguono l'accento attivo. */
  background-image:
    radial-gradient(120% 80% at 50% -20%, var(--bg-wash-1), transparent 62%),
    radial-gradient(90% 60% at 100% 0%, var(--bg-wash-2), transparent 58%);
  background-attachment: fixed;
  transition: background-color var(--dur) var(--ease);
}
body { background: transparent; }

body {
  min-height: 100vh;
  line-height: 1.5;
  font-size: var(--fs-md);
}

h1, h2, h3, h4 {
  margin: 0;
  line-height: 1.22;
  letter-spacing: -0.018em;
  font-weight: 640;
}
h2 { font-size: var(--fs-2xl); }
h3 { font-size: var(--fs-lg); }
h4 { font-size: var(--fs-md); }
p { margin: 0 0 var(--sp-3); }

a { color: var(--accent-strong); text-decoration: none; transition: color 160ms var(--ease); }
a:hover { color: var(--accent-2); }

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

/* Micro-label ricorrente: caps + tracking + colore attenuato.
   Usata per header di griglia, label slot, meta del composer. */
.eyebrow, .cal-head, .meal-slot .slot-title, .meal-row .meal-slot-label,
.composer-meta, .seg-label, .kpi .l {
  font-size: var(--fs-micro);
  font-weight: 620;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-3);
}

/* Scrollbar discreta (desktop) */
* { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
*::-webkit-scrollbar { width: 9px; height: 9px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border-radius: var(--r-full);
  border: 2px solid transparent;
  background-clip: content-box;
}
*::-webkit-scrollbar-thumb:hover { background: var(--accent-line); background-clip: content-box; }

/* ==========================================================================
   3. AMBIENT LAYER (canvas gestito da public/js/ambient.js)
   ========================================================================== */

#ambient-canvas {
  position: fixed;
  inset: 0;
  /* 100% (= viewport) e NON 100vw: su mobile 100vw può superare la larghezza
     reale del viewport e far scorrere la pagina in orizzontale (bug 2026-09-13). */
  width: 100%;
  height: 100%;
  max-width: 100%;
  z-index: 0;
  pointer-events: none;
  will-change: opacity;
}
.app-shell { position: relative; z-index: 1; }

/* ==========================================================================
   4. CONTROLLI
   ========================================================================== */

button {
  font: inherit;
  font-weight: 560;
  cursor: pointer;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  padding: 11px 18px;
  border-radius: var(--r-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  transition: background-color 180ms var(--ease), color 180ms var(--ease),
              border-color 180ms var(--ease), transform 120ms var(--ease),
              box-shadow 200ms var(--ease);
}
button:hover:not(:disabled) { filter: brightness(1.08); }
button:active:not(:disabled) { transform: translateY(1px) scale(0.994); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

/* Anello di focus unico per tutta l'app (accessibilita' + coerenza). */
:where(button, a, input, textarea, [tabindex]):focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

button.secondary {
  background: var(--surface-2);
  color: var(--fg);
  border: 1px solid var(--line);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}
button.secondary:hover:not(:disabled) {
  background: var(--surface-3);
  border-color: var(--line-strong);
  filter: none;
}

input, textarea {
  font: inherit;
  font-size: var(--fs-base);
  background: var(--surface-2);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 11px 13px;
  width: 100%;
  transition: border-color 180ms var(--ease), background-color 180ms var(--ease),
              box-shadow 200ms var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--fg-3); }
input:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent-line);
  background: var(--surface-1);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 100px; resize: vertical; }

/* Le checkbox non sono campi di testo: `width:100%` le deformava. */
input[type='checkbox'] {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  padding: 0;
  border-radius: 5px;
  accent-color: var(--accent);
}
/* Riga con checkbox + etichetta: area di tocco comoda anche su mobile. */
.table label.chk {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 40px;
  font-size: var(--fs-sm);
}
hr { border: none; border-top: 1px solid var(--line); margin: var(--sp-5) 0; }

/* --- Segmented control (modalita' / accento) ------------------------------
   Pattern "segmented control" (Component Gallery): binario incassato,
   thumb che scorre. Il thumb si posiziona leggendo data-mode / data-accent
   sul <html>: nessun JS aggiuntivo, le meccaniche restano identiche. */
.seg {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0;
  padding: 3px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.seg-thumb {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  border-radius: var(--r-full);
  background: var(--accent);
  box-shadow: 0 2px 10px -2px var(--glow);
  transition: transform 320ms var(--ease), background-color var(--dur) var(--ease);
  pointer-events: none;
}
.seg button {
  position: relative;
  z-index: 1;
  background: transparent;
  color: var(--fg-2);
  padding: 7px 13px 7px 11px;
  border-radius: var(--r-full);
  font-size: var(--fs-xs);
  font-weight: 600;
  white-space: nowrap;
  transition: color 200ms var(--ease);
}
.seg button:hover:not(.active) { color: var(--fg); filter: none; }
.seg button.active { color: var(--accent-ink); }
.seg button:active { transform: none; }

/* Il thumb segue la selezione */
[data-mode='light'] #theme-toggle .seg-thumb,
[data-accent='rosa']  #accent-toggle .seg-thumb { transform: translateX(100%); }

/* Pallino-campione accanto al nome dell'accento */
.seg button[data-accent]::before {
  content: '';
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-right: 6px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.18);
}
.seg button[data-accent='azzurro']::before { background: #38bdf8; }
.seg button[data-accent='rosa']::before    { background: #f472b6; }

/* Switch di vista (utente / admin) — visibile solo all'admin.
   Bordo accento per non confonderlo con i due controlli di tema. */
.seg--view { border-color: var(--accent-line); }
.seg--view button { font-weight: 640; }
.seg--view button.active { color: var(--accent-ink); }
.seg--view[data-active='admin'] .seg-thumb { transform: translateX(100%); }

/* ==========================================================================
   5. LAYOUT
   ========================================================================== */

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background: transparent;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  flex-wrap: wrap;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 680;
  font-size: var(--fs-lg);
  letter-spacing: -0.028em;
}
.brand-img {
  width: 26px; height: 26px;
  display: block;
  filter: drop-shadow(0 0 10px var(--glow));
}
.brand-mark {
  width: 26px; height: 26px; border-radius: var(--r-xs);
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  box-shadow: 0 0 16px var(--glow);
}
.brand-mark::after {
  content: ''; width: 10px; height: 10px; border-radius: 50%;
  background: var(--bg); display: block;
}
.top-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.top-actions > a.small { white-space: nowrap; }

main.container {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-7);
  display: grid;
  gap: var(--sp-5);
  align-content: start;
}

/* ==========================================================================
   6. SUPERFICI (glass a livelli, hairline, non bordi pesanti)
   ========================================================================== */

.card {
  position: relative;
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  background: var(--surface-1);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-1), var(--shadow-2);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
}

/* Intestazione di sezione dentro una card: titolo + eventuale meta a destra */
.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.card-head h3 { font-size: var(--fs-lg); }

/* ==========================================================================
   7. ORB STAGE — il canvas diventa un "palco", non un rettangolo vuoto
   ========================================================================== */

.orb-area {
  display: grid;
  justify-items: center;
  gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-5) var(--sp-5);
  overflow: hidden;
  isolation: isolate;
}
/* Alone radiale dietro l'orb: da' profondita' alla scena. */
.orb-area::before {
  content: '';
  position: absolute;
  inset: -40% -10% auto;
  height: 150%;
  background: radial-gradient(48% 46% at 50% 46%, var(--accent-soft), transparent 72%);
  opacity: 0.9;
  z-index: -1;
  transition: opacity 600ms var(--ease);
}
/* Anelli guida statici attorno all'orb (danno scala e simmetria). */
.orb-area::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 340px; height: 340px;
  margin: -170px 0 0 -170px;
  border-radius: 50%;
  border: 1px dashed var(--line);
  opacity: 0.5;
  z-index: -1;
  pointer-events: none;
}
.orb-canvas { width: 248px; height: 248px; display: block; }

/* Chip di stato: pallino live + micro-label caps */
.orb-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 13px 6px 11px;
  border-radius: var(--r-full);
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: var(--fs-micro);
  font-weight: 620;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-2);
}
.orb-state::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 0 var(--glow);
  animation: live-pulse 2.4s var(--ease) infinite;
}
.orb-area[data-state='thinking']::before,
.orb-area[data-state='generating']::before { opacity: 1; }
.orb-area[data-state='thinking'] .orb-state::before { animation-duration: 1s; }
.orb-area[data-state='generating'] .orb-state::before { animation-duration: 0.7s; }
@keyframes live-pulse {
  0%   { box-shadow: 0 0 0 0 var(--glow); }
  70%  { box-shadow: 0 0 0 7px transparent; }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ==========================================================================
   8. CHAT — log, empty state, thinking, composer
   ========================================================================== */

.chat-card { display: flex; flex-direction: column; gap: var(--sp-4); }

.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 340px;
  min-height: 84px;
  overflow-y: auto;
  /* NIENTE `overscroll-behavior: contain` qui.
     Un contenitore con overflow:auto e' un scroll container anche quando NON
     ha nulla da scrollare: con `contain` il gesto non viene mai incatenato al
     parent, quindi la pagina resta immobile. Misurato con gesto touch reale
     (2026-09-12): su mobile .chat-log e' alto 293px e non scrollabile, la tile
     "Cosa cuciniamo?" ne occupa 289 -> tutta quella zona era morta e non si
     riusciva a scorrere la pagina. Default (`auto`) = incatenamento normale. */
  padding: 2px 6px 2px 2px;
}

/* --- Messaggi --- */
.chat-msg {
  position: relative;
  max-width: 86%;
  padding: 11px 15px;
  border-radius: var(--r-md);
  font-size: var(--fs-base);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  animation: msg-in 300ms var(--ease) both;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}
.chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--accent-ink);
  border-bottom-right-radius: var(--r-xs);
  box-shadow: 0 6px 20px -10px var(--glow);
}
.chat-msg.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: var(--r-xs);
  /* Rail d'accento: sostituisce il bordo generico, da' identita' al bot. */
  padding-left: 17px;
}
.chat-msg.assistant::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 11px;
  bottom: 11px;
  width: 2px;
  border-radius: var(--r-full);
  background: var(--accent);
  opacity: 0.55;
}

/* --- Stato "thinking" (Beautiful UI: loading state con tempo) --- */
.chat-msg.thinking {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding-left: 17px;
}
.chat-msg.thinking::before {
  content: '';
  position: absolute;
  left: 7px; top: 11px; bottom: 11px;
  width: 2px; border-radius: var(--r-full);
  background: var(--accent);
  opacity: 0.55;
}
.thinking-dots { display: inline-flex; gap: 4px; }
.thinking-dots i {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent);
  animation: dot-bounce 1.2s var(--ease) infinite;
}
.thinking-dots i:nth-child(2) { animation-delay: 0.15s; }
.thinking-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-bounce {
  0%, 60%, 100% { opacity: 0.28; transform: translateY(0); }
  30%           { opacity: 1;    transform: translateY(-3px); }
}
.thinking-label { font-size: var(--fs-micro); letter-spacing: 0.09em; text-transform: uppercase; color: var(--fg-3); font-weight: 620; }
.thinking-elapsed { font-size: var(--fs-micro); color: var(--fg-3); font-variant-numeric: tabular-nums; }

/* --- Empty state (Component Gallery: icona + titolo + azione) --- */
.chat-empty {
  display: grid;
  justify-items: center;
  text-align: center;
  gap: var(--sp-2);
  padding: var(--sp-5) var(--sp-3);
  border: 1px dashed var(--line-strong);
  border-radius: var(--r-md);
  background: var(--surface-2);
}
.chat-empty[hidden] { display: none; }
.ce-mark {
  width: 40px; height: 40px;
  border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent-strong);
  margin-bottom: 2px;
}
.ce-mark svg { width: 20px; height: 20px; }
.chat-empty h4 { font-size: var(--fs-md); letter-spacing: -0.01em; }
.chat-empty p { margin: 0; color: var(--fg-2); font-size: var(--fs-sm); max-width: 42ch; }
.ce-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; margin-top: 6px; }
.chip {
  background: var(--surface-1);
  color: var(--fg-2);
  border: 1px solid var(--line);
  border-radius: var(--r-full);
  padding: 7px 13px;
  font-size: var(--fs-xs);
  font-weight: 560;
  transition: color 160ms var(--ease), border-color 160ms var(--ease),
              background-color 160ms var(--ease), transform 140ms var(--ease);
}
.chip:hover {
  color: var(--fg);
  border-color: var(--accent-line);
  background: var(--accent-soft);
  filter: none;
}
.chip:active { transform: scale(0.97); }

/* --- Composer (21st.dev "Input Bar": slot mode + campo + invio) --- */
.composer {
  display: flex;
  align-items: flex-end;
  gap: var(--sp-2);
  padding: 7px;
  border-radius: var(--r-lg);
  background: var(--surface-2);
  border: 1px solid var(--line);
  transition: border-color 200ms var(--ease), box-shadow 240ms var(--ease);
}
.composer:focus-within {
  border-color: var(--accent-line);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.composer-field {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 2px;
}
.composer-field textarea {
  border: none;
  background: transparent;
  padding: 3px 4px;
  min-height: 0;
  height: auto;
  resize: none;
  font-size: var(--fs-base);
  line-height: 1.45;
  max-height: 140px;
  overflow-y: auto;
  box-shadow: none;
}
.composer-field textarea:focus { outline: none; box-shadow: none; background: transparent; border: none; }
/* Riga di contesto sotto il campo — gerarchia tipo "Sonnet 4.6" del riferimento.
   Contiene il motore attivo a sinistra e la scorciatoia d'invio a destra. */
.composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: 0 4px 2px;
  font-size: 10px;
  letter-spacing: 0.09em;
  transition: color 200ms var(--ease);
}
/* Scorciatoia: utile solo con una tastiera fisica, nascosta su mobile. */
.send-hint { opacity: 0.7; white-space: nowrap; }

/* Pill della modalita': dentro il composer, non un bottone fuori. */
.mode-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  align-self: flex-end;
  padding: 8px 13px;
  border-radius: var(--r-md);
  background: var(--accent-soft);
  border: 1px solid var(--accent-line);
  color: var(--accent-strong);
  font-size: var(--fs-xs);
  font-weight: 620;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background-color 200ms var(--ease), border-color 200ms var(--ease),
              color 200ms var(--ease), transform 140ms var(--ease);
}
.mode-pill:hover:not(:disabled) { background: var(--accent-soft); border-color: var(--accent); filter: none; }
.mode-pill:active:not(:disabled) { transform: scale(0.98); }
.mode-pill:disabled { opacity: 0.55; cursor: wait; }
.mode-pill .mode-icon { font-size: 14px; line-height: 1; }
.mode-pill .mode-label { letter-spacing: -0.005em; }
.mode-pill[data-mode='conv'] {
  background: var(--surface-3);
  border-color: var(--line-strong);
  color: var(--fg);
}

/* Bottone invio circolare con icona (riferimento: send icon del composer) */
.send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: var(--r-full);
  display: grid;
  place-items: center;
  box-shadow: 0 6px 18px -8px var(--glow);
}
.send-btn svg { width: 17px; height: 17px; display: block; }
.send-btn:hover:not(:disabled) { filter: brightness(1.09); }

/* ==========================================================================
   9. CALENDARIO — griglia desktop (7 giorni x 5 slot)
   ========================================================================== */

/* 5 SLOT = 5 colonne. Prima erano dichiarate 4: la colonna Cena andava a capo. */
.calendar.cal-grid {
  display: grid;
  grid-template-columns: minmax(58px, 74px) repeat(5, minmax(0, 1fr));
  gap: 6px;
  min-width: 0;
}
.cal-agenda { display: none; }

.cal-head {
  padding: 6px 4px 8px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 10px;
  line-height: 1.3;
  color: var(--fg-3);
}
.cal-head .slot-ico { display: block; font-size: 13px; margin-bottom: 3px; letter-spacing: 0; }
.cal-head.corner { border-bottom-color: transparent; }

.cal-day-label {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  padding: 4px 6px;
  border-radius: var(--r-xs);
}
.cal-day-label .dow {
  font-size: var(--fs-xs);
  font-weight: 640;
  letter-spacing: -0.01em;
  color: var(--fg-2);
}
.cal-day-label .dom {
  font-size: 10px;
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
}
.cal-day-label.today .dow { color: var(--accent-strong); }
.cal-day-label.today .dom { color: var(--accent-strong); opacity: 0.8; }

.meal-slot {
  position: relative;
  min-width: 0;
  min-height: 58px;
  padding: 8px 9px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  border: 1px solid var(--line);
  cursor: pointer;
  overflow-wrap: anywhere;
  transition: border-color 180ms var(--ease), background-color 180ms var(--ease),
              transform 160ms var(--ease);
}
.meal-slot:hover {
  border-color: var(--accent-line);
  background: var(--surface-3);
  transform: translateY(-1px);
}
.meal-slot .slot-title {
  font-size: 10px;
  margin-bottom: 3px;
  display: none; /* l'header di colonna basta: meno rumore in cella */
}
.meal-slot .meal-title {
  font-size: var(--fs-sm);
  font-weight: 540;
  line-height: 1.35;
  letter-spacing: -0.008em;
}
/* Cella vuota = dashed + nessun titolo: distinta a colpo d'occhio da quella piena */
.meal-slot:has(.meal-empty) {
  background: transparent;
  border-style: dashed;
  border-color: var(--line);
}
.meal-slot:has(.meal-empty):hover { border-color: var(--accent-line); }
.meal-slot .meal-empty {
  color: var(--fg-3);
  font-size: var(--fs-micro);
  font-style: normal;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
/* Colonna di oggi: rail a sinistra su ogni cella della giornata */
.meal-slot.today {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}
.meal-slot.today::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 2px;
  border-radius: var(--r-full);
  background: var(--accent);
}
.meal-slot.flash,
.meal-row.flash { animation: flash 1.3s var(--ease); }
@keyframes flash {
  0%   { box-shadow: 0 0 0 0 var(--glow); }
  45%  { box-shadow: 0 0 0 5px var(--glow); }
  100% { box-shadow: 0 0 0 0 transparent; }
}

/* ==========================================================================
   10. CALENDARIO — agenda mobile
   ========================================================================== */

.cal-agenda { flex-direction: column; gap: var(--sp-3); }

.day-card {
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  overflow: hidden;
  scroll-margin-top: 84px; /* sticky topbar non copre la card */
}
.day-card.today {
  border-color: var(--accent-line);
  box-shadow: inset 2px 0 0 var(--accent), 0 10px 30px -18px var(--glow);
}
.day-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--sp-2);
  padding: 11px 14px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--line);
}
/* Giorno + data raggruppati a sinistra, badge pasti a destra:
   con 3 figli in space-between il badge finiva a meta' card. */
.day-head-left {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}
.day-card-header .day-name {
  font-size: var(--fs-md);
  font-weight: 640;
  letter-spacing: -0.018em;
}
.day-card-header .day-date {
  font-size: var(--fs-xs);
  color: var(--fg-3);
  font-variant-numeric: tabular-nums;
}
.day-card.today .day-name { color: var(--accent-strong); }
.day-count {
  font-size: var(--fs-micro);
  font-weight: 620;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-3);
  padding: 3px 8px;
  border-radius: var(--r-full);
  background: var(--surface-3);
  font-variant-numeric: tabular-nums;
}
.day-card.today .day-count { background: var(--accent-soft); color: var(--accent-strong); }

.meal-row {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  cursor: pointer;
  min-width: 0;
  min-height: 52px;
  transition: background-color 180ms var(--ease);
}
.meal-row:first-child { border-top: none; }
.meal-row:hover { background: var(--surface-3); }
.meal-row .meal-slot-label {
  flex-shrink: 0;
  width: 80px;
  padding-top: 2px;
  font-size: 10px;
  line-height: 1.45;
  color: var(--fg-3);
}
.meal-row .meal-slot-label .slot-ico {
  display: block;
  font-size: 13px;
  margin-bottom: 2px;
  letter-spacing: 0;
}
.meal-row .meal-body { flex: 1; min-width: 0; }
.meal-row .meal-body .meal-title {
  font-size: var(--fs-base);
  font-weight: 540;
  line-height: 1.4;
  letter-spacing: -0.008em;
  overflow-wrap: anywhere;
}
.meal-row:has(.meal-empty) { cursor: default; }
.meal-row:has(.meal-empty):hover { background: transparent; }
.meal-row .meal-body .meal-empty {
  color: var(--fg-3);
  font-size: var(--fs-micro);
  font-style: normal;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* Chevron: segnala che la riga si espande (affordance mancante prima) */
.meal-row .meal-body .meal-title::after {
  content: '';
}
.meal-row.open { background: var(--surface-3); }
.meal-row .meal-expand {
  display: block;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  padding-top: 0;
  border-top: 1px dashed transparent;
  font-size: var(--fs-sm);
  color: var(--fg-2);
  transition: max-height 320ms var(--ease), opacity 220ms var(--ease),
              margin-top 320ms var(--ease), padding-top 320ms var(--ease);
}
.meal-row.open .meal-expand {
  max-height: 1600px;
  opacity: 1;
  margin-top: 11px;
  padding-top: 11px;
  border-top-color: var(--line-strong);
}
.meal-row .meal-expand strong {
  display: block;
  font-size: var(--fs-micro);
  font-weight: 620;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin-bottom: 5px;
}
.meal-row .meal-expand ul { margin: 0 0 13px; padding-left: 18px; }
.meal-row .meal-expand li { margin-bottom: 2px; }
.meal-row .meal-expand ul:last-child { margin-bottom: 0; }
.meal-row .meal-expand p { margin: 0; white-space: pre-wrap; }

/* ==========================================================================
   11. DETAIL PANEL (click su cella desktop)
   ========================================================================== */

.meal-detail {
  position: relative;
  margin-top: var(--sp-4);
  padding: var(--sp-5);
  padding-right: 52px;
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
  animation: msg-in 260ms var(--ease) both;
}
.meal-detail h4 {
  font-size: var(--fs-md);
  font-weight: 620;
  letter-spacing: -0.015em;
  margin-bottom: var(--sp-3);
}
.meal-detail strong {
  display: block;
  font-size: var(--fs-micro);
  font-weight: 620;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--fg-3);
  margin-bottom: 6px;
}
.meal-detail ul { margin: 0 0 var(--sp-4); padding-left: 18px; color: var(--fg-2); }
.meal-detail ul:last-child { margin-bottom: 0; }
.meal-detail p { margin: 0; color: var(--fg-2); font-size: var(--fs-sm); line-height: 1.6; }
.meal-detail .close-x {
  position: absolute;
  top: var(--sp-3);
  right: var(--sp-3);
  width: 30px; height: 30px;
  padding: 0;
  border-radius: var(--r-full);
  font-size: 17px;
  line-height: 1;
  background: var(--surface-3);
  color: var(--fg-2);
  border: 1px solid var(--line);
}
.meal-detail .close-x:hover { color: var(--fg); border-color: var(--line-strong); filter: none; }

/* ==========================================================================
   12. LOGIN
   ========================================================================== */

.login-card {
  width: 100%;
  max-width: 432px;
  margin: clamp(20px, 6vh, 64px) auto;
  padding: var(--sp-6);
}
.login-card h2 { font-size: var(--fs-xl); margin-bottom: 6px; }
.login-card > p { color: var(--fg-2); font-size: var(--fs-sm); margin-bottom: var(--sp-5); }
.login-card .row { display: flex; flex-direction: column; gap: 7px; margin-bottom: var(--sp-3); }
.login-card .row label {
  font-size: var(--fs-micro);
  font-weight: 620;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  /* --fg-2 e non --fg-3: le label sono testo piccolo in caps, con --fg-3
     restavano sotto la soglia AA (2026-09-13). */
  color: var(--fg-2);
}
.login-card .err {
  color: var(--danger);
  font-size: var(--fs-sm);
  min-height: 0;
  margin-bottom: var(--sp-2);
}
.login-card .err:not(:empty) {
  padding: 9px 12px;
  border-radius: var(--r-xs);
  background: color-mix(in srgb, var(--danger) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--danger) 32%, transparent);
}
.login-card button { width: 100%; }
.login-card hr { margin: var(--sp-5) 0 var(--sp-4); }
#otp-row { gap: var(--sp-2); }
#otp-row label { margin-bottom: 0; }
#login-code {
  font-family: var(--font-mono);
  font-size: var(--fs-xl);
  letter-spacing: 0.42em;
  text-align: center;
  padding: 13px 10px 13px 16px;
  font-variant-numeric: tabular-nums;
}
#otp-row button { width: 100%; }

/* ==========================================================================
   13. PWA
   ========================================================================== */

.pwa-install-banner {
  position: fixed;
  left: 12px; right: 12px; bottom: 12px;
  z-index: 100;
  pointer-events: none;
  animation: pwa-slide-up 340ms var(--ease);
}
.pwa-install-banner[hidden] { display: none; }
@keyframes pwa-slide-up {
  from { transform: translateY(22px); opacity: 0; }
  to   { transform: none; opacity: 1; }
}
.pwa-install-card {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  max-width: 540px;
  margin: 0 auto;
  padding: 14px 16px;
  border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--surface-solid) 82%, transparent);
  backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(var(--glass-sat));
  border: 1px solid var(--line-strong);
  box-shadow: var(--shadow-2);
}
.pwa-install-icon {
  width: 46px; height: 46px;
  flex-shrink: 0;
  border-radius: var(--r-sm);
  filter: drop-shadow(0 0 10px var(--glow));
}
.pwa-install-body { flex: 1; min-width: 0; }
.pwa-install-title { font-weight: 620; font-size: var(--fs-base); margin-bottom: 2px; letter-spacing: -0.012em; }
.pwa-install-sub { font-size: var(--fs-sm); color: var(--fg-2); }
.pwa-install-ios { font-size: var(--fs-sm); color: var(--fg-2); display: flex; flex-direction: column; gap: 4px; margin-top: 4px; }
.pwa-install-ios-row { display: flex; align-items: center; gap: var(--sp-2); }
.pwa-install-ios .kbd {
  display: inline-grid;
  place-items: center;
  width: 22px; height: 22px;
  border-radius: 6px;
  background: var(--surface-3);
  border: 1px solid var(--line);
  font-size: var(--fs-xs);
}
.pwa-install-actions { display: flex; gap: var(--sp-2); flex-shrink: 0; }
.pwa-install-actions button { padding: 8px 14px; font-size: var(--fs-xs); white-space: nowrap; }
.pwa-toast {
  position: fixed;
  left: 50%; bottom: 24px;
  transform: translateX(-50%);
  background: var(--accent);
  color: var(--accent-ink);
  padding: 10px 18px;
  border-radius: var(--r-full);
  font-weight: 560;
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-2);
  z-index: 101;
  animation: pwa-toast-in 240ms var(--ease);
}
@keyframes pwa-toast-in {
  from { transform: translate(-50%, 14px); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}

/* ==========================================================================
   14. ADMIN
   ========================================================================== */

.admin-shell { padding: var(--sp-6) var(--sp-5); max-width: 1240px; margin: 0 auto; }
.admin-shell > .card + .card,
.admin-shell > section > .card + .card { margin-top: var(--sp-5); }
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-5); align-items: start; }
.admin-shell .row { display: flex; flex-direction: column; gap: 7px; margin-bottom: var(--sp-3); }
.admin-shell .row label {
  font-size: var(--fs-micro);
  font-weight: 620;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--fg-3);
}
.admin-shell h3 { margin-bottom: var(--sp-4); }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: var(--fs-sm);
}
.table th {
  color: var(--fg-3);
  font-weight: 620;
  font-size: var(--fs-micro);
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.table tbody tr { transition: background-color 160ms var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: none; }

.kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: var(--sp-4); }
.kpi > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: var(--sp-4);
  border-radius: var(--r-md);
  background: var(--surface-2);
  border: 1px solid var(--line);
}
.kpi .v {
  font-size: var(--fs-2xl);
  font-weight: 660;
  letter-spacing: -0.03em;
  color: var(--accent-strong);
  font-variant-numeric: tabular-nums;
}
.kpi .l { font-size: var(--fs-micro); }

/* ==========================================================================
   15. UTILITY
   ========================================================================== */

.flex { display: flex; gap: var(--sp-2); align-items: center; }
.flex.between { justify-content: space-between; }
.muted { color: var(--fg-2); }
.small { font-size: var(--fs-xs); }
[hidden] { display: none !important; }

/* ==========================================================================
   16. RESPONSIVE
   ========================================================================== */

@media (max-width: 900px) {
  .calendar.cal-grid { grid-template-columns: minmax(50px, 62px) repeat(5, minmax(0, 1fr)); gap: 4px; }
  .meal-slot { padding: 7px; min-height: 54px; }
  .meal-slot .meal-title { font-size: var(--fs-xs); }
}

@media (max-width: 767px) {
  main.container { padding: var(--sp-4) var(--sp-3) var(--sp-6); gap: var(--sp-4); }
  .topbar { padding: 10px 13px; gap: var(--sp-2); row-gap: 10px; }
  .card { padding: var(--sp-4); border-radius: var(--r-md); }
  .orb-area { padding: var(--sp-5) var(--sp-4) var(--sp-4); }
  .orb-canvas { width: 200px; height: 200px; }
  .orb-area::after { width: 272px; height: 272px; margin: -136px 0 0 -136px; }

  /* Swap vista calendario: agenda su mobile */
  .calendar.cal-grid { display: none; }
  .cal-agenda { display: flex; }

  .chat-log { max-height: 300px; }
  .chat-msg { max-width: 92%; }
  .composer { flex-wrap: wrap; }
  .composer-field { order: 1; flex-basis: 100%; }
  .mode-pill { order: 2; }
  .send-btn { order: 3; margin-left: auto; }
  .meal-detail { padding-right: var(--sp-5); }

  .admin-grid { grid-template-columns: 1fr; }

  /* --- Admin su mobile: la tabella diventa una lista di card -------------
     Una tabella a 5 colonne con input dentro e' inutilizzabile a 390px:
     campi schiacciati, "Salva"/"Elimina" appaiati in pochi pixel, checkbox
     minuscola. Ogni riga diventa una card con l'etichetta sopra il valore. */
  .admin-shell .flex { flex-direction: column; align-items: stretch; }
  .admin-shell .flex > button { width: 100%; }

  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr {
    background: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--r-md);
    padding: var(--sp-3);
    margin-bottom: var(--sp-3);
  }
  .table tbody tr:hover { background: var(--surface-2); }
  .table td {
    border: none;
    padding: 6px 0;
    font-size: var(--fs-sm);
  }
  .table td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 5px;
    font-size: var(--fs-micro);
    font-weight: 620;
    letter-spacing: 0.09em;
    text-transform: uppercase;
    color: var(--fg-3);
  }
  .table td.acts {
    display: flex;
    gap: var(--sp-2);
    padding-top: var(--sp-3);
    margin-top: 4px;
    border-top: 1px solid var(--line);
  }
  .table td.acts::before { display: none; }
  .table td.acts button { flex: 1; }
}

@media (max-width: 480px) {
  :root { --fs-md: 0.9375rem; }
  .brand { font-size: var(--fs-md); }
  .top-actions { gap: 6px; }
  .seg button { padding: 6px 10px; font-size: 11px; }
  .orb-canvas { width: 176px; height: 176px; }
  .orb-area::after { display: none; }
  .card { padding: 13px; }
  .pwa-install-banner { left: 8px; right: 8px; bottom: 8px; }
  .pwa-install-card { padding: 12px; gap: 10px; }
  .pwa-install-icon { width: 38px; height: 38px; }
  .pwa-install-title { font-size: var(--fs-sm); }
  .pwa-install-sub, .pwa-install-ios { font-size: var(--fs-xs); }
  .meal-row .meal-slot-label { width: 68px; }
}

/* Tabelle admin: wrap forzato su schermi stretti */
@media (max-width: 600px) {
  .table th, .table td { padding: 7px 7px; font-size: var(--fs-xs); overflow-wrap: anywhere; }
}

/* ==========================================================================
   17. MOTION — rispetta la preferenza di sistema
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ==========================================================================
   Navigazione settimane nel calendario (2026-09-13)
   Serve a guardare la settimana successiva — es. la domenica, per fare la
   spesa in anticipo — e a tornare indietro a quella corrente.
   ========================================================================== */
.week-nav {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.week-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: var(--r-full);
  border: 1px solid var(--line);
  background: var(--surface-1);
  color: var(--fg-2);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  transition: color 160ms var(--ease), border-color 160ms var(--ease),
              background-color 160ms var(--ease), transform 140ms var(--ease);
}
.week-btn:hover {
  color: var(--fg);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.week-btn:active { transform: scale(0.94); }
.week-range-label {
  min-width: 92px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.week-tools {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  margin: calc(-1 * var(--sp-2)) 0 var(--sp-3);
}
@media (max-width: 520px) {
  .card-head { flex-wrap: wrap; }
  .week-nav { width: 100%; justify-content: space-between; }
  .week-range-label { min-width: 0; }
}

/* ==========================================================================
   Rigenerazione di un singolo giorno (2026-09-13)
   Pulsante ↻ su ogni giorno: rigenera solo quel giorno, senza messaggi in chat.
   ========================================================================== */
.day-regen {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  margin-top: 3px;
  border-radius: var(--r-full);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--fg-3);
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  transition: color 160ms var(--ease), border-color 160ms var(--ease),
              background-color 160ms var(--ease), transform 140ms var(--ease);
}
.day-regen:hover {
  color: var(--fg);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}
.day-regen:active { transform: scale(0.92); }
.day-regen.busy { color: var(--accent-strong); animation: day-regen-spin 900ms linear infinite; }
.day-card-header .day-regen { margin-top: 0; margin-left: var(--sp-2); }
.week-status { font-variant-numeric: tabular-nums; }
@keyframes day-regen-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .day-regen.busy { animation: none; opacity: 0.65; }
}

/* Pulsante rigenera: compatto nella griglia desktop (colonna stretta),
   etichettato e piu' grande nell'agenda mobile — su telefono l'icona 22px era
   troppo piccola da centrare col dito (segnalazione di Francesco). */
.day-regen { width: 26px; height: 26px; font-size: 13px; gap: 6px; }
.day-regen-label { display: none; }
.day-head-right {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-left: auto;
}
.day-card-header { align-items: center; }
.day-card-header .day-regen {
  width: auto;
  height: auto;
  min-height: 34px;
  padding: 0 12px;
  margin: 0;
  font-size: var(--fs-xs);
  font-weight: 560;
  color: var(--fg-2);
}
.day-card-header .day-regen-label { display: inline; }
/* Su telefono il pulsante e' un target tattile: 40px di altezza, testo 13px */
.day-card-header .day-regen {
  min-height: 40px;
  padding: 0 14px;
  font-size: 13px;
}
@media (max-width: 520px) {
  .day-card-header .day-regen { min-height: 40px; padding: 0 14px; }
}

/* Rete di sicurezza mobile (2026-09-13): nessun elemento sostituito può
   superare la larghezza del contenitore. Un canvas/img con attributi grandi
   può altrimenti allargare il layout viewport e far scorrere la pagina. */
img, canvas, svg, video { max-width: 100%; }

/* ============================================================
   2026-09-13 — Auth email/password, footer legale, paywall
   ============================================================ */

/* Tab del login (Email / Telegram) */
.auth-tabs {
  display: flex;
  gap: var(--sp-2);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.auth-tabs .chip {
  min-height: 40px;
  padding: 0 14px;
  font-weight: 600;
}
/* ATTENZIONE: qui serve --accent-strong ("accent leggibile come testo"), NON
   --accent-ink: quello e' il colore da usare SOPRA un riempimento accent, quindi
   in dark e' quasi nero e in light e' bianco → testo invisibile sulla card
   (bug segnalato da Francesco il 2026-09-13). */
.auth-tabs .chip.active {
  color: var(--accent-strong);
  border-color: var(--accent-line);
  background: var(--accent-soft, rgba(120, 170, 255, .14));
}

/* Link dentro le card di accesso */
.login-card a { color: var(--accent-strong); text-decoration: underline; text-underline-offset: 2px; }
.login-card .row.small { gap: 4px; }

/* Footer legale (app + pagine informative) */
.site-footer {
  max-width: 1080px;
  margin: var(--sp-6, 32px) auto 0;
  padding: var(--sp-4, 16px) var(--sp-4, 16px) 48px;
  border-top: 1px solid var(--line, rgba(255, 255, 255, .08));
  display: flex;
  flex-direction: column;
  gap: var(--sp-3, 12px);
}
.site-footer nav {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 16px;
}
.site-footer nav a {
  color: var(--fg-2);
  text-decoration: none;
  font-size: var(--fs-xs);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}
.site-footer nav a:hover { color: var(--fg); text-decoration: underline; }

/* Link a forma di pulsante (es. "Vai alla pagina di pagamento") */
.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 18px;
  border-radius: var(--r-md, 12px);
  background: var(--accent, #3b7bff);
  /* testo SOPRA l'accent → qui --accent-ink e' corretto (scuro in dark, bianco in light) */
  color: var(--accent-ink);
  font-weight: 620;
  text-decoration: none;
  margin-top: var(--sp-3, 12px);
}
.button-link:hover { filter: brightness(1.08); }

/* Blocchi <details> nelle impostazioni account */
.settings-details {
  margin-top: var(--sp-4, 16px);
  border-top: 1px solid var(--line, rgba(255, 255, 255, .08));
  padding-top: var(--sp-3, 12px);
}
.settings-details > summary {
  cursor: pointer;
  font-weight: 620;
  min-height: 44px;
  display: flex;
  align-items: center;
  list-style: none;
}
.settings-details > summary::-webkit-details-marker { display: none; }
.settings-details > summary::before {
  content: '+';
  display: inline-block;
  width: 18px;
  color: var(--fg-2);
}
.settings-details[open] > summary::before { content: '\2212'; }
#settings-card .flex { display: flex; gap: 8px; flex-wrap: wrap; }
#settings-card button.secondary { min-height: 44px; }
#settings-msg { margin-top: var(--sp-3, 12px); display: block; }
