/* Palette calda e sempre chiara: sfondo bianco/crema, arancio corallo, magenta.
   Verde = papà deve, rosso = devi tu, ambra = ricorrenti. */
:root {
  --bg: #fbf6f0;
  --card: #ffffff;
  --text: #2a1f17;
  --muted: #8b7d70;
  --line: rgba(120, 90, 60, 0.13);
  --bubble: #f7efe6;
  --accent: #ee6331;
  --accent-ink: #ffffff;
  --accent-soft: rgba(238, 99, 49, 0.12);
  --pos: #11845a;
  --neg: #d8344f;
  --neg-soft: rgba(216, 52, 79, 0.12);
  --rec: #f2a12a;
  --rec-bg: #fff7e8;
  --rec-soft: rgba(242, 161, 42, 0.2);
  --rec-ink: #9a5800;
  --ok: #11845a;
  --ok-soft: rgba(17, 132, 90, 0.12);
  --warn: #b45309;
  --warn-soft: rgba(245, 158, 11, 0.18);
  --hero: linear-gradient(135deg, #f58a3c 0%, #e8554f 52%, #b93a7d 100%);
  --hero-neg: linear-gradient(135deg, #7c5cf0 0%, #c2449a 100%);
  --hero-shadow: 0 12px 30px rgba(232, 85, 79, 0.28);
  --shadow: 0 1px 2px rgba(80, 50, 20, 0.05), 0 8px 24px rgba(80, 50, 20, 0.07);
  --radius: 18px;
  color-scheme: light;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; height: 100%; }

/* La pagina non scorre mai: scorre solo la parte centrale, così la barra in basso resta ferma
   anche con l'effetto elastico dell'iPhone. */
body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

#app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 560px; margin: 0 auto;
}
main {
  flex: 1; min-height: 0;
  padding: 0 16px 28px;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain;
}

/* ---- barra in alto ---- */
.top {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px;
  background: var(--bg);
}
.top h1 { flex: 1; margin: 0; font-size: 21px; font-weight: 800; text-align: center; letter-spacing: -0.02em; }
.top-side, .icon-btn { width: 44px; height: 44px; flex: none; }
.icon-btn {
  display: grid; place-items: center;
  border: 0; border-radius: 14px; background: transparent; color: var(--accent);
}
.icon-btn:disabled { color: var(--muted); opacity: 0.3; }

.icon {
  width: 22px; height: 22px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* ---- card e totale ---- */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 16px; margin-bottom: 16px; }
.card h3 { margin: 0; font-size: 17px; }

.hero {
  position: relative; overflow: hidden;
  margin-top: 4px; padding: 20px;
  border-radius: 24px; background: var(--hero); color: #ffffff; box-shadow: var(--hero-shadow);
}
.hero.neg { background: var(--hero-neg); }
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%; background: rgba(255, 255, 255, 0.12); pointer-events: none;
}
.hero::before { width: 190px; height: 190px; right: -60px; top: -80px; }
.hero::after { width: 120px; height: 120px; right: 70px; bottom: -80px; background: rgba(255, 255, 255, 0.08); }
.hero-top { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hero-label { font-size: 15px; font-weight: 700; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }
.hero-amount {
  position: relative; margin: 6px 0 4px;
  font-size: 46px; font-weight: 800; letter-spacing: -0.02em; font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}
.hero-sub { position: relative; max-width: 80%; font-size: 14px; opacity: 0.92; }
.hero-emoji {
  position: absolute; right: 18px; top: 54px;
  font-size: 54px; line-height: 1; transform: rotate(-8deg);
  filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.18)); pointer-events: none;
}
.hero .chip { background: rgba(255, 255, 255, 0.24); color: #ffffff; }

.chip {
  display: inline-block; padding: 3px 10px; border-radius: 999px; white-space: nowrap;
  font-size: 12px; font-weight: 700; background: var(--accent-soft); color: var(--accent);
}
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.neg { background: var(--neg-soft); color: var(--neg); }

.pill {
  display: inline-flex; align-items: center; gap: 3px;
  padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap;
}
.pill.rec { background: var(--rec-soft); color: var(--rec-ink); }

/* ---- bottoni ---- */
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 16px; border: 0; border-radius: 14px;
  background: var(--card); color: var(--accent); font-weight: 700; box-shadow: var(--shadow);
}
.btn .icon { width: 18px; height: 18px; stroke-width: 2.4; }
.btn.primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 6px 16px rgba(238, 99, 49, 0.28); }
.btn.danger { color: var(--neg); }
.btn.block { width: 100%; margin-top: 12px; }
.btn.grow { flex: 1; white-space: nowrap; }
.btn.full { flex-basis: 100%; }
.btn:disabled, .btn.busy { opacity: 0.55; }
.link { border: 0; background: transparent; color: var(--accent); font-weight: 700; padding: 10px 0 10px 16px; }

