/* Spese di famiglia — foglio di stile unico, mobile first. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f4;
  --border: #dcdfe6;
  --text: #1a1d23;
  --muted: #6b7280;
  --accent: #3f6fd8;
  --accent-soft: #e6edfb;
  --ok: #2f855a;
  --ok-soft: #e3f4ea;
  --warn: #b45309;
  --warn-soft: #fdf1e0;
  --err: #c0392b;
  --err-soft: #fbe9e7;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 14px rgba(16, 24, 40, .05);
  --tabbar-h: 60px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2b303b;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --accent: #6d97ef;
    --accent-soft: #1d2740;
    --ok: #57c98a;
    --ok-soft: #16281f;
    --warn: #e0a355;
    --warn-soft: #2c2317;
    --err: #ef7a6d;
    --err-soft: #2e1b1a;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

body { padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); }
body.no-tabbar { padding-bottom: 0; }

a { color: var(--accent); text-decoration: none; }

/* --- topbar ------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top);
}
.topbar-inner {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  max-width: 780px; margin: 0 auto; padding: 12px 16px;
}
.brand { font-weight: 650; font-size: 1.05rem; letter-spacing: -.01em; }

.content { max-width: 780px; margin: 0 auto; padding: 14px 16px 24px; }

/* --- tabbar ------------------------------------------------------------ */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; height: var(--tabbar-h);
  color: var(--muted); font-size: .7rem; font-weight: 550;
}
.tab svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tab.is-active { color: var(--accent); }

/* --- card / campi ------------------------------------------------------ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px; margin-bottom: 14px;
}
.card.tight { padding: 12px; }

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field > label, .field-label {
  display: block; font-size: .78rem; font-weight: 650; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); margin-bottom: 7px;
}

input[type=text], input[type=password], input[type=date], input[type=number],
input[type=search], input[type=file], select, textarea {
  width: 100%; padding: 11px 12px; font-size: 1rem; font-family: inherit;
  color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px;
  appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { min-height: 70px; resize: vertical; }
input[type=color] { width: 44px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }

/* importo grande, in evidenza */
.amount-input {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); padding: 6px 14px;
}
.amount-input:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.amount-input .cur { font-size: 1.6rem; color: var(--muted); }
.amount-input input {
  border: none; background: transparent; box-shadow: none !important;
  font-size: 2.1rem; font-weight: 650; letter-spacing: -.02em; padding: 6px 0;
  text-align: right;
}

/* --- chip -------------------------------------------------------------- */
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 13px; border-radius: 999px; font-size: .9rem; font-weight: 550;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background .12s, border-color .12s, transform .08s;
}
.chip:active { transform: scale(.96); }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.chip[aria-pressed=true], .chip.is-on {
  background: var(--accent-soft); border-color: var(--accent); color: var(--text);
}
.chip.chip-add { border-style: dashed; color: var(--muted); font-weight: 600; }
.chip.chip-sm { padding: 5px 10px; font-size: .82rem; }

.chip-row-actions { display: flex; gap: 7px; margin-bottom: 8px; flex-wrap: wrap; }
.hint { font-size: .76rem; color: var(--muted); margin-top: 7px; }

/* --- bottoni ----------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 11px 16px; font-size: .95rem; font-weight: 600; font-family: inherit;
  border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-ghost { background: transparent; }
.btn-danger { color: var(--err); border-color: var(--err); background: transparent; }
.btn-block { width: 100%; }
.btn-lg { padding: 15px 20px; font-size: 1.05rem; border-radius: 12px; }
.btn-sm { padding: 7px 11px; font-size: .82rem; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.submit-bar {
  position: sticky; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding: 10px 0 4px; background: linear-gradient(to top, var(--bg) 62%, transparent);
  z-index: 20;
}

/* --- flash / toast ----------------------------------------------------- */
.flash {
  padding: 11px 14px; border-radius: 10px; margin-bottom: 10px;
  font-size: .9rem; border: 1px solid transparent;
}
.flash-success { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.flash-error { background: var(--err-soft); color: var(--err); border-color: var(--err); }
.flash-info { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + 18px + env(safe-area-inset-bottom));
  z-index: 60; display: flex; align-items: center; gap: 14px;
  background: #21262f; color: #fff; padding: 12px 16px; border-radius: 12px;
  font-size: .9rem; box-shadow: 0 8px 28px rgba(0, 0, 0, .3);
  max-width: calc(100vw - 32px);
}
.toast button {
  background: none; border: none; color: #8ab4ff; font: inherit; font-weight: 700;
  cursor: pointer; padding: 0;
}

