/* in public/css/login.css */
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;700&display=swap');

:root {
    --primary-color: #007aff;
    --background-gradient: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
    --card-background: #ffffff;
    --text-color: #1d1d1f;
    --error-color: #d93025;
}

body {
    font-family: 'Poppins', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--background-gradient);
    margin: 0;
    padding: 20px;
    box-sizing: border-box;
}

.login-container, .login-hub-container {
    background-color: var(--card-background);
    padding: 40px;
    border-radius: 20px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
    text-align: center;
    width: 100%;
    border: 1px solid rgba(0,0,0,0.05);
}
.login-container { max-width: 340px; }
.login-hub-container { max-width: 700px; }
.logo { width: 100px; margin-bottom: 10px; }
h1 { font-size: 1.5em; margin-bottom: 8px; }
p { color: #6c757d; margin-bottom: 24px; }
.error, .pin-error { color: var(--error-color); height: 20px; font-weight: 500; }

/* Hub di Selezione */
.login-options { display: flex; gap: 1.5rem; margin-top: 2rem; }
.login-card {
    flex: 1; background: #f8f9fa; border: 1px solid #dee2e6;
    border-radius: 12px; padding: 2rem; text-decoration: none;
    color: #1d1d1f; cursor: pointer; text-align: center;
    transition: all 0.2s;
}
.login-card:hover { transform: translateY(-5px); box-shadow: 0 10px 25px rgba(0,0,0,0.08); border-color: var(--primary-color); }
.card-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }
.login-card h3 { margin: 0.5rem 0; font-size: 1.2rem; }
.login-card p { font-size: 0.9rem; color: #6c757d; margin-bottom: 0; }

/* Display PIN (comune) */
.pin-display { display: flex; justify-content: center; gap: 10px; margin-bottom: 15px; }
.pin-dot { width: 16px; height: 16px; border-radius: 50%; background-color: #e0e0e0; }
.pin-dot.active { background-color: var(--primary-color); }

/* Keypad Generale */
.keypad {
    display: grid;
    gap: 15px;
    max-width: 280px;
    margin: 1.5rem auto 0 auto;
}
.key {
    border: none; border-radius: 50%; width: 70px; height: 70px; font-size: 2em;
    cursor: pointer; background: #f5f5f5; transition: all 0.1s;
}
.key:active { transform: scale(0.95); }
.key-action { background: transparent; font-size: 1.5em; }

/* Login Istituto */
#istituto-keypad {
    grid-template-columns: repeat(3, 1fr);
}

/* Login Classe */
#login-container-classe .form-group {
    text-align: center;
    margin: 1.5rem 0;
}
#class-code-input {
    width: 100%; max-width: 240px; margin: 0 auto; padding: 15px;
    font-size: 2rem; text-align: center; letter-spacing: 0.5em; text-transform: uppercase;
    border: 2px solid #ccc; border-radius: 8px; box-sizing: border-box;
}

/* ** LA CORREZIONE DEFINITIVA E' QUI ** */
/* Regola Specifica per il Keypad di Classe Stile ATM */
#class-keypad.atm-keypad {
    grid-template-columns: repeat(3, 1fr);
}

.cta-button {
    background-color: var(--primary-color); color: white; border: none; padding: 14px 20px;
    border-radius: 8px; cursor: pointer; width: 100%; margin-top: 10px; font-size: 1rem;
    font-family: 'Poppins', sans-serif; font-weight: 500; transition: background-color 0.2s;
}
.cta-button:disabled { background-color: #6c757d; cursor: not-allowed; }
.link-button {
    background: none; border: none; color: var(--primary-color); font-family: 'Poppins', sans-serif;
    font-size: 0.9rem; cursor: pointer; margin-top: 15px; padding: 5px;
}

/* Media Queries */
@media (max-width: 700px) { .login-options { flex-direction: column; } }

.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(255, 255, 255, 0.95);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
    z-index: 1000;
}

.loading-overlay.active {
    opacity: 1;
    visibility: visible;
}

.spinner {
    border: 8px solid #f3f3f3;
    border-top: 8px solid var(--primary-color);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: spin 1s linear infinite;
    
    /* SOLUZIONE: Aggiungi i margini automatici per centrarlo */
    margin: 20px auto 0 auto;
}

