@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz,wght@9..144,400;9..144,600;9..144,700&family=Karla:wght@400;500;600;700&display=swap');

:root {
  color-scheme: light dark;
  --cream: #faf5ec;
  --paper: #fffbf4;
  --ink: #4a3a2f;
  --ink-soft: #8a7768;
  --line: #e8dbc6;
  --terracotta: #c1653f;
  --terracotta-dark: #a24f2f;
  --sage: #7c8f5c;
  --sage-dark: #5f7245;
  --rust: #b5482a;
  --gold: #cf9d4e;
  --shadow: 0 2px 10px rgba(90, 62, 34, 0.08);
  --radius: 14px;
}

/* Tema scuro: stessa grammatica "boho vintage", valori su fondo scuro caldo.
   Si attiva con <html data-theme="dark"> (scelta salvata sul dispositivo,
   default = preferenza di sistema); il boot anti-flash sta in theme-boot.js. */
[data-theme="dark"] {
  --cream: #1c1611;
  --paper: #262019;
  --ink: #f1e7d8;
  --ink-soft: #c2b3a0;
  --line: #3a3128;
  --terracotta: #d97e56;
  --terracotta-dark: #e79470;
  --sage: #a3b57e;
  --sage-dark: #bfce9e;
  --rust: #e88a6f;
  --gold: #dcae66;
  --shadow: 0 2px 10px rgba(0, 0, 0, 0.28);
}

html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }

/* Fondi chiari hardcoded che in tema scuro diventerebbero illeggibili. */
[data-theme="dark"] .error-message,
[data-theme="dark"] .badge.overdue,
[data-theme="dark"] .billing-banner.danger { background: #3d241d; }
[data-theme="dark"] .guest-banner,
[data-theme="dark"] .billing-banner.info { background: #2e2720; }
[data-theme="dark"] .billing-banner.warning { background: #3a3020; color: var(--gold); }
[data-theme="dark"] .confirm-overlay,
[data-theme="dark"] .sheet-overlay { background: rgba(10, 7, 5, 0.6); }
[data-theme="dark"] .btn-primary { color: #1c1611; }
[data-theme="dark"] .home-feature-icon { background: #3b2a20; }
/* Il QR resta su fondo bianco anche al buio: deve restare scansionabile. */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--cream);
  color: var(--ink);
  font-family: 'Karla', sans-serif;
  -webkit-font-smoothing: antialiased;
  /* "manipulation" still allows pinch-zoom (only blocks double-tap-zoom);
     pan-x pan-y blocks pinch/double-tap zoom while keeping normal scrolling —
     this is what Safari actually honors, since it ignores user-scalable=no. */
  touch-action: pan-x pan-y;
  overscroll-behavior: none;
}

h1, h2, h3 { font-family: 'Fraunces', serif; font-weight: 600; margin: 0 0 0.4em; }

.hidden { display: none !important; }

button, input, select { font-family: inherit; font-size: 1rem; }

a { color: var(--terracotta-dark); }

/* ---------- Barra di stato iOS 26/27 (app installate) ---------- */
/* Nelle app aggiunte alla Home, iOS 26/27 disegna una sfocatura di sistema in
   cima ("scroll edge effect"): non si toglie con un colore né con
   backdrop-filter. WebKit però legge il colore della barra di stato dallo
   stile di un elemento fixed in cima, alto più di 10px: questo div ha il
   colore dichiarato ma non dipinge nulla (background-clip: text su un elemento
   vuoto), quindi la barra diventa tinta unita chiara e la testata resta
   nitida. Vale solo in standalone e su WebKit; altrove resta display: none. */
.ios-status-strip { display: none; }

@supports (((-webkit-background-clip: text) or (background-clip: text)) and (-webkit-touch-callout: none)) {
  @media (display-mode: standalone) {
    .ios-status-strip {
      display: block;
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      /* > 10px: sotto quella soglia WebKit ignora il colore dichiarato
         (thinBorderWidth). Non è un valore di design. */
      height: 11px;
      /* Il punto di campionamento di WebKit è a 4px dal bordo: lassù deve
         trovare questo elemento, non la testata. */
      z-index: 2147483647;
      pointer-events: none;
      background-color: var(--cream);
      -webkit-background-clip: text;
      background-clip: text;
    }
  }
}

/* ---------- Login screen ---------- */
#view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  position: relative;
}

.login-card::before {
  content: '';
  display: block;
  width: 46px;
  height: 46px;
  margin: 0 auto 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, var(--gold), var(--terracotta));
}

.login-card h1 { font-size: 1.5rem; }
.login-card p.subtitle { color: var(--ink-soft); margin: 0 0 24px; font-size: 0.92rem; }

/* min-width: 0 overrides the grid/flex item default of min-width: auto —
   without it, a grid item never shrinks below its content's intrinsic
   minimum size, and native inputs like datetime-local (whose "mm/dd/yyyy,
   --:-- --" + calendar icon can be wider than the grid column on iOS) force
   the whole column wider than its card instead of fitting it. */
.field { text-align: left; margin-bottom: 16px; min-width: 0; }
.field label { display: block; font-weight: 600; font-size: 0.86rem; margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--cream);
  color: var(--ink);
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--terracotta);
}
/* iOS: il campo data/ora con l'aspetto nativo ignora width/padding ed è più
   largo e più alto della colonna, coprendo il campo accanto (e nascondendone il
   bordo). appearance:none lo allinea agli altri campi; il selettore nativo si
   apre comunque al tocco. */
