/* =========================================
   1. RESET E BASE
   ========================================= */
body, html { 
    margin: 0; padding: 0; height: 100%; 
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; 
    overflow: hidden; 
}
.hidden { display: none !important; }

/* =========================================
   2. MAPPA E MARKER
   ========================================= */
#map { height: 100%; width: 100%; position: absolute; z-index: 1; }
.crosshair-cursor { cursor: crosshair !important; }

/* Marker Posizione Utente */
.user-location-marker { 
    background-color: #007bff; border: 2px solid white; border-radius: 50%; 
    box-shadow: 0 0 10px rgba(0, 123, 255, 0.6); width: 15px !important; height: 15px !important; 
}

/* =========================================
   3. FIX CONTROLLI LEAFLET
   ========================================= */
.leaflet-control-layers {
    border: none !important; border-radius: 8px !important;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2) !important; background: white;
    font-family: 'Segoe UI', sans-serif; padding: 6px !important;
}
.leaflet-control-layers-expanded { padding: 10px 15px !important; min-width: 180px; }
.leaflet-control-layers label { display: flex !important; align-items: center; margin-bottom: 6px; font-size: 13px; color: #333; cursor: pointer; }
.leaflet-control-layers label:last-child { margin-bottom: 0; }
.leaflet-control-layers input { margin: 0 8px 0 0 !important; cursor: pointer; width: 16px; height: 16px; display: inline-block; vertical-align: middle; }

/* =========================================
   4. INTERFACCIA UTENTE
   ========================================= */
#ui-toggle {
    position: absolute; top: 20px; right: 20px; z-index: 1001;
    width: 50px; height: 50px; border-radius: 50%;
    background: white; color: #333; border: none; cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3); 
    display: flex; justify-content: center; align-items: center; font-size: 20px;
    transition: transform 0.2s;
}
#ui-toggle:hover { background: #f0f0f0; transform: scale(1.05); }

#ui-container {
    position: absolute; top: 85px; right: 20px; width: 320px;
    background: white; padding: 20px; z-index: 1000;
    border-radius: 12px; box-shadow: 0 5px 20px rgba(0,0,0,0.2);
    max-height: 80vh; overflow-y: auto;
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform-origin: top right; opacity: 1; transform: scale(1) translateY(0);
}
#ui-container.collapsed { opacity: 0; pointer-events: none; transform: scale(0.9) translateY(-20px); }

