:root {
    --bg-base: #000000;
    /* Deep iOS Dark Mode Black */
    --bg-surface: rgba(28, 28, 30, 0.65);
    /* iOS System Gray 6 equivalent */
    --bg-surface-hover: rgba(44, 44, 46, 0.85);
    /* iOS System Gray 5 */
    --bg-highlight: rgba(255, 255, 255, 0.05);
    /* Highlight overlay */
    --sidebar-bg: rgba(28, 28, 30, 0.4);
    --chat-ai-bg: rgba(30, 41, 59, 0.8);
    --chat-user-bg: rgba(249, 115, 22, 0.15);
    --input-bg: rgba(0, 0, 0, 0.3);
    --input-bg-focus: rgba(0, 0, 0, 0.5);
    --primary: #f97316;
    /* Mantenuto Arancione Sicurezza */
    --primary-hover: #ea580c;
    --text-main: #ffffff;
    --text-muted: #ebebf599;
    /* iOS Secondary Text */
    --border-color: rgba(255, 255, 255, 0.1);
    --danger: #ff453a;
    /* iOS Red */
    --glass-blur: 24px;
    /* Aumentato per un vero effetto Apple Vibrancy */
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", sans-serif;
    background-color: var(--bg-base);
    background-image:
        radial-gradient(circle at 10% 20%, rgba(249, 115, 22, 0.15), transparent 30%),
        radial-gradient(circle at 90% 80%, rgba(10, 132, 255, 0.1), transparent 35%),
        radial-gradient(circle at 50% 50%, rgba(94, 92, 230, 0.05), transparent 50%);
    background-attachment: fixed;
    color: var(--text-main);
    transition: background-color 0.5s ease, color 0.5s ease;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Typography & Utilities */
::placeholder {
    color: var(--text-main) !important;
    opacity: 0.4 !important;
}

::-webkit-input-placeholder {
    color: var(--text-main) !important;
    opacity: 0.4 !important;
}

h1,
h2,
h3,
h4,
p {
    margin: 0;
}

.hidden {
    display: none !important;
}

/* App Layout */
body {
    overflow: hidden;
    /* Prevenire scroll globale, deleghiamo al main-content */
}

.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background: var(--sidebar-bg);
    /* iOS Sidebar translucent */
    backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
    padding: 24px;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    z-index: 10;
    box-shadow: 1px 0 24px rgba(0, 0, 0, 0.3);
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 40px;
}

.brand i {
    color: var(--primary);
}

.nav-item {
    padding: 12px 16px;
    border-radius: 12px;
    /* Stile iOS pill */
    color: var(--text-muted);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1);
    /* Curva iOS */
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 4px;
    /* Meno spazio tra i tab */
}

.nav-item:hover {
    background: rgba(255, 255, 255, 0.08);
}

.nav-item.active {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(249, 115, 22, 0.3);
}

.nav-item.active i {
    color: #ffffff;
}

.nav-item:active {
    transform: scale(0.97);
    /* Micro-animazione iOS al click */
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 40px;
    overflow-y: auto;
    height: 100vh;
    box-sizing: border-box;
}

/* Icon Colors */
.icon-sun {
    color: #facc15;
}

.icon-moon {
    color: #cbd5e1;
}

.icon-cloud {
    color: #94a3b8;
}

.icon-rain {
    color: #38bdf8;
}

.icon-snow {
    color: #a5f3fc;
}

/* Header (Search & Actions) */
.header-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 40px;
}

.search-box {
    display: flex;
    align-items: center;
    background: rgba(118, 118, 128, 0.24);
    /* iOS Search Bar color */
    border: none;
    border-radius: 12px;
    padding: 0 16px;
    width: 400px;
    backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

.search-box:focus-within {
    background: rgba(118, 118, 128, 0.35);
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.4);
}

.search-box i {
    color: var(--text-muted);
}

.search-box input {
    background: transparent;
    border: none;
    color: var(--text-main);
    padding: 12px;
    width: 100%;
    outline: none;
    font-family: inherit;
    font-size: 1rem;
}

.btn-primary,
.btn-secondary {
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s, filter 0.2s;
}

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

.btn-primary:hover {
    transform: translateY(-2px);
    filter: brightness(1.1);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-main);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: translateY(-2px);
}

/* Dashboard Grid */
.dashboard-title {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 24px;
}

