:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --ink: #12182a;
  --muted: #6d7589;
  --line: #e5e8f0;
  --accent: #168a63;
  --accent-2: #38b882;
  --good: #0f9f77;
  --warn: #dc8a16;
  --danger: #d94a62;
  --nav: #0d211a;
  --nav-muted: #9ebcaf;
  --shadow: 0 18px 45px rgba(24, 32, 56, .07);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 5px; font-size: 11px; font-weight: 800; letter-spacing: .12em; color: var(--muted); }
h1,h2,h3,p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: 32px; }
h2 { margin: 0; font-size: 25px; }
h3 { margin: 0; font-size: 18px; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at top, #255a46 0, #0d211a 58%); }
.login-card { width: min(430px, 100%); padding: 38px; background: rgba(255,255,255,.98); border-radius: 24px; box-shadow: 0 30px 80px rgba(0,0,0,.28); }
.brand-mark { width: 52px; height: 52px; border-radius: 16px; display: grid; place-items: center; font-weight: 900; color: white; background: linear-gradient(135deg, var(--accent), #42bd88); margin-bottom: 22px; }
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; margin: 0; flex: 0 0 auto; }
.form-error { min-height: 20px; margin: 12px 0 0; color: var(--danger); font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 235px 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--nav); color: white; padding: 26px 18px; display: flex; flex-direction: column; }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 10px 28px; line-height: 1.05; }
#nav { display: grid; gap: 6px; }
.nav-item { border: 0; border-radius: 12px; background: transparent; color: var(--nav-muted); padding: 12px 13px; text-align: left; cursor: pointer; display: flex; gap: 10px; align-items: center; font-weight: 650; }
.nav-item:hover, .nav-item.active { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { box-shadow: inset 3px 0 var(--accent-2); }
.logout { margin-top: auto; width: 100%; }

.content { min-width: 0; padding: 28px 34px 48px; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 26px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }
.date-pill { background: #fff; border: 1px solid var(--line); padding: 9px 12px; border-radius: 10px; font-size: 13px; color: var(--muted); }
.view { display: none; }
.view.active { display: block; }

.kpi-grid { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 17px; padding: 18px; box-shadow: var(--shadow); }
.kpi .value { font-weight: 800; font-size: clamp(20px, 2vw, 28px); margin: 6px 0 4px; }
.kpi .sub { color: var(--muted); font-size: 12px; }
.grid { display: grid; gap: 16px; margin-bottom: 16px; }
.grid.two-thirds { grid-template-columns: 2fr 1fr; }
.grid.half { grid-template-columns: 1fr 1fr; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 17px; padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.card-head.wrap { flex-wrap: wrap; }
.annual-chart-head { align-items:flex-end; }
.chart-year-filter { display:grid; gap:5px; min-width:105px; font-size:11px; color:var(--muted); font-weight:800; letter-spacing:.04em; }
.chart-year-filter select { width:105px; padding:8px 30px 8px 10px; border-radius:10px; font-weight:750; color:var(--ink); }
.chart-wrap { position: relative; height: 290px; }
.chart-wrap.donut { max-width: 320px; margin: auto; }

.progress-list { display: grid; gap: 22px; }
.progress-row .progress-top { display:flex; justify-content:space-between; gap:10px; margin-bottom:8px; }
.progress-row .progress-top span { color:var(--muted); font-size:13px; }
.progress-bar { height: 10px; background: #edf0f6; border-radius: 999px; overflow: hidden; }
.progress-bar > i { display:block; height:100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius:inherit; }
.progress-meta { display:flex; justify-content:space-between; color:var(--muted); font-size:12px; margin-top:7px; }

.mini-list { display: grid; }
.mini-item { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; align-items: center; padding: 11px 0; border-bottom: 1px solid var(--line); }
.mini-item:last-child { border-bottom: 0; }
.mini-icon { width:36px; height:36px; border-radius:10px; display:grid; place-items:center; background:#eaf8f1; color:var(--accent); font-weight:800; }
.mini-item.gift .mini-icon { background:#fff5df; color:var(--warn); }
.mini-title { font-weight:700; font-size:13px; margin-bottom:2px; }
.mini-sub { font-size:11px; color:var(--muted); }
.amount-pos { font-weight:800; font-variant-numeric: tabular-nums; white-space:nowrap; }
.amount-neg { font-weight:800; font-variant-numeric:tabular-nums; white-space:nowrap; color:var(--danger); }
.badge.debit { color:var(--danger); background:#fff1f3; border-color:#f4c8d0; }
.field-hint { display:block; margin-top:6px; color:var(--muted); font-size:12px; line-height:1.35; }

.stack { display:grid; gap:14px; }
.form-card { max-width: 900px; }
.form-grid { display:grid; grid-template-columns: 1fr 1fr; gap:16px; }
.form-grid.compact-form { gap: 12px; }
.span-2 { grid-column: 1 / -1; }
label { display:grid; gap:7px; font-size:13px; font-weight:700; }
input, select, textarea { width:100%; border:1px solid #d9deea; border-radius:11px; background:#fff; color:var(--ink); padding:11px 12px; outline:none; }
input:focus, select:focus, textarea:focus { border-color:var(--accent); box-shadow:0 0 0 3px rgba(22,138,99,.14); }
textarea { resize: vertical; }
.btn { border:0; border-radius:11px; padding:11px 15px; cursor:pointer; font-weight:750; text-decoration:none; display:inline-flex; align-items:center; justify-content:center; gap:7px; }
.btn.primary { background:var(--accent); color:#fff; }
.btn.primary:hover { filter:brightness(.96); }
.btn.secondary { background:#fff; color:var(--ink); border:1px solid var(--line); }
.btn.compact { padding:9px 12px; font-size:13px; }
.link-btn { border:0; background:transparent; color:var(--accent); cursor:pointer; font-size:12px; font-weight:800; }
.form-actions { display:flex; justify-content:flex-end; gap:10px; }
.gift-toggle { grid-template-columns:auto auto 1fr; align-items:center; padding:14px; border:1px dashed #d7dbea; border-radius:13px; cursor:pointer; }
.gift-toggle input { position:absolute; opacity:0; pointer-events:none; }
.switch { width:42px; height:24px; border-radius:99px; background:#dfe3ee; position:relative; transition:.2s; }
.switch:after { content:""; position:absolute; width:18px; height:18px; border-radius:50%; background:white; top:3px; left:3px; box-shadow:0 1px 4px rgba(0,0,0,.2); transition:.2s; }
.gift-toggle input:checked + .switch { background:var(--warn); }
.gift-toggle input:checked + .switch:after { transform:translateX(18px); }
.gift-toggle small { display:block; margin-top:3px; color:var(--muted); font-weight:500; }

.filters { display:grid; grid-template-columns: 1.1fr 1fr 1fr 1fr 1.5fr auto; gap:9px; margin-bottom:13px; }
.table-summary { display:flex; flex-wrap:wrap; gap:10px; margin:12px 0; font-size:12px; color:var(--muted); }
.summary-chip { border:1px solid var(--line); background:#fafbfe; border-radius:999px; padding:6px 9px; }
.table-scroll { overflow:auto; border:1px solid var(--line); border-radius:13px; }
table { border-collapse:collapse; width:100%; min-width:820px; }
th, td { padding:12px 13px; border-bottom:1px solid var(--line); text-align:left; font-size:13px; vertical-align:middle; }
th { color:var(--muted); background:#fafbfe; font-size:11px; letter-spacing:.06em; text-transform:uppercase; }
tbody tr:last-child td { border-bottom:0; }
.badge { display:inline-flex; padding:5px 8px; border-radius:999px; font-size:11px; font-weight:800; background:#eaf8f1; color:var(--accent); white-space:nowrap; }
.badge.gift { background:#fff4dc; color:#a96808; }
.actions { display:flex; gap:5px; justify-content:flex-end; }
.icon-btn { border:1px solid var(--line); background:white; border-radius:8px; padding:6px 8px; cursor:pointer; }
.icon-btn.danger { color:var(--danger); }
.pagination { display:flex; align-items:center; justify-content:flex-end; gap:12px; margin-top:14px; }

.settings-grid { align-items:start; }
.loan-setting { padding:14px; background:#fafbfe; border:1px solid var(--line); border-radius:13px; }
.loan-setting + .loan-setting { margin-top:10px; }
.loan-setting .row { display:grid; grid-template-columns:1fr 1fr; gap:10px; margin-top:10px; }
.people-list { display:grid; gap:8px; margin-top:18px; max-height:380px; overflow:auto; }
.person-row { display:grid; grid-template-columns:1fr auto; gap:10px; align-items:center; border:1px solid var(--line); border-radius:12px; padding:11px 12px; }
.person-row small { color:var(--muted); }

.toast { position:fixed; z-index:100; right:22px; bottom:22px; transform:translateY(20px); opacity:0; pointer-events:none; background:#111827; color:white; border-radius:12px; padding:12px 15px; box-shadow:0 15px 40px rgba(0,0,0,.2); transition:.2s; max-width:360px; font-size:13px; }
.toast.show { opacity:1; transform:translateY(0); }
.toast.error { background:#8f2035; }
.empty { color:var(--muted); text-align:center; padding:28px 12px; }

@media (max-width: 1100px) {
  .kpi-grid { grid-template-columns: repeat(3, 1fr); }
  .filters { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 820px) {
  .app-shell { display:block; }
  .sidebar { position:fixed; z-index:50; bottom:0; top:auto; height:auto; width:100%; padding:8px; flex-direction:row; }
  .sidebar .brand, .logout { display:none; }
  #nav { width:100%; display:grid; grid-template-columns:repeat(4,1fr); gap:4px; }
  .nav-item { justify-content:center; flex-direction:column; gap:3px; font-size:10px; padding:8px 4px; }
  .content { padding:20px 16px 92px; }
  .topbar { align-items:flex-start; }
  .date-pill { display:none; }
  .grid.two-thirds, .grid.half, .settings-grid { grid-template-columns:1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns:1fr; }
  .span-2 { grid-column:auto; }
  .filters { grid-template-columns:1fr 1fr; }
}
@media (max-width: 520px) {
  .topbar-actions .btn { display:none; }
  .kpi-grid { grid-template-columns:1fr 1fr; }
  .kpi { padding:14px; }
  .filters { grid-template-columns:1fr; }
  .login-card { padding:28px 22px; }
}

/* Piano rateale e forecast */
.forecast-grid { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:14px; margin-bottom:16px; }
.forecast-kpi { background:linear-gradient(180deg,#fff,#f7fcfa); border:1px solid var(--line); border-radius:17px; padding:17px; box-shadow:var(--shadow); }
.forecast-kpi .value { font-size:clamp(19px,2vw,25px); font-weight:850; margin:6px 0 4px; }
.forecast-kpi .sub { color:var(--muted); font-size:12px; }
.metric-list { display:grid; gap:0; }
.metric-row { display:flex; justify-content:space-between; gap:16px; align-items:center; padding:13px 0; border-bottom:1px solid var(--line); font-size:13px; }
.metric-row span { color:var(--muted); }
.metric-row strong { text-align:right; }
.metric-note { margin:15px 0 0; color:var(--muted); font-size:11px; line-height:1.5; }
.text-good { color:var(--good); }
.text-danger { color:var(--danger); }

.plan-timeline { display:grid; max-height:365px; overflow:auto; padding-right:3px; }
.timeline-row { display:grid; grid-template-columns:18px minmax(0,1fr) auto; gap:10px; align-items:start; padding:12px 0; border-bottom:1px solid var(--line); }
.timeline-row:last-child { border-bottom:0; }
.timeline-dot { width:10px; height:10px; border-radius:50%; background:#c9cedb; margin-top:5px; box-shadow:0 0 0 4px #f1f3f7; }
.timeline-row.paid .timeline-dot { background:var(--good); box-shadow:0 0 0 4px #e2f6f0; }
.timeline-row.overdue .timeline-dot { background:var(--danger); box-shadow:0 0 0 4px #fdecef; }
.timeline-row.due .timeline-dot { background:var(--warn); box-shadow:0 0 0 4px #fff2dd; }
.timeline-main { min-width:0; }
.timeline-top { display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.timeline-sub, .plan-actual { display:block; color:var(--muted); font-size:11px; margin-top:4px; }
.status-badge { display:inline-flex; align-items:center; border-radius:999px; padding:4px 8px; font-size:10px; font-weight:850; white-space:nowrap; background:#f0f2f6; color:var(--muted); }
.status-badge.paid { background:#e3f7f0; color:#087a5b; }
.status-badge.overdue { background:#fdebee; color:#b7354c; }
.status-badge.due { background:#fff0d8; color:#a6660b; }
.status-badge.planned { background:#eaf8f1; color:var(--accent); }

.plan-layout { grid-template-columns:minmax(280px,.72fr) minmax(0,1.45fr); align-items:start; }
.compact-card { max-width:none; }
.inline-filters { display:flex; gap:8px; align-items:center; }
.inline-filters input { width:105px; }
.inline-filters select { width:175px; }
.notice { margin:-2px 0 18px; padding:12px 14px; border:1px solid #cce9dc; background:#effaf5; color:#176746; border-radius:12px; font-size:13px; line-height:1.45; }
.btn.tiny { padding:6px 8px; font-size:11px; border-radius:8px; }
.small-text { font-size:11px; }
.summary-chip.summary-danger { color:var(--danger); border-color:#f4ccd4; background:#fff6f7; }


.year-summary { display:grid; }
.year-summary-row { padding:14px 0; border-bottom:1px solid var(--line); }
.year-summary-row:last-child { border-bottom:0; }
.year-summary-head { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.year-summary-head strong { font-size:20px; color:var(--ink); }
.year-summary-head span { color:var(--muted); font-size:11px; }
.year-summary-total { margin:6px 0 10px; font-size:24px; font-weight:850; color:var(--accent); font-variant-numeric:tabular-nums; }
.year-summary-breakdown { display:grid; grid-template-columns:1fr 1fr; gap:7px 16px; }
.year-summary-breakdown span { display:flex; justify-content:space-between; gap:8px; color:var(--muted); font-size:11px; }
.year-summary-breakdown strong { color:var(--ink); font-variant-numeric:tabular-nums; }

@media (max-width: 1100px) {
  .forecast-grid { grid-template-columns:repeat(2,1fr); }
  .plan-layout { grid-template-columns:1fr; }
}
@media (max-width: 820px) {
  #nav { grid-template-columns:repeat(5,1fr); }
  .forecast-grid { grid-template-columns:repeat(2,1fr); }
  .timeline-row { grid-template-columns:16px minmax(0,1fr); }
  .timeline-row > .amount-pos { grid-column:2; }
}
@media (max-width: 520px) {
  .forecast-grid { grid-template-columns:1fr 1fr; gap:10px; }
  .forecast-kpi { padding:14px; }
  .inline-filters { width:100%; display:grid; grid-template-columns:1fr 1.4fr; }
  .inline-filters input, .inline-filters select { width:100%; }
  .metric-row { align-items:flex-start; }
}
