/* ============================================================
   Genius P Sign — design tokens (A.8)
   Moderno, curato, intuitivo, fresco. La firma e' l'unico protagonista.
   ============================================================ */
:root {
  --ink: #14202B;
  --ink-soft: #4a5a68;
  --ink-faint: #7a8794;
  --surface: #ffffff;
  --surface-muted: #f5f7fa;
  --line: #e3e8ef;
  --accent: #2f6df6;
  --accent-dark: #2557c9;
  --accent-tint: #eaf1fe;
  --success: #12a150;
  --success-tint: #e6f6ee;
  --danger: #d64545;
  --danger-tint: #fbeaea;
  --radius: 16px;
  --radius-sm: 12px;
  --shadow-sm: 0 1px 2px rgba(20, 32, 43, .04), 0 2px 8px rgba(20, 32, 43, .06);
  --shadow-md: 0 8px 30px rgba(20, 32, 43, .10);
  --font: "Inter", "Segoe UI", Roboto, Helvetica, Arial, system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--surface-muted);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body { line-height: 1.5; }

h1, h2, h3 { font-weight: 700; letter-spacing: -0.01em; margin: 0 0 .4em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
p { margin: 0 0 1rem; }
a { color: var(--accent); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  font: inherit; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--radius-sm);
  padding: .8rem 1.3rem; min-height: 46px;
  transition: background .15s ease, transform .05s ease, box-shadow .15s ease;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-primary:disabled { background: #b9c6da; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { background: var(--surface-muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: .45rem .8rem; min-height: 36px; font-size: .875rem; }

:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

/* ---------- Area firma pubblica ---------- */
.sign-shell { min-height: 100vh; display: flex; flex-direction: column; }
.sign-topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .85rem 1.1rem;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; }
.brand-dot { width: 26px; height: 26px; border-radius: 8px; background: var(--accent);
  display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: .85rem; }
.topbar-hint { font-size: .9rem; color: var(--ink-soft); }
.topbar-ref { font-size: .8rem; color: var(--ink-faint); }

.viewer-wrap { flex: 1; overflow: auto; padding: 1.2rem clamp(.5rem, 3vw, 2rem) 6rem; }
.viewer-inner { max-width: 900px; margin: 0 auto; }
.pdf-page-container { position: relative; margin: 0 auto 1rem; box-shadow: var(--shadow-sm);
  border-radius: 6px; overflow: hidden; background: #fff; width: fit-content; }
.pdf-page-container canvas { display: block; max-width: 100%; height: auto; }

/* Box "Firma qui" overlay */
.sig-box {
  position: absolute; z-index: 5; cursor: pointer;
  border: 2px dashed var(--accent); background: rgba(47, 109, 246, .07);
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  color: var(--accent-dark); font-weight: 600; font-size: .85rem; text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.sig-box .sig-box-label { padding: 2px 6px; pointer-events: none; }
.sig-box.pulse { animation: sigpulse 1.4s ease-in-out 3; }
.sig-box.filled { border-style: solid; background: rgba(18, 161, 80, .10); border-color: var(--success); color: var(--success); }
@keyframes sigpulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(47, 109, 246, .0); }
  50% { box-shadow: 0 0 0 6px rgba(47, 109, 246, .18); }
}
@media (prefers-reduced-motion: reduce) { .sig-box.pulse { animation: none; } }

.floating-cta {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
  padding: .8rem clamp(.5rem, 3vw, 2rem) calc(.8rem + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--surface) 70%, rgba(255,255,255,0));
}
.floating-cta .inner { max-width: 900px; margin: 0 auto; }

/* ---------- Modale firma ---------- */
.gp-modal-backdrop {
  position: fixed; inset: 0; z-index: 50; background: rgba(20, 32, 43, .45);
  display: none; align-items: flex-end; justify-content: center; padding: 0;
}
.gp-modal-backdrop.open { display: flex; }
@media (min-width: 640px) { .gp-modal-backdrop { align-items: center; padding: 1rem; } }
.gp-modal {
  background: var(--surface); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; box-shadow: var(--shadow-md);
  max-height: 94vh; overflow: auto; animation: sheetup .22s ease;
}
@media (min-width: 640px) { .gp-modal { border-radius: 20px; } }
@keyframes sheetup { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .gp-modal { animation: none; } }
.gp-modal-head { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.25rem .3rem; }
.gp-modal-body { padding: .5rem 1.25rem 1.4rem; }
.gp-modal-close { background: none; border: none; font-size: 1.4rem; color: var(--ink-faint); cursor: pointer; line-height: 1; }

.field { margin-bottom: 1.1rem; }
.field label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .35rem; }
.field input[type=text] {
  width: 100%; font: inherit; padding: .75rem .9rem; border: 1px solid var(--line);
  border-radius: var(--radius-sm); background: var(--surface);
}
.field input[type=text]:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-tint); }
.field .hint { font-size: .8rem; color: var(--ink-faint); margin-top: .3rem; }

