/* Intasca — "il foglio verde e il quaderno".
   Un foglio verde bosco regge il numero che conta; sotto, un quaderno avorio a righe sottili.
   Corallo solo per gli avvisi. Superfici: piane e tonali, niente ombre. */

:root {
  --paper: #F8F7F2;
  --paper-raised: #FFFEFB;
  --ink: #203B32;
  --muted: #56695F;
  --sage: #E8EFE6;
  --honey: #F2E9D7;
  --coral: #D66B5D;
  --coral-text: #B24436;
  --coral-soft: #F6C9C1;
  --forest-track: #3A5E50;
  --on-forest-muted: #B9CCC1;
  --on-forest-coral: #F2A094;
  --line: rgba(32, 59, 50, 0.14);
  --line-strong: rgba(32, 59, 50, 0.34);

  --r-surface: 24px;
  --r-control: 12px;
  --gutter: 20px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --nav-height: 64px;

  /* Una tinta per categoria: terre e verdi caldi, stessa famiglia della palette. Sempre accompagnate dal nome. */
  --cat-spesa: #2F6B57;
  --cat-carburante: #E0B03A;
  --cat-casa: #5B87A6;
  --cat-salute: #D98C8C;
  --cat-ragazzi: #8CA860;
  --cat-svago: #B8693B;
  --cat-abbigliamento: #9C8F7A;
  --cat-altro: #6B7A72;

  --font: 'Manrope', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

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

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

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 1rem/1.45 var(--font);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  overflow-wrap: anywhere;
}

h1, h2, h3, p, dl, dd, ul, figure { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: inherit; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }

:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.hero :focus-visible { outline-color: var(--honey); }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.skip {
  position: fixed; top: 8px; left: 8px; z-index: 50; padding: 10px 14px; border-radius: var(--r-control);
  background: var(--ink); color: var(--paper); transform: translateY(-200%);
}
.skip:focus { transform: none; }

/* ——— Struttura ——— */

.app { min-height: 100dvh; }
.stage { padding-bottom: calc(var(--nav-height) + var(--safe-bottom) + 40px); }
main { outline: none; }
main > :not(.hero):not(.loading) { padding-inline: var(--gutter); }
body[data-theme='paper'] .stage { padding-top: var(--safe-top); }

.banner {
  margin: 0; padding: 8px var(--gutter); background: var(--honey); font-size: 0.8125rem; font-weight: 600;
}
.banner a { font-weight: 700; }
#banners > .banner:first-child { padding-top: calc(var(--safe-top) + 8px); }
.stage:has(.banner) .hero { padding-top: 16px; }

/* ——— Navigazione ——— */

.nav {
  position: fixed; z-index: 20; inset: auto 0 0 0;
  background: var(--paper); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-bottom);
}
.nav ul { display: grid; grid-template-columns: repeat(5, 1fr); align-items: end; max-width: 560px; margin: 0 auto; }
.nav-brand, .nav-settings, .nav-add-long { display: none; }

.nav-link {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  min-height: var(--nav-height); text-decoration: none; color: var(--muted); font-size: 0.75rem; font-weight: 600;
}
.nav-link svg, .nav-add-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.nav-link[aria-current='page'] { color: var(--ink); font-weight: 800; }
.nav-link[aria-current='page']::before {
  content: ''; position: absolute; top: 0; left: 50%; width: 28px; height: 3px; margin-left: -14px; background: var(--ink);
}

.nav-add { display: flex; justify-content: center; }
.nav-add-btn {
  display: grid; place-items: center; width: 62px; height: 62px; margin-top: -22px;
  border: 0; border-radius: 50%; background: var(--ink); color: var(--paper);
  box-shadow: 0 0 0 6px var(--paper); /* anello pieno, non un'ombra: stacca il pulsante dalla barra */
}
.nav-add-btn svg { width: 28px; height: 28px; stroke-width: 2.4; }
.nav-add-btn span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.nav-add-btn:focus-visible { outline-offset: 6px; }
.nav-add-btn:active { transform: scale(0.96); }

/* ——— Bottoni e link ——— */