.field input[type="date"],
.field input[type="datetime-local"] {
  -webkit-appearance: none;
  appearance: none;
  max-width: 100%;
}
.field input[type="date"]::-webkit-date-and-time-value,
.field input[type="datetime-local"]::-webkit-date-and-time-value {
  text-align: left;
}
.field .hint { color: var(--ink-soft); font-size: 0.8rem; margin-top: 6px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 999px;
  padding: 11px 22px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.08s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--terracotta); color: #fff9f2; }
.btn-primary:hover { background: var(--terracotta-dark); }
.btn-secondary { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { border-color: var(--terracotta); }
.btn-danger { background: transparent; color: var(--rust); border: 1px solid var(--rust); }
.btn-block { width: 100%; }

.error-message {
  background: #fbe7e0;
  color: var(--rust);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.88rem;
  margin-bottom: 14px;
}

/* ---------- App shell ---------- */
#view-app { min-height: 100vh; display: flex; flex-direction: column; }

header.app-header {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: max(14px, env(safe-area-inset-top)) 20px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, #34d399, #047857);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.brand h1 { font-size: 1.15rem; line-height: 1.1; }
.brand p { margin: 0; color: var(--ink-soft); font-size: 0.78rem; }

.header-actions { display: flex; align-items: center; gap: 10px; }
.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; border-radius: 50%; border: 1px solid var(--line);
  background: transparent; color: var(--ink-soft); cursor: pointer; padding: 0;
  transition: transform 0.4s ease, color 0.15s ease, border-color 0.15s ease;
}
.btn-icon:hover { color: var(--terracotta-dark); border-color: var(--terracotta); }
.btn-icon.spinning svg { animation: spin 0.7s linear; }

.session-timer {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.76rem; font-weight: 600; color: var(--ink-soft);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 10px;
  white-space: nowrap;
}
.session-timer.warning { color: var(--rust); border-color: var(--rust); }

.login-refresh { position: absolute; top: 14px; right: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.lang-select-wrap {
  position: relative; display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--paper);
  padding: 0 26px 0 12px; height: 38px; color: var(--ink-soft);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.lang-select-wrap:hover { border-color: var(--terracotta); }
.lang-select-wrap:focus-within { border-color: var(--terracotta); box-shadow: 0 0 0 3px rgba(193, 101, 63, 0.15); }
.lang-select-wrap .globe { flex-shrink: 0; }
.lang-select {
  appearance: none; -webkit-appearance: none; border: 0; background: transparent;
  font: inherit; font-size: 0.84rem; font-weight: 700; color: var(--ink);
  padding: 8px 0; cursor: pointer; max-width: 130px;
}
.lang-select:focus { outline: none; }
.lang-select-wrap .chevron { position: absolute; right: 10px; pointer-events: none; color: var(--ink-soft); }

nav.app-nav {
  display: flex;
  justify-content: center;
  gap: 4px;
  padding: 10px 16px 0;
  overflow-x: auto;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}
nav.app-nav button {
  border: none; background: transparent; padding: 10px 16px; cursor: pointer;
  font-weight: 600; color: var(--ink-soft); border-bottom: 3px solid transparent; white-space: nowrap;
  display: flex; align-items: center; gap: 8px;
}
nav.app-nav button.active { color: var(--terracotta-dark); border-bottom-color: var(--terracotta); }
nav.app-nav .nav-icon { display: flex; flex-shrink: 0; }
nav.app-nav .nav-icon svg { display: block; }

/* Bottom tab bar on mobile, like a native app: fixed to the viewport bottom
   instead of sitting under the header, icon stacked above label instead of
   side by side. #view-app reserves matching bottom padding so the fixed bar
   never overlaps scrollable content (including the footer) — grows with the
   safe-area inset so it clears the home indicator on notched phones instead
   of sitting under it. */
@media (max-width: 640px) {
  #view-app { padding-bottom: calc(70px + env(safe-area-inset-bottom)); }

  nav.app-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    justify-content: space-around;
    gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    overflow-x: hidden;
    border-bottom: none;
    border-top: 1px solid var(--line);
    box-shadow: 0 -2px 10px rgba(90, 62, 34, 0.08);
  }
  nav.app-nav button {
    flex: 1;
    min-width: 0;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    text-align: center;
    white-space: normal;
    padding: 6px 2px;
    border-bottom: none;
    border-radius: 10px;
    font-size: 0.68rem;
    line-height: 1.15;
  }
  nav.app-nav .nav-icon svg { width: 20px; height: 20px; }
  nav.app-nav button.active { color: var(--terracotta-dark); background: var(--cream); }
}

main.app-main { flex: 1; padding: 20px; max-width: 980px; margin: 0 auto; width: 100%; }

.guest-banner {
  background: #f1ead9; color: var(--ink-soft); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 16px; margin-bottom: 16px; font-size: 0.88rem;
}

/* ---------- Avviso "nuova versione" ---------- */
.update-banner {
  position: fixed;
  left: 50%;
  /* In alto, sotto la tacca del telefono; su desktop un filo sotto il bordo. */
  top: calc(12px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% - 24px);
  max-width: 430px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  animation: fade-in 0.15s ease;
}
.update-banner-text { flex: 1; font-size: 0.88rem; font-weight: 600; }
.update-banner .btn { padding: 8px 16px; font-size: 0.84rem; }
.update-banner-close { padding: 7px; color: var(--ink-soft); }
.update-banner-close:hover { color: var(--ink); }
@media (min-width: 641px) {
  .update-banner { top: 18px; }
}

.card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px;
}