h3 { margin-top: 0; color: #333; }
label { font-weight: 500; font-size: 0.9em; color: #555; display: block; margin-top: 10px; }
input, textarea, button { width: 100%; margin-bottom: 5px; padding: 10px; box-sizing: border-box; border: 1px solid #ddd; border-radius: 4px; }
textarea { resize: vertical; }
button { background: #007bff; color: white; border: none; cursor: pointer; font-weight: bold; margin-top: 10px; }
button:hover { background: #0056b3; }
.btn-secondary { background: #6c757d; }
.btn-secondary:hover { background: #5a3b62; }
.btn-small { width: auto; padding: 5px 12px; font-size: 0.85em; margin: 0 0 0 10px; }
.instruction { font-size: 0.9em; color: #666; font-style: italic; }

/* =========================================
   5. POPUP
   ========================================= */
.leaflet-popup-content-wrapper { border-radius: 8px; padding: 0; overflow: hidden; }
.leaflet-popup-content { margin: 0; width: 300px !important; }
.popup-header { padding: 15px; background: #f8f9fa; border-bottom: 1px solid #eee; }
.popup-title { font-size: 1.2em; font-weight: bold; margin: 0; color: #333; }
.popup-body { padding: 15px; }
.popup-desc { margin-bottom: 10px; line-height: 1.4; }
.popup-img { width: 100%; height: 180px; object-fit: cover; display: block; cursor: zoom-in; border-radius: 4px; }
.popup-tags { margin-top: 10px; }
.tag-badge { display: inline-block; background: #e9ecef; color: #495057; padding: 3px 8px; border-radius: 12px; font-size: 0.75em; margin-right: 5px; }
.popup-actions { display: flex; gap: 10px; margin-top: 15px; }
.btn-edit { background: #ffc107; color: #333; border: none; padding: 8px; flex: 1; border-radius: 4px; font-size: 0.9em; cursor: pointer; font-weight: bold; margin-top:0; }
.btn-delete { background: #dc3545; color: white; border: none; padding: 8px; flex: 1; border-radius: 4px; font-size: 0.9em; cursor: pointer; margin-top:0; }

/* =========================================
   6. BOTTONI FLOTTANTI
   ========================================= */
#floating-tools { 
    position: absolute; bottom: 30px; right: 20px; z-index: 1500; 
    display: flex; flex-direction: column; gap: 15px; align-items: center;
    pointer-events: none; 
}
.float-btn { 
    width: 60px; height: 60px; border-radius: 50%; color: white; border: none; 
    box-shadow: 0 4px 10px rgba(0,0,0,0.3); font-size: 24px; cursor: pointer; 
    transition: all 0.3s ease; display: flex; justify-content: center; align-items: center;
    pointer-events: auto; 
}
.float-btn:hover { transform: scale(1.1); }

#btn-add-float { background-color: #28a745; }
#btn-add-float.adding-mode { background-color: #dc3545; transform: rotate(45deg); }
#btn-gallery-float { background-color: #6f42c1; }
#btn-table-float { background-color: #fd7e14; }
#btn-home-float { background-color: #343a40; }
#btn-gps-float { background-color: white; color: #007bff; }

/* =========================================
   7. MODALI (GALLERIA E TABELLA)
   ========================================= */
#gallery-modal, #table-modal {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.85); z-index: 3000; 
    display: none; justify-content: center; align-items: center;
    backdrop-filter: blur(5px);
}
#gallery-modal:not(.hidden), #table-modal:not(.hidden) { display: flex; }

.gallery-container, .table-container-box {
    background: white; width: 90%; max-width: 1200px; height: 85vh;
    border-radius: 8px; display: flex; flex-direction: column;
    overflow: hidden; box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    position: relative;
}
.gallery-header { padding: 15px 20px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; background: #f8f9fa; min-height: 50px; }
.close-gallery { font-size: 2rem; cursor: pointer; line-height: 1rem; color: #666; }
.close-gallery:hover { color: #dc3545; }

/* Galleria Grid */
#gallery-grid { 
    flex: 1; overflow-y: auto; padding: 20px; 
    display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); 
    gap: 15px; align-content: start; 
}
.gallery-item { 
    position: relative; width: 100%; padding-bottom: 100%; 
    overflow: hidden; border-radius: 6px; background: #eee; 
    box-shadow: 0 2px 5px rgba(0,0,0,0.1); cursor: pointer; 
}
.gallery-item img { position: absolute; top: 0; left: 0; width: 100%; height: 100%; object-fit: cover; transition: transform 0.3s ease; display: block; }
.gallery-item:hover img { transform: scale(1.1); }
.gallery-info { position: absolute; bottom: 0; left: 0; width: 100%; background: linear-gradient(to top, rgba(0,0,0,0.9), transparent); color: white; padding: 20px 10px 10px 10px; box-sizing: border-box; opacity: 0; transition: opacity 0.3s ease; pointer-events: none; }
.gallery-item:hover .gallery-info { opacity: 1; }
.gallery-title { font-weight: bold; display: block; font-size: 0.9em; }
.gallery-author { font-size: 0.8em; color: #ddd; }

/* Tabella Grid.js */
#grid-wrapper { flex: 1; overflow-y: auto; padding: 10px; }
.gridjs-pagination .gridjs-pages button { background-color: #f8f9fa; border: 1px solid #ddd; border-radius: 4px; padding: 6px 12px; margin: 0 2px; color: #333; font-size: 14px; cursor: pointer; }
.gridjs-pagination .gridjs-pages button:hover:not(:disabled) { background-color: #e2e6ea; }
.gridjs-pagination .gridjs-pages button:disabled { opacity: 0.5; cursor: not-allowed; }
.gridjs-pagination .gridjs-pages button.gridjs-currentPage { background-color: #007bff; color: white; border-color: #007bff; font-weight: bold; }
.gridjs-pagination .gridjs-summary { color: #666; margin-top: 10px; }

/* Lightbox */
#lightbox { 
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; 
    background: rgba(0,0,0,0.95); z-index: 4000; 
    display: none; justify-content: center; align-items: center; cursor: zoom-out; 
}
#lightbox.active { display: flex; }
#lightbox img { max-width: 95%; max-height: 95%; border-radius: 4px; box-shadow: 0 0 20px rgba(0,0,0,0.5); }
.close-lightbox { position: absolute; top: 20px; right: 30px; font-size: 40px; color: white; cursor: pointer; }