.btn {
  display: inline-flex; align-items: center; justify-content: center; min-height: 52px; padding: 0 22px;
  border: 1.5px solid transparent; border-radius: 14px; font-weight: 700; text-decoration: none; text-align: center;
}
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-light { background: var(--paper); color: var(--ink); }
.btn-quiet { background: transparent; border-color: var(--line-strong); color: var(--ink); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn:active:not(:disabled) { transform: translateY(1px); }

.link-btn {
  min-height: 44px; padding: 0 4px; border: 0; background: none; font-weight: 600; font-size: 0.9375rem;
  text-decoration: underline; text-underline-offset: 3px;
}

.inline-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin-top: 20px; }

/* ——— Foglio verde (hero) ——— */

.hero {
  padding: calc(var(--safe-top) + 14px) var(--gutter) 28px;
  background: var(--ink); color: var(--paper);
  border-radius: 0 0 28px 28px;
}

.masthead { display: grid; grid-template-columns: 1fr auto auto; align-items: center; column-gap: 12px; }
.wordmark { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.04em; }
.masthead-month { font-size: 0.875rem; font-weight: 600; color: var(--on-forest-muted); text-transform: capitalize; }
.avatar {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%;
  background: var(--honey); color: var(--ink); font-weight: 800; text-decoration: none;
}
.greeting { grid-column: 1 / -1; margin-top: 14px; color: var(--on-forest-muted); font-size: 1rem; }

.label { margin: 28px 0 0; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; color: var(--on-forest-muted); }
.label-ink { margin: 0; color: var(--muted); }

.hero-amount {
  margin: 2px 0 4px; font-size: clamp(3rem, 15.5vw, 4.5rem); font-weight: 800; letter-spacing: -0.04em; line-height: 1.04;
  white-space: nowrap;
}
.hero-sub { color: var(--on-forest-muted); font-size: 0.9375rem; }

.meter { height: 8px; margin-top: 20px; border-radius: 999px; background: var(--forest-track); overflow: hidden; }
.meter span { display: block; height: 100%; border-radius: 999px; background: var(--paper); }
.meter-legend { display: flex; justify-content: space-between; gap: 12px; margin-top: 8px; font-size: 0.8125rem; font-weight: 600; color: var(--on-forest-muted); }

.notice {
  margin-top: 18px; padding: 10px 14px; border-radius: var(--r-control); background: var(--honey); color: var(--ink);
  font-size: 0.875rem; font-weight: 600;
}
.notice a { font-weight: 800; }

.hero-low .meter span { background: var(--honey); }
.hero-over .hero-amount { color: var(--on-forest-coral); }
.hero-over .label { color: var(--on-forest-coral); }
.hero-over .meter span { background: var(--coral); }
.hero-over .meter-legend span:first-child { color: var(--on-forest-coral); }

.hero-setup .hero-heading { margin: 28px 0 10px; font-size: 1.875rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.12; }
.hero-setup .hero-sub { max-width: 46ch; margin-bottom: 22px; }

.hero-loading { min-height: 280px; }
.skeleton { background: var(--forest-track); border-radius: 8px; animation: pulse 1.4s ease-in-out infinite; }
.skeleton-big { width: 70%; height: 56px; margin-top: 56px; }
.skeleton-line { width: 45%; height: 16px; margin-top: 16px; }
@keyframes pulse { 50% { opacity: 0.55; } }

/* ——— Cifre secondarie ——— */

