/* Calcolo IVA – tusoldi.com */
:root {
  --navy: #0a1b33;
  --navy-2: #12305a;
  --navy-3: #1d426f;
  --emerald: #0f9d6c;
  --emerald-ink: #057650;
  --emerald-soft: #d9f4e8;
  --emerald-glow: #3be0a8;
  --paper: #edf1f6;
  --card: #ffffff;
  --tint: #f3f6fa;
  --line: #d5deea;
  --ink: #0f2037;
  --muted: #526279;
  --danger: #b3261e;
  --radius: 16px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1rem;
  line-height: 1.55;
}
h1, h2, h3 { font-family: var(--serif); line-height: 1.2; margin: 0; }
p { margin: 0 0 .9rem; }
button, input { font: inherit; color: inherit; }
.wrap { width: 100%; max-width: 1040px; margin: 0 auto; padding: 0 1.25rem; }
.sr { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.skip { position: absolute; left: .75rem; top: -4rem; background: #fff; color: var(--navy); padding: .6rem 1rem; border-radius: 8px; z-index: 10; font-weight: 600; }
.skip:focus { top: .75rem; }

:focus-visible { outline: 3px solid var(--emerald); outline-offset: 2px; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-2) 100%);
  color: #fff;
  padding: 1.25rem 0 5.5rem;
}
.brand { font-family: var(--serif); font-weight: 700; font-size: 1.1rem; letter-spacing: .01em; color: var(--emerald-glow); margin-bottom: 2.25rem; }
.hero h1 { font-size: clamp(2.1rem, 6.5vw, 3.4rem); font-weight: 700; letter-spacing: -.01em; margin-bottom: .75rem; }
.lead { font-size: 1.1rem; max-width: 46ch; color: #d4e0f0; margin-bottom: 1rem; }
.disclaimer { font-size: .85rem; color: #a9bdd8; margin: 0; }

/* ---------- Layout principale ---------- */
.main { margin-top: -3.4rem; padding-bottom: 3rem; }
.tablist {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: .25rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  border-bottom: 0;
  padding: .4rem .4rem 0;
}
[role="tab"] {
  appearance: none;
  background: transparent;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: .85rem .5rem;
  font-weight: 600;
  font-size: .98rem;
  color: var(--muted);
  cursor: pointer;
  border-radius: 10px 10px 0 0;
  text-align: center;
  line-height: 1.25;
}
[role="tab"]:hover { color: var(--navy); background: var(--tint); }
[role="tab"][aria-selected="true"] { color: var(--navy); border-bottom-color: var(--emerald); }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-top: 1px solid var(--line);
  border-radius: 0 0 var(--radius) var(--radius);
  padding: 1.75rem;
  min-width: 0;
  box-shadow: 0 18px 40px -24px rgba(10, 27, 51, .35);
}
.panel[hidden] { display: none; }

/* ---------- Calcolatore ---------- */
.calc-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 2rem; align-items: start; }
.calc-in, .calc-out { min-width: 0; }

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend, label.lbl, .field > label, .custom label { font-weight: 600; font-size: .95rem; color: var(--navy); padding: 0; }
legend { margin-bottom: .55rem; }

.rates { margin-bottom: 1.1rem; }
.chips { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; margin-bottom: .9rem; }
.chip {
  min-height: 46px;
  border: 1.5px solid var(--line);
  background: #fff;
  border-radius: 12px;
  font-weight: 700;
  font-size: 1.05rem;
  cursor: pointer;
  color: var(--navy);
}
.chip:hover:not(:disabled) { border-color: var(--navy-3); }
.chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }
.chip:disabled { opacity: .45; cursor: not-allowed; }

