/* ============================================
   TECH DASHBOARD THEME - ASL Salerno
   ============================================ */

/* Pulsante navigazione header */
.header-actions-nav {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
    margin-right: 20px;
}

.header-nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(139, 92, 246, 0.1));
    color: #c4b5fd;
    text-decoration: none;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 600;
    transition: all 0.2s ease;
    border: 1px solid rgba(139, 92, 246, 0.4);
    box-shadow: 0 2px 8px rgba(139, 92, 246, 0.15);
}

.header-nav-btn:hover {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.35), rgba(139, 92, 246, 0.2));
    color: #fff;
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.25);
    transform: translateY(-1px);
}

.header-nav-btn svg {
    width: 18px;
    height: 18px;
}

/* Indicatore stato servizio catastale */
.catasto-status {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: default;
    margin-left: 8px;
    background: rgba(100, 116, 139, 0.15);
    color: var(--text-muted);
    border: 1px solid rgba(100, 116, 139, 0.2);
}

.catasto-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #64748b; /* grigio = sconosciuto */
    flex-shrink: 0;
}

.catasto-status.online .catasto-dot {
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.catasto-status.online {
    background: rgba(34, 197, 94, 0.1);
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.25);
}

.catasto-status.offline .catasto-dot {
    background: #ef4444;
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.5);
}

.catasto-status.offline {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
    border-color: rgba(239, 68, 68, 0.25);
}

.catasto-status.partial .catasto-dot {
    background: #f59e0b;
    box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
}

.catasto-status.partial {
    background: rgba(245, 158, 11, 0.1);
    color: #fcd34d;
    border-color: rgba(245, 158, 11, 0.25);
}

/* 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;
    overflow-x: hidden;
}

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: 6px 12px;
    border-radius: 6px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 6px;
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

.metric-badge .metric-icon {
    display: flex;
    align-items: center;
    color: var(--text-secondary);
}

.metric-badge .metric-icon svg {
    width: 14px;
    height: 14px;
}

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

.metric-badge .metric-label {
    color: var(--text-secondary);
}

/* Stats row layout */
.stats-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

