/* ============================================
   TECH DASHBOARD THEME - Diocesi Alife 360
   ============================================ */

/* Pulsante navigazione header */
.header-actions-nav {
    display: flex;
    align-items: center;
    margin-right: 16px;
}

.header-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px;
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    transition: background 0.2s, color 0.2s;
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.header-nav-btn:hover {
    background: rgba(139, 92, 246, 0.25);
    color: #c4b5fd;
}

/* Fade-in morbido sui tile WMS (evita apparizione brusca) */
.leaflet-tile {
    transition: opacity 0.3s ease-in;
}

/* Indicatore posizione comune/foglio sulla mappa */
#location-indicator {
    z-index: 1000 !important;
    background: rgba(15, 23, 42, 0.85);
    color: #e2e8f0;
    padding: 6px 14px;
    border-radius: 8px;
    font-size: 0.82rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    pointer-events: none;
    white-space: nowrap;
    border: 1px solid rgba(255,255,255,0.15);
}

/* ==================== VARIABILI CSS ==================== */
:root {
    /* Colori principali - Dark Theme */
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --bg-hover: #475569;

    /* Accenti */
    --accent-blue: #3b82f6;
    --accent-green: #22c55e;
    --accent-purple: #8b5cf6;
    --accent-orange: #f97316;
    --accent-red: #ef4444;

    /* Testo */
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    /* Border */
    --border-color: #334155;
    --border-focus: #3b82f6;

    /* Ombre */
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.5);

    /* Layout */
    --header-height: 64px;
    --banner-height: 0px;
    --sidebar-width: 320px;
    --sidebar-collapsed-width: 70px;
    --transition-speed: 0.3s;
}

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

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 14px;
    line-height: 1.5;
}

/* ==================== HEADER ==================== */
.header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: var(--shadow-md);
    z-index: 1100;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
}

.dev-banner {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    z-index: 999;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sidebar-toggle {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-speed);
    position: relative;
    z-index: 1200; /* Sopra l'overlay del pannello destro e la header */
}

.sidebar-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.header-title h1 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.header-title p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin: 0;
}

.header-metrics {
    display: flex;
    gap: 20px;
    align-items: center;
}

.metric-badge {
    background: var(--bg-tertiary);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--border-color);
}

.metric-badge .icon {
    font-size: 1rem;
}

.metric-badge .value {
    font-weight: 600;
    color: var(--accent-blue);
}

/* ==================== MAIN CONTAINER ==================== */
.main-container {
    display: flex;
    height: calc(100vh - var(--header-height) - var(--banner-height, 0px));
    margin-top: calc(var(--header-height) + var(--banner-height, 0px));
    position: relative;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
    width: var(--sidebar-width);
    min-width: 280px;
    max-width: 600px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    transition: none; /* Rimosso per ridimensionamento fluido */
    position: relative;
    z-index: 100;
}

/* Stato collassata */
.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
    min-width: var(--sidebar-collapsed-width);
}

/* Nascondi contenuti quando collassata su desktop */
.sidebar.collapsed .filters,
.sidebar.collapsed .results-count,
.sidebar.collapsed .table-container,
.sidebar.collapsed .selected-info,
.sidebar.collapsed .no-geometry-section {
    display: none;
}

/* Resize Handle */
.sidebar-resize-handle {
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 101;
    transition: background 0.2s;
}

.sidebar-resize-handle:hover {
    background: var(--accent-blue);
}

.sidebar-resize-handle:active {
    background: var(--accent-blue);
}

/* Linea verticale visibile durante hover */
.sidebar-resize-handle::before {
    content: '';
    position: absolute;
    right: 2px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: transparent;
    transition: background 0.2s;
}

.sidebar-resize-handle:hover::before {
    background: var(--accent-blue);
}

.sidebar.collapsed .filters,
.sidebar.collapsed .results-count,
.sidebar.collapsed .table-container,
.sidebar.collapsed .selected-info,
.sidebar.collapsed .no-geometry-section {
    display: none;
}

.sidebar.collapsed .sidebar-header {
    padding: 16px 12px;
    justify-content: center;
}

.sidebar-header {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
}

.sidebar-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    min-width: 24px;
}

.sidebar-text {
    transition: opacity var(--transition-speed), width var(--transition-speed);
    opacity: 1;
    width: auto;
}

.sidebar.collapsed .sidebar-text {
    opacity: 0;
    width: 0;
    overflow: hidden;
}

/* ==================== TOOLTIP ==================== */
.sidebar-toggle {
    position: relative;
}

.sidebar-toggle::after {
    content: attr(title);
    position: absolute;
    left: 100%;
    margin-left: 10px;
    padding: 6px 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
}

.sidebar-toggle:hover::after {
    opacity: 1;
}

/* Tooltip per sidebar collapsed */
.sidebar.collapsed .sidebar-icon {
    position: relative;
    cursor: help;
}

.sidebar.collapsed .sidebar-icon::before {
    content: attr(data-tooltip);
    position: absolute;
    left: 100%;
    margin-left: 10px;
    padding: 8px 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.8rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    z-index: 1000;
    box-shadow: var(--shadow-lg);
}

.sidebar.collapsed .sidebar-icon:hover::before {
    opacity: 1;
}

/* ==================== FILTRI ==================== */
.filters {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-bottom: 1px solid var(--border-color);
}

/* Righe di filtri orizzontali */
.filters-row {
    display: flex;
    gap: 8px;
}

.filters-row.filters-actions {
    justify-content: space-between;
    align-items: center;
}

.filter-group {
    flex: 1;
}

.filter-group.compact label {
    font-size: 0.7rem;
    margin-bottom: 4px;
}

.filter-group label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    font-weight: 500;
}

.filter-group select,
.filter-group input[type="text"] {
    width: 100%;
    padding: 6px 8px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: all var(--transition-speed);
}

.filter-group select:focus,
.filter-group input[type="text"]:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.1);
}

.filter-group select option {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.filter-group input[type="checkbox"] {
    margin-right: 6px;
    accent-color: var(--accent-blue);
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 0.8rem;
    user-select: none;
}

.filter-checkbox input {
    margin: 0;
}

.filter-checkbox span {
    color: var(--text-secondary);
}

/* Bottone centrale più piccolo */
.btn-center {
    padding: 6px 12px;
    font-size: 0.8rem;
    white-space: nowrap;
}

/* ==================== BOTTONI ==================== */
.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-speed);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-center {
    width: 100%;
    background: var(--accent-blue);
    color: white;
}

