:root {
  color-scheme: light;
  --bg: #e6eaf0;
  --paper: #ffffff;
  --ink: #14213d;
  --muted: #5a6478;
  --line: #d3dae5;
  --pen: #1d4ed8;
  --ok: #1f7a4d;
  --warn: #a63d12;
  --ui: "Public Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --doc: "Source Serif 4", Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 var(--ui); }
a { color: var(--pen); }
:focus-visible { outline: 3px solid var(--pen); outline-offset: 2px; }
h1 { font-size: 1.75rem; line-height: 1.2; margin: 0 0 .4rem; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; margin: 1.6rem 0 .6rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
code { font-size: .8rem; word-break: break-all; }

/* Pulsanti e campi */
.btn { display: inline-block; font: 600 1rem var(--ui); background: var(--pen); color: #fff; border: 0; border-radius: 6px; padding: .75rem 1.25rem; cursor: pointer; text-decoration: none; }
.btn:hover { background: #1a43b8; }
.btn.small { padding: .45rem .85rem; font-size: .9rem; }
.btn.ghost { background: transparent; color: var(--pen); box-shadow: inset 0 0 0 1.5px var(--pen); }
.btn.danger { background: transparent; color: var(--warn); box-shadow: inset 0 0 0 1.5px var(--warn); }
.link { background: none; border: 0; color: var(--pen); font: inherit; text-decoration: underline; cursor: pointer; padding: 0; }
label { display: block; font-size: .9rem; font-weight: 500; margin-bottom: .8rem; }
label small { font-weight: 400; color: var(--muted); margin-left: .3rem; }
input, select, textarea { display: block; width: 100%; margin-top: .3rem; font: 1rem var(--ui); color: var(--ink); background: #fff; border: 1.5px solid var(--line); border-radius: 6px; padding: .6rem .7rem; }
input:focus, select:focus, textarea:focus { border-color: var(--pen); outline: none; box-shadow: 0 0 0 3px rgba(29,78,216,.15); }
input[type=checkbox] { display: inline; width: 1.15rem; height: 1.15rem; margin: 0; accent-color: var(--pen); vertical-align: -3px; }
.check { display: flex; gap: .5rem; align-items: center; font-weight: 400; }
.alert { padding: .75rem 1rem; border-radius: 6px; background: #fdeee8; color: var(--warn); }
.alert.ok { background: #e7f4ed; color: var(--ok); }
.alert.info { background: #e9effc; color: var(--pen); }
.inline { display: inline-block; margin: .3rem .5rem .3rem 0; }

/* Area admin */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: .9rem 1.25rem; background: var(--ink); color: #fff; }
.topbar .brand { color: #fff; font-weight: 700; text-decoration: none; }
.topbar .link, .topbar a.link { color: #c9d3ea; margin-left: 1rem; }
.flash { max-width: 980px; margin: 1rem auto 0; padding: .75rem 1rem; background: #e9effc; color: var(--pen); border-radius: 6px; }
.sheet { background: var(--paper); max-width: 760px; margin: 1.5rem auto; padding: 2rem; border-radius: 10px; }
.sheet.wide { max-width: 980px; }
.narrow .sheet, .sheet.narrow { max-width: 420px; }
.login { margin-top: 12vh; }
.form fieldset { border: 0; border-top: 1.5px solid var(--line); padding: 1.2rem 0 .4rem; margin: 0; }
.form legend { font-weight: 700; padding-right: .6rem; }
.g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.g3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 1rem; align-items: end; }
.span2 { grid-column: span 2; }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1.4rem; align-items: center; margin-bottom: .8rem; }
.checks label:not(.check) { margin: 0; }
.srv, .srv-head { display: grid; grid-template-columns: 1.6rem 2.2fr 1fr 1fr 1.1fr 1fr 2fr; gap: .4rem; align-items: center; }
.srv { margin-bottom: .4rem; }
.srv input, .srv select { margin: 0; padding: .45rem .5rem; font-size: .9rem; }
.srv-head { font-size: .78rem; color: var(--muted); margin-bottom: .3rem; }
.list, .log { width: 100%; border-collapse: collapse; font-size: .92rem; }
.list th, .log th { text-align: left; color: var(--muted); font-weight: 500; border-bottom: 1.5px solid var(--line); padding: .5rem .4rem; }
.list td, .log td { border-bottom: 1px solid var(--line); padding: .6rem .4rem; vertical-align: top; }
.list tr:hover td { background: #f4f6fa; cursor: pointer; }
.log td { font-size: .82rem; }
.status { display: inline-block; font-weight: 600; }
.s-inviato { color: var(--pen); }
.s-firmato { color: var(--ok); }
.s-annullato { color: var(--muted); text-decoration: line-through; }
.copyrow { display: flex; gap: .5rem; align-items: center; }
.copyrow input { margin: 0; font-size: .85rem; }
.actions { display: flex; flex-wrap: wrap; gap: .6rem; }
.empty { padding: 2rem 0; color: var(--muted); }

/* Pagina cliente */
.reader-top { position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: center; padding: .7rem 1.25rem; background: rgba(230,234,240,.92); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); font-weight: 600; }
.intro, .done { max-width: 820px; margin: 2rem auto 1rem; padding: 0 1.25rem; }
.intro p, .done p { color: var(--muted); max-width: 60ch; }
.done h1 { color: var(--ok); }
.paper { background: var(--paper); max-width: 820px; margin: 0 auto 2rem; padding: 3rem 3.2rem; box-shadow: 0 1px 2px rgba(20,33,61,.08), 0 12px 32px -12px rgba(20,33,61,.18); font-family: var(--doc); font-size: 1.02rem; line-height: 1.62; }

.contratto h1 { font-size: 1.9rem; font-weight: 600; margin: .2rem 0; }
.contratto h2 { font-family: var(--ui); font-size: .98rem; font-weight: 700; margin: 2rem 0 .6rem; padding-bottom: .3rem; border-bottom: 1.5px solid var(--ink); }
.c-head { padding-bottom: 1rem; border-bottom: 3px double var(--ink); margin-bottom: 1rem; }
.c-num, .c-sub { font-family: var(--ui); font-size: .85rem; color: var(--muted); margin: 0; }
.contratto table { width: 100%; border-collapse: collapse; margin: .3rem 0 .6rem; }
.contratto .kv th { width: 40%; text-align: left; font-weight: 400; color: var(--muted); padding: .35rem 1rem .35rem 0; vertical-align: top; border-bottom: 1px solid var(--line); font-family: var(--ui); font-size: .88rem; }
.contratto .kv td { padding: .35rem 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.contratto .grid { display: block; overflow-x: auto; font-size: .92rem; }
.contratto .grid th, .contratto .grid td { border: 1px solid var(--line); padding: .45rem .55rem; text-align: left; vertical-align: top; }
.contratto .grid th { font-family: var(--ui); font-size: .8rem; background: #f2f4f8; }
.contratto .num { white-space: nowrap; }
.contratto .small { font-size: .85rem; color: var(--muted); }
.contratto .vuoto { color: #a2abbb; }
.contratto ol.cg { padding-left: 1.4rem; }
.contratto ol.cg li { margin-bottom: .7rem; }
.contratto .pending { color: #a2abbb; font-style: italic; }
.contratto .signed { color: var(--pen); }

.signbox { max-width: 820px; margin: 0 auto 4rem; padding: 2rem 3.2rem 2.4rem; background: var(--paper); border-top: 4px solid var(--pen); }
.signbox h2 { margin-top: 0; font-size: 1.4rem; }
.decl { display: flex; gap: .7rem; align-items: flex-start; font-weight: 400; padding: .9rem 0; border-top: 1px solid var(--line); margin: 0; }
.decl input { margin-top: .2rem; flex: none; }
.decl + .btn, .decl ~ .btn { margin-top: 1rem; }

/* La riga di firma: il codice si scrive "a penna" */
.sigline { max-width: 340px; margin: 1.6rem 0 1rem; }
.sigline span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .2rem; }
.sigline input { border: 0; border-bottom: 2px solid var(--ink); border-radius: 0; padding: .2rem 0 .3rem; font: 600 2.6rem/1 var(--doc); letter-spacing: .5em; color: var(--pen); background: transparent; }
.sigline input:focus { box-shadow: none; border-bottom-color: var(--pen); }

@media (max-width: 720px) {
  .sheet { margin: 0; border-radius: 0; padding: 1.4rem 1.1rem; }
  .paper { padding: 1.6rem 1.1rem; font-size: .98rem; box-shadow: none; }
  .signbox { padding: 1.5rem 1.1rem 2rem; }
  .g2, .g3 { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .srv-head { display: none; }
  .srv { grid-template-columns: 1.6rem 1fr 1fr; padding: .6rem 0; border-bottom: 1px solid var(--line); }
  .srv > input:nth-child(2) { grid-column: 2 / 4; }
  .srv > input:last-child { grid-column: 1 / 4; }
  .contratto .kv th { width: 45%; }
  .sigline input { font-size: 2.1rem; letter-spacing: .4em; }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }
@media print { .reader-top, .signbox, .intro { display: none; } .paper { box-shadow: none; } body { background: #fff; } }

/* ---------- Pagine pubbliche in linea con cosafareweb.it ---------- */
[hidden] { display: none !important; }
body.public, body.reader { background: #f8f4e8; }
body.public .reader-top, body.reader .reader-top { background: rgba(248,244,232,.94); border-bottom-color: #e6dfcb; }
.brandlink { color: var(--ink); text-decoration: none; font-weight: 700; }
.btn.ghost-light { background: transparent; color: #fff; box-shadow: inset 0 0 0 1.5px rgba(255,255,255,.6); }
.btn.big { padding: .95rem 1.6rem; font-size: 1.05rem; margin-top: .8rem; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.attiva { max-width: 1120px; margin: 0 auto; padding: 2rem 1.25rem 4rem; display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 2.5rem; align-items: start; }
.att-main h1 { font-family: var(--doc); font-weight: 600; font-size: clamp(2rem, 4vw, 2.8rem); letter-spacing: -.02em; }
.lead { color: var(--muted); max-width: 60ch; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .88rem; margin: .2rem 0 .8rem; }
.attiva fieldset { border: 0; border-top: 1.5px solid #e2dac4; margin: 1.6rem 0 0; padding: 1.2rem 0 0; }
.attiva legend { font-weight: 700; font-size: 1.05rem; padding-right: .6rem; }
.attiva input, .attiva select, .attiva textarea { border-color: #ddd4bd; }
.attiva input.bad { border-color: var(--warn); }
.attiva input.good { border-color: var(--ok); }
.famname { font-size: .85rem; color: var(--muted); margin: .9rem 0 .4rem; }
.famname small { margin-left: .4rem; color: var(--pen); }
.pills { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: .6rem; }
.pill { margin: 0; cursor: pointer; }
.pill input { position: absolute; opacity: 0; pointer-events: none; }
.pill span { display: inline-block; padding: .5rem .95rem; border-radius: 999px; background: #fff; box-shadow: inset 0 0 0 1.5px #ddd4bd; font-weight: 500; }
.pill input:checked + span { background: var(--ink); color: #fff; box-shadow: none; }
.pill input:focus-visible + span { outline: 3px solid var(--pen); outline-offset: 2px; }
.g3x { display: grid; grid-template-columns: 7rem 1fr 5rem; gap: 0 1rem; }
.paylist { display: grid; gap: .5rem; }
.pay { display: flex; gap: .7rem; align-items: flex-start; font-weight: 400; background: #fff; padding: .8rem 1rem; border-radius: 8px; box-shadow: inset 0 0 0 1.5px #e6dfcb; margin: 0; cursor: pointer; }
.pay input { margin-top: .25rem; width: auto; display: inline; accent-color: var(--pen); }
.pay:has(input:checked) { box-shadow: inset 0 0 0 2px var(--ink); }
.attiva .decl { border-top-color: #e6dfcb; }
.attiva .alert ul { margin: .4rem 0 0; padding-left: 1.1rem; }

/* Il riepilogo: la cosa che si ricorda */
.att-side { position: sticky; top: 4.5rem; background: var(--ink); color: #f8f4e8; padding: 1.6rem 1.5rem 1.4rem; border-radius: 4px; }
.side-k { margin: 0; font-size: .82rem; color: #b9c0d0; }
.side-name { font-family: var(--doc); font-size: 1.5rem; font-weight: 600; margin: .1rem 0 .3rem; }
.side-claim { color: #cfd5e2; font-size: .92rem; margin: 0 0 1.1rem; }
.side-price { margin: 0; font-family: var(--doc); font-size: 2.6rem; font-weight: 600; line-height: 1; padding-top: 1rem; border-top: 1px solid rgba(248,244,232,.2); }
.side-price small { font-family: var(--ui); font-size: .9rem; font-weight: 400; color: #cfd5e2; }
.side-tot { font-size: .9rem; color: #cfd5e2; margin: .5rem 0 1rem; }
.side-notes { margin: 0; padding: 0; list-style: none; font-size: .88rem; }
.side-notes li { padding: .55rem 0; border-top: 1px solid rgba(248,244,232,.14); }

.contratto ul.incl { padding-left: 1.2rem; margin: .4rem 0 .8rem; }
.contratto ul.incl li { margin-bottom: .2rem; }

@media (max-width: 900px) {
  .attiva { grid-template-columns: 1fr; gap: 1.2rem; }
  .att-side { position: static; order: -1; }
  .side-price { font-size: 2.1rem; }
}
@media (max-width: 520px) { .g3x { grid-template-columns: 6rem 1fr; } .g3x label:last-child { grid-column: span 2; } }

/* ---------- Listino (admin) ---------- */
.headrow { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.lst-fam { display: flex; align-items: baseline; gap: 1rem; margin-top: 1.8rem; border-bottom: 1.5px solid var(--ink); padding-bottom: .3rem; }
.lst-fam h2 { margin: 0; }
.lst-head, .lst-row { display: grid; grid-template-columns: minmax(0, 1.6fr) 1fr 1.25fr 1.25fr 4rem 4.5rem 4.5rem; gap: .7rem; align-items: start; }
.lst-head { font-size: .78rem; color: var(--muted); padding: .6rem 0 .2rem; }
.lst-row { padding: .7rem 0; border-bottom: 1px solid var(--line); }
.lst-row.off { opacity: .55; }
.lst-row label { margin: 0; font-weight: 400; }
.lst-row input { margin: 0; padding: .45rem .55rem; font-variant-numeric: tabular-nums; }
.lst-name strong { display: block; }
.lst-name small { display: block; color: var(--muted); font-size: .8rem; line-height: 1.35; }
.rate-wrap { display: flex; gap: .3rem; }
.calc { flex: none; border: 1.5px solid var(--line); background: #fff; border-radius: 6px; font: 600 .78rem var(--ui); color: var(--pen); padding: 0 .45rem; cursor: pointer; }
.tot { display: block; font-size: .75rem; color: var(--muted); margin-top: .25rem; }
.tot.warn { color: var(--warn); }
.tgl { display: flex; justify-content: center; padding-top: .55rem; }
.ord { max-width: 4.5rem; }
.m-lab { display: none; }
.savebar { position: sticky; bottom: 0; background: linear-gradient(transparent, #fff 35%); padding: 1.4rem 0 .4rem; margin-top: .5rem; }
@media (max-width: 820px) {
  .lst-head { display: none; }
  .lst-row { grid-template-columns: 1fr 1fr; }
  .lst-name { grid-column: 1 / -1; }
  .m-lab { display: block; font-size: .75rem; color: var(--muted); margin-bottom: .2rem; }
  .tgl { justify-content: flex-start; gap: .4rem; align-items: center; }
  .tgl .m-lab { display: inline; margin: 0; }
}

/* Come si firma e dati di chi fornisce il servizio */
.att-firma { margin-top: 1.6rem; padding: 1.2rem 1.3rem; background: #fff; border-radius: 8px; box-shadow: inset 0 0 0 1.5px #e6dfcb; }
.att-firma .side-k { color: var(--muted); margin: 0 0 .5rem; }
.att-firma ol { margin: 0 0 .7rem; padding-left: 1.2rem; }
.att-firma li { margin: .35rem 0; line-height: 1.45; }
.att-firma p.small { margin: 0; font-size: .82rem; }
.att-azienda { max-width: 1180px; margin: 0 auto; padding: 1.6rem 1.25rem 2.4rem; display: flex; flex-wrap: wrap; gap: 1rem 3rem; justify-content: space-between; border-top: 1px solid #e6dfcb; font-size: .86rem; color: var(--muted); }
.att-azienda div { display: flex; flex-direction: column; gap: .2rem; }
.att-azienda strong { color: var(--ink); }
.att-azienda a { color: inherit; }

/* Cancellazione del contratto */
.cancella { margin: 2rem 0 1rem; padding: 1rem 1.1rem; border-radius: 8px; box-shadow: inset 0 0 0 1.5px #f1c9c0; background: #fff8f6; }
.cancella p { margin: 0 0 .6rem; }
.cancella .check { margin: 0 0 .8rem; }

/* Controllo */
.controlli { list-style: none; padding: 0; margin: 1.2rem 0 1.6rem; }
.controlli li { padding: .75rem 0; border-top: 1px solid #e6dfcb; display: flex; flex-direction: column; gap: .25rem; }
.controlli li.ok strong { color: #2f6b3a; }
.controlli li.ko strong { color: var(--warn); }
.controlli li span { font-size: .9rem; color: var(--muted); }
.flash.avviso { background: #fdf0e9; color: #8a3a12; }
.flash.avviso a { color: inherit; }

/* Codice sconto */
.sconto-campo { margin-top: 1rem; }
.sconto-campo input { text-transform: uppercase; letter-spacing: .06em; max-width: 16rem; }
.sconto-esito { margin: .35rem 0 0; font-size: .88rem; min-height: 1.2em; }
.sconto-esito.ok { color: #2f6b3a; }
.sconto-esito.ko { color: var(--warn); }
.side-listino { margin: 0 0 .2rem; font-size: .88rem; color: #cfd5e2; text-decoration: line-through; }
.side-sconto { margin: .5rem 0 0; font-size: .88rem; color: #d7f5a8; }

/* Codici sconto (admin) */
.list.sconti td { vertical-align: top; }
.azioni-sconto { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; min-width: 20rem; }
.azioni-sconto input.mini { width: 100%; font-size: .78rem; padding: .3rem .45rem; }
.sconto-form fieldset { margin: 1rem 0; }
.sconto-form .checks { margin: .3rem 0; }

/* Pagamento dopo la firma */
.paga { margin: 1.6rem auto 0; max-width: 34rem; padding: 1.2rem 1.3rem; background: #fff; border-radius: 10px; box-shadow: inset 0 0 0 1.5px #e6dfcb; text-align: center; }
.paga p { margin: 0 0 .8rem; }
.paga p.small { margin: .8rem 0 0; color: var(--muted); }
.list.pagamenti input { width: 100%; font-size: .85rem; }
.list.pagamenti tr:hover td { background: transparent; cursor: default; }
.linkpag { margin: 1.6rem 0 0; padding: 1rem 1.1rem; border-radius: 8px; box-shadow: inset 0 0 0 1.5px #e6dfcb; }
.linkpag p { margin: .3rem 0 .6rem; }

.paga-billie { margin-top: 12px; }
.paga .btn.ghost { box-shadow: inset 0 0 0 1.5px var(--ink); color: var(--ink); background: transparent; }

/* Gestione: i campi su misura si vedono solo con «Su misura» scelto */
.gestione fieldset:not(:has(input[value="su_misura"]:checked)) .su-misura{display:none}

/* Verifica in due passaggi (24 ott 2026) */
.qr-2fa { text-align: center; margin: 14px 0; }
.qr-2fa img { background: #fff; padding: 10px; border: 1px solid #d5dae6; border-radius: 10px; }
.passi-2fa { margin: 10px 0 0 20px; }
.passi-2fa li { margin-bottom: 4px; }
pre.codici { font: 700 18px/1.7 ui-monospace, Menlo, monospace; letter-spacing: .06em; background: #f4f6fb; border: 1px dashed #9aa3b8; border-radius: 10px; padding: 12px 16px; text-align: center; }
