:root {
  --bg: #1B211D;
  --panel: #232922;
  --panel-alt: #20261F;
  --panel-hover: #252B24;
  --border: #3A4238;
  --border-soft: #2A3128;
  --text: #E9E4D8;
  --muted: #8A9285;
  --faint: #5C6357;
  --gold: #C9A455;
  --gold-hover: #D9B565;
  --green: #8FAF7D;
  --red: #C1766B;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  min-height: 100vh;
}

.mono { font-family: 'IBM Plex Mono', monospace; }
.display { font-family: 'Fraunces', serif; }

header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(27,33,29,0.95);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  padding: calc(env(safe-area-inset-top, 0px) + 16px) 20px 16px;
}
.wrap { max-width: 640px; margin: 0 auto; }
.header-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; }
.title-group { display: flex; align-items: center; gap: 8px; min-width: 0; }
h1 { font-family: 'Fraunces', serif; font-size: 20px; letter-spacing: -0.02em; color: var(--text); font-weight: 600; }
.save-status { font-size: 10px; color: var(--muted); min-height: 13px; }
.save-status.err { color: var(--red); }

.year-nav { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.year-btn {
  background: var(--panel-hover); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; width: 32px; height: 32px; font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
select#yearSelect {
  background: var(--panel-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
  color: var(--text);
  font-family: 'IBM Plex Mono', monospace;
}
.year-add {
  background: none; border: 1px dashed var(--border); color: var(--muted);
  border-radius: 6px; width: 32px; height: 32px; font-size: 14px; cursor: pointer;
}

.totals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 12px; }
.totals .label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); }
.totals .value { font-family: 'IBM Plex Mono', monospace; font-size: 17px; color: var(--text); }
.totals .value.green { color: var(--green); }
.totals .value.red { color: var(--red); }

.progress { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress-fill { height: 100%; background: var(--gold); width: 0%; transition: width 0.5s ease-out; }
.progress-label { text-align: right; font-size: 11px; font-family: 'IBM Plex Mono', monospace; color: var(--muted); margin-top: 4px; }

main { max-width: 640px; margin: 0 auto; padding: 24px 20px 60px; }

.section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted);
  margin: 28px 0 12px;
  display: flex; align-items: center; justify-content: space-between;
}

.form-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 12px;
}
.form-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-bottom: 12px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.form-grid .full { grid-column: 1 / span 2; }
input, select, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  width: 100%;
  font-family: 'Inter', sans-serif;
}
textarea { resize: vertical; min-height: 64px; font-size: 14px; line-height: 1.4; }
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, select:focus, textarea:focus { border-color: var(--gold); }
input.mono { font-family: 'IBM Plex Mono', monospace; }

.btn-add {
  width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  background: var(--gold);
  color: var(--bg);
  font-weight: 600;
  border: none;
  border-radius: 6px;
  padding: 12px 0;
  font-size: 15px;
  cursor: pointer;
  font-family: 'Inter', sans-serif;
}
.btn-add:active { background: var(--gold-hover); }

.btn-ghost {
  background: none; border: 1px solid var(--border); color: var(--muted);
  font-size: 12px; border-radius: 6px; padding: 8px 14px; cursor: pointer;
  font-family: 'Inter', sans-serif;
}
.btn-ghost:active { border-color: var(--gold); color: var(--gold); }

.empty { text-align: center; color: var(--faint); font-size: 14px; padding: 40px 0; }

.months { display: flex; flex-direction: column; gap: 12px; }
.month-card { border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--panel-alt); }
.month-header {
  width: 100%;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  background: none; border: none; cursor: pointer;
  color: var(--text);
  font-family: 'Inter', sans-serif;
}
.month-header:active { background: var(--panel-hover); }
.month-left { display: flex; align-items: center; gap: 8px; }
.chevron { color: var(--muted); font-size: 12px; width: 14px; display: inline-block; }
.month-name { font-family: 'Fraunces', serif; font-size: 16px; }
.badge-now {
  font-size: 9px; text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--gold); border: 1px solid var(--gold);
  border-radius: 999px; padding: 2px 8px;
}
.note-dot { width: 6px; height: 6px; border-radius: 999px; background: var(--gold); flex-shrink: 0; }
.month-right { display: flex; align-items: center; gap: 12px; font-family: 'IBM Plex Mono', monospace; font-size: 14px; }
.month-right .pct { color: var(--muted); }

.items { border-top: 1px solid var(--border); }
.item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-soft);
}
.item:last-child { border-bottom: none; }
.check {
  background: none; border: none; cursor: pointer; padding: 0;
  flex-shrink: 0; display: flex;
  width: 22px; height: 22px;
}
.check svg { width: 22px; height: 22px; }
.item-body { flex: 1; min-width: 0; }
.item-name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
.item-name.done { text-decoration: line-through; color: var(--faint); }
.item-meta { font-size: 11px; color: var(--faint); font-family: 'IBM Plex Mono', monospace; }
.item-amount { font-family: 'IBM Plex Mono', monospace; font-size: 14px; color: var(--text); }
.item-amount.done { color: var(--faint); }
.del {
  background: none; border: none; cursor: pointer;
  flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  color: var(--red);
  min-width: 40px; min-height: 40px;
  margin: -8px -8px -8px 0;
}
.del svg { width: 18px; height: 18px; }

.month-notes { padding: 12px 16px 16px; border-top: 1px solid var(--border); }
.month-notes-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-bottom: 6px; }

/* Sezione pianificazione generale (note, risparmi, ecc.) */
.planning-list { display: flex; flex-direction: column; gap: 10px; }
.planning-card {
  background: var(--panel-alt); border: 1px solid var(--border); border-radius: 10px; padding: 14px;
}
.planning-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 6px; }
.planning-title-input {
  background: none; border: none; padding: 0; font-family: 'Fraunces', serif; font-size: 15px; color: var(--text); width: 100%;
}
.planning-title-input:focus { outline: none; }
.planning-body {
  background: none; border: none; padding: 0; font-size: 13px; color: var(--muted); width: 100%;
  resize: vertical; min-height: 44px; font-family: 'Inter', sans-serif; line-height: 1.4;
}
.planning-body:focus { outline: none; color: var(--text); }
.planning-meta { font-size: 10px; color: var(--faint); font-family: 'IBM Plex Mono', monospace; margin-top: 6px; }

.backup-bar {
  display: flex; gap: 8px; justify-content: center; margin-top: 32px; padding-top: 20px;
  border-top: 1px solid var(--border-soft);
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--gold); color: var(--text);
  padding: 10px 18px; border-radius: 8px; font-size: 13px; z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  max-width: calc(100% - 40px); text-align: center;
}

.update-banner {
  position: sticky; top: 0; z-index: 30;
  background: var(--gold); color: var(--bg);
  padding: 10px 16px; font-size: 13px; text-align: center;
  display: none; align-items: center; justify-content: center; gap: 12px;
}
.update-banner button {
  background: var(--bg); color: var(--gold); border: none; border-radius: 6px;
  padding: 6px 12px; font-size: 12px; cursor: pointer; font-weight: 600;
}

input[type="file"] { display: none; }
