:root {
    --border-color: #e0e0e0;
    --hover-bg: #dbeafe;
    --modal-bg: rgba(0, 0, 0, 0.6);
    --font-family: 'Roboto', sans-serif;
}

/* Regola base per la pagina: RIMOSSO 'overflow: hidden' per permettere alle media query di funzionare */
html, body {
    height: 100%;
    margin: 0;
}

body {
    font-family: var(--font-family);
    background-color: #f9f9f9;
    color: #333;
    display: flex;
    flex-direction: column;
}

header {
    padding: 0.5rem 1rem;
    background-color: #ffffff;
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
    display: flex;
    justify-content: center;
    align-items: center;
}

#legend {
    display: flex;
    gap: 1.5rem;
    justify-content: center;
}
.legend-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8rem; }
.color-box { width: 14px; height: 14px; border-radius: 3px; }

#mobile-nav { display: none; }

/* Contenitore per lo scorrimento del calendario */
#calendar-wrapper {
    flex-grow: 1;
    overflow: hidden;
    position: relative; /* Aggiunto per stabilità */
}

main#calendar-container {
    display: grid;
    grid-template-columns: repeat(12, 1fr);
    width: 100%;
    height: 100%;
}

.day-cell.weekend {
    background-color: #e0e0e0; 
    border-bottom-color: #f5f5f5;
}
/* Aggiunge un bordo superiore a ogni evento che segue un altro evento nello stesso giorno */
.event-item + .event-item {
    border-top: 1px solid rgba(255, 255, 255, 0.4); /* Linea bianca semitrasparente */
}

