/* --- VARIABILI --- */
:root {
    --primary-color: #0056b3;
    --secondary-color: #28a745;
    --bg-color: #f4f7f6;
    --card-bg: #ffffff;
    --text-color: #333;
    --border-radius: 12px;
}

/* --- BASE --- */
body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.main-test-wrapper {
    background-color: var(--card-bg);
    max-width: 1000px;  /* Più largo su desktop */
    width: 100%;
    padding: 20px;
    border-radius: var(--border-radius);
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    box-sizing: border-box;
}

/* --- HEADER --- */
.header-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid #eee;
    padding: 10px 0;
    margin-bottom: 10px;
    background-color: white;
}

.header-box img {
    max-height: 40px;
    width: auto;
}

h1 {
    font-size: 1.8rem;
    color: var(--primary-color);
    text-align: center;
    margin-bottom: 10px;
}

.instruction-text {
    background: #e7f3ff;
    padding: 15px;
    border-left: 4px solid var(--primary-color);
    border-radius: 4px;
    font-size: 0.95rem;
    margin-bottom: 25px;
}

/* --- DOMANDE --- */
.question {
    background: #fff;
    border: 1px solid #e1e4e8;
    border-radius: var(--border-radius);
    padding: 20px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
}

.question:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 10px rgba(0, 86, 179, 0.2);
}

label {
    display: block;
    background: #f8f9fa;
    padding: 12px;
    margin: 8px 0;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.2s;
}

label:hover {
    background: #e9ecef;
}

input[type="radio"] {
    margin-right: 10px;
    transform: scale(1.2);
}

/* --- SPIEGAZIONI E GRAFICI --- */
.steps {
    display: none;
    margin-top: 15px;
    padding: 15px;
    background: #fff9db;
    border-left: 4px solid #fcc419;
    border-radius: 4px;
    font-size: 0.9rem;
}

/* --- BOTTONI GENERALI --- */
button {
    width: 100%;
    padding: 12px;
    margin-top: 10px;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.3s ease;
}

/* --- BOTTONE SPIEGAZIONE (Grigio) --- */
.btn-secondary {
    background-color: #6c757d;
    color: white;
    transition: all 0.3s ease;
    display: inline-block;
    border: none;
    padding: 8px 15px;
    border-radius: 5px;
    cursor: pointer;
}

.btn-secondary:hover {
    background-color: #495057;
}

.btn-secondary:active {
    transform: scale(0.98);
}

/* --- BOTTONE GRAFICO (Azzurro) --- */
.btn-info {
    background-color: #17a2b8;
    color: white;
}

/* --- FOOTER E NAVIGAZIONE --- */
.footer-container {
    margin-top: 20px;
    width: 100%;
    text-align: center;
}

.footer-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-bottom: 20px;
}

/* Stili specifici bottoni footer */
.btn-verify { background-color: #0056b3; color: white; }
.btn-verify:hover { background-color: #003d82; }

.btn-reset { background-color: #d9534f; color: white; }
.btn-reset:hover { background-color: #c9302c; box-shadow: 0 4px 8px rgba(0,0,0,0.2); }

.btn-dsa-version { background-color: #ff8c00; color: white; }
.btn-dsa-version:hover { background-color: #e67e00; transform: translateY(-2px); }

.btn-index { background-color: #800020; color: white; }
.btn-index:hover { background-color: #600018; transform: translateY(-2px); }

/* --- RESPONSIVE DESKTOP --- */
@media (min-width: 600px) {
    button { 
        width: auto; 
        padding: 10px 20px; 
    }
}

/* --- RESPONSIVE SMARTPHONE --- */
@media (max-width: 768px) {
    .main-test-wrapper {
        max-width: 100%;
        padding: 15px;
        margin: 0;
        border-radius: 8px;
    }
    
    body {
        padding: 5px;
    }
    
    h1 {
        font-size: 1.5rem;
    }
    
    .instruction-text {
        padding: 12px;
        font-size: 0.9rem;
    }
    
    .question {
        padding: 15px;
    }
    
    .question h2 {
        font-size: 1.3rem;
    }
    
    label {
        padding: 10px;
        font-size: 0.95rem;
    }
    
    button {
        font-size: 0.9rem;
        padding: 10px;
    }
    
    .header-box img {
        max-height: 30px;
    }
    
    /* Grafici più piccoli su mobile */
    [id^="plot"] {
        min-height: 200px !important;
    }
    
    .steps {
        padding: 12px;
        font-size: 0.85rem;
    }
}

/* --- REGOLE PER LA STAMPA --- */
@media print {
    /* 1. Forza la visualizzazione di soluzioni, grafici e SVG */
    .steps, 
    .box, 
    #results, 
    .graph-container, 
    [id^="graph"], 
    [id^="solution"], 
    [id^="plot"],
    svg,
    svg * {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        overflow: visible !important;
    }

    /* 2. FONDAMENTALE: Forza i colori e gli sfondi per i grafici SVG */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        color-adjust: exact !important;
    }
    
    /* 3. Regole specifiche per SVG e path dei grafici */
    svg {
        max-width: 100% !important;
        height: auto !important;
        page-break-inside: avoid !important;
    }
    
    svg path,
    svg line,
    svg circle,
    svg rect,
    svg text,
    svg g {
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
    }
    
    /* 4. Assicurati che i container dei grafici siano visibili */
    .graph-container,
    [id^="plot"] {
        display: block !important;
        visibility: visible !important;
        width: 100% !important;
        min-height: 300px !important;
        page-break-inside: avoid !important;
        margin: 20px 0 !important;
        border: 1px solid #ddd !important;
        padding: 10px !important;
    }

    /* 5. Nascondi elementi interattivi e inutili su carta */
    button, 
    .footer-buttons, 
    .header-box, 
    input[type="radio"], 
    .button-group, 
    hr, 
    .btn-theory {
        display: none !important;
    }

    /* 6. Layout pulito per le domande */
    .question {
        page-break-inside: avoid;
        border: none !important;
        border-bottom: 1px solid #ddd !important;
        margin-bottom: 30px !important;
        padding-bottom: 20px !important;
    }

    /* 7. Ottimizzazione immagini */
    img {
        max-width: 100% !important;
        height: auto !important;
        page-break-inside: avoid;
    }
    
    /* 8. Rimuove ombre e sfondi grigi per risparmiare inchiostro */
    body {
        background: white !important;
    }
    
    .main-test-wrapper {
        box-shadow: none !important;
        padding: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
    }
    
    /* 9. Spiegazioni con sfondo leggero stampabile */
    .steps {
        background: #fffef5 !important;
        border-left: 3px solid #999 !important;
        page-break-inside: avoid;
    }
}