:root {
  --ink: #1d1d1f; --sub: #6e6e73; --faint: #6e6e73; --bg: #f5f5f7; --line: #d2d2d7; --hair: #e8e8ed;
  --blue: #0071e3; --blue-dark: #0060c0; --blue-soft: #e8f1fd; --ok: #1a8f3c; --ok-soft: #e6f6ea; --danger: #c4281c; --danger-soft: #fdecea;
  --sf: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-font-smoothing: antialiased; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 400 16px/1.5 var(--sf); letter-spacing: -.006em; }
button { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; letter-spacing: -.022em; }

.top { position: sticky; top: 0; z-index: 20; background: rgba(245, 245, 247, .88); backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px); border-bottom: 1px solid var(--hair); }
.top-in { max-width: 920px; margin: 0 auto; padding: 12px 16px; display: flex; align-items: center; gap: 14px; }
.top img { height: 24px; display: block; }
.top .doc { margin-left: auto; text-align: right; min-width: 0; }
.top .doc b { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 46vw; }
.top .doc span { font-size: 12px; color: var(--faint); }

main { max-width: 920px; margin: 0 auto; padding: 20px 16px 140px; }
.card { background: #fff; border-radius: 20px; padding: 24px; }
.card + .card { margin-top: 14px; }
.over { font-size: 13px; font-weight: 600; color: var(--blue); margin-bottom: 4px; }
.title { font-size: 28px; line-height: 1.12; font-weight: 700; letter-spacing: -.03em; }
.lead { color: var(--sub); font-size: 16px; line-height: 1.55; margin: 10px 0 0; }
.lead b { color: var(--ink); font-weight: 600; }
.note { background: var(--bg); border-radius: 14px; padding: 12px 14px; margin: 14px 0 0; font-size: 14px; color: var(--sub); white-space: pre-line; }

/* Messaggi di stato (link scaduto, già firmato…) */
.state { text-align: center; padding: 44px 24px; }
.state .big { width: 64px; height: 64px; border-radius: 50%; display: grid; place-items: center; margin: 0 auto 16px; font-size: 30px; }
.state .big.ok { background: var(--ok-soft); color: var(--ok); }
.state .big.warn { background: var(--danger-soft); color: var(--danger); }
.state .big.wait { background: var(--bg); color: var(--faint); }
.state h1 { font-size: 24px; font-weight: 700; margin-bottom: 8px; }
.state p { color: var(--sub); margin: 0 auto; max-width: 440px; }
.state .actions { margin-top: 22px; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* Pulsanti */
.btn { appearance: none; border: 0; border-radius: 14px; padding: 13px 22px; font-weight: 600; font-size: 16px; cursor: pointer; background: var(--blue); color: #fff; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; transition: background .15s, transform .05s; }
.btn:hover { background: var(--blue-dark); }
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.ghost { background: transparent; color: var(--blue); }
.btn.ghost:hover { background: var(--blue-soft); }
.btn.light { background: var(--bg); color: var(--ink); }
.btn.light:hover { background: var(--hair); }
.btn.block { width: 100%; }
.btn:focus-visible, .field:focus-visible, input:focus-visible { outline: 3px solid rgba(0, 113, 227, .45); outline-offset: 2px; }

/* PDF */
.pages { display: grid; gap: 14px; margin-top: 14px; }
.pdf-page { position: relative; background: #fff; border-radius: 6px; box-shadow: 0 1px 3px rgba(0,0,0,.08), 0 8px 30px rgba(0,0,0,.06); overflow: hidden; width: 100%; }
.pdf-page canvas { display: block; width: 100%; height: auto; }
.pdf-loading { color: var(--faint); text-align: center; padding: 60px 0; }
.page-no { position: absolute; right: 10px; bottom: 8px; font-size: 11px; color: var(--faint); background: rgba(255,255,255,.85); padding: 1px 7px; border-radius: 9px; }

.field { position: absolute; border: 2px dashed var(--blue); border-radius: 8px; background: rgba(0, 113, 227, .08); cursor: pointer; display: grid; place-items: center; padding: 0; overflow: hidden; }
.field.todo { animation: pulse 1.8s ease-in-out infinite; }
.field .hint { font-size: clamp(9px, 1.9vw, 13px); font-weight: 600; color: var(--blue); pointer-events: none; text-align: center; line-height: 1.15; padding: 0 4px; }
.field.done { border: 2px solid var(--ok); background: rgba(26, 143, 60, .06); animation: none; }
.field.done img { max-width: 94%; max-height: 80%; object-fit: contain; pointer-events: none; }
.field.date { border-style: solid; border-color: var(--line); background: rgba(0,0,0,.025); cursor: default; animation: none; }
.field.date .hint { color: var(--sub); font-weight: 500; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(0,113,227,.35); } 50% { box-shadow: 0 0 0 7px rgba(0,113,227,0); } }
@media (prefers-reduced-motion: reduce) { .field.todo { animation: none; } }

/* Barra in basso */
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: rgba(255,255,255,.92); backdrop-filter: saturate(180%) blur(14px); -webkit-backdrop-filter: saturate(180%) blur(14px); border-top: 1px solid var(--hair); padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); }
.bar-in { max-width: 920px; margin: 0 auto; display: flex; align-items: center; gap: 14px; }
.bar .count { flex: 1; min-width: 0; }
.bar .count b { display: block; font-size: 15px; font-weight: 600; }
.bar .count span { font-size: 13px; color: var(--sub); }
.meter { height: 5px; background: var(--hair); border-radius: 3px; margin-top: 6px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--blue); width: 0; transition: width .25s; }

