/* ============================================================
   Calcolo Codice Fiscale — stile ispirato all'Agenzia delle Entrate
   Palette istituzionale: blu #0066cc, blu scuro #003366, grigi.
   ============================================================ */
:root {
  --blu: #0066cc;
  --blu-scuro: #003366;
  --blu-chiaro: #e6f0fa;
  --verde: #009246;
  --rosso: #ce2b37;
  --grigio-bg: #f4f6f8;
  --grigio-bordo: #d6dce2;
  --testo: #1b1b1b;
  --testo-soft: #55606b;
  --radius: 6px;
  --ombra: 0 2px 8px rgba(0, 40, 90, 0.08);
}

* { box-sizing: border-box; }
/* L'attributo hidden deve avere sempre la precedenza (altrimenti display:flex
   su .install-banner lo rende sempre visibile). */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: "Titillium Web", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color: var(--testo);
  background: var(--grigio-bg);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.container { width: 100%; max-width: 860px; margin: 0 auto; padding: 0 16px; }

a { color: var(--blu); }

/* ---------- HEADER ---------- */
.site-header { background: #fff; box-shadow: var(--ombra); border-bottom: 3px solid var(--blu); }

.flag {
  display: inline-flex; width: 46px; height: 32px; flex: none;
  border: 1px solid var(--grigio-bordo); border-radius: 3px; overflow: hidden;
}
.flag span { display: block; width: 33.33%; height: 100%; }
.flag-green { background: var(--verde); }
.flag-white { background: #fff; }
.flag-red { background: var(--rosso); }

.header-main-inner { display: flex; align-items: center; padding: 16px; }
.brand { display: flex; align-items: center; gap: 14px; }

/* Banner installazione PWA (sopra l'header) */
.install-banner {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--blu-scuro); color: #fff; padding: 10px 16px;
}
.install-banner-text { flex: 1 1 auto; font-size: 14px; font-weight: 600; }
.install-banner-btn {
  flex: none; background: var(--verde); color: #fff; padding: 8px 16px; font-size: 14px;
}
.install-banner-btn:hover { filter: brightness(.93); }
.install-banner-close {
  flex: none; background: transparent; border: none; color: #cfe0f5; cursor: pointer;
  font-size: 16px; line-height: 1; padding: 6px 8px;
}
.install-banner-close:hover { color: #fff; }

.ios-hint {
  background: var(--blu-chiaro); border: 1px solid #b9d5f2; border-radius: var(--radius);
  padding: 12px 14px; margin: 0 0 16px; font-size: 14px; color: var(--blu-scuro);
}
.brand-title { margin: 0; font-size: 24px; color: var(--blu-scuro); line-height: 1.1; }
.brand-sub { margin: 2px 0 0; font-size: 14px; color: var(--testo-soft); }

.header-nav { background: var(--blu); }
.header-nav ul { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; }
.header-nav a {
  display: block; color: #fff; text-decoration: none; padding: 12px 18px;
  font-size: 15px; font-weight: 600;
}
.header-nav a:hover { background: rgba(255,255,255,.14); }

/* ---------- LAYOUT ---------- */
main { padding: 22px 0 40px; }
.layout { width: 100%; }
.content { min-width: 0; }

.card {
  background: #fff; border: 1px solid var(--grigio-bordo); border-radius: var(--radius);
  padding: 24px; margin-bottom: 22px; box-shadow: var(--ombra);
}
.card-title {
  margin: 0 0 14px; font-size: 20px; color: var(--blu-scuro);
  border-bottom: 3px solid var(--blu); padding-bottom: 8px; display: inline-block;
}
.card-intro { color: var(--testo-soft); margin-top: 0; }

/* Card collassabile (es. "Come funziona") */
.card-details > summary {
  cursor: pointer; list-style: none; font-size: 18px; font-weight: 700;
  color: var(--blu-scuro); display: flex; align-items: center; justify-content: space-between;
}
.card-details > summary::-webkit-details-marker { display: none; }
.card-details > summary::after { content: "▾"; color: var(--blu); font-size: 14px; margin-left: 10px; }
.card-details[open] > summary::after { content: "▴"; }
.card-details[open] > summary { margin-bottom: 12px; border-bottom: 3px solid var(--blu); padding-bottom: 8px; }

/* ---------- CHIP PRIVACY ---------- */
.privacy-chip {
  display: flex; align-items: center; gap: 6px; width: fit-content; max-width: 100%;
  margin: 0 auto 16px; padding: 7px 15px; border-radius: 999px;
  background: #e7f6ec; color: #1a7f37; border: 1px solid #a6dab5;
  font-size: 13px; font-weight: 600; text-align: center;
}

/* ---------- SELETTORE MODALITÀ ---------- */
.mode-tabs {
  display: flex; gap: 6px; background: #fff; border: 1px solid var(--grigio-bordo);
  border-radius: var(--radius); padding: 6px; margin-bottom: 22px; box-shadow: var(--ombra);
}
.mode-tab {
  flex: 1 1 0; text-align: center; padding: 11px 10px; border-radius: 4px;
  text-decoration: none; font-weight: 600; color: var(--blu); font-size: 15px;
}
.mode-tab:hover { background: var(--blu-chiaro); }
.mode-tab.active { background: var(--blu); color: #fff; }

/* ---------- DECODIFICA (verifica) ---------- */
.decode { margin-top: 20px; }
.decode-badge { margin-bottom: 14px; }
.badge { display: inline-block; padding: 10px 14px; border-radius: var(--radius); font-weight: 700; font-size: 15px; }
.badge-ok { background: #e7f6ec; color: #1a7f37; border: 1px solid #a6dab5; }
.badge-ko { background: #fdecec; color: #a3241a; border: 1px solid #f3b6b1; }
.decode-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--grigio-bordo); }
.decode-k { color: var(--testo-soft); font-weight: 600; }
.decode-v { text-align: right; font-weight: 600; color: var(--blu-scuro); }
.decode-note { font-weight: 400; color: var(--testo-soft); font-size: 12px; }
.decode-omo { background: var(--blu-chiaro); border: 1px solid #b9d5f2; border-radius: var(--radius); padding: 10px 12px; font-size: 13px; margin-top: 14px; }
.decode-warn { font-size: 13px; color: var(--testo-soft); margin-top: 14px; }

/* ---------- FORM ---------- */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.field { margin-bottom: 16px; }
.field label, .label-like { display: block; font-weight: 600; margin-bottom: 6px; font-size: 15px; }
.opt { font-weight: 400; color: var(--testo-soft); }

input[type=text], input[type=date], select {
  width: 100%; padding: 11px 12px; font-size: 16px; color: var(--testo);
  border: 1px solid var(--grigio-bordo); border-radius: var(--radius); background: #fff;
}
input:focus, select:focus { outline: 3px solid rgba(0,102,204,.25); border-color: var(--blu); }

.date-row { display: flex; gap: 8px; }
.date-row #giorno { flex: 0 0 26%; }
.date-row #mese { flex: 1 1 auto; }
.date-row #anno { flex: 0 0 30%; }

.radio-row { display: flex; gap: 20px; padding-top: 6px; }
.radio { font-weight: 400; display: flex; align-items: center; gap: 6px; cursor: pointer; }

.hint { font-size: 13px; color: var(--testo-soft); margin: 6px 0 0; }

/* Autocompletamento luogo */
.autocomplete { position: relative; }
.ac-list {
  position: absolute; z-index: 30; left: 0; right: 0; top: 100%;
  margin: 4px 0 0; padding: 4px; list-style: none;
  background: #fff; border: 1px solid var(--grigio-bordo); border-radius: var(--radius);
  box-shadow: var(--ombra); max-height: 260px; overflow-y: auto;
}
.ac-item { padding: 9px 10px; border-radius: 4px; cursor: pointer; font-size: 15px; }
.ac-item:hover, .ac-item.active { background: var(--blu-chiaro); }

.actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.btn {
  display: inline-block; border: none; border-radius: var(--radius); padding: 12px 22px;
  font-size: 16px; font-weight: 600; cursor: pointer; font-family: inherit;
  text-decoration: none; text-align: center;
}
.btn-primary { background: var(--blu); color: #fff; }
.btn-primary:hover { background: var(--blu-scuro); }
.btn-secondary { background: var(--verde); color: #fff; }
.btn-secondary:hover { filter: brightness(.93); }
.btn-ghost { background: #fff; color: var(--blu); border: 1px solid var(--blu); }
.btn-ghost:hover { background: var(--blu-chiaro); }

/* ---------- RISULTATO / ALERT ---------- */
.alert { padding: 12px 14px; border-radius: var(--radius); margin-top: 16px; font-weight: 600; }
.alert-error { background: #fdecec; color: #a3241a; border: 1px solid #f3b6b1; }

.result {
  margin-top: 20px; padding: 22px; text-align: center;
  background: var(--blu-chiaro); border: 1px solid #b9d5f2; border-radius: var(--radius);
}
.result-label { margin: 0 0 8px; font-weight: 600; color: var(--blu-scuro); text-transform: uppercase; font-size: 13px; letter-spacing: 1px; }
.result-code {
  margin: 0 0 14px; font-size: clamp(16px, 5.2vw, 34px); font-weight: 700; letter-spacing: 2px;
  color: var(--blu-scuro); font-family: "Courier New", monospace;
  white-space: nowrap; overflow-x: auto; max-width: 100%;
}
.result-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.result-note { font-size: 12px; color: var(--testo-soft); margin: 14px 0 0; }

/* ---------- CONTENUTI ---------- */
.steps { padding-left: 20px; }
.steps li { margin-bottom: 6px; }
.card h3 { color: var(--blu-scuro); margin-bottom: 6px; }

details { border-bottom: 1px solid var(--grigio-bordo); padding: 10px 0; }
details summary { cursor: pointer; font-weight: 600; color: var(--blu-scuro); }
details p { margin: 8px 0 0; color: var(--testo-soft); }
.small { font-size: 13px; color: var(--testo-soft); }

/* ---------- PUBBLICITÀ (solo banner sopra e sotto) ---------- */
.ad-slot { display: block; margin: 0 0 22px; text-align: center; overflow: hidden; }
.ad-slot .adsbygoogle { display: block; }

/* ---------- FOOTER ---------- */
.site-footer { background: var(--blu-scuro); color: #dfe7f0; padding: 22px 0; text-align: center; }
.site-footer p { margin: 4px 0; }
.site-footer .small { color: #a9bcd4; }
.footer-links a { color: #cfe0f5; text-decoration: none; font-weight: 600; }
.footer-links a:hover { text-decoration: underline; }

/* ---------- RESPONSIVE ---------- */
@media (max-width: 560px) {
  .grid-2 { grid-template-columns: 1fr; }
  .brand-title { font-size: 20px; }
  .header-nav a { padding: 10px 12px; font-size: 14px; }
}

/* ================= Calcolo Mutuo ================= */
.stat-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 6px; }
.stat-tile {
  flex: 1 1 130px; background: #fff; border: 1px solid var(--grigio-bordo);
  border-radius: var(--radius); padding: 12px 14px; text-align: left;
}
.stat-label { display: block; font-size: 12px; color: var(--testo-soft); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { display: block; font-size: 18px; font-weight: 700; color: var(--blu-scuro); margin-top: 4px; }

.table-wrap { overflow-x: auto; margin-top: 14px; }
.plan-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.plan-table th, .plan-table td { padding: 7px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--grigio-bordo); }
.plan-table th { background: var(--blu-chiaro); color: var(--blu-scuro); position: sticky; top: 0; }
.plan-table td:first-child, .plan-table th:first-child { text-align: left; }
.plan-details { margin-top: 16px; }
.plan-details summary { cursor: pointer; font-weight: 600; color: var(--blu); }
.plan-details .table-wrap { max-height: 340px; overflow-y: auto; }

.plan-table.scenari td { text-align: right; }
.row-current { background: var(--blu-chiaro); font-weight: 700; }
.scenario-tag { display: inline-block; font-size: 11px; color: var(--testo-soft); font-weight: 600; margin-left: 4px; }
.diff-up { color: #a3241a; font-weight: 600; }
.diff-down { color: #1a7f37; font-weight: 600; }

.result { text-align: left; }
.result .result-label, .result .result-code { text-align: center; }

.result-export { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-top: 18px; }

/* Stampa / PDF: mostra solo il risultato, nasconde navigazione, form e annunci */
@media print {
  .install-banner, .site-header, .site-footer, .ad-slot, #form-mutuo,
  .card-details, .privacy-chip, .result-export, .ios-hint { display: none !important; }
  body { background: #fff; }
  .card { border: none; box-shadow: none; padding: 0; }
  .result { border: none; background: #fff; }
  .plan-details > summary { display: none; }
  .plan-details .table-wrap { max-height: none !important; overflow: visible !important; }
  .plan-table th { position: static; }
}
