/* =============================================================
   Totem Visitor - interfaccia totem
   ============================================================= */

:root {
  --red: #E30613;
  --red-dark: #b7050f;
  --navy: #1B3A6B;
  --navy-soft: #22314a;
  --green: #1f9d63;
  --green-dark: #17784b;
  --grey: #929291;
  --ink: #22314a;
  --muted: #7a879e;
  --line: #dfe5ee;
  --bg-top: #b9c6d6;
  --bg-bottom: #ffffff;
  --radius: 18px;
  --shadow: 0 10px 40px rgba(27, 58, 107, .13);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(170deg, var(--bg-top) 0%, #e8eef5 42%, var(--bg-bottom) 100%);
  -webkit-user-select: none;
  user-select: none;
  touch-action: manipulation;
}

button, input, textarea { font-family: inherit; }

/* ---------- struttura ---------- */

#app { position: relative; height: 100vh; width: 100vw; }

.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: 26px 34px 22px;
  animation: fade .22s ease;
}
.screen.active { display: flex; }

@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  min-height: 58px;
  flex: 0 0 auto;
}

.logo-box { display: flex; align-items: center; gap: 14px; }
.logo-box img { max-height: 54px; max-width: 260px; object-fit: contain; }
.logo-box .fallback {
  font-size: 22px; font-weight: 700; color: var(--red); letter-spacing: .02em;
}

.topbar-right { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  width: 46px; height: 46px; border-radius: 50%;
  border: 0; background: rgba(255,255,255,.55); color: var(--navy);
  display: grid; place-items: center; cursor: pointer;
  transition: background .15s;
}
.icon-btn:hover { background: rgba(255,255,255,.9); }
.icon-btn svg { width: 24px; height: 24px; }