/* Summary tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.tile .label { color: var(--ink-soft); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.tile .value { font-family: 'Fraunces', serif; font-size: 1.6rem; margin-top: 4px; }
.tile.positive .value { color: var(--sage-dark); }
.tile.negative .value { color: var(--rust); }

.row-between { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }

/* Period selector (summary) and register filters */
.period-field { margin-bottom: 0; min-width: 180px; }
.filter-group { display: flex; gap: 10px; flex-wrap: wrap; }

/* Movements list */
.movement-list { display: flex; flex-direction: column; gap: 10px; }
.movement-item {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--cream);
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center;
}
.movement-item .m-main { min-width: 0; }
.movement-item .m-date { color: var(--ink-soft); font-size: 0.78rem; }
.movement-item .m-desc { font-weight: 600; }
.movement-item .m-cat { color: var(--ink-soft); font-size: 0.82rem; }
.movement-item .m-amounts { text-align: right; }
.movement-item .m-income { color: var(--sage-dark); font-weight: 700; }
.movement-item .m-expense { color: var(--rust); font-weight: 700; }
.movement-item .m-balance { font-size: 0.78rem; color: var(--ink-soft); }
.movement-item .m-actions { display: flex; gap: 6px; margin-top: 6px; grid-column: 1 / -1; justify-content: flex-end; }
.movement-item .m-actions button { font-size: 0.78rem; padding: 5px 12px; }
.movement-item.excluded { opacity: 0.55; }

table.data-table { width: 100%; border-collapse: collapse; }
table.data-table th, table.data-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
table.data-table th { color: var(--ink-soft); font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.03em; }

/* Forms */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.checkbox-field { display: flex; align-items: center; gap: 8px; }
.checkbox-field input { width: auto; }
.form-actions { display: flex; align-items: center; gap: 10px; margin-top: 16px; }