.month { display: flex; flex-direction: column; border-left: 1px solid var(--border-color); min-width: 80px; }
.month:last-child { border-right: 1px solid var(--border-color); }
.month-header { padding: 0.5rem 0.2rem; text-align: center; font-weight: 700; background-color: #f5f5f5; border-bottom: 1px solid var(--border-color); font-size: 0.9rem; }
.days-grid { display: grid; grid-template-rows: repeat(31, 1fr); flex-grow: 1; }
.day-cell { border-bottom: 1px solid var(--border-color); position: relative; cursor: pointer; overflow: hidden; }
.day-cell.empty { background-color: #fafafa; cursor: default; }
.day-cell:hover:not(.empty) { background-color: var(--hover-bg); }
.day-number { position: absolute; top: 2px; left: 2px; font-size: 0.5rem; color: #888; background-color: rgba(255, 255, 255, 0.8); padding: 1px 2px; border-radius: 2px; z-index: 5; }
.events-container { position: absolute; top: 0; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; }
.event-item { flex-grow: 1; font-size: 0.7rem; padding: 2px 4px; color: white; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; justify-content: center; text-align: center; position: relative; }
.admin-view .event-item { cursor: zoom-in; }
.event-item .delete-btn { display: none; position: absolute; right: 3px; top: 50%; transform: translateY(-50%); cursor: pointer; font-weight: bold; color: white; background: rgba(0,0,0,0.4); border-radius: 50%; width: 16px; height: 16px; text-align: center; line-height: 16px; font-size: 12px; z-index: 10; }
.admin-view .event-item:hover .delete-btn { display: block; }

footer { position: fixed; bottom: 10px; left: 10px; z-index: 100; }
#admin-login-icon { font-size: 1.5rem; cursor: pointer; opacity: 0.3; transition: opacity 0.2s; }
#admin-login-icon:hover { opacity: 1; }

/* --- Stili Modali --- */
.modal-hidden { display: none !important; }
#edit-modal, #view-modal { display: flex; position: fixed; z-index: 1000; left: 0; top: 0; width: 100%; height: 100%; background-color: var(--modal-bg); justify-content: center; align-items: center; }
.modal-content { background-color: white; padding: 1.5rem; border-radius: 8px; box-shadow: 0 5px 15px rgba(0,0,0,0.3); width: 90%; max-width: 400px; position: relative; }
.modal-content h2 { margin-top: 0; margin-bottom: 1rem; font-size: 1.2rem; }
.close-button { position: absolute; top: 8px; right: 12px; font-size: 1.8rem; font-weight: bold; cursor: pointer; color: #aaa; }

/* Form compatto */
#event-form { display: flex; flex-direction: column; gap: 0.8rem; }
#event-form label { font-weight: 500; font-size: 0.9rem; margin-bottom: -0.5rem; }
#event-form input, #event-form select, #event-form textarea, #event-form button { padding: 0.6rem; border-radius: 5px; border: 1px solid #ccc; font-size: 0.9rem; font-family: var(--font-family); }
#event-form textarea { resize: vertical; }
#event-form button { background-color: #417a2a; color: white; border: none; cursor: pointer; font-weight: bold; }

/* Dettagli evento (vista utente) */
#view-modal-body .event-view { border-left: 5px solid; margin-bottom: 1rem; padding-left: 1rem; }
#view-modal-body .event-view-title { font-weight: bold; font-size: 1.1rem; }
#view-modal-body .event-view-category { font-size: 0.8rem; opacity: 0.8; margin-bottom: 0.5rem; }
#view-modal-body .event-view-details { font-size: 0.9rem; white-space: pre-wrap; }

.honeypot-field { display: none; }


/* --- REGOLE PER DISPOSITIVI --- */

/* 1. DESKTOP (schermi grandi, > 1024px) */
/* Qui blocchiamo lo scroll verticale come volevamo all'inizio, mantenendo la vista perfetta */
@media (min-width: 1025px) {
    html, body {
        overflow: hidden;
    }
}

/* 2. TABLET (tra 769px e 1024px) */
/* Qui forziamo lo scroll ORIZZONTALE per vedere tutto il calendario */
@media (max-width: 1024px) and (min-width: 769px) {
    #calendar-wrapper {
        overflow-x: auto; /* Abilita lo scorrimento solo per il contenitore del calendario */
        overflow-y: hidden;
    }
    main#calendar-container {
        min-width: 1200px; /* Forza il calendario ad essere largo per provocare lo scroll */
    }
}

/* 3. MOBILE (fino a 768px) */
/* Qui attiviamo la vista a mese singolo con scroll VERTICALE */
@media (max-width: 768px) {
    html, body {
        overflow-x: hidden;
        overflow-y: auto;
    }
    #calendar-wrapper {
        overflow: visible;
    }
    main#calendar-container {
        grid-template-columns: 1fr;
        height: auto;
        min-width: unset;
    }
    header { justify-content: space-between; }
    #legend { display: none; }
    #mobile-nav { display: flex; width: 100%; justify-content: space-between; align-items: center; }
    #mobile-nav button { background: #eee; border: 1px solid #ccc; border-radius: 50%; width: 30px; height: 30px; font-size: 1.2rem; cursor: pointer; }
    #mobile-month-year { font-weight: bold; }
    .month { display: none; }
    .month.active-month { display: flex; }
    .days-grid { grid-template-rows: repeat(31, auto); }
    .day-cell { min-height: 60px; }
}

/* --- Navigazione Anno (Desktop) --- */
#year-nav-desktop {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-left: 2rem; /* Distanzia dalla legenda */
    font-weight: bold;
    font-size: 1.2rem;
}

#year-nav-desktop button {
    background: transparent;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    cursor: pointer;
    padding: 0.2rem 0.6rem;
    font-weight: bold;
    color: #555;
    transition: background 0.2s;
}

#year-nav-desktop button:hover {
    background-color: var(--hover-bg);
    color: #000;
}

/* Nascondiamo la navigazione anno desktop quando siamo su mobile 
   (perché su mobile usano le frecce dei mesi) */
@media (max-width: 768px) {
    #year-nav-desktop {
        display: none;
    }
}