:root {
  --primary: #1a56db;
  --primary-dark: #1446b8;
  --ok: #16a34a;
  --warn: #f59e0b;
  --danger: #dc2626;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  overscroll-behavior: none;
}
button { font: inherit; cursor: pointer; border: 0; }
.hidden { display: none !important; }

/* ── Schermate ─────────────────────────────────────────────────────────── */
.screen { display: none; min-height: 100%; }
.screen.active { display: flex; flex-direction: column; }
.screen.center.active { align-items: center; justify-content: center; text-align: center; padding: 32px; gap: 8px; }
.screen.dark { background: #0b0f17; color: #fff; }

/* ── Home ──────────────────────────────────────────────────────────────── */
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(18px + var(--safe-top)) 20px 14px;
  background: var(--primary); color: #fff;
}
.brand { font-size: 20px; font-weight: 800; }
.sub { font-size: 14px; opacity: .85; margin-top: 2px; }
.badge {
  background: #fff3; padding: 4px 10px; border-radius: 99px;
  font-size: 12px; font-weight: 700; letter-spacing: .5px; text-transform: uppercase;
}
.banner {
  margin: 14px 16px 0; padding: 12px 14px; border-radius: 12px;
  background: #fff7ed; border: 1px solid #fdba74; color: #9a3412; font-size: 14px;
}
.actions { display: grid; gap: 12px; padding: 16px; }
.big {
  display: flex; align-items: center; gap: 14px; text-align: left;
  padding: 18px; border-radius: var(--radius); background: var(--surface);
  border: 1px solid var(--line); color: var(--text);
}
.big b { display: block; font-size: 18px; }
.big small { display: block; color: var(--muted); font-size: 13px; margin-top: 2px; }
.big .ico { font-size: 30px; width: 44px; text-align: center; }
.big.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.big.primary small { color: #dbe6ff; }

.pages { flex: 1; padding: 4px 16px 120px; }
.pages-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pages-head h2 { font-size: 17px; margin: 8px 0; }
.count {
  display: inline-block; min-width: 24px; padding: 1px 8px; border-radius: 99px;
  background: var(--primary); color: #fff; font-size: 13px; text-align: center;
}
.switch { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.switch input { width: 18px; height: 18px; accent-color: var(--primary); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 12px; }
.empty {
  grid-column: 1 / -1; padding: 28px 12px; text-align: center; color: var(--muted);
  border: 2px dashed var(--line); border-radius: var(--radius); font-size: 14px;
}
.thumb {
  position: relative; background: var(--surface); border-radius: 12px; overflow: hidden;
  border: 1px solid var(--line); aspect-ratio: 3 / 4; display: flex; align-items: center; justify-content: center;
}
.thumb img { width: 100%; height: 100%; object-fit: contain; background: #fff; }
.thumb .num {
  position: absolute; left: 6px; top: 6px; background: #000a; color: #fff;
  font-size: 12px; font-weight: 700; border-radius: 99px; padding: 2px 8px;
}
.thumb .warn {
  position: absolute; left: 6px; bottom: 6px; right: 6px; background: #f59e0bee; color: #111;
  font-size: 11px; font-weight: 700; border-radius: 8px; padding: 3px 6px; text-align: center;
}
.thumb .move { position: absolute; right: 4px; top: 4px; display: flex; gap: 4px; }
.thumb .move button {
  width: 28px; height: 28px; border-radius: 99px; background: #fffe; color: #111;
  font-size: 14px; box-shadow: 0 1px 3px #0003;
}

.bottom {
  position: fixed; left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(12px + var(--safe-bottom));
  background: linear-gradient(transparent, var(--bg) 30%);
}
.send {
  width: 100%; padding: 17px; border-radius: 14px; background: var(--ok); color: #fff;
  font-size: 17px; font-weight: 700; box-shadow: 0 6px 18px #16a34a55;
}
.send:disabled { background: #cbd5e1; box-shadow: none; color: #fff; }

/* ── Bordi e pagina ────────────────────────────────────────────────────── */
.bar-top, .bar-bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 14px; }
.bar-top { padding-top: calc(12px + var(--safe-top)); }
.bar-bottom { padding-bottom: calc(14px + var(--safe-bottom)); }
.link { background: none; color: #93c5fd; font-size: 16px; padding: 6px 4px; }
.link.danger { color: #fca5a5; }
.primary { background: var(--primary); color: #fff; padding: 13px 20px; border-radius: 12px; font-weight: 700; font-size: 16px; }
.ghost { background: #ffffff1f; color: #fff; padding: 13px 16px; border-radius: 12px; font-weight: 600; }
.ghost.light { background: var(--surface); color: var(--primary); border: 1px solid var(--line); margin-top: 12px; }
.editor-host { flex: 1; position: relative; min-height: 0; margin: 0 8px; }
.page-preview { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 0; padding: 8px 14px; }
.page-preview canvas { max-width: 100%; max-height: 62vh; background: #fff; border-radius: 6px; box-shadow: 0 8px 30px #0008; }
.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px 14px 0; }
.filters { display: flex; gap: 8px; justify-content: center; padding: 4px 12px; flex-wrap: wrap; }
.chip { padding: 9px 14px; border-radius: 99px; background: #ffffff1f; color: #fff; font-weight: 600; }
.chip.on { background: #fff; color: #0b0f17; }

/* ── Invio, avvisi ─────────────────────────────────────────────────────── */
.spinner {
  width: 42px; height: 42px; border-radius: 99px; border: 4px solid #cbd5e1;
  border-top-color: var(--primary); animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
progress { width: min(320px, 80vw); height: 10px; accent-color: var(--primary); }
.done-ico {
  width: 74px; height: 74px; border-radius: 99px; background: var(--ok); color: #fff;
  font-size: 40px; display: flex; align-items: center; justify-content: center; font-weight: 800;
}
.done-ico.err { background: var(--danger); }
.busy {
  position: fixed; inset: 0; background: #0009; color: #fff; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; z-index: 50; font-weight: 600;
}
.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%) translateY(20px);
  background: #111827; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px;
  opacity: 0; transition: all .25s; z-index: 60; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Editor degli angoli di Scanic: colori del gestionale */
.editor-host { --scanic-accent: #4ade80; --scanic-mask: rgba(0, 0, 0, 0.55); }
