:root {
  --bg: #f4f4f8;
  --card: #ffffff;
  --ink: #1a1a2e;
  --ink-soft: #5b5b70;
  --accent: #ff7a00;
  --accent-dark: #e06a00;
  --navy: #1a1a2e;
  --danger: #d33;
  --ok: #1a9c6b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(26, 26, 46, 0.08), 0 4px 14px rgba(26, 26, 46, 0.06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--navy); color: #fff;
  padding: calc(14px + env(safe-area-inset-top)) 18px 14px;
  display: flex; align-items: baseline; gap: 10px;
}
.topbar h1 { font-size: 1.15rem; margin: 0; }
.topbar .subtitle { font-size: 0.75rem; opacity: 0.7; }

main { max-width: 720px; margin: 0 auto; padding: 14px 14px 20px; }
.tab.hidden, .hidden { display: none !important; }

.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 14px;
}
.card h2 { font-size: 1rem; margin: 0 0 12px; }

label { display: block; font-size: 0.82rem; color: var(--ink-soft); margin-bottom: 10px; font-weight: 600; }
input, select {
  width: 100%; margin-top: 4px; padding: 10px 12px;
  border: 1px solid #d8d8e4; border-radius: 10px;
  font-size: 1rem; font-weight: 400; color: var(--ink); background: #fff;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 420px) { .grid2 { grid-template-columns: 1fr; } }

.btn {
  border: none; border-radius: 10px; padding: 12px 16px;
  font-size: 0.95rem; font-weight: 700; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:active { background: var(--accent-dark); }
.btn-ghost { background: #ececf3; color: var(--ink); }
.btn-danger { background: #fdecec; color: var(--danger); }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; align-items: center; }
.btn-row .btn { flex: 1; }
.btn-row label.btn-row { margin: 0; }

.msg { margin-top: 10px; font-size: 0.85rem; font-weight: 600; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

.file-label { display: block; }
.file-name { display: block; font-size: 0.78rem; color: var(--ink-soft); font-weight: 400; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; font-weight: 600; color: var(--ink-soft); margin: 10px 0; }
.check input { width: auto; margin: 0; }

/* filtri */
#f-mese { }

/* lista spese */
.summary {
  background: var(--navy); color: #fff; border-radius: var(--radius);
  padding: 10px 16px; margin-bottom: 14px; font-size: 0.9rem; font-weight: 600;
  display: flex; justify-content: space-between;
}
.spesa {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; margin-bottom: 10px; cursor: pointer;
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
}
.spesa:active { background: #f0f0f6; }
.spesa .sinfo { min-width: 0; }
.spesa .sline1 { font-weight: 700; font-size: 0.92rem; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spesa .sline2 { font-size: 0.78rem; color: var(--ink-soft); margin-top: 3px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spesa .simporto { font-weight: 800; font-size: 1rem; white-space: nowrap; }
.chip {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 0.68rem; font-weight: 700; color: #fff;
}
.chip.Autostrada\ furgone\ scuola { background: #f97316; }
.chip.Autostrada\ auto\ propria { background: #f43f5e; }
.chip.Traghetto { background: #14b8a6; }
.chip.Rifornimenti\ furgone\ scuola { background: #f59e0b; }
.chip.Rifornimenti\ auto\ propria { background: #ec4899; }
.chip.Rifornimenti\ moto { background: #eab308; }
.chip.Ristorante { background: #ef4444; }
.chip.Albergo { background: #3b82f6; }
.chip.Bar { background: #8b5cf6; }
.chip.Parcheggi { background: #10b981; }
.chip.Treni { background: #06b6d4; }
.chip.Aerei { background: #6366f1; }
.chip.Varie { background: #6b7280; }
.empty { text-align: center; color: var(--ink-soft); padding: 30px 0; font-size: 0.9rem; }

/* report */
.seg { display: flex; background: #ececf3; border-radius: 10px; padding: 4px; margin-bottom: 14px; }
.seg-btn {
  flex: 1; border: none; background: transparent; padding: 9px 6px;
  border-radius: 8px; font-size: 0.8rem; font-weight: 700; color: var(--ink-soft); cursor: pointer;
}
.seg-btn.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,0.12); }

.rep-table-wrap { overflow-x: auto; }
table.rep { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
table.rep th {
  background: var(--navy); color: #fff; text-align: left;
  padding: 8px 10px; font-size: 0.75rem; white-space: nowrap;
}
table.rep td { padding: 8px 10px; border-bottom: 1px solid #e6e6ee; vertical-align: top; }
table.rep tr:nth-child(even) td { background: #f8f8fc; }
table.rep td.imp { text-align: right; font-weight: 700; white-space: nowrap; }
table.rep tfoot td { font-weight: 800; background: #ffe8d1 !important; }
.rep-tot { margin-top: 10px; display: flex; justify-content: space-between; font-weight: 800; font-size: 1.05rem; }
.rep-actions { display: flex; gap: 10px; margin-top: 14px; }
.rep-actions .btn { flex: 1; }
.btn-xls { background: #1a9c6b; color: #fff; }
.btn-pdf { background: #d33; color: #fff; }
.rep-meta { font-size: 0.8rem; color: var(--ink-soft); margin: 0 0 10px; }

/* anagrafiche */
.inline-form { display: flex; gap: 10px; margin-bottom: 12px; }
.inline-form input { flex: 1; margin: 0; }
.inline-form .btn { white-space: nowrap; }
.form-evento input { margin-bottom: 10px; }
.form-evento .btn { width: 100%; }
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 4px; border-bottom: 1px solid #ececf3; font-size: 0.9rem;
}
.list li:last-child { border-bottom: none; }
.list .lname { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.list .lsub { font-size: 0.75rem; color: var(--ink-soft); font-weight: 400; }
.del-btn {
  border: none; background: #fdecec; color: var(--danger);
  border-radius: 8px; padding: 6px 10px; font-weight: 700; cursor: pointer; font-size: 0.8rem;
}

/* tabbar */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: flex; background: #fff;
  border-top: 1px solid #e6e6ee;
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbtn {
  flex: 1; border: none; background: transparent; padding: 10px 4px 8px;
  font-size: 0.72rem; font-weight: 700; color: var(--ink-soft); cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.tabbtn span { font-size: 1.3rem; }
.tabbtn.active { color: var(--accent); }

@media (min-width: 800px) {
  .topbar { border-radius: 0; }
  body { padding-bottom: 20px; }
  .tabbar {
    position: static; flex-direction: row;
    margin: 0 auto 20px; max-width: 720px;
    border: 1px solid #e6e6ee; border-radius: var(--radius);
    padding: 0; background: #fff;
  }
  .tabbtn { flex-direction: row; gap: 8px; padding: 12px; }
  main { padding-top: 18px; }
}

/* modale */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 20, 35, 0.5); }
.modal-box {
  position: relative; width: 100%; max-width: 720px; max-height: 90vh; overflow-y: auto;
  background: var(--card); border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
}
.modal-box h2 { margin: 0 0 12px; font-size: 1.05rem; }
@media (min-width: 700px) {
  .modal { align-items: center; }
  .modal-box { border-radius: 18px; max-height: 85vh; }
}
.dettaglio-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; font-size: 0.9rem; margin-bottom: 12px; }
.dettaglio-grid .k { color: var(--ink-soft); font-size: 0.75rem; font-weight: 600; }
.dettaglio-grid .v { font-weight: 600; }
.allegato-anteprima img { max-width: 100%; max-height: 260px; border-radius: 10px; display: block; margin-bottom: 8px; }
.allegato-anteprima iframe { width: 100%; height: 260px; border: 1px solid #e6e6ee; border-radius: 10px; }

/* toast */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(80px + env(safe-area-inset-bottom)); z-index: 60;
  background: var(--navy); color: #fff; padding: 10px 18px;
  border-radius: 999px; font-size: 0.85rem; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25); max-width: 90vw;
}