/* ==================== 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: 350px;
    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;
    overflow-x: hidden;
    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: visible;
}

#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: 1200px) {
    /* Header compatto su tablet (copre Tab S4 landscape 1138px) */
    :root {
        --header-height: 50px;
    }

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

    .header-title p {
        display: none;
    }

    .header-metrics {
        display: none;
    }

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

    /* Tab navigation con label su tablet */
    .tab-navigation {
        gap: 2px;
        padding: 6px;
    }

    .tab-button {
        padding: 6px 4px;
        gap: 3px;
    }

    .tab-label {
        display: block !important;
        font-size: 0.6rem;
    }

    .tab-icon svg {
        width: 16px;
        height: 16px;
    }

    .tab-count {
        font-size: 0.6rem;
        padding: 0 4px;
        min-width: 16px;
        height: 16px;
        line-height: 16px;
    }

    /* Sync button visibile */
    .sync-button-compact {
        min-width: 34px;
        width: 34px;
        height: 34px;
        flex-shrink: 0;
    }

    .sync-button-compact svg {
        width: 16px;
        height: 16px;
    }

    /* Toggle chips — griglia 2 colonne leggibili */
    .quick-toggles {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 5px;
        padding: 0 8px;
        box-sizing: border-box;
        width: 100%;
    }

    .toggle-chip {
        padding: 6px 8px;
        gap: 4px;
        font-size: 0.72rem;
        min-width: 0;
        justify-content: flex-start;
    }

    .chip-label {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .toggle-chip svg {
        width: 13px;
        height: 13px;
        flex-shrink: 0;
    }

    .chip-count {
        font-size: 0.65rem;
        padding: 1px 4px;
        flex-shrink: 0;
        margin-left: auto;
    }

    /* Filtri */
    .filters-grid {
        gap: 6px;
        padding: 8px;
    }

    .filter-group label {
        font-size: 0.7rem;
    }

    .filter-group select,
    .filter-group input[type="text"] {
        min-height: 38px;
        padding: 6px 8px;
        font-size: 0.8rem;
    }

    .filter-search-row {
        padding: 0 8px 4px;
    }

    .filter-search-row input {
        min-height: 38px;
        padding: 8px;
        font-size: 0.8rem;
    }

    /* Filters actions sticky */
    .filters-actions-sticky {
        padding: 8px;
    }

    .filters-actions-sticky .btn {
        min-height: 40px;
        font-size: 0.8rem;
    }

    /* 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;
    }

    /* 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;
    }
}

/* ===== TABLET TOUCH — touch targets minimi 44px (Apple HIG / Material Design) ===== */
@media (hover: none) and (pointer: coarse) {
    .popup-actions .btn {
        padding: 10px 14px;
        min-height: 44px;
        font-size: 0.84rem;
    }
    .stato-rilievo {
        padding: 12px 16px;
        min-height: 48px;
        font-size: 1rem;
    }
    .page-btn {
        padding: 10px 16px;
        min-height: 44px;
        font-size: 14px;
    }
    .registro-filters select,
    .registro-filters input {
        padding: 10px 12px;
        font-size: 14px;
        min-height: 44px;
    }
    td { padding: 12px 10px; }
    .btn-sm { padding: 10px 14px; min-height: 44px; }
    .leaflet-popup-close-button {
        font-size: 28px !important;
        width: 36px !important;
        height: 36px !important;
        line-height: 36px !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 styling */
.leaflet-popup-content-wrapper {
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
}

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

.leaflet-popup-close-button {
    font-size: 20px;
    color: var(--text-secondary);
    line-height: 1;
    padding: 4px 8px;
}

.leaflet-popup-close-button:hover {
    color: var(--text-primary);
}

/* Controls z-index */
.leaflet-top,
.leaflet-bottom {
    z-index: 900 !important;
}

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

.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: contain;
    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;
}

/* ==================== 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.da-fare {
    background: rgba(239, 68, 68, 0.15);
    color: #dc2626;
}

.stato-rilievo.rilevato {
    background: rgba(234, 179, 8, 0.15);
    color: #ca8a04;
}

.stato-rilievo.gia-fatto {
    background: rgba(20, 184, 166, 0.15);
    color: #0d9488;
}

/* Alias legacy (usati altrove) */
.stato-rilievo.visionato  { background: rgba(234, 179, 8, 0.15); color: #ca8a04; }
.stato-rilievo.da-visionare { background: rgba(239, 68, 68, 0.15); color: #dc2626; }

.stato-icona {
    font-size: 1.1rem;
    flex-shrink: 0;
}

.stato-testo {
    flex: 1;
    font-size: 0.88rem;
}

/* Popup tipo badge */
.popup-tipo-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 700;
    flex-shrink: 0;
}
.popup-tipo-badge.fab { background: rgba(59,130,246,0.2); color: #3b82f6; }
.popup-tipo-badge.ter { background: rgba(34,197,94,0.2);  color: #16a34a; }

/* Popup catasto chips */
.popup-catasto-chip {
    display: inline-block;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 1px 6px;
    font-size: 0.78rem;
    margin-right: 4px;
    color: var(--text-primary);
}

.popup-catasto-row {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-bottom: 3px;
    line-height: 1.4;
}

.popup-section {
    margin-bottom: 8px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-color);
}

.popup-section:last-of-type {
    border-bottom: none;
    margin-bottom: 0;
    padding-bottom: 0;
}

.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;
}

/* ==================== 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-beni-enhanced {
    width: 100%;
    border-collapse: collapse;
}

#table-beni-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-beni-enhanced th:hover {
    background: var(--bg-primary);
}

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

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

#table-beni-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-beni-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-fab td:first-child {
    border-left-color: #3b82f6 !important;
}

/* Terreni - Bordo verde sulla prima cella */
.row-ter 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-beni-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);
}

/* Comuni List - Compact horizontal bars */
#chart-comuni {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.comuni-list-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.comuni-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.comuni-list-name {
    font-size: 0.8rem;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
}

.comuni-list-count {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent-blue);
    margin-left: 8px;
}

.comuni-list-bar {
    height: 6px;
    background: var(--bg-secondary);
    border-radius: 3px;
    overflow: hidden;
}

.comuni-list-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
    border-radius: 3px;
    transition: width 0.3s ease;
}

/* 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);
}

/* Stats Header */
.stats-header {
    text-align: center;
    padding: 16px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.1), rgba(16, 185, 129, 0.1));
    border-radius: 8px;
    margin-bottom: 4px;
}

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

.stats-subtitle {
    margin: 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* Stat Card Variants */
.stat-card-primary {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.05));
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.stat-card-primary .stat-icon {
    color: #3b82f6;
}

