
:root{
  --ink:#172235;--navy:#14263d;--blue:#275b8f;--blue2:#eaf2fb;--line:#d9e1ea;
  --muted:#6c7888;--bg:#eef2f6;--white:#fff;--green:#176b43;--greenbg:#e8f6ef;
  --shadow:0 8px 26px rgba(20,38,61,.08);--radius:16px;
}
*{box-sizing:border-box}
html{font-family:Inter,ui-sans-serif,-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;color:var(--ink);background:var(--bg)}
body{margin:0}
button,input,textarea{font:inherit}
button{cursor:pointer}
.topbar{position:sticky;top:0;z-index:30;background:rgba(20,38,61,.96);color:white;display:flex;align-items:center;justify-content:space-between;padding:12px max(16px,calc((100vw - 1180px)/2));box-shadow:0 3px 16px rgba(0,0,0,.16)}
.brand{display:flex;align-items:center;gap:12px}.brand h1{font-size:18px;margin:0}.brand p{font-size:12px;margin:2px 0 0;opacity:.8}
.brandmark{width:46px;height:46px;border-radius:12px;border:2px solid #fff;display:grid;place-items:center;font-weight:800;letter-spacing:-1px}
.top-actions{display:flex;gap:8px}.page{max-width:1180px;margin:22px auto;padding:0 16px 42px}
.status{position:fixed;right:18px;bottom:18px;background:var(--navy);color:#fff;padding:10px 14px;border-radius:999px;box-shadow:var(--shadow);font-size:13px;z-index:50;opacity:0;transform:translateY(8px);transition:.2s}
.status.show{opacity:1;transform:none}.status.error{background:#8b2030}
.card{background:var(--white);border:1px solid var(--line);border-radius:var(--radius);box-shadow:var(--shadow);padding:20px;margin:0 0 16px}
.section-title{display:flex;align-items:center;gap:10px;border-bottom:1px solid var(--line);padding-bottom:12px;margin-bottom:18px}
.section-title span{width:30px;height:30px;border-radius:50%;display:grid;place-items:center;background:var(--blue);color:#fff;font-weight:800}
.section-title h2{font-size:18px;margin:0;color:var(--navy)}
h3{font-size:14px;margin:18px 0 10px;color:var(--navy)}
.grid{display:grid;gap:12px;margin-bottom:12px}.cols-2{grid-template-columns:repeat(2,minmax(0,1fr))}.cols-3{grid-template-columns:repeat(3,minmax(0,1fr))}.cols-4{grid-template-columns:repeat(4,minmax(0,1fr))}
.span2{grid-column:span 2}
label{display:flex;flex-direction:column;gap:6px;font-size:12px;font-weight:700;color:#4a5868}
input,textarea{width:100%;border:1px solid #cbd5df;border-radius:10px;padding:11px 12px;background:#fff;color:var(--ink);outline:none;transition:.15s}
input:focus,textarea:focus{border-color:var(--blue);box-shadow:0 0 0 3px rgba(39,91,143,.12)}
textarea{resize:vertical;min-height:80px}
.btn{border:0;border-radius:10px;padding:10px 14px;font-weight:750}
.btn.primary{background:#3379bd;color:#fff}.btn.secondary{background:var(--blue2);color:var(--blue)}.btn.ghost{background:rgba(255,255,255,.12);color:inherit;border:1px solid rgba(255,255,255,.2)}
.card .btn.ghost{background:#fff;color:var(--navy);border:1px solid var(--line)}
.chips{display:flex;gap:8px;flex-wrap:wrap}.chips label,.inline-check{display:flex;flex-direction:row;align-items:center;background:#f7f9fb;border:1px solid var(--line);border-radius:10px;padding:9px 12px}.chips input,.inline-check input,.preventivo input{width:auto}
.lookup-box{display:grid;grid-template-columns:1fr 1.25fr;gap:14px;background:#f3f7fb;border:1px solid #cfe0f0;border-radius:14px;padding:14px;margin-bottom:14px}
.lookup-field{position:relative}.lookup-row{display:grid;grid-template-columns:1fr auto;gap:8px}.lookup-field small{display:block;margin-top:6px;color:var(--muted)}
.suggestions{position:absolute;left:0;right:0;top:100%;z-index:20;background:#fff;border-radius:12px;box-shadow:0 10px 28px rgba(0,0,0,.14);overflow:hidden;margin-top:5px}
.suggestion{padding:10px 12px;border-bottom:1px solid var(--line);cursor:pointer}.suggestion:hover{background:var(--blue2)}.suggestion b{display:block;color:var(--navy)}.suggestion small{margin:2px 0 0}
.client-found{background:var(--greenbg);color:var(--green);padding:11px 13px;border-radius:10px;margin-bottom:14px;display:flex;gap:8px;align-items:center}.hidden{display:none!important}
.instrument{background:#f8fafc;border:1px solid var(--line);border-radius:12px;padding:12px;margin-bottom:10px}.instrument-top{display:flex;justify-content:space-between;align-items:center;margin-bottom:10px}.instrument-top b{color:var(--navy)}.icon-btn{border:1px solid var(--line);background:white;border-radius:9px;padding:7px 10px}
.preventivo{display:flex;flex-direction:row;align-items:flex-start;gap:10px;background:#fff7e7;border:1px solid #ead19c;border-radius:12px;padding:13px;margin-bottom:14px}.preventivo span{display:flex;flex-direction:column;gap:2px}.preventivo small{font-weight:500;color:#78653d}
.cost-table{border:1px solid var(--line);border-radius:12px;overflow:hidden}.cost-head,.cost-row{display:grid;grid-template-columns:2fr .6fr .7fr .8fr;gap:8px;align-items:center;padding:10px 12px}.cost-head{background:var(--navy);color:#fff;font-size:12px;font-weight:800}.cost-row{border-top:1px solid var(--line)}.cost-row:first-of-type{border-top:0}.cost-row input{padding:8px}.cost-row output{text-align:right;font-weight:800}.cost-row small{display:block;color:var(--muted)}
.ricambio{display:grid;grid-template-columns:.8fr 2fr .55fr .65fr .75fr auto;gap:8px;align-items:center;margin-bottom:8px}.ricambio output{text-align:right;font-weight:750}.grand-total{margin-top:14px;background:var(--navy);color:#fff;border-radius:12px;padding:15px 16px;display:flex;justify-content:space-between;align-items:center}.grand-total strong{font-size:21px}
.signature-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:14px}.signature-box{border:1px solid var(--line);border-radius:14px;padding:12px;min-height:260px;display:flex;flex-direction:column;gap:8px}.signature-box h3{margin:0 0 3px}.stamp-preview{height:150px;border:1px dashed #aab7c4;border-radius:10px;display:grid;place-items:center;overflow:hidden;background:#fafbfc;color:var(--muted)}.stamp-preview img{width:100%;height:100%;object-fit:contain}.file-btn{display:block;text-align:center}.file-btn input{display:none}
.signature-canvas{width:100%;height:150px;border:1px dashed #aab7c4;border-radius:10px;background:white;touch-action:none}
.sheet-footer{text-align:center;color:var(--muted);font-size:11px;padding:8px}
@media(max-width:800px){
  .topbar{position:static;align-items:flex-start;gap:10px}.top-actions{flex-wrap:wrap;justify-content:flex-end}.page{margin-top:12px;padding:0 10px 30px}.card{padding:14px;border-radius:14px}
  .cols-4,.cols-3,.cols-2,.lookup-box,.signature-grid{grid-template-columns:1fr}.span2{grid-column:auto}
  .cost-head{display:none}.cost-row{grid-template-columns:1fr 1fr}.cost-row span{grid-column:1/-1;font-weight:750}.cost-row output{text-align:left}
  .ricambio{grid-template-columns:1fr 1fr}.ricambio .desc{grid-column:1/-1}.ricambio output{grid-column:1/2;text-align:left}
  .brand p{display:none}.btn{padding:9px 10px}.lookup-row{grid-template-columns:1fr auto}
}
@media(max-width:470px){
  .topbar{display:block}.top-actions{margin-top:10px;display:grid;grid-template-columns:1fr 1fr 1fr}.top-actions .btn{font-size:12px}
}
@media print{
  @page{size:A4;margin:8mm}
  html,body{background:#fff}.topbar{position:static;background:#fff;color:#111;box-shadow:none;padding:0 0 6mm}.brandmark{color:#111;border-color:#111}.page{max-width:none;margin:0;padding:0}
  .no-print,.btn{display:none!important}.card{box-shadow:none;border:1px solid #aeb7c1;border-radius:7px;padding:10px;margin-bottom:7px;break-inside:avoid}
  .section-title{padding-bottom:5px;margin-bottom:8px}.section-title span{width:23px;height:23px;font-size:11px}.section-title h2{font-size:13px}
  label{font-size:9px;gap:2px}input,textarea{padding:5px 6px;border-radius:4px;font-size:10px;min-height:0}textarea{height:auto}
  .grid{gap:6px;margin-bottom:6px}.chips label{padding:4px 6px;font-size:9px}.cost-head,.cost-row{padding:5px 6px;font-size:9px}.grand-total{padding:7px 9px}.grand-total strong{font-size:14px}
  .signature-box{min-height:145px;padding:6px}.signature-canvas,.stamp-preview{height:85px}.signature-grid{gap:7px}.sheet-footer{font-size:8px}
}

/* Logo aziendale nella web app */
.screen-logo{width:132px;height:auto;display:block;filter:brightness(0) invert(1)}
.brand-copy h1{font-size:16px}.brand-copy p{font-size:11px}

/* Il documento PDF usa un layout separato, progettato per una singola A4. */
.print-sheet{display:none}

@media print{
  @page{size:A4 portrait;margin:5mm}
  html,body{width:auto!important;min-width:0!important;margin:0!important;padding:0!important;background:#fff!important;-webkit-print-color-adjust:exact!important;print-color-adjust:exact!important}
  body>*:not(.print-sheet){display:none!important}
  .print-sheet{display:block!important;width:100%!important;max-width:none!important;margin:0!important;padding:0!important;box-sizing:border-box;color:#172235;background:#fff;font-family:Arial,Helvetica,sans-serif;font-size:7.45pt;line-height:1.14}
  .print-sheet *{box-sizing:border-box}
  .print-sheet .pdf-content{display:block}
  .print-sheet .pdf-bottom{margin-top:1.2mm}
  .print-sheet .signatures-section{margin-top:1.4mm}
  .print-sheet .pdf-header{display:grid;grid-template-columns:48mm 1fr 45mm;align-items:center;gap:3.2mm;border-bottom:2.2px solid #0a8e86;padding:0 0 2.4mm;margin-bottom:1.8mm}
  .print-sheet .pdf-logo{width:42mm;max-height:15mm;object-fit:contain;object-position:left center}
  .print-sheet .pdf-company{font-size:6.9pt;line-height:1.24;color:#4d5b67}
  .print-sheet .pdf-company strong{display:block;color:#07588f;font-size:9pt;margin-bottom:.5mm}
  .print-sheet .pdf-doc-title{text-align:right}
  .print-sheet .pdf-doc-title .kicker{color:#0a8e86;font-size:6.2pt;font-weight:800;letter-spacing:.55px;text-transform:uppercase}
  .print-sheet .pdf-doc-title h1{font-size:13.1pt;line-height:1.01;margin:.8mm 0 0;color:#173c5a;letter-spacing:-.2px}

  .print-sheet .pdf-section{border:1px solid #bfcbd5;border-radius:2mm;overflow:hidden;margin-bottom:1.5mm;break-inside:avoid;background:#fff}
  .print-sheet .pdf-section-title{display:flex;align-items:center;gap:1.6mm;background:#edf7f6;border-bottom:1px solid #c9dddb;padding:1.05mm 1.8mm;font-size:7pt;color:#07588f;font-weight:800;text-transform:uppercase;letter-spacing:.22px}
  .print-sheet .pdf-section-title .num{display:inline-grid;place-items:center;width:4.6mm;height:4.6mm;border-radius:50%;background:#0a8e86;color:#fff;font-size:6.3pt}
  .print-sheet .pdf-body{padding:1.35mm 1.8mm}
  .print-sheet .pdf-grid{display:grid;gap:1.1mm 1.8mm}
  .print-sheet .g2{grid-template-columns:repeat(2,minmax(0,1fr))}
  .print-sheet .g3{grid-template-columns:repeat(3,minmax(0,1fr))}
  .print-sheet .g4{grid-template-columns:repeat(4,minmax(0,1fr))}
  .print-sheet .g5{grid-template-columns:repeat(5,minmax(0,1fr))}
  .print-sheet .wide2{grid-column:span 2}
  .print-sheet .field{min-width:0}
  .print-sheet .field-label{display:block;color:#6a7782;font-size:5.45pt;font-weight:700;text-transform:uppercase;letter-spacing:.16px;margin-bottom:.25mm}
  .print-sheet .field-value{font-size:7.15pt;font-weight:700;color:#172235;border-bottom:.35px solid #d9e1e7;min-height:3.2mm;padding:.2mm 0;overflow-wrap:anywhere}
  .print-sheet .field-value.normal{font-weight:500}
  .print-sheet .flags{display:flex;flex-wrap:wrap;gap:1.1mm 2.4mm;margin-top:1mm;padding-top:.9mm;border-top:.35px solid #e1e7ec;font-size:6.35pt}
  .print-sheet .flag b{color:#0a8e86;margin-right:.6mm}
  .print-sheet .main-columns{display:grid;grid-template-columns:1fr 1.05fr;gap:1.6mm;align-items:start}
  .print-sheet .stack>.pdf-section:last-child{margin-bottom:0}

  .print-sheet table{border-collapse:collapse;width:100%;table-layout:fixed}
  .print-sheet th{background:#173c5a;color:#fff;font-size:5.8pt;text-transform:uppercase;letter-spacing:.12px;padding:.85mm 1mm;text-align:left}
  .print-sheet td{font-size:6.35pt;padding:.8mm 1mm;border-bottom:.35px solid #dce3e8;vertical-align:top;overflow-wrap:anywhere}
  .print-sheet tr:last-child td{border-bottom:0}
  .print-sheet .instrument-card{border:.45px solid #d4dde4;border-radius:1.2mm;padding:1mm 1.3mm;margin-bottom:1mm;background:#fbfcfd}
  .print-sheet .instrument-card:last-child{margin-bottom:0}
  .print-sheet .instrument-name{font-weight:800;color:#07588f;font-size:6.25pt;margin-bottom:.6mm}
  .print-sheet .text-box{white-space:pre-wrap;border:.45px solid #d5dee5;border-radius:1.2mm;padding:1mm 1.25mm;min-height:7.6mm;font-size:6.45pt;line-height:1.16;background:#fcfdfe}
  .print-sheet .text-box.small{min-height:4.8mm}
  .print-sheet .mini-line{display:flex;justify-content:space-between;gap:2.4mm;margin-top:1mm;font-size:6.15pt}
  .print-sheet .mini-line strong{color:#07588f}

  .print-sheet .cost-total{display:flex;justify-content:space-between;align-items:center;background:#173c5a;color:#fff;padding:1.15mm 1.7mm;font-size:7pt;font-weight:800;margin-top:1mm;border-radius:1.25mm}
  .print-sheet .cost-total b{font-size:8.6pt}
  .print-sheet .preventivo-box{border:1px solid #d7b96b;background:#fff9eb;color:#6b571e;border-radius:1.3mm;padding:1.1mm 1.4mm;font-weight:800;font-size:6.7pt}
  .print-sheet .payment-note{font-size:5.1pt;line-height:1.12;color:#53616d;border-top:.35px solid #dce3e8;margin-top:.9mm;padding-top:.8mm}

  .print-sheet .signatures{display:grid;grid-template-columns:1.22fr .89fr .89fr;gap:1.5mm;align-items:stretch}
  .print-sheet .signature{border:.6px solid #bfcbd5;border-radius:1.5mm;padding:1.2mm;min-height:26mm;position:relative;background:#fff}
  .print-sheet .signature h3{font-size:6.4pt;color:#07588f;margin:0 0 .7mm;text-transform:uppercase}
  .print-sheet .sign-img{width:100%;height:14.5mm;object-fit:contain;display:block}
  .print-sheet .sign-empty{height:14.5mm;border-bottom:.4px solid #cbd5dc}
  .print-sheet .sign-meta{font-size:5.35pt;color:#687681;margin-top:.55mm;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
  .print-sheet .pdf-footer{display:flex;justify-content:space-between;gap:4mm;color:#677581;font-size:5.1pt;border-top:.5px solid #cfd9df;padding-top:.9mm;margin-top:.9mm}

  .print-sheet .signature.stamp-box{min-height:28mm}
  .print-sheet .signature.stamp-box .sign-img,.print-sheet .signature.stamp-box .sign-empty{height:20mm}
  .print-sheet .signature.stamp-box .sign-meta{font-size:5.2pt}

  /* Espansione controllata quando la scheda è corta, per usare meglio la pagina. */
  .print-sheet.roomy{font-size:8.05pt;line-height:1.24}
  .print-sheet.roomy .pdf-header{padding-bottom:3.3mm;margin-bottom:2.9mm}
  .print-sheet.roomy .pdf-logo{width:48mm;max-height:18mm}
  .print-sheet.roomy .pdf-company{font-size:7.45pt}
  .print-sheet.roomy .pdf-company strong{font-size:9.5pt}
  .print-sheet.roomy .pdf-doc-title .kicker{font-size:6.9pt}
  .print-sheet.roomy .pdf-doc-title h1{font-size:15.2pt}
  .print-sheet.roomy .pdf-section{margin-bottom:2.4mm}
  .print-sheet.roomy .pdf-section-title{padding:1.55mm 2.2mm;font-size:7.8pt}
  .print-sheet.roomy .pdf-body{padding:2mm 2.2mm}
  .print-sheet.roomy .field-label{font-size:6pt;margin-bottom:.45mm}
  .print-sheet.roomy .field-value{font-size:7.95pt;min-height:4.3mm;padding:.45mm 0}
  .print-sheet.roomy .flags{font-size:7pt;gap:1.8mm 3.3mm;margin-top:1.6mm;padding-top:1.4mm}
  .print-sheet.roomy .instrument-card{padding:1.4mm 1.7mm;margin-bottom:1.5mm}
  .print-sheet.roomy .instrument-name{font-size:6.9pt;margin-bottom:1mm}
  .print-sheet.roomy .text-box{min-height:11mm;font-size:7.05pt;padding:1.45mm 1.7mm;line-height:1.26}
  .print-sheet.roomy .text-box.small{min-height:6.8mm}
  .print-sheet.roomy .mini-line{margin-top:1.45mm;font-size:6.7pt}
  .print-sheet.roomy th{font-size:6.15pt;padding:1.1mm 1.25mm}
  .print-sheet.roomy td{font-size:6.95pt;padding:1.1mm 1.25mm}
  .print-sheet.roomy .cost-total{padding:1.7mm 2.1mm;font-size:7.7pt;margin-top:1.4mm}
  .print-sheet.roomy .cost-total b{font-size:9.8pt}
  .print-sheet.roomy .payment-note{font-size:5.7pt;margin-top:1.25mm;padding-top:1.1mm}
  .print-sheet.roomy .signature{min-height:36mm;padding:1.8mm}
  .print-sheet.roomy .signature h3{font-size:6.9pt}
  .print-sheet.roomy .sign-img,.print-sheet.roomy .sign-empty{height:21mm}
  .print-sheet.roomy .sign-meta{font-size:5.9pt;margin-top:1mm}
  .print-sheet.roomy .pdf-footer{font-size:5.6pt;padding-top:1.3mm;margin-top:1.3mm}

  /* Riduzione progressiva automatica se una scheda contiene molto testo / più righe. */
  .print-sheet.dense{font-size:7.1pt;line-height:1.12}
  .print-sheet.dense .pdf-section{margin-bottom:1.6mm}.print-sheet.dense .pdf-body{padding:1.35mm 1.7mm}.print-sheet.dense .pdf-section-title{padding:1mm 1.7mm}
  .print-sheet.dense td{padding:.7mm .95mm}.print-sheet.dense .text-box{min-height:6.3mm;padding:.9mm 1.1mm}.print-sheet.dense .signature{min-height:23mm}.print-sheet.dense .sign-img,.print-sheet.dense .sign-empty{height:12mm}.print-sheet.dense .signature.stamp-box{min-height:25mm}.print-sheet.dense .signature.stamp-box .sign-img,.print-sheet.dense .signature.stamp-box .sign-empty{height:17mm}
  .print-sheet.very-dense{font-size:6.55pt;line-height:1.08}
  .print-sheet.very-dense .pdf-header{margin-bottom:1.5mm;padding-bottom:2mm}.print-sheet.very-dense .pdf-logo{width:39mm;max-height:14mm}.print-sheet.very-dense .pdf-doc-title h1{font-size:12.4pt}
  .print-sheet.very-dense .pdf-section{margin-bottom:1.25mm}.print-sheet.very-dense .pdf-section-title{padding:.75mm 1.5mm}.print-sheet.very-dense .pdf-body{padding:1mm 1.5mm}
  .print-sheet.very-dense td{font-size:5.9pt;padding:.5mm .75mm}.print-sheet.very-dense th{font-size:5.35pt;padding:.55mm .75mm}.print-sheet.very-dense .field-value{font-size:6.45pt;min-height:2.85mm}.print-sheet.very-dense .field-label{font-size:5pt}.print-sheet.very-dense .text-box{font-size:5.95pt;min-height:5mm}.print-sheet.very-dense .signature{min-height:20mm}.print-sheet.very-dense .sign-img,.print-sheet.very-dense .sign-empty{height:10mm}.print-sheet.very-dense .signature.stamp-box{min-height:22mm}.print-sheet.very-dense .signature.stamp-box .sign-img,.print-sheet.very-dense .signature.stamp-box .sign-empty{height:14.5mm}
  .print-sheet.ultra-dense{font-size:5.8pt;line-height:1.02;zoom:.92}
  .print-sheet.ultra-dense .pdf-section{margin-bottom:.8mm}.print-sheet.ultra-dense .payment-note{font-size:4.7pt}.print-sheet.ultra-dense .signature{min-height:18mm}.print-sheet.ultra-dense .sign-img,.print-sheet.ultra-dense .sign-empty{height:9mm}.print-sheet.ultra-dense .signature.stamp-box{min-height:20mm}.print-sheet.ultra-dense .signature.stamp-box .sign-img,.print-sheet.ultra-dense .signature.stamp-box .sign-empty{height:12.5mm}
}
@media print{
  .print-sheet .flag{display:inline-flex;align-items:center;gap:.8mm;white-space:nowrap}
  .print-sheet .flag-mark{width:2.7mm;height:2.7mm;border:.5px solid #9aa8b4;border-radius:.6mm;display:inline-block;background:#fff;position:relative}
  .print-sheet .flag-mark.on{border-color:#0a8e86;background:#0a8e86}
  .print-sheet .flag-mark.on:after{content:"";position:absolute;left:.75mm;top:.25mm;width:.7mm;height:1.35mm;border:solid #fff;border-width:0 .45mm .45mm 0;transform:rotate(45deg)}
}
@media print{
  .print-sheet .signature:not(:first-child) .sign-img{border-bottom:.4px solid #cbd5dc}
}

/* Esito problema */
.problem-status-grid .inline-check{height:100%;justify-content:flex-start}
@media(max-width:800px){.problem-status-grid{grid-template-columns:1fr}}
@media print{
  .print-sheet .problem-outcome{justify-content:flex-start}
  .print-sheet .problem-outcome strong{color:#07588f}
}