/* Cash count */
.cash-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 640px) { .cash-columns { grid-template-columns: 1fr; } }
.cash-columns h3 { font-size: 1rem; margin-bottom: 10px; }
.cash-row { display: grid; grid-template-columns: 1fr 132px 90px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.cash-row .denom { font-weight: 600; }
.cash-row input { padding: 6px 8px; text-align: center; }
.cash-row input:disabled { background: var(--line); color: var(--ink-soft); cursor: not-allowed; opacity: 0.7; }
.cash-row .subtotal { text-align: right; color: var(--ink-soft); }
.qty-stepper { display: flex; align-items: center; gap: 4px; }
.qty-stepper .cash-qty { width: 100%; min-width: 0; }
.qty-btn {
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line);
  background: transparent; color: var(--ink); font-size: 1.1rem; line-height: 1;
  cursor: pointer; padding: 0; transition: color 0.15s ease, border-color 0.15s ease;
}
.qty-btn:hover:not(:disabled) { color: var(--terracotta-dark); border-color: var(--terracotta); }
.qty-btn:active:not(:disabled) { transform: scale(0.93); }
.qty-btn:disabled { color: var(--ink-soft); cursor: not-allowed; opacity: 0.5; }
.cash-verify { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.cash-verify .diff-ok { color: var(--sage-dark); font-weight: 700; }
.cash-verify .diff-bad { color: var(--rust); font-weight: 700; }

/* Guest keys */
.guest-key-item {
  border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; background: var(--cream);
  display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap;
}
.guest-key-item .k-label { font-weight: 600; }
.guest-key-item .k-meta { font-size: 0.78rem; color: var(--ink-soft); }
.guest-key-item.inactive { opacity: 0.5; }

.link-box { display: flex; gap: 8px; align-items: center; background: var(--cream); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin-top: 10px; }
.link-box input { flex: 1; border: none; background: transparent; font-size: 0.82rem; }

footer.app-footer { text-align: center; color: var(--ink-soft); font-size: 0.76rem; padding: 18px; }

/* ---------- Themed confirm dialog ---------- */
.confirm-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(74, 58, 47, 0.42);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: fade-in 0.15s ease;
}
.confirm-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 24px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  animation: pop-in 0.16s ease;
}
.confirm-card p { margin: 0 0 22px; font-size: 0.96rem; line-height: 1.4; }
.confirm-actions { display: flex; gap: 10px; justify-content: center; }
.confirm-actions .btn { flex: 1; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: scale(1); } }

@media (max-width: 560px) {
  .movement-item { grid-template-columns: 1fr; }
  .movement-item .m-amounts { text-align: left; }
}

/* ---------- Conti / liste generiche ---------- */
.account-balance-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--line); }
.account-balance-row:last-child { border-bottom: none; }
.account-balance-row .a-name { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-block; background: var(--cream); border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; font-size: 0.7rem; color: var(--ink-soft); font-weight: 600; white-space: nowrap; }
.badge.overdue { background: #fbe7e0; border-color: var(--rust); color: var(--rust); }
.list-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--cream); margin-bottom: 8px; flex-wrap: wrap; }
.list-item.inactive { opacity: 0.55; }
.list-item .li-title { font-weight: 600; }
.list-item .li-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.list-item .li-actions button { font-size: 0.78rem; padding: 5px 12px; }
.day-section { margin: 14px 0 8px; font-size: 0.86rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }

/* ---------- Calendario ---------- */
.calendar-weekdays { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin-bottom: 4px; }
.calendar-weekdays span { text-align: center; font-size: 0.72rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.03em; }
.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-day { position: relative; min-height: 56px; border: 1px solid var(--line); border-radius: 10px; background: var(--cream); padding: 4px 5px; display: flex; flex-direction: column; align-items: flex-start; gap: 2px; cursor: pointer; font: inherit; color: var(--ink); }
.cal-day.empty { border: none; background: transparent; cursor: default; }
.cal-day.today { border-color: var(--terracotta); }
.cal-day.selected { background: var(--paper); box-shadow: inset 0 0 0 2px var(--terracotta); }
.cal-day-num { font-weight: 600; font-size: 0.82rem; }
.cal-net { font-size: 0.66rem; font-weight: 700; }
.cal-net.positive { color: var(--sage-dark); }
.cal-net.negative { color: var(--rust); }
.cal-dots { display: flex; gap: 3px; margin-top: auto; }
.cal-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.cal-dot.event { background: var(--terracotta); }
.cal-dot.loan { background: var(--sage-dark); }