.sites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
}

/* Site Card (Glassmorphism) */
.site-card {
    background: var(--bg-surface);
    backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    /* iOS App Icon radius */
    padding: 24px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    position: relative;
    overflow: hidden;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 8px 24px rgba(0, 0, 0, 0.2);
}

.site-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
    transform: scaleY(0);
    transition: transform 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    transform-origin: bottom;
}

.site-card:hover {
    transform: translateY(-2px);
    border-color: rgba(255, 255, 255, 0.15);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 12px 32px rgba(0, 0, 0, 0.3);
}

.site-card:active {
    transform: scale(0.98);
}

.site-card:hover::before {
    transform: scaleY(1);
}

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

.card-title {
    font-size: 1.25rem;
    font-weight: 600;
}

.card-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.status-badge {
    background: rgba(34, 197, 94, 0.1);
    color: #4ade80;
    padding: 4px 8px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Modal */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(4px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 32px;
    width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    transform: translateY(20px) scale(0.95);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
}

.modal-overlay.active .modal-content {
    transform: translateY(0) scale(1);
}

.modal-content h3 {
    font-size: 1.5rem;
    margin-bottom: 8px;
}

.modal-content p {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 16px;
}

.form-input {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 12px;
    color: var(--text-main);
    outline: none;
    box-sizing: border-box;
    transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1);
}

.form-input:focus {
    background: var(--input-bg-focus);
    box-shadow: 0 0 0 2px rgba(249, 115, 22, 0.4);
}

/* Timeline & Weather View */
.weather-view {
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.weather-header {
    background: var(--bg-surface);
    backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 24px;
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* Segmented Controls (Tabs) */
.segmented-control {
    display: flex;
    background: var(--input-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 4px;
    gap: 4px;
}

.segment {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px 16px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.25, 1, 0.5, 1);
    font-family: inherit;
    font-size: 0.9rem;
}

.segment:hover {
    color: var(--text-main);
}

.segment.active {
    background: var(--bg-surface);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
}

.timeline {
    display: flex;
    gap: 12px;
    overflow-x: auto;
    padding-bottom: 12px;
}

.hour-card {
    min-width: 80px;
    background: var(--bg-surface);
    backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 30px;
    /* Stile a pillola Apple Weather */
    padding: 16px 8px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 8px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);
}

.hour-card:hover {
    transform: translateY(-2px);
    background: var(--bg-surface-hover);
}

.hour-card.risk {
    border-color: var(--danger);
    background: rgba(255, 69, 58, 0.15);
}

/* Loader */
.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s cubic-bezier(0.55, 0.15, 0.45, 0.85) infinite;
    margin: 0 auto 16px;
}

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

/* Skeleton Loader */
.skeleton {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
    background-size: 200% 100%;
    animation: shimmer 2s infinite linear;
    border-radius: 8px;
    min-height: 20px;
}

@keyframes shimmer {
    0% {
        background-position: 200% 0;
    }

    100% {
        background-position: -200% 0;
    }
}

/* Micro-interactions */
tbody tr {
    transition: background 0.3s ease, transform 0.2s ease;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

/* Chart & Heatmap Styles */
.heatmap-container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 2px;
    overflow-x: auto;
    padding-top: 24px;
}

.heatmap-row {
    display: flex;
    gap: 2px;
    align-items: center;
}

.heatmap-label {
    width: 60px;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: right;
    padding-right: 8px;
    flex-shrink: 0;
}

.heatmap-cell {
    flex: 1;
    height: 24px;
    border-radius: 4px;
    min-width: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.6rem;
    color: transparent;
    transition: all 0.2s ease;
}

.heatmap-cell:hover {
    color: rgba(255, 255, 255, 0.8);
    transform: scale(1.1);
}

/* Hero Banner */
.hero-banner {
    background: var(--bg-surface);
    backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(180%);
    border: 1px solid var(--border-color);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
    border-radius: 16px;
    padding: 24px;
    margin-bottom: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.hero-greeting {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
}

.hero-greeting span {
    color: var(--primary);
}

.hero-kpi-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
}

.hero-kpi-box {
    background: var(--bg-highlight);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
    border-radius: 12px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    align-items: center;
    text-align: center;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s !important;
}