.figures { display: grid; grid-template-columns: 1fr 1fr; padding-block: 24px 8px; }
.figure { padding-right: 16px; }
.figure + .figure { padding: 0 0 0 20px; border-left: 1px solid var(--line); }
.figure-label { font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.figure-value { margin: 4px 0 6px; font-size: clamp(1.4rem, 6.6vw, 1.875rem); font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; white-space: nowrap; }
.figure-none { color: var(--muted); }
.figure-foot { font-size: 0.8125rem; line-height: 1.4; color: var(--muted); }

/* ——— Liste a righe ——— */

.recent { padding-top: 20px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.section-head h2 { font-size: 1.125rem; font-weight: 800; letter-spacing: -0.01em; }
.section-head a { font-size: 0.9375rem; font-weight: 700; padding: 8px 0 8px 12px; }

.rows { margin-top: 6px; }
.row {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 16px; width: 100%; min-height: 60px; padding: 12px 0;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left;
}
.rows li:last-child .row { border-bottom: 0; }
.row-main { display: grid; gap: 2px; min-width: 0; }
.row-title { font-weight: 700; }
.row-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 0 6px; font-size: 0.8125rem; color: var(--muted); }
.row-amount { font-weight: 700; white-space: nowrap; }
.who {
  display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 50%;
  background: var(--sage); color: var(--ink); font-size: 0.6875rem; font-weight: 800;
}
.row:hover { background: var(--sage); }
.empty { padding: 20px 0; color: var(--muted); max-width: 52ch; }
.empty a { font-weight: 700; color: var(--ink); }

/* ——— Pagine interne ——— */

.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 4px 16px; padding-top: 22px; }
.page-head h1 { font-size: 1.875rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
.page-lead { margin: 8px 0 20px; max-width: 60ch; color: var(--muted); font-size: 0.9375rem; }
.page-lead strong { color: var(--ink); }

.month-switch { display: inline-flex; align-items: center; }
.month-switch span { min-width: 8.5em; text-align: center; font-weight: 700; text-transform: capitalize; }
.month-switch a, .month-switch-end {
  display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; font-size: 1.5rem; text-decoration: none; line-height: 1;
}
.month-switch a:hover { background: var(--sage); }
.month-switch .month-switch-end { min-width: 44px; opacity: 0.25; }

.filters { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; padding-bottom: 12px; }
.filters label { display: grid; gap: 4px; font-size: 0.8125rem; font-weight: 600; color: var(--muted); }

.list-total { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0 4px; color: var(--muted); font-size: 0.875rem; }
.list-total strong { color: var(--ink); font-size: 1.125rem; font-weight: 800; }
.day { padding-top: 14px; }
.day h3 { display: flex; justify-content: space-between; padding-bottom: 4px; border-bottom: 1.5px solid var(--ink); font-size: 0.8125rem; font-weight: 700; color: var(--muted); }
.day h3 span:first-child { display: inline-block; color: var(--ink); }
.day h3 span:first-child::first-letter { text-transform: uppercase; }
.day .rows { margin-top: 0; }

/* ——— Fondo ——— */

.fund-top { margin-top: 20px; padding: 24px var(--gutter) 28px; background: var(--sage); }
.big-amount { margin: 2px 0 8px; font-size: clamp(2.5rem, 13vw, 3.75rem); font-weight: 800; letter-spacing: -0.04em; line-height: 1.05; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 18px; }
.pair dt { font-size: 0.8125rem; font-weight: 600; color: var(--muted); }
.pair dd { font-size: 1.5rem; font-weight: 800; letter-spacing: -0.02em; }
.meter-ink { background: rgba(32, 59, 50, 0.16); margin-top: 20px; }
.meter-ink span { background: var(--ink); }

.block { padding-top: 28px; }
.block-first { padding-top: 20px; }
.block-title { margin-bottom: 8px; font-size: 1.125rem; font-weight: 800; letter-spacing: -0.01em; }

.table { width: 100%; margin-top: 6px; border-collapse: collapse; }
.table th, .table td { padding: 12px 0; border-bottom: 1px solid var(--line); }
.table thead th { padding-top: 4px; font-size: 0.75rem; font-weight: 700; color: var(--muted); text-align: left; }
.table tbody th { text-align: left; font-weight: 600; text-transform: capitalize; }
.table .num { text-align: right; font-weight: 700; white-space: nowrap; }
.table thead .num { font-weight: 700; }

/* ——— Report ——— */

.ledger > div { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.ledger dt small { display: block; font-size: 0.8125rem; color: var(--muted); }
.ledger dd { font-weight: 700; white-space: nowrap; }
.ledger .ledger-total { border-bottom: 0; border-top: 1.5px solid var(--ink); background: var(--sage); padding-inline: 12px; margin-inline: -12px; border-radius: 0; }
.ledger .ledger-total dt { font-weight: 800; }
.ledger .ledger-total dd { font-size: 1.25rem; font-weight: 800; }
.ledger-over dd { color: var(--coral-text); }
.fine { margin-top: 14px; font-size: 0.8125rem; color: var(--muted); max-width: 62ch; }
.fine strong { color: var(--ink); }

.bars { display: grid; gap: 14px; }
.bars li { display: grid; grid-template-columns: 1fr auto; column-gap: 12px; row-gap: 6px; align-items: baseline; }
.bar-name { font-weight: 600; }
.bar-amount { font-weight: 700; }
.bar-track { height: 8px; border-radius: 999px; background: var(--sage); align-self: center; overflow: hidden; }
.bar-track span { display: block; height: 100%; background: var(--ink); border-radius: 999px; }
.bar-share { min-width: 3ch; text-align: right; font-size: 0.8125rem; color: var(--muted); }
.compare { margin-top: 18px; color: var(--muted); font-size: 0.9375rem; }
.compare strong { color: var(--ink); }

/* ——— Moduli ——— */

.field { display: grid; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field > label, .field > legend, .edit-row label, .filters label { font-size: 0.875rem; font-weight: 700; }
.field > legend { padding: 0; margin-bottom: 6px; }
.optional { font-weight: 500; color: var(--muted); }
.hint { font-size: 0.8125rem; color: var(--muted); max-width: 62ch; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

input:not([type='radio']):not([type='checkbox']), select {
  width: 100%; min-height: 48px; padding: 0 14px; border: 1px solid var(--line-strong); border-radius: var(--r-control);
  background: var(--paper-raised); font-size: 1rem;
}
input[type='date'] { min-width: 0; }
select { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5l5-5' fill='none' stroke='%23203B32' stroke-width='1.8'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 14px center; background-size: 12px; }
input:not([type='radio']):not([type='checkbox']):focus-visible, select:focus-visible { outline-offset: 0; border-color: var(--ink); }

.amount-input { position: relative; }
.amount-input input { padding-right: 44px; min-height: 72px; font-size: 2.5rem; font-weight: 800; letter-spacing: -0.03em; }
.amount-input > span { position: absolute; right: 16px; top: 50%; transform: translateY(-50%); font-size: 1.5rem; font-weight: 800; color: var(--muted); pointer-events: none; }
.amount-input-sm input { min-height: 52px; font-size: 1.25rem; letter-spacing: 0; }
.amount-input-sm > span { font-size: 1.125rem; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; }
.chip input, .segmented input, .check input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.chip span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 14px; border: 1px solid var(--line-strong);
  border-radius: var(--r-control); background: var(--paper-raised); font-size: 0.9375rem; font-weight: 600; cursor: pointer;
}
.chip input:checked + span { background: var(--ink); border-color: var(--ink); color: var(--paper); }
.chip input:focus-visible + span, .segmented input:focus-visible + span, .check input:focus-visible + span { outline: 3px solid var(--ink); outline-offset: 2px; }

.segmented { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--line-strong); border-radius: var(--r-control); background: var(--paper-raised); }
.segmented label { position: relative; }
.sheet-form .field-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); }
@media (max-width: 400px) { .sheet-form .field-row { grid-template-columns: 1fr; } }
.segmented span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: grid; place-items: center; min-height: 46px; padding: 0 10px; border-radius: calc(var(--r-control) - 1px); font-weight: 700; cursor: pointer; text-align: center; }
.segmented input:checked + span { background: var(--ink); color: var(--paper); }