.btn-center:hover {
    background: #2563eb;
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary {
    background: var(--accent-blue);
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

/* ==================== RISULTATI ==================== */
.results-count {
    padding: 12px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
}

/* ==================== TABELLE ==================== */
.table-container {
    flex: 1;
    overflow-y: auto;
    border-bottom: 1px solid var(--border-color);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

thead {
    position: sticky;
    top: 0;
    background: var(--bg-tertiary);
    z-index: 10;
}

th {
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

td {
    padding: 10px 8px;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

tbody tr {
    cursor: pointer;
    transition: background var(--transition-speed);
}

tbody tr:hover {
    background: var(--bg-tertiary);
}

/* Badge */
.tipo-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
}

.tipo-fabbricato {
    background: rgba(59, 130, 246, 0.2);
    color: var(--accent-blue);
}

.tipo-terreno {
    background: rgba(34, 197, 94, 0.2);
    color: var(--accent-green);
}

.tour-badge {
    font-size: 1rem;
}

/* ==================== SELECTED INFO ==================== */
.selected-info {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
}

.selected-info h4 {
    font-size: 1rem;
    color: var(--accent-blue);
    margin-bottom: 12px;
}

.data-table {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.data-row {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 8px;
    font-size: 0.85rem;
}

.data-label {
    color: var(--text-secondary);
    font-weight: 500;
}

.data-value {
    color: var(--text-primary);
    word-break: break-word;
}

.data-value.empty {
    color: var(--text-muted);
    font-style: italic;
}

.action-buttons {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

/* ==================== NO GEOMETRY SECTION ==================== */
.no-geometry-section {
    border-top: 1px solid var(--border-color);
}

.no-geometry-section.collapsed .section-content {
    display: none;
}

.section-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: rgba(249, 115, 22, 0.1);
    cursor: pointer;
    transition: background var(--transition-speed);
}

.section-header:hover {
    background: rgba(249, 115, 22, 0.15);
}

.section-header h4 {
    flex: 1;
    font-size: 0.9rem;
    color: var(--accent-orange);
}

.warning-icon {
    font-size: 1rem;
}

.count-badge {
    background: var(--accent-orange);
    color: white;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

.toggle-icon {
    transition: transform var(--transition-speed);
}

.no-geometry-section.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.section-content {
    max-height: 300px;
    overflow-y: auto;
}

/* ==================== MAP CONTAINER ==================== */
.map-container {
    flex: 1;
    position: relative;
    background: var(--bg-primary);
    overflow: hidden;
}

#map {
    width: 100%;
    height: 100%;
}

/* ==================== LEGENDA ==================== */
.map-legend {
    position: absolute;
    bottom: 20px;
    left: 20px;
    max-width: 200px;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    box-shadow: var(--shadow-lg);
    z-index: 400;
}

.legend-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-primary);
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.legend-items {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 10px;
}

.legend-color {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    flex-shrink: 0;
    border: 2px solid var(--border-color);
}

.legend-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ==================== MODAL ==================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    width: 90%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
}

.modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    z-index: 10;
}

.modal-close:hover {
    background: var(--bg-hover);
}

.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    color: var(--text-primary);
    font-size: 1.1rem;
}

.modal-body {
    flex: 1;
    overflow: hidden;
}

.modal-body iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ==================== RESPONSIVE ==================== */

/* Overlay scuro dietro sidebar su tablet/mobile */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 2400;
    opacity: 0;
    transition: opacity 0.3s;
}

.sidebar-overlay.active {
    opacity: 1;
}

@media (max-width: 1024px) {
    /* Header compatto su tablet */
    :root {
        --header-height: 50px;
    }

    .header-title h1 {
        font-size: 1.05rem;
    }

    .header-title p {
        display: none;
    }

    .sidebar {
        position: fixed;
        left: 0;
        top: var(--header-height);
        height: calc(100% - var(--header-height));
        width: 300px !important;
        min-width: 300px !important;
        max-width: 85vw !important;
        z-index: 2500;
        box-shadow: var(--shadow-lg);
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    /* Sidebar aperta */
    .sidebar.expanded {
        transform: translateX(0) !important;
    }

    /* Sidebar chiusa */
    .sidebar.collapsed {
        transform: translateX(-100%) !important;
    }

    /* Overlay visibile quando sidebar aperta */
    .sidebar-overlay {
        display: block;
    }

    .header-metrics {
        display: none;
    }

    /* Right panel: pannello laterale ridotto */
    .right-panel {
        width: 350px;
        max-width: 85vw;
    }

    .map-legend {
        bottom: 10px;
        left: 10px;
        right: 10px;
        max-width: none;
    }

    .legend-items {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 8px 16px;
    }

    .metric-badge {
        font-size: 0.75rem;
        padding: 6px 10px;
    }

    /* Mappa occupa tutto lo spazio */
    .main-container {
        margin-left: 0 !important;
    }

    .map-container {
        width: 100% !important;
    }
}

@media (max-width: 640px) {
    :root {
        --header-height: 46px;
    }

    .header {
        padding: 0 10px;
    }

    .header-title h1 {
        font-size: 0.95rem;
    }

    .sidebar {
        width: 280px !important;
        min-width: 280px !important;
    }

    /* Right panel fullscreen su mobile */
    .right-panel {
        width: 100%;
        max-width: 100%;
    }

    .right-panel-body {
        padding: 16px;
    }

    .table-container {
        font-size: 0.8rem;
    }

    th, td {
        padding: 8px 4px;
    }

    .sidebar-header {
        padding: 12px;
    }

    .filters {
        padding: 12px;
    }

    /* Nascondi colonne non essenziali su mobile */
    .table-container th:nth-child(2),
    .table-container td:nth-child(2) {
        display: none;
    }
}

/* ==================== SMARTPHONE PORTRAIT (< 400px) ==================== */
@media (max-width: 400px) {
    .sidebar {
        width: 100% !important;
        max-width: 100% !important;
    }
}

/* ==================== ANIMAZIONI E MICRO-INTERAZIONI ==================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(-20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* Animazioni elementi */
.metric-badge,
.map-legend {
    animation: fadeIn 0.4s ease;
}

.filters > * {
    animation: slideIn 0.3s ease backwards;
}

.filters > *:nth-child(1) { animation-delay: 0.05s; }
.filters > *:nth-child(2) { animation-delay: 0.1s; }
.filters > *:nth-child(3) { animation-delay: 0.15s; }
.filters > *:nth-child(4) { animation-delay: 0.2s; }
.filters > *:nth-child(5) { animation-delay: 0.25s; }

/* Hover effects migliorati */
.btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.btn:active {
    transform: translateY(0);
}

tbody tr:hover {
    background: var(--bg-tertiary);
}

/* Loading animation */
.header-metrics:empty::before {
    content: "Caricamento...";
    animation: pulse 1.5s ease-in-out infinite;
}

/* Focus states per accessibilità */
.filter-group select:focus,
.filter-group input:focus,
.btn:focus,
.sidebar-toggle:focus {
    outline: 2px solid var(--accent-blue);
    outline-offset: 2px;
}

/* Stato loading statistiche */
@keyframes shimmer {
    0% {
        background-position: -200% 0;
    }
    100% {
        background-position: 200% 0;
    }
}

.loading-shimmer {
    background: linear-gradient(
        90deg,
        var(--bg-tertiary) 0%,
        var(--bg-hover) 50%,
        var(--bg-tertiary) 100%
    );
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
}

/* ==================== ANIMAZIONI ==================== */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.metric-badge,
.map-legend {
    animation: fadeIn 0.3s ease;
}

/* ==================== LEAFLET OVERRIDES ==================== */
.leaflet-popup-content-wrapper {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    /* Assicura che il popup non esca dallo schermo */
    max-height: 80vh;
    overflow-y: auto;
}

.leaflet-popup-content {
    max-height: 70vh;
    overflow-y: auto;
}

/* Popup personalizzato per immobili */
.custom-immobile-popup {
    max-width: 400px !important;
}

.leaflet-popup-tip {
    background: var(--bg-secondary);
}

/* Popup sempre sopra i controlli mappa */
.leaflet-pane.leaflet-popup-pane {
    z-index: 1150 !important;
}

.leaflet-control-container {
    z-index: 800 !important;
}

.leaflet-popup-close-button {
    font-size: 24px;
    padding: 4px 8px;
}

.leaflet-container {
    background: var(--bg-primary);
}

.leaflet-control-attribution {
    background: var(--bg-secondary);
    color: var(--text-muted);
}

.leaflet-control-zoom {
    border: 1px solid var(--border-color);
}

.leaflet-control-zoom a {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.leaflet-control-zoom a:hover {
    background: var(--bg-tertiary);
}

.leaflet-top {
    z-index: 800;
}

/* Tooltip comuni */
.comune-label {
    background: var(--bg-secondary) !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-primary) !important;
    padding: 4px 8px !important;
    border-radius: 6px !important;
    font-size: 0.75rem !important;
}

/* Popup styles */
.popup-container {
    color: var(--text-primary);
    font-size: 0.8rem; /* Ridotto da default */
}

.popup-header {
    background: var(--bg-tertiary);
    padding: 8px 12px;
    border-radius: 8px 8px 0 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}

.popup-header h3 {
    margin: 0;
    font-size: 0.9rem;
    color: var(--accent-blue);
}

.popup-header .code {
    font-family: 'Courier New', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.popup-body {
    padding: 10px 12px;
    max-height: 400px; /* Limita altezza massima */
    overflow-y: auto;
}

.popup-cover {
    margin-bottom: 8px;
    border-radius: 6px;
    overflow: hidden;
}
.popup-cover img {
    width: 100%;
    max-height: 150px;
    object-fit: cover;
    display: block;
}

.popup-section {
    margin-bottom: 10px;
}

.popup-section h4 {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.popup-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.8rem;
    gap: 8px;
}

.popup-row:last-child {
    border-bottom: none;
}

.popup-row .label {
    color: var(--text-secondary);
    font-weight: 500;
    flex-shrink: 0;
}

.popup-row .value {
    color: var(--text-primary);
    text-align: right;
    word-break: break-word;
}

.popup-row .value.empty {
    color: var(--text-muted);
    font-style: italic;
}

.popup-actions {
    display: flex;
    gap: 6px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border-color);
}

.popup-actions .btn {
    font-size: 0.75rem;
    padding: 6px 12px;
}

/* ==================== RIGHT PANEL (Senza Geometria) ==================== */
.right-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 400px;
    max-width: 90vw;
    z-index: 1500;
    pointer-events: none;
    opacity: 0 !important;
    visibility: hidden !important;
    transform: translateX(100%) !important; /* Sposta completamente fuori dallo schermo */
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

.right-panel.active {
    pointer-events: auto;
    opacity: 1 !important;
    visibility: visible !important;
    transform: translateX(0) !important;
}

.right-panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.right-panel.active .right-panel-overlay {
    opacity: 1;
}

.right-panel-content {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
    /* Transform rimosso - gestito dal parent .right-panel */
    display: flex;
    flex-direction: column;
}

.right-panel-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-tertiary);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.right-panel-header h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin: 0;
}

