/* Spese di viaggio — mobile first. Palette: verde = ti devono, rosso = devi. */
:root {
  --bg: #F8FAFC;
  --card: #FFFFFF;
  --fg: #0F172A;
  --muted: #475569;
  --line: #E2E8F0;
  --line-strong: #94A3B8;
  --primary: #047857;
  --primary-hover: #065F46;
  --on-primary: #FFFFFF;
  --pos: #047857;
  --pos-soft: #ECFDF5;
  --neg: #B91C1C;
  --neg-soft: #FEF2F2;
  --focus: #0EA5E9;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
body.lock { overflow: hidden; }

h1, h2, h3 { margin: 0; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
h2 { font-size: 1.1rem; font-weight: 650; }
h3 { font-size: 0.9rem; font-weight: 600; color: var(--muted); }
p { margin: 0; }

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 20px 16px calc(104px + var(--safe-b));
}

.top { display: grid; gap: 6px; margin-bottom: 18px; }
.top .back {
  justify-self: start;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.center { text-align: center; }
.error { color: var(--neg); font-size: 0.9rem; }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.stack { display: grid; gap: 10px; }
.stack-lg { display: grid; gap: 16px; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

.field { display: grid; gap: 6px; border: 0; margin: 0; padding: 0; min-width: 0; }
.field > span, .field legend, .label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
  padding: 0;
}
.field legend { margin-bottom: 6px; }

input {
  width: 100%;
  font: inherit;
  font-size: 16px; /* evita lo zoom automatico su iOS */
  color: var(--fg);
  background: #FFFFFF;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  min-height: 48px;
}
input::placeholder { color: #64748B; }
input:focus-visible, button:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  border-radius: var(--radius-sm);
  min-height: 48px;
  padding: 12px 18px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background-color 150ms ease, border-color 150ms ease;
}
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: #FFFFFF; color: var(--fg); border-color: var(--line-strong); }
.btn.ghost:hover { background: #F1F5F9; }
.btn.danger { background: var(--neg); color: #FFFFFF; }
.btn.danger:hover { background: #991B1B; }
.btn.block { width: 100%; }

.link-btn {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--primary);
  background: none;
  border: 0;
  padding: 8px 0;
  min-height: 44px;
  cursor: pointer;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  flex: none;
}
.icon-btn:hover { background: #F1F5F9; color: var(--fg); }
.icon-btn.del:hover { color: var(--neg); background: var(--neg-soft); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  min-height: 44px;
  padding: 8px 16px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: #FFFFFF;
  color: var(--fg);
  cursor: pointer;
  transition: background-color 150ms ease, color 150ms ease;
}
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: #E2E8F0;
  border-radius: 12px;
  margin-bottom: 16px;
}
.tabs button {
  font: inherit;
  font-weight: 600;
  min-height: 44px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.tabs button[aria-selected="true"] { background: #FFFFFF; color: var(--fg); box-shadow: var(--shadow); }

.big-balance { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.amt { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li + li { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .meta { color: var(--muted); font-size: 0.875rem; }

.day { margin-bottom: 16px; }
.day > h3 { margin: 0 0 6px; text-transform: none; }

.summary-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}
.summary-chip.pos { background: var(--pos-soft); }
.summary-chip.neg { background: var(--neg-soft); }

.empty { text-align: center; padding: 28px 8px; color: var(--muted); }

.fab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 12px 16px calc(12px + var(--safe-b));
  background: linear-gradient(to top, var(--bg) 70%, rgba(248, 250, 252, 0));
  pointer-events: none;
}
.fab-bar .btn { pointer-events: auto; max-width: 480px; margin: 0 auto; display: block; width: 100%; box-shadow: var(--shadow); }

.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity 200ms ease;
}
.sheet-overlay.open { opacity: 1; }
.sheet {
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 8px 16px calc(20px + var(--safe-b));
  transform: translateY(24px);
  transition: transform 200ms ease;
}
.sheet-overlay.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sheet-head h2 { margin-left: 4px; }

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  top: calc(12px + env(safe-area-inset-top, 0px));
  max-width: 448px;
  margin: 0 auto;
  background: var(--fg);
  color: #FFFFFF;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  text-align: center;
  font-size: 0.95rem;
  z-index: 200;
}

.hint { font-size: 0.875rem; color: var(--muted); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

.grow { flex: 1; min-width: 0; }
.grow > p { margin: 0; }
.small-btn { min-height: 44px; padding: 8px 14px; font-size: 0.9rem; flex: none; }
