:root {
  --fondo: #0f1522;
  --scheda: #182030;
  --bordo: #263042;
  --input: #374151;
  --input-bordo: #4b5563;
  --testo: #f3f4f6;
  --tenue: #9ca3af;
  --blu: #3b82f6;
  --blu-chiaro: #60a5fa;
  --verde: #22c55e;
  --rosso: #ef4444;
  --raggio: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--fondo);
  color: var(--testo);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.pagina { max-width: 760px; margin: 0 auto; padding: 24px 16px calc(40px + env(safe-area-inset-bottom)); }
.testata h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -0.01em; }
.sotto { margin: 0 0 22px; color: #cbd5e1; font-size: 14px; }

.scheda {
  background: var(--scheda);
  border: 1px solid var(--bordo);
  border-radius: 14px;
  padding: 22px 24px;
  margin-bottom: 22px;
}
.scheda h2 { display: flex; align-items: center; gap: 8px; font-size: 17px; margin: 0 0 18px; }
.punto { width: 7px; height: 7px; border-radius: 50%; background: var(--c); flex: none; }
.obbl { color: #facc15; }
.nota-titolo { color: var(--tenue); font-weight: 400; font-size: 12px; }

.aiuto { color: var(--tenue); font-size: 13px; margin: -8px 0 14px; }
.aiuto.piccolo { font-size: 12px; margin: 10px 0 0; }
.centro { text-align: center; }

.campo { display: block; color: #d1d5db; font-size: 14px; margin-bottom: 16px; }
.campo:last-child { margin-bottom: 0; }
.griglia { display: grid; gap: 16px; margin-bottom: 16px; }
.griglia .campo { margin-bottom: 0; }
.griglia:last-child { margin-bottom: 0; }
.griglia.due { grid-template-columns: 1fr 1fr; }
.griglia.tre { grid-template-columns: repeat(3, 1fr); }
.griglia.tre.senza-titolo { grid-template-columns: 1fr 1fr; }

input, textarea, select {
  font: inherit;
  font-size: 16px; /* sotto i 16px Safari su iPhone ingrandisce la pagina */
  color: var(--testo);
  background: var(--input);
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px 15px;
  width: 100%;
  margin-top: 8px;
  outline: none;
  transition: border-color .15s, box-shadow .15s, background-color .4s;
}
textarea { resize: vertical; display: block; }
input::placeholder, textarea::placeholder { color: #9ca3af; }
input:focus, textarea:focus, select:focus { border-color: var(--blu); box-shadow: 0 0 0 3px rgba(59,130,246,.25); }
.maiuscolo { text-transform: uppercase; }
.maiuscolo::placeholder { text-transform: none; }

.con-prefisso { display: flex; margin-top: 8px; }
.con-prefisso input { margin-top: 0; border-radius: 0 8px 8px 0; }
.prefisso {
  display: grid; place-items: center; padding: 0 12px;
  background: #4b5563; color: #e5e7eb; border-radius: 8px 0 0 8px;
  font: 600 13px ui-monospace, SFMono-Regular, Menlo, monospace;
}

.telefono { display: flex; gap: 8px; margin-top: 8px; }
.telefono select {
  margin-top: 0; width: auto; flex: 0 0 auto; max-width: 128px;
  background: #3f3f46; border: 1px solid #52525b; padding: 10px 8px; font-size: 14px;
}
.telefono input { margin-top: 0; min-width: 0; flex: 1; }

/* Campi compilati dal sistema */
.compilato { border-color: rgba(34,197,94,.7) !important; background-color: #2f4a3c !important; }
.compilato-fine { border-color: rgba(34,197,94,.35); }

/* Tipo cliente */
.tipi { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.tipo {
  position: relative;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 26px 12px 24px;
  background: #222a38; color: #9ca3af;
  border: 2px solid #4b5563; border-radius: 12px;
  font: inherit; cursor: pointer;
  transition: all .15s;
}
.tipo svg { width: 38px; height: 38px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; margin-bottom: 8px; }
.tipo strong { font-size: 17px; color: #d1d5db; }
.tipo small { font-size: 12px; }
.tipo.attivo { background: #1e3a64; border-color: var(--blu); color: var(--blu-chiaro); box-shadow: 0 0 24px rgba(59,130,246,.25); }
.tipo.attivo strong { color: var(--blu-chiaro); }
.tipo.attivo::after { content: ""; position: absolute; top: 10px; right: 10px; width: 11px; height: 11px; border-radius: 50%; background: var(--blu); }

/* Campo unico */
.scheda-unico { border-color: #1e4a6e; background: linear-gradient(180deg, #172b40, var(--scheda)); }
.unico { position: relative; }
.unico textarea { margin-top: 0; padding-right: 72px; min-height: 110px; font-size: 17px; }
.microfono {
  position: absolute; right: 10px; bottom: 10px;
  width: 52px; height: 52px; border-radius: 50%;
  border: 0; background: var(--blu); color: #fff; cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(59,130,246,.4);
  touch-action: manipulation;
}
.microfono svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.microfono.acceso { background: var(--rosso); animation: pulsa 1.3s infinite; }
.microfono.conto, .microfono.conto:disabled { background: #f59e0b; color: #111; font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; cursor: wait; box-shadow: none; }
.microfono .quadro { width: 16px; height: 16px; border-radius: 3px; background: #fff; }
.oscillo { display: block; width: 100%; height: 56px; margin-top: 10px; border-radius: 10px; background: #0d1117; border: 1px solid var(--bordo); }
.microfono[disabled] { background: #4b5563; box-shadow: none; cursor: not-allowed; }
@keyframes pulsa { 0% { box-shadow: 0 0 0 0 rgba(239,68,68,.6); } 100% { box-shadow: 0 0 0 16px rgba(239,68,68,0); } }

.azioni-unico { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }
.stato { color: var(--tenue); font-size: 13px; flex: 1; min-width: 160px; }
.stato.lavora::before { content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -2px; border: 2px solid var(--blu-chiaro); border-right-color: transparent; border-radius: 50%; animation: gira .7s linear infinite; }
.stato.errore { color: #fca5a5; }
.stato.ok { color: #86efac; }
@keyframes gira { to { transform: rotate(360deg); } }

.bottone {
  font: inherit; font-weight: 600; font-size: 15px;
  padding: 12px 20px; border-radius: 10px; cursor: pointer;
  background: #2b3445; color: var(--testo); border: 1px solid #3c475b;
  touch-action: manipulation;
}
.bottone.primario { background: var(--blu); border-color: var(--blu); color: #fff; }
.bottone:disabled { opacity: .6; cursor: wait; }

/* Domande di chiarimento */
.domande { margin-top: 18px; display: grid; gap: 12px; }
.domanda { background: #2a2414; border: 1px solid #7c5f14; border-radius: 10px; padding: 14px 16px; }
.domanda p { margin: 0 0 10px; color: #fde68a; font-weight: 600; }
.opzioni { display: flex; flex-wrap: wrap; gap: 8px; }
.opzioni button {
  font: inherit; font-size: 14px; padding: 9px 14px; border-radius: 999px; cursor: pointer;
  background: #3d3420; color: #fef3c7; border: 1px solid #8a6d1d;
  touch-action: manipulation;
}
.opzioni button:hover { background: #4d4126; }
.opzioni .altro { display: flex; gap: 6px; flex: 1 1 200px; }
.opzioni .altro input { margin: 0; padding: 8px 12px; font-size: 15px; border-radius: 999px; }

.fondo { display: flex; justify-content: flex-end; gap: 12px; }
.mancante { border-color: var(--rosso) !important; }

dialog {
  background: var(--scheda); color: var(--testo);
  border: 1px solid var(--bordo); border-radius: 14px;
  width: min(560px, calc(100vw - 32px)); padding: 22px;
}
dialog::backdrop { background: rgba(0,0,0,.6); }
dialog h2 { margin: 0 0 14px; }
dialog pre {
  background: #0f1522; padding: 14px; border-radius: 8px; overflow: auto; max-height: 50vh;
  font-size: 13px; white-space: pre-wrap; word-break: break-word;
}
dialog form { text-align: right; margin-top: 14px; }

[hidden] { display: none !important; }

@media (max-width: 600px) {
  .pagina { padding-top: 18px; }
  .testata h1 { font-size: 22px; }
  .scheda { padding: 18px 16px; border-radius: 12px; margin-bottom: 16px; }
  .griglia.due, .griglia.tre, .griglia.tre.senza-titolo { grid-template-columns: 1fr; }
  .tipi { gap: 10px; }
  .tipo { padding: 18px 8px; }
  .tipo svg { width: 32px; height: 32px; }
  .azioni-unico .bottone { width: 100%; }
  .fondo .bottone { flex: 1; }
}