.hero-kpi-box:hover {
    transform: translateY(-2px) scale(1.02) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
    background: var(--bg-highlight) !important;
}

.hero-kpi-val {
    font-weight: 700;
    font-size: 0.9rem;
}

.hero-kpi-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Toggle Switch */
.switch {
    position: relative;
    display: inline-block;
    width: 40px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
}

input:checked+.slider {
    background-color: var(--primary);
}

input:checked+.slider:before {
    transform: translateX(16px);
}

.slider.round {
    border-radius: 24px;
}

.slider.round:before {
    border-radius: 50%;
}

/* Chat Message Styles */
.chat-msg {
    max-width: 80%;
    padding: 12px 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    margin-bottom: 0;
}

.chat-msg.user {
    align-self: flex-end;
    background: var(--primary);
    color: #fff;
    border-radius: 12px 12px 0 12px;
}

.chat-msg.ai {
    align-self: flex-start;
    background: var(--chat-ai-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px 12px 12px 0;
}

/* Leaflet Map Overrides */
.leaflet-container {
    background: var(--bg-base);
    font-family: 'Outfit', sans-serif;
}

.custom-leaflet-marker {
    transition: transform 0.3s ease;
}

.custom-leaflet-marker:hover {
    transform: scale(1.3);
}

.leaflet-popup-content-wrapper {
    background: var(--bg-surface);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    backdrop-filter: blur(var(--glass-blur));
}

.leaflet-popup-tip {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
}

/* ==========================================
   Responsive & Mobile-First Overrides
   ========================================== */

/* Nascondiamo il pulsante hamburger su Desktop */
.mobile-nav-toggle {
    display: none !important;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    z-index: 998;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

@media (max-width: 768px) {
    body {
        overflow-y: auto !important;
        /* Consenti lo scorrimento verticale su mobile */
    }

    .app-layout {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
    }

    /* Pulsante Hamburger visibile su Mobile */
    .mobile-nav-toggle {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        background: rgba(30, 41, 59, 0.8);
        border: 1px solid var(--border-color);
        border-radius: 8px;
        color: var(--text-main);
        cursor: pointer;
        outline: none;
    }

    /* Sidebar come drawer a comparsa laterale */
    .sidebar {
        position: fixed;
        top: 0;
        bottom: 0;
        left: -320px;
        /* Nascosta a sinistra di default */
        width: 280px;
        box-sizing: border-box;
        height: 100vh;
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0.3s;
        z-index: 999;
        box-shadow: none;
        visibility: hidden;
        /* Completamente invisibile quando chiusa */
        overflow: hidden;
        border-right: none;
        /* Rimuove il bordo destro che creava la riga visibile */
    }

    .sidebar.open {
        left: 0;
        visibility: visible;
        /* Mostra sidebar */
        box-shadow: 10px 0 30px rgba(0, 0, 0, 0.5);
        transition: left 0.3s cubic-bezier(0.4, 0, 0.2, 1), visibility 0s linear 0s;
    }

    /* Adattamento contenuto principale */
    .main-content {
        padding: 20px 16px;
        height: auto;
        min-height: calc(100vh - 60px);
    }

    .header-actions {
        flex-wrap: wrap;
        gap: 16px;
        margin-bottom: 24px;
    }

    .header-actions .search-box {
        width: 100%;
        margin-left: 0;
    }

    /* Griglie KPI e Cantieri fluide */
    .hero-kpi-grid {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px;
    }

    .sites-grid {
        grid-template-columns: 1fr !important;
        gap: 16px;
    }

    /* Adattamento grafici e mappe */
    .weather-detail-grid {
        grid-template-columns: 1fr !important;
    }

    .chart-container {
        height: 300px;
    }

    /* Dialoghi e modali */
    .modal-content {
        width: 90% !important;
        padding: 24px 16px !important;
        margin: 20px auto;
    }

    /* Touch Target conformità 48px */
    .btn-primary,
    .form-input {
        min-height: 48px;
    }

    /* ==========================================
       CHATBOT MOBILE: layout completamente
       ristrutturato — chat fullscreen, skills
       in un bottom-sheet drawer separato
       ========================================== */
    #chatbot-view {
        height: calc(100dvh - 130px) !important;
    }

    #chatbot-view>div {
        flex-direction: column !important;
        gap: 0 !important;
        height: 100% !important;
    }

    /* Chat area occupa tutto lo spazio */
    #chatbot-view>div>div:first-child {
        flex: 1 !important;
        min-height: 0;
    }

    /* Sidebar skills nascosta di default su mobile */
    #chatbot-skills-panel {
        display: none;
    }

    /* Bottone skills visibile solo su mobile */
    #chatbot-skills-toggle-btn {
        display: flex !important;
    }

    /* Bottom-sheet per le skills su mobile */
    #skills-bottom-sheet {
        display: flex;
        position: fixed;
        bottom: -100%;
        left: 0;
        right: 0;
        z-index: 1100;
        background: var(--bg-panel, #1e293b);
        border-radius: 20px 20px 0 0;
        border-top: 1px solid var(--border-color);
        padding: 12px 20px 32px;
        flex-direction: column;
        gap: 16px;
        transition: bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        max-height: 80vh;
        overflow-y: auto;
        box-shadow: 0 -8px 40px rgba(0, 0, 0, 0.4);
    }

    #skills-bottom-sheet.open {
        bottom: 0;
    }

    #skills-bottom-sheet-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 1099;
        backdrop-filter: blur(4px);
    }

    #skills-bottom-sheet-overlay.active {
        display: block;
    }

    /* Leaflet controls: z-index < sidebar overlay quando aperta */
    body.sidebar-open .leaflet-control-container {
        z-index: 0 !important;
        pointer-events: none !important;
    }

    body.sidebar-open .leaflet-control-attribution {
        display: none !important;
    }

    body.sidebar-open .leaflet-control-zoom {
        display: none !important;
    }
}

