/* ==========================================================================
   1. RESET E VARIABILI
   ========================================================================== */
:root { 
    --primary: #0066CC; 
    --bg: #f4f7f6; 
    --border: #ddd;
}

body { 
    margin: 0; 
    font-family: 'Inter', sans-serif; 
    background: var(--bg); 
    overflow: hidden; 
}

/* ==========================================================================
   2. LAYOUT APP
   ========================================================================== */
#app-interface { 
    max-width: 600px; margin: 0 auto; background: white; 
    height: 100vh; height: 100dvh; 
    display: flex; flex-direction: column; 
    position: relative;
    box-shadow: 0 0 15px rgba(0,0,0,0.1);
}

.app-header { flex-shrink: 0; padding: 15px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: #fff; z-index: 100; }
.header-left { display: flex; align-items: center; }
.header-left h1 { margin: 0; font-size: 18px; color: var(--primary); }
.app-logo { height: 35px; width: auto; margin-right: 10px; border-radius: 5px; }

.progress-bar { flex-shrink: 0; display: flex; gap: 5px; padding: 10px; justify-content: center; background: #fafafa; flex-wrap: wrap; }
.step-dot { width: 30px; height: 30px; background: #ddd; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: bold; cursor: pointer; font-size: 11px; margin-bottom: 5px; }
.step-dot.active { background: var(--primary); color: white; }

.app-content { flex-grow: 1; padding: 20px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.step-section { display: none; }
.step-section.active { display: block; animation: fadeIn 0.3s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.app-footer { flex-shrink: 0; padding: 15px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; background: white; z-index: 200; }

/* ==========================================================================
   3. ELEMENTI FORM
   ========================================================================== */
.card { border: 1px solid var(--border); padding: 15px; border-radius: 8px; margin-bottom: 20px; background: white; }
.border-blue { border-left: 5px solid #00aeef; }
.border-yellow { border-left: 5px solid #fff200; }

.input-label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 14px; color: #333; }
.input-field { width: 100%; padding: 12px; border: 1px solid #ccc; border-radius: 8px; font-size: 16px; box-sizing: border-box; margin-bottom: 10px; }

.geo-wrapper { display: flex; gap: 5px; }
.btn-geo { background: #eee; border: 1px solid #ccc; border-radius: 8px; font-size: 20px; width: 50px; cursor: pointer; transition: background 0.2s; }
.btn-geo:active { background: #ccc; }

.toggle-container { display: flex; width: 100%; border: 1px solid #ccc; border-radius: 8px; overflow: hidden; margin-bottom: 15px; }
.toggle-container input { display: none; }
.toggle-container label { flex: 1; padding: 12px; text-align: center; background: #f9f9f9; cursor: pointer; border-left: 1px solid #ccc; font-weight: bold; font-size: 14px; transition: 0.2s; }
.toggle-container label:first-of-type { border-left: none; }
.toggle-container input:checked + label { background: var(--primary); color: white; }

.divider { border: 0; border-top: 1px solid #e0e0e0; margin: 15px 0; }
.row { display: flex; gap: 10px; } .col { flex: 1; }

.btn-action { padding: 6px 12px; border: none; border-radius: 4px; font-weight: bold; cursor: pointer; margin-left: 5px; font-size: 12px; }
.save { background: #28a745; color: white; }
.load { background: #ffc107; color: #333; }
.print { background: #333; color: white; }

.btn-nav { padding: 10px 25px; border-radius: 20px; border: none; font-weight: bold; cursor: pointer; background: #e0e0e0; }
.btn-nav.primary { background: var(--primary); color: white; }
.big { font-size: 16px; padding: 15px 30px; width: 100%; border-radius: 8px; }
.btn-mini { padding: 4px 8px; font-size: 11px; background: #007bff; color: white; border: none; border-radius: 3px; cursor: pointer; }

/* Checklist */
.checklist { height: 350px; overflow-y: auto; border: 1px solid #ddd; border-radius: 4px; }
.check-head { display: flex; align-items: center; padding: 10px 5px; background: #eee; font-weight: bold; position: sticky; top: 0; z-index: 5; border-bottom: 1px solid #ccc; }
.check-head span:first-child, .check-head span:last-child { width: 50px; text-align: center; flex-shrink: 0; }
.check-head span:nth-child(2) { flex: 1; text-align: center; }
.check-row { display: flex; align-items: center; padding: 12px 5px; border-bottom: 1px solid #f0f0f0; background: #fff; }
.check-row:nth-child(even) { background-color: #fafafa; }
.check-row input { width: 50px; height: 20px; margin: 0; flex-shrink: 0; cursor: pointer; }
.check-row span { flex: 1; text-align: center; padding: 0 10px; font-size: 13px; line-height: 1.3; }

/* Share */
.share-actions { margin-top: 20px; padding: 10px; border-top: 1px solid #eee; }
.btn-share { width: 48%; padding: 12px; margin: 1%; border: none; border-radius: 5px; color: white; font-weight: bold; cursor: pointer; font-size: 13px; }
.wa { background: #25D366; } .email { background: #007bff; }

/* ==========================================================================
   4. SEZIONI SPECIALI (Firme e Impatti)
   ========================================================================== */
.fullscreen-sign-area { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: #fdfdfd; z-index: 9999; display: flex; flex-direction: column; padding: 20px; }
.sign-header { text-align: center; margin-bottom: 10px; }
.sign-footer { margin-top: 10px; display: flex; justify-content: space-between; }

/* --- OTTIMIZZAZIONE MOBILE PER FIRMA (MODIFICA RICHIESTA) --- */
@media (max-width: 768px) {
    .fullscreen-sign-area {
        padding: 0 !important; /* Rimuove i bordi per sfruttare tutto lo schermo */
    }
    .fullscreen-sign-area .sign-header {
        padding: 10px;
        flex-shrink: 0;
    }
    .fullscreen-sign-area canvas {
        flex-grow: 1; /* Il canvas occupa tutto lo spazio verticale disponibile */
        width: 100%;
        border-top: 1px solid #eee;
        border-bottom: 1px solid #eee;
        background: #fff;
    }
    .fullscreen-sign-area .sign-footer {
        padding: 15px;
        flex-shrink: 0;
        background: #fdfdfd;
        margin-top: 0;
    }
}

.impact-section { padding: 10px; background: white; border-radius: 8px; }
.impact-container { position: relative; width: 100%; border: 2px solid #ccc; border-radius: 8px; overflow: hidden; touch-action: none; }
.impact-image { width: 100%; display: block; }
.arrow-ui { position: absolute; font-size: 50px; color: red; font-weight: bold; transform: translate(-50%, -50%) rotate(-45deg); pointer-events: none; text-shadow: 2px 2px 0px white; }

/* ==========================================================================
   5. GRAFICO (ASPECT RATIO 2.9)
   ========================================================================== */
.sketch-ratio-box {
    position: relative;
    /* Ratio Fisso 87mm/30mm = 2.9 */
    aspect-ratio: 87 / 30; 
    overflow: hidden;
    background: white;
    border: 1px solid #ddd;
}

#sketch-preview-container { width: 100%; margin-top: 10px; }

/* Posizionamento nel modulo A4 */
#print-sketch-box {
    position: absolute;
    top: 76.2%; left: 27.4%; 
    width: 46.0%; height: 13.5%;
    z-index: 900;
    border: none;
}

/* Stili elementi grafici SCALABILI */
/* Fix: Larghezza % relativa al contenitore 87x30 */
.print-item { position: absolute; width: 15%; height: auto; transform-origin: center center; }
.print-item img { width: 100%; height: auto; display: block; } 

.print-curve { position: absolute; top: 0; left: 0; width: 100%; height: 100%; }
.print-curve svg { overflow: visible; width: 100%; height: 100%; }
.print-curve path { fill: none; stroke: black; stroke-linecap: round; vector-effect: non-scaling-stroke; }

/* ==========================================================================
   6. STAMPA A4 (Modulo CAI)
   ========================================================================== */
#print-container { display: none; }

@media print {
    body, html { margin: 0; padding: 0; height: 100%; overflow: visible !important; background: white !important; }
    #app-interface { display: none !important; }
    #print-container { display: block !important; position: absolute; top: 0; left: 0; width: 210mm; height: 297mm; overflow: hidden; margin: 0; padding: 0; box-shadow: none; }
}

#cai-module { position: relative; width: 210mm; height: 297mm; background: white; overflow: hidden; box-shadow: 0 0 10px rgba(0,0,0,0.5); }
.bg-img { width: 100%; height: 100%; object-fit: contain; position: relative; z-index: 1; }
.txt { position: absolute; font-family: 'Courier Prime', monospace; font-size: 10pt; color: #000; font-weight: 600; line-height: 1; white-space: nowrap; overflow: hidden; z-index: 100; }
.mark { position: absolute; font-family: Arial, sans-serif; font-weight: bold; font-size: 14pt; color: #000; z-index: 100; }
.hidden { display: none; }

.sig-img { position: absolute; height: auto; z-index: 999; transform: rotate(90deg); transform-origin: center center; }
#print-sigA { top: 85.0%; left: 43.5%; width: 11.9%; }
#print-sigB { top: 87.1%; left: 43.5%; width: 11.9%; }

#print-impact-box-A { position: absolute; top: 74.5%; left: 4.2%; width: 21.6%; height: 11%; z-index: 999; }
#print-impact-box-B { position: absolute; top: 74.5%; left: 73.0%; width: 21.1%; height: 10.9%; z-index: 999; }
.arrow-print { position: absolute; font-size: 35pt; color: red; font-weight: bold; transform: translate(-50%, -50%) rotate(-45deg); line-height: 1; }

#p-data { top: 7.8%; left: 8%; max-width: 15%; } #p-ora { top: 7.8%; left: 23%; max-width: 10%; } #p-luogo { top: 7.8%; left: 30.5%; max-width: 30%; font-size: 9pt; } #p-testimoni { top: 10.6%; left: 41%; max-width: 58%; font-size: 9pt; white-space: normal; line-height: 1.1; }
#x-feriti-no { top: 7.4%; left: 77.8%; } #x-feriti-si { top: 7.4%; left: 88.8%; }
#x-dV-no { top: 11.5%; left: 10.2%; } #x-dV-si { top: 11.5%; left: 16.2%; }
#x-dO-no { top: 11.5%; left: 25.3%; } #x-dO-si { top: 11.5%; left: 31.0%; }

/* Campi A */
#p-cognomeA { top: 18.6%; left: 12.8%; max-width: 20%; } #p-nomeA { top: 20.0%; left: 12.8%; max-width: 20%; } #p-cfA { top: 21.5%; left: 17.5%; max-width: 20%; }
#p-indirizzoA { top: 24.4%; left: 5.8%; max-width: 20%; font-size: 9pt; } #p-capA { top: 25.6%; left: 11.8%; max-width: 8%; } #p-statoA { top: 25.6%; left: 23.0%; max-width: 10%; } #p-telA { top: 27.2%; left: 15.5%; max-width: 20%; }
#p-modelloA { top: 33.5%; left: 7.0%; max-width: 18%; font-size: 9pt; } #p-targaA { top: 36.2%; left: 7.0%; max-width: 15%; font-size: 11pt; font-weight: bold; } #p-statoImmA { top: 36.2%; left: 25.0%; max-width: 5%; font-size: 9pt; }
#p-compA { top: 42.0%; left: 16.8%; max-width: 30%; font-size: 9pt; } #p-polA { top: 43.4%; left: 16.8%; max-width: 20%; } #p-cartaVerdeA { top: 48.0%; left: 16.8%; max-width: 20%; font-size: 9pt; }
#p-valA { top: 47.5%; left: 12.7%; max-width: 10%; } #p-valAlA { top: 47.5%; left: 25.0%; max-width: 10%; } #p-agA { top: 50.4%; left: 7.2%; max-width: 30%; font-size: 9pt; }
#x-dCop-no-A { top: 58.3%; left: 22.0%; font-size: 12pt; } #x-dCop-si-A { top: 58.3%; left: 30.0%; font-size: 12pt; }
#p-dCognomeA { top: 61.0%; left: 12.8%; max-width: 30%; } #p-dNomeA { top: 62.4%; left: 12.8%; max-width: 30%; }
#p-dDobA { top: 63.8%; left: 15.9%; max-width: 20%; font-size: 9pt; } #p-dCfA { top: 65.1%; left: 15.9%; max-width: 30%; font-size: 9pt; }
#p-dIndA { top: 68.1%; left: 5.5%; max-width: 30%; font-size: 9pt; } #p-dStatoA { top: 69.2%; left: 12.0%; max-width: 10%; font-size: 9pt; } #p-dTelA { top: 70.8%; left: 15.6%; max-width: 15%; font-size: 9pt; }
#p-patA { top: 72.1%; left: 15.0%; max-width: 20%; } #p-catA { top: 73.5%; left: 16.0%; max-width: 5%; } #p-patValA { top: 73.5%; left: 26.8%; max-width: 10%; }
#p-danniA { top: 87.2%; left: 5.5%; width: 25%; font-size: 8pt; white-space: normal; } #p-ossA { top: 91.5%; left: 5.8%; width: 35%; font-size: 8pt; white-space: normal; }

/* Campi B */
#p-cognomeB { top: 18.6%; left: 72.0%; max-width: 20%; } #p-nomeB { top: 20.0%; left: 72.0%; max-width: 20%; } #p-cfB { top: 21.5%; left: 76.7%; max-width: 20%; }
#p-indirizzoB { top: 24.4%; left: 65.0%; max-width: 20%; font-size: 9pt; } #p-capB { top: 25.6%; left: 71.0%; max-width: 8%; } #p-statoB { top: 25.6%; left: 82.2%; max-width: 10%; } #p-telB { top: 27.2%; left: 74.7%; max-width: 20%; }
#p-modelloB { top: 33.5%; left: 66.2%; max-width: 18%; font-size: 9pt; } #p-targaB { top: 36.2%; left: 66.2%; max-width: 15%; font-size: 11pt; font-weight: bold; } #p-statoImmB { top: 36.2%; left: 84.2%; max-width: 5%; font-size: 9pt; }
#p-compB { top: 42.0%; left: 76.0%; max-width: 30%; font-size: 9pt; } #p-polB { top: 43.4%; left: 76.0%; max-width: 20%; } #p-cartaVerdeB { top: 48.0%; left: 76.0%; max-width: 20%; font-size: 9pt; }
#p-valB { top: 47.5%; left: 71.9%; max-width: 10%; } #p-valAlB { top: 47.5%; left: 84.2%; max-width: 10%; } #p-agB { top: 50.4%; left: 66.4%; max-width: 30%; font-size: 9pt; }
#x-dCop-no-B { top: 58.3%; left: 81.2%; font-size: 12pt; } #x-dCop-si-B { top: 58.3%; left: 89.2%; font-size: 12pt; }
#p-dCognomeB { top: 61.0%; left: 72.0%; max-width: 30%; } #p-dNomeB { top: 62.4%; left: 72.0%; max-width: 30%; }
#p-dDobB { top: 63.8%; left: 75.1%; max-width: 20%; font-size: 9pt; } #p-dCfB { top: 65.1%; left: 75.1%; max-width: 30%; font-size: 9pt; }
#p-dIndB { top: 68.1%; left: 64.7%; max-width: 30%; font-size: 9pt; } #p-dStatoB { top: 69.2%; left: 71.2%; max-width: 10%; font-size: 9pt; } #p-dTelB { top: 70.8%; left: 74.8%; max-width: 15%; font-size: 9pt; }
#p-patB { top: 72.1%; left: 74.2%; max-width: 20%; } #p-catB { top: 73.5%; left: 75.2%; max-width: 5%; } #p-patValB { top: 73.5%; left: 86.0%; max-width: 10%; }
#p-danniB { top: 87.2%; left: 64.7%; width: 25%; font-size: 8pt; white-space: normal; } #p-ossB { top: 91.5%; left: 65.0%; width: 35%; font-size: 8pt; white-space: normal; }

/* Checklist */
#px-cA-1 { top: 19.60%; left: 36.1%; } #px-cB-1 { top: 19.60%; left: 62.4%; } #px-cA-2 { top: 22.35%; left: 36.1%; } #px-cB-2 { top: 22.35%; left: 62.4%; } #px-cA-3 { top: 25.10%; left: 36.1%; } #px-cB-3 { top: 25.10%; left: 62.4%; } #px-cA-4 { top: 27.85%; left: 36.1%; } #px-cB-4 { top: 27.85%; left: 62.4%; } #px-cA-5 { top: 30.60%; left: 36.1%; } #px-cB-5 { top: 30.60%; left: 62.4%; } #px-cA-6 { top: 33.35%; left: 36.1%; } #px-cB-6 { top: 33.35%; left: 62.4%; } #px-cA-7 { top: 36.10%; left: 36.1%; } #px-cB-7 { top: 36.10%; left: 62.4%; } #px-cA-8 { top: 38.85%; left: 36.1%; } #px-cB-8 { top: 38.85%; left: 62.4%; } #px-cA-9 { top: 41.60%; left: 36.1%; } #px-cB-9 { top: 41.60%; left: 62.4%; } #px-cA-10 { top: 44.35%; left: 36.1%; } #px-cB-10 { top: 44.35%; left: 62.4%; } #px-cA-11 { top: 47.10%; left: 36.1%; } #px-cB-11 { top: 47.10%; left: 62.4%; } #px-cA-12 { top: 49.85%; left: 36.1%; } #px-cB-12 { top: 49.85%; left: 62.4%; } #px-cA-13 { top: 52.60%; left: 36.1%; } #px-cB-13 { top: 52.60%; left: 62.4%; } #px-cA-14 { top: 55.35%; left: 36.1%; } #px-cB-14 { top: 55.35%; left: 62.4%; } #px-cA-15 { top: 58.10%; left: 36.1%; } #px-cB-15 { top: 58.10%; left: 62.4%; } #px-cA-16 { top: 60.85%; left: 36.1%; } #px-cB-16 { top: 60.85%; left: 62.4%; } #px-cA-17 { top: 63.60%; left: 36.1%; } #px-cB-17 { top: 63.60%; left: 62.4%; }
#p-countA { top: 67.9%; left: 35.8%; text-align: center; width: 3%; } #p-countB { top: 67.9%; left: 62.4%; text-align: center; width: 3%; }
}