/* ── Variables ─────────────────────────────────────────────────────────────── */
:root {
  --bg:     #0f172a;
  --card:   #1e293b;
  --border: #334155;
  --blue:   #3b82f6;
  --green:  #22c55e;
  --amber:  #f59e0b;
  --red:    #ef4444;
  --text:   #f1f5f9;
  --muted:  #94a3b8;
  --purple: #a78bfa;
  --dark:   #0f172a;
}

/* ── Reset ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
button, input, textarea { font-family: inherit; -webkit-appearance: none; appearance: none; }
a { color: inherit; text-decoration: none; }

html {
  height: 100%;
  /* Prevent font scaling in landscape on iPhone */
  -webkit-text-size-adjust: 100%;
}

body {
  height: 100%;
  min-height: -webkit-fill-available;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Helvetica Neue', sans-serif;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* ── Layout ────────────────────────────────────────────────────────────────── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  height: 100vh; /* fallback */
  min-height: -webkit-fill-available;
}

#tab-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 16px;
  padding-top: max(56px, calc(env(safe-area-inset-top, 0px) + 16px));
  padding-bottom: 24px;
}

/* ── Bottom Nav ────────────────────────────────────────────────────────────── */
#nav {
  flex-shrink: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-top: 8px;
  padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
}

.nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 4px 2px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  transition: color 0.15s;
}

.nav-item.active { color: var(--blue); }
.nav-item svg { display: block; }
.nav-label { font-size: 10px; font-weight: 600; line-height: 1; }

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 16px; }
.page-title  { font-size: 28px; font-weight: 800; color: var(--text); letter-spacing: 0.3px; }
.page-sub    { font-size: 14px; color: var(--muted); margin-top: 2px; }

/* ── Section label ─────────────────────────────────────────────────────────── */
.section-label {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 8px 0 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}

/* ── Card ──────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  flex: 1;
}

/* ── Stat row / box ────────────────────────────────────────────────────────── */
.stat-row { display: flex; gap: 8px; }

.stat-box {
  flex: 1;
  background: var(--dark);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
}

.stat-value { font-size: 15px; font-weight: 700; }
.stat-sub   { font-size: 11px; font-weight: 600; opacity: 0.85; }
.stat-label { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* ── Saldo badge ───────────────────────────────────────────────────────────── */
.saldo-badge {
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 14px;
  font-weight: 700;
}

/* ── Alert / info / warning boxes ─────────────────────────────────────────── */
.alert-box, .info-box, .warn-box {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 8px;
  padding: 10px;
  margin-top: 10px;
  font-size: 13px;
  border-width: 1px;
  border-style: solid;
  line-height: 1.4;
}

.alert-box  { background: rgba(239,68,68,0.08);   border-color: rgba(239,68,68,0.2);   color: var(--text); }
.info-box   { background: rgba(59,130,246,0.08);  border-color: rgba(59,130,246,0.2);  color: var(--text); }
.warn-box   { background: rgba(245,158,11,0.08);  border-color: rgba(245,158,11,0.2);  color: var(--amber); }

/* ── Lordo row ─────────────────────────────────────────────────────────────── */
.lordo-row {
  margin-top: 12px;
  padding: 10px;
  background: var(--dark);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.lordo-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.lordo-value { font-size: 16px; font-weight: 700; color: var(--text); }
.lordo-sub   { font-size: 11px; color: var(--muted); }

/* ── Simulator ─────────────────────────────────────────────────────────────── */
.sim-label { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

.sim-row {
  display: flex;
  gap: 10px;
  margin-bottom: 8px;
}

.sim-input {
  flex: 1;
  background: var(--dark);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 16px;
  padding: 10px 14px;
  outline: none;
}

.sim-input:focus { border-color: var(--blue); }

.sim-btn {
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.sim-results { display: flex; flex-direction: column; gap: 6px; }

.sim-result-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--dark);
  border-radius: 10px;
  padding: 10px;
}

.sim-result-label { flex: 1; font-size: 13px; color: var(--text); }
.sim-result-value { font-size: 16px; font-weight: 800; color: var(--blue); }
.sim-result-rate  { font-size: 11px; color: var(--muted); min-width: 80px; text-align: right; }

/* ── Recupero box ──────────────────────────────────────────────────────────── */
.recupero-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(245,158,11,0.08);
  border: 1px solid rgba(245,158,11,0.2);
  border-radius: 8px;
  padding: 10px;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text);
}

/* ── Month / Day navigator ─────────────────────────────────────────────────── */
.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.nav-btn {
  background: var(--card);
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--blue);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}

.month-title { font-size: 20px; font-weight: 700; color: var(--text); text-align: center; }
.day-subtitle { font-size: 12px; color: var(--muted); margin-top: 2px; text-align: center; text-transform: capitalize; }

/* ── Forms ─────────────────────────────────────────────────────────────────── */
.section-card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}

.section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
}