.form-error { padding: 10px 14px; border-radius: var(--r-control); background: var(--coral-soft); color: #5B1D15; font-size: 0.875rem; font-weight: 600; }
.form-error[hidden] { display: none; }

/* Impostazioni del mese */
.settings { display: grid; gap: 4px; max-width: 760px; }
.settings .block .field + .field { margin-top: 20px; }
.settings .hint { margin-bottom: 10px; }
.edit-list { margin-bottom: 12px; }
.edit-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; align-items: end; padding: 14px 0; border-bottom: 1px solid var(--line); }
.edit-row label { display: grid; gap: 4px; min-width: 0; }
.edit-row .grow { grid-column: 1 / -1; }
.edit-row .link-btn { grid-column: 1 / -1; justify-self: end; min-height: 36px; }
.edit-row .paid-amount { grid-column: 1 / -1; }
.edit-row .paid-amount[hidden] { display: none; }
.check { position: relative; display: flex !important; align-items: center; min-height: 48px; }
.check span { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; }
.check span::before {
  content: ''; width: 24px; height: 24px; border: 1.5px solid var(--ink); border-radius: 6px; background: var(--paper-raised);
}
.check input:checked + span::before {
  background: var(--ink) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6 12.5 4 4 8-9' fill='none' stroke='%23F8F7F2' stroke-width='2.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / 18px no-repeat;
}
.preview { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 24px; padding: 14px 16px; border-radius: var(--r-control); background: var(--sage); font-weight: 600; }
.preview strong { font-size: 1.375rem; font-weight: 800; letter-spacing: -0.02em; }
.preview .negative { color: var(--coral-text); }
.settings .form-error { margin-top: 12px; }
.settings > .btn { margin-top: 16px; width: 100%; }