/* ---------- Conta cassa: carte/conti ---------- */
.cash-other-account { border-top: 1px dashed var(--line); margin-top: 18px; padding-top: 14px; }
.cash-other-account .other-diff { font-size: 0.82rem; margin-top: 4px; }
.other-diff.diff-ok { color: var(--sage-dark); font-weight: 700; }
.other-diff.diff-bad { color: var(--rust); font-weight: 700; }

/* 7 voci di navigazione: etichette un filo più compatte sui telefoni. */
@media (max-width: 640px) {
  nav.app-nav button { font-size: 0.62rem; padding: 6px 1px; }
  .cal-day { min-height: 48px; }
}

/* ---------- Calendario: legenda e form a scomparsa ---------- */
.calendar-legend { display: flex; gap: 14px; flex-wrap: wrap; margin-top: 10px; font-size: 0.76rem; color: var(--ink-soft); }
.calendar-legend > span { display: inline-flex; align-items: center; gap: 5px; }
#event-form-box, #loan-form-box { margin-top: 6px; }

/* ---------- Invito a installare l'app (PWA) ---------- */
.install-banner {
  position: fixed;
  left: 50%;
  /* In alto, sotto la tacca del telefono; su desktop un filo sotto il bordo. */
  top: calc(12px + env(safe-area-inset-top));
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  align-items: center;
  gap: 10px;
  width: calc(100% - 24px);
  max-width: 430px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 10px 12px;
  animation: fade-in 0.15s ease;
}
.install-banner-text { flex: 1; font-size: 0.88rem; font-weight: 600; }
.install-banner .btn { padding: 8px 16px; font-size: 0.84rem; }
/* L'avviso "nuova versione" ha la precedenza: finché è visibile, l'invito non si sovrappone. */
#update-banner:not(.hidden) ~ #install-banner { display: none !important; }
@media (min-width: 641px) {
  .install-banner { top: 18px; }
}

.install-guide-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 20px;
  max-width: 420px;
  width: 100%;
  animation: pop-in 0.16s ease;
}
.install-guide-card h2 { margin: 0 0 6px; font-size: 1.05rem; }
.install-guide-intro { margin: 0 0 14px; font-size: 0.88rem; color: var(--ink-soft); line-height: 1.4; }
.install-guide-block { margin-bottom: 12px; }
.install-guide-block[hidden] { display: none; }
.install-guide-subtitle { margin: 0 0 4px; font-size: 0.86rem; font-weight: 700; }
.install-guide-steps { margin: 0; font-size: 0.86rem; color: var(--ink-soft); line-height: 1.45; white-space: pre-line; }
.install-guide-card .confirm-actions { margin-top: 4px; }

/* ---------- Avviso cookie e dati locali ---------- */
/* Informa e basta: l'app usa solo memorizzazioni tecniche, nessun consenso da
   raccogliere. Il markup sta in index.html, la logica in cookie-notice.js. */
.cookie-banner {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 10px 14px;
  flex-wrap: wrap;
  width: calc(100% - 24px);
  max-width: 640px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 12px 14px;
  animation: fade-in 0.15s ease;
}
.cookie-banner-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 220px; }
.cookie-banner-text strong { font-size: 0.9rem; }
.cookie-banner-text span { font-size: 0.82rem; color: var(--ink-soft); line-height: 1.4; }
.cookie-banner-actions { display: flex; gap: 8px; flex: 0 0 auto; }
.cookie-banner .btn { padding: 8px 16px; font-size: 0.84rem; }
@media (max-width: 640px) {
  .cookie-banner { flex-direction: column; align-items: stretch; }
  .cookie-banner-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.cookie-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 22px 20px;
  max-width: 560px;
  width: 100%;
  max-height: calc(100dvh - 40px);
  overflow-y: auto;
  animation: pop-in 0.16s ease;
}
.cookie-card h2 { margin: 0 0 6px; font-size: 1.05rem; text-align: center; }
.cookie-intro { margin: 0 0 16px; font-size: 0.88rem; color: var(--ink-soft); line-height: 1.45; text-align: center; }
.cookie-section { margin-bottom: 14px; }
.cookie-section h3 { margin: 0 0 4px; font-size: 0.92rem; }
.cookie-section p { margin: 0 0 6px; font-size: 0.85rem; color: var(--ink-soft); line-height: 1.45; }
.cookie-section a { color: var(--terracotta-dark); }
.cookie-list { margin: 0; padding-left: 18px; display: flex; flex-direction: column; gap: 4px; font-size: 0.83rem; color: var(--ink-soft); }
.cookie-card .confirm-actions { margin-top: 8px; }