.right-panel-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-hover);
    color: var(--text-primary);
    border-radius: 8px;
    cursor: pointer;
    font-size: 1.5rem;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.right-panel-close:hover {
    background: var(--accent-orange);
    color: white;
}

.right-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Contenuto del pannello destro */
.right-panel-section {
    margin-bottom: 24px;
}

.right-panel-section h4 {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.right-panel-data-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.right-panel-data-row:last-child {
    border-bottom: none;
}

.right-panel-data-label {
    color: var(--text-secondary);
    font-weight: 500;
    flex-shrink: 0;
}

.right-panel-data-value {
    color: var(--text-primary);
    text-align: right;
    word-break: break-word;
}

.right-panel-data-value.empty {
    color: var(--text-muted);
    font-style: italic;
}

.right-panel-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

/* Responsive pannello destro - gestito nei breakpoint sopra */

/* ==================== STATO RILIEVI ==================== */

/* Colonna stato nella tabella */
.stato-cell {
    width: 40px;
    text-align: center;
}

.stato-cell span {
    font-size: 1.1rem;
}

.visionato {
    color: #16a34a; /* Verde */
}

.da-visionare {
    color: #ea580c; /* Arancione */
}

/* Stato rilievi nel popup */
.stato-rilievo {
    padding: 10px;
    border-radius: 6px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}

.stato-rilievo.visionato {
    background: rgba(22, 163, 74, 0.15);
    color: #16a34a;
}

.stato-rilievo.da-visionare {
    background: rgba(234, 88, 12, 0.15);
    color: #ea580c;
}

.stato-icona {
    font-size: 1.3rem;
}

.stato-testo {
    flex: 1;
}

.rilievo-type {
    font-size: 0.85rem;
    padding: 3px 8px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.1);
}
/* Liste multi-valore nel popup */
.multi-value-list {
    margin: 0;
    padding-left: 20px;
    list-style-type: disc;
}

.multi-value-list li {
    margin: 4px 0;
    line-height: 1.4;
}

.multi-value-list li:first-child {
    margin-top: 0;
}

.multi-value-list li:last-child {
    margin-bottom: 0;
}

/* ==================== ALERT DUPLICATI ==================== */

.duplicati-alert {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.4);
    border-radius: 8px;
    padding: 12px 20px;
    margin: 12px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
}

.duplicati-alert .alert-icon {
    font-size: 1.2rem;
}

.duplicati-alert .alert-text {
    flex: 1;
    font-size: 0.95rem;
}

.duplicati-alert .alert-text a {
    color: #dc2626;
    text-decoration: underline;
    font-weight: 600;
}

.duplicati-alert .alert-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.duplicati-alert .alert-close:hover {
    color: #dc2626;
}

/* ==================== BADGE DUPLICATO ==================== */

.duplicato-badge {
    display: inline-block;
    margin-left: 6px;
    font-size: 0.9rem;
    animation: pulse 2s infinite;
    cursor: help;
}

.duplicato-row {
    background: rgba(239, 68, 68, 0.1) !important;
    border-left: 3px solid #dc2626;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.8; transform: scale(1.1); }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ==================== MODALE DUPLICATI ==================== */

.duplicati-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.3s ease;
}

.duplicati-modal-content {
    background: var(--bg-primary);
    border-radius: 12px;
    max-width: 900px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.duplicati-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
}

.duplicati-modal-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: var(--text-primary);
}

.duplicati-modal-header .btn-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.duplicati-modal-header .btn-close:hover {
    color: var(--text-primary);
}

.duplicati-modal-body {
    padding: 24px;
    overflow-y: auto;
}

.duplicati-modal-body p {
    margin: 0 0 16px 0;
    color: var(--text-secondary);
}

.duplicati-table {
    width: 100%;
    border-collapse: collapse;
    margin: 16px 0;
}

.duplicati-table thead {
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
}

.duplicati-table th {
    padding: 12px 8px;
    text-align: left;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
}

.duplicati-table td {
    padding: 10px 8px;
    font-size: 0.85rem;
    border-bottom: 1px solid var(--border-color);
}

.duplicati-table .duplicato-row {
    background: rgba(239, 68, 68, 0.1) !important;
}

.duplicati-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ==================== TAB SYSTEM ==================== */

/* Tab Navigation */
.tab-navigation {
    display: flex;
    gap: 4px;
    padding: 8px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-top: 8px;
}