/* Fogli (firma, conferma) */
.sheet-wrap { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; background: rgba(0,0,0,.4); animation: fade .15s; }
.sheet { background: #fff; width: 100%; max-width: 560px; border-radius: 24px 24px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; animation: rise .22s cubic-bezier(.2,.8,.2,1); }
@media (min-width: 640px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 24px; } }
@keyframes fade { from { opacity: 0; } } @keyframes rise { from { transform: translateY(24px); opacity: 0; } }
.sheet h2 { font-size: 22px; font-weight: 700; margin-bottom: 4px; }
.sheet .sub { color: var(--sub); margin: 0 0 16px; font-size: 15px; }
.pad { position: relative; border: 1.5px solid var(--line); border-radius: 16px; background: #fff; touch-action: none; }
.pad canvas { display: block; width: 100%; height: 200px; border-radius: 16px; cursor: crosshair; touch-action: none; }
.pad .guide { position: absolute; left: 18px; right: 18px; bottom: 46px; border-bottom: 1px dashed var(--line); pointer-events: none; }
.pad .ph { position: absolute; inset: 0; display: grid; place-items: center; color: var(--faint); pointer-events: none; font-size: 15px; }
.row { display: flex; gap: 10px; margin-top: 14px; }
.row > * { flex: 1; }
.tabs { display: flex; background: var(--bg); border-radius: 12px; padding: 3px; margin-bottom: 14px; }
.tabs button { flex: 1; border: 0; background: transparent; padding: 9px 10px; border-radius: 10px; font-weight: 600; color: var(--sub); cursor: pointer; font-size: 15px; }
.tabs button[aria-selected="true"] { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.typed { width: 100%; border: 1.5px solid var(--line); border-radius: 16px; padding: 14px 16px; font-size: 38px; font-family: "Snell Roundhand", "Segoe Script", "Brush Script MT", "Apple Chancery", cursive; height: 200px; }

label.field-l { display: block; font-size: 14px; font-weight: 600; color: var(--sub); margin: 14px 0 6px; }
input[type=text], input[type=email] { width: 100%; border: 1.5px solid var(--line); border-radius: 14px; padding: 13px 14px; font-size: 17px; background: #fff; color: var(--ink); }
input[type=text]:focus { border-color: var(--blue); outline: none; box-shadow: 0 0 0 4px rgba(0,113,227,.15); }
.otp { letter-spacing: .5em; font-size: 28px; font-weight: 600; text-align: center; font-variant-numeric: tabular-nums; }
.check { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1.5px solid var(--hair); border-radius: 14px; margin-top: 10px; cursor: pointer; font-size: 15px; line-height: 1.4; }
.check input { width: 22px; height: 22px; margin: 1px 0 0; flex: none; accent-color: var(--blue); }
.check.on { border-color: var(--blue); background: var(--blue-soft); }
.check.special { border-color: #f2c27a; background: #fff8ec; }
.check.special.on { border-color: var(--blue); background: var(--blue-soft); }
.err { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-top: 12px; }
.okmsg { background: var(--ok-soft); color: var(--ok); border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-top: 12px; }
.small { font-size: 13px; color: var(--faint); margin-top: 14px; line-height: 1.5; }
.spinner { width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }
.btn.light .spinner, .btn.ghost .spinner { border-color: rgba(0,0,0,.15); border-top-color: var(--blue); }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }
footer.page-foot { text-align: center; color: var(--faint); font-size: 12px; padding: 18px 16px 28px; }
footer.page-foot a { color: var(--faint); }

/* Solo per lettori di schermo */
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.errtext { color: var(--danger); font-weight: 600; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .001s !important; transition-duration: .001s !important; } .spinner { animation: none; border-top-color: #fff; } }