/* ---------- Registrazione self-service (login screen) ---------- */
.auth-switch { margin: 18px 0 0; text-align: center; }
.link-btn {
  background: none; border: none; padding: 4px;
  color: var(--terracotta-dark); font: inherit; font-weight: 600;
  text-decoration: underline; cursor: pointer;
}
.turnstile-container { margin-bottom: 14px; display: flex; justify-content: center; }
.qr-box { display: flex; justify-content: center; margin: 14px 0; }
.qr-box svg { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.secret-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.95rem; letter-spacing: 1.5px; word-break: break-all;
  background: var(--cream); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; margin-bottom: 14px; text-align: center;
}
.recovery-codes { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 10px 0 16px; }
.recovery-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.9rem; background: var(--cream); border: 1px dashed var(--line);
  border-radius: 8px; padding: 8px; text-align: center;
}

/* ---------- Banner abbonamento ---------- */
.billing-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 16px; margin-bottom: 16px; font-size: 0.88rem;
}
.billing-banner > span:first-child { flex: 1; min-width: 200px; }
.billing-banner.info { background: #f1ead9; color: var(--ink-soft); }
.billing-banner.warning { background: #faf0dc; border-color: var(--gold); color: #7a5b1e; }
.billing-banner.danger { background: #fbe7e0; border-color: var(--rust); color: var(--rust); }
.billing-banner .btn { padding: 8px 16px; font-size: 0.84rem; }

.billing-status-box { margin-bottom: 6px; }
.billing-status-line { font-weight: 600; margin: 0 0 8px; }

/* Sola lettura per abbonamento scaduto: la UI nasconde le azioni di scrittura,
   il server le blocca comunque con 402 subscription_required. */
body.billing-locked #btn-new-movement,
body.billing-locked #btn-new-transfer,
body.billing-locked #btn-add-event,
body.billing-locked #btn-new-loan,
body.billing-locked #cash-form .form-actions,
body.billing-locked #settings-form .form-actions,
body.billing-locked #account-form .form-actions,
body.billing-locked #guest-key-form,
body.billing-locked #categories-input,
body.billing-locked #btn-save-categories,
body.billing-locked .btn-edit,
body.billing-locked .btn-edit-transfer,
body.billing-locked .btn-delete,
body.billing-locked .btn-event-convert,
body.billing-locked .btn-event-edit,
body.billing-locked .btn-event-done,
body.billing-locked .btn-event-delete,
body.billing-locked .btn-loan-return,
body.billing-locked .btn-loan-edit,
body.billing-locked .btn-loan-delete,
body.billing-locked .btn-account-edit,
body.billing-locked .btn-account-archive,
body.billing-locked .btn-account-delete,
body.billing-locked .btn-revoke,
body.billing-locked .btn-purge { display: none !important; }

.field textarea {
  width: 100%; min-width: 0; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--cream); color: var(--ink);
  font-family: inherit; font-size: 1rem; resize: vertical;
}
.field textarea:focus { outline: none; border-color: var(--terracotta); }
.btn-small { padding: 8px 16px; font-size: 0.84rem; }

/* Selettore tema nelle Impostazioni: due opzioni affiancate. */
.theme-switch { display: flex; gap: 8px; flex-wrap: wrap; }
.theme-switch .btn[aria-pressed="true"] {
  border-color: var(--terracotta);
  color: var(--terracotta-dark);
  box-shadow: 0 0 0 3px rgba(193, 101, 63, 0.15);
}

/* ---------- Homepage (casella Smart + landing completa) ---------- */
#view-home { min-height: 100vh; display: flex; flex-direction: column; }
.home-header-actions { display: flex; align-items: center; gap: 10px; }
.home-header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: max(14px, env(safe-area-inset-top)) 20px 14px; max-width: 1040px; margin: 0 auto; width: 100%;
}
.home-main { flex: 1; width: 100%; max-width: 1040px; margin: 0 auto; padding: 8px 20px 24px; }
.home-hero { display: grid; grid-template-columns: minmax(0, 1fr); gap: 40px; align-items: center; text-align: center; padding: 12px 0 8px; }
.home-hero-left { display: flex; flex-direction: column; align-items: center; }
.home-title { font-size: 1.9rem; line-height: 1.22; margin: 14px 0 10px; max-width: 560px; }
.home-tagline { color: var(--ink-soft); margin: 0 0 26px; font-size: 1rem; max-width: 480px; }
.home-card { margin: 0 auto; max-width: 420px; width: 100%; }
.home-card h3 { font-size: 1.15rem; }
.home-badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px 18px; margin-top: 20px; font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
.home-badges > span { display: inline-flex; align-items: center; gap: 6px; }

/* Mockup dell'app nella hero (desktop): stessi colori e forme dell'app. */
.home-hero-preview { display: none; }
.mock-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 14px; text-align: left; }
.mock-card:last-child { margin-bottom: 0; }
.mock-label { margin: 0 0 8px; font-size: 0.68rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-soft); }
.mock-balance { margin: 0 0 12px; font-family: 'Fraunces', serif; font-size: 1.7rem; }
.mock-tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mock-tiles span { display: block; font-size: 0.72rem; color: var(--ink-soft); }
.mock-tiles strong { font-size: 0.95rem; }
.mock-row { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 0.88rem; }
.mock-row:last-child { border-bottom: 0; }
.mock-row .pos, .mock-tiles .pos { color: var(--sage-dark); }
.mock-row .neg, .mock-tiles .neg { color: var(--rust); }

