/* ================================================
   FIX FOOTER - Mantieni layout originale nelle pagine TOLC
   ================================================= */

body[class*="path-mod-tolc"] #page-footer .footer-bottomtext,
body[class*="path-mod-tolc"] #page-footer a.footer-bottomtext {
    display: inline !important;
    width: auto !important;
    max-width: none !important;
}

body[class*="path-mod-tolc"] #page-footer .footer-secondarysection-wrapper {
    padding-left: 16px !important;
    padding-right: 16px !important;
}

/* ================================================
   LAYOUT GENERALE
   ================================================= */

.tolc {
    width: 80%;
    margin: 0 auto;
    padding: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: #333;
    box-sizing: border-box;
    border: 1px solid #ccc;
}

/* Colori di sfondo per le sezioni */
.bck-blue { background: #0d9fd7; }
.bck-orange { background: #f59f00; }
.bck-green { background: #61a561; }
.bck-bronze { background: #bd7c04; }

/* Colori per i pallini delle sezioni */
.dot.dot-blue { background: #0d9fd7; }
.dot.dot-yellow { background: #ffc627; }
.dot.dot-green { background: #30a559; }
.dot.dot-orange { background: #f28c28; }

/* ================================================
   HEADER TOLC (barra blu in alto)
   ================================================= */

.tolcheader {
    height: 35px;
    width: 100%;
    position: relative;
}

/* Mobile header - nascosto di default */
.tolc-mobile-header {
    display: none;
}

/* ================================================
   BARRE SEZIONI (tabs)
   ================================================= */

.tolc-sections-wrapper {
    /* Wrapper per le sezioni */
}

/* ================================================
   BARRE SEZIONI (tabs)
   ================================================= */

.tolc-sections {
    list-style: none;
    display: flex;
    gap: 20px;
    padding: 12px 20px;
    margin: 0;
    background: #e8f2ff;
    border-bottom: 2px solid #1d75b0;
}

.tolc-section-bar {
    background: #e9faff;
    display: flex;
    align-items: center;
}

/* Tab sezione (non attivo) */
.tolc-section {
    display: flex;
    align-items: center;
    font-size: 15px;
    font-weight: 500;
    padding: 6px 12px;
    background: transparent;
    border-radius: 0;
    cursor: default;
    height: 42px;
    border: 1px solid #c5d3e0;
}

/* Tab attivo */
.tolc-section.active {
    background: #ffffff;
    font-weight: 600;
    border: 1px solid #c5d3e0;
    border-radius: 0;
    border-bottom: none;
}

/* Tab clickable (sezione successiva) */
a.tolc-section {
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.2s;
}

a.tolc-section:hover {
    background: #d0e8f7;
}

/* Tab completato (non cliccabile) */
.tolc-section.completed {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Dot colorata */
.tolc-section .dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
    margin-right: 8px;
}

/* ================================================
   BREADCRUMB
   ================================================= */

.tolc-breadcrumb-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 0 0 15px 0;
    border-bottom: 1px solid #ccc;
}

.tolc-breadcrumb {
    font-size: 20px;
    font-weight: 500;
    color: #526069;
    padding: 12px 0 12px 15px;
}

.tolc-end-btn {
    padding: 16px;
    background-color: #e9faff;
    color: #003b70;
    font-weight: 600;
    font-size: 14px;
    border: none;
    text-decoration: none;
    cursor: pointer;
    border-top: 1px solid #c5d3e0;
    border-left: 1px solid #c5d3e0;
}

/* ================================================
   BLOCCO DOMANDE
   ================================================= */

/* Testo domanda */
.tolc-question-container .qtext {
    font-size: 17px;
    color: #526069;
    margin-bottom: 20px;
}

/* Risposte */
.tolc-question-container .answer > div {
    margin-bottom: 12px;
}

.tolc-question-container input[type="radio"] {
    transform: scale(1.2);
    margin-right: 10px;
}

.tolc-question-container .que .info {
    display: none !important;
}

.tolc-question-container .que .content {
    margin: 0 !important;
}

.tolc-question-container .que .formulation {
    color: #526069;
    background-color: #fff !important;
    border: none;
}

.tolc-question-container .que .qtype_multichoice_clearchoice {
    display: none !important;
}

/* ================================================
   TIMER
   ================================================= */

.tolctimer {
    background: #5382a7;
    padding: 0px 20px;
    font-size: 14px;
    font-weight: bold;
    color: #fff;
    text-align: right;
    height: 20px;
}

/* =========================================================
   NAVIGAZIONE DOMANDE
   ========================================================= */

/* Contenitore della navigation */
.qn_buttons {
    background: #ffffff;
    padding: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

/* Singolo numero */
.qnbutton {
    width: 40px;
    height: 40px;
    border: 1px solid #c9d4df;
    display: flex;
    justify-content: center;
    align-items: center;
    text-decoration: none !important;
    font-weight: 600;
    font-size: 16px;
    color: #003b70;
    background: #f4f9ff;
    border-radius: 0;
    cursor: pointer;
}

/* Domanda corrente */
.qnbutton.thispage {
    background: #f0f4f8;
    color: #003b70;
    border-top: 3px solid #003b70 !important;
}

/* Risposta salvata - colori per sezione */
.qnbutton.answersaved.color-blue {
    background: #0d9fd7;
    border-color: #0a7db0;
    color: #fff;
}

.qnbutton.answersaved.color-orange {
    background: #f59f00;
    border-color: #d68700;
    color: #fff;
}

.qnbutton.answersaved.color-green {
    background: #61a561;
    border-color: #4f8a4f;
    color: #fff;
}

.qnbutton.answersaved.color-bronze {
    background: #bd7c04;
    border-color: #9d6603;
    color: #fff;
}

/* Non risposte */
.qnbutton.notanswered {
    background: #f0f4f8;
    border-color: #d0dce6;
}

/* Pulsanti < e > */
.qnbutton.nav-prev,
.qnbutton.nav-next {
    width: 38px;
    height: 38px;
    background: #4877a8;
    color: white !important;
    font-weight: 700;
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 3px;
    border: none;
    text-decoration: none;
}

.qnbutton.disabled {
    opacity: 0.4;
    pointer-events: none;
}

/* ============================================================================
   REVIEW (RISULTATI)
============================================================================ */

.tolc-review {
    width: 80%;
    margin: 0 auto;
}

.tolc_result_section {
    padding: 15px;
}

.tolc_result_section h4 {
    margin: 0 0 10px 0;
    font-weight: 600;
}

.tolc_result_table,
.tolc_result_table tbody,
.tolc_result_table tr,
.tolc_result_table td {
    border: none !important;
}

.tolc_result_table {
    width: 100%;
    border-collapse: collapse;
}

.tolc_result_table tr.tolc_last_row {
    border-bottom: 2px solid #555 !important;
}

.tolc_result_table tr.tolc_last_row td {
    border-bottom: 2px solid #555 !important;
}

.tolc_result_table tr.tolc_section_score {
    font-weight: 700;
}

.tolc_result_table tr.tolc_section_score td {
    padding-top: 8px !important;
}

.tolc_result_label_column {
    padding: 0px 12px;
    text-align: left;
    color: #555;
}

.tolc_result_values_column {
    padding: 0px 12px;
    text-align: right;
    font-weight: 500;
}

.tolc_total_score {
    padding: 0px 15px;
    font-size: 24px;
}

.tolc_total_score b {
    font-size: 20px;
}

/* ============================================================================
   REVIEW ATTEMPT - Stati domande
============================================================================ */

/* Risposta corretta */
.qnbutton.correct {
    background: #5cb85c;
    border-color: #4cae4c;
    color: #fff;
}

/* Risposta sbagliata */
.qnbutton.incorrect {
    background: #d9534f;
    border-color: #d43f3a;
    color: #fff;
}

/* ============================================================================
   MODAL CHECKBOX ALIGNMENT
============================================================================ */

.tolc-checkbox-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin-bottom: 12px;
}

.tolc-checkbox-row input[type="checkbox"] {
    flex-shrink: 0;
    margin-top: 3px;
}

.tolc-checkbox-row label {
    flex: 1;
    margin: 0;
    cursor: pointer;
    line-height: 1.4;
}

/* ============================================================================
   RESPONSIVE - TABLET
============================================================================ */

@media (max-width: 992px) {
    .tolc {
        width: 95%;
    }
    
    .tolc-review {
        width: 95%;
    }
    
    .tolc-sections {
        gap: 10px;
        padding: 10px 15px;
    }
    
    .tolc-section {
        font-size: 14px;
        padding: 5px 10px;
        height: auto;
    }
}

/* ============================================================================
   RESPONSIVE - MOBILE
============================================================================ */

@media (max-width: 768px) {
    /* === PREVIENI OVERFLOW ORIZZONTALE === */
    body[class*="path-mod-tolc"] {
        overflow-x: hidden !important;
    }

    body[class*="path-mod-tolc"] #page,
    body[class*="path-mod-tolc"] #page-wrapper,
    body[class*="path-mod-tolc"] #page-content {
        overflow-x: hidden !important;
    }

    /* === FORZA LARGHEZZA PIENA SU MOBILE === */
    /* Sovrascrive contenitori Moodle 4.x/5.x - solo contenuto principale */
    body[class*="path-mod-tolc"] #page-content #region-main-box {
        padding-left: 0 !important;
        padding-right: 0 !important;
        overflow-x: hidden !important;
    }

    body[class*="path-mod-tolc"] .drawer-left-toggle {
        display: none !important;
    }

    body[class*="path-mod-tolc"] #topofscroll,
    body[class*="path-mod-tolc"] #region-main,
    body[class*="path-mod-tolc"] #region-main-box,
    body[class*="path-mod-tolc"] .region-main-inner,
    body[class*="path-mod-tolc"] [role="main"],
    body[class*="path-mod-tolc"] #maincontent {
        padding: 0 !important;
        margin: 0 !important;
        max-width: 100% !important;
        width: 100% !important;
    }

    /* Padding per contenuti pagina view (riepilogo tentativi, voto, bottone avvia) */
    body[class*="path-mod-tolc"] #region-main > .quizattemptsummary,
    body[class*="path-mod-tolc"] #region-main > h3,
    body[class*="path-mod-tolc"] #region-main > div > .btn,
    body[class*="path-mod-tolc"] [role="main"] > h3,
    body[class*="path-mod-tolc"] [role="main"] > .quizattemptsummary,
    body[class*="path-mod-tolc"] [role="main"] > div > .btn {
        margin-left: 16px !important;
        margin-right: 16px !important;
    }

    body[class*="path-mod-tolc"] .quizattemptsummary {
        margin-left: 16px !important;
        margin-right: 16px !important;
        width: calc(100% - 32px) !important;
    }

    /* Moodle 5.x usa drawer-based layout - solo contenuto, non footer */
    body[class*="path-mod-tolc"] .drawers #page-content {
        padding: 0 !important;
    }

    body[class*="path-mod-tolc"] .drawers .main-inner {
        max-width: 100% !important;
        padding: 0 !important;
    }

    .tolc {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        border-left: none;
        border-right: none;
        border-radius: 0;
        box-sizing: border-box !important;
    }

    .tolc-review {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        box-sizing: border-box !important;
    }

    /* === IMMAGINI RESPONSIVE === */
    .tolc-question-container img,
    .tolc-question-container .qtext img,
    .tolc-question-container .formulation img {
        max-width: 100% !important;
        height: auto !important;
        display: block;
    }

    /* === TABELLE RESPONSIVE === */
    .tolc-question-container table {
        display: block;
        width: 100% !important;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .tolc-question-container table td,
    .tolc-question-container table th {
        min-width: 80px;
        padding: 8px;
    }

    /* === MOBILE HEADER === */
    .tolcheader {
        height: auto;
        padding: 0;
    }
    
    .tolc-mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 8px 12px;
        background: inherit;
    }
    
    /* Hamburger button */
    .tolc-hamburger {
        background: none;
        border: none;
        cursor: pointer;
        padding: 5px;
        display: flex;
        flex-direction: column;
        gap: 4px;
    }
    
    .tolc-hamburger span {
        display: block;
        width: 22px;
        height: 3px;
        background: #fff;
        border-radius: 2px;
        transition: 0.3s;
    }
    
    .tolc-mobile-section-name {
        color: #fff;
        font-weight: 600;
        font-size: 14px;
        flex: 1;
        text-align: center;
    }
    
    /* Termina button mobile */
    .tolc-end-btn-mobile {
        background: rgba(255,255,255,0.2);
        border: 1px solid rgba(255,255,255,0.5);
        color: #fff;
        padding: 6px 12px;
        font-size: 12px;
        font-weight: 600;
        border-radius: 4px;
        cursor: pointer;
    }
    
    /* === SEZIONI DROPDOWN === */
    .tolc-sections-wrapper {
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
    }
    
    .tolc-sections-wrapper.open {
        max-height: 300px;
    }
    
    .tolc-section-bar {
        flex-direction: column;
        padding: 0;
        gap: 0;
    }
    
    .tolc-section {
        width: 100%;
        justify-content: flex-start;
        padding: 12px 15px;
        font-size: 14px;
        height: auto;
        border: none;
        border-bottom: 1px solid #d0dce6;
        background: #f8fbff;
    }
    
    .tolc-section.active {
        background: #fff;
        border-left: 4px solid #0d9fd7;
    }
    
    .tolc-section .dot {
        width: 10px;
        height: 10px;
        margin-right: 10px;
    }
    
    /* === BREADCRUMB - mostra solo testo, nasconde bottone === */
    .tolc-breadcrumb-wrapper {
        border-bottom: 1px solid #ccc;
    }
    
    .tolc-breadcrumb {
        font-size: 14px;
        padding: 8px 10px;
    }
    
    /* Nasconde il bottone Termina desktop (c'è già nell'header mobile) */
    .tolc-end-btn {
        display: none;
    }
    
    /* Timer */
    .tolctimer {
        font-size: 13px;
        padding: 0 10px;
    }
    
    /* Domanda */
    .tolc-question-container .qtext {
        font-size: 15px;
        padding: 0 10px;
    }

    /* Contenitore domanda con padding mobile */
    .tolc-question-container {
        padding: 15px 10px !important;
    }

    /* Risposte più facili da toccare */
    .tolc-question-container .answer > div {
        margin-bottom: 15px;
        padding: 10px;
        background: #f8f9fa;
        border-radius: 6px;
        border: 1px solid #e9ecef;
    }

    .tolc-question-container .answer > div:active,
    .tolc-question-container .answer > div:focus-within {
        background: #e8f4ff;
        border-color: #0d9fd7;
    }

    /* Radio buttons più grandi su mobile */
    .tolc-question-container input[type="radio"] {
        width: 20px;
        height: 20px;
        margin-right: 12px;
    }

    .tolc-question-container .answer label {
        font-size: 15px;
        line-height: 1.5;
        display: inline;
    }

    /* Navigation buttons */
    .qn_buttons {
        padding: 10px;
        gap: 6px;
        justify-content: center;
        flex-wrap: wrap;
    }

    /* Tap targets per mobile */
    .qnbutton {
        width: 36px;
        height: 36px;
        font-size: 14px;
    }

    .qnbutton.nav-prev,
    .qnbutton.nav-next {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
    
    /* Review risultati */
    .tolc_result_label_column,
    .tolc_result_values_column {
        padding: 0px 8px;
        font-size: 14px;
    }
    
    .tolc_total_score {
        padding: 0px 10px;
        font-size: 20px;
    }
    
    .tolc_total_score b {
        font-size: 18px;
    }
}

/* Desktop - nascondi elementi mobile */
@media (min-width: 577px) {
    .tolc-mobile-header {
        display: none !important;
    }
    
    .tolc-end-btn-mobile {
        display: none !important;
    }
}

/* ============================================================================
   TABELLA TENTATIVI RESPONSIVE
============================================================================ */

.quizattemptsummary {
    width: 100%;
}

@media (max-width: 576px) {
    .quizattemptsummary {
        font-size: 14px;
    }

    .quizattemptsummary th,
    .quizattemptsummary td {
        padding: 8px 6px;
    }

    .quizattemptsummary .statedetails {
        display: block;
        font-size: 12px;
    }
}

/* ============================================================================
   MODALI OTTIMIZZATE PER MOBILE
============================================================================ */

@media (max-width: 768px) {
    /* Modale fullscreen-like su mobile */
    #tolc-section-confirm-modal .modal-dialog,
    #tolc-end-confirm-modal .modal-dialog,
    #tolc-end-not-last-modal .modal-dialog,
    #tolc-time-expired-modal .modal-dialog {
        margin: 10px !important;
        max-width: calc(100% - 20px) !important;
        width: calc(100% - 20px) !important;
    }

    #tolc-section-confirm-modal .modal-content,
    #tolc-end-confirm-modal .modal-content,
    #tolc-end-not-last-modal .modal-content,
    #tolc-time-expired-modal .modal-content {
        max-height: none !important;
        overflow: visible !important;
    }

    #tolc-section-confirm-modal .modal-footer,
    #tolc-end-confirm-modal .modal-footer,
    #tolc-end-not-last-modal .modal-footer,
    #tolc-time-expired-modal .modal-footer {
        position: relative !important;
        z-index: 10 !important;
        padding: 15px !important;
        background: #fff !important;
    }

    /* Rimuovi larghezza fissa del container dentro le modali */
    #tolc-section-confirm-modal .container,
    #tolc-end-confirm-modal .container,
    #tolc-end-not-last-modal .container,
    #tolc-time-expired-modal .container,
    #tolc-section-confirm-modal .container.tolcmodal,
    #tolc-end-confirm-modal .container.tolcmodal,
    #tolc-end-not-last-modal .container.tolcmodal,
    #tolc-time-expired-modal .container.tolcmodal {
        max-width: 100% !important;
        width: 100% !important;
        padding-left: 15px !important;
        padding-right: 15px !important;
        box-sizing: border-box !important;
    }

    /* Previeni overflow nelle modali */
    .modal {
        overflow-x: hidden !important;
    }

    .modal-dialog {
        max-width: calc(100vw - 20px) !important;
        margin: 10px auto !important;
    }

    .modal-body {
        overflow-x: hidden !important;
        word-wrap: break-word !important;
    }

    .modal-body p,
    .modal-body h3,
    .modal-body label {
        word-wrap: break-word !important;
        overflow-wrap: break-word !important;
    }

    .tolcmodal {
        padding: 10px 5px !important;
    }

    .tolcmodal h3 {
        font-size: 18px !important;
        line-height: 1.3 !important;
    }

    .tolcmodal p {
        font-size: 14px !important;
        line-height: 1.5 !important;
    }

    .tolcmodal .fa-exclamation-triangle,
    .tolcmodal .fa-exclamation-circle {
        font-size: 40px !important;
    }

    /* Checkbox più facili da toccare */
    .tolc-checkbox-row {
        padding: 8px 0 !important;
    }

    .tolc-checkbox-row input[type="checkbox"] {
        width: 22px !important;
        height: 22px !important;
        margin-top: 0 !important;
    }

    .tolc-checkbox-row label {
        font-size: 14px !important;
    }

    /* Bottoni modale più grandi */
    #tolc-section-confirm-modal .modal-footer .btn,
    #tolc-end-confirm-modal .modal-footer .btn,
    #tolc-end-not-last-modal .modal-footer .btn,
    #tolc-time-expired-modal .modal-footer .btn {
        padding: 12px 24px !important;
        font-size: 16px !important;
        min-width: 100px !important;
    }
}

/* ============================================================================
   SAFE AREA PER iPHONE (notch e home indicator)
============================================================================ */

@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .tolc {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .tolcbtns {
        padding-bottom: calc(10px + env(safe-area-inset-bottom));
    }

    @media (max-width: 576px) {
        .tolcheader {
            padding-top: env(safe-area-inset-top);
        }

        .modal-content {
            padding-bottom: env(safe-area-inset-bottom);
        }
    }
}

/* ============================================================================
   ORIENTAMENTO LANDSCAPE SU MOBILE
============================================================================ */

@media (max-width: 896px) and (orientation: landscape) {
    .tolc-mobile-header {
        padding: 5px 12px;
    }

    .tolc-section {
        padding: 8px 15px;
    }

    .tolc-breadcrumb {
        padding: 6px 10px;
    }

    .tolc-question-container {
        padding: 10px !important;
    }

    .qn_buttons {
        padding: 8px;
    }

    .qnbutton {
        width: 38px;
        height: 38px;
    }
}