/* ---- liste ---- */
.section-title {
  margin: 22px 4px 8px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted);
}
.list { overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 64px;
  padding: 10px 16px; border: 0; background: transparent; text-align: left;
}
.row + .row { border-top: 1px solid var(--line); }
button.row:active, .row-tap:active { filter: brightness(0.96); }
.row.rec { background: var(--rec-bg); box-shadow: inset 4px 0 0 var(--rec); }
.row.carry .row-desc { color: var(--muted); font-style: italic; font-weight: 500; }
.row.off .row-main, .row.off .bubble { opacity: 0.45; }
.bubble {
  display: grid; place-items: center; flex: none; width: 42px; height: 42px;
  border-radius: 14px; background: var(--bubble); font-size: 22px; line-height: 1;
}
.row.rec .bubble { background: var(--rec-soft); }
.row-main { flex: 1; min-width: 0; }
.row-tap { border: 0; background: transparent; text-align: left; padding: 0; }
.row-desc { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 3px; color: var(--muted); font-size: 13px; }
.row-amt { font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.empty { padding: 20px 12px; color: var(--muted); text-align: center; font-size: 15px; }
.intro { margin: 4px 4px 12px; color: var(--muted); font-size: 15px; }


/* ---- barra in basso ---- */
.tabs {
  flex: none; display: flex; justify-content: space-around;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--card); border-top: 1px solid var(--line);
}
.tab {
  flex: 1; max-width: 140px; display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 2px 0; border: 0; background: transparent; color: var(--muted); font-size: 11px; font-weight: 700;
}
.tab-ico { display: grid; place-items: center; width: 58px; height: 30px; border-radius: 999px; transition: background 0.2s; }
.tab.active { color: var(--accent); }
.tab.active .tab-ico { background: var(--accent-soft); }

/* ---- pannelli dal basso ---- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(20, 10, 5, 0); transition: background 0.25s;
}
.overlay.open { background: rgba(20, 10, 5, 0.45); }
.sheet {
  width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom));
  background: var(--bg); border-radius: 24px 24px 0 0;
  transform: translateY(100%); transition: transform 0.25s ease;
}
.overlay.open .sheet { transform: none; }
.sheet-head {
  position: sticky; top: -8px; z-index: 1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 0 4px; background: var(--bg);
}
.sheet-head h3 { margin: 0; font-size: 19px; font-weight: 800; }

/* ---- moduli ---- */
.field { margin-top: 14px; }
.field-label { display: block; margin: 0 4px 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.input {
  display: block; width: 100%; min-height: 48px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card);
  font-size: 17px; -webkit-appearance: none; appearance: none;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.input.amount { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; }
input[type="date"].input::-webkit-date-and-time-value { text-align: left; }

.seg { display: flex; gap: 3px; padding: 3px; border-radius: 14px; background: var(--line); }
.seg-btn {
  flex: 1; min-height: 40px; border: 0; border-radius: 11px; background: transparent;
  font-size: 15px; font-weight: 700; color: var(--text);
}
.seg-btn.on { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.chip-btn { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); font-size: 14px; }
.note { margin: 14px 4px 0; color: var(--muted); font-size: 14px; }

.emoji-pick {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 8px 14px 8px 8px;
  border: 1px solid var(--line); border-radius: 14px; background: var(--card); text-align: left;
}
.emoji-now { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 12px; background: var(--bubble); font-size: 28px; }
.emoji-text { display: flex; flex-direction: column; font-weight: 700; }
.emoji-text small { color: var(--muted); font-size: 13px; font-weight: 500; }
.emoji-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 4px;
  margin-top: 8px; padding: 8px; border: 1px solid var(--line); border-radius: 14px; background: var(--card);
}
.emoji-opt { height: 44px; border: 0; border-radius: 10px; background: transparent; font-size: 24px; }
.emoji-opt.on { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.emoji-opt.auto { grid-column: span 2; font-size: 13px; font-weight: 800; color: var(--accent); }

.switch {
  position: relative; flex: none; width: 51px; height: 31px; margin: 0;
  border-radius: 999px; background: var(--line); cursor: pointer;
  -webkit-appearance: none; appearance: none; transition: background 0.2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px;
  border-radius: 50%; background: #ffffff; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25); transition: transform 0.2s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }
.switch-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 16px; padding: 10px 14px; border-radius: 14px; background: var(--card); font-weight: 700;
}

/* ---- accesso ---- */
.auth {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 24px 24px; text-align: center;
}
.auth .logo { width: 88px; height: 88px; border-radius: 22px; box-shadow: var(--hero-shadow); }
.auth h1 { margin: 16px 0 4px; font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.auth .form { width: 100%; max-width: 340px; margin-top: 8px; text-align: left; }
.muted { color: var(--muted); }
.who-pick { display: flex; gap: 12px; width: 100%; max-width: 340px; margin: 12px 0; }
.pick {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 18px 8px;
  border: 2px solid transparent; border-radius: var(--radius); background: var(--card);
  box-shadow: var(--shadow); font-weight: 800;
}
.pick.on { border-color: var(--accent); }
.pick small { color: var(--muted); font-size: 12px; font-weight: 500; }
.pick:disabled { opacity: 0.6; }
.avatar {
  display: grid; place-items: center; flex: none; width: 48px; height: 48px; border-radius: 50%;
  background: var(--hero); color: #ffffff; font-size: 20px; font-weight: 800;
}
.who { display: flex; align-items: center; gap: 14px; }
.who-name { font-size: 18px; font-weight: 800; }
.steps { margin: 8px 0 0; padding-left: 20px; }
.steps li { margin: 6px 0; }

/* ---- avvisi ---- */
.toast {
  position: fixed; left: 50%; z-index: 50; bottom: calc(92px + env(safe-area-inset-bottom));
  max-width: calc(100% - 32px); padding: 12px 18px; border-radius: 16px;
  background: #2a1f17; color: #ffffff; font-size: 15px; font-weight: 700; text-align: center;
  opacity: 0; pointer-events: none; transform: translate(-50%, 20px); transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--neg); color: #ffffff; }
.toast.ok { background: var(--pos); color: #ffffff; }