.stat-card-primary .stat-value {
    color: #3b82f6;
}

.stat-card-success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.15), rgba(16, 185, 129, 0.05));
    border: 1px solid rgba(16, 185, 129, 0.2);
}

.stat-card-success .stat-icon {
    color: #10b981;
}

.stat-card-success .stat-value {
    color: #10b981;
}

.stat-card-warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(245, 158, 11, 0.05));
    border: 1px solid rgba(245, 158, 11, 0.2);
}

.stat-card-warning .stat-icon {
    color: #f59e0b;
}

.stat-card-warning .stat-value {
    color: #f59e0b;
}

.stat-card-info {
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.15), rgba(139, 92, 246, 0.05));
    border: 1px solid rgba(139, 92, 246, 0.2);
}

.stat-card-info .stat-icon {
    color: #8b5cf6;
}

.stat-card-info .stat-value {
    color: #8b5cf6;
}

.stat-card-nature {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.15), rgba(34, 197, 94, 0.05));
    border: 1px solid rgba(34, 197, 94, 0.2);
}

.stat-card-nature .stat-icon {
    color: #22c55e;
}

.stat-card-nature .stat-value {
    color: #22c55e;
}

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

.stats-section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 0 16px 0;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.stats-section-title svg {
    color: var(--accent-blue);
}

/* Verification Progress */
.verification-progress {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

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

.progress-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

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

.progress-bar {
    height: 8px;
    background: var(--bg-primary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.5s ease;
}

.progress-pending {
    background: linear-gradient(90deg, #f59e0b, #fbbf24);
}

.progress-working {
    background: linear-gradient(90deg, #3b82f6, #60a5fa);
}

.progress-verified {
    background: linear-gradient(90deg, #10b981, #34d399);
}

.progress-approved {
    background: linear-gradient(90deg, #22c55e, #4ade80);
}

/* Completeness Grid */
.completeness-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

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

.completeness-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: var(--bg-primary);
    border-radius: 6px;
}

.completeness-icon {
    font-size: 1.2rem;
}

.completeness-info {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.completeness-percent {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-blue);
}

.completeness-bar {
    width: 100%;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    margin-top: 6px;
    grid-column: 1 / -1;
}

.completeness-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-blue), var(--accent-green));
    border-radius: 2px;
    transition: width 0.5s ease;
}

/* Quick Stats */
.quick-stats {
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 8px 0;
}

.quick-stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: 6px;
    border-left: 3px solid var(--accent-blue);
}

.quick-stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent-blue);
}

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

/* ==================== 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-beni-enhanced th,
    #table-beni-enhanced td {
        padding: 8px 4px;
        font-size: 0.75rem;
    }

    /*
     * Hide columns by position (nth-child) so both th AND td are hidden.
     * Columns: 1=#, 2=Stato, 3=Codice, 4=Comune, 5=Foglio, 6=Particella, 7=Sub, 8=Cat, 9=Superficie, 10=Tour
     * Hide: 2(Stato), 7(Sub), 10(Tour)
     */
    #table-beni-enhanced th:nth-child(2),
    #table-beni-enhanced td:nth-child(2),
    #table-beni-enhanced th:nth-child(7),
    #table-beni-enhanced td:nth-child(7),
    #table-beni-enhanced th:nth-child(10),
    #table-beni-enhanced td:nth-child(10) {
        display: none;
    }

    /* Compress remaining columns */
    .col-prog { width: 30px; }
    .col-codice { width: 70px; }
    .col-comune { min-width: 70px; }
    .col-foglio { width: 30px; }
    .col-particella { width: 40px; }
    .col-categoria { width: 40px; }
    .col-superficie { width: 60px; font-size: 0.65rem; }
}

/* Smaller phones: hide cat + superficie (cols 8, 9) too */
@media (max-width: 480px) {
    #table-beni-enhanced th:nth-child(8),
    #table-beni-enhanced td:nth-child(8),
    #table-beni-enhanced th:nth-child(9),
    #table-beni-enhanced td:nth-child(9) {
        display: none;
    }
}

/* ==================== 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;
}

/* Sezione scheda read-only nel popup */
.popup-scheda {
    padding: 5px 12px 6px;
    border-top: 1px solid rgba(255,255,255,0.07);
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.popup-detail-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
    font-size: 0.71rem;
    line-height: 1.45;
    color: var(--text-secondary);
}
.popup-detail-label {
    flex-shrink: 0;
    color: #64748b;
    font-weight: 500;
    min-width: 74px;
}
.popup-note .popup-detail-label { align-self: flex-start; }
.popup-note span:last-child { font-style: italic; text-align: right; }

