/* ===========================
   FONT & RESET
=========================== */

body {
margin: 0;
    padding: 0;
    background: #f5f5f5;
    font-family: 'Inter', sans-serif;
    color: #333;
}

h1, h2, h3 {
    font-family: 'Judson', serif;
    margin-top: 0;
}

* {
    box-sizing: border-box;
}
/* ===========================
   HEADER
=========================== */

.main-header {
    position: fixed;
    top: 0;
    width: 100%;
    height: 70px;
    background: linear-gradient(90deg, #1e3a8a, #3b82f6);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
     z-index: 1100; 
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
/* Logo con testo a fianco (opzionale se vuoi aggiungere il nome vicino all'immagine) */
.logo-box {
    background: white;
    padding: 5px 15px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    height: 50px;
}

.logo-box img {
    height: 35px;
}

/* Navigazione stile Pillola */
nav {
    display: flex;
    gap: 5px;
}

nav a {
    color: white;
    padding: 8px 20px;
    text-decoration: none;
    font-weight: 500;
    border-radius: 50px;
    transition: all 0.3s ease;
}

/* Stile per il link attivo (quello bianco nello screenshot) */
nav a.active, nav a:hover {
    background: white;
    color: #1e3a8a;
}

/* User Box & Badge */
.user-box {
    display: flex;
    align-items: center;
    gap: 15px;
    color: white;
    font-weight: 500;
}

.role-badge {
    background: #ef4444; /* Rosso Admin */
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
}

.logout-link {
    background: rgba(255,255,255,0.1);
    padding: 8px 15px;
    border-radius: 8px;
    color: white;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 5px;
}

.logout-link:hover {
    background: rgba(255,255,255,0.2);
}

/* ===========================
   CONTENT
=========================== */

.content {
    padding: 100px 30px 40px;
}

/* ===========================
   LOGIN
=========================== */
.login-container {
    max-width: 380px;
    margin: 120px auto;
    background: white;
    padding: 30px;
    border-radius: 18px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    text-align: center;
    /* Impedisce al contenitore di allargarsi se non necessario */
    box-sizing: border-box; 
}

.login-container input {
    width: 100%;
    padding: 12px;
    margin: 10px 0;
    border-radius: 8px;
    border: 1px solid #ccc;
    /* CRUCIALE: include padding e border nel calcolo della width */
    box-sizing: border-box; 
}

.login-btn {
    width: 100%;
    padding: 12px;
    background: #1976d2;
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer; /* Aggiunge la manina al passaggio del mouse */
    box-sizing: border-box; 
    transition: background 0.3s ease;
}

.login-container img {
    width: 120px;
    margin-bottom: 20px;
}

.login-btn:hover {
    background: #0d47a1;
}

/* ===========================
   CARD
=========================== */

.card {
    background: white;
    padding: 24px;
    border-radius: 18px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    margin-bottom: 25px;
}

/* ===========================
   MAPPA
=========================== */

#map {
	z-index: 1; /* Un valore basso */
    position: relative;
    width: 100%;
    height: 80vh;
    border-radius: 18px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

/* ===========================
   TABELLE
=========================== */

table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 16px;
    overflow: hidden;
}

th {
    background: #1976d2;
    color: white;
    padding: 12px;
    text-align: left;
	user-select: none;
}

th:nth-child(-n+4) {
    cursor: pointer;
}
th:nth-child(5), 
th:nth-child(6) {
    cursor: default;
}
th i {
    margin-left: 8px;
    color: #cbd5e1; /* Colore grigio chiaro di default */
    transition: all 0.2s;
}

/* Icona attiva (colonna ordinata) */
th.sort-asc i.fa-sort,
th.sort-asc i.fa-sort-up,
th.sort-asc i.fa-sort-down {
    color: #cbd5e1 !important;
    content: "\f0de"; /* Codice FontAwesome per sort-up */
}

th.sort-desc i.fa-sort-up,
th.sort-desc i.fa-sort-down {
    color: #cbd5e1 !important;
}

td {
    padding: 12px;
    border-bottom: 1px solid #eee;
}

tr:hover {
    background: #f0f8ff;
}



/* ===========================
   BOTTONI
=========================== */

.btn {
    padding: 8px 14px;
    border-radius: 8px;
    text-decoration: none;
    color: white;
    font-size: 14px;
}

.btn-green { background: #22c55e; }
.btn-orange { background: #f97316; }
.btn-yellow { background: #eab308; color: black; }
.btn-red { background: #d32f2f; }
.btn-blue { background: #1976d2; }

.btn:hover { opacity: 0.85; }

/* ===========================
   FILTRI (Stile Pillole)
=========================== */

.filter-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    background: white;
    padding: 10px 20px;
    border-radius: 50px; /* Arrotondamento completo come in foto */
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-label {
    font-weight: bold;
    color: #666;
    margin-right: 10px;
}

.pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 16px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 600;
    color: white;
    cursor: pointer;
    transition: transform 0.2s;
}

.pill:hover { transform: translateY(-2px); opacity: 0.9; }

.pill-dot {
    width: 8px;
    height: 8px;
    background: white;
    border-radius: 50%;
}

/* Colori specifici per le pillole */
.bg-blue { background-color: #3b82f6; }
.bg-red { background-color: #ef4444; }
.bg-orange { background-color: #f97316; }
.bg-yellow { background-color: #eab308; }
.bg-green { background-color: #22c55e; }
.bg-gray { background-color: #94a3b8; }

/* Badge Admin nell'header */
.admin-badge {
    background: #ef4444;
    color: white;
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: bold;
    font-size: 12px;
    margin-right: 10px;
}

/* ===========================
   RESPONSIVE & HAMBURGER
=========================== */

/* Nascondi info utente mobile su desktop */
.mobile-user-info { display: none; }
.hamburger { display: none; cursor: pointer; flex-direction: column; gap: 5px; }
.hamburger span { width: 25px; height: 3px; background: white; border-radius: 2px; transition: 0.3s; }

@media (max-width: 768px) {
    .logo-text { display: none; } /* Nascondi testo logo se troppo stretto */
    .desktop-only { display: none; }
    
    .hamburger { display: flex; }

    /* Navigazione Mobile (Menu Laterale) */
    nav {
        position: fixed;
        right: -100%; /* Nascosto a destra */
        top: 70px;
        flex-direction: column;
        background: #1e3a8a;
        width: 250px;
        height: calc(100vh - 70px);
        padding: 20px;
        transition: 0.4s;
        box-shadow: -5px 0 15px rgba(0,0,0,0.2);
        gap: 10px;
		z-index: 1200;
    }

    nav.active { right: 0; } /* Mostra quando attivo */

    nav a { width: 100%; border-radius: 8px; }
    
    .mobile-user-info { display: block; color: white; margin-top: 20px; }
    .mobile-user-info hr { border: 0; border-top: 1px solid rgba(255,255,255,0.2); margin: 15px 0; }

    /* Adattamento Mappa e Filtri */
    .filter-bar { padding: 10px; border-radius: 15px; }
    .pill { padding: 5px 12px; font-size: 12px; }
    #map { height: 60vh; }
    .content { padding: 90px 15px 20px; }
}

/* Badge per lo stato nella tabella */
.status-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 700;
    display: inline-block;
}
.status-contattato { background-color: #ffedd5; color: #9a3412; }
.status-confermato { background-color: #dcfce7; color: #166534; }
.status-scoperto { background-color: #fee2e2; color: #991b1b; }
.status-trattativa { background-color: #fef9c3; color: #854d0e; }
.status-passato { background-color: #f1f5f9; color: #475569; }

/* Stile barra azioni sopra la tabella */
.table-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.search-box {
    position: relative;
    flex-grow: 1;
}

.search-box input {
    width: 100%;
    padding: 10px 15px 10px 40px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.search-box i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
}

/* Pulsanti export */
.export-btns {
    display: flex;
    gap: 10px;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.btn-pdf { background: #d32f2f; }
.btn-csv { background: #1976d2; }
.btn-print { background: #334155; }

/* Icone azioni in tabella */
.action-link {
    color: #3b82f6;
    margin: 0 5px;
    font-size: 1.1rem;
    transition: color 0.2s;
}
.action-link.delete { color: #ef4444; }
.action-link:hover { opacity: 0.7; }

/* ===========================
   RESPONSIVE TABELLA EVENTI
=========================== */

@media (max-width: 768px) {
    /* Trasforma la barra delle azioni (ricerca, filtri, export) in colonna */
    .table-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .export-btns {
        justify-content: space-between;
    }

    .export-btns .btn {
        flex: 1;
        justify-content: center;
        font-size: 12px;
        padding: 10px 5px;
    }

    /* Trasforma la tabella in un layout a schede */
    #eventsTable, 
    #eventsTable thead, 
    #eventsTable tbody, 
    #eventsTable th, 
    #eventsTable td, 
    #eventsTable tr { 
        display: block; 
    }

    /* Nascondi l'intestazione originale */
    #eventsTable thead tr { 
        position: absolute;
        top: -9999px;
        left: -9999px;
    }

    #eventsTable tr {
        margin-bottom: 15px;
        border: 1px solid #e2e8f0;
        border-radius: 12px;
        padding: 10px;
        background: white;
        box-shadow: 0 2px 4px rgba(0,0,0,0.02);
    }

    #eventsTable td { 
        border: none;
        position: relative;
        padding-left: 50%; 
        text-align: right;
        min-height: 40px;
        display: flex;
        align-items: center;
        justify-content: flex-end;
    }

    /* Aggiunge le etichette delle colonne prima del dato */
    #eventsTable td:before { 
        position: absolute;
        left: 10px;
        width: 45%; 
        padding-right: 10px; 
        white-space: nowrap;
        text-align: left;
        font-weight: bold;
        color: #64748b;
        font-size: 0.8rem;
        content: attr(data-label); /* Usa l'attributo data-label che aggiungeremo nel PHP */
    }

    /* Adattamento specifico per la colonna Nome (la prima) */
    #eventsTable td:first-child {
        background: #f8fafc;
        margin: -10px -10px 10px -10px;
        border-radius: 12px 12px 0 0;
        padding-top: 15px;
        padding-bottom: 15px;
    }
}

.leaflet-popup-content-wrapper {
    border-radius: 18px;
    padding: 10px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.15);
}

.custom-popup {
    font-family: 'Inter', sans-serif;
    min-width: 280px;
}

.popup-title {
    color: #1e3a8a;
    font-size: 1.2rem;
    margin-bottom: 5px;
    font-weight: 700;
}

.popup-location {
    color: #64748b;
    margin-bottom: 15px;
}

.popup-badges {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

.status-nd { background: #f1f5f9; color: #94a3b8; }

.popup-info {
    border-top: 1px solid #e2e8f0;
    padding-top: 10px;
    margin-bottom: 15px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
    font-size: 0.9rem;
}

.info-row span:first-child { color: #64748b; font-weight: 600; }
.info-row span:last-child { color: #1e293b; }

/* Bottoni nel Popup */
.popup-actions {
    display: flex;
    gap: 10px;
    margin-top: 15px;
}

.btn-popup {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px;
    border-radius: 10px;
    text-decoration: none;
    font-weight: 700;
    font-size: 0.85rem;
    color: #ffffff !important; 
    transition: background 0.3s ease;
}

.btn-edit { 
    background-color: #3b82f6; /* Blu come da immagine */
}

.btn-delete { 
    background-color: #ef4444; /* Rosso come da immagine */
}
.btn-popup:hover { 
    opacity: 0.9;
    color: #ffffff !important; /* Mantiene il bianco anche al passaggio del mouse */
}

.btn-popup i {
    color: #ffffff;
}

.calendar-layout {
    display: grid;
    grid-template-columns: 1fr 300px;
    gap: 25px;
    align-items: start;
}

@media (max-width: 1024px) {
    .calendar-layout { grid-template-columns: 1fr; }
}

/* Griglia dei giorni */
.calendar-grid {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 15px;
    overflow: hidden;
}

.calendar-grid th {
    padding: 15px;
    background: #f8fafc;
    color: #64748b;
    font-size: 0.8rem;
    text-transform: uppercase;
}

.calendar-grid td {
    border: 1px solid #f1f5f9;
    height: 100px;
    width: 14.28%;
    vertical-align: top;
    padding: 10px;
    transition: background 0.2s;
}

.calendar-grid td:hover { background: #f8fafc; }

.day-number {
    font-weight: 700;
    color: #1e293b;
    display: inline-block;
    width: 30px;
    height: 30px;
    line-height: 30px;
    text-align: center;
}

/* Giorno Corrente (Blu) */
.today-circle {
    background: #3b82f6;
    color: white !important;
    border-radius: 50%;
}

/* Sidebar Cards */
.side-card {
    background: white;
    padding: 20px;
    border-radius: 15px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.side-card h3 {
    font-size: 1rem;
    color: #1e3a8a;
    margin-bottom: 15px;
}

.legenda-item {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.dot { height: 10px; width: 10px; border-radius: 50%; }

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.stat-box {
    background: #f8fafc;
    padding: 10px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
}

.nav-arrow {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    color: #64748b;
    text-decoration: none;
    transition: all 0.2s;
}

.nav-arrow:hover {
    background-color: #f8fafc;
    border-color: #cbd5e1;
    color: #1e3a8a;
}

/* Pulsante "Oggi" accanto al mese */
.btn-today {
    background: #eff6ff;
    color: #3b82f6;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    transition: 0.2s;
}

.btn-today:hover {
    background: #dbeafe;
}

.insert-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: start;
    margin-top: 20px;
}

.form-section {
    background: white;
    padding: 25px;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    display: flex;
    flex-direction: column;
    gap: 20px; /* Spaziatura verticale costante tra tutti i campi */
}

.input-group-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px; /* Spazio tra i due input nella stessa riga */
}

.input-field {
    display: flex;
    flex-direction: column;
    gap: 8px; /* Spazio tra label e input */
}

.input-field label {
    font-size: 0.85rem;
    font-weight: 700;
    color: #1e293b;
}

.input-field input, 
.input-field select, 
.input-field textarea {
    padding: 12px 15px;
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    font-size: 0.95rem;
    width: 100%;
    box-sizing: border-box;
}

.map-sidebar {
    position: sticky;
    top: 90px;
}

#map-insert {
    height: 300px; /* Altezza bilanciata */
    border-radius: 12px;
    border: 1px solid #e2e8f0;
    margin-bottom: 20px;
}

@media (max-width: 992px) {
    .insert-container {
        grid-template-columns: 1fr; /* Una colonna su tablet/mobile */
    }
    
    .input-group-row {
        grid-template-columns: 1fr; /* Gli input affiancati vanno uno sotto l'altro */
    }

    .form-section {
        padding: 20px;
    }
}