/* Sezioni marketing (su mobile compaiono solo aprendo #sito) */
.home-section { padding: 46px 0 10px; text-align: center; }
.home-marketing .home-section + .home-section { border-top: 1px solid var(--line); }
.home-section-title { font-size: 1.5rem; margin: 0 0 8px; }
.home-section-subtitle { color: var(--ink-soft); font-size: 0.95rem; margin: 0 auto 28px; max-width: 480px; }
.home-features { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; text-align: left; }
.home-feature { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.home-feature-icon { display: inline-flex; width: 38px; height: 38px; align-items: center; justify-content: center; border-radius: 50%; background: #f2ded3; color: var(--terracotta-dark); margin-bottom: 2px; }
.home-feature strong { font-size: 0.97rem; }
.home-feature > span:last-child { color: var(--ink-soft); font-size: 0.85rem; line-height: 1.5; }
.home-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 18px; text-align: left; }
.home-step-num { font-family: 'Fraunces', serif; font-size: 1.9rem; color: var(--terracotta); margin: 0 0 4px; }
.home-step h3 { font-size: 1rem; margin: 0 0 4px; }
.home-step p { margin: 0; color: var(--ink-soft); font-size: 0.86rem; line-height: 1.5; }
.home-pricing { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; text-align: left; max-width: 720px; margin: 0 auto; }
.pricing-card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px 22px 20px; display: flex; flex-direction: column; }
.pricing-card.featured { border: 2px solid var(--terracotta); }
.pricing-card h3 { font-size: 1.05rem; margin: 0 0 6px; }
.pricing-card .price { font-family: 'Fraunces', serif; font-size: 2.1rem; margin: 0; }
.pricing-card .period { color: var(--ink-soft); font-size: 0.84rem; margin: 2px 0 14px; }
.pricing-card ul { list-style: none; margin: 0 0 18px; padding: 0; display: flex; flex-direction: column; gap: 8px; font-size: 0.88rem; }
.pricing-card li { display: flex; gap: 8px; align-items: flex-start; }
.pricing-card li svg { flex-shrink: 0; margin-top: 2px; color: var(--sage-dark); }
.pricing-card .btn { margin-top: auto; }
.home-note { color: var(--ink-soft); font-size: 0.8rem; max-width: 560px; margin: 18px auto 0; line-height: 1.55; }
.home-faq { max-width: 640px; margin: 0 auto; text-align: left; display: flex; flex-direction: column; gap: 10px; }
.home-faq details { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 12px 16px; }
.home-faq summary { cursor: pointer; font-weight: 700; font-size: 0.92rem; }
.home-faq p { margin: 10px 0 2px; color: var(--ink-soft); font-size: 0.88rem; line-height: 1.55; }
.home-cta { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 34px 24px; margin-top: 46px; }
.home-cta h2 { font-size: 1.4rem; margin: 0 0 8px; }
.home-cta p { color: var(--ink-soft); margin: 0 0 18px; font-size: 0.95rem; }
.home-footer { text-align: center; padding: 26px 20px calc(20px + env(safe-area-inset-bottom)); color: var(--ink-soft); font-size: 0.78rem; }
.home-footer a { color: var(--ink-soft); }
.legal-links { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; margin-bottom: 6px; }
.legal-links a { color: var(--ink-soft); text-decoration: none; }
.legal-links a:hover { color: var(--terracotta-dark); text-decoration: underline; }
.legal-links button.legal-link-btn { background: none; border: none; padding: 0; font: inherit; color: var(--ink-soft); cursor: pointer; }
.legal-links button.legal-link-btn:hover { color: var(--terracotta-dark); text-decoration: underline; }
.legal-check label { font-weight: 500; font-size: 0.86rem; line-height: 1.4; }
.legal-check a { color: var(--terracotta-dark); }

