:root {
  --bg: #15111f;
  --bg-card: #211c30;
  --bg-card-2: #2a2438;
  --text: #f2eefa;
  --muted: #a49bc0;
  --orange: #ff8a3d;
  --orange-dark: #e06a1f;
  --pink: #e0356b;
  --pink-2: #b0205a;
  --green: #35c07a;
  --yellow: #f0b429;
  --red: #ef4444;
  --border: #33304a;
  --radius: 18px;
  font-size: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  min-height: 100vh;
  padding-bottom: 84px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }

button { font-family: inherit; cursor: pointer; }
input, select {
  font-family: inherit;
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1rem;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--orange); }

label { display: block; margin-bottom: 14px; font-size: 0.85rem; color: var(--muted); }
label input, label select { margin-top: 6px; color: var(--text); }

.btn {
  border: none;
  border-radius: 14px;
  padding: 13px 18px;
  font-weight: 600;
  font-size: 0.95rem;
  width: 100%;
}
.btn-primary { background: linear-gradient(135deg, var(--orange), var(--pink)); color: #fff; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-secondary { background: var(--bg-card-2); color: var(--text); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn-small { width: auto; padding: 8px 12px; font-size: 0.82rem; border-radius: 10px; }

.icon-btn {
  background: var(--bg-card-2);
  border: none;
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 50%;
  font-size: 1.1rem;
}

/* ---------- Login ---------- */
#view-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.login-box {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 36px 28px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}
.login-logo { font-size: 2.6rem; margin-bottom: 8px; }
.login-box h1 { margin: 0 0 4px; font-size: 1.3rem; }
.login-box input { margin: 18px 0 14px; text-align: center; letter-spacing: 3px; }
.error-text { color: var(--red); min-height: 1.2em; font-size: 0.85rem; }

/* ---------- Topbar ---------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 20px 18px 8px;
}
.eyebrow { color: var(--orange); font-size: 0.72rem; font-weight: 700; letter-spacing: 1.5px; }
.topbar h1 { font-size: 1.35rem; margin: 4px 0 2px; }
.role-badge {
  font-size: 0.65rem;
  background: var(--bg-card-2);
  padding: 3px 9px;
  border-radius: 20px;
  vertical-align: middle;
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
}

main { padding: 8px 16px 16px; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 14px;
}
.hero-card {
  background: linear-gradient(135deg, var(--pink), var(--pink-2));
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
  position: relative;
  overflow: hidden;
}
.hero-card .eyebrow { color: #ffd9e6; }
.hero-card .amount { font-size: 2.1rem; font-weight: 800; margin: 6px 0 2px; }
.hero-card .sub { color: #ffd9e6; font-size: 0.85rem; }
.alert-badge {
  position: absolute; top: 16px; right: 16px;
  background: var(--orange);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 5px 11px;
  border-radius: 20px;
}

.action-row { display: flex; gap: 10px; margin-bottom: 16px; }
.action-card {
  flex: 1;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px 10px;
  text-align: center;
  color: var(--text);
}
.action-card.primary { border-color: var(--orange); }
.action-card .emoji { font-size: 1.6rem; display: block; margin-bottom: 6px; }
.action-card .label { font-weight: 700; font-size: 0.9rem; }
.action-card .sub { font-size: 0.72rem; color: var(--muted); }

.pill-row { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.pill-btn {
  background: var(--bg-card-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
}
.pill-btn.active { background: var(--pink); border-color: var(--pink); color: #fff; }

.section-title {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 18px 0 8px;
  font-weight: 700;
}

/* ---------- Expense rows ---------- */
.expense-item {
  background: var(--bg-card);
  border-radius: 14px;
  padding: 13px 14px;
  margin-bottom: 10px;
}
.expense-top { display: flex; justify-content: space-between; align-items: center; }
.expense-left { display: flex; align-items: center; gap: 10px; }
.expense-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--bg-card-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem;
}
.expense-name { font-weight: 700; font-size: 0.92rem; }
.expense-meta { font-size: 0.75rem; color: var(--muted); }
.expense-amount { font-weight: 800; font-size: 1rem; }
.expense-amount.entrata { color: var(--green); }
.expense-amount.uscita { color: var(--text); }
.expense-del { background: none; border: none; color: var(--muted); font-size: 0.9rem; padding: 4px; }

