/* ==========================================
   1. VARIABILI E RESET GLOBALE
   ========================================== */
:root {
    --header-blue: #1b52a4;
    --card-blue: #3a9beb;
    --bg-gray: #e4e8f3;
    --text-dark: #000000;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
    background-color: #222; /* Sfondo esterno per Desktop */
    font-family: Arial, sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

/* ==========================================
   2. CONTENITORE PRINCIPALE (#app) & RESPONSIVE
   ========================================== */
#app {
    width: 100%;
    height: 100dvh; /* Altezza dinamica mobile real-time */
    background-color: var(--bg-gray);
    display: flex;
    flex-direction: column; 
    position: relative;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

/* Formato Smartphone (Desktop View) */
@media (min-width: 480px) {
    #app {
        width: 100%;
        max-width: 420px;
        height: 92vh;
        max-height: 860px;
        border-radius: 12px;
    }
}

/* ==========================================
   3. APP HEADER & NOTCH SUPPORT
   ========================================== */
.app-header {
    background-color: var(--header-blue);
    color: white;
    display: flex;
    align-items: center;
    padding: calc(10px + env(safe-area-inset-top)) 15px 10px 15px; 
    height: auto; 
    min-height: 70px;
    box-sizing: border-box;
}

.header-logo {
    width: 50px;
    height: 50px;
    background: white;
    border-radius: 50%;
    margin-right: 15px;
}

.header-info {
    flex: 1;
}

.header-info h1 {
    margin: 0;
    font-size: 20px;
    font-weight: bold;
}

.header-info p {
    margin: 2px 0 0 0;
    font-size: 11px;
    opacity: 0.9;
}

.header-badge {
    background-color: #00a61c;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 14px;
}

#menu-badge-utente {
    cursor: pointer;
    transition: transform 0.15s ease, opacity 0.15s ease;
}

#menu-badge-utente:active {
    transform: scale(0.9);
    opacity: 0.8;
}

/* ==========================================
   4. LAYOUT CONTENITORI & SCENE
   ========================================== */
.scene-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
    overflow: hidden; 
    padding: 5px; 
    height: 100%;
    min-height: 0;
}

.orario-docenti-container, 
.orario-studenti-container, 
.orario-lab-container, 
.orario-consigli-container,
.utility-container {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden; 
    min-height: 0;
}

/* Sub-stati dinamici */
.sub-state {
    display: none;
    width: 100%;
    height: 90%;
}

.sub-state.active,
#sub-state-alfabeto.sub-state.active,
#sub-state-docenti.sub-state.active {
    display: flex !important;
    flex-direction: column !important;
    flex: 1 1 0% !important;
    height: 100% !important;
    max-height: calc(100vh - 70px) !important; /* Detrae l'header top o lascia lo spazio al footer */
    min-height: 0 !important;
    overflow: hidden !important; /* Impedisce al padre di allungarsi oltre lo schermo */
}

.consiglio-wrapper {
    width: 100%;
    overflow: visible; 
}

/* ==========================================
   5. MENU DASHBOARD (TILES)
   ========================================== */
.menu-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    padding: 25px;
}

.menu-card {
    background-color: var(--card-blue);
    border: none;
    border-radius: 18px;
    color: white;
    padding: 20px 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    height: 180px;
}

.menu-card img {
    width: 55px;
    height: 55px;
    object-fit: contain;
}

.menu-card span {
    font-size: 16px;
    font-weight: bold;
}

/* ==========================================
   6. REGISTRAZIONE E FORMS
   ========================================== */
.reg-full-page {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    min-height: 0;
    overflow: hidden;
    padding-bottom: 70px; /* Riserva spazio per il footer fisso */
}

.reg-bar {
    background-color: #7f7f7f;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 15px;
}

.reg-title {
    color: white;
    font-size: 22px;
    margin: 0;
}

.reg-input {
    width: 50%;
    padding: 6px 10px;
    font-size: 18px;
    border: none;
    border-radius: 2px;
}

