/* I Want to Save — stile, pensato prima per il telefono. */

:root {
  --bg: #0E1412;
  --surface: #18221E;
  --surface-2: #1F2B26;
  --surface-settings: #141C2A;
  --border: #26332D;
  --primary: #6FD66B;
  --primary-ink: #0E1412;
  --text: #E4ECE6;
  --text-muted: #8A9A92;
  --danger: #E5534B;

  --radius: 14px;
  --radius-sm: 10px;
  --tap: 44px;
  --tabbar-h: 64px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
}

a { color: inherit; text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.35rem; font-weight: 650; }
h2 { font-size: 1.05rem; font-weight: 600; }

svg.lucide { width: 22px; height: 22px; stroke-width: 2; flex: none; }

.muted { color: var(--text-muted); }
.danger { color: var(--danger); }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---- Contenitore delle viste ---- */

.view {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
}

.view-inner { display: flex; flex-direction: column; gap: 16px; }

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: var(--tap);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 32px 16px;
  text-align: center;
  color: var(--text-muted);
}
.empty.error { color: var(--danger); }
.empty svg.lucide { width: 32px; height: 32px; }

/* ---- Pulsanti ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* ---- Campi ---- */

.field { display: flex; flex-direction: column; gap: 6px; }
.field label, .field .label { font-size: 0.9rem; color: var(--text-muted); }

.input, select.input, textarea.input {
  width: 100%;
  min-height: var(--tap);
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.input:focus { outline: none; border-color: var(--primary); }
.input[type="color"] { padding: 4px; width: 64px; }

.form-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(229, 83, 75, 0.12);
  color: var(--danger);
}

/* ---- Elenchi ---- */

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: 0; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .sub { font-size: 0.85rem; color: var(--text-muted); }

.badge-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  flex: none;
}

.tag {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ---- Barra in basso ---- */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  align-items: center;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--surface);
  border-top: 1px solid var(--border);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: var(--tap);
  height: 100%;
  color: var(--text-muted);
  font-size: 0.72rem;
}
.tab.active { color: var(--primary); }

.tab-add-circle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  margin-top: -22px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--primary-ink);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
.tab-add-circle svg.lucide { width: 28px; height: 28px; stroke-width: 2.5; }
.tab-add.active .tab-add-circle { outline: 2px solid var(--text); outline-offset: 2px; }

/* ---- PC ---- */

@media (min-width: 768px) {
  .view { padding-top: 32px; }
  .tabbar {
    left: 50%;
    right: auto;
    bottom: 16px;
    width: 480px;
    transform: translateX(-50%);
    border: 1px solid var(--border);
    border-radius: 20px;
    height: var(--tabbar-h);
    padding-bottom: 0;
  }
  .tab:hover { color: var(--text); }
}

/* ---- Mese ---- */

.month-nav h1 { flex: 1; text-align: center; }

.total-card { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.total { font-size: 2rem; font-weight: 700; }
.chart-box { position: relative; width: 100%; max-width: 260px; height: 220px; margin-top: 8px; }

section.card h2 { margin-bottom: 4px; }

.expense-link { color: inherit; }
.expense-link:active { background: var(--surface-2); }
.expense-link .grow { display: flex; flex-direction: column; }
.expense-link .tag { margin-left: 6px; vertical-align: 1px; }

/* ---- Modulo spesa ---- */

.expense-form { display: flex; flex-direction: column; gap: 18px; }

.amount-input { display: flex; align-items: center; gap: 8px; font-size: 1.6rem; }
.input-amount { font-size: 1.6rem; font-weight: 650; }

.cat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.cat-chip {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 72px;
  padding: 8px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.78rem;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
}
.cat-chip svg.lucide { color: var(--cat); }
.cat-chip[aria-checked="true"] {
  border-color: var(--cat);
  background: color-mix(in srgb, var(--cat) 18%, var(--surface));
  box-shadow: inset 0 0 0 1px var(--cat);
}

.icon-picker summary {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: var(--tap);
  cursor: pointer;
  color: var(--text-muted);
}
.icon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--tap), 1fr));
  gap: 6px;
  padding-top: 8px;
}
.icon-choice {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: var(--tap);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}
.icon-choice[aria-pressed="true"] { border-color: var(--primary); color: var(--primary); }

/* Salva resta sempre visibile sopra la barra in basso: importo, categoria, Salva senza scorrere. */
.expense-form [type="submit"] {
  position: sticky;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 10px);
  z-index: 5;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
@media (min-width: 768px) {
  .expense-form [type="submit"] { bottom: calc(var(--tabbar-h) + 28px); }
}

/* ---- Anno ---- */

.bar-box { position: relative; width: 100%; height: 220px; margin-top: 8px; }
.hint { font-size: 0.8rem; }

/* ---- Impostazioni: area separata, con superfici blu scuro ---- */

.settings-title {
  padding: 12px 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #1B2638, var(--surface-settings));
  border: 1px solid #22304A;
}
.settings-title h1 { display: flex; align-items: center; gap: 10px; }
.settings-title svg.lucide { color: #8FB3FF; }

.settings-card { background: var(--surface-settings); border-color: #22304A; }
.settings-card .list-item { border-bottom-color: #22304A; }

.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; }
.btn-small svg.lucide { width: 18px; height: 18px; }

.row-btn {
  width: 100%;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}
li:last-child > .row-btn { border-bottom: 0; }
.row-btn:active { background: rgba(255, 255, 255, 0.04); }
.row-btn .grow { display: flex; flex-direction: column; }
.row-btn > svg.lucide.muted { width: 18px; height: 18px; color: var(--text-muted); }
.row-btn.inactive .title, .row-btn.inactive .amount { color: var(--text-muted); text-decoration: line-through; }

/* ---- Finestre modali (dal basso sul telefono, al centro su PC) ---- */

dialog.sheet {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  margin: auto auto 0;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  border: 1px solid #22304A;
  border-radius: 18px 18px 0 0;
  background: var(--surface-settings);
  color: var(--text);
  overflow-y: auto;
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, 0.6); }
.sheet-form { display: flex; flex-direction: column; gap: 16px; }
.sheet-form .icon-grid { max-height: 168px; overflow-y: auto; }
.sheet-form .icon-choice { background: var(--bg); }

.icon-field { display: flex; align-items: center; gap: 10px; }
.icon-field .input { flex: 1; }

@media (min-width: 768px) {
  dialog.sheet { margin: auto; border-radius: 18px; }
}
.past-warning { font-size: 0.85rem; color: #F2C94C; }
