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

/* ===================== Design tokens ===================== */
:root {
  --ink: #10201C;         /* fondo principale, verde pino profondo */
  --surface: #172B25;     /* superfici/card sopra il fondo */
  --surface-2: #1E362E;   /* superfici sopra le card (hover, input) */
  --rule: #2C4A3F;        /* linee sottili, come righe di un registro */
  --paper: #F2EFE4;       /* testo chiaro caldo, "carta" */
  --paper-dim: #B9C4BD;   /* testo secondario */
  --income: #6FA98A;      /* entrate: verde eucalipto */
  --income-soft: rgba(111,169,138,.15);
  --expense: #C4704F;     /* uscite: terracotta bruciato */
  --expense-soft: rgba(196,112,79,.15);
  --gold: #C9A227;        /* accento, il "sigillo" */
  --gold-soft: rgba(201,162,39,.15);
  --danger: #D0654F;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 8px 30px rgba(0,0,0,.25);
  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--ink);
  color: var(--paper);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  font-size: 15px;
}
h1, h2, h3, .display { font-family: var(--font-display); font-weight: 600; letter-spacing: -.01em; }
.num, .amount, input[type=number], time, .mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
a { color: inherit; }
button { font-family: inherit; }

::selection { background: var(--gold-soft); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; border-radius: 4px; }

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

/* ===================== Bottoni ===================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font-family: var(--font-body); font-weight: 600; font-size: .92rem;
  padding: .8rem 1.2rem; border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; text-decoration: none; transition: transform .12s ease, background .15s ease, border-color .15s ease;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.98); }
.btn-block { width: 100%; }
.btn-primary { background: var(--gold); color: #14231F; }
.btn-primary:hover { background: #DCB233; }
.btn-outline { background: transparent; border-color: var(--rule); color: var(--paper); }
.btn-outline:hover { border-color: var(--gold); }
.btn-ghost { background: transparent; color: var(--paper-dim); padding: .5rem .7rem; }
.btn-ghost:hover { color: var(--paper); }
.btn-danger { background: transparent; border-color: var(--expense); color: var(--expense); }
.btn-sm { padding: .5rem .8rem; font-size: .82rem; }
.btn-icon { padding: .55rem; border-radius: 999px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ===================== Login ===================== */
.login-body {
  display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1.5rem;
  background: radial-gradient(circle at 50% 0%, #16302A 0%, var(--ink) 60%);
}
.login-card {
  width: 100%; max-width: 380px; text-align: center;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: 2.4rem 1.8rem; box-shadow: var(--shadow);
}
.login-seal {
  width: 56px; height: 56px; margin: 0 auto 1.1rem; border-radius: 50%;
  border: 1.5px solid var(--gold); color: var(--gold); font-family: var(--font-display);
  font-size: 1.6rem; display: flex; align-items: center; justify-content: center;
}
.login-title { font-size: 1.7rem; margin: 0 0 .3rem; }
.login-sub { color: var(--paper-dim); font-size: .9rem; margin: 0 0 1.8rem; line-height: 1.5; }
.login-actions { display: flex; flex-direction: column; gap: .7rem; }
.login-hint { color: var(--paper-dim); font-size: .82rem; margin: .3rem 0 0; }
.login-error { background: var(--expense-soft); color: var(--expense); border-radius: var(--radius-sm); padding: .6rem .8rem; font-size: .85rem; margin-bottom: 1rem; }
.login-footer { margin-top: 1.8rem; font-size: .78rem; color: var(--paper-dim); }
.login-footer a { text-decoration: underline; text-underline-offset: 2px; }

/* ===================== Pagine documento (privacy/cookie) ===================== */
.doc-body { background: var(--ink); color: var(--paper); font-family: var(--font-body); min-height: 100vh; }
.doc { max-width: 640px; margin: 0 auto; padding: 2.5rem 1.5rem 5rem; line-height: 1.65; }
.doc h1 { font-size: 1.8rem; margin-bottom: .2rem; }
.doc h2 { font-family: var(--font-body); font-size: 1.05rem; color: var(--gold); margin-top: 2rem; }
.doc-updated { color: var(--paper-dim); font-size: .85rem; }
.doc-back { color: var(--paper-dim); text-decoration: none; font-size: .85rem; }
.doc-table { width: 100%; border-collapse: collapse; margin-top: .8rem; font-size: .88rem; }
.doc-table th, .doc-table td { text-align: left; padding: .6rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
.doc code { background: var(--surface); padding: .1rem .35rem; border-radius: 4px; font-family: var(--font-mono); font-size: .85em; }

/* ===================== App shell ===================== */
#app { min-height: 100vh; display: flex; flex-direction: column; }
[x-cloak] { display: none !important; }

.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 1rem 1.1rem; background: rgba(16,32,28,.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--rule);
}
.topbar-title { font-family: var(--font-display); font-size: 1.25rem; display: flex; align-items: center; gap: .5rem; }
.topbar-title .seal { color: var(--gold); }

.view { flex: 1; padding: 1.1rem 1.1rem 6.5rem; max-width: 880px; width: 100%; margin: 0 auto; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; justify-content: space-around; background: var(--surface);
  border-top: 1px solid var(--rule); padding: .5rem .3rem calc(.5rem + env(safe-area-inset-bottom));
}
.bottomnav a, .bottomnav button {
  background: none; border: none; color: var(--paper-dim); display: flex; flex-direction: column;
  align-items: center; gap: .2rem; font-size: .68rem; padding: .35rem .5rem; border-radius: 10px;
  text-decoration: none; cursor: pointer; flex: 1;
}
.bottomnav .active { color: var(--gold); }
.bottomnav svg { width: 21px; height: 21px; }

.fab {
  position: fixed; right: 1.1rem; bottom: calc(4.6rem + env(safe-area-inset-bottom)); z-index: 25;
  width: 54px; height: 54px; border-radius: 50%; background: var(--gold); color: #14231F;
  border: none; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow);
  cursor: pointer; font-size: 1.6rem;
}