.tab-button {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px;
    background: transparent;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
    color: var(--text-secondary);
}

.tab-button:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.tab-button.active {
    background: var(--accent-blue);
    color: white;
}

.tab-icon {
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tab-icon svg { width: 16px; height: 16px; }

.tab-label {
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.tab-count {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--accent-red);
    color: white;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 10px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

/* Tab Content Container */
.tab-content-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    position: relative;
    min-height: 0; /* Importante per flex scroll */
}

/* Tab Content */
.tab-content {
    display: none;
    max-height: none;
    overflow-y: auto;
    padding: 12px;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
    animation: fadeIn 0.3s ease;
    /* Assicura che il contenuto sia scrollabile */
    flex: 1;
    min-height: 0;
}

/* ==================== FILTERS SECTIONS ==================== */

.filters-section {
    margin-bottom: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
}

.filters-section .section-title {
    padding: 10px 12px;
    margin: 0;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
    background: var(--bg-hover);
}

.filters-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding: 10px 12px;
}

@media (max-width: 400px) {
    .filters-grid {
        grid-template-columns: 1fr;
    }
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.filter-group label {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.filter-group select,
.filter-group input[type="text"] {
    padding: 8px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: all 0.2s;
}

.filter-group select:focus,
.filter-group input[type="text"]:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* Filters Advanced (collapsible) */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: 12px;
    background: var(--bg-hover);
    transition: background 0.2s;
}

.section-header:hover {
    background: var(--bg-hover);
}

.toggle-icon {
    transition: transform 0.3s ease;
    font-size: 0.8rem;
}

.section-header.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

.filters-advanced {
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.filters-advanced.collapsed {
    max-height: 0;
}

/* ==================== FILTRI QUICK - COLLABSLABILI ==================== */

.section-header-quick {
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    user-select: none;
    padding: 12px 16px;
    background: rgba(34, 197, 94, 0.1); /* Verde chiaro per distinguerlo */
    border-radius: 8px;
    margin-bottom: 8px;
    transition: background 0.2s ease;
}

.section-header-quick:hover {
    background: rgba(34, 197, 94, 0.15);
}

.section-header-quick .section-title {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.section-header-quick .toggle-icon {
    transition: transform 0.3s ease;
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.section-header-quick.collapsed .toggle-icon {
    transform: rotate(-90deg);
}

/* Stati collassati per filters-quick */
.filters-quick {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}

.filters-quick.collapsed {
    max-height: 0;
    padding: 0;
    margin: 0;
}

/* Range Slider */
.range-slider {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.range-slider input[type="range"] {
    width: 100%;
    height: 6px;
    border-radius: 3px;
    background: var(--bg-primary);
    outline: none;
    -webkit-appearance: none;
}

.range-slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: pointer;
}

.range-slider input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--accent-blue);
    cursor: pointer;
    border: none;
}

.range-values {
    display: flex;
    justify-content: space-between;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Filters Quick (checkboxes) */
.filters-quick {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.filter-checkbox {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-primary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
}

.filter-checkbox:hover {
    background: var(--bg-hover);
    border-color: var(--border-color);
}

.filter-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.checkbox-label {
    flex: 1;
    font-size: 0.85rem;
    color: var(--text-primary);
}

.checkbox-count {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-blue);
    background: var(--bg-tertiary);
    padding: 4px 8px;
    border-radius: 12px;
}

/* Filters Actions */
.filters-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    padding: 12px;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.filters-actions .btn-center {
    grid-column: 1 / -1;
}

.btn {
    padding: 10px 16px;
    border: none;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary {
    background: var(--accent-blue);
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--bg-tertiary);
}

.btn-center {
    background: var(--accent-green);
    color: white;
}

.btn-center:hover {
    background: #16a34a;
    transform: translateY(-1px);
}

/* Active Filters */
.active-filters {
    padding: 12px;
    background: var(--accent-blue);
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
    border-radius: 8px;
    margin-top: 8px;
}

.active-filters h4 {
    margin: 0 0 8px 0;
    font-size: 0.85rem;
    color: white;
}

.active-filters-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.active-filter-tag {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: white;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--bg-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.active-filter-tag .remove {
    cursor: pointer;
    color: var(--accent-red);
    font-weight: 700;
    font-size: 1rem;
    line-height: 1;
}

.active-filter-tag .remove:hover {
    color: #dc2626;
}

/* ==================== RESULTS HEADER ==================== */

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 16px;
}

.results-count-large {
    text-align: center;
}

.count-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-blue);
    line-height: 1;
}

.count-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.results-sort {
    display: flex;
    align-items: center;
    gap: 8px;
}

.results-sort label {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.results-sort select {
    padding: 6px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.8rem;
    cursor: pointer;
}

.sort-direction {
    padding: 6px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    transition: all 0.2s;
}

.sort-direction:hover {
    background: var(--bg-hover);
}

/* ==================== TABLE ENHANCED ==================== */

.table-container-enhanced {
    flex: 1;
    overflow: auto;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 16px;
}

#table-immobili-enhanced {
    width: 100%;
    border-collapse: collapse;
}

#table-immobili-enhanced th {
    position: sticky;
    top: 0;
    background: var(--bg-hover);
    padding: 12px 8px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border-color);
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
    z-index: 10;
}

#table-immobili-enhanced th:hover {
    background: var(--bg-primary);
}

#table-immobili-enhanced td {
    padding: 10px 8px;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

#table-immobili-enhanced tbody tr {
    cursor: pointer;
    transition: background 0.2s;
}

#table-immobili-enhanced tbody tr:hover {
    background: var(--bg-hover);
}

/* Colonne specifiche */
.col-prog { width: 50px; text-align: center; font-weight: bold; }
.prog-cell { text-align: center; font-weight: bold; color: var(--accent-color); }
.col-stato { width: 40px; text-align: center; }
.col-codice { width: 100px; }
.col-comune { min-width: 120px; }
.col-foglio { width: 50px; text-align: center; }
.col-particella { width: 70px; text-align: center; }
.col-sub { width: 40px; text-align: center; }
.col-categoria { width: 60px; }
.col-superficie { width: 90px; text-align: right; }
.col-tour { width: 40px; text-align: center; }

/* ==================== COLORI RIGHE TABELLA PER TIPO ==================== */

/* ==================== COLORI RIGHE TABELLA PER TIPO (FIXED) ==================== */

/* FIX: Con border-collapse: collapse, i bordi su TR non sono visibili
   Soluzione: Applicare bordo alla PRIMA CELLA (td:first-child) */

/* Imposta bordo trasparente di default sulla prima cella */
#table-immobili-enhanced tbody tr td:first-child,
#tbody-no-geometry-enhanced tr td:first-child {
    border-left: 4px solid transparent;
}

/* Fabbricati - Bordo blu sulla prima cella */
.row-fabbricato td:first-child {
    border-left-color: #3b82f6 !important;
}

/* Terreni - Bordo verde sulla prima cella */
.row-terreno td:first-child {
    border-left-color: #22c55e !important;
}

/* Senza geometria - Bordo grigio medio sulla prima cella */
.row-senza-geometria td:first-child {
    border-left-color: #6b7280 !important;
}

/* Effetto hover per le righe */
#table-immobili-enhanced tbody tr:hover,
#tbody-no-geometry-enhanced tr:hover {
    background: var(--bg-hover);
}