.custom { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.err { color: var(--danger); font-size: .9rem; min-height: 0; margin: .4rem 0 0; }
.err:empty { display: none; }

.inputwrap { position: relative; }
.inputwrap input {
  width: 100%;
  min-height: 50px;
  padding: .55rem 2.4rem .55rem .9rem;
  border: 1.5px solid #b8c5d6;
  border-radius: 12px;
  background: #fff;
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.inputwrap input:hover:not(:disabled) { border-color: var(--navy-3); }
.inputwrap input:disabled { background: var(--tint); color: var(--muted); border-color: var(--line); cursor: not-allowed; }
.inputwrap input[aria-invalid="true"] { border-color: var(--danger); }
.inputwrap .unit { position: absolute; right: .95rem; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; pointer-events: none; }
.inputwrap.narrow { width: 7.5rem; }
.field.is-source input { border-color: var(--emerald); box-shadow: 0 0 0 3px var(--emerald-soft); }
.field.is-source input:focus-visible { outline-color: var(--emerald-ink); }

.fields { display: grid; gap: .95rem; margin-top: 1.25rem; }
.field > label { display: block; margin-bottom: .35rem; }

/* Interruttore inversione contabile */
.switch { display: flex; align-items: center; gap: .75rem; cursor: pointer; padding: .35rem 0; width: fit-content; max-width: 100%; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.track { flex: none; width: 48px; height: 28px; background: #b8c5d6; border-radius: 14px; position: relative; transition: background .15s; }
.knob { position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + .track { background: var(--emerald); }
.switch input:checked + .track .knob { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid var(--emerald); outline-offset: 3px; }
.switch-text { font-weight: 600; color: var(--navy); }
.note { background: var(--emerald-soft); color: #0b3d2b; border-radius: 12px; padding: .75rem .9rem; font-size: .92rem; margin: .5rem 0 0; }
.note[hidden] { display: none; }

/* Risultati */
.out-title { font-weight: 600; color: var(--muted); margin-bottom: .75rem; }
.results { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; margin: 0 0 1rem; }
.res { background: var(--tint); border: 1px solid var(--line); border-radius: 14px; padding: .9rem 1rem; min-width: 0; }
.res dt { font-size: .9rem; color: var(--muted); font-weight: 600; margin-bottom: .15rem; }
.res dd { margin: 0; font-family: var(--serif); font-weight: 700; font-size: clamp(1.35rem, 4.4vw, 1.75rem); color: var(--navy); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; line-height: 1.2; }
.res-total { grid-column: 1 / -1; background: var(--navy); border-color: var(--navy); }
.res-total dt { color: #b9cbe3; }
.res-total dd { color: var(--emerald-glow); font-size: clamp(1.9rem, 7vw, 2.6rem); }

.split { display: flex; height: 14px; border-radius: 7px; overflow: hidden; background: var(--line); }
.seg-imp { background: var(--navy-3); transition: width .25s ease; }
.seg-iva { background: var(--emerald); transition: width .25s ease; }
.legend { display: flex; flex-wrap: wrap; gap: .25rem 1.1rem; margin: .5rem 0 1rem; font-size: .88rem; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: .4rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot-imp { background: var(--navy-3); }
.dot-iva { background: var(--emerald); }
.bar-label { margin-left: auto; }
.bar-label:empty { display: none; }

.formula { background: var(--tint); border-left: 4px solid var(--emerald); border-radius: 0 10px 10px 0; padding: .7rem .9rem; font-size: .95rem; overflow-wrap: anywhere; }
.formula p { margin: 0; }
.formula p + p:not(:empty) { margin-top: .25rem; }
.formula p:empty { display: none; }

.actions { display: flex; align-items: center; gap: .9rem; flex-wrap: wrap; margin-top: 1.1rem; }
.status { font-size: .9rem; color: var(--emerald-ink); font-weight: 600; }

.btn {
  appearance: none;
  min-height: 46px;
  padding: .6rem 1.2rem;
  border-radius: 12px;
  border: 1.5px solid transparent;
  font-weight: 700;
  cursor: pointer;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--emerald-ink); color: #fff; }
.btn-primary:hover:not(:disabled) { background: #046444; }
.btn-outline { background: #fff; border-color: var(--navy); color: var(--navy); }
.btn-outline:hover:not(:disabled) { background: var(--tint); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover:not(:disabled) { color: var(--danger); background: #fdeeed; }

.disclaimer-light { margin: 1.5rem 0 0; font-size: .85rem; color: var(--muted); }

/* ---------- Fattura ---------- */
.inv-tools { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem 1.5rem; flex-wrap: wrap; }
.round { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; }
.round legend { float: left; margin: 0 .5rem 0 0; padding: 0; line-height: 1.9; }
.radio { display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; min-height: 40px; }
.radio input { width: 20px; height: 20px; accent-color: var(--emerald-ink); margin: 0; }
.inv-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.hint { font-size: .9rem; color: var(--muted); margin: .9rem 0; max-width: 78ch; }

.table-scroll { position: relative; overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; -webkit-overflow-scrolling: touch; max-width: 100%; }
.table-scroll:focus-visible { outline-offset: 0; }
table { width: 100%; border-collapse: collapse; }
.inv { min-width: 880px; }
.inv th, .inv td { padding: .5rem .55rem; text-align: left; vertical-align: middle; }
.inv thead th { background: var(--navy); color: #fff; font-size: .88rem; font-weight: 600; white-space: nowrap; }
.inv tbody tr + tr td { border-top: 1px solid var(--line); }
.col-desc { width: 26%; min-width: 190px; }
.col-q { width: 9%; min-width: 80px; }
.col-p { width: 14%; min-width: 120px; }
.col-r { width: 9%; min-width: 92px; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.strong { font-weight: 700; }
.act { width: 48px; text-align: center !important; }
.cell { width: 100%; min-height: 42px; padding: .35rem .6rem; border: 1.5px solid #c9d4e2; border-radius: 9px; background: #fff; }
.cell-num { text-align: right; font-variant-numeric: tabular-nums; }
.cell[aria-invalid="true"] { border-color: var(--danger); }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: transparent; color: var(--muted); cursor: pointer; display: inline-grid; place-items: center; }
.icon-btn:hover { background: #fdeeed; color: var(--danger); }
.inv tfoot .sub th, .inv tfoot .sub td { background: var(--tint); border-top: 1px solid var(--line); font-size: .95rem; }
.inv tfoot th { font-weight: 600; text-align: left; }
.inv tfoot .grand th, .inv tfoot .grand td { background: var(--navy); color: var(--emerald-glow); font-weight: 700; font-size: 1.02rem; }
.inv tfoot .grand th { color: #fff; }

.inv-sum { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .75rem; margin: 1.25rem 0 0; }
.inv-sum > div { background: var(--tint); border: 1px solid var(--line); border-radius: 14px; padding: .8rem 1rem; min-width: 0; }
.inv-sum dt { font-size: .88rem; color: var(--muted); font-weight: 600; }
.inv-sum dd { margin: 0; font-family: var(--serif); font-weight: 700; font-size: clamp(1.1rem, 3.6vw, 1.5rem); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.inv-sum .grand { background: var(--navy); border-color: var(--navy); }
.inv-sum .grand dt { color: #b9cbe3; }
.inv-sum .grand dd { color: var(--emerald-glow); }

/* ---------- Guida ---------- */
.guide article { max-width: 78ch; }
.guide h2 { font-size: 1.5rem; margin: 2.2rem 0 .8rem; color: var(--navy); }
.guide h2:first-child { margin-top: 0; }
.guide h3 { font-size: 1.1rem; margin-bottom: .4rem; color: var(--navy); }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.how { background: var(--tint); border: 1px solid var(--line); border-radius: 14px; padding: 1.1rem 1.2rem; }
.how p:last-child { margin-bottom: 0; }
.ex { font-family: var(--serif); font-weight: 700; font-size: 1.05rem; color: var(--navy); overflow-wrap: anywhere; }
.plain .rates-table { min-width: 520px; }
.rates-table th, .rates-table td { padding: .7rem .85rem; text-align: left; border-top: 1px solid var(--line); vertical-align: top; }
.rates-table thead th { background: var(--tint); border-top: 0; font-size: .9rem; color: var(--muted); }
.rates-table tbody th { font-family: var(--serif); font-size: 1.15rem; color: var(--emerald-ink); white-space: nowrap; }
.callout { background: #fff7f0; border: 1.5px solid #f0c8a8; border-radius: 14px; padding: 1.1rem 1.25rem; margin: 2rem 0 0; }
.callout h2 { margin: 0 0 .5rem; font-size: 1.25rem; }
.callout p { margin: 0; }

.faq { border: 1px solid var(--line); border-radius: 12px; background: #fff; margin-bottom: .6rem; }
.faq summary { cursor: pointer; padding: .95rem 3rem .95rem 1.1rem; font-weight: 600; color: var(--navy); list-style: none; position: relative; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after {
  content: "";
  position: absolute; right: 1.15rem; top: 50%;
  width: 9px; height: 9px;
  border-right: 2.5px solid var(--emerald-ink); border-bottom: 2.5px solid var(--emerald-ink);
  transform: translateY(-70%) rotate(45deg);
  transition: transform .15s;
}
.faq[open] summary::after { transform: translateY(-30%) rotate(-135deg); }
.faq[open] { border-color: var(--emerald); }
.faq summary:focus-visible { outline-offset: -3px; border-radius: 12px; }
.faq p { padding: 0 1.1rem 1rem; margin: 0; }

/* ---------- Footer ---------- */
.foot { background: var(--navy); color: #b9cbe3; padding: 1.75rem 0; font-size: .9rem; }
.foot p { margin: 0 0 .35rem; }
.foot p:last-child { margin: 0; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .calc-grid { grid-template-columns: minmax(0, 1fr); gap: 1.5rem; }
  .two { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  .wrap { padding: 0 .9rem; }
  .hero { padding-bottom: 5rem; }
  .brand { margin-bottom: 1.5rem; }
  .panel { padding: 1.1rem .9rem; }
  [role="tab"] { font-size: .86rem; padding: .7rem .2rem; }
  .results { gap: .55rem; }
  .res { padding: .75rem .8rem; }
  .inv-sum { grid-template-columns: minmax(0, 1fr); }
  .inv-actions { width: 100%; }
  .inv-actions .btn { flex: 1 1 auto; padding-left: .8rem; padding-right: .8rem; }
  .guide h2 { font-size: 1.3rem; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

/* ---------- Stampa ---------- */
@media print {
  body { background: #fff; color: #000; font-size: 11pt; }
  .skip, .tablist, .btn, .icon-btn, .chips, .switch, .inv-actions, .actions, .hint, .legend, .split, .act, .col-act, .foot .wrap p:first-child { display: none !important; }
  .hero { background: none; color: #000; padding: 0 0 .5rem; }
  .hero h1 { font-size: 22pt; }
  .brand, .lead, .disclaimer { color: #333; }
  .main { margin-top: 0; padding-bottom: 0; }
  .panel { border: 0; box-shadow: none; padding: 0; }
  .calc-grid { grid-template-columns: 1fr 1fr; }
  .res, .res-total, .inv-sum > div, .inv-sum .grand { background: #fff !important; border: 1px solid #999; }
  .res dd, .res-total dd, .inv-sum dd, .inv-sum .grand dd { color: #000; }
  .res dt, .res-total dt, .inv-sum dt { color: #333; }
  .table-scroll { overflow: visible; border: 0; }
  .inv { min-width: 0; font-size: 10pt; }
  .inv thead th, .inv tfoot .grand th, .inv tfoot .grand td { background: #eee !important; color: #000 !important; }
  .cell, .inputwrap input { border: 0; padding: 0; background: none; min-height: 0; }
  .inputwrap input { font-size: 14pt; padding: 0; }
  .unit { display: none; }
  .faq { border: 0; }
  .faq summary::after { display: none; }
  .faq summary { padding: 0; }
  .faq p { padding: 0 0 .5rem; }
  .guide article { max-width: none; }
  .foot { background: none; color: #333; padding: 1rem 0 0; }
  a { color: #000; }
}