/* --- elenco spese ------------------------------------------------------ */
.month-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 10px; margin: 20px 2px 8px; flex-wrap: wrap;
}
.month-head h2 { font-size: 1rem; margin: 0; letter-spacing: -.01em; }
.month-total { font-variant-numeric: tabular-nums; font-weight: 650; }

.expense-list { list-style: none; margin: 0; padding: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.expense-row {
  display: flex; align-items: center; gap: 11px; padding: 11px 13px;
  border-bottom: 1px solid var(--border); color: inherit;
}
.expense-list li:last-child .expense-row { border-bottom: none; }
.expense-row .bar { width: 4px; align-self: stretch; border-radius: 3px; flex: none; }
.expense-row .main { flex: 1; min-width: 0; }
.expense-row .desc { font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-row .meta { font-size: .76rem; color: var(--muted); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.expense-row .amt { font-variant-numeric: tabular-nums; font-weight: 650; white-space: nowrap; }

.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px;
  font-size: .7rem; font-weight: 650; background: var(--surface-2); color: var(--muted);
}

/* --- saldi ------------------------------------------------------------- */
.balance-hero { text-align: center; padding: 22px 16px; }
.balance-hero .big {
  font-size: 2.4rem; font-weight: 700; letter-spacing: -.03em;
  font-variant-numeric: tabular-nums; margin: 6px 0;
}
.balance-hero .who { color: var(--muted); font-size: .95rem; }
.pos { color: var(--ok); }
.neg { color: var(--err); }

table.grid { width: 100%; border-collapse: collapse; font-size: .88rem; }
table.grid th, table.grid td { padding: 8px 6px; text-align: right; border-bottom: 1px solid var(--border); }
table.grid th:first-child, table.grid td:first-child { text-align: left; }
table.grid th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 650; }
table.grid td { font-variant-numeric: tabular-nums; }
table.grid tr:last-child td { border-bottom: none; }

/* --- grafici ----------------------------------------------------------- */
.charts { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 620px) { .charts { grid-template-columns: 1fr 1fr; } }
.chart-title { font-size: .78rem; font-weight: 650; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); margin-bottom: 10px; }
.chart-body { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.chart-body svg { width: 132px; height: 132px; flex: none; }
.legend { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 150px; font-size: .82rem; }
.legend li { display: flex; align-items: center; gap: 7px; padding: 2.5px 0; }
.legend .sw { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .lbl { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend .val { font-variant-numeric: tabular-nums; color: var(--muted); }

/* --- filtri ------------------------------------------------------------ */
details.filters summary {
  cursor: pointer; list-style: none; font-weight: 600; font-size: .9rem;
  display: flex; align-items: center; justify-content: space-between;
}
details.filters summary::-webkit-details-marker { display: none; }
.filter-group { margin-top: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* --- import ------------------------------------------------------------ */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }
table.rows { width: 100%; border-collapse: collapse; font-size: .82rem; white-space: nowrap; }
table.rows th, table.rows td { padding: 7px 8px; border-bottom: 1px solid var(--border); text-align: left; }
table.rows th { font-size: .7rem; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }
table.rows tr.is-dup { background: var(--warn-soft); }
table.rows tr.is-err { background: var(--err-soft); }
table.rows select { padding: 5px 7px; font-size: .8rem; border-radius: 7px; width: auto; min-width: 108px; }
table.rows input[type=checkbox] { width: 20px; height: 20px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82rem; }

.spec { font-size: .85rem; }
.spec dt { font-weight: 650; margin-top: 9px; }
.spec dd { margin: 2px 0 0; color: var(--muted); }

.empty { text-align: center; color: var(--muted); padding: 40px 20px; }

/* --- login ------------------------------------------------------------- */
.login-wrap { max-width: 380px; margin: 8vh auto; padding: 0 20px; }
.login-logo { text-align: center; margin-bottom: 22px; }
.login-logo svg { width: 56px; height: 56px; }
.login-logo h1 { font-size: 1.3rem; margin: 10px 0 0; letter-spacing: -.02em; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stack > * + * { margin-top: 10px; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.nowrap { white-space: nowrap; }
hr.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