/* ==================== PAGINATION ==================== */

.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    flex-wrap: wrap;
}

.pagination-btn {
    padding: 8px 16px;
    background: var(--accent-blue);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}

.pagination-btn:hover:not(:disabled) {
    background: #2563eb;
    transform: translateY(-1px);
}

.pagination-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.pagination-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.pagination-per-page {
    padding: 6px 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 0.85rem;
    cursor: pointer;
}

/* ==================== STATS DASHBOARD ==================== */

.stats-dashboard {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

/* Stats Cards Grid */
.stats-cards-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.stat-card {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--bg-tertiary);
    border-radius: 8px;
    transition: all 0.2s;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    font-size: 2rem;
    line-height: 1;
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-blue);
    line-height: 1;
}

.stat-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Charts */
.stats-charts {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 600px) {
    .stats-charts {
        grid-template-columns: 1fr;
    }
}

.chart-section {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 8px;
}

.chart-section h4 {
    margin: 0 0 12px 0;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.chart-bars,
.chart-pie {
    min-height: 200px;
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

/* Bar Chart */
.chart-bar {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.bar-fill {
    width: 100%;
    background: var(--accent-blue);
    border-radius: 4px 4px 0 0;
    transition: height 0.3s ease;
    min-height: 4px;
}

.bar-label {
    font-size: 0.65rem;
    color: var(--text-secondary);
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.bar-value {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Pie Chart */
.pie-chart {
    display: flex;
    height: 100%;
    border-radius: 8px;
    overflow: hidden;
}

.pie-segment {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 12px;
    transition: all 0.2s;
}

.pie-segment:hover {
    opacity: 0.9;
}

.pie-segment.fabbricati {
    background: var(--accent-blue);
}

.pie-segment.terreni {
    background: var(--accent-green);
}

/* Stats Tables */
.stats-table-section {
    background: var(--bg-tertiary);
    padding: 16px;
    border-radius: 8px;
}

.stats-table-section h4 {
    margin: 0 0 12px 0;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.stats-table th {
    padding: 10px 8px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border-bottom: 2px solid var(--border-color);
}

.stats-table td {
    padding: 10px 8px;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-primary);
}

.stats-table tbody tr:hover {
    background: var(--bg-primary);
}

/* ==================== RESPONSIVE ADJUSTMENTS ==================== */

@media (max-width: 640px) {
    .tab-navigation {
        padding: 6px;
        gap: 2px;
    }

    .tab-label {
        font-size: 0.65rem;
    }

    .tab-icon {
        font-size: 1rem;
    }

    .filters-grid {
        grid-template-columns: 1fr;
        gap: 8px;
        padding: 8px;
    }

    .stats-cards-grid {
        grid-template-columns: 1fr;
    }

    .results-header {
        flex-direction: column;
        gap: 12px;
        padding: 12px;
    }

    .results-sort {
        width: 100%;
        justify-content: space-between;
    }

    .results-sort select {
        flex: 1;
    }

    #table-immobili-enhanced th,
    #table-immobili-enhanced td {
        padding: 8px 4px;
        font-size: 0.75rem;
    }

    /* Hide less important columns on mobile */
    .col-categoria,
    .col-superficie {
        display: none;
    }
}

/* ==================== SYNC BUTTON ==================== */
.sync-button {
    width: 100%;
    padding: 12px 16px;
    margin-bottom: 16px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.sync-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.sync-button:active {
    transform: translateY(0);
}

.sync-button.syncing {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
    cursor: not-allowed;
    pointer-events: none;
}

.sync-button.syncing .sync-icon {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ==================== TOAST NOTIFICATION ==================== */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    min-width: 300px;
    padding: 16px;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 12px;
    animation: slideIn 0.3s ease;
    border-left: 4px solid #3b82f6;
}

.toast.success {
    border-left-color: #22c55e;
}

.toast.error {
    border-left-color: #ef4444;
}

.toast.warning {
    border-left-color: #f59e0b;
}

.toast-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    margin-bottom: 4px;
    color: #1f2937;
}

.toast-message {
    font-size: 0.875rem;
    color: #6b7280;
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.25rem;
    color: #9ca3af;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.toast-close:hover {
    background: #f3f4f6;
    color: #6b7280;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes slideOut {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

.toast.hiding {
    animation: slideOut 0.3s ease forwards;
}

/* ==================== POPUP LEAFLET - X CHIUSURA MIGLIORATA ==================== */

/* Popup personalizzato */
.custom-immobile-popup {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
}

/* ✅ FIX: Rende la X di chiusura MOLTO più visibile */
.custom-immobile-popup .leaflet-popup-close-button {
    width: 32px !important;
    height: 32px !important;
    font-size: 28px !important;
    line-height: 1 !important;
    text-align: center !important;
    color: #ffffff !important;
    background: #ef4444 !important;
    border: 2px solid #ffffff !important;
    border-radius: 50% !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4) !important;
    transition: all 0.2s ease !important;
    top: 8px !important;
    right: 8px !important;
    /* ✅ CRITICAL FIX: Z-index molto alto per stare sopra TUTTO il contenuto popup */
    z-index: 9999 !important;
    /* ✅ CRITICAL FIX: Centra verticalmente la X */
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 0 !important;
}

/* Hover sulla X - ancora più visibile */
.custom-immobile-popup .leaflet-popup-close-button:hover {
    background: #dc2626 !important;
    transform: scale(1.1) !important;
    box-shadow: 0 4px 12px rgba(220, 38, 38, 0.6) !important;
}

/* Focus per accessibilità */
.custom-immobile-popup .leaflet-popup-close-button:focus {
    outline: 2px solid #3b82f6 !important;
    outline-offset: 2px !important;
}

/* ==================== BANNER DI AVVISO ==================== */
/* Banner di avviso per immobili senza geometria */
.warning-banner {
    background: rgba(249, 115, 22, 0.15);
    padding: 12px;
    border-radius: 8px;
    color: var(--accent-orange);
    margin-bottom: 16px;
    font-size: 0.85rem;
    border: 1px solid rgba(249, 115, 22, 0.3);
}

/* Nota: lo stile inline è già presente nel codice JS, questo CSS è ridondante ma consigliato per manutenibilità */

/* ==================== FORM EDITING IMMOBILI ==================== */
/**
 * Stili per il form di compilazione dati immobili
 * Utilizzato durante il disegno di nuove particelle
 */

.property-form {
    min-width: 300px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

.property-form h3 {
    margin: 0 0 15px 0;
    color: #1f2937;
    font-size: 16px;
    font-weight: 700;
    border-bottom: 2px solid #3b82f6;
    padding-bottom: 8px;
}

.property-form .form-group {
    margin-bottom: 12px;
}

.property-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 4px;
    color: #374151;
    font-size: 13px;
}

.property-form input,
.property-form select {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 14px;
    box-sizing: border-box;
    transition: all 0.2s;
    background: white;
}

.property-form input:focus,
.property-form select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.property-form input::placeholder {
    color: #9ca3af;
}

.property-form .form-actions {
    display: flex;
    gap: 8px;
    margin-top: 15px;
}

.property-form .btn-save,
.property-form .btn-cancel {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 6px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
}

.property-form .btn-save {
    background: #22c55e;
}

.property-form .btn-save:hover {
    background: #16a34a;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(34, 197, 94, 0.2);
}

.property-form .btn-cancel {
    background: #ef4444;
}

.property-form .btn-cancel:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 6px rgba(239, 68, 68, 0.2);
}

/* Popup personalizzato per form */
.property-popup .leaflet-popup-content-wrapper {
    border-radius: 12px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    padding: 0;
}

.property-popup .leaflet-popup-content {
    margin: 16px;
}

.property-popup .leaflet-popup-tip {
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

/* ==============================================================================
   PROPERTY EDITOR PANEL
   ============================================================================== */

.property-editor {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 2000;
}

.property-editor-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.4);
}

.property-editor-content {
    position: absolute;
    top: 0;
    right: 0;
    width: 450px;
    height: 100%;
    background: var(--bg-secondary, #1e293b);
    color: var(--text-primary, #f1f5f9);
    box-shadow: -4px 0 20px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.25s ease-out;
}

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.property-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, #334155);
    flex-shrink: 0;
}

.property-editor-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--accent-blue, #3b82f6);
}

.property-editor-body {
    flex: 1;
    overflow-y: auto;
    padding: 12px 20px 20px;
}

.pe-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--accent-blue, #3b82f6);
    margin: 16px 0 8px;
    padding-bottom: 4px;
    border-bottom: 1px solid var(--border-color, #334155);
}

.pe-section {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.pe-field {
    width: 100%;
}

.pe-field.pe-half {
    width: calc(50% - 4px);
}

.pe-field.pe-third {
    width: calc(33.33% - 6px);
}

.pe-field label {
    display: block;
    font-size: 0.72rem;
    color: var(--text-secondary, #94a3b8);
    margin-bottom: 2px;
    font-weight: 500;
}

.pe-field input,
.pe-field select,
.pe-field textarea {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color, #334155);
    border-radius: 4px;
    background: var(--bg-tertiary, #0f172a);
    color: var(--text-primary, #f1f5f9);
    font-size: 0.85rem;
    font-family: inherit;
}

.pe-field input:focus,
.pe-field select:focus,
.pe-field textarea:focus {
    outline: none;
    border-color: var(--accent-blue, #3b82f6);
    box-shadow: 0 0 0 2px rgba(59,130,246,0.2);
}

.pe-field input.pe-readonly {
    background: var(--bg-primary, #0f172a);
    color: var(--accent-blue, #3b82f6);
    font-weight: 600;
    cursor: default;
}

.pe-field input:required {
    border-left: 2px solid var(--accent-blue, #3b82f6);
}

.pe-actions {
    display: flex;
    gap: 8px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-color, #334155);
    position: sticky;
    bottom: 0;
    background: var(--bg-secondary, #1e293b);
    padding-bottom: 8px;
}

.pe-actions .btn {
    flex: 1;
    padding: 10px;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    border-radius: 6px;
    font-weight: 600;
}

.pe-actions .btn-danger {
    background: #dc2626;
    color: white;
}

.pe-actions .btn-danger:hover {
    background: #b91c1c;
}

@media (max-width: 500px) {
    .property-editor-content {
        width: 100%;
    }
}

/* ==================== PERCORSO RILIEVO ==================== */

/* Toggle button (overlay sulla mappa) */
.route-toggle-btn {
    position: absolute;
    top: 10px;
    left: 60px;
    z-index: 1000;
    width: 42px;
    height: 42px;
    border-radius: 8px;
    border: none;
    background: var(--bg-secondary);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
    transition: background 0.2s, color 0.2s;
}

.route-toggle-btn:hover {
    background: var(--accent-blue);
    color: #fff;
}

.route-toggle-btn.active {
    background: #f59e0b;
    color: #fff;
    animation: route-pulse 2s ease-in-out infinite;
}

@keyframes route-pulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
    50% { box-shadow: 0 2px 16px rgba(245,158,11,0.6); }
}

/* Route Panel */
.route-panel {
    position: absolute;
    top: 10px;
    left: 110px;
    z-index: 1000;
    width: 320px;
    max-height: calc(100vh - 120px);
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.route-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(245,158,11,0.08);
}

.route-panel-header h3 {
    margin: 0;
    font-size: 0.9rem;
    font-weight: 600;
    color: #f59e0b;
}

.route-panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.route-panel-close:hover {
    color: var(--text-primary);
}

.route-panel-instructions {
    padding: 10px 16px;
    font-size: 0.8rem;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

/* Waypoint list */
.route-panel-list {
    overflow-y: auto;
    max-height: 300px;
    flex: 1;
}

.route-waypoint {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.82rem;
    transition: background 0.15s;
}

.route-waypoint:hover {
    background: var(--bg-tertiary);
}

.route-waypoint.active-waypoint {
    background: rgba(245,158,11,0.15);
    border-left: 3px solid #f59e0b;
}

.route-waypoint.reached {
    opacity: 0.5;
}

.route-waypoint-num {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--accent-blue);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 700;
    flex-shrink: 0;
}

.route-waypoint.reached .route-waypoint-num {
    background: var(--accent-green);
}

.route-waypoint.active-waypoint .route-waypoint-num {
    background: #f59e0b;
}

.route-waypoint-info {
    flex: 1;
    min-width: 0;
}

.route-waypoint-code {
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.route-waypoint-detail {
    font-size: 0.72rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.route-waypoint-dist {
    font-size: 0.75rem;
    color: var(--accent-blue);
    font-weight: 600;
    white-space: nowrap;
}

.route-waypoint-actions {
    display: flex;
    gap: 2px;
}

.route-wp-btn {
    width: 24px;
    height: 24px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    padding: 0;
}

.route-wp-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.route-wp-btn.remove:hover {
    color: var(--accent-red);
}

/* Stats */
.route-panel-stats {
    display: flex;
    gap: 16px;
    padding: 8px 16px;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-primary);
}

.route-stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.route-stat-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
}

.route-stat-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-primary);
}

/* Actions */
.route-panel-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 10px 16px;
}

.route-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 14px !important;
    font-size: 0.8rem !important;
    border-radius: 6px !important;
}

/* Navigation HUD */
.route-nav-hud {
    padding: 12px 16px;
    background: rgba(245,158,11,0.1);
    border-top: 2px solid #f59e0b;
}

.route-nav-next {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-bottom: 8px;
}

.route-nav-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    color: var(--text-muted);
}

.route-nav-name {
    font-size: 0.9rem;
    font-weight: 700;
    color: #f59e0b;
}

.route-nav-distance {
    display: flex;
    align-items: baseline;
    gap: 4px;
    margin-bottom: 8px;
}

.route-nav-dist-value {
    font-size: 1.8rem;
    font-weight: 800;
    color: var(--text-primary);
    line-height: 1;
}

.route-nav-dist-unit {
    font-size: 0.9rem;
    color: var(--text-muted);
}

.route-nav-progress {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.route-nav-progress span {
    font-size: 0.72rem;
    color: var(--text-muted);
}

.route-nav-progress-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.route-nav-progress-fill {
    height: 100%;
    background: #f59e0b;
    border-radius: 2px;
    transition: width 0.3s;
}

/* Tablet responsive */
@media (max-width: 1024px) {
    .route-toggle-btn {
        width: 48px;
        height: 48px;
        left: 12px;
        top: 12px;
    }

    .route-panel {
        left: 12px;
        top: 68px;
        width: 300px;
        max-height: calc(100vh - 160px);
    }

    .route-waypoint {
        padding: 10px 16px;
    }

    .route-wp-btn {
        width: 32px;
        height: 32px;
    }
}

/* Mobile */
@media (max-width: 600px) {
    .route-panel {
        left: 8px;
        right: 8px;
        width: auto;
        top: 64px;
        max-height: 50vh;
    }

    .route-toggle-btn {
        left: 10px;
    }
}

/* ==================== USER BADGE (Auth) ==================== */

.user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
    padding: 4px 10px;
    background: rgba(255,255,255,0.05);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 0.8rem;
    flex-shrink: 0;
}

.user-badge-name {
    color: var(--text-primary);
    font-weight: 500;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-badge-role {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.badge-admin {
    background: rgba(245,158,11,0.2);
    color: #f59e0b;
}

.badge-user {
    background: rgba(59,130,246,0.2);
    color: #60a5fa;
}

.badge-lettore {
    background: rgba(156,163,175,0.2);
    color: #9ca3af;
}

.user-badge-admin-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 1rem;
    transition: color 0.2s;
}

.user-badge-admin-link:hover {
    color: var(--accent-blue);
}

.user-badge-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 2px 4px;
    border-radius: 4px;
    transition: color 0.2s, background 0.2s;
}

.user-badge-logout:hover {
    color: var(--accent-red);
    background: rgba(220,38,38,0.15);
}

.user-badge-login {
    color: var(--accent-blue);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid var(--accent-blue);
    transition: background 0.2s, color 0.2s;
}
.user-badge-login:hover {
    background: var(--accent-blue);
    color: #fff;
}

@media (max-width: 768px) {
    .user-badge-name {
        display: none;
    }

    .user-badge {
        padding: 4px 8px;
        gap: 6px;
    }
}

/* ===================== VERIFICA BADGES ===================== */

.verifica-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.verifica-badge.da-verificare {
    background: rgba(156, 163, 175, 0.2);
    color: #9ca3af;
}

.verifica-badge.in-lavorazione {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.verifica-badge.verificato {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

.verifica-badge.approvato {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

/* Badge nel popup mappa */
.popup-verifica-badge {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border-color, #333);
}

/* Colonna verifica nel registro */
.col-verifica {
    width: 110px;
    text-align: center;
}

/* ==========================================
   SIDEBAR RESTYLING v2
   ========================================== */

/* Sync button compatto nella tab navigation */
.sync-button-compact {
    width: 36px;
    height: 36px;
    min-width: 36px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    margin-left: 4px;
}
.sync-button-compact:hover {
    color: #a78bfa;
    border-color: #a78bfa;
    background: rgba(139, 92, 246, 0.1);
}
.sync-button-compact.syncing svg {
    animation: spin 1s linear infinite;
}

/* ===== SYNC DIALOG ===== */
.sync-dialog-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.sync-dialog {
    background: var(--bg-secondary, #1e293b);
    border: 1px solid var(--border-color, #334155);
    border-radius: 12px;
    max-width: 520px;
    width: 100%;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
    color: var(--text-primary, #f1f5f9);
}
.sync-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color, #334155);
}
.sync-dialog-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}
.sync-dialog-close {
    background: none;
    border: none;
    color: var(--text-secondary, #94a3b8);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
}
.sync-dialog-close:hover {
    background: rgba(255,255,255,0.1);
    color: var(--text-primary, #f1f5f9);
}
.sync-dialog-body {
    padding: 16px 20px;
}
.sync-section {
    margin-bottom: 14px;
}
.sync-section h4 {
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary, #94a3b8);
    margin: 0 0 8px;
}
.sync-desc {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary, #94a3b8);
    margin: 0;
}
.sync-file-status {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.85rem;
    margin-bottom: 8px;
}
.sync-file-ok {
    background: rgba(34,197,94,0.1);
    border: 1px solid rgba(34,197,94,0.3);
}
.sync-file-missing {
    background: rgba(245,158,11,0.1);
    border: 1px solid rgba(245,158,11,0.3);
    color: #f59e0b;
}
.sync-upload-area {
    margin-top: 8px;
}
.sync-upload-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    background: var(--bg-primary, #0f172a);
    border: 1px dashed var(--border-color, #334155);
    border-radius: 6px;
    color: var(--accent-blue, #3b82f6);
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s;
}
.sync-upload-btn:hover {
    background: rgba(59,130,246,0.1);
    border-color: var(--accent-blue, #3b82f6);
}
.sync-protected-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.sync-tag {
    padding: 3px 8px;
    background: rgba(139,92,246,0.15);
    border: 1px solid rgba(139,92,246,0.3);
    border-radius: 4px;
    font-size: 0.75rem;
    color: #a78bfa;
    font-family: monospace;
}
.sync-last-info {
    font-size: 0.78rem;
    color: var(--text-secondary, #94a3b8);
    padding-top: 8px;
    border-top: 1px solid var(--border-color, #334155);
}
.sync-dialog-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 20px;
    border-top: 1px solid var(--border-color, #334155);
}
.sync-btn-cancel {
    padding: 8px 16px;
    background: transparent;
    border: 1px solid var(--border-color, #334155);
    color: var(--text-secondary, #94a3b8);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
}
.sync-btn-cancel:hover {
    background: rgba(255,255,255,0.05);
}
.sync-btn-confirm {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 18px;
    background: var(--accent-blue, #3b82f6);
    border: none;
    color: #fff;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}
.sync-btn-confirm:hover:not(:disabled) {
    background: #2563eb;
}
.sync-btn-confirm:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.sync-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Sync result dialog */
.sync-result-dialog {
    max-width: 400px;
    text-align: center;
}
.sync-result-badges {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin: 12px 0;
}
.sync-result-badge {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 18px;
    border-radius: 10px;
    min-width: 80px;
}
.sync-badge-num {
    font-size: 1.8rem;
    font-weight: 700;
    line-height: 1;
}
.sync-badge-label {
    font-size: 0.75rem;
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.sync-badge-inserted {
    background: rgba(34,197,94,0.15);
    color: #22c55e;
}
.sync-badge-updated {
    background: rgba(59,130,246,0.15);
    color: #3b82f6;
}
.sync-badge-errors {
    background: rgba(100,116,139,0.15);
    color: #64748b;
}
.sync-badge-errors.has-errors {
    background: rgba(239,68,68,0.15);
    color: #ef4444;
}
.sync-result-note {
    font-size: 0.8rem;
    color: var(--text-secondary, #94a3b8);
    margin: 12px 0 0;
}

/* Divider tra sezioni filtri */
.filter-divider {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 10px 0;
}

/* Search row */
.filter-search-row {
    padding: 0 12px 4px;
}
.filter-search-row input {
    width: 100%;
    padding: 10px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    min-height: 44px;
    box-sizing: border-box;
}
.filter-search-row input:focus {
    border-color: var(--border-focus);
    outline: none;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* Quick Toggles - chip grid */
.quick-toggles {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 0 12px;
}
.toggle-chip {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.78rem;
    color: var(--text-secondary);
    transition: all 0.15s;
    user-select: none;
    min-height: 44px;
    box-sizing: border-box;
}
.toggle-chip:hover {
    border-color: var(--accent-blue);
    color: var(--text-primary);
}
.toggle-chip input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}
.toggle-chip svg {
    flex-shrink: 0;
    opacity: 0.6;
}
/* Active state */
.toggle-chip:has(input:checked),
.toggle-chip.checked {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--accent-blue);
    color: var(--accent-blue);
}
.toggle-chip:has(input:checked) svg,
.toggle-chip.checked svg {
    opacity: 1;
}
.toggle-chip--danger:has(input:checked),
.toggle-chip--danger.checked {
    background: rgba(239, 68, 68, 0.15);
    border-color: var(--accent-red);
    color: var(--accent-red);
}
.chip-label { flex: 1; }
.chip-count {
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 22px;
    text-align: center;
}

/* Collapsible trigger */
.collapsible-trigger {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    min-height: 44px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    box-sizing: border-box;
}
.collapsible-trigger:hover {
    background: var(--bg-hover);
}
.collapsible-trigger .chevron-icon {
    transition: transform 0.3s;
}
.collapsible-trigger.collapsed .chevron-icon {
    transform: rotate(-90deg);
}
.collapsible-body {
    max-height: 600px;
    overflow: hidden;
    transition: max-height 0.3s ease;
}
.collapsible-body.collapsed {
    max-height: 0;
}

/* Actions sticky */
.filters-actions-sticky {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    position: sticky;
    bottom: 0;
    z-index: 5;
    margin-top: auto;
}
.filters-actions-sticky .btn {
    flex: 1;
    padding: 10px 8px;
    font-size: 0.82rem;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

/* Touch targets migliorati */
.filter-group select,
.filter-group input[type="text"] {
    min-height: 44px;
    padding: 10px 12px;
}

/* Tablet breakpoint 768px */
@media (max-width: 768px) {
    .quick-toggles {
        grid-template-columns: 1fr 1fr 1fr;
    }
    .tab-button {
        padding: 12px 8px;
        min-height: 48px;
    }
    .filters-actions-sticky .btn {
        min-height: 48px;
        font-size: 0.85rem;
    }
}

/* Lista particelle mancanti */
.mancanti-list {
    margin: 6px 12px;
    border: 1px solid var(--border-color, #333);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary, #1a1a2e);
}
.mancanti-list-title {
    font-size: 0.7rem;
    font-weight: 600;
    color: #dc2626;
    padding: 6px 10px 2px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.mancanti-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    border-top: 1px solid var(--border-color, #333);
    transition: background 0.15s;
    font-size: 0.8rem;
    color: var(--text-primary, #e0e0e0);
}
.mancanti-item:first-of-type {
    border-top: none;
}
.mancanti-item:hover {
    background: rgba(220, 38, 38, 0.15);
}
.mancanti-item-icon {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #dc2626;
}
.mancanti-item-label {
    flex: 1;
    line-height: 1.3;
}
.mancanti-item-arrow {
    flex-shrink: 0;
    color: #888;
    font-size: 0.75rem;
}
.mancanti-actions {
    display: flex;
    gap: 6px;
    padding: 4px 10px 8px 26px;
}
.mancanti-btn {
    flex: 1;
    padding: 4px 8px;
    border: none;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s;
}
.mancanti-btn:hover { opacity: 0.85; }
.mancanti-btn--add {
    background: #16a34a;
    color: #fff;
}
.mancanti-btn--discard {
    background: #555;
    color: #ccc;
}

/* ==================== CATASTO SEARCH TAB ==================== */

.catasto-search-panel {
    padding: 4px 0;
}

.catasto-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.catasto-subtitle {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.catasto-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

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

.catasto-field label {
    display: block;
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-bottom: 4px;
    font-weight: 500;
}

.catasto-field input {
    width: 100%;
    padding: 9px 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 0.85rem;
    transition: border-color 0.2s;
}

.catasto-field input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.catasto-autocomplete {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0 0 6px 6px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.catasto-ac-item {
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.82rem;
    color: var(--text-primary);
    transition: background 0.15s;
}

.catasto-ac-item:hover {
    background: var(--bg-hover);
}

.catasto-ac-item .ac-code {
    color: var(--accent-color);
    font-weight: 600;
    margin-right: 6px;
}

.catasto-btn-search {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 11px;
    background: var(--accent-color);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
    margin-top: 4px;
}

.catasto-btn-search:hover {
    background: #2563eb;
}

.catasto-btn-search:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.catasto-status {
    margin-top: 12px;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    line-height: 1.5;
}

.catasto-status.info {
    background: rgba(37, 99, 235, 0.1);
    border: 1px solid rgba(37, 99, 235, 0.3);
    color: #93c5fd;
}

.catasto-status.success {
    background: rgba(22, 163, 74, 0.1);
    border: 1px solid rgba(22, 163, 74, 0.3);
    color: #86efac;
}

.catasto-status.error {
    background: rgba(220, 38, 38, 0.1);
    border: 1px solid rgba(220, 38, 38, 0.3);
    color: #fca5a5;
}

.catasto-result {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
}

.catasto-result dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 4px 12px;
    font-size: 0.8rem;
}

.catasto-result dt {
    color: var(--text-secondary);
    font-weight: 500;
}

.catasto-result dd {
    color: var(--text-primary);
    margin: 0;
}

.catasto-result-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.catasto-btn-add {
    flex: 1;
    padding: 9px;
    background: #16a34a;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.catasto-btn-add:hover {
    background: #15803d;
}

.catasto-btn-zoom {
    padding: 9px 14px;
    background: var(--bg-hover);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.2s;
}

.catasto-btn-zoom:hover {
    background: var(--border-color);
}

.catasto-btn-clear {
    padding: 9px 14px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.82rem;
    cursor: pointer;
    transition: background 0.2s;
}

.catasto-btn-clear:hover {
    background: rgba(220, 38, 38, 0.1);
    color: #fca5a5;
    border-color: rgba(220, 38, 38, 0.3);
}

.catasto-log {
    margin-top: 12px;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 0.72rem;
    background: rgba(0,0,0,0.2);
    padding: 10px;
    border-radius: 6px;
    max-height: 180px;
    overflow-y: auto;
    white-space: pre-wrap;
    color: var(--text-secondary);
    line-height: 1.5;
}

.catasto-log:empty {
    display: none;
}

.catasto-log .log-step { color: #93c5fd; }
.catasto-log .log-ok { color: #86efac; }
.catasto-log .log-err { color: #fca5a5; }

.catasto-btn-associa {
    flex: 1;
    padding: 9px;
    background: #2563eb;
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.catasto-btn-associa:hover {
    background: #1d4ed8;
}

.catasto-associa-panel {
    margin-top: 10px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: var(--bg-card);
    overflow: hidden;
}

.catasto-associa-header {
    padding: 8px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: var(--bg-hover);
    border-bottom: 1px solid var(--border-color);
}

.catasto-associa-search {
    width: 100%;
    padding: 8px 12px;
    border: none;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 0.82rem;
    outline: none;
}

.catasto-associa-search:focus {
    background: rgba(37, 99, 235, 0.05);
}

.catasto-associa-list {
    max-height: 200px;
    overflow-y: auto;
}

.catasto-associa-item {
    padding: 8px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    color: var(--text-primary);
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.catasto-associa-item:hover {
    background: rgba(37, 99, 235, 0.1);
    color: #93c5fd;
}

.catasto-associa-empty {
    padding: 12px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}