@media (min-width: 860px) {
  .bottomnav { flex-direction: column; justify-content: flex-start; top: 0; bottom: 0; right: auto;
    width: 210px; border-top: none; border-right: 1px solid var(--rule); padding: 1.3rem .8rem; gap: .2rem; }
  .bottomnav a, .bottomnav button { flex-direction: row; justify-content: flex-start; font-size: .88rem; padding: .65rem .8rem; }
  #app { flex-direction: row; }
  .view { margin-left: 210px; padding-bottom: 3rem; max-width: 900px; }
  .topbar { display: none; }
  .fab { left: calc(210px + 1.6rem); right: auto; bottom: 1.6rem; }
}

/* ===================== Card & layout ===================== */
.card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1.2rem; }
.grid { display: grid; gap: .9rem; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 520px) { .grid-3 { grid-template-columns: 1fr 1fr; } }

.section-title { font-family: var(--font-display); font-size: 1.05rem; margin: 1.6rem 0 .7rem; display: flex; align-items: center; justify-content: space-between; }
.section-title:first-child { margin-top: 0; }

/* Sigillo saldo totale in dashboard */
.balance-hero { text-align: center; padding: 1.6rem 1rem 1.4rem; }
.balance-hero .label { color: var(--paper-dim); font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; }
.balance-hero .amount { font-family: var(--font-mono); font-size: clamp(2.1rem, 8vw, 2.8rem); font-weight: 600; margin: .3rem 0; }
.balance-hero .sub { display: flex; justify-content: center; gap: 1.6rem; margin-top: .6rem; font-size: .85rem; }
.balance-hero .sub .income { color: var(--income); }
.balance-hero .sub .expense { color: var(--expense); }