@media (min-width: 900px) {
  .home-hero { grid-template-columns: minmax(0, 1fr) 340px; text-align: left; padding: 34px 0 8px; }
  .home-hero-left { align-items: flex-start; }
  .home-title { font-size: 2.2rem; }
  .home-card { margin: 0; }
  .home-badges { justify-content: flex-start; }
  .home-hero-preview { display: block; }
  .home-section { padding: 64px 0 10px; }
}

/* Su mobile la home è solo login/registrazione: titolo, tagline, badge e
   sezioni compaiono aprendo la homepage completa (#sito), come nelle altre
   repo. Su desktop è sempre tutto visibile e i due pulsanti sono nascosti. */
@media (max-width: 640px) {
  .home-title { font-size: 1.45rem; }
  #view-home .home-title,
  #view-home .home-tagline,
  #view-home .home-badges,
  #view-home .home-marketing,
  #view-home .home-site-back { display: none; }
  #view-home.home-site .home-title,
  #view-home.home-site .home-tagline { display: block; }
  #view-home.home-site .home-badges { display: flex; }
  #view-home.home-site .home-marketing { display: block; }
  #view-home.home-site .home-site-toggle { display: none; }
  #view-home.home-site .home-site-back { display: block; }
}
@media (min-width: 641px) {
  .home-site-toggle,
  .home-site-back { display: none; }
}
.app-footer .legal-links { margin-top: 4px; }

/* ---------- Finestre "a foglio" dei form (mobile, come wors-app) ---------- */
.sheet-overlay {
  position: fixed;
  inset: 0;
  top: var(--sheet-vv-top, 0px);
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: var(--sheet-vv-height, 100dvh);
  padding: 0;
  background: rgba(74, 58, 47, 0.42);
  animation: fade-in 0.15s ease;
}
.sheet-card {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: calc(var(--sheet-vv-height, 100dvh) - 10px);
  background: var(--paper);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  animation: sheet-up 0.2s ease;
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px 10px; border-bottom: 1px solid var(--line); }
.sheet-title { min-width: 0; }
.sheet-title h2, .sheet-title h3 { margin: 0; font-size: 1.02rem; line-height: 1.2; }
.sheet-close { padding: 7px; color: var(--ink-soft); }
.sheet-close:hover { color: var(--ink); }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 14px 16px max(16px, env(safe-area-inset-bottom)); }
/* Dentro il foglio il form non è più una card: niente doppio bordo, sfondo o ombra. */
.sheet-body .panel, .sheet-body .card { margin: 0; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
body.sheet-open { overflow: hidden; }
@keyframes sheet-up { from { opacity: 0.6; transform: translateY(22px); } to { opacity: 1; transform: translateY(0); } }

/* Anche conferma e guida installazione sono fogli, su mobile. */
@media (max-width: 640px) {
  .confirm-overlay { align-items: flex-end; padding: 0; }
  .confirm-card, .install-guide-card { width: 100%; max-width: none; border-radius: var(--radius) var(--radius) 0 0; text-align: left; }
  .confirm-card { padding-bottom: max(26px, env(safe-area-inset-bottom)); }
  .install-guide-card { padding-bottom: max(22px, env(safe-area-inset-bottom)); }
}
@media (min-width: 641px) {
  .sheet-overlay { align-items: center; padding: 20px; }
  .sheet-card { max-width: 460px; max-height: calc(100dvh - 40px); border: 1px solid var(--line); border-radius: var(--radius); }
}