#welcome-loading-text {
    color: var(--text-color);
    font-size: 1.8em;
    font-weight: 500;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    50% { transform: translateX(5px); }
    75% { transform: translateX(-5px); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Media Queries per la Responsività --- */
@media (max-width: 480px) {
    /* SOLUZIONE: Non forziamo più l'altezza e la larghezza al 100% */
    .login-container {
        padding: 30px;
        border-radius: 20px; /* Manteniamo i bordi arrotondati */
        box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1); /* Manteniamo l'ombra */
        
        /* Rimuoviamo le regole che causavano l'allungamento */
        /* width: 100%; (rimosso) */
        /* height: 100%; (rimosso) */
    }

    .key, .key-action {
        width: 65px;
        height: 65px;
        font-size: 1.8em;
    }

    #keypad {
        gap: 15px;
    }

    #pin-display {
        gap: 10px;
    }

    .pin-dot {
        width: 14px;
        height: 14px;
    }
}

/* --- Stili per Animazione di Caricamento a Fasi (CORRETTI) --- */

.loading-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transform: scale(0.95);
    transition: opacity 0.4s ease-out, transform 0.4s ease-out;
}

/* FASE 1: Il contenitore appare */
.loading-overlay.active .loading-content.stage-1 {
    opacity: 1;
    transform: scale(1);
}

.loading-logo {
    width: 120px;
    margin-bottom: 10px;
    opacity: 0;
    transform: translateY(0); /* Inizia al centro */
    transition: opacity 0.5s cubic-bezier(0.4, 0, 0.2, 1), transform 0.8s cubic-bezier(0.4, 0, 0.2, 1);
}

/* FASE 2: Il logo appare al centro */
.loading-overlay.active .loading-content.stage-2 .loading-logo {
    opacity: 1;
    transform: translateY(0);
}

/* FASE 3: Il logo si sposta verso l'alto E il testo appare */
.loading-overlay.active .loading-content.stage-3 .loading-logo {
    transform: translateY(-30px); /* Si sposta verso l'alto */
}

.welcome-text {
    text-align: center;
    color: var(--text-color);
    opacity: 0;
    transform: translateY(20px); /* Inizia più in basso */
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

/* FASE 3: Il testo appare dal basso mentre il logo sale */
.loading-overlay.active .loading-content.stage-3 .welcome-text {
    opacity: 1;
    transform: translateY(0); /* Si sposta nella posizione finale */
}

#welcome-title {
    display: block;
    font-size: 2em;
    font-weight: 500;
}

#welcome-name {
    display: block;
    font-size: 1.2em;
    color: #6c757d;
    margin-top: 10px;
}


/* --- Definizioni delle Animazioni (Keyframes) --- */

@keyframes fadeInContent {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

@keyframes moveUp {
    from { transform: translateY(0); }
    to { transform: translateY(-20px); }
}

@keyframes fadeInText {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOutPage {
    from { opacity: 1; }
    to { opacity: 0; }
}
body.fade-out {
    animation: fadeOutPage 0.2s ease-in forwards; 
}

/* Rimuoviamo il vecchio spinner se ancora presente */
.loading-overlay .spinner, .loading-overlay #welcome-loading-text {
    display: none;
}

/* Aggiungi alla fine di login.css */
.cta-button {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 14px 20px;
    border-radius: 8px;
    cursor: pointer;
    width: 100%;
    margin-top: 10px;
    font-size: 1rem;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    transition: background-color 0.2s;
}
.cta-button:hover {
    background-color: #0056b3;
}

.link-button {
    background: none;
    border: none;
    color: var(--primary-color);
    font-family: 'Poppins', sans-serif;
    font-size: 0.9rem;
    cursor: pointer;
    margin-top: 15px;
    padding: 5px;
}
.link-button:hover {
    text-decoration: underline;
}

.login-hub-container { /* Stili per la schermata di selezione iniziale */
    /* ... simili a .login-container ma magari con max-width più grande */
    max-width: 600px;
}
.login-options {
    display: flex;
    gap: 1.5rem;
    margin-top: 2rem;
}
.login-card {
    flex: 1;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: 12px;
    padding: 2rem;
    text-decoration: none;
    color: var(--text-color);
    transition: transform 0.2s, box-shadow 0.2s;
    text-align: center;
}
.login-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.card-icon { font-size: 2.5rem; margin-bottom: 0.5rem; }

/* Stile per il tastierino a simboli */
.symbol-keypad .key {
    font-size: 1.8rem; /* Simboli più piccoli dei numeri */
}

@media (max-width: 600px) {
    .login-options { flex-direction: column; }
}

/* Stile per il display del codice (diverso dai pin-dot) */
.code-display {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin: 1.5rem 0;
}
.code-display span {
    width: 40px;
    height: 50px;
    border: 2px solid #ccc;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.8rem;
    font-weight: 500;
    transition: border-color 0.2s, transform 0.2s;
}
.code-display span.filled {
    border-color: var(--primary-color);
    transform: scale(1.1);
}

/* Stile per l'input del Codice Classe */
#login-container-classe .form-group {
    margin: 1.5rem 0;
}
#login-container-classe .form-group input {
    width: 100%;
    max-width: 200px; /* Limita la larghezza */
    margin: 0 auto; /* Centra */
    padding: 15px;
    font-size: 2rem;
    text-align: center;
    letter-spacing: 0.5em; /* Spazia i caratteri */
    border: 2px solid #ccc;
    border-radius: 8px;
    box-sizing: border-box;
}