.reg-content {
    background: white;
    margin: 15px;
    padding: 15px;
    flex: 1;
    font-size: 13px;
    line-height: 1.4;
    color: #000;
    border-radius: 4px;
    text-align: left;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.reg-content-scroll {
    flex: 1;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 20px;
}

.checkbox-group {
    margin-top: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.checkbox-item {
    display: flex;
    align-items: center;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
}

.checkbox-item input[type="checkbox"],
.checkbox-item input[type="radio"] {
    width: 22px;
    height: 22px;
    margin-right: 15px;
    cursor: pointer;
    -webkit-appearance: checkbox;
    appearance: checkbox;          
}

.btn-avanti {
    display: block;
    margin: 15px 15px 15px auto;
    background-color: #a6a6a6;
    color: white;
    border: none;
    padding: 10px 30px;
    font-size: 16px;
    border-radius: 10px;
    cursor: not-allowed;
}

.btn-avanti.active {
    background-color: var(--card-blue);
    cursor: pointer;
}

/* ==========================================
   7. LIST VIEWS (ALFABETO & DOCENTI)
   ========================================== */
/* LISTA SCROLLABILE ISOLATA */
.list-view {
    list-style: none;
    padding: 0;
    margin: 0;
    background: #fff;
    flex: 1 1 0% !important; /* Occupa tutto lo spazio rimanente nel sub-state */
    height: 100% !important;
    min-height: 0 !important;
    overflow-y: auto !important; /* Abilita lo scroll SOLO sulla lista */
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 80px !important; /* Mantiene l'ultimo elemento ben staccato dalla barra "indietro" */
}

.list-view li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 15px;
    border-bottom: 1px solid #e0e0e0;
    cursor: pointer;
    font-size: 18px;
    color: #000;
}

.list-view li:hover { 
    background-color: #f0f0f0; 
}

.list-view-left { 
    display: flex; 
    align-items: center; 
    gap: 15px; 
}

.list-view-left img { 
    width: 36px; 
    height: auto; 
}

.list-view-left span {
    font-size: 20px;
    font-weight: 500;
}

.counter { 
    color: #757575; 
    font-size: 18px; 
}

/* ==========================================
   8. TABELLE & GRIGLIE ORARIO
   ========================================== */
.tables-scroll-wrapper {
    flex: 1;
    width: 100%;
    overflow-y: auto;            
    overflow-x: hidden;           
    padding-bottom: 90px; 
    -webkit-overflow-scrolling: touch; 
}

.orario-titolo-docente { 
    color: red; 
    text-align: center; 
    margin: 15px 0 5px 0; 
    font-size: 22px; 
    text-transform: uppercase; 
}

.orario-titolo-sezione { 
    color: #1b52a4;               
    text-align: center;
    margin: 20px 0 8px 0;
    font-size: 16px;
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    background: #c3d6f1;
}

.table-responsive { 
    width: 100%; 
    padding: 0 5px; 
    box-sizing: border-box; 
    display: flex;
    justify-content: center;
}

.grid-orario { 
    width: 100%; 
    max-width: 600px; 
    margin: 0 auto; 
    border-collapse: separate; 
    border-spacing: 2px; 
    table-layout: fixed; 
}

.grid-orario th, 
.grid-orario td,
.grid-orario td.cell-data,
.grid-orario td.hour-label { 
    text-align: center; 
    padding: 6px 2px; 
    font-size: clamp(10px, 3vw, 14px);
    font-weight: 700 !important;
    height: 35px; 
    word-break: break-word; 
    -webkit-font-smoothing: antialiased;
}

.grid-orario th:first-child,
.grid-orario td.hour-label {
    width: 14%; 
    min-width: 45px;
}

.grid-orario th:not(:first-child), 
.grid-orario td:not(.hour-label) {
    width: calc((100% - 14%) / 6);
}

.grid-orario th { 
    color: blue; 
    background: transparent; 
}

.grid-orario th.current-day { 
    color: red; 
}

.grid-orario td.hour-label { 
    color: blue; 
    background: transparent; 
    font-size: clamp(11px, 3.2vw, 15px);
    font-weight: 700 !important;
    padding: 6px 0;
}

.grid-orario td.cell-data { 
    background: #dedede; 
    color: #000; 
}

.grid-orario td.cell-data.current-day {
    background: #c3d6f1;
}

.grid-orario td.cell-data.current-hour-cell {
    background-color: #ffeb3b !important; 
    color: #000000 !important;
    font-weight: bold !important;
    animation: flash-current-hour 1.5s infinite alternate !important;
}

/* ==========================================
   9. FOOTER GLOBALE (BOTTONE INDIETRO)
   ========================================== */
.menu-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: calc(70px + env(safe-area-inset-bottom)); 
    padding-bottom: env(safe-area-inset-bottom);
    background-color: #e5e6ee; 
    display: flex;
    justify-content: center;
    align-items: center;
    border-top: 1px solid #d0d2d9;
    box-shadow: 0 -2px 5px rgba(0, 0, 0, 0.05);
    z-index: 999;
}

.back-button {
    background: transparent;
    border: none;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    cursor: pointer;
    outline: none;
    padding: 10px 20px;
}

.back-button img {
    width: 44px;  
    height: 44px;
    transition: transform 0.1s ease;
}

.back-button span {
    color: #2b78c5; 
    font-size: 18px;
    font-weight: bold;
    text-transform: lowercase; 
}

.back-button:active img {
    transform: scale(0.92);
}

/* Inserisci questo in fondo al tuo file CSS principale */
#list-reg-filtro.grid-2-col {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 8px !important;
  max-height: 80vh !important;
  overflow-y: auto !important;
  -webkit-overflow-scrolling: touch !important;
  padding: 5px !important;
}

/**********************************************************/

/* Correzione padding griglia per non sovrapporsi al footer fisso */
.utility-container {
    padding-bottom: 90px !important;
    overflow-y: auto !important;
}

/* ==========================================
   MODALE CUSTOM RESETA APP
   ========================================== */
.custom-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(0, 0, 0, 0.65);
    display: none; /* Nascosto di default */
    justify-content: center;
    align-items: center;
    z-index: 10000; /* Sopra a qualsiasi footer o header */
    backdrop-filter: blur(3px);
}

.custom-modal-overlay.active {
    display: flex !important;
}

.custom-modal-box {
    background: #ffffff;
    width: 85%;
    max-width: 340px;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.3);
    text-align: center;
    animation: modalPop 0.2s ease-out;
}

@keyframes modalPop {
    from { transform: scale(0.85); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.custom-modal-header {
    font-size: 18px;
    font-weight: bold;
    color: #d32f2f;
    margin-bottom: 12px;
}

.custom-modal-body {
    font-size: 14px;
    color: #333333;
    line-height: 1.4;
    margin-bottom: 20px;
}

.custom-modal-actions {
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.modal-btn {
    flex: 1;
    padding: 12px 8px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
}

.modal-btn.btn-cancel {
    background-color: #e0e0e0;
    color: #333333;
}

.modal-btn.btn-danger {
    background-color: #d32f2f;
    color: #ffffff;
}

.modal-btn:active {
    opacity: 0.8;
}