/* =============================================================================
   MyKinetico — Pagina pubblica di firma (mobile-first, Cobalt v2, SOLO light)
   Token cromatici inline (la pagina è standalone, non eredita lo stile dell'app).
   ============================================================================= */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f6f8fb;
  --text: #1C1F3A;
  --text-2: #5A6172;
  --text-3: #8A9099;
  --border: rgba(60,60,67,.14);
  --border-strong: rgba(60,60,67,.24);
  --accent: #0A84FF;
  --accent-dark: #0066d6;
  --accent-2: #5E5CE6;
  --accent-soft: rgba(10,132,255,.10);
  --accent-grad: linear-gradient(135deg, #0A84FF 0%, #5E5CE6 100%);
  --positive: #34C759;
  --positive-soft: rgba(52,199,89,.12);
  --rose: #FF3B30;
  --rose-soft: rgba(255,59,48,.08);
  --rose-text: #D70015;
  --shadow-card: 0 1px 2px rgba(16,20,40,.04), 0 8px 22px -12px rgba(16,20,40,.18);
  --r-md: 12px;
  --r-lg: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.firma-app { max-width: 560px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* Header */
.firma-head {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255,255,255,.82); backdrop-filter: blur(10px) saturate(140%); -webkit-backdrop-filter: blur(10px) saturate(140%);
  border-bottom: 1px solid var(--border);
  padding: 12px 18px;
}
.firma-brand { display: flex; align-items: center; gap: 10px; }
.firma-mark { flex-shrink: 0; border-radius: 9px; }
.firma-studio { font-weight: 800; font-size: 16px; letter-spacing: -0.2px; }
.firma-steps { display: flex; gap: 8px; margin-top: 10px; }
.firma-step {
  flex: 1; text-align: center; font-size: 11px; font-weight: 600;
  color: var(--text-3); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 999px; padding: 5px 8px;
}
.firma-step.is-active { color: #fff; border-color: transparent; background: var(--accent-grad); }
.firma-step.is-done { color: var(--accent-dark); background: var(--accent-soft); border-color: transparent; }

/* Main */
.firma-main { flex: 1; padding: 18px 16px 120px; }
.firma-loading { color: var(--text-3); text-align: center; padding: 60px 0; }

.firma-intro { margin: 2px 0 18px; }
.firma-intro h1 { font-size: 22px; line-height: 1.2; margin: 0 0 6px; letter-spacing: -0.4px; }
.firma-intro p { margin: 0; color: var(--text-2); font-size: 14px; }

/* Card documento */
.firma-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-card);
  padding: 16px; margin-bottom: 16px;
}
.firma-card-tag {
  display: inline-block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  color: var(--accent-dark); background: var(--accent-soft); border-radius: 999px; padding: 3px 10px; margin-bottom: 8px;
}
.firma-card h2 { font-size: 17px; margin: 0 0 10px; letter-spacing: -0.2px; }

/* Testo documento (scrollabile) */
.firma-doc-text {
  max-height: 280px; overflow-y: auto;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 12px 14px; font-size: 13px; line-height: 1.55; color: var(--text-2);
  white-space: pre-wrap; word-wrap: break-word;
  -webkit-overflow-scrolling: touch;
}
.firma-doc-text::-webkit-scrollbar { width: 8px; }
.firma-doc-text::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; }

.firma-section-label { font-size: 13px; font-weight: 700; margin: 16px 0 6px; }
.firma-hint { font-size: 13px; color: var(--text-3); margin: 0 0 10px; }

/* Canvas firma */
.firma-canvas-wrap {
  position: relative; background: var(--surface-2);
  border: 1px dashed var(--border-strong); border-radius: var(--r-md);
  height: 180px; overflow: hidden; touch-action: none;
}
#firma-canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.firma-line { position: absolute; left: 18px; right: 18px; bottom: 42px; border-bottom: 1px solid var(--border-strong); }
.firma-placeholder {
  position: absolute; left: 0; right: 0; bottom: 14px; text-align: center;
  color: var(--text-3); font-size: 13px; pointer-events: none; transition: opacity .15s;
}
.firma-canvas-actions { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; }
.firma-signed-ok { display: inline-flex; align-items: center; gap: 6px; color: var(--accent-dark); font-weight: 600; font-size: 13px; }

/* Consensi */
.consenso-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 0; border-top: 1px solid var(--border);
}
.consenso-row:first-of-type { border-top: none; }
.consenso-main { min-width: 0; }
.consenso-title { font-weight: 600; font-size: 14px; }
.consenso-sub { font-size: 12px; color: var(--text-3); }
.consenso-req { color: var(--accent-dark); font-weight: 600; }

/* Switch sì/no */
.sw { position: relative; flex-shrink: 0; width: 52px; height: 30px; border-radius: 999px; background: var(--border-strong); cursor: pointer; transition: background .2s; }
.sw .sw-knob { position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.sw.is-on { background: var(--accent-grad); }
.sw.is-on .sw-knob { transform: translateX(22px); }
.sw-labels { display: flex; align-items: center; gap: 8px; }
.sw-no, .sw-yes { font-size: 12px; font-weight: 600; color: var(--text-3); }
.sw.is-on ~ .sw-yes, .consenso-switch.on .sw-yes { color: var(--accent-dark); }

/* Checkbox necessario (salute) */
.consenso-check { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; }
.consenso-check input { width: 20px; height: 20px; margin-top: 1px; accent-color: var(--accent); flex-shrink: 0; }

/* Input nome */
.firma-field { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.firma-field label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.firma-field input {
  font: inherit; font-size: 15px; padding: 11px 12px;
  border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--text);
}
.firma-field input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* Bottoni */
.btn { font: inherit; font-weight: 600; border: none; border-radius: var(--r-md); cursor: pointer; padding: 13px 18px; font-size: 15px; transition: filter .15s, background .15s, opacity .15s; }
.btn-primary { color: #fff; background: var(--accent-grad); box-shadow: 0 6px 16px -6px rgba(10,132,255,.6); }
.btn-primary:disabled { opacity: .45; box-shadow: none; cursor: default; }
.btn-primary:active:not(:disabled) { filter: brightness(.96); }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:active { background: var(--surface-2); }
.btn-sm { padding: 8px 13px; font-size: 13px; }
.btn-block { width: 100%; }

/* Barra sticky in basso */
.firma-bar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: rgba(255,255,255,.9); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
}
.firma-bar-inner { max-width: 560px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.firma-bar .btn-primary { flex: 1; }

/* Stato finale / errori */
.firma-final { text-align: center; padding: 48px 24px; }
.firma-final .ico { width: 72px; height: 72px; border-radius: 50%; margin: 0 auto 18px; display: flex; align-items: center; justify-content: center; }
.firma-final.ok .ico { background: var(--positive-soft); }
.firma-final.err .ico { background: var(--rose-soft); }
.firma-final h1 { font-size: 22px; margin: 0 0 8px; }
.firma-final p { color: var(--text-2); margin: 0; }

.firma-error-banner { background: var(--rose-soft); color: var(--rose-text); border-radius: var(--r-md); padding: 10px 12px; font-size: 13px; margin-bottom: 12px; }
.firma-demo-badge { position: fixed; top: 8px; right: 8px; z-index: 50; background: #111; color: #fff; font-size: 10px; font-weight: 700; padding: 3px 8px; border-radius: 999px; opacity: .7; }