/* Stile per il display verticale del PIN */
.pin-display.vertical-display {
    flex-direction: column; /* Impila i punti verticalmente */
    gap: 15px;
    border: 2px solid #eee;
    border-radius: 12px;
    padding: 20px;
    width: 60px; /* Larghezza fissa */
    margin: 1.5rem auto; /* Centra */
}
.pin-display.vertical-display span {
    width: 20px;
    height: 20px;
    background-color: #e0e0e0;
    border-radius: 50%;
    transition: background-color 0.2s;
}
.pin-display.vertical-display span.filled {
    background-color: var(--primary-color);
}

/* Stile per il tastierino stile ATM (3 colonne) */
#login-container-classe .keypad.atm-keypad {
    grid-template-columns: repeat(3, 1fr); /* Forza il layout a 3 colonne */
    max-width: 280px;
    margin: 1.5rem auto 0 auto; /* Aggiunge spazio sopra e centra */
}

/* --- Stili Specifici per la Pagina di Logout --- */

/* 
   Queste regole si applicano solo alla pagina che ha <body class="logout-page">.
   Assicurano che il contenuto sia visibile di default, senza aspettare le classi
   JavaScript dell'animazione di login, ma usando le proprie animazioni.
*/
.logout-page .loading-content,
.logout-page .loading-logo,
.logout-page .welcome-text {
    opacity: 1;
    transform: none;
}

.logout-page .loading-logo {
    /* Usa l'animazione 'moveUp' che abbiamo definito sotto */
    animation: moveUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) 1s forwards;
}

.logout-page .welcome-text {
    /* Usa l'animazione 'fadeInText' con un piccolo ritardo */
    opacity: 0; /* Inizia invisibile per farla apparire */
    animation: fadeInText 0.6s ease-out 1.5s forwards;
}

body.fade-out {
    animation: fadeOutPage 0.2s ease-in forwards; 
}

/* --- Stili per Animazione di Avvio "VERSUS" (Versione 2.0) --- */

/* Importa il font Augustus (o un'alternativa simile) */
@import url('https://fonts.googleapis.com/css2?family=Cinzel:wght@800&display=swap'); /* Cinzel è un ottimo sostituto per Augustus */

.versus-container {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: var(--background-gradient);
    z-index: 9999;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    opacity: 1;
    transition: opacity 0.5s ease-out 2.5s; /* Dissolvenza dopo 2.5s */
}

.versus-container.hidden {
    opacity: 0;
    visibility: hidden;
}

.logo-side {
    position: absolute;
    /* Transizione più lunga per un movimento più lento e maestoso */
    transition: transform 1.2s cubic-bezier(0.6, 0, 0.2, 1);
}

.logo-side img {
    width: 120px;
    transition: opacity 0.6s ease-out; /* Aggiunta transizione per l'opacità */
}

/* ** LA "X" MINIMAL ** */
.versus-x {
    font-family: 'Cinzel', serif; /* Usa il font importato */
    font-size: 3.5rem; /* Dimensione ridotta */
    font-weight: 800;
    color: black;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.5s ease-out 0.2s, transform 0.5s ease-out 0.2s; /* Ritardo di 0.2s sull'apparizione */
}

/* --- Logica dell'Animazione a Fasi --- */

/* FASE 0 (Iniziale): Il logo sinistro è al centro, il destro è invisibile e dietro */
#logo-left {
    transform: translateX(0);
    z-index: 10;
}
#logo-right {
    transform: translateX(0);
    opacity: 0; /* Inizia invisibile */
    z-index: 9;
}

/* FASE 1: Il logo sinistro inizia a muoversi. Il destro appare e si muove. La X appare. */
.versus-container.stage-1 #logo-left {
    transform: translateX(-110px); /* Spazio leggermente aumentato */
}
.versus-container.stage-1 #logo-right {
    transform: translateX(110px);
    opacity: 1; /* Appare */
}
.versus-container.stage-1 .versus-x {
    opacity: 1;
    transform: scale(1);
}