/* ——— Torta delle spese ——— */

.spending { padding-top: 26px; }
.spend-sub { margin-top: 2px; font-size: 0.8125rem; color: var(--muted); }
.donut { width: min(220px, 62vw); margin: 14px auto 6px; }
.donut svg { display: block; width: 100%; height: auto; overflow: visible; }
.donut-track { stroke: var(--sage); }
.slice { stroke: var(--muted); }
.donut-label { font-size: 11px; font-weight: 700; fill: var(--muted); letter-spacing: 0.08em; text-transform: uppercase; }
.donut-total { font-size: 20px; font-weight: 800; fill: var(--ink); letter-spacing: -0.03em; }
.donut-eur { font-size: 13px; font-weight: 700; fill: var(--muted); }
.legend { margin-top: 10px; }
.legend li { display: grid; grid-template-columns: auto 1fr auto 3.2ch; align-items: center; column-gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); font-size: 0.9375rem; }
.legend li:last-child { border-bottom: 0; }
.legend-name { font-weight: 600; min-width: 0; }
.legend-amount { font-weight: 700; white-space: nowrap; }
.legend-share { text-align: right; font-size: 0.8125rem; color: var(--muted); }
.dot { width: 12px; height: 12px; border-radius: 4px; background: var(--muted); }
.cat-spesa { stroke: var(--cat-spesa); background: var(--cat-spesa); }
.cat-carburante { stroke: var(--cat-carburante); background: var(--cat-carburante); }
.cat-casa { stroke: var(--cat-casa); background: var(--cat-casa); }
.cat-salute { stroke: var(--cat-salute); background: var(--cat-salute); }
.cat-ragazzi { stroke: var(--cat-ragazzi); background: var(--cat-ragazzi); }
.cat-svago { stroke: var(--cat-svago); background: var(--cat-svago); }
.cat-abbigliamento { stroke: var(--cat-abbigliamento); background: var(--cat-abbigliamento); }
.cat-altro { stroke: var(--cat-altro); background: var(--cat-altro); }
circle.slice { background: none; }

/* ——— Obiettivo ——— */

.goal-when { margin-top: -2px; font-size: 0.875rem; color: var(--muted); }
.goal-amounts { margin-top: 10px; display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 8px; }
.goal-amounts strong { font-size: 1.75rem; font-weight: 800; letter-spacing: -0.03em; }
.goal-amounts span { color: var(--muted); font-weight: 600; }
.meter-legend-ink { color: var(--muted); }
.goal-sentence { margin-top: 12px; max-width: 56ch; font-size: 0.9375rem; }
.goal-behind, .goal-overdue { padding: 10px 14px; border-radius: var(--r-control); background: var(--honey); font-weight: 600; }
.goal-reached { padding: 10px 14px; border-radius: var(--r-control); background: var(--sage); font-weight: 700; }

/* ——— Tira per aggiornare ——— */

html { overscroll-behavior-y: contain; }
.pull {
  position: fixed; z-index: 30; left: 50%; top: calc(var(--safe-top) + 8px);
  padding: 8px 16px; border: 1px solid var(--line-strong); border-radius: 999px;
  background: var(--paper-raised); color: var(--ink); font-size: 0.875rem; font-weight: 700; white-space: nowrap;
  transform: translate(-50%, calc(var(--pull, 0px) - 64px)); opacity: 0; pointer-events: none;
}
.pull-visible { opacity: 1; transition: opacity 0.15s; }

