/* ============ Finanze — Francesco Gervasi · v3 "Revolut light" ============
   Bianco, superfici neutre chiare, colore solo semantico
   (verde/rosso scuri leggibili, ambra per investimenti).
   Vedi DESIGN.md nel progetto. */
:root {
  --bg: #FFFFFF;
  --card: #F2F2F5;
  --card-2: #E8E8ED;
  --line: rgba(0, 0, 0, .08);
  --text: #0A0A0C;
  --muted: #6E6E76;
  --green: #0C8443;
  --red: #D92D20;
  --yellow: #B45309;        /* testo/icone investimenti (ambra scura leggibile) */
  --yellow-bright: #EAB308; /* barre/pallini investimenti */
  --radius: 16px;
  --tabbar-h: 76px;
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 560px;
  margin: 0 auto;
  overscroll-behavior-y: none;
  user-select: none;
  -webkit-user-select: none;
}

button { font-family: inherit; }
button:focus-visible, input:focus-visible {
  outline: 2px solid rgba(10, 10, 12, .6);
  outline-offset: 2px;
}

/* ---------- Header ---------- */
.app-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 20px 10px;
  position: sticky; top: 0; z-index: 20;
  background: linear-gradient(to bottom, rgba(255,255,255,.95), rgba(255,255,255,.85) 70%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.brand { font-weight: 700; font-size: 1.08rem; letter-spacing: -.02em; }
.brand .chev { color: var(--green); font-weight: 800; margin-right: 2px; }
.icon-btn {
  position: relative;
  background: var(--card); border: none; color: var(--muted);
  width: 40px; height: 40px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
  transition: transform .15s ease;
}
.icon-btn:active { transform: scale(.92); }
/* pallino stato sync sull'ingranaggio */
.icon-btn .sync-dot {
  position: absolute; top: 2px; right: 2px;
  width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid var(--bg);
  display: none;
}
.icon-btn.sync-err .sync-dot { display: block; background: var(--red); }
.icon-btn.sync-off .sync-dot { display: block; background: var(--yellow-bright); }

/* ---------- Layout ---------- */
main { padding: 4px 16px calc(var(--tabbar-h) + 96px + env(safe-area-inset-bottom)); }
.view { display: none; }
.view.active { display: block; animation: fadein .15s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.section-title {
  font-size: .78rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--muted);
  margin: 26px 4px 10px;
  display: flex; justify-content: space-between; align-items: center;
}
.section-title .link { color: var(--text); text-transform: none; letter-spacing: 0; font-size: .84rem; cursor: pointer; background: none; border: none; font-weight: 600; opacity: .8; }

/* ---------- Hero patrimonio (sul bianco, nessuna card) ---------- */
.hero {
  padding: 20px 2px 6px;
  text-align: center;
}
.hero .label {
  font-size: .76rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: .1em; color: var(--muted);
}
.hero .big {
  font-size: 2.7rem; font-weight: 700; letter-spacing: -.03em; line-height: 1.15;
  font-variant-numeric: tabular-nums; margin-top: 6px; color: var(--text);
}
.hero .big .dec { font-size: .55em; font-weight: 600; color: var(--muted); }
.hero .subchips { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; justify-content: center; }
.chip-mini {
  font-size: .75rem; font-weight: 600; padding: 6px 12px; border-radius: 99px;
  background: var(--card); color: var(--muted);
}
/* delta del range: ▲ verde / ▼ rosso */
.chip-mini.delta-up   { background: rgba(12,132,67,.10); color: var(--green); }
.chip-mini.delta-down { background: rgba(217,45,32,.09);  color: var(--red); }
.chip-mini.inv-chip   { background: rgba(234,179,8,.14); color: var(--yellow); }

.chart-wrap { margin-top: 16px; }
.chart-wrap svg { width: 100%; height: auto; display: block; }

/* Range pills (1M / 6M / Tutto) */
.range-seg { display: flex; gap: 4px; background: var(--card); border-radius: 99px; padding: 3px; margin: 14px auto 0; width: max-content; }
.range-seg button {
  border: none; background: transparent; color: var(--muted); font-weight: 600;
  font-size: .78rem; padding: 6px 16px; border-radius: 99px; cursor: pointer;
  transition: background .15s ease, color .15s ease;
}
.range-seg button.active { background: var(--text); color: #fff; }

/* ---------- Azioni rapide ---------- */
.quick-row {
  display: flex; justify-content: center; gap: 34px;
  margin: 22px 0 8px;
}
.qa {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 8px;
  color: var(--muted); font-size: .74rem; font-weight: 600;
}
.qa .qa-ico {
  width: 56px; height: 56px; border-radius: 50%;
  background: var(--card);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s ease;
}
.qa:active .qa-ico { transform: scale(.9); }
.qa .qa-ico.g svg { stroke: var(--green); }
.qa .qa-ico.r svg { stroke: var(--red); }
.qa .qa-ico.y svg { stroke: var(--yellow); }

/* ---------- Stat cards entrate/uscite ---------- */
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  background: var(--card); border-radius: var(--radius);
  padding: 15px 16px;
}
.stat .k { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.stat .v { font-size: 1.3rem; font-weight: 700; margin-top: 5px; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.stat .v.pos { color: var(--green); }
.stat .v.neg { color: var(--red); }
.dot { width: 8px; height: 8px; border-radius: 99px; display: inline-block; flex-shrink: 0; }
.dot.green { background: var(--green); }
.dot.red { background: var(--red); }
.dot.yellow { background: var(--yellow-bright); }
.invested-line {
  display: flex; align-items: center; gap: 8px; justify-content: center;
  font-size: .82rem; color: var(--yellow); font-weight: 600; margin-top: 14px;
}

/* ---------- Liste transazioni (flat) ---------- */
.tx-list { display: flex; flex-direction: column; }
.tx-group-date {
  font-size: .76rem; font-weight: 600; color: var(--muted);
  margin: 16px 4px 4px; text-transform: capitalize;
}
.tx {
  display: flex; align-items: center; gap: 13px;
  padding: 11px 6px; border-radius: 14px; cursor: pointer;
  transition: background .15s ease;
}
.tx:active { background: var(--card); }
.tx .ico {
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.25rem;
  background: var(--card);
}
.tx .ico.k-entrata { background: rgba(12,132,67,.10); }
.tx .ico.k-uscita  { background: rgba(217,45,32,.08); }
.tx .ico.k-inv     { background: rgba(234,179,8,.14); }
.tx .mid { flex: 1; min-width: 0; }
.tx .t1 { font-size: .93rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .t2 { font-size: .76rem; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx .amt { font-weight: 700; font-size: .95rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.amt.pos { color: var(--green); }
.amt.neg { color: var(--red); }
.amt.inv { color: var(--yellow); }
.badge {
  font-size: .62rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 2px 7px; border-radius: 99px; margin-left: 6px; vertical-align: 1px;
}
.badge.yellow { background: rgba(234,179,8,.16); color: var(--yellow); }
.badge.green  { background: rgba(12,132,67,.12); color: var(--green); }

.empty {
  text-align: center; color: var(--muted); font-size: .88rem;
  padding: 34px 20px; line-height: 1.55;
}
.empty .big-emoji { font-size: 2rem; display: block; margin-bottom: 8px; }

/* ---------- Filtri / segmented (pillole) ---------- */
.seg {
  display: flex; background: var(--card);
  border-radius: 99px; padding: 4px; gap: 4px; margin-bottom: 14px;
}
.seg button {
  flex: 1; border: none; background: transparent; color: var(--muted);
  font-weight: 600; font-size: .84rem; padding: 10px 4px; border-radius: 99px; cursor: pointer;
  transition: background .15s ease, color .15s ease, box-shadow .15s ease;
}
.seg button.active { background: #FFFFFF; color: var(--text); box-shadow: 0 1px 4px rgba(0,0,0,.12); }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  border: none; background: var(--card); color: var(--muted);
  font-size: .82rem; font-weight: 600; padding: 9px 15px; border-radius: 99px;
  cursor: pointer; white-space: nowrap;
  transition: background .15s ease, color .15s ease;
}
.chip.active { background: var(--text); color: #fff; }
.chip.active.y { background: rgba(234,179,8,.18); color: var(--yellow); }
.chip.active.g { background: rgba(12,132,67,.12); color: var(--green); }
.chip.active.r { background: rgba(217,45,32,.10); color: var(--red); }

/* Month nav */
.month-nav {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.month-nav .mn-label { font-weight: 700; font-size: 1rem; text-transform: capitalize; }
.month-nav button {
  width: 40px; height: 40px; border-radius: 50%; border: none;
  background: var(--card); color: var(--text); font-size: 1rem; cursor: pointer; font-weight: 700;
}

/* ---------- Barre categoria ---------- */
.cat-bars { display: flex; flex-direction: column; gap: 13px; }
.cat-bar .row1 { display: flex; justify-content: space-between; font-size: .85rem; font-weight: 600; margin-bottom: 6px; }
.cat-bar .row1 .val { font-variant-numeric: tabular-nums; color: var(--muted); }
.cat-bar .track { height: 7px; border-radius: 99px; background: var(--card-2); overflow: hidden; }
.cat-bar .fill { height: 100%; border-radius: 99px; background: var(--red); }
.cat-bar .fill.yellow { background: var(--yellow-bright); }
.cat-bar .fill.green { background: var(--green); }
.cat-bar .fill.blue { background: var(--text); }

/* ---------- Investimenti ---------- */
.inv-card {
  background: var(--card); border-radius: var(--radius);
  padding: 15px 16px; margin-bottom: 8px;
  display: flex; align-items: center; gap: 13px; cursor: pointer;
  transition: background .15s ease;
}
.inv-card:active { background: var(--card-2); }
.inv-card .ico {
  width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
  background: rgba(234,179,8,.15);
  display: flex; align-items: center; justify-content: center; font-size: 1.4rem;
}
.inv-card .mid { flex: 1; min-width: 0; }
.inv-card .t1 { font-weight: 600; font-size: .95rem; }
.inv-card .t2 { font-size: .77rem; color: var(--muted); margin-top: 3px; }
.btn-sold {
  border: none; border-radius: 99px; padding: 10px 16px; font-weight: 700; font-size: .8rem;
  background: rgba(12,132,67,.11); color: var(--green); cursor: pointer; white-space: nowrap;
  transition: transform .15s ease;
}
.btn-sold:active { transform: scale(.95); }

.sold-row {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 4px; border-bottom: 1px solid var(--line);
  font-size: .86rem;
}
.sold-row:last-child { border-bottom: none; }
.sold-row .name { flex: 1; font-weight: 600; }
.sold-row .flow { color: var(--muted); font-size: .76rem; font-variant-numeric: tabular-nums; }
.sold-row .profit { font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Bottoni (pillola) ---------- */
.btn {
  display: block; width: 100%; border: none; border-radius: 99px;
  padding: 16px; font-size: 1rem; font-weight: 700; cursor: pointer;
  transition: transform .15s ease, opacity .15s ease;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--text); color: #fff; }
.btn.ghost { background: var(--card); color: var(--text); }
.btn.danger { background: rgba(217,45,32,.10); color: var(--red); }
.btn + .btn { margin-top: 10px; }

/* ---------- FAB ---------- */
#fab {
  position: fixed; right: 18px; bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  width: 58px; height: 58px; border-radius: 50%; border: none;
  background: var(--text); color: #fff; font-size: 1.9rem; font-weight: 400; line-height: 1;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .28);
  cursor: pointer; z-index: 30;
  display: flex; align-items: center; justify-content: center; padding-bottom: 3px;
  transition: transform .15s ease;
}
#fab:active { transform: scale(.92); }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 560px; height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  background: rgba(255, 255, 255, .92);
  backdrop-filter: blur(22px); -webkit-backdrop-filter: blur(22px);
  border-top: 1px solid var(--line);
  display: flex; z-index: 25;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; border: none; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  font-size: .68rem; font-weight: 600; cursor: pointer;
  transition: color .15s ease;
}
.tab.active { color: var(--text); }

/* ---------- Sheet / overlay ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(10, 10, 12, .4);
  display: flex; align-items: flex-end; justify-content: center;
  opacity: 1; transition: opacity .2s ease;
}
.overlay.hidden { opacity: 0; pointer-events: none; }
.sheet {
  width: 100%; max-width: 560px; max-height: 88vh; overflow-y: auto;
  background: #FFFFFF;
  border-radius: 20px 20px 0 0;
  padding: 10px 20px calc(26px + env(safe-area-inset-bottom));
  transform: translateY(0); transition: transform .25s cubic-bezier(.2,.8,.3,1);
  box-shadow: 0 -8px 32px rgba(0,0,0,.14);
}
.overlay.hidden .sheet { transform: translateY(100%); }
.sheet-handle { width: 40px; height: 4px; border-radius: 99px; background: #D9D9DE; margin: 6px auto 14px; }
.sheet-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 16px; letter-spacing: -.01em; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .74rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 7px; }
.field input, .field select {
  width: 100%; background: var(--card); border: 1px solid transparent; border-radius: 14px;
  color: var(--text); font-size: 1rem; padding: 14px; font-family: inherit;
  outline: none; -webkit-appearance: none; appearance: none;
  transition: border-color .15s ease;
}
.field input::placeholder { color: #75757E; }
.field input:focus { border-color: rgba(10, 10, 12, .45); }
.amount-wrap { position: relative; }
.amount-wrap input {
  font-size: 1.7rem; font-weight: 700; text-align: center; padding: 16px 14px;
  font-variant-numeric: tabular-nums;
}
.amount-wrap .cur {
  position: absolute; right: 18px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-weight: 600; font-size: 1.1rem;
}
input[type="date"] { color-scheme: light; }

.profit-preview {
  text-align: center; font-size: .95rem; font-weight: 600; margin: 4px 0 14px;
  color: var(--muted);
}
.profit-preview b.pos { color: var(--green); }
.profit-preview b.neg { color: var(--red); }

/* Riga dettaglio nel sheet */
.detail-rows { margin-bottom: 16px; }
.detail-rows .dr {
  display: flex; justify-content: space-between; padding: 11px 2px;
  border-bottom: 1px solid var(--line); font-size: .9rem;
}
.detail-rows .dr:last-child { border-bottom: none; }
.detail-rows .dr .k { color: var(--muted); }
.detail-rows .dr .v { font-weight: 600; text-align: right; }

.sync-status { font-size: .82rem; color: var(--muted); line-height: 1.5; margin-bottom: 14px; }
.sync-status .ok { color: var(--green); font-weight: 700; }
.sync-status .off { color: var(--yellow); font-weight: 700; }
.sync-status .err { color: var(--red); font-weight: 700; }

/* ---------- Toast (scuro su tema chiaro, stile iOS) ---------- */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom));
  background: #1C1C21; color: #fff;
  font-size: .88rem; font-weight: 600; padding: 13px 22px; border-radius: 99px;
  z-index: 60; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  opacity: 1; transition: opacity .25s ease, transform .25s ease;
  max-width: 86%; text-align: center;
}
.toast.hidden { opacity: 0; pointer-events: none; transform: translateX(-50%) translateY(8px); }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

/* piccoli aiuti */
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mb0 { margin-bottom: 0; }
.muted { color: var(--muted); }
.small { font-size: .78rem; }
.center { text-align: center; }
