/* =====================================================================
   IRIGuest — Generatore badge aziendali con QR Code
   Stile pagina + anteprima badge. Riusa i token di site.css.
   ===================================================================== */

/* ---------- Hero ---------- */
.bg-hero {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 64px 0 40px;
  text-align: center;
}
.bg-hero h1 {
  margin: 8px 0 14px;
  font-size: clamp(1.9rem, 4vw, 2.9rem);
  line-height: 1.12;
  color: var(--ink);
  -webkit-text-fill-color: var(--ink);
}
.bg-hero__lead {
  max-width: 760px;
  margin: 0 auto;
  color: var(--text-muted);
  font-size: 1.08rem;
  line-height: 1.6;
}

/* ---------- Layout strumento ---------- */
.bg-tool { padding: 48px 0; }
.bg-tool__grid {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 0.95fr);
  gap: 40px;
  align-items: start;
}
@media (max-width: 920px) {
  .bg-tool__grid { grid-template-columns: 1fr; gap: 32px; }
  .bg-preview { order: -1; }   /* anteprima sopra il form su mobile */
}

/* ---------- Form ---------- */
.bg-form {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 28px;
}
.bg-field { margin-bottom: 20px; }
.bg-field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 480px) { .bg-field-row { grid-template-columns: 1fr; } }

.bg-form label,
.bg-modes legend {
  display: block;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
  font-size: .96rem;
}
.bg-req { color: var(--teal); }

.bg-form input[type="text"],
.bg-form input[type="number"],
.bg-form input[type="file"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
.bg-form input[type="file"] { padding: 10px 12px; }
.bg-form input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(31, 111, 147, .15);
}
.bg-hint {
  display: block;
  margin-top: 6px;
  color: var(--text-muted);
  font-size: .82rem;
  line-height: 1.4;
}

/* honeypot nascosto */
.bg-hp {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

/* orientamento */
.bg-modes {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px;
  background: var(--surface);
}
.bg-radio {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-weight: 400 !important;
  margin-bottom: 10px;
  cursor: pointer;
  font-size: .92rem;
  color: var(--text);
}
.bg-radio:last-child { margin-bottom: 0; }
.bg-radio input { margin-top: 3px; accent-color: var(--teal); }

/* Checkbox "Senza logo" */
.bg-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 400 !important;
  font-size: .9rem;
  color: var(--text-muted);
  cursor: pointer;
  margin-top: 9px;
}
.bg-check input[type="checkbox"] {
  width: auto;
  padding: 0;
  accent-color: var(--teal);
  cursor: pointer;
  flex-shrink: 0;
}

/* Select formato foglio */
.bg-select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  cursor: pointer;
}
.bg-select:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(31, 111, 147, .15);
}

/* Impostazioni avanzate del foglio */
.bg-advanced { margin: 0 0 20px; }
.bg-advanced__toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: none;
  border: none;
  padding: 4px 0;
  font: inherit;
  font-size: .9rem;
  font-weight: 600;
  color: var(--teal);
  cursor: pointer;
}
.bg-advanced__toggle:hover { color: var(--teal-deep); }
.bg-advanced__chev {
  width: 16px;
  height: 16px;
  transition: transform .18s ease;
}
.bg-advanced__toggle.is-open .bg-advanced__chev { transform: rotate(180deg); }

.bg-advanced__body {
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
}
.bg-advanced__help {
  margin: 0 0 14px;
  font-size: .84rem;
  line-height: 1.5;
  color: var(--text-muted);
}

.bg-adv-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}
@media (max-width: 480px) { .bg-adv-grid { grid-template-columns: 1fr; } }
.bg-adv-field label {
  font-size: .82rem;
  font-weight: 500;
  margin-bottom: 4px;
}
.bg-adv-field input[type="number"] {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: .92rem;
  color: var(--text);
  background: #fff;
}
.bg-adv-field input:focus {
  outline: none;
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(31, 111, 147, .15);
}

/* Readout calcolati */
.bg-adv-calc {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin: 16px 0 0;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
.bg-adv-calc > div { display: flex; flex-direction: column; gap: 2px; }
.bg-adv-calc dt {
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}
.bg-adv-calc dd {
  margin: 0;
  font-size: .98rem;
  font-weight: 600;
  color: var(--ink);
}

.bg-adv-warning {
  margin: 14px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #FDECEC;
  border: 1px solid #F3C2C2;
  color: #9c2b2b;
  font-size: .85rem;
  line-height: 1.45;
}
.bg-print-note {
  background: #FFF7E8;
  border: 1px solid #F0E2C4;
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: .86rem;
  color: #6b5a32;
  line-height: 1.5;
  margin: 4px 0 22px;
}

.bg-actions {
  display: flex;
  align-items: center;
  gap: 14px;
}
.bg-actions .btn { cursor: pointer; }
.bg-actions .btn[disabled] { opacity: .6; cursor: progress; }

/* spinner */
.bg-spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--line-strong);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: bg-spin .7s linear infinite;
}
@keyframes bg-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .bg-spinner { animation: none; } }

