/* === Session Overlay Popup === */
.session-overlay {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.session-popup {
    background: var(--header-bg, #fff);
    border: 1px solid var(--header-border);
    border-radius: 24px;
    padding: 32px;
    width: 420px;
    max-width: 90vw;
    max-height: 70vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg, 0 20px 60px rgba(0,0,0,0.3));
    user-select: none;
}

.session-popup h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0 0 4px;
}

.popup-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin: 0 0 20px;
}

.session-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.session-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--header-border);
    background: var(--surface, #f8fafc);
    cursor: pointer;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.session-item:hover {
    border-color: var(--accent-light, #bfdbfe);
    box-shadow: 0 0 0 2px var(--accent-light, #bfdbfe);
    transform: translateY(-1px);
}

.session-item-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.session-item-info strong {
    font-size: 0.95rem;
    color: var(--text-primary);
}

.session-item-id {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    font-family: monospace;
}

.session-item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.session-item-time {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.session-item-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #10b981;
    box-shadow: 0 0 8px #10b981;
    flex-shrink: 0;
}

.session-loading,
.session-empty,
.session-error {
    text-align: center;
    padding: 32px 16px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.session-error {
    color: #ef4444;
}

/* === Top Info (Last Update) === */
.last-update {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* === Layout Wrappers === */
.dashboard-layout {
    display: flex;
    align-items: flex-start;
    gap: 24px;
    margin: 0 30px 20px;
    padding-bottom: 140px; /* Evita che la bottom bar copra i dati */
}

.main-column {
    flex: 1;
    min-width: 0;
}

/* === Sticky Map & Expanded Chart === */
.sticky-area {
    position: sticky;
    top: 20px;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 20px;
}

.map-container {
    border-radius: 24px;
    overflow: hidden;
    border: 1px solid rgba(226, 232, 240, 0.6);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.04);
    background: var(--surface);
}

.map-container #liveMap {
    width: 100%;
    height: 300px; /* Ridotto un po' per far spazio */
}

.expanded-chart-container {
    background: var(--surface, #f8fafc);
    border: 1px solid rgba(226, 232, 240, 0.6);
    border-radius: 24px;
    padding: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.04);
    position: relative;
    display: flex;
    flex-direction: column;
    height: 300px;
}

.expanded-chart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.expanded-chart-header h3 {
    margin: 0;
    font-size: 1rem;
    color: var(--text-primary);
}

.close-expanded-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
}

.close-expanded-btn:hover {
    color: var(--text-primary);
}

.expanded-chart-body {
    flex: 1;
    min-height: 0;
    position: relative;
}

.expanded-chart-body canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

/* === Card ibrida (Dati + Minigrafico) === */
.grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.data-card {
    background: var(--surface, #ffffff);
    border: 1px solid rgba(226, 232, 240, 0.6);
    border-radius: 24px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 4px 20px rgba(0,0,0,0.03);
    position: relative;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.data-card:hover {
    box-shadow: 0 12px 32px rgba(0,0,0,0.06);
    border-color: var(--accent-light);
    transform: translateY(-2px);
}

.card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
}

.card-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-icon {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: #f1f5f9;
    color: #64748b;
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-info {
    margin-left: 6px;
}

.card-info h4 {
    margin: 0;
    font-size: 0.9rem;
    color: var(--text-primary);
    font-weight: 600;
}

.card-info span {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.card-actions {
    display: flex;
    gap: 6px;
    opacity: 0;
    transition: opacity 0.2s;
}

.data-card:hover .card-actions {
    opacity: 1;
}

.card-action-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.card-action-btn:hover {
    background: #f1f5f9;
    color: var(--text-primary);
}

.card-body {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 16px;
    padding: 0 6px 6px;
}

.card-values {
    display: flex;
    flex-direction: row;
    align-items: flex-end;
    gap: 4px;
    min-width: 80px;
}

.card-main-val {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
}

.card-unit {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 2px;
}

.card-mini-chart {
    flex: 1;
    height: 50px;
    position: relative;
    min-width: 0;
}

.card-mini-chart canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

/* Modalità Confronto disabilita il minigrafico se selezionato, ma lascio a JS questo controllo visivo */

/* === Sidebar Confronto === */
.comparison-sidebar {
    width: 400px;
    background: var(--surface);
    border: 1px solid rgba(226, 232, 240, 0.6);
    border-radius: 24px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.04);
    position: sticky;
    top: 20px;
    height: calc(100vh - 120px);
    overflow: hidden;
}

.comp-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--header-border);
    padding-bottom: 12px;
}

.comp-header h3 {
    margin: 0;
    font-size: 1.1rem;
}

.comp-close {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.comp-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.comp-pill {
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 6px;
    background: #f1f5f9;
    border: 1px solid var(--header-border);
}

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

.comp-pill button {
    background: none;
    border: none;
    cursor: pointer;
    line-height: 1;
    font-size: 1rem;
    color: var(--text-secondary);
}

.comp-chart-area {
    flex: 1;
    min-height: 0;
    position: relative;
}

.comp-chart-area canvas {
    position: absolute;
    inset: 0;
    width: 100% !important;
    height: 100% !important;
}

/* Quando la modalita confronto è attiva le card cambiano aspetto al click? Lo gestisce JS (es. classe .selected-for-comp) */
.data-card.selected-for-comp {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 1px var(--accent-color);
}
.data-card.selected-for-comp .card-mini-chart {
    opacity: 0.2; /* Nasconde o sbiadisce il mini chart per far capire che è in confronto */
}

/* === Bottom Bar & secondary ... same as before mostly === */
.bottom-bar {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    width: max-content;
    max-width: 95vw;
    height: 56px;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    font-size: 15px;
    user-select: none;
    background-color: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 28px;
    z-index: 1000;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.08), 0 4px 12px rgba(0, 0, 0, 0.02);
    overflow-x: auto;
    scrollbar-width: none;
    color: var(--text-primary);
}

.bottom-bar::-webkit-scrollbar {
    display: none;
}

.bottom-bar .search-field {
    height: 38px;
    width: 200px;
    padding-right: 10px;
    border-radius: 14px;
    border: 1px solid rgba(226, 232, 240, 0.8);
    background: rgba(255, 255, 255, 0.6);
    display: flex;
    align-items: center;
    transition: background 0.3s ease, border-color 0.3s ease, box-shadow 0.3s ease;
    flex-shrink: 0;
}

.bottom-bar .search-field:focus-within {
    background: rgba(255, 255, 255, 0.9);
    border-color: var(--accent-light, #bfdbfe);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.1);
}

.bottom-bar .search-field input {
    border: none;
    outline: none;
    background: transparent;
    color: var(--text-primary);
    font-size: 14px;
    padding: 5px;
    width: 100%;
}

.bottom-bar .filter {
    display: flex;
    height: 38px;
    padding: 0 4px;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    border-radius: 14px;
    border: 1px solid rgba(226, 232, 240, 0.8);
    background: rgba(255, 255, 255, 0.6);
}

.bottom-bar .filter.boxed button {
    display: flex;
    width: 30px;
    height: 30px;
    padding: 0;
    justify-content: center;
    align-items: center;
}

.bottom-bar .filter button {
    display: flex;
    padding: 6px 12px;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    transition: color 0.15s ease, background 0.15s ease;
    cursor: pointer;
    white-space: nowrap;
    font-size: 13px;
    font-weight: 500;
}

.bottom-bar .filter button.active {
    background: var(--accent-color);
    color: #ffffff;
}

.bottom-bar > button#downloadBtn {
    display: flex;
    padding: 6px 16px;
    justify-content: center;
    align-items: center;
    border-radius: 12px;
    background: var(--surface, #f8fafc);
    border: 1px solid var(--header-border);
    color: var(--text-primary);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.bar-sep {
    width: 1px;
    height: 24px;
    background-color: var(--header-border);
    margin: 0 4px;
    flex-shrink: 0;
}

.map-bar {
    position: fixed;
    bottom: 6rem;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    display: flex;
    width: max-content;
    height: 48px;
    justify-content: center;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    background-color: rgba(255, 255, 255, 0.75);
    backdrop-filter: blur(24px) saturate(1.5);
    -webkit-backdrop-filter: blur(24px) saturate(1.5);
    border: 1px solid rgba(255, 255, 255, 0.4);
    border-radius: 24px;
    z-index: 1000;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.06);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.map-bar.visible {
    opacity: 1;
    pointer-events: all;
    transform: translateX(-50%) translateY(0);
}

.map-bar .filter {
    display: flex;
    height: 36px;
    padding: 0 4px;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    border-radius: 12px;
    border: 1px solid var(--header-border);
    background: var(--surface, #f8fafc);
}

.map-bar .filter button {
    display: flex;
    padding: 6px 12px;
    justify-content: center;
    align-items: center;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
}

.map-bar .filter button.active {
    background: var(--accent-color);
    color: #ffffff;
}

.map-toggles-group {
    display: flex;
    gap: 8px;
    align-items: center;
}

.bb-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--surface, #f8fafc);
    border: 1px solid var(--header-border);
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
}

.bb-toggle.on {
    border-color: var(--accent-border, #bfdbfe);
    background: var(--accent-light, #eff6ff);
    color: var(--accent-color, #2563eb);
}

@media (max-width: 1100px) {
    .dashboard-layout {
        flex-direction: column;
    }
    .comparison-sidebar {
        width: 100%;
        height: 400px;
        position: static;
    }
}

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