/* ——— Scontrino ——— */

.scan { display: grid; gap: 6px; }
.scan-pick { position: relative; display: block; }
.scan-pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.scan-pick .btn { width: 100%; cursor: pointer; }
.scan-pick input:focus-visible + .btn { outline: 3px solid var(--ink); outline-offset: 2px; }
.scan-pick input:disabled + .btn { opacity: 0.55; cursor: progress; }
.scan .hint:empty { display: none; }

/* ——— Pannello dal basso ——— */

dialog#sheet {
  width: 100%; max-width: 600px; max-height: min(94dvh, var(--visible-height, 94dvh));
  margin: auto auto var(--keyboard, 0px); padding: 0; border: 0; border-radius: var(--r-surface) var(--r-surface) 0 0;
  background: var(--paper); color: var(--ink); overflow-y: auto; overscroll-behavior: contain;
}
dialog#sheet[open] { animation: rise 0.22s ease-out; }
dialog#sheet::backdrop { background: rgba(32, 59, 50, 0.5); }
@keyframes rise { from { transform: translateY(24px); opacity: 0; } }

.sheet-form { display: grid; gap: 18px; padding: 0 var(--gutter); }
.sheet-head { position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between; padding: 16px 0 8px; background: var(--paper); }
.sheet-head h2 { font-size: 1.25rem; font-weight: 800; letter-spacing: -0.02em; }
.sheet-note { margin-top: -6px; font-size: 0.875rem; color: var(--muted); }
.sheet-actions { position: sticky; bottom: 0; display: grid; gap: 8px; padding: 10px 0 calc(var(--safe-bottom) + 16px); background: var(--paper); }
.sheet-actions .btn { min-height: 56px; font-size: 1.0625rem; }
.sheet-actions .btn-quiet { min-height: 48px; border-color: transparent; color: var(--coral-text); text-decoration: underline; text-underline-offset: 3px; }

/* ——— Accesso ——— */

body[data-theme='login'] .nav { display: none; }
body[data-theme='login'] .app { display: block; }
.login { max-width: 400px; margin: 0 auto; padding: calc(var(--safe-top) + 12vh) var(--gutter) 40px !important; }
.login .wordmark { font-size: 1.75rem; margin-bottom: 40px; }
.login h1 { font-size: 1.875rem; font-weight: 800; letter-spacing: -0.03em; }
.login form { display: grid; gap: 18px; margin-top: 8px; }

/* ——— Conferme ——— */

