/* Budget Control - stile responsive mobile-first.
   Palette sobria con accenti per gli stati. */

:root {
  --bg: #F8FAFC;
  --bg-elev: #FFFFFF;
  --bg-soft: #F1F5F9;
  --text: #0F172A;
  --text-soft: #475569;
  --text-muted: #94A3B8;
  --border: #E2E8F0;
  --primary: #4F46E5;
  --primary-dark: #4338CA;
  --primary-soft: #EEF2FF;
  --ok: #10B981;
  --ok-soft: #ECFDF5;
  --warning: #F59E0B;
  --warning-soft: #FFFBEB;
  --bad: #EF4444;
  --bad-soft: #FEF2F2;
  --neutral: #94A3B8;
  --shadow: 0 1px 2px rgba(15,23,42,0.04), 0 4px 12px rgba(15,23,42,0.06);
  --radius: 14px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  line-height: 1.45;
  font-size: 16px;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout ---------- */
.main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

@media (min-width: 768px) {
  .main { padding: 24px; padding-bottom: 24px; }
}

.page-header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.page-header h1 { margin: 0; font-size: 22px; }
.page-header .subtitle { color: var(--text-soft); font-size: 14px; margin: 0; }

@media (min-width: 768px) {
  .page-header h1 { font-size: 28px; }
}

/* ---------- Topbar ---------- */
.topbar {
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}

.topbar-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex; align-items: center; gap: 8px;
  color: var(--text); font-weight: 600;
  text-decoration: none;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--primary); color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700;
}
.brand-name { font-size: 15px; }

.nav-desktop {
  display: none;
  margin-left: 24px;
  gap: 4px;
}

.nav-desktop a {
  color: var(--text-soft);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
}
.nav-desktop a:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }

@media (min-width: 900px) {
  .nav-desktop { display: flex; }
  .brand-name { font-size: 16px; }
}

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-soft);
  background: transparent;
  border: 1px solid transparent;
}
.icon-btn:hover { background: var(--bg-soft); color: var(--text); text-decoration: none; }

/* ---------- Bottom bar (mobile) ---------- */
.bottombar {
  position: fixed; left: 0; right: 0; bottom: 0;
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 60;
  padding-bottom: env(safe-area-inset-bottom);
}
.bb-item {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 4px;
  color: var(--text-soft);
  font-size: 11px;
  font-weight: 500;
}
.bb-item:hover { text-decoration: none; color: var(--text); }
.bb-add {
  background: var(--primary);
  border-radius: 50%;
  color: #fff !important;
  width: 52px; height: 52px;
  flex: 0 0 auto;
  margin-top: -16px;
  box-shadow: 0 4px 14px rgba(79,70,229,0.4);
}
.bb-plus { font-size: 28px; line-height: 1; font-weight: 300; }

@media (min-width: 900px) {
  .bottombar { display: none; }
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 12px; }

.card-title {
  margin: 0 0 12px 0;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-row {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.card-row:last-child { border-bottom: none; }
.card-row .label { color: var(--text-soft); font-size: 14px; }
.card-row .value { font-weight: 600; }

.cards-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
@media (min-width: 640px) {
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 980px) {
  .cards-grid { grid-template-columns: repeat(3, 1fr); }
}

.kpi {
  display: flex; flex-direction: column; gap: 6px;
}
.kpi .kpi-label {
  font-size: 13px; color: var(--text-soft);
  text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600;
}
.kpi .kpi-value { font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.kpi .kpi-sub { font-size: 13px; color: var(--text-soft); }

/* ---------- Status badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--bg-soft);
  color: var(--text-soft);
}
.badge::before {
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
  background: currentColor;
}
.badge.status-ok { background: var(--ok-soft); color: var(--ok); }
.badge.status-warning { background: var(--warning-soft); color: var(--warning); }
.badge.status-bad { background: var(--bad-soft); color: var(--bad); }
.badge.status-neutral { background: var(--bg-soft); color: var(--text-muted); }

/* ---------- Progress bars ---------- */
.progress {
  height: 10px;
  background: var(--bg-soft);
  border-radius: 999px;
  overflow: hidden;
}
.progress > .bar {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress.status-ok > .bar { background: var(--ok); }
.progress.status-warning > .bar { background: var(--warning); }
.progress.status-bad > .bar { background: var(--bad); }
.progress.status-neutral > .bar { background: var(--neutral); }
.progress-lg { height: 14px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
}
.btn:hover { background: var(--bg-soft); text-decoration: none; }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }
.btn-danger {
  background: var(--bad); color: #fff; border-color: var(--bad);
}
.btn-danger:hover { background: #DC2626; border-color: #DC2626; color: #fff; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-lg { padding: 14px 20px; font-size: 16px; }
.btn-block { width: 100%; }

.btn-row {
  display: flex; gap: 8px; flex-wrap: wrap;
  margin-top: 16px;
}

.hide-on-mobile { display: none; }
@media (min-width: 640px) { .hide-on-mobile { display: inline-flex; } }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block; font-size: 14px; font-weight: 500; margin-bottom: 6px;
  color: var(--text-soft);
}
.form-control,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  font-size: 16px;
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; min-height: 64px; }

.form-help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-error {
  font-size: 13px; color: var(--bad); margin-top: 4px;
}
.form-row {
  display: grid; grid-template-columns: 1fr; gap: 12px;
}
@media (min-width: 640px) {
  .form-row { grid-template-columns: 1fr 1fr; }
}

.errorlist { list-style: none; padding: 0; margin: 4px 0 0; color: var(--bad); font-size: 13px; }

.checkbox-row {
  display: flex; align-items: flex-start; gap: 8px; margin: 8px 0;
}
.checkbox-row input[type="checkbox"] {
  width: 18px; height: 18px; flex: 0 0 18px; margin-top: 2px;
}

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
}
table.t {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.t th, table.t td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.t th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-soft);
  background: var(--bg-soft);
}
table.t tr:last-child td { border-bottom: none; }
table.t .num { text-align: right; font-variant-numeric: tabular-nums; }

