/* CRM Cerabino — fogli comuni. Font e palette stanno in theme-<istanza>.css, caricato subito dopo questo
   (views/partials/head.ejs, auth-head.ejs, questionario.ejs): qui si usano solo le variabili. */

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 16px/1.5 var(--font); color: var(--text); background: var(--bg-alt); }
a { color: var(--viola); }
a:hover { color: var(--viola-900); }
h1, h2, h3 { color: var(--ink); line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: 1.75rem; font-weight: 600; }
h2 { font-size: 1.2rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 1em; }

/* ---------- barra */
.top { background: var(--viola-900); color: #fff; }
.top__in { max-width: 1200px; margin: 0 auto; padding: 0 16px; display: flex; align-items: center; gap: 24px; min-height: 60px; flex-wrap: wrap; }
.brand { color: #fff; text-decoration: none; font-weight: 600; letter-spacing: .01em; display: flex; align-items: center; gap: 10px; }
.brand::before { content: ''; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { color: #e9e5f5; text-decoration: none; padding: 8px 12px; border-radius: var(--radius); font-size: .95rem; }
.nav a:hover { background: var(--viola-700); color: #fff; }
.nav a[aria-current="page"] { background: var(--viola); color: #fff; box-shadow: inset 0 -3px 0 var(--accent); }
.top form { margin: 0; }
.linkbtn { background: none; border: 0; color: #e9e5f5; font: inherit; cursor: pointer; padding: 8px 0; text-decoration: underline; }
.linkbtn:hover { color: #fff; }

/* ---------- pagina */
.page { max-width: 1200px; margin: 0 auto; padding: 28px 16px 64px; }
.page__head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page__head h1 { margin: 0; }
.sub { color: var(--muted); font-size: .95rem; margin-top: 4px; }
.grid { display: grid; gap: 20px; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 20px; }
.grid .card + .card { margin-top: 0; }

.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 20px; }
.stat { background: var(--bg); border: 1px solid var(--line); border-left: 4px solid var(--viola); border-radius: var(--radius); padding: 14px 16px; text-decoration: none; color: inherit; }
.stat:hover { border-color: var(--viola-500); }
.stat__n { display: block; font-size: 1.8rem; font-weight: 600; color: var(--ink); line-height: 1.1; }
.stat__l { font-size: .9rem; color: var(--muted); }
.stat--accent { border-left-color: var(--accent); }

/* ---------- tabelle */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { font-weight: 500; color: var(--muted); font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; border-bottom-color: var(--line); white-space: nowrap; }
tr:hover td { background: var(--bg-alt); }
.empty { color: var(--muted); padding: 16px 0; margin: 0; }

/* ---------- etichette */
.tag { display: inline-block; font-size: .8rem; font-weight: 500; padding: 2px 8px; border-radius: 999px; background: var(--bg-tint); color: var(--viola-700); white-space: nowrap; }
.tag--alta, .tag--late { background: var(--bad-soft); color: var(--bad); }
.tag--media, .tag--sospeso, .tag--in_pausa { background: var(--warn-soft); color: var(--warn); }
.tag--bassa, .tag--attivo, .tag--fatta { background: var(--ok-soft); color: var(--ok); }
.tag--onboarding, .tag--in_corso { background: var(--accent-soft); color: var(--accent-ink); }
.tag--saltata, .tag--concluso { background: var(--line-soft); color: var(--muted); }

/* ---------- form */
form.stack { display: grid; gap: 14px; }
.row { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
label { display: grid; gap: 6px; font-size: .9rem; font-weight: 500; color: var(--ink); }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
input, select, textarea { font: inherit; color: var(--ink); background: #fff; border: 1px solid #cfc8de; border-radius: var(--radius); padding: 9px 11px; min-height: 44px; width: 100%; }
.check input { width: auto; min-height: 0; }
textarea { min-height: 90px; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.hint { font-size: .85rem; color: var(--muted); font-weight: 400; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 0; }
legend { padding: 0 6px; font-weight: 500; color: var(--ink); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: 500 .95rem/1 var(--font); padding: 11px 18px; min-height: 44px; border-radius: var(--radius); border: 1px solid var(--viola); background: var(--viola); color: #fff; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--viola-700); color: #fff; }
.btn--ghost { background: #fff; color: var(--viola); }
.btn--ghost:hover { background: var(--bg-tint); color: var(--viola-900); }
.btn--sm { padding: 7px 12px; min-height: 44px; font-size: .88rem; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.inline { display: inline; margin: 0; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: flex-end; }
.inline-form label { min-width: 150px; }

.flash { background: var(--ok-soft); color: var(--ok); border: 1px solid #b7dfc9; padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; }
.error { background: var(--bad-soft); color: var(--bad); border: 1px solid #efc0c0; padding: 12px 16px; border-radius: var(--radius); }

/* ---------- fasi */
.phases { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.phases li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 10px; border: 1px solid var(--line-soft); border-radius: var(--radius); flex-wrap: wrap; }
.phases .n { font-weight: 600; color: var(--viola); margin-right: 6px; }
.phases select { width: auto; min-height: 44px; padding: 4px 8px; font-size: .88rem; }

.timeline { list-style: none; margin: 0; padding: 0; font-size: .92rem; }
.timeline li { padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.timeline time { color: var(--muted); font-size: .85rem; margin-right: 8px; }

/* ---------- accesso */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: var(--viola-900); }
.auth .card { width: 100%; max-width: 420px; padding: 28px; }
.auth__brand { color: var(--viola); font-weight: 600; margin-bottom: 18px; }
.qr { display: block; width: 200px; height: 200px; margin: 0 auto 12px; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: .9rem; word-break: break-all; background: var(--bg-alt); padding: 8px; border-radius: var(--radius); }

@media (max-width: 640px) {
  h1 { font-size: 1.45rem; }
  .top__in { gap: 8px; padding-top: 8px; padding-bottom: 8px; }
  .nav { order: 3; width: 100%; }
  .card { padding: 16px; }
}

.sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* ---------- riassunto IA */
.facts { margin: 0 0 1em; padding-left: 1.4em; display: grid; gap: 12px; }
.facts li { padding-left: 4px; }
.quote { margin: 6px 0 0; padding: 6px 10px; border-left: 3px solid var(--viola-500); background: var(--bg-alt); color: var(--muted); font-size: .9rem; }

/* ---------- lotto 3b: incarico, kit, note, questionario */
.btn--danger { background: var(--bad); border-color: var(--bad); }
.btn--danger:hover { background: #7e1818; }
details.confirm { display: inline-block; }
details.confirm > summary { cursor: pointer; color: var(--muted); font-size: .88rem; text-decoration: underline; padding: 4px 0; }
details.confirm[open] > summary { margin-bottom: 6px; }
.warn { background: var(--warn-soft); color: var(--warn); border: 1px solid #f0cfa6; padding: 10px 14px; border-radius: var(--radius); margin: 0; }
.kit-text { min-height: 320px; font-size: .95rem; line-height: 1.5; }
.inline-label { display: flex; align-items: center; gap: 8px; }
.inline-label select { width: auto; }
.inline-form .grow { flex: 1 1 260px; }
.select--sm { width: auto; min-height: 44px; padding: 4px 8px; font-size: .88rem; }
.stats--compact { margin-bottom: 8px; }
.notes .note-body { white-space: pre-wrap; margin: 6px 0; color: var(--ink); }
.answers { margin: 0 0 1.2em; display: grid; gap: 4px; }
.answers dt { font-weight: 500; color: var(--ink); margin-top: 10px; }
.answers dd { margin: 0; white-space: pre-wrap; }
details > summary { cursor: pointer; }
.page--narrow { max-width: 760px; }
.public .brand { cursor: default; }
.qn { color: var(--viola); font-weight: 600; }
.public__foot { margin: 24px 0 0; padding-top: 14px; border-top: 1px solid var(--line-soft); }

/* ---------- TD-Gate L2 (13/10): bersagli da 44px e niente scroll orizzontale a 360px */
.brand { min-height: 44px; }
.nav a { display: inline-flex; align-items: center; min-height: 44px; }
.linkbtn { min-height: 44px; min-width: 44px; padding: 8px 6px; }
.check { min-height: 44px; position: relative; padding-left: 34px; cursor: pointer; }
/* casella vera trasparente da 44x44 sopra quella disegnata: il bersaglio è grande, l'aspetto resta 20px */
.check input { position: absolute; left: -12px; top: 50%; width: 44px; height: 44px; margin: -22px 0 0; opacity: 0; cursor: pointer; }
.check::before { content: ''; position: absolute; left: 0; top: 50%; width: 20px; height: 20px; margin-top: -10px; border: 2px solid var(--viola-500); border-radius: 3px; background: #fff; box-sizing: border-box; }
.check:has(input:checked)::before { background: var(--viola) center / 14px no-repeat url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M3 8.5l3 3 7-7' fill='none' stroke='%23fff' stroke-width='2.2'/%3E%3C/svg%3E"); border-color: var(--viola); }
.check:has(input:focus-visible)::before { outline: 3px solid var(--accent); outline-offset: 1px; }
.grid > * { min-width: 0; }
.table-wrap { max-width: 100%; position: relative; }   /* contiene anche i .sr assoluti delle intestazioni */
/* mirror L3 (13/10): un <details> non si attacca al blocco che segue */
details + h3, details + h2, details + .actions, .actions + h3 { margin-top: 16px; }
.mono { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; }

/* ---------- F2 lotto C: checklist documentale (sezioni in <details>, niente JS) */
details.cl-sec { border-top: 1px solid var(--line-soft); }
details.cl-sec > summary { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 8px; min-height: 44px; padding: 6px 0; font-weight: 500; color: var(--ink); }
.cl-sec__name { flex: 1 1 200px; min-width: 0; }
.cl-list { list-style: none; margin: 0; padding: 0; }
.cl-item { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.cl-item__label { flex: 1 1 260px; min-width: 0; overflow-wrap: anywhere; }
.cl-item__ctl { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.cl-item__date input { width: auto; min-width: 0; }
.cl-actions { margin: 10px 0 14px; }
details.cl-add { margin-top: 16px; }
details.cl-add > summary { min-height: 44px; display: flex; align-items: center; color: var(--viola); font-weight: 500; }
/* mirror L3 (30/10): display:flex toglie il marker nativo; senza freccia la sezione sembra testo statico */
details.cl-sec > summary::-webkit-details-marker, details.cl-add > summary::-webkit-details-marker { display: none; }
details.cl-sec > summary::before, details.cl-add > summary::before { content: "\25B8"; flex: 0 0 auto; width: 1em; color: var(--muted); }
details.cl-sec[open] > summary::before, details.cl-add[open] > summary::before { content: "\25BE"; }
/* «Oggi» per cliente (lotto D, mirror L3 30/10): colonne allineate tra i card, nome cliente meno pesante di «Da richiamare» */
.oggi-cliente table { table-layout: fixed; }
.oggi-cliente th:nth-child(1), .oggi-cliente td:nth-child(1) { width: 9rem; }
.oggi-cliente th:nth-child(3), .oggi-cliente td:nth-child(3) { width: 6rem; text-align: right; }
.oggi-cliente h2 a { text-decoration: none; }
.oggi-cliente h2 a:hover, .oggi-cliente h2 a:focus-visible { text-decoration: underline; }
.oggi-cliente .sub:last-child { margin-bottom: 0; }
@media (max-width: 480px) {
  .oggi-cliente th:nth-child(1), .oggi-cliente td:nth-child(1) { width: 5.5rem; white-space: normal; }
  #richiamare th:nth-child(3), #richiamare td:nth-child(3) { display: none; }
}
/* F2 lotto F1: lettera d'incarico in firma (card sull'opportunità, pagina /firma/:id, avvisi in «Oggi») */
.lettera { border-top: 1px solid var(--line-soft); margin: 12px 0 16px; padding-top: 4px; }
.lettera > h3 { margin-top: 12px; }
.lettera .warn, .lettera details { margin-top: 8px; }
.page > .error, .page > .flash { margin-bottom: 16px; }
p.mono, .hint.mono { overflow-wrap: anywhere; }
input.copy { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; margin: 6px 0 12px; }
/* mirror L3 F1: respiro tra pulsanti e blocco successivo */
#stato form + h3, #stato form.inline + .warn { margin-top: 20px; }
#stato .warn + p, .lettera .warn + details { margin-top: 12px; }
/* F2: pagina pubblica di firma /f/:token */
.firma-pub h2 { margin-top: 28px; }
.firma-pub .flash, .firma-pub .error { margin: 0 0 16px; }
.firma-pub .consent { font-size: .95rem; }
.firma-pub form + .hint { margin-top: 12px; }
/* mirror L3 F2: il link dei documenti in «Oggi» è il tocco principale da telefono */
.oggi-cliente p.sub a { display: inline-block; padding: 12px 0; }
