* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #f5f7fa;
  color: #1a202c;
  line-height: 1.6;
  padding: 20px;
}

.container { max-width: 960px; margin: 0 auto; }

header { text-align: center; margin-bottom: 40px; }
header h1 { font-size: 2.2rem; color: #1a365d; margin-bottom: 8px; }
.subtitle { color: #4a5568; font-size: 1.05rem; }

form {
  background: white;
  padding: 30px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin-bottom: 30px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.field { display: flex; flex-direction: column; }
.field label { font-weight: 600; margin-bottom: 6px; font-size: 0.92rem; }
.field .req { color: #e53e3e; }
.field input, .field select {
  padding: 10px 12px;
  border: 1px solid #cbd5e0;
  border-radius: 8px;
  font-size: 0.95rem;
  transition: border 0.2s;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: #3182ce;
  box-shadow: 0 0 0 3px rgba(49,130,206,0.1);
}
.field small { color: #718096; font-size: 0.82rem; margin-top: 4px; }

button[type="submit"] {
  background: #3182ce;
  color: white;
  border: none;
  padding: 14px 28px;
  font-size: 1.05rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  width: 100%;
  transition: background 0.2s;
}
button[type="submit"]:hover:not(:disabled) { background: #2c5282; }
button[type="submit"]:disabled { background: #a0aec0; cursor: not-allowed; }

.hidden { display: none !important; }

#loading {
  text-align: center;
  padding: 40px;
  background: white;
  border-radius: 12px;
  margin-bottom: 30px;
}
.spinner {
  width: 40px; height: 40px;
  border: 4px solid #e2e8f0;
  border-top-color: #3182ce;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error {
  background: #fed7d7;
  color: #742a2a;
  padding: 16px 20px;
  border-radius: 8px;
  border-left: 4px solid #e53e3e;
  margin-bottom: 30px;
  white-space: pre-wrap;
}

.card {
  background: white;
  padding: 24px;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin-bottom: 20px;
}
.card h3 { color: #2d3748; margin-bottom: 16px; font-size: 1.15rem; }
.card h4 { color: #4a5568; margin-bottom: 10px; font-size: 1rem; }

.card.highlight {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}
.card.highlight h3 { color: white; opacity: 0.95; }
.big-number { font-size: 3rem; font-weight: 700; margin: 12px 0 4px; }
.card.highlight .label { opacity: 0.85; font-size: 0.9rem; margin-bottom: 20px; }
.card.highlight dt { color: rgba(255,255,255,0.85); }
.card.highlight dd { color: white; }

dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 20px; }
dt { color: #4a5568; font-size: 0.9rem; font-weight: 500; }
dd { font-weight: 600; text-align: right; }

.decorrenza-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 640px) {
  .decorrenza-grid { grid-template-columns: 1fr; }
}

table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 12px;
  font-size: 0.9rem;
}
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid #e2e8f0; }
th { background: #f7fafc; font-weight: 600; }

details { margin-top: 16px; }
summary { cursor: pointer; color: #3182ce; font-weight: 500; padding: 8px 0; }

.avvertenza {
  background: #fffaf0;
  border-left: 4px solid #ed8936;
  padding: 16px 20px;
  border-radius: 8px;
  font-size: 0.92rem;
  color: #744210;
  margin-bottom: 20px;
}

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
  font-weight: 600;
}
.badge.ok { background: #c6f6d5; color: #22543d; }
.badge.no { background: #fed7d7; color: #742a2a; }


#intestazione {
  text-align: center;
  margin-bottom: 30px;
  padding: 20px;
  background: linear-gradient(135deg, #f6f8fb 0%, #e9eef5 100%);
  border-radius: 12px;
}
#intestazione h2 {
  color: #1a365d;
  margin: 0 0 6px 0;
  font-size: 1.6rem;
}
#intestazione .cf {
  color: #4a5568;
  font-size: 0.95rem;
  margin: 0;
  font-family: 'Courier New', monospace;
  letter-spacing: 1px;
}
/* --- Pulsante stampa --- */
.azioni-stampa {
  text-align: right;
  margin-bottom: 20px;
}
.btn-stampa {
  background: #3182ce;
  color: white;
  border: none;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
.btn-stampa:hover {
  background: #2c5282;
}

/* --- Stili per la stampa --- */
@media print {
  /* Nasconde header, form, loading, errore, footer, tasto stampa */
  header,
  form,
  #loading,
  #errore,
  .no-print,
  footer {
    display: none !important;
  }

  /* Corpo: bianco, senza ombre, margini stretti */
  body {
    background: white !important;
    padding: 0 !important;
    margin: 0 !important;
    font-size: 11pt;
  }

  .container {
    max-width: 100% !important;
    margin: 0 !important;
  }

  /* Intestazione (nome e CF) */
  #intestazione {
    background: #f0f4f8 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
    page-break-after: avoid;
  }

  /* Card: niente ombre, bordi sottili */
  .card {
    box-shadow: none !important;
    border: 1px solid #cbd5e0;
    page-break-inside: avoid;
    margin-bottom: 12px;
  }

  /* Card highlight: mantiene il gradiente in stampa */
  .card.highlight {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  /* Grandi numeri: dimensione ridotta per stare in pagina */
  .big-number {
    font-size: 2rem !important;
  }

  /* Tabelle: compattate */
  table {
    font-size: 9pt;
    page-break-inside: auto;
  }
  tr {
    page-break-inside: avoid;
  }
  th, td {
    padding: 4px 8px !important;
  }

  /* Avvertenza: bordo visibile */
  .avvertenza {
    page-break-inside: avoid;
    border-left-width: 4px !important;
  }

  /* Link: nessuna sottolineatura blu */
  a {
    color: inherit !important;
    text-decoration: none !important;
  }

  /* Nessun margine extra dopo l'ultima card */
  #risultati > *:last-child {
    margin-bottom: 0;
  }

  /* Evita di spezzare la sezione decorrenza tra due pagine */
  .decorrenza-grid {
    page-break-inside: avoid;
  }
}