.method-toggle { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; margin-bottom: 1rem; }
.method-toggle button {
  font: inherit; font-weight: 600; padding: .7rem; border-radius: var(--radius-sm);
  border: 1px solid var(--line); background: var(--surface); color: var(--ink-soft); cursor: pointer;
}
.method-toggle button.active { border-color: var(--accent); background: var(--accent-tint); color: var(--accent-dark); }

.pad-wrap { border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff; position: relative; overflow: hidden; }
.pad-wrap canvas { display: block; width: 100%; height: 200px; touch-action: none; }
.pad-baseline { position: absolute; left: 5%; right: 5%; bottom: 34px; border-bottom: 1px dashed var(--line); pointer-events: none; }
.pad-tools { display: flex; justify-content: space-between; align-items: center; margin-top: .5rem; }
.pad-tools .rotate-hint { font-size: .78rem; color: var(--ink-faint); }

.upload-drop {
  border: 1.5px dashed var(--line); border-radius: var(--radius-sm); padding: 1.4rem;
  text-align: center; color: var(--ink-soft); background: var(--surface-muted);
}
.upload-preview { margin-top: .8rem; text-align: center; }
.upload-preview img { max-width: 100%; max-height: 180px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }

.alert { padding: .7rem .9rem; border-radius: var(--radius-sm); font-size: .9rem; margin-bottom: 1rem; }
.alert-error { background: var(--danger-tint); color: #9a2b2b; }
.hidden { display: none !important; }

.spinner { width: 18px; height: 18px; border: 2px solid rgba(255,255,255,.5); border-top-color: #fff;
  border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Pagine di stato ---------- */
.state-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; }
.state-card { background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: var(--shadow-sm); max-width: 460px; width: 100%; padding: 2.4rem 2rem; text-align: center; }
.state-icon { width: 68px; height: 68px; border-radius: 50%; margin: 0 auto 1.2rem;
  display: flex; align-items: center; justify-content: center; }
.state-icon.success { background: var(--success-tint); color: var(--success); }
.state-icon.neutral { background: var(--surface-muted); color: var(--ink-faint); }
.state-icon svg { width: 34px; height: 34px; }
.check-anim path { stroke-dasharray: 48; stroke-dashoffset: 48; animation: draw .6s ease .1s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
@media (prefers-reduced-motion: reduce) { .check-anim path { animation: none; stroke-dashoffset: 0; } }
.state-meta { background: var(--surface-muted); border-radius: var(--radius-sm); padding: .9rem 1rem; margin-top: 1.3rem; text-align: left; font-size: .9rem; }
.state-meta div { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem 0; }
.state-meta .k { color: var(--ink-faint); }
.state-meta .v { font-weight: 600; }

/* ---------- Area admin ---------- */
.admin-shell { max-width: 1180px; margin: 0 auto; padding: 1.2rem clamp(.75rem, 3vw, 2rem) 3rem; }
.admin-topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .4rem 0 1.2rem; border-bottom: 1px solid var(--line); margin-bottom: 1.4rem; }
.admin-user { font-size: .85rem; color: var(--ink-soft); display: flex; align-items: center; gap: .8rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin-bottom: 1rem; }
.toolbar input[type=search], .toolbar select {
  font: inherit; padding: .55rem .75rem; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #fff;
}
.toolbar input[type=search] { min-width: 220px; }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.data th, table.data td { text-align: left; padding: .7rem .8rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); }
table.data tr:hover td { background: var(--surface-muted); }
.actions-cell { display: flex; gap: .35rem; flex-wrap: wrap; }
.actions-cell form { display: inline; }

.badge { display: inline-block; font-size: .74rem; font-weight: 700; padding: .2rem .55rem; border-radius: 999px; }
.badge.pending { background: #fff5e6; color: #a86a13; }
.badge.signed { background: var(--success-tint); color: var(--success); }
.badge.revoked { background: var(--danger-tint); color: #9a2b2b; }
.badge.expired { background: var(--surface-muted); color: var(--ink-faint); }

.pagination { display: flex; gap: .4rem; justify-content: center; margin-top: 1.2rem; }
.pagination a, .pagination span { padding: .4rem .7rem; border-radius: 8px; border: 1px solid var(--line); text-decoration: none; color: var(--ink-soft); font-size: .85rem; }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }

.flash { padding: .75rem 1rem; border-radius: var(--radius-sm); margin-bottom: 1.2rem; font-size: .9rem; }
.flash.ok { background: var(--success-tint); color: var(--success); }
.flash.error { background: var(--danger-tint); color: #9a2b2b; }

.empty { text-align: center; color: var(--ink-faint); padding: 3rem 1rem; }

.audit-list { list-style: none; margin: 0; padding: 0; }
.audit-list li { padding: .7rem .2rem; border-bottom: 1px solid var(--line); display: flex; gap: 1rem; font-size: .88rem; }
.audit-list .ts { color: var(--ink-faint); white-space: nowrap; }
.audit-list .act { font-weight: 600; min-width: 90px; }
.audit-list .meta { color: var(--ink-soft); word-break: break-word; }
code.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82em; }