/* Righe di registro (transazioni) */
.ledger { display: flex; flex-direction: column; }
.ledger-row {
  display: flex; align-items: center; gap: .8rem; padding: .8rem 0; border-bottom: 1px solid var(--rule);
  cursor: pointer;
}
.ledger-row:last-child { border-bottom: none; }
.ledger-tick { width: 34px; height: 34px; border-radius: 9px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.ledger-body { flex: 1; min-width: 0; }
.ledger-desc { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ledger-meta { color: var(--paper-dim); font-size: .78rem; margin-top: .1rem; }
.ledger-amount { font-family: var(--font-mono); font-weight: 600; white-space: nowrap; }
.ledger-amount.income { color: var(--income); }
.ledger-amount.expense { color: var(--expense); }
.empty-state { text-align: center; color: var(--paper-dim); padding: 2.5rem 1rem; font-size: .9rem; }

/* Budget bars */
.budget-item { padding: .9rem 0; border-bottom: 1px solid var(--rule); }
.budget-item:last-child { border-bottom: none; }
.budget-head { display: flex; justify-content: space-between; font-size: .88rem; margin-bottom: .5rem; }
.budget-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.budget-bar-fill { height: 100%; border-radius: 4px; transition: width .3s ease; }

/* Chip/pill */
.pill { display: inline-flex; align-items: center; gap: .4rem; padding: .3rem .7rem; border-radius: 999px; font-size: .78rem; background: var(--surface-2); }
.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ===================== Form ===================== */
label { display: block; font-size: .82rem; color: var(--paper-dim); margin-bottom: .35rem; }
.field { margin-bottom: 1rem; }
input, select, textarea {
  width: 100%; background: var(--surface-2); border: 1px solid var(--rule); color: var(--paper);
  border-radius: var(--radius-sm); padding: .75rem .85rem; font-size: .95rem; font-family: var(--font-body);
}
input[type=date], input[type=number] { font-family: var(--font-mono); }
textarea { resize: vertical; min-height: 70px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath fill='%23B9C4BD' d='M0 0l6 8 6-8z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .9rem center; padding-right: 2rem; }
.type-toggle { display: flex; gap: .5rem; margin-bottom: 1rem; }
.type-toggle button { flex: 1; padding: .7rem; border-radius: var(--radius-sm); border: 1px solid var(--rule); background: transparent; color: var(--paper-dim); cursor: pointer; font-weight: 600; }
.type-toggle button.active.income { border-color: var(--income); color: var(--income); background: var(--income-soft); }
.type-toggle button.active.expense { border-color: var(--expense); color: var(--expense); background: var(--expense-soft); }

/* ===================== Modal / sheet ===================== */
.overlay { position: fixed; inset: 0; background: rgba(8,16,14,.6); backdrop-filter: blur(2px); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
@media (min-width: 620px) { .overlay { align-items: center; } }
.sheet {
  background: var(--surface); border: 1px solid var(--rule); border-radius: 18px 18px 0 0;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; padding: 1.4rem 1.3rem calc(1.4rem + env(safe-area-inset-bottom));
}
@media (min-width: 620px) { .sheet { border-radius: var(--radius); margin: 1rem; } }
.sheet-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.1rem; }
.sheet-head h2 { font-size: 1.15rem; margin: 0; }

/* ===================== Toast ===================== */
.toast { position: fixed; bottom: calc(5.6rem + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--rule); border-radius: var(--radius-sm);
  padding: .7rem 1.1rem; font-size: .85rem; z-index: 60; box-shadow: var(--shadow); }
.toast.error { border-color: var(--expense); color: var(--expense); }

/* ===================== Utility ===================== */
.flex { display: flex; }
.between { justify-content: space-between; }
.center { align-items: center; }
.gap-sm { gap: .5rem; }
.muted { color: var(--paper-dim); }
.mt-1 { margin-top: 1rem; }
.text-right { text-align: right; }
.spinner { width: 20px; height: 20px; border: 2px solid var(--rule); border-top-color: var(--gold); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