/* selettore lingua */
.lang-switch { display: flex; gap: 7px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.lang-chip {
  border: 1.5px solid transparent;
  background: rgba(255,255,255,.6);
  border-radius: 999px;
  padding: 7px 15px;
  font-size: 14px; font-weight: 600; color: var(--navy-soft);
  cursor: pointer; transition: all .15s; line-height: 1;
}
.lang-chip:hover { background: #fff; }
.lang-chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.screen-body {
  flex: 1 1 auto;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  min-height: 0;
}

.screen-footer {
  flex: 0 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding-top: 14px; min-height: 62px;
}

.footer-label {
  font-size: clamp(13px, 1.1vw, 17px); font-weight: 700; letter-spacing: .16em;
  color: var(--muted); text-transform: uppercase;
}

/* ---------- home ---------- */

/* Le dimensioni tengono conto sia della larghezza sia dell'altezza utile:
   su schermi molto ampi ma bassi è l'altezza a limitare, e viceversa. */
.home-actions {
  display: flex; align-items: center; justify-content: center;
  gap: clamp(48px, 10vw, 280px); width: 100%;
}

.big-circle {
  width: clamp(200px, min(30vw, 44vh), 520px);
  height: clamp(200px, min(30vw, 44vh), 520px);
  border-radius: 50%;
  border: 0; cursor: pointer; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(12px, 1.6vh, 26px);
  box-shadow: 0 18px 46px rgba(0,0,0,.2);
  transition: transform .15s, box-shadow .15s;
  position: relative;
}
.big-circle::after {
  content: ''; position: absolute; inset: clamp(14px, 1.6vh, 26px); border-radius: 50%;
  border: 3px solid rgba(255,255,255,.75); pointer-events: none;
}
.big-circle:active { transform: scale(.96); box-shadow: 0 6px 18px rgba(0,0,0,.2); }
.big-circle svg {
  width: clamp(56px, min(7vw, 11vh), 150px);
  height: clamp(56px, min(7vw, 11vh), 150px);
}
.big-circle span {
  font-size: clamp(18px, min(2.4vw, 3.4vh), 42px);
  font-weight: 700; letter-spacing: .1em;
}
.circle-in { background: linear-gradient(150deg, #2eb578, var(--green) 55%, var(--green-dark)); }
.circle-out { background: linear-gradient(150deg, #f0303c, var(--red) 55%, var(--red-dark)); }

.welcome-msg {
  font-size: clamp(22px, min(3vw, 4.6vh), 54px); font-weight: 300; color: var(--navy);
  margin-bottom: clamp(24px, 5vh, 70px); text-align: center;
}

/* ---------- card generiche ---------- */

.card {
  background: rgba(255,255,255,.92);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: clamp(28px, 3.4vh, 46px) clamp(30px, 3.6vw, 60px);
  width: min(1180px, 94%);
  max-height: 100%;
  display: flex; flex-direction: column;
  min-height: 0;
}

/* la card del form respira di più: è la schermata dove si scrive */
.card.card-form { width: min(1280px, 96%); }

.card-title {
  font-size: clamp(24px, min(2.7vw, 4vh), 46px); font-weight: 600; color: var(--navy);
  margin: 0 0 8px; text-align: center;
}
.card-sub {
  font-size: clamp(15px, min(1.5vw, 2.1vh), 26px); color: var(--muted);
  text-align: center; margin: 0 0 clamp(18px, 2.4vh, 30px);
}

/* ---------- scelta metodo ---------- */

.method-grid {
  display: flex; gap: clamp(30px, 7vw, 200px);
  align-items: flex-start; justify-content: center; flex-wrap: wrap;
}
.method-item {
  background: none; border: 0; cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  gap: clamp(14px, 2vh, 26px);
  padding: clamp(12px, 1.6vh, 22px); border-radius: 20px; transition: background .15s;
  max-width: clamp(240px, 26vw, 440px);
}
.method-item:hover { background: rgba(255,255,255,.5); }
.method-item:active { transform: scale(.97); }
.method-circle {
  width: clamp(130px, min(18vw, 26vh), 320px);
  height: clamp(130px, min(18vw, 26vh), 320px);
  border-radius: 50%; display: grid; place-items: center;
  box-shadow: 0 14px 34px rgba(0,0,0,.16);
}
.method-circle svg { width: 46%; height: 46%; color: #fff; }
.mc-form { background: linear-gradient(150deg, #6fb3cf, #4f93b8); }
.mc-qr { background: linear-gradient(150deg, #4f7fc4, #3a63a8); }
.method-item .label {
  font-size: clamp(15px, min(1.7vw, 2.4vh), 30px); font-weight: 700; color: var(--navy);
  letter-spacing: .07em; text-align: center;
}
.method-item .hint {
  font-size: clamp(13px, min(1.3vw, 1.8vh), 22px);
  color: var(--muted); text-align: center; line-height: 1.4;
}

/* ---------- form ---------- */

.form-scroll { overflow-y: auto; padding-right: 6px; min-height: 0; }

.field { margin-bottom: clamp(16px, 2.4vh, 30px); }
.field label {
  display: block; font-size: clamp(14px, 1.2vw, 19px); font-weight: 700;
  color: var(--navy); margin-bottom: clamp(6px, 1vh, 11px); letter-spacing: .02em;
}
.field label .req { color: var(--red); margin-left: 3px; }
.field input {
  width: 100%; border: 2px solid var(--line); background: #f6f9fc;
  border-radius: 12px;
  padding: clamp(14px, 1.9vh, 22px) clamp(15px, 1.3vw, 22px);
  font-size: clamp(17px, 1.55vw, 25px); color: var(--ink);
  outline: none; transition: border-color .15s, background .15s;
}
.field input:focus { border-color: var(--navy); background: #fff; }
.field input.invalid { border-color: var(--red); background: #fff5f5; }
.field .err { font-size: clamp(13px, 1.05vw, 16px); color: var(--red); margin-top: 6px; display: none; }
.field.has-error .err { display: block; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 clamp(22px, 2.6vw, 44px); }
@media (max-width: 820px) { .form-grid { grid-template-columns: 1fr; } }

/* ---------- privacy ---------- */

.privacy-box {
  flex: 1 1 auto; min-height: 180px;
  overflow-y: auto;
  border: 1.5px solid var(--line); border-radius: 12px;
  background: #fbfcfe; padding: clamp(20px, 2.6vh, 32px) clamp(24px, 2.8vw, 44px);
  font-size: clamp(15px, 1.25vw, 20px); line-height: 1.66; color: #3a4761;
  scroll-behavior: smooth;
}
.privacy-box h2 {
  font-size: clamp(21px, 2vw, 30px); color: var(--navy); text-align: center;
  margin: 0 0 8px; font-weight: 600;
}
.privacy-box h3 { font-size: clamp(16px, 1.35vw, 22px); color: var(--navy); margin: 22px 0 7px; }
.privacy-box p.sub {
  text-align: center; font-size: clamp(13px, 1.05vw, 17px); color: var(--muted);
  font-weight: 600; margin: 0 0 18px;
}
.privacy-box ul { padding-left: 24px; margin: 10px 0; }
.privacy-box li { margin-bottom: 7px; }

.accept-row {
  display: flex; align-items: center; gap: 18px;
  padding: clamp(16px, 2.2vh, 26px) 4px 4px; cursor: pointer;
}
.accept-row .switch {
  flex: 0 0 auto; width: 70px; height: 38px; border-radius: 999px;
  background: #cdd6e2; position: relative; transition: background .2s;
}
.accept-row .switch::after {
  content: ''; position: absolute; top: 4px; left: 4px;
  width: 30px; height: 30px; border-radius: 50%; background: #fff;
  box-shadow: 0 2px 5px rgba(0,0,0,.22); transition: transform .2s;
}
.accept-row.on .switch { background: var(--green); }
.accept-row.on .switch::after { transform: translateX(32px); }
.accept-row .text { font-size: clamp(16px, 1.4vw, 22px); color: var(--navy-soft); }

/* ---------- fotocamera ---------- */

.cam-stage {
  position: relative; width: min(620px, 100%); aspect-ratio: 4 / 3;
  background: #14203a; border-radius: 16px; overflow: hidden;
  display: grid; place-items: center; box-shadow: var(--shadow);
}
.cam-stage video, .cam-stage canvas, .cam-stage img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
/* la sola anteprima del volto è speculare, come uno specchio */
.cam-stage video.mirror { transform: scaleX(-1); }
.cam-msg {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #cfdbec; font-size: 15px; text-align: center; padding: 30px;
  background: #14203a; white-space: pre-line; line-height: 1.55;
}
.cam-guide {
  position: absolute; width: 46%; aspect-ratio: 3/4; border: 3px dashed rgba(255,255,255,.4);
  border-radius: 50% 50% 46% 46%; pointer-events: none;
}

/* indicatore "anteprima dal vivo" */
.live-badge {
  position: absolute; top: 12px; left: 12px; z-index: 4;
  display: flex; align-items: center; gap: 7px;
  background: rgba(10,20,40,.62); color: #fff;
  padding: 6px 13px 6px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 700; letter-spacing: .08em;
}
.live-badge .dot {
  width: 9px; height: 9px; border-radius: 50%; background: #ff4d5a;
  animation: pulse 1.4s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .25; } }

/* riquadro di mira per la lettura QR */
.qr-frame {
  position: absolute; width: 58%; aspect-ratio: 1; pointer-events: none;
  border-radius: 14px; z-index: 3;
  box-shadow: 0 0 0 4000px rgba(10,20,40,.42);
  transition: box-shadow .18s;
}
.qr-frame::before, .qr-frame::after,
.qr-frame > i::before, .qr-frame > i::after {
  content: ''; position: absolute; width: 34px; height: 34px;
  border: 4px solid #ffffff; transition: border-color .18s;
}
.qr-frame::before { top: -2px; left: -2px; border-right: 0; border-bottom: 0; border-radius: 10px 0 0 0; }
.qr-frame::after { top: -2px; right: -2px; border-left: 0; border-bottom: 0; border-radius: 0 10px 0 0; }
.qr-frame > i::before { bottom: -2px; left: -2px; border-right: 0; border-top: 0; border-radius: 0 0 0 10px; }
.qr-frame > i::after { bottom: -2px; right: -2px; border-left: 0; border-top: 0; border-radius: 0 0 10px 0; }

/* stato "codice agganciato" */
.cam-stage.detected .qr-frame::before,
.cam-stage.detected .qr-frame::after,
.cam-stage.detected .qr-frame > i::before,
.cam-stage.detected .qr-frame > i::after { border-color: #33e08a; }
.cam-stage.detected .qr-frame { box-shadow: 0 0 0 4000px rgba(10,40,26,.34); }

/* canvas su cui viene disegnato il contorno del QR riconosciuto */
.qr-overlay {
  position: absolute; inset: 0; z-index: 2; pointer-events: none;
  width: 100% !important; height: 100% !important; object-fit: fill !important;
}

/* riga di stato sotto l'anteprima */
.scan-status {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  margin-top: 14px; padding: 11px 22px; border-radius: 999px;
  background: #eef3f9; color: var(--muted);
  font-size: 14.5px; font-weight: 600; transition: all .2s;
  min-height: 44px;
}
.scan-status .ind {
  width: 12px; height: 12px; border-radius: 50%; background: #c2ccd9; flex: 0 0 auto;
  transition: background .2s;
}
.scan-status.searching { background: #eaf1fb; color: #3a63a8; }
.scan-status.searching .ind { background: #3a63a8; animation: pulse 1.1s ease-in-out infinite; }
.scan-status.found { background: #e2f7ec; color: #157a45; }
.scan-status.found .ind { background: #1f9d63; animation: none; }
.scan-status.failed { background: #fdecec; color: #b3121d; }
.scan-status.failed .ind { background: var(--red); animation: none; }

/* ---------- firma ---------- */

.sign-wrap {
  position: relative; width: 100%; flex: 1 1 auto; min-height: 220px;
  background: #fff; border-radius: 14px; border: 1.5px solid var(--line);
  overflow: hidden;
}
.sign-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
.sign-line {
  position: absolute; left: 12%; right: 12%; bottom: 26%;
  border-bottom: 2px solid #dbe2ec; pointer-events: none;
}
.sign-eraser {
  position: absolute; top: 14px; right: 14px;
  width: 62px; height: 62px; border-radius: 12px; border: 0;
  background: rgba(238,243,249,.95); color: var(--red);
  display: grid; place-items: center; cursor: pointer; box-shadow: 0 3px 10px rgba(0,0,0,.08);
}
.sign-eraser svg { width: 30px; height: 30px; }

/* ---------- pulsanti ---------- */

.btn {
  border: 0; border-radius: 12px; cursor: pointer;
  font-size: clamp(15px, 1.25vw, 20px); font-weight: 700; letter-spacing: .07em;
  padding: clamp(15px, 1.9vh, 21px) clamp(28px, 2.7vw, 44px);
  transition: filter .15s, transform .1s;
  display: inline-flex; align-items: center; gap: 11px;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .42; cursor: not-allowed; }
.btn svg { width: clamp(20px, 1.6vw, 26px); height: clamp(20px, 1.6vw, 26px); }

.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.12); }
/* Deroga alla foto quando la telecamera non è disponibile: colore di richiamo
   distinto dal verde di conferma, per non farla scambiare per il flusso normale. */
.btn-amber { background: #b26a00; color: #fff; }
.btn-amber:hover:not(:disabled) { filter: brightness(1.12); }

.cam-fallback-note {
  margin: 16px auto 0; max-width: 640px; text-align: center;
  font-size: clamp(14px, min(1.15vw, 1.9vh), 20px); line-height: 1.5; color: #5b6b82;
}

.btn-green { background: var(--green); color: #fff; }
.btn-green:hover:not(:disabled) { filter: brightness(1.1); }
.btn-red { background: var(--red); color: #fff; }
.btn-red:hover:not(:disabled) { filter: brightness(1.1); }
.btn-ghost { background: transparent; color: var(--navy); padding-left: 12px; }
.btn-ghost:hover { background: rgba(255,255,255,.6); }
.btn-light { background: #eef3f9; color: var(--navy); }

.btn-wide {
  width: 100%; justify-content: center; font-size: clamp(17px, 1.5vw, 24px);
  padding: clamp(18px, 2.3vh, 26px); border-radius: 12px; margin-top: 16px;
  background: linear-gradient(90deg, #56b8e8, #3f9bd6); color: #fff;
}

/* ---------- risultati ricerca uscita ---------- */

.search-input-wrap { position: relative; width: 100%; margin-bottom: 6px; }
.search-input-wrap input {
  width: 100%; border: 2px solid var(--line); background: #fff;
  border-radius: 999px;
  padding: clamp(17px, 2.2vh, 24px) clamp(56px, 4vw, 68px) clamp(17px, 2.2vh, 24px) clamp(26px, 2.2vw, 36px);
  font-size: clamp(19px, 1.7vw, 27px); outline: none;
}
.search-input-wrap input:focus { border-color: var(--navy); }
.search-input-wrap svg {
  position: absolute; right: clamp(22px, 1.9vw, 30px); top: 50%; transform: translateY(-50%);
  width: clamp(22px, 1.8vw, 30px); height: clamp(22px, 1.8vw, 30px);
  color: var(--muted); pointer-events: none;
}

.result-list { flex: 1 1 auto; overflow-y: auto; margin-top: 14px; min-height: 0; }
.result-item {
  display: flex; align-items: center; gap: clamp(16px, 1.6vw, 24px);
  padding: clamp(13px, 1.8vh, 20px) clamp(16px, 1.5vw, 24px);
  border-radius: 14px; cursor: pointer;
  border: 1.5px solid transparent; transition: background .13s, border-color .13s;
}
.result-item:hover { background: #f2f7fc; border-color: var(--line); }
.result-item:active { transform: scale(.995); }
.result-avatar {
  width: clamp(52px, 4.6vw, 74px); height: clamp(52px, 4.6vw, 74px);
  border-radius: 50%; flex: 0 0 auto;
  background: var(--green); display: grid; place-items: center; overflow: hidden;
  color: #fff;
}
.result-avatar img { width: 100%; height: 100%; object-fit: cover; }
.result-avatar svg { width: 50%; height: 50%; }
.result-main { flex: 1 1 auto; min-width: 0; }
.result-name { font-size: clamp(17px, 1.6vw, 25px); font-weight: 700; color: var(--navy); }
.result-meta { font-size: clamp(13.5px, 1.15vw, 18px); color: var(--muted); }
.result-time { font-size: clamp(13px, 1.05vw, 17px); color: var(--muted); text-align: right; white-space: nowrap; }
.result-time strong { display: block; color: var(--navy); font-size: clamp(15px, 1.3vw, 21px); }

.empty-state { text-align: center; color: var(--muted); padding: 46px 20px; font-size: clamp(16px, 1.35vw, 21px); }

/* ---------- schede ---------- */

.tabs { display: flex; gap: 10px; justify-content: center; margin-bottom: clamp(16px, 2.2vh, 26px); }
.tab {
  border: 0; background: #eef3f9; color: var(--navy);
  padding: clamp(11px, 1.5vh, 16px) clamp(22px, 2.2vw, 34px);
  border-radius: 999px; cursor: pointer;
  font-size: clamp(14px, 1.2vw, 19px); font-weight: 700; letter-spacing: .05em;
}
.tab.active { background: var(--navy); color: #fff; }

/* ---------- esito ---------- */

.done-icon {
  width: 108px; height: 108px; border-radius: 50%;
  display: grid; place-items: center; margin: 0 auto 20px;
  color: #fff;
}
.done-icon svg { width: 56px; height: 56px; }
.done-in { background: var(--green); }
.done-out { background: var(--red); }
.done-title { font-size: 27px; font-weight: 600; color: var(--navy); text-align: center; margin-bottom: 8px; }
.done-msg { font-size: 17px; color: var(--navy-soft); text-align: center; margin-bottom: 20px; }

.badge-box {
  display: flex; align-items: center; gap: 22px; justify-content: center;
  background: #f4f8fc; border: 1.5px solid var(--line); border-radius: 14px;
  padding: 18px 24px; margin-top: 6px;
}
.badge-box img { width: 132px; height: 132px; border-radius: 8px; background: #fff; }
.badge-box .code {
  font-family: Consolas, 'Courier New', monospace; font-size: 24px;
  letter-spacing: .14em; font-weight: 700; color: var(--navy);
}
.badge-box .note { font-size: 13.5px; color: var(--muted); max-width: 290px; margin-top: 6px; }

.countdown { text-align: center; font-size: 13px; color: var(--muted); margin-top: 14px; }

/* ---------- overlay ---------- */

.overlay {
  position: fixed; inset: 0; background: rgba(20,32,58,.55);
  display: none; place-items: center; z-index: 50; padding: 24px;
  backdrop-filter: blur(2px);
}
.overlay.show { display: grid; }
.overlay-card {
  background: #fff; border-radius: 16px; padding: 30px 34px;
  width: min(520px, 100%); text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.overlay-card h3 { margin: 0 0 10px; font-size: 22px; color: var(--navy); }
.overlay-card p { margin: 0 0 22px; font-size: 16px; color: var(--navy-soft); }
.overlay-actions { display: flex; gap: 12px; justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: 34px; transform: translateX(-50%) translateY(20px);
  background: var(--navy); color: #fff; padding: 14px 26px; border-radius: 10px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: all .25s; z-index: 60;
  max-width: 80vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); }

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

/* ---------- adattamento schermi bassi ---------- */

@media (max-height: 720px) {
  .screen { padding: 16px 24px 14px; }
  .card { padding: 20px 26px; }
  .welcome-msg { margin-bottom: 20px; }
  .card-sub { margin-bottom: 14px; }
}