.toast {
  position: fixed; z-index: 40; left: 12px; right: 12px; bottom: calc(var(--nav-height) + var(--safe-bottom) + 18px);
  display: flex; align-items: center; justify-content: space-between; gap: 12px; max-width: 460px; margin: 0 auto;
  padding: 6px 6px 6px 16px; border-radius: var(--r-control); background: var(--ink); color: var(--paper); font-size: 0.9375rem; font-weight: 600;
}
.toast[hidden] { display: none; }
.toast button { min-height: 44px; padding: 0 14px; border: 0; border-radius: 8px; background: none; color: var(--honey); font-weight: 800; text-decoration: underline; text-underline-offset: 3px; }
.toast-error { background: var(--coral-soft); color: #5B1D15; padding-block: 12px; }

.fatal { max-width: 480px; margin: 20vh auto 0; padding: 0 var(--gutter); }
.fatal h1 { font-size: 1.5rem; margin-bottom: 8px; }
.fatal p { margin-bottom: 20px; color: var(--muted); }

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

/* ——— Tablet ——— */

@media (min-width: 640px) {
  :root { --gutter: 32px; }
  .hero { padding-inline: var(--gutter); }
  dialog#sheet { margin: auto; border-radius: var(--r-surface); }
  .edit-row { grid-template-columns: 2fr 1fr 1fr auto; }
  .edit-row .grow { grid-column: auto; }
  .edit-row .link-btn { grid-column: auto; }
  .edit-row[data-fixed] { grid-template-columns: 2fr 1fr auto auto; }
  .edit-row[data-fixed] .paid-amount { grid-column: 2 / 4; }
  .edit-row[data-fixed] .link-btn { grid-column: 4; grid-row: 1; }
  .toast { bottom: calc(var(--nav-height) + var(--safe-bottom) + 24px); }
}

/* ——— Desktop: barra laterale e composizione a due colonne ——— */

@media (min-width: 960px) {
  :root { --gutter: 0px; }

  .app { display: grid; grid-template-columns: 252px minmax(0, 1fr); }
  .stage { max-width: 1120px; width: 100%; padding: 36px 56px 72px; }
  body[data-theme='paper'] .stage { padding-top: 36px; }
  main > :not(.hero):not(.loading) { padding-inline: 0; }

  .nav {
    position: sticky; top: 0; inset: auto; height: 100dvh; display: flex; flex-direction: column;
    padding: 32px 20px 28px; border-top: 0; border-right: 1px solid var(--line);
  }
  .nav-brand { display: block; margin: 0 12px 28px; font-size: 1.75rem; font-weight: 800; letter-spacing: -0.04em; }
  .nav ul { display: flex; flex-direction: column; gap: 4px; max-width: none; margin: 0; }
  .nav-add { order: -1; margin-bottom: 16px; }
  .nav-add-btn {
    display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 52px; margin: 0;
    border-radius: 14px; box-shadow: none; font-weight: 700; font-size: 1rem;
  }
  .nav-add-btn svg { width: 22px; height: 22px; }
  .nav-add-btn span { position: static; width: auto; height: auto; overflow: visible; clip: auto; }
  .nav-add-long { display: inline; }
  .nav-add-btn:focus-visible { outline-offset: 3px; }
  .nav-link { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 46px; padding: 0 12px; border-radius: var(--r-control); font-size: 1rem; }
  .nav-link[aria-current='page'] { background: var(--sage); }
  .nav-link[aria-current='page']::before { display: none; }
  .nav-settings { display: block; margin: auto 12px 0; font-size: 0.875rem; font-weight: 600; color: var(--muted); }
  .nav-settings:hover { color: var(--ink); }

  /* Home: foglio verde a sinistra, cifre secondarie nel pannello salvia a destra */
  body[data-theme='forest'] main {
    display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(260px, 1fr); grid-template-rows: auto 1fr; gap: 0 40px; align-items: start;
  }
  body[data-theme='forest'] .stage { padding-top: 36px; }
  .hero { padding: 28px 36px 36px; border-radius: var(--r-surface); grid-column: 1; grid-row: 1; }
  .stage:has(.banner) .hero { padding-top: 28px; }
  .hero .wordmark { display: none; }
  .masthead { grid-template-columns: 1fr auto; }
  .hero-amount { font-size: clamp(4rem, 7vw, 5.75rem); }
  .side { grid-column: 2; grid-row: 1 / span 2; align-self: start; padding: 32px 28px 28px; background: var(--sage); border-radius: var(--r-surface); }
  .figures { grid-template-columns: 1fr; gap: 28px; padding: 0; }
  .figure, .figure + .figure { padding: 0; border: 0; }
  .figure + .figure { padding-top: 28px; border-top: 1px solid var(--line-strong); }
  .figure-value { font-size: 2.5rem; }
  .figure-foot { font-size: 0.875rem; }
  .recent { grid-column: 1; grid-row: 2; padding-top: 32px; }
  .spending { margin-top: 28px; padding-top: 28px; border-top: 1px solid var(--line-strong); }
  .hero-setup { grid-column: 1 / -1; }
  .hero-setup + .recent { grid-column: 1 / -1; }

  .page-head h1 { font-size: 2.25rem; }
  .page-head { padding-top: 0; }
  .fund-top { margin-top: 24px; padding: 32px 36px 36px; border-radius: var(--r-surface); max-width: 760px; }
  .block { max-width: 760px; }
  .filters { max-width: 480px; }
  #expense-list, .rows { max-width: 760px; }
  .toast { left: calc(252px + 12px); right: 12px; bottom: 24px; margin: 0 auto 0 0; }
}
