/* =============================
   CSS OTTIMIZZATO COMPLETO
   ============================= */

/* ===== RESET ===== */
* {
    box-sizing: border-box;
}

/* ===== BODY ===== */
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 10px;
    background-color: #f4f4f4;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ===== CONTENITORE ===== */
.main-test-wrapper {
    background-color: #ffffff;
    max-width: 1050px;
    width: 95%;
    padding: 20px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    margin: 20px auto;
}

/* ===== HEADER ===== */
.header-box {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 3px solid #eee;
    padding-bottom: 15px;
    margin-bottom: 20px;
}

.left-image, .right-image {
    max-height: 45px;
}

/* ===== TITOLI ===== */
h1.centrato {
    text-align: center;
    color: #28a745;
    font-size: 1.8rem;
}

.green-subtitle {
    color: #0056b3;
    font-size: 1.3rem;
    margin-top: 25px;
    border-bottom: 2px solid #1a3a5a;
    padding-bottom: 5px;
    font-weight: bold;
}

/* ===== BOX ===== */
.box {
    border: 1px solid #ccc;
    padding: 20px;
    margin-top: 20px;
    background-color: #f9f9f9;
    border-radius: 8px;
}

/* ===== BOTTONI ===== */
.button-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin: 20px 0;
}

button {
    padding: 12px;
    font-size: 1rem;
    font-weight: bold;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: white;
}

.btn-theory { background-color: #007BFF; }
.btn-standard { background-color: #28a745; }
.btn-dsa { background-color: #ff8c00; }
.btn-index { background-color: #800020; }
.btn-print { background-color: #6f42c1; }

.btn-example {
    background-color: #28a745;
    padding: 10px;
    width: 100%;
}

.btn-soluzione {
    background-color: #17a2b8 !important;
}

/* =============================
   FORMULE (FIX DEFINITIVO)
   ============================= */

.formula {
    background-color: #e3f2fd;
    border-left: 5px solid #0056b3;
    padding: 15px;
    margin: 20px 0;
    border-radius: 0 8px 8px 0;

    overflow: hidden; /* ❗ niente scroll sul box */
}

/* Scroll SOLO interno MathJax (invisibile) */
.formula mjx-container {
    display: block;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;

    scrollbar-width: none;
}

.formula mjx-container::-webkit-scrollbar {
    display: none;
}

/* ===== SOLUZIONI ===== */
.calculation {
    background-color: #e3f2fd;
    padding: 15px;
    border-radius: 5px;
    margin: 10px 0;
    border: 1px solid #b3d7ff;
}

/* ===== GRAFICI ===== */
.plot-container {
    width: 100%;
    height: 300px;
    margin: 20px auto;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
}

/* ===== FOOTER ===== */
.footer {
    text-align: center;
    margin-top: 40px;
}

/* ===== UTILITY ===== */
.hidden {
    display: none;
}

/* =============================
   DESKTOP
   ============================= */
@media (min-width: 600px) {
    .button-container {
        flex-direction: row;
        justify-content: center;
        flex-wrap: wrap;
    }

    .btn-example {
        width: auto;
    }

    .main-test-wrapper {
        padding: 30px;
    }
}

/* =============================
   MOBILE
   ============================= */
@media (max-width: 480px) {
    .formula {
        padding: 10px;
    }

    .formula mjx-container {
        font-size: 0.9em;
    }

    .left-image, .right-image {
        max-height: 40px;
    }
}

/* =============================
   STAMPA (FIX DEFINITIVO)
   ============================= */
@media print {

    .hidden {
        display: block !important;
    }

    button,
    .button-container,
    .instruction-text,
    .instruction-box-standard,
    .header-box,
    .footer {
        display: none !important;
    }

    /* 🔴 FIX FONDAMENTALE: FLEX BODY */
    body {
        display: block !important;
        background: white !important;
        color: black !important;
        margin: 0;
        padding: 0;
        font-size: 11pt;
    }

    .main-test-wrapper {
        box-shadow: none !important;
        border: none !important;
        width: 100% !important;
        padding: 0 !important;
    }

    .calculation {
        display: block !important;
        background: none !important;
        border-left: 3px solid black !important;
    }

    /* =============================
       FORMULE (FIX STABILE)
       ============================= */
    .formula {
        background: none !important;
        border-left: 3px solid black !important;
        padding: 10px;

        /* 🔴 NON bloccare la stampa dei contenuti lunghi */
        overflow: visible !important;

        /* 🔴 FIX CHIAVE: evita sparizioni */
        page-break-inside: auto !important;
        break-inside: auto !important;
    }

    .formula mjx-container {
        display: inline-block !important;
        max-width: 100% !important;
        overflow: visible !important;
        white-space: normal !important;
    }

    .plot-container {
        display: none !important;
    }
}

/* =============================
   PAGINA STAMPA
   ============================= */
@page {
    margin: 1.5cm;
}
/* Box Istruzioni */
.instruction-text {
    background-color: #e3f2fd;        /* azzurrino come soluzioni */
    border: 2px solid #0056b3;        /* bordo blu scuro */
    padding: 20px;
    font-weight: bold;
    margin: 20px 0;
    border-radius: 8px;               /* leggermente più morbido */
    text-align: center;
}
.instruction-box-standard {
    background-color: #fff9e6;
    color: #0056b3;
    padding: 12px 20px;
    margin: 20px auto;
    border: 2px solid #ffc107;
    border-radius: 10px;
    text-align: center;
    font-weight: bold;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}
.footer-validation {
    margin-top: 20px;
    text-align: center;
}

.validation-links a {
    font-size: 0.85em;
    text-decoration: none;
    color: #777;
}
.example-title {
    font-weight: bold;
    color: #0056b3;
    font-size: 1.2rem;
    display: inline-block;
    margin-bottom: 10px;
}