:root {
  --primary: #1f5eff;
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #182033;
  --muted: #5d6676;
  --border: #e2e5ea;
  --good: #137a3f;
  --good-bg: #e6f4ec;
  --mid: #9a5b00;
  --mid-bg: #fdf2dd;
  --bad: #b42318;
  --bad-bg: #fde8e6;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151c;
    --surface: #1a2029;
    --text: #e8ebf0;
    --muted: #9aa3b2;
    --border: #2c3440;
    --good: #5fd08f;
    --good-bg: #173326;
    --mid: #f2b84b;
    --mid-bg: #3a2c12;
    --bad: #ff8a7f;
    --bad-bg: #3d1b18;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); }
@media (prefers-color-scheme: dark) { a { color: color-mix(in srgb, var(--primary) 55%, white); } }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .6em; }
h1 { font-size: clamp(1.6rem, 3.5vw, 2.3rem); letter-spacing: -.01em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 1em; }
code, .code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .88em; }
pre.code, textarea.code { display: block; width: 100%; padding: 12px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; color: var(--text); }
img { max-width: 100%; height: auto; }

.wrap { width: 100%; max-width: 1080px; margin: 0 auto; padding: 0 16px; }
.narrow { max-width: 620px; margin-left: auto; margin-right: auto; }
.center-block { text-align: center; padding: 48px 0; }
.center-block .left, .left { text-align: left; }
.skip { position: absolute; left: -999px; top: 0; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.lead { font-size: 1.1rem; }
.eyebrow { text-transform: uppercase; letter-spacing: .08em; font-size: .78rem; font-weight: 600; color: var(--primary); margin-bottom: .4em; }

/* Header / footer */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-height: 64px; flex-wrap: wrap; padding-top: 8px; padding-bottom: 8px; }
.brand { display: flex; align-items: center; text-decoration: none; color: var(--text); }
.brand img { max-height: 44px; width: auto; }
.brand-text { font-weight: 700; font-size: 1.15rem; }
.nav { display: flex; gap: 16px; flex-wrap: wrap; align-items: center; }
.nav a, .linklike { color: var(--text); text-decoration: none; font-weight: 500; font-size: .95rem; }
.nav a:hover, .linklike:hover { color: var(--primary); }
.linklike { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; }
main.wrap { padding-top: 28px; padding-bottom: 48px; min-height: 60vh; }
.footer { border-top: 1px solid var(--border); background: var(--surface); font-size: .875rem; color: var(--muted); }
.footer-inner { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding-top: 18px; padding-bottom: 18px; }
.footer a { color: var(--muted); }

/* Components */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 20px; box-shadow: var(--shadow); }
.btn { display: inline-block; background: var(--primary); color: #fff; border: 1px solid var(--primary); border-radius: 8px; padding: 11px 20px; font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; line-height: 1.2; }
.btn:hover { filter: brightness(1.08); }
.btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible, summary:focus-visible, .linklike:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-small { padding: 7px 12px; font-size: .9rem; }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }
.btn-danger { background: transparent; color: var(--bad); border-color: var(--bad); }
.inline { display: inline; }
.inline-form { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.inline-form input, .inline-form select { width: auto; margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; border: 1px solid transparent; text-align: left; }
.alert-ok { background: var(--good-bg); color: var(--good); border-color: color-mix(in srgb, var(--good) 30%, transparent); }
.alert-err { background: var(--bad-bg); color: var(--bad); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
.alert-warn { background: var(--mid-bg); color: var(--mid); border-color: color-mix(in srgb, var(--mid) 30%, transparent); }

/* Forms */
.form label { display: block; font-weight: 500; font-size: .95rem; margin-bottom: 14px; }
.form label small { display: block; font-weight: 400; color: var(--muted); margin-top: 4px; }
input, select, textarea { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
input[type="checkbox"] { display: inline-block; width: 18px; height: 18px; margin: 0 8px 0 0; vertical-align: -3px; accent-color: var(--primary); }
input[type="color"] { height: 44px; padding: 4px; }
input[type="file"] { padding: 8px; }
.form .check { font-weight: 400; display: flex; align-items: flex-start; gap: 2px; }
.form .check input { margin-top: 3px; flex: none; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 16px; }
.hp { position: absolute; left: -9999px; }
.sticky-save { position: sticky; bottom: 0; background: var(--bg); padding: 12px 0; border-top: 1px solid var(--border); z-index: 2; }

/* Home */
.hero { display: grid; grid-template-columns: 1.1fr 1fr; gap: 32px; align-items: start; padding: 16px 0 24px; }
.hero h1 { font-size: clamp(1.9rem, 4.2vw, 2.8rem); }
.checks { list-style: none; padding: 0; margin: 0 0 1em; }
.checks li { padding-left: 28px; position: relative; margin-bottom: 8px; }
.checks li::before { content: "✓"; position: absolute; left: 0; color: var(--good); font-weight: 700; }
.how { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; padding-top: 24px; }
.how div { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.step { display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; margin-bottom: 10px; }
@media (max-width: 820px) { .hero, .how { grid-template-columns: 1fr; } }

.reqs { list-style: none; padding: 0; }
.reqs .ok { color: var(--good); }
.reqs .ko { color: var(--bad); font-weight: 600; }
.steps li { margin-bottom: 10px; }

/* Status */
.spinner { width: 48px; height: 48px; margin: 24px auto; border: 4px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 4s; } }

/* Scores */
.score-good { --c: var(--good); --cbg: var(--good-bg); }
.score-mid { --c: var(--mid); --cbg: var(--mid-bg); }
.score-bad { --c: var(--bad); --cbg: var(--bad-bg); }
.report-head { display: flex; justify-content: space-between; gap: 24px; align-items: center; margin-bottom: 20px; }
.report-head h1 { word-break: break-word; }
.score-ring { flex: none; width: 148px; height: 148px; border-radius: 50%; display: grid; place-items: center; align-content: center; background: radial-gradient(closest-side, var(--surface) 78%, transparent 79% 100%), conic-gradient(var(--c) calc(var(--val) * 1%), var(--border) 0); }
.score-num { font-size: 2.6rem; font-weight: 800; color: var(--c); line-height: 1; }
.score-label { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.chips { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.chips li { font-size: .8rem; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px 10px; color: var(--muted); }
.areas { display: grid; grid-template-columns: repeat(6, 1fr); gap: 12px; margin-bottom: 24px; }
.area-card { display: flex; flex-direction: column; gap: 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-decoration: none; color: var(--text); }
.area-card:hover { border-color: var(--c); }
.area-name { font-weight: 600; font-size: .95rem; }
.area-score { font-size: 1.8rem; font-weight: 800; color: var(--c); line-height: 1; }
.area-score small { font-size: .9rem; color: var(--muted); font-weight: 500; }
.bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--c); }
@media (max-width: 1000px) { .areas { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px) { .areas { grid-template-columns: repeat(2, 1fr); } .report-head { flex-direction: column-reverse; align-items: flex-start; } }
.area-inline { font-size: .9rem; color: var(--c); background: var(--cbg); padding: 2px 8px; border-radius: 999px; vertical-align: middle; margin-left: 6px; }
.pill { display: inline-block; min-width: 36px; text-align: center; padding: 2px 8px; border-radius: 999px; background: var(--cbg); color: var(--c); font-weight: 700; }

.psi-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 700px) { .psi-grid { grid-template-columns: 1fr; } }
.psi-scores { list-style: none; padding: 0; display: flex; gap: 14px; flex-wrap: wrap; }
.psi-scores li { display: flex; flex-direction: column; align-items: center; font-size: .8rem; color: var(--muted); }
.psi-scores span { display: grid; place-items: center; width: 52px; height: 52px; border-radius: 50%; border: 4px solid var(--c); color: var(--c); font-weight: 800; font-size: 1.05rem; margin-bottom: 4px; }
.cwv { list-style: none; padding: 0; display: flex; gap: 10px; flex-wrap: wrap; }
.cwv li { background: var(--cbg); color: var(--c); padding: 6px 12px; border-radius: 8px; }

.area-section { margin: 32px 0; }
.ok-line { color: var(--good); }
.finding { background: var(--surface); border: 1px solid var(--border); border-left: 5px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; }
.finding.sev-alta { border-left-color: var(--bad); }
.finding.sev-media { border-left-color: var(--mid); }
.finding.sev-bassa { border-left-color: var(--muted); }
.finding-head { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.finding h3 { margin: 0 0 .5em; }
.fix { background: var(--bg); padding: 10px 12px; border-radius: 8px; }
.price { float: right; font-weight: 700; white-space: nowrap; margin-left: 12px; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge-alta { background: var(--bad-bg); color: var(--bad); }
.badge-media { background: var(--mid-bg); color: var(--mid); }
.badge-bassa { background: var(--bg); color: var(--muted); border: 1px solid var(--border); }
details summary { cursor: pointer; font-weight: 600; }
.finding details summary { font-size: .9rem; color: var(--muted); }
.items { font-size: .85rem; color: var(--muted); padding-left: 18px; word-break: break-word; max-height: 320px; overflow: auto; }
.manual ul { padding-left: 20px; }
.manual li { margin-bottom: 6px; }
.disclaimer { margin-top: 28px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tfoot td { font-weight: 700; border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table.small td { padding: 6px; word-break: break-word; }
.quote label { display: inline; font-weight: 500; }
.quote .form > label, .quote .grid2 label { display: block; }

/* Admin */
.adminbar { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: center; }
.adminbar .small { word-break: break-all; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; color: var(--muted); text-decoration: none; font-size: .9rem; }
.stat span { display: block; font-size: 1.7rem; font-weight: 800; color: var(--text); }
@media (max-width: 700px) { .stats { grid-template-columns: repeat(2, 1fr); } }
.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.filters input, .filters select { width: auto; flex: 1 1 180px; margin: 0; }
.status { font-size: .8rem; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); white-space: nowrap; }
.status-completato { background: var(--good-bg); color: var(--good); border-color: transparent; }
.status-errore { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.status-in_corso, .status-in_coda { background: var(--mid-bg); color: var(--mid); border-color: transparent; }
.catalog-row { padding: 12px 16px; margin-bottom: 8px; }
.catalog-row summary { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-weight: 500; }
.catalog-row summary .muted { margin-left: auto; }
.catalog-row[open] summary { margin-bottom: 14px; }
.catalog-row.disabled { opacity: .6; }
.uploads { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.upload { border: 1px dashed var(--border); border-radius: 8px; padding: 12px; }
.upload-label { display: block; font-weight: 500; margin-bottom: 8px; }
.upload-preview { max-height: 60px; display: block; margin-bottom: 8px; padding: 6px; background: #fff; border-radius: 6px; }
.upload-preview.on-dark { background: #1d2433; }
.quote-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }

@media print {
  .topbar, .footer, .no-print, .adminbar, .quote form, .skip, .sticky-save { display: none !important; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .card, .finding, .area-card { box-shadow: none; break-inside: avoid; }
  details > *:not(summary) { display: block !important; }
  details summary { list-style: none; }
  a { color: inherit; text-decoration: none; }
  .areas { grid-template-columns: repeat(6, 1fr); }
}

/* Servizi */
.service-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 0; border-bottom: 1px solid var(--border); }
.service-row:last-of-type { border-bottom: 0; }
.service-row h3 { margin: 0 0 4px; }
.service-row p { margin: 0; }
.form label.switch, .switch { position: relative; display: inline-flex; margin: 0; align-items: center; gap: 10px; flex: none; cursor: pointer; font-weight: 600; font-size: .9rem; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; }
.switch > span:last-child { min-width: 9.5em; }
.switch .track { display: inline-block; flex: none; width: 48px; height: 28px; border-radius: 999px; background: var(--border); position: relative; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + .track { background: var(--good); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 3px solid color-mix(in srgb, var(--primary) 45%, transparent); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .5; }
.switch.disabled { cursor: not-allowed; color: var(--muted); }
.interventions-list { padding-left: 20px; }

.area-ref { margin-top: -6px; }
.area-card.na .area-score { color: var(--muted); }

/* Verifica manuale */
.manual-form h3 { margin-top: 22px; }
.mc-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; padding: 12px 0 12px 12px; border-bottom: 1px solid var(--border); border-left: 4px solid var(--border); }
.mc-row.mc-good { border-left-color: var(--good); }
.mc-row.mc-bad { border-left-color: var(--bad); }
.mc-row.mc-na { border-left-color: var(--muted); }
.mc-text details summary { font-size: .85rem; color: var(--muted); font-weight: 500; }
.mc-text details p { margin: 4px 0 0; }
.mc-outcomes { border: 0; margin: 0; padding: 0; display: flex; gap: 4px; flex-wrap: wrap; align-items: flex-start; }
.form .mc-opt { display: inline-flex; align-items: center; gap: 4px; margin: 0; padding: 4px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: .82rem; font-weight: 500; cursor: pointer; white-space: nowrap; }
.mc-opt input { margin: 0; width: 14px; height: 14px; }
.mc-opt:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 10%, transparent); }
.form .mc-note { grid-column: 1 / -1; margin: 0; }
.mc-note input { margin-top: 0; padding: 6px 10px; font-size: .9rem; }
@media (max-width: 760px) { .mc-row { grid-template-columns: 1fr; } }
.manual-progress span { white-space: nowrap; }
.mc-good { color: var(--good); } .mc-bad { color: var(--bad); } .mc-na, .mc-todo { color: var(--muted); }
.mc-summary { list-style: none; padding: 0; display: flex; gap: 12px; flex-wrap: wrap; }
.mc-summary li { background: var(--bg); border-radius: 8px; padding: 8px 14px; font-size: .9rem; }
.mc-summary span { display: block; font-size: 1.5rem; font-weight: 800; }
.mc-tag { font-weight: 600; white-space: nowrap; }
.mc-tag.mc-todo { font-weight: 400; }
.mc-summary + details { margin-bottom: 18px; }
.mc-hint { margin: 4px 0 2px; color: var(--muted); }
.mc-suggested { background: color-mix(in srgb, var(--mid-bg) 55%, transparent); }
.mc-suggested .mc-opt:has(input:checked) { border-style: dashed; }
