:root {
  --bg: #f2f4f7; --card: #fff; --text: #1d2433; --muted: #5d677a;
  --accent: #1f4f8f; --border: #cfd6e2; --ok: #1e8e4e; --warn: #d08a00; --ko: #c0392b;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 16px; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--accent); color: #fff; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; }
.topbar h1 { margin: 0; font-size: 1.15rem; }
.bozza { font-size: .8rem; opacity: .85; }
main { max-width: 720px; margin: 0 auto; padding: 12px 12px 40px; }
.card { background: var(--card); border-radius: 12px; padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.card h2 { margin: 0 0 12px; font-size: 1.05rem; color: var(--accent); }
label { display: block; font-size: .9rem; color: var(--muted); margin-bottom: 10px; }
input[type=text], input:not([type]), input[type=date], textarea {
  display: block; width: 100%; margin-top: 4px; padding: 12px; font-size: 1rem; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px; background: #fff; font-family: inherit;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.invalid { border-color: var(--ko) !important; }
.due { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 480px) { .due { grid-template-columns: 1fr; } }

.btn { display: block; width: 100%; padding: 14px; font-size: 1rem; font-weight: 600; border: 0; border-radius: 10px; cursor: pointer; text-align: center; text-decoration: none; margin-top: 10px; font-family: inherit; }
.btn.primario { background: var(--accent); color: #fff; }
.btn.secondario { background: #e6ecf5; color: var(--accent); }
.btn.link { background: none; color: var(--muted); font-weight: 400; text-decoration: underline; }
.btn:disabled { opacity: .6; cursor: wait; }
.row-btn .btn { margin: 0 0 12px; }
#qr-reader { width: 100%; margin-bottom: 8px; }

.esito { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
@media (max-width: 480px) { .esito { grid-template-columns: 1fr; } }
.big { margin: 0; }
.big input { position: absolute; opacity: 0; pointer-events: none; }
.big span { display: flex; align-items: center; justify-content: center; min-height: 64px; border: 2px solid var(--border); border-radius: 12px; font-size: 1.05rem; font-weight: 700; color: var(--text); background: #fff; text-align: center; padding: 8px; }
.big.ok input:checked + span { background: var(--ok); border-color: var(--ok); color: #fff; }
.big.warn input:checked + span { background: var(--warn); border-color: var(--warn); color: #fff; }
.big.ko input:checked + span { background: var(--ko); border-color: var(--ko); color: #fff; }
.big input:focus-visible + span { outline: 3px solid var(--accent); }

.checklist label { display: flex; align-items: center; gap: 12px; color: var(--text); font-size: 1rem; padding: 10px 4px; border-bottom: 1px solid #edf0f5; margin: 0; }
.checklist input { width: 24px; height: 24px; flex: none; }

.anteprime { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; margin-top: 10px; }
.anteprime figure { position: relative; margin: 0; }
.anteprime img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; display: block; }
.anteprime button { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; font-size: 1rem; cursor: pointer; }

.firma-wrap { border: 2px dashed var(--border); border-radius: 10px; background: #fff; height: 200px; touch-action: none; }
#firma { width: 100%; height: 100%; display: block; }

.msg.errore { background: #fdecea; color: var(--ko); padding: 10px 12px; border-radius: 8px; font-weight: 600; }

/* Documento PDF fuori schermo */
#report-host { position: fixed; left: -10000px; top: 0; width: 794px; }
#report { width: 794px; padding: 32px; background: #fff; color: #111; font-family: Helvetica, Arial, sans-serif; font-size: 13px; }
#report .rp-head { border-bottom: 4px solid #1f4f8f; padding-bottom: 12px; margin-bottom: 18px; display: flex; justify-content: space-between; align-items: flex-end; }
#report .rp-head h1 { margin: 0; font-size: 24px; color: #1f4f8f; }
#report .rp-head small { color: #555; }
#report h2 { font-size: 15px; color: #1f4f8f; margin: 18px 0 6px; border-bottom: 1px solid #ccd; padding-bottom: 3px; }
#report table { width: 100%; border-collapse: collapse; }
#report td { border: 1px solid #ccd; padding: 6px 8px; vertical-align: top; }
#report td.k { width: 28%; background: #eef2f8; font-weight: 700; }
#report .chk td:first-child { width: 28px; text-align: center; font-weight: 700; }
#report .esito-badge { display: inline-block; padding: 4px 12px; border-radius: 6px; color: #fff; font-weight: 700; }
#report .foto { display: flex; flex-wrap: wrap; gap: 8px; }
#report .foto img { width: 240px; height: 180px; object-fit: cover; border: 1px solid #ccd; }
#report .firma img { max-width: 320px; max-height: 120px; border-bottom: 1px solid #333; display: block; }
#report .nobreak { page-break-inside: avoid; }