/* Card-list su mobile per spese/entrate */
.tx-list { display: flex; flex-direction: column; gap: 8px; }
.tx-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.tx-item .tx-icon {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--primary-soft);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 20px;
}
.tx-item .tx-main { min-width: 0; }
.tx-item .tx-name {
  font-weight: 600; font-size: 15px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tx-item .tx-meta {
  color: var(--text-soft); font-size: 12px;
}
.tx-item .tx-amount {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.tx-amount.is-expense { color: var(--bad); }
.tx-amount.is-income { color: var(--ok); }
.tx-item .tx-actions {
  display: flex; gap: 6px;
}

/* ---------- Alerts/messages ---------- */
.messages {
  max-width: 1080px;
  margin: 12px auto 0;
  padding: 0 16px;
  display: flex; flex-direction: column; gap: 8px;
}
.alert {
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  border: 1px solid;
}
.alert-success { background: var(--ok-soft); border-color: rgba(16,185,129,0.3); color: #065F46; }
.alert-info { background: var(--primary-soft); border-color: rgba(79,70,229,0.3); color: #3730A3; }
.alert-warning { background: var(--warning-soft); border-color: rgba(245,158,11,0.3); color: #92400E; }
.alert-error { background: var(--bad-soft); border-color: rgba(239,68,68,0.3); color: #991B1B; }

/* ---------- Public home ---------- */
.public-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 32px 20px;
  text-align: center;
}
.public-hero {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 24px;
  box-shadow: var(--shadow);
}
.public-hero h1 {
  margin: 0 0 12px;
  font-size: 28px;
  letter-spacing: -0.02em;
}
.public-hero p {
  margin: 0 auto 20px;
  color: var(--text-soft);
  max-width: 540px;
}
.feature-list {
  display: grid; grid-template-columns: 1fr; gap: 12px;
  margin-top: 24px; text-align: left;
}
@media (min-width: 640px) {
  .feature-list { grid-template-columns: 1fr 1fr; }
  .public-hero h1 { font-size: 36px; }
}
.feature {
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 16px;
  font-size: 14px;
}
.feature strong { display: block; margin-bottom: 4px; }

/* ---------- Helpers ---------- */
.row-flex { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.row-flex.between { justify-content: space-between; }
.muted { color: var(--text-soft); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.num { font-variant-numeric: tabular-nums; }
.tcenter { text-align: center; }
.tright { text-align: right; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }

.period-form {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.period-form select, .period-form input { padding: 8px 10px; font-size: 14px; }

/* Empty state */
.empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-soft);
}
.empty p { margin: 8px 0; }

/* Bar list (alternative semplice ai grafici) */
.bar-list { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 1fr; gap: 4px; }
.bar-row .bar-row-head {
  display: flex; justify-content: space-between; font-size: 13px;
}
.bar-row .bar-name { font-weight: 500; }
.bar-row .bar-value { font-variant-numeric: tabular-nums; color: var(--text-soft); }

/* Chart canvas wrapper */
.chart-wrap {
  position: relative;
  width: 100%;
  height: 260px;
}
@media (min-width: 768px) { .chart-wrap { height: 320px; } }

/* ---------- Settings ---------- */
.danger-zone {
  border: 1px solid rgba(239,68,68,0.3);
  background: var(--bad-soft);
  border-radius: var(--radius);
  padding: 16px;
}
.danger-zone h3 { color: var(--bad); margin-top: 0; }

/* Catetogory list */
.category-grid {
  display: grid; grid-template-columns: 1fr; gap: 12px;
}
@media (min-width: 640px) {
  .category-grid { grid-template-columns: 1fr 1fr; }
}
.cat-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.cat-row .cat-icon {
  width: 36px; height: 36px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--primary-soft);
  font-size: 18px;
}
.cat-row.is-inactive { opacity: 0.55; }
.cat-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }
.cat-actions form { display: inline; }
.cat-name { font-weight: 600; }

hr.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

/* Public auth */
.auth-wrap {
  max-width: 420px;
  margin: 0 auto;
  padding: 32px 16px;
}
.auth-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 16px; font-size: 22px; }
.auth-foot { text-align: center; font-size: 14px; margin-top: 12px; color: var(--text-soft); }

/* List filter strip */
.filter-strip {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  margin-bottom: 16px;
}
@media (min-width: 640px) {
  .filter-strip { grid-template-columns: auto 1fr 1fr auto; align-items: center; }
}

.summary-strip {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 16px;
}
.summary-strip .label { color: var(--text-soft); font-size: 13px; }
.summary-strip .value { font-weight: 700; font-size: 20px; }
