:root {
  --bg: #fff;
  --fg: #1a1a1a;
  --muted: #666;
  --line: #e2e2e2;
  --ok: #2e7d32;
  --ok-bg: #e8f2e8;
  --ko: #c62828;
  --ko-bg: #fce4e4;
  --head: #1a1a1a;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Arial, system-ui, -apple-system, sans-serif;
  color: var(--fg);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button { font-family: inherit; cursor: pointer; }

/* ---- header ---- */
.topbar {
  background: var(--head);
  color: #fff;
  padding: 16px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.topbar h1 { font-size: 17px; margin: 0; letter-spacing: .5px; }
.sub { margin: 2px 0 0; font-size: 12px; color: #bbb; }
.btn-ghost {
  background: transparent;
  color: #fff;
  border: 1px solid #555;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 13px;
}
.btn-ghost:hover { background: #fff; color: #000; }
.counters { display: flex; gap: 10px; margin-top: 14px; }
.counter { flex: 1; background: #262626; border-radius: 8px; padding: 10px; text-align: center; }
.counter span { display: block; font-size: 22px; font-weight: 700; }
.counter label { font-size: 11px; color: #aaa; text-transform: uppercase; letter-spacing: .5px; }
.counter.ok span { color: #7ccb80; }
.counter.ko span { color: #ef8a8a; }
.progress { height: 6px; background: #333; border-radius: 4px; margin-top: 12px; overflow: hidden; }
.bar { height: 100%; background: var(--ok); width: 0; transition: width .25s ease; }

/* ---- controls ---- */
.controls {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  border-bottom: 1px solid var(--line);
}
#search { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 15px; }
.filters { display: flex; gap: 8px; }
.filters button { flex: 1; padding: 10px; border: 1px solid var(--line); background: #fff; border-radius: 8px; font-size: 13px; }
.filters button.active { background: var(--fg); color: #fff; border-color: var(--fg); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions button { flex: 1; min-width: 90px; padding: 10px; border: 1px solid var(--line); background: #fff; border-radius: 8px; font-size: 13px; }
.actions button:hover { background: #f3f3f3; }

/* ---- list ---- */
.list { list-style: none; margin: 0; padding: 0; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  user-select: none;
}
.row:active { background: #fafafa; }
.num { width: 26px; color: var(--muted); font-size: 13px; text-align: right; flex: none; }
.check {
  width: 24px;
  height: 24px;
  border: 2px solid var(--ko);
  border-radius: 6px;
  flex: none;
  position: relative;
}
.row.paid .check { border-color: var(--ok); background: var(--ok); }
.row.paid .check::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 3px;
  width: 6px;
  height: 11px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}
.name { flex: 1; font-size: 15px; }
.name strong { font-weight: 700; }
.note { display: block; font-style: italic; color: var(--muted); font-size: 12px; margin-top: 2px; }
.tag {
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 5px;
  flex: none;
  color: var(--ko);
  background: var(--ko-bg);
}
.row.paid .tag { color: var(--ok); background: var(--ok-bg); }
.empty { text-align: center; color: var(--muted); padding: 30px; }

.footer { padding: 20px 16px; text-align: center; }
.footer .btn-ghost { color: var(--fg); border-color: var(--line); }
.footer .btn-ghost:hover { background: var(--fg); color: #fff; }

/* ---- login ---- */
.login-body {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  background: var(--head);
  padding: 20px;
}
.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 32px;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-card h1 { margin: 0; font-size: 26px; letter-spacing: 1px; }
.login-card .sub { color: var(--muted); }
.login-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.login-card input { padding: 14px; border: 1px solid var(--line); border-radius: 8px; font-size: 16px; text-align: center; }
.login-card button { padding: 14px; background: var(--fg); color: #fff; border: none; border-radius: 8px; font-size: 16px; font-weight: 700; }
.error { color: var(--ko); font-size: 13px; margin: 0; }

/* ---- print: nasconde controlli, lascia caselle vuote da spuntare a mano ---- */
@media print {
  .topbar .btn-ghost, .controls, .footer, .progress, .counters { display: none !important; }
  .topbar { position: static; background: #fff; color: #000; padding: 0 0 10px; border-bottom: 2px solid #000; }
  .topbar h1 { font-size: 18px; }
  .sub { color: #000; }
  .row { cursor: default; page-break-inside: avoid; }
  .check { border-color: #000 !important; background: #fff !important; }
  .check::after { display: none !important; } /* casella vuota per spunta manuale */
  .tag { border: 1px solid #000; background: #fff !important; color: #000 !important; }
}

/* ---- desktop ---- */
@media (min-width: 680px) {
  .topbar, .controls, .list, .footer { max-width: 760px; margin-left: auto; margin-right: auto; }
  .controls { flex-direction: row; flex-wrap: wrap; align-items: center; }
  #search { flex: 1; min-width: 200px; }
}

/* ---- bottone recap (riga propria, evidenziato) ---- */
.recap-trigger { flex: 1 1 100% !important; font-weight: 700; border-color: var(--ko) !important; color: var(--ko); }
.recap-trigger:hover { background: var(--ko-bg) !important; }

/* ---- modal recap mancanti ---- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
}
.modal[hidden] { display: none; }
.modal-box {
  background: #fff;
  width: 100%;
  max-width: 600px;
  border-radius: 16px 16px 0 0;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.modal-head strong { font-size: 16px; }
.modal-x { background: none; border: none; font-size: 20px; color: var(--muted); padding: 4px 8px; line-height: 1; }
.recap-list { margin: 0; padding-left: 26px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.recap-list li { padding: 9px 4px; border-bottom: 1px solid var(--line); font-size: 15px; }
.recap-list li strong { font-weight: 700; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.modal-actions button { flex: 1; min-width: 110px; padding: 14px; border: 1px solid var(--line); background: #fff; border-radius: 10px; font-size: 14px; font-weight: 600; }
.modal-actions .wa { background: #25d366; color: #fff; border-color: #25d366; }
.modal-actions .wa:hover { background: #1fb955; }
@media (min-width: 680px) {
  .modal { align-items: center; padding: 20px; }
  .modal-box { border-radius: 16px; }
}

/* ---- safe-area iPhone (notch + web app standalone dalla home) ---- */
.topbar { padding-top: calc(16px + env(safe-area-inset-top)); }
.footer { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }

@media print { .modal { display: none !important; } }