/* messaggi */
.bg-result, .bg-error {
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: var(--radius-sm);
  font-size: .95rem;
  line-height: 1.5;
}
.bg-result {
  background: #E9F6EF;
  border: 1px solid #B9E3CD;
  color: #1c5e3f;
}
.bg-result .bg-fallback-link {
  display: block;
  margin-top: 8px;
  font-size: .84rem;
  color: var(--teal);
  text-decoration: underline;
}
.bg-error {
  background: #FDECEC;
  border: 1px solid #F3C2C2;
  color: #9c2b2b;
}

/* ---------- Anteprima ---------- */
.bg-preview__title { font-size: 1.15rem; margin: 0 0 16px; }
.bg-preview__hint {
  margin: 12px 0 0;
  color: var(--text-muted);
  font-size: .82rem;
  line-height: 1.45;
}

/* Badge in proporzione reale 85:55 */
.bg-badge {
  position: relative;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 85 / 55;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  /* padding interno proporzionale al margine di sicurezza ~5mm */
  padding: 5.9%;
  font-family: var(--sans);
}

/* Badge verticale nascosto di default; JS lo porta a display:flex quando serve.
   L'ID ha specificità maggiore di .bg-badge--portrait, quindi vince su display:flex. */
#bg-badge-v { display: none; }

/* Anteprima verticale: rettangolo portrait con elementi in colonna centrati */
.bg-badge--portrait {
  aspect-ratio: 55 / 85;
  max-width: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 7%;
  gap: 0;
}

/* Logo (quadrato centrato, ~33% della larghezza del badge) */
.bgv__logo {
  width: 33%;
  aspect-ratio: 1;
  flex-shrink: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  margin-bottom: 5%;
}
.bgv__logo img { width: 100%; height: 100%; object-fit: contain; }
.bgv__logo span {
  font-weight: 700;
  color: var(--teal);
  font-size: clamp(.9rem, 3.5vw, 1.4rem);
}

/* Nome azienda */
.bgv__company {
  font-weight: 600;
  color: #000;
  font-size: clamp(.66rem, 2.5vw, .9rem);
  text-align: center;
  width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 5%;
}

/* Numero badge (grande, centrato) */
.bgv__number {
  font-weight: 400;
  color: #000;
  font-size: clamp(2rem, 8vw, 3rem);
  letter-spacing: .04em;
  line-height: 1;
  text-align: center;
  width: 100%;
  margin-bottom: 6%;
}

/* QR placeholder (centrato, ~44% della larghezza) */
.bgv__qr {
  width: 44%;
  aspect-ratio: 1;
  flex-shrink: 0;
  margin-bottom: 4%;
}
.bgv__qr svg { display: block; width: 100%; height: 100%; }

/* Dominio */
.bgv__domain {
  color: var(--text-muted);
  font-size: clamp(.38rem, 1.5vw, .55rem);
  letter-spacing: .01em;
  text-align: center;
}

.bg-badge__top {
  display: flex;
  align-items: flex-start;
  gap: 4%;
  position: relative;
  z-index: 1;
}
.bg-badge__logo {
  flex: 0 0 auto;
  width: 19%;
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.bg-badge__logo img { width: 100%; height: 100%; object-fit: contain; }
.bg-badge__logo span {
  font-weight: 700;
  color: var(--teal);
  font-size: clamp(1rem, 5vw, 1.6rem);
}
/* Nome azienda: una riga, bordo alto allineato a quello del logo.
   Può estendersi sopra l'area del QR (che è più in basso). */
.bg-badge__company {
  font-weight: 600;
  color: #000;
  font-size: clamp(.72rem, 3vw, .98rem);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-top: 1px;
  flex: 1 1 auto;
  min-width: 0;
}
.bg-badge__number {
  position: absolute;
  left: 5.9%;
  bottom: 15%;
  font-weight: 400;
  color: #000;
  font-size: clamp(2rem, 11vw, 3.5rem);
  line-height: 1;
  letter-spacing: .04em;
  z-index: 1;
}
.bg-badge__qr {
  position: absolute;
  right: 5.9%;
  top: 24%;
  width: 27%;
  aspect-ratio: 1 / 1;
  z-index: 1;
}
.bg-badge__qr svg { display: block; width: 100%; height: 100%; }
.bg-badge__domain {
  position: absolute;
  right: 5.9%;
  bottom: 6%;
  width: 27%;
  text-align: center;
  color: var(--text-muted);
  font-size: clamp(.42rem, 1.8vw, .6rem);
  letter-spacing: .01em;
  z-index: 1;
}

/* mini griglia A4 */
.bg-grid__title { font-size: .98rem; margin: 26px 0 10px; }
.bg-grid__sheet {
  width: 150px;
  aspect-ratio: 210 / 297;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  padding: 5%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: 1fr;
  gap: 4px 8px;
  box-shadow: var(--shadow-sm);
}
.bg-grid__cell {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 2px;
}

/* ---------- Contenuto informativo ---------- */
.bg-info {
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 56px 0;
}
.bg-info__inner { max-width: 820px; margin: 0 auto; }
.bg-info h2 {
  font-size: 1.25rem;
  margin: 28px 0 8px;
  color: var(--ink);
}
.bg-info h2:first-child { margin-top: 0; }
.bg-info p {
  color: var(--text-muted);
  line-height: 1.65;
  margin: 0 0 6px;
}
.bg-info__soft {
  margin-top: 22px;
  padding: 18px 20px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--text);
}
.bg-info__soft a { color: var(--teal); font-weight: 600; }