.section-note {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 12px;
  line-height: 1.5;
}

.field-row { margin-bottom: 12px; }
.field-row:last-child { margin-bottom: 0; }

.field-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.field-hint {
  display: block;
  font-size: 11px;
  color: #475569;
  margin-bottom: 4px;
  line-height: 1.4;
}

.input-wrap { display: flex; align-items: center; gap: 8px; }

.input {
  width: 100%;
  background: var(--dark);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  padding: 10px 12px;
  outline: none;
  -webkit-appearance: none;
}
.input:focus { border-color: var(--blue); }
.input::placeholder { color: var(--muted); }

.input-suffix { font-size: 13px; color: var(--muted); min-width: 60px; }

.half-row { display: flex; gap: 10px; }
.half-field { flex: 1; }

.note-input {
  min-height: 60px;
  resize: none;
  vertical-align: top;
  -webkit-appearance: none;
}

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn-primary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 14px;
  padding: 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
  transition: background 0.15s;
}

.btn-primary.saved { background: var(--green); }

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  padding: 14px;
  cursor: pointer;
}

.btn-danger {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(239,68,68,0.12);
  border: 1px solid rgba(239,68,68,0.25);
  border-radius: 10px;
  color: var(--red);
  font-size: 14px;
  font-weight: 600;
  padding: 12px;
  cursor: pointer;
  width: 100%;
}

.danger-zone {
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: 16px;
  padding: 16px;
  margin-top: 8px;
  margin-bottom: 16px;
}

.danger-title {
  font-size: 12px;
  color: var(--red);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

/* ── Tags ──────────────────────────────────────────────────────────────────── */
.tag {
  display: inline-flex;
  border-radius: 6px;
  padding: 3px 8px;
  border-width: 1px;
  border-style: solid;
  font-size: 11px;
  font-weight: 600;
}

.mini-tag {
  border-radius: 6px;
  padding: 2px 7px;
  font-size: 10px;
  font-weight: 600;
  display: inline-block;
}

/* ── Giornaliero grid ──────────────────────────────────────────────────────── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

/* ── Entry rows ────────────────────────────────────────────────────────────── */
.entry-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--border);
  cursor: pointer;
}

.entry-date {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
  min-width: 32px;
}

.entry-tags { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; }

/* ── Storico ───────────────────────────────────────────────────────────────── */
.storico-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.export-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  color: var(--blue);
  cursor: pointer;
}

.export-btn.disabled { opacity: 0.5; color: var(--muted); }

.totals-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin-bottom: 12px;
}

.totals-title {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
}

.totals-row { display: flex; justify-content: space-around; }
.total-item { display: flex; flex-direction: column; align-items: center; }
.total-value { font-size: 18px; font-weight: 800; }
.total-label { font-size: 11px; color: var(--muted); margin-top: 2px; }

.year-scroll {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 12px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.year-scroll::-webkit-scrollbar { display: none; }

.year-btn {
  padding: 8px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.year-btn.active { background: var(--blue); border-color: var(--blue); color: white; }

.month-row {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 8px;
}

.month-header {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.month-name {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  min-width: 76px;
}

.month-tags { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }

.month-csv-btn {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 16px;
  cursor: pointer;
  padding: 2px 4px;
  line-height: 1;
}

.month-chevron {
  color: var(--muted);
  font-size: 12px;
  transition: transform 0.2s;
}

.month-detail {
  display: none;
  margin-top: 12px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.month-detail.open { display: block; }

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 3px 0;
}

.detail-label { font-size: 13px; color: var(--muted); }
.detail-value { font-size: 13px; color: var(--text); font-weight: 600; }
.detail-value.highlight { color: var(--green); }

/* ── Impostazioni ──────────────────────────────────────────────────────────── */
.riepilogo-card {
  background: var(--dark);
  border-radius: 12px;
  padding: 12px;
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.riepilogo-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.riepilogo-total {
  border-top: 1px solid var(--border);
  padding-top: 8px;
  margin-top: 2px;
}

.riepilogo-label { font-size: 13px; color: var(--muted); }
.riepilogo-value { font-size: 14px; font-weight: 700; color: var(--text); }

.info-card {
  text-align: center;
  padding: 16px 0 8px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.info-title { font-size: 15px; font-weight: 700; color: var(--muted); }
.info-text  { font-size: 13px; color: var(--border); }

/* ── Empty state ───────────────────────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 0;
  gap: 8px;
  color: var(--muted);
}

.empty-icon  { font-size: 48px; opacity: 0.5; }
.empty-title { font-size: 16px; font-weight: 600; }
.empty-sub   { font-size: 13px; color: var(--border); }

/* ── Hint text ─────────────────────────────────────────────────────────────── */
.hint-text {
  font-size: 13px;
  color: var(--muted);
  text-align: center;
  line-height: 1.5;
}

/* ── Count footer ──────────────────────────────────────────────────────────── */
.count-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 12px;
}