/* ==================== 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à */

/* ==================== MAP CONTROLS GROUP ==================== */

.map-controls-group {
    position: absolute;
    bottom: 80px;
    right: 12px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.map-ctrl-btn {
    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;
}

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

/* GPS attivo */
.map-ctrl-btn.gps-active {
    background: #4285F4;
    color: #fff;
    animation: gps-pulse 2s ease-in-out infinite;
}

@keyframes gps-pulse {
    0%, 100% { box-shadow: 0 2px 8px rgba(0,0,0,0.4); }
    50% { box-shadow: 0 2px 16px rgba(66,133,244,0.7); }
}

/* ==================== MAP FULLSCREEN ==================== */

.map-fullscreen-btn {
    /* Stili base ereditati da .map-ctrl-btn */
}

.map-fullscreen-btn:hover {
    /* ereditato da .map-ctrl-btn:hover */
}

/* Fullscreen mode: sidebar chiusa ma apribile, mappa occupa tutto */
body.map-fullscreen .sidebar {
    position: fixed;
    left: 0;
    top: var(--header-height);
    height: calc(100% - var(--header-height));
    z-index: 2500;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
}

body.map-fullscreen .sidebar.expanded {
    transform: translateX(0) !important;
}

body.map-fullscreen .sidebar.collapsed {
    transform: translateX(-100%) !important;
}

body.map-fullscreen .sidebar-overlay {
    display: block;
}

body.map-fullscreen .right-panel {
    display: none !important;
}

body.map-fullscreen .main-container {
    margin-left: 0 !important;
}

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


@media (max-width: 1200px) {
    .map-controls-group {
        bottom: 90px;
        right: 10px;
        gap: 10px;
    }

    .map-ctrl-btn {
        width: 44px;
        height: 44px;
    }
}

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

/* Toggle button — stili base ereditati da .map-ctrl-btn */
.route-toggle-btn {
    /* solo override specifici sotto */
}

.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: 1200px) {
    .route-toggle-btn {
        width: 44px;
        height: 44px;
    }

    .route-panel {
        left: 12px;
        top: 70px;
        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;
    }

}

/* ==================== USER BADGE (Auth) ==================== */
/* ==========================================
   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;
}

/* 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;
    }
    .tab-button {
        padding: 12px 8px;
        min-height: 48px;
    }
    .filters-actions-sticky .btn {
        min-height: 48px;
        font-size: 0.85rem;
    }
}

/* Lista particelle mancanti */
/* ==================== 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 e coordinate gestite via JS (position:fixed + getBoundingClientRect)
       per evitare il clipping dell'overflow-y:auto del tab-content parent */
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 0 0 6px 6px;
    max-height: 200px;
    overflow-y: auto;
    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-warning {
    background: rgba(234, 179, 8, 0.15);
    border: 1px solid rgba(234, 179, 8, 0.4);
    border-radius: 6px;
    color: #fde68a;
    font-size: 12px;
    line-height: 1.4;
    margin-bottom: 10px;
    padding: 8px 10px;
}

.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;
}

/* ==================== TABLET 8" RESPONSIVE ==================== */

/* Popup Leaflet su tablet: più compatto */
@media (max-width: 1200px) {
    .custom-immobile-popup {
        max-width: 320px !important;
    }

    .leaflet-popup-content-wrapper {
        max-height: 60vh;
    }

    .leaflet-popup-content {
        max-height: 50vh;
        font-size: 0.85rem;
    }

    /* Layer control collassato su tablet */
    .leaflet-control-layers {
        max-width: 200px;
    }

    .leaflet-control-layers-expanded {
        max-height: 50vh;
        overflow-y: auto;
    }

    /* Popup close button più grande per touch */
    .leaflet-popup-close-button {
        font-size: 28px !important;
        width: 32px !important;
        height: 32px !important;
    }

    /* Right panel overlay su tablet */
    .right-panel {
        position: fixed;
        top: var(--header-height);
        right: 0;
        height: calc(100% - var(--header-height));
        z-index: 2000;
        box-shadow: -4px 0 16px rgba(0, 0, 0, 0.4);
    }

    /* Sync dialog compatto */
    .sync-dialog {
        width: 90vw !important;
        max-width: 500px;
    }
}