@media (max-width: 480px) {
    .hero-kpi-grid {
        grid-template-columns: 1fr !important;
        /* Singola colonna su telefoni molto piccoli */
    }

    .hero-greeting {
        font-size: 1.4rem;
    }

    .dashboard-title {
        font-size: 1.5rem;
    }
}

body.light-mode {
    --bg-base: #f4f4f5;
    /* Light grey base */
    --bg-surface: rgba(255, 255, 255, 0.75);
    /* Translucent white */
    --bg-surface-hover: rgba(228, 228, 231, 0.85);
    /* Slightly darker white on hover */
    --bg-highlight: rgba(0, 0, 0, 0.05);
    /* Highlight overlay */
    --sidebar-bg: rgba(255, 255, 255, 0.6);
    --chat-ai-bg: rgba(228, 228, 231, 0.8);
    --chat-user-bg: rgba(249, 115, 22, 0.1);
    --input-bg: rgba(0, 0, 0, 0.05);
    --input-bg-focus: rgba(0, 0, 0, 0.1);
    --primary: #ea580c;
    /* Keeping safety orange */
    --primary-hover: #c2410c;
    --text-main: #18181b;
    /* Dark text */
    --text-muted: #52525b;
    /* Muted dark text */
    --border-color: rgba(0, 0, 0, 0.1);
    --danger: #dc2626;
}

/* Chatbot skills toggle button — nascosto su desktop, visibile su mobile via media query */
#chatbot-skills-toggle-btn {
    display: none;
}

/* Bottom-sheet overlay — nascosto su desktop */
#skills-bottom-sheet {
    display: none;
}

#skills-bottom-sheet-overlay {
    display: none;
}

/* =========================================
   GODMODE ANIMATIONS & MICRO-INTERACTIONS
   ========================================= */