.budget-mini { margin-top: 8px; }
.budget-mini-bar { height: 5px; border-radius: 4px; background: var(--bg-card-2); overflow: hidden; }
.budget-mini-fill { height: 100%; border-radius: 4px; }
.budget-mini-label { font-size: 0.7rem; color: var(--muted); margin-top: 3px; }

.status-ok { color: var(--green); }
.status-quasi { color: var(--yellow); }
.status-superato { color: var(--red); }
.fill-ok { background: var(--green); }
.fill-quasi { background: var(--yellow); }
.fill-superato { background: var(--red); }

/* ---------- Budget page ---------- */
.budget-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.budget-card-top { display: flex; justify-content: space-between; align-items: baseline; }
.budget-card-title { font-weight: 700; }
.budget-bar-outer { height: 8px; border-radius: 6px; background: var(--bg-card-2); margin: 10px 0 6px; overflow: hidden; }
.budget-bar-inner { height: 100%; border-radius: 6px; transition: width .3s; }
.budget-card-bottom { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--muted); }
.carry-badge {
  background: rgba(255,138,61,0.15);
  color: var(--orange);
  font-size: 0.68rem;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 700;
}
.status-chip {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 10px;
  text-transform: uppercase;
}
.status-chip.ok { background: rgba(53,192,122,0.15); color: var(--green); }
.status-chip.quasi { background: rgba(240,180,41,0.15); color: var(--yellow); }
.status-chip.superato { background: rgba(239,68,68,0.15); color: var(--red); }

.no-budget-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
}

/* ---------- Riepilogo ---------- */
.summary-row {
  display: flex; justify-content: space-between;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.summary-row:last-child { border-bottom: none; }
.chart-wrap { background: var(--bg-card); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.chart-wrap canvas { max-height: 320px; }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}
.tab-btn {
  flex: 1;
  background: none; border: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 1.1rem; padding: 6px 2px;
  border-radius: 10px;
}
.tab-btn span { font-size: 0.62rem; font-weight: 600; }
.tab-btn.active { color: var(--orange); }

/* ---------- Modal ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.6);
  display: flex; align-items: flex-end; justify-content: center;
  z-index: 50;
}
.modal-card {
  background: var(--bg-card);
  width: 100%; max-width: 480px;
  border-radius: 22px 22px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  max-height: 90vh;
  overflow-y: auto;
}
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.ocr-zone { text-align: center; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px dashed var(--border); }

.alert-box {
  background: rgba(239,68,68,0.12);
  border: 1px solid var(--red);
  color: #ffb3b3;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.82rem;
  margin-bottom: 14px;
}

.toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: var(--bg-card-2); color: var(--text);
  padding: 10px 18px; border-radius: 30px;
  font-size: 0.85rem; z-index: 60;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
}

.month-select-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.month-select-row select { flex: 1; }

.fab-add {
  position: fixed; right: 18px; bottom: 96px;
  width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--orange), var(--pink));
  color: #fff; font-size: 1.6rem; border: none;
  box-shadow: 0 6px 18px rgba(224,53,107,0.4);
  z-index: 25;
}

.cat-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-card); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px;
}
.cat-row .cat-name { font-weight: 600; font-size: 0.88rem; }
.cat-row .cat-type { font-size: 0.7rem; color: var(--muted); }

.two-col { display: flex; gap: 10px; }
.two-col > * { flex: 1; }

.empty-state { text-align: center; color: var(--muted); padding: 30px 10px; font-size: 0.88rem; }