@keyframes fadeSlideUp {
    0% {
        opacity: 0;
        transform: translateY(20px);
    }

    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-up {
    animation: fadeSlideUp 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    opacity: 0;
}

/* Staggered delays */
.delay-100 {
    animation-delay: 0.1s;
}

.delay-200 {
    animation-delay: 0.2s;
}

.delay-300 {
    animation-delay: 0.3s;
}

.delay-400 {
    animation-delay: 0.4s;
}

.delay-500 {
    animation-delay: 0.5s;
}

/* Map Glowing Pins */
.glowing-pin {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    position: relative;
    box-shadow: 0 0 10px currentColor;
    background-color: currentColor;
    margin: 5px;
    /* offset per center L.divIcon */
}

.glowing-pin::after {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    right: -6px;
    bottom: -6px;
    border-radius: 50%;
    border: 2px solid currentColor;
    animation: pulseGlow 1.5s infinite cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes pulseGlow {
    0% {
        transform: scale(0.6);
        opacity: 0.8;
    }

    100% {
        transform: scale(2);
        opacity: 0;
    }
}

.pin-green {
    color: #22c55e;
}

.pin-yellow {
    color: #eab308;
}

.pin-red {
    color: #ef4444;
}

/* Chatbot Typing Indicator */
.typing-indicator {
    display: inline-flex;
    gap: 4px;
    padding: 12px 16px;
    background: var(--chat-ai-bg);
    border-radius: 12px;
    border: 1px solid var(--border-color);
    width: fit-content;
    margin-bottom: 12px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

/* Chatbot Quick Actions */
.quick-actions-container {
    display: flex;
    gap: 8px;
    padding: 8px 0;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    margin-top: -8px;
    margin-bottom: 8px;
}

.quick-actions-container::-webkit-scrollbar {
    display: none;
}

.quick-action-btn {
    white-space: nowrap;
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--bg-highlight);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s ease;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.quick-action-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
    transform: translateY(-2px);
}

/* Specific Site KPI Boxes Glassmorphism */
.kpi-box {
    background: var(--bg-surface) !important;
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s !important;
}

.kpi-box:hover {
    transform: translateY(-2px) scale(1.02) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1) !important;
    background: var(--bg-highlight) !important;
}

.glow-highlight {
    box-shadow: 0 0 20px 5px rgba(56, 189, 248, 0.4) !important;
    border-color: var(--primary) !important;
    transform: translateY(-2px) !important;
    z-index: 10;
    transition: all 0.3s ease-in-out;
}

/* ============================================================
   CORREZIONI MOBILE RESPONSIVE PER SMARTPHONE (iOS / Android)
   ============================================================ */

@media (max-width: 768px) {

    /* --- 1. GESTIONE CANTIERI (Tabella con Scroll Orizzontale) --- */
    #manage-sites-view>div {
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch;
    }

    #manage-sites-view table {
        min-width: 600px !important;
        /* Mantiene la tabella leggibile permettendo lo scroll a destra */
    }

    /* --- 2. IMPOSTAZIONI ALERT (Input impilati in verticale) --- */
    #settings-view,
    #settings-per-site-container {
        max-width: 100% !important;
        padding: 12px !important;
    }

    /* Forziamo tutti i blocchi affiancati ad andare uno sotto l'altro */
    #settings-view div[style*="grid-template-columns"],
    #settings-per-site-container div[style*="grid-template-columns"],
    #settings-per-site-container div[style*="display: flex"] {
        display: flex !important;
        flex-direction: column !important;
        gap: 12px !important;
    }

    #settings-view input,
    #settings-view select {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    /* --- 3. ASSISTENTE AI (Chat a Schermo Intero) --- */
    #chatbot-view {
        height: calc(100vh - 120px) !important;
    }

    #chatbot-view>div {
        flex-direction: column !important;
        height: 100% !important;
    }

    /* Nascondiamo la colonna fissa delle Skills su mobile per dare tutto lo spazio alla Chat */
    #chatbot-skills-panel {
        display: none !important;
    }

    #chatbot-view>div>div:first-child {
        display: flex !important;
        flex-direction: column !important;
        height: 100% !important;
        flex: 1 !important;
        width: 100% !important;
    }

    #chat-history {
        flex: 1 !important;
        max-height: none !important;
        overflow-y: auto !important;
    }

    /* --- 4. DETTAGLIO CANTIERE & VISUAL DASHBOARD --- */
    #detail-name {
        font-size: 1.4rem !important;
        word-break: break-word;
    }

    /* Trasformiamo la griglia a 3 colonne affiancate in 1 colonna verticale impilata */
    .visual-dashboard {
        display: flex !important;
        flex-direction: column !important;
        height: auto !important;
        gap: 20px !important;
    }

    .dash-module {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .kpi-module {
        min-height: auto !important;
    }

    .chart-module {
        min-height: 340px !important;
    }

    .radar-module {
        min-height: 320px !important;
        height: 320px !important;
    }

    /* Segmented Controls (Pulsanti Oggi/Domani/1h/3h) */
    .segmented-control {
        flex-wrap: wrap !important;
    }

    .segment {
        padding: 6px 10px !important;
        font-size: 0.8rem !important;
        flex: 1;
        text-align: center;
    }
}