/**
 * BalzOS Design System v2.1
 * macOS Sonoma/Sequoia — Glass, Dock, Menu Bar, Window Chrome
 * Dark Mode (default) + Light Mode via [data-theme="light"]
 */

/* ============================================================================
   1. Design Tokens — Dark Mode (default)
   ============================================================================ */
:root {
    /* Desktop background */
    --body-bg: #0c1220;

    /* Window / Panel surfaces */
    --window-bg:      rgba(14, 14, 16, 0.82);
    --sidebar-bg:     rgba(20, 20, 22, 0.90);
    --card-bg:        rgba(40, 40, 42, 0.55);
    --card-hover:     rgba(54, 54, 56, 0.68);
    --surface-color:  rgba(40, 40, 42, 0.55);
    --surface-elevated: rgba(54, 54, 56, 0.68);

    /* Glass */
    --glass-bg:     rgba(40, 40, 42, 0.55);
    --glass-border: rgba(255, 255, 255, 0.09);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);

    /* Borders */
    --border-subtle: rgba(255, 255, 255, 0.08);
    --border-color:  rgba(255, 255, 255, 0.09);
    --border-strong: rgba(255, 255, 255, 0.15);

    /* Accent */
    --accent:        #0a84ff;
    --accent-hover:  #409cff;

    /* Text hierarchy */
    --text-primary:   #f2f2f7;
    --text-secondary: rgba(255, 255, 255, 0.55);
    --text-tertiary:  rgba(255, 255, 255, 0.28);
    --text-muted:     rgba(255, 255, 255, 0.35);
    --text-light:     #ffffff;

    /* Legacy compat */
    --primary-color:    rgba(20, 20, 22, 0.90);
    --primary-dark:     #0d0d10;
    --bg-primary:       #0d0d10;
    --bg-secondary:     rgba(40, 40, 42, 0.55);
    --bg-sidebar:       rgba(20, 20, 22, 0.90);
    --secondary-color:  #0a84ff;
    --secondary-light:  #409cff;
    --secondary-dark:   #0066cc;
    --accent-color:     #5e5ce6;
    --accent-light:     #7d7aff;
    --accent-pink:      #ff375f;
    --accent-cyan:      #5ac8fa;

    /* Module gradients */
    --module-amministrazione: linear-gradient(180deg, #62dc80 0%, #24a043 100%);
    --module-magazzino:       linear-gradient(180deg, #ffe047 0%, #ccaa00 100%);
    --module-presenze:        linear-gradient(180deg, #47a3ff 0%, #0065cc 100%);
    --module-rendicontazione: linear-gradient(180deg, #d593f6 0%, #a921ee 100%);
    --module-produzione:      linear-gradient(180deg, #ff7f77 0%, #fc0e00 100%);
    --module-iot:             linear-gradient(180deg, #95dcfc 0%, #1fb4f8 100%);
    --module-video:           linear-gradient(180deg, #9291ee 0%, #2a27de 100%);
    --module-ai:              linear-gradient(180deg, #ff7490 0%, #f90032 100%);
    --module-infrastruttura:  linear-gradient(180deg, #47a3ff 0%, #0065cc 100%);
    --module-preventivazione: linear-gradient(180deg, #f7b546 0%, #bb7808 100%);
    --module-rt:              linear-gradient(180deg, #5cc5d8 0%, #248496 100%);

    /* Status */
    --success-color: #30d158;
    --warning-color: #ffd60a;
    --danger-color:  #ff453a;
    --info-color:    #0a84ff;

    /* Shadows */
    --shadow-sm:  0 1px 4px rgba(0, 0, 0, 0.35);
    --shadow-md:  0 4px 16px rgba(0, 0, 0, 0.45);
    --shadow-lg:  0 8px 32px rgba(0, 0, 0, 0.55);
    --shadow-xl:  0 16px 48px rgba(0, 0, 0, 0.65);
    --shadow-2xl: 0 24px 64px rgba(0, 0, 0, 0.75);

    /* Spacing */
    --spacing-xs:  0.25rem;
    --spacing-sm:  0.5rem;
    --spacing-md:  1rem;
    --spacing-lg:  1.5rem;
    --spacing-xl:  2rem;
    --spacing-2xl: 3rem;

    /* Radius */
    --radius-sm:  6px;
    --radius-md:  10px;
    --radius-lg:  14px;
    --radius-xl:  16px;
    --radius-2xl: 20px;

    /* Motion */
    --transition-fast:   150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow:   400ms cubic-bezier(0.4, 0, 0.2, 1);
    --ease-spring:       cubic-bezier(0.34, 1.56, 0.64, 1);
    --ease-out:          cubic-bezier(0.16, 1, 0.3, 1);
}

/* ============================================================================
   2. Light Mode — [data-theme="light"]
   ============================================================================ */
[data-theme="light"] {
    --body-bg: transparent;           /* usa wallpaper.jpg come dark mode */
    --window-bg: rgba(235, 235, 240, 0.68); /* vetro frosted chiaro */
    --sidebar-bg:       #d4d4da;      /* grigio medio-scuro — sidebar */
    --card-bg:          #ffffff;      /* bianco puro — cards (contrasto netto) */
    --card-hover:       #f5f5f7;      /* grigio chiarissimo — hover */
    --surface-color:    #ffffff;
    --surface-elevated: #ffffff;

    --glass-bg:     #ffffff;
    --glass-border: rgba(0, 0, 0, 0.08);

    --border-subtle: rgba(0, 0, 0, 0.08);
    --border-color:  rgba(0, 0, 0, 0.11);
    --border-strong: rgba(0, 0, 0, 0.18);

    --text-primary:   #1c1c1e;
    --text-secondary: rgba(60, 60, 67, 0.6);
    --text-tertiary:  rgba(60, 60, 67, 0.30);
    --text-muted:     rgba(60, 60, 67, 0.40);
    --text-light:     #1c1c1e;

    --bg-primary:    #f2f2f7;
    --bg-secondary:  #ffffff;
    --bg-sidebar:    #e8e8ed;
    --primary-color: #ffffff;

    --shadow-sm:  0 1px 4px rgba(0, 0, 0, 0.10);
    --shadow-md:  0 4px 16px rgba(0, 0, 0, 0.12);
    --shadow-lg:  0 8px 32px rgba(0, 0, 0, 0.14);
    --shadow-xl:  0 16px 48px rgba(0, 0, 0, 0.16);
    --shadow-2xl: 0 24px 64px rgba(0, 0, 0, 0.18);
}

[data-theme="light"] .macos-menubar {
    background: rgba(220, 220, 228, 0.85);
    border-bottom-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .macos-dock {
    background: rgba(215, 215, 225, 0.82);
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow:
        0 8px 40px rgba(0, 0, 0, 0.15),
        0 2px 0 rgba(255, 255, 255, 0.6) inset;
}

[data-theme="light"] .dock-tooltip {
    background: rgba(28, 28, 30, 0.88);
    border-color: rgba(0, 0, 0, 0.15);
}

[data-theme="light"] .macos-window {
    background: rgba(235, 235, 240, 0.68);
    backdrop-filter: blur(30px) saturate(160%);
    -webkit-backdrop-filter: blur(30px) saturate(160%);
    box-shadow:
        0 22px 60px rgba(0, 0, 0, 0.22),
        0 1px 0 rgba(255, 255, 255, 0.6) inset;
    border-color: rgba(0, 0, 0, 0.10);
}

[data-theme="light"] .window-titlebar {
    background: rgba(228, 228, 235, 0.92);
    border-bottom-color: rgba(0, 0, 0, 0.09);
}

[data-theme="light"] .collapsible-header {
    background: rgba(255, 255, 255, 0.55);
}
[data-theme="light"] .collapsible-header:hover {
    background: rgba(255, 255, 255, 0.75);
}

[data-theme="light"] .module-card:hover {
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .stat-card:hover {
    box-shadow: var(--shadow-md);
}

[data-theme="light"] .dock-separator {
    background: rgba(0, 0, 0, 0.12);
}

[data-theme="light"] .menubar-logout:hover {
    background: rgba(255, 69, 58, 0.1);
}

[data-theme="light"] .btn-nav {
    background: rgba(255, 255, 255, 0.7);
    color: #1c1c1e;
}

[data-theme="light"] .tipo-pill.entrata { background: rgba(48, 209, 88, 0.12); }
[data-theme="light"] .tipo-pill.uscita  { background: rgba(255, 69, 58, 0.1); }

/* ============================================================================
   3. Reset + Base
   ============================================================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html { scroll-behavior: smooth; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'SF Pro Display',
                 Inter, 'Helvetica Neue', Arial, sans-serif;
    background:
        url("/static/core/img/wallpaper.c5107205dff9.jpg") center center / cover no-repeat fixed;
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    padding-top: 28px;
    padding-bottom: 108px;
    min-height: 100vh;
    overflow-x: hidden;
    transition: background-color 0.35s ease, color 0.2s ease;
}

/* light mode: body keeps wallpaper.jpg from base body rule */

*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 3px;
}

/* ============================================================================
   4. macOS Menu Bar
   ============================================================================ */
.macos-menubar {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 28px;
    background: rgba(14, 14, 16, 0.88);
    backdrop-filter: blur(24px) saturate(180%);
    -webkit-backdrop-filter: blur(24px) saturate(180%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    z-index: 500;
    display: flex;
    align-items: center;
    padding: 0 14px;
    user-select: none;
    transition: background 0.3s ease;
}

.menubar-left {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.menubar-brand {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-primary);
    text-decoration: none;
    letter-spacing: -0.02em;
    flex-shrink: 0;
    transition: opacity var(--transition-fast);
}
.menubar-brand:hover { opacity: 0.75; }
.menubar-brand .blue { color: #c3bcb3; }
.menubar-brand .cyan { color: #b68255; }

.menubar-divider {
    color: rgba(255, 255, 255, 0.22);
    font-size: 0.65rem;
    flex-shrink: 0;
}
[data-theme="light"] .menubar-divider { color: rgba(0,0,0,0.22); }

.menubar-page {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menubar-right {
    display: flex;
    align-items: center;
    gap: 2px;
    flex-shrink: 0;
}

.menubar-time {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-primary);
    letter-spacing: 0.01em;
    min-width: 38px;
    text-align: center;
    padding: 0 6px;
}

.menubar-user-info {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 3px 7px;
    border-radius: 6px;
    transition: background var(--transition-fast);
    cursor: default;
}
.menubar-user-info:hover { background: rgba(255,255,255,0.07); }
[data-theme="light"] .menubar-user-info:hover { background: rgba(0,0,0,0.06); }

.menubar-avatar {
    width: 18px; height: 18px;
    background: var(--accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.58rem; font-weight: 700;
    color: white; flex-shrink: 0;
}

.menubar-username {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-primary);
}

/* Theme Toggle */
.menubar-theme-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 26px; height: 20px;
    border-radius: 5px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.75rem;
    font-family: inherit;
    transition: background var(--transition-fast), color var(--transition-fast);
    flex-shrink: 0;
}
.menubar-theme-toggle:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}
[data-theme="light"] .menubar-theme-toggle:hover { background: rgba(0,0,0,0.07); }

.menubar-logout {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 3px 8px;
    border-radius: 6px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 0.72rem;
    font-family: inherit;
    transition: background var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
}
.menubar-logout:hover {
    background: rgba(255, 69, 58, 0.12);
    color: #ff453a;
}
.menubar-logout i { font-size: 0.85rem; }

/* ============================================================================
   5. macOS Window Chrome
   ============================================================================ */
.macos-window-wrap {
    padding: 8px 12px 0;
    animation: windowAppear 0.35s var(--ease-out) backwards;
}

@keyframes windowAppear {
    from { opacity: 0; transform: scale(0.982) translateY(8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

.macos-window {
    background: var(--window-bg);
    backdrop-filter: blur(30px) saturate(180%);
    -webkit-backdrop-filter: blur(30px) saturate(180%);
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow:
        0 22px 64px rgba(0, 0, 0, 0.7),
        0 1px 0 rgba(255, 255, 255, 0.06) inset;
    overflow: hidden;
    transition: background 0.3s ease;
}

.window-titlebar {
    height: 40px;
    background: rgba(22, 22, 24, 0.98);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    display: flex;
    align-items: center;
    padding: 0 14px;
    gap: 10px;
    position: sticky;
    top: 28px;
    z-index: 100;
    flex-shrink: 0;
    transition: background 0.3s ease;
}

.window-controls {
    display: flex;
    align-items: center;
    gap: 7px;
    flex-shrink: 0;
}

.traffic-light {
    width: 12px; height: 12px;
    border-radius: 50%;
    display: block;
    opacity: 0.82;
    transition: opacity var(--transition-fast), filter var(--transition-fast);
}
.traffic-light:hover { opacity: 1; }
.window-titlebar:hover .traffic-light { opacity: 1; }

.tl-close    { background: #ff5f57; box-shadow: 0 0 0 0.5px rgba(0,0,0,0.25) inset; }
.tl-minimize { background: #febc2e; box-shadow: 0 0 0 0.5px rgba(0,0,0,0.25) inset; }
.tl-maximize { background: #28c840; box-shadow: 0 0 0 0.5px rgba(0,0,0,0.25) inset; }

.window-title {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-secondary);
    flex: 1;
    text-align: center;
    letter-spacing: 0.005em;
    pointer-events: none;
}

.window-titlebar-spacer { width: 52px; flex-shrink: 0; }

/* ============================================================================
   6. macOS Dock
   ============================================================================ */
.macos-dock {
    position: fixed;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 500;
    background: rgba(36, 36, 38, 0.82);
    backdrop-filter: blur(40px) saturate(200%);
    -webkit-backdrop-filter: blur(40px) saturate(200%);
    border: 1px solid rgba(255, 255, 255, 0.14);
    border-radius: 20px;
    box-shadow:
        0 8px 40px rgba(0, 0, 0, 0.6),
        0 2px 0 rgba(255, 255, 255, 0.06) inset,
        0 -1px 0 rgba(0, 0, 0, 0.3) inset;
    padding: 8px 10px;
    display: flex;
    align-items: flex-end;
    gap: 4px;
    user-select: none;
    -webkit-user-select: none;
    animation: dockAppear 0.55s 0.1s var(--ease-spring) backwards;
    transition: background 0.3s ease, border-color 0.3s ease;
}

@keyframes dockAppear {
    from { opacity: 0; transform: translateX(-50%) translateY(24px) scale(0.88); }
    to   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
}

.dock-separator {
    width: 1px;
    height: 38px;
    background: rgba(255, 255, 255, 0.12);
    margin: 0 3px 8px;
    align-self: flex-end;
    flex-shrink: 0;
    transition: background 0.3s ease;
}

.dock-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    gap: 3px;
    cursor: pointer;
    position: relative;
    text-decoration: none !important;
    height: 68px;
    padding-bottom: 2px;
    -webkit-tap-highlight-color: transparent;
}

.dock-icon {
    width: 52px; height: 52px;
    border-radius: 12px; /* fallback se clip-path non supportato */
    clip-path: url(#squircle-clip);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.55rem;
    color: white;
    flex-shrink: 0;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    position: relative;
    z-index: 1;
    overflow: hidden;
    transition: transform 300ms var(--ease-spring), box-shadow 150ms ease;
    will-change: transform;
}

/* Velo di luce superiore, coerente con .app-icon */
.dock-icon::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 52%;
    background: linear-gradient(180deg, rgba(255,255,255,0.30) 0%, rgba(255,255,255,0) 100%);
    pointer-events: none;
}

.dock-item.active .dock-icon {
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.5), 0 0 0 2px rgba(255, 255, 255, 0.22);
}

.dock-dot {
    width: 4px; height: 4px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.55);
    flex-shrink: 0;
    opacity: 0;
    transition: opacity var(--transition-fast);
}
.dock-item.active .dock-dot { opacity: 1; background: rgba(255,255,255,0.8); }

.dock-tooltip {
    position: absolute;
    bottom: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%) translateY(5px);
    background: rgba(20, 20, 22, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    color: white;
    font-size: 0.7rem; font-weight: 600;
    padding: 4px 9px;
    border-radius: 7px;
    white-space: nowrap;
    pointer-events: none;
    opacity: 0;
    transition: opacity 140ms ease, transform 140ms ease;
    z-index: 600;
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
}
.dock-item:hover .dock-tooltip { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Dock icon gradients — stessi colori delle app icon desktop */
.dock-icon.dock-dashboard  { background: linear-gradient(145deg, #3a3a3c, #2a2a2c); border: 1px solid rgba(255,255,255,0.1); }
.dock-icon.dock-amm        { background: linear-gradient(180deg, #62dc80, #24a043); }
.dock-icon.dock-iot        { background: linear-gradient(180deg, #95dcfc, #1fb4f8); }
.dock-icon.dock-chat       { background: linear-gradient(180deg, #ff7490, #f90032); }
.dock-icon.dock-rend       { background: linear-gradient(180deg, #d593f6, #a921ee); }
.dock-icon.dock-cnc        { background: linear-gradient(180deg, #ff7f77, #fc0e00); }
.dock-icon.dock-presenze   { background: linear-gradient(180deg, #47a3ff, #0065cc); }
.dock-icon.dock-infra      { background: linear-gradient(180deg, #47a3ff, #0065cc); }
.dock-icon.dock-sistema    { background: linear-gradient(145deg, #3d4f6b, #4a5c7a); }
.dock-icon.dock-magazzino  { background: linear-gradient(180deg, #ffe047, #ccaa00); }
.dock-icon.dock-rt         { background: linear-gradient(180deg, #5cc5d8, #248496); }
.dock-icon.dock-api        { background: linear-gradient(145deg, #48484a, #3a3a3c); border: 1px solid rgba(255,255,255,0.1); }
.dock-icon.dock-admin      { background: linear-gradient(145deg, #ff453a, #bb2018); }

/* ============================================================================
   7. Main Content
   ============================================================================ */
.main-content {
    padding: var(--spacing-xl) var(--spacing-xl);
    min-height: calc(100vh - 28px - 40px - 108px);
}

/* ============================================================================
   8. Page Greeting
   ============================================================================ */
.page-greeting {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    padding-bottom: 24px;
    margin-bottom: 4px;
}

.greeting-title {
    font-size: 1.75rem; font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
    margin: 0 0 4px 0;
    line-height: 1.2;
}

.greeting-sub { color: var(--text-tertiary); font-size: 0.85rem; margin: 0; }

.greeting-badge-live {
    font-size: 0.7rem; color: #30d158; font-weight: 600;
    letter-spacing: 0.02em;
    padding: 4px 10px;
    background: rgba(48, 209, 88, 0.10);
    border: 1px solid rgba(48, 209, 88, 0.20);
    border-radius: 20px;
    backdrop-filter: blur(8px);
}

/* ============================================================================
   9. Section Headers
   ============================================================================ */
.section-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.section-icon { font-size: 1.3rem; color: var(--text-secondary); }

.section-title {
    font-size: 1.3rem; font-weight: 600;
    color: var(--text-primary); margin: 0;
    letter-spacing: -0.01em;
}

.section-subtitle { color: var(--text-secondary); font-size: 0.875rem; margin-top: 2px; }

.collapsible-header {
    cursor: pointer;
    user-select: none;
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    transition: background var(--transition-fast);
}
.collapsible-header:hover { background: var(--card-hover); }

.collapse-icon {
    font-size: 1.1rem;
    color: var(--text-tertiary);
    transition: transform var(--transition-normal);
    margin-left: auto;
}
.collapsible-header[aria-expanded="true"] .collapse-icon { transform: rotate(180deg); }

/* ============================================================================
   10. Stats Cards — Glass
   ============================================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: var(--spacing-lg);
    margin-bottom: var(--spacing-xl);
}

.stat-card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: var(--spacing-lg);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-sm);
    transition: background var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.12), transparent);
}

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

.stat-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: var(--spacing-sm);
}

.stat-title {
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.stat-icon {
    width: 44px; height: 44px;
    border-radius: var(--radius-lg);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
    backdrop-filter: blur(4px);
}

.stat-icon.primary  { background: rgba(10, 132, 255, 0.15); color: #0a84ff; }
.stat-icon.success  { background: rgba(48, 209, 88, 0.15);  color: #30d158; }
.stat-icon.danger   { background: rgba(255, 69, 58, 0.15);  color: #ff453a; }
.stat-icon.warning  { background: rgba(255, 214, 10, 0.15); color: #ffd60a; }
.stat-icon.info     { background: rgba(90, 200, 250, 0.15); color: #5ac8fa; }

.stat-value {
    font-size: 1.9rem; font-weight: 700;
    color: var(--text-primary);
    margin-bottom: var(--spacing-xs);
    letter-spacing: -0.02em;
}

.stat-description { font-size: 0.78rem; color: var(--text-secondary); }

/* ============================================================================
   11. Module Cards — Glass
   ============================================================================ */
.modules-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--spacing-lg);
}

.module-card {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-radius: var(--radius-xl);
    padding: var(--spacing-lg);
    border: 1px solid var(--border-subtle);
    border-top: 2px solid rgba(255, 255, 255, 0.05);
    box-shadow: var(--shadow-sm);
    transition: background var(--transition-fast), box-shadow var(--transition-fast), transform var(--transition-fast);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* Shimmer line at top */
.module-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.1), transparent);
    opacity: 0;
    transition: opacity var(--transition-fast);
}
.module-card:hover::before { opacity: 1; }

.module-card:hover {
    background: var(--card-hover);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    transform: translateY(-2px);
}

.module-glow { display: none; }

/* Module top-border accents */
.module-amministrazione  { border-top-color: #30d158; }
.module-amministrazione:hover  { border-color: var(--border-subtle); border-top-color: #30d158; box-shadow: 0 8px 32px rgba(48,209,88,0.12); }
.module-magazzino        { border-top-color: #ffd60a; }
.module-magazzino:hover        { border-color: var(--border-subtle); border-top-color: #ffd60a; box-shadow: 0 8px 32px rgba(255,214,10,0.12); }
.module-presenze         { border-top-color: #0a84ff; }
.module-presenze:hover         { border-color: var(--border-subtle); border-top-color: #0a84ff; box-shadow: 0 8px 32px rgba(10,132,255,0.12); }
.module-rendicontazione  { border-top-color: #bf5af2; }
.module-rendicontazione:hover  { border-color: var(--border-subtle); border-top-color: #bf5af2; box-shadow: 0 8px 32px rgba(191,90,242,0.12); }
.module-produzione       { border-top-color: #ff453a; }
.module-produzione:hover       { border-color: var(--border-subtle); border-top-color: #ff453a; box-shadow: 0 8px 32px rgba(255,69,58,0.12); }
.module-iot              { border-top-color: #5ac8fa; }
.module-iot:hover              { border-color: var(--border-subtle); border-top-color: #5ac8fa; box-shadow: 0 8px 32px rgba(90,200,250,0.12); }
.module-video            { border-top-color: #5e5ce6; }
.module-video:hover            { border-color: var(--border-subtle); border-top-color: #5e5ce6; box-shadow: 0 8px 32px rgba(94,92,230,0.12); }
.module-ai               { border-top-color: #ff375f; }
.module-ai:hover               { border-color: var(--border-subtle); border-top-color: #ff375f; box-shadow: 0 8px 32px rgba(255,55,95,0.12); }
.module-infrastruttura   { border-top-color: #0a84ff; }
.module-infrastruttura:hover   { border-color: var(--border-subtle); border-top-color: #0a84ff; box-shadow: 0 8px 32px rgba(10,132,255,0.12); }

.module-header {
    display: flex; align-items: center;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-md);
}

.module-icon-container { position: relative; width: 48px; height: 48px; flex-shrink: 0; }

.module-icon {
    position: relative; width: 100%; height: 100%;
    border-radius: var(--radius-lg);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.4rem;
    background: linear-gradient(135deg, var(--accent), #5e5ce6);
    color: white; z-index: 2;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}

.module-icon-bg { display: none; }

.module-amministrazione .module-icon  { background: var(--module-amministrazione); }
.module-magazzino .module-icon        { background: var(--module-magazzino); }
.module-presenze .module-icon         { background: var(--module-presenze); }
.module-rendicontazione .module-icon  { background: var(--module-rendicontazione); }
.module-produzione .module-icon       { background: var(--module-produzione); }
.module-iot .module-icon              { background: var(--module-iot); }
.module-video .module-icon            { background: var(--module-video); }
.module-ai .module-icon               { background: var(--module-ai); }
.module-infrastruttura .module-icon   { background: var(--module-infrastruttura); }

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

.module-title {
    font-size: 1rem; font-weight: 600;
    color: var(--text-primary); margin: 0;
    line-height: 1.3; letter-spacing: -0.01em;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.module-description {
    color: var(--text-secondary);
    font-size: 0.825rem;
    line-height: 1.5;
    flex: 1; margin-bottom: 0;
}

.module-footer {
    display: flex; align-items: center;
    justify-content: space-between;
    padding-top: var(--spacing-md);
    border-top: 1px solid var(--border-subtle);
    margin-top: auto;
}

.module-version-bottom {
    text-align: center;
    margin-top: var(--spacing-sm);
    font-size: 0.68rem;
    color: var(--text-tertiary);
    font-weight: 500;
}

.module-status {
    display: inline-flex; align-items: center;
    gap: var(--spacing-xs);
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 0.78rem; font-weight: 600;
}

.module-status.not-implemented {
    background: rgba(255, 214, 10, 0.10);
    border: 1px solid rgba(255, 214, 10, 0.25);
    color: #ffd60a;
}

.module-status.active,
.module-status.implemented {
    background: rgba(48, 209, 88, 0.10);
    border: 1px solid rgba(48, 209, 88, 0.25);
    color: #30d158;
}

.module-status.inactive {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-subtle);
    color: var(--text-tertiary);
}

.status-indicator {
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.6; transform: scale(1.2); }
}

.module-actions { display: flex; gap: var(--spacing-xs); }

.btn-module {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 5px 14px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    font-size: 0.8rem; font-weight: 600;
    cursor: not-allowed;
    transition: all var(--transition-fast);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-tertiary);
    white-space: nowrap;
}

.btn-module:not(:disabled),
.btn-module[href] {
    cursor: pointer;
    background: var(--accent);
    color: white;
    border-color: transparent;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(10,132,255,0.25);
}

.btn-module:not(:disabled):hover,
.btn-module[href]:hover {
    background: var(--accent-hover);
    box-shadow: 0 4px 14px rgba(10, 132, 255, 0.4);
    transform: translateY(-1px);
}

.btn-module:not(:disabled):active,
.btn-module[href]:active { transform: translateY(0); }

.btn-module i { font-size: 1rem; }
.btn-module:disabled { opacity: 0.4; }

/* ============================================================================
   12. Shared Button Nav
   ============================================================================ */
.btn-nav {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    color: var(--text-primary);
    font-size: 0.875rem; font-weight: 500;
    text-decoration: none;
    transition: all var(--transition-fast);
    cursor: pointer;
}
.btn-nav:hover {
    background: var(--secondary-color);
    color: #fff;
    border-color: var(--secondary-color);
    box-shadow: 0 4px 12px rgba(10,132,255,0.3);
}

/* ============================================================================
   13. macOS Tables
   ============================================================================ */
.macos-table-wrapper {
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.macos-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.macos-table thead {
    /* position: sticky rimosso — causa rendering bug in Safari/WebKit
       con overflow:hidden sul wrapper parent */
}

.macos-table thead th {
    padding: 10px 16px;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.055em;
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.04);
    border-bottom: 1px solid var(--border-subtle);
    white-space: nowrap;
}

[data-theme="light"] .macos-table thead th {
    background: rgba(0, 0, 0, 0.03);
}

.macos-table tbody tr {
    transition: background var(--transition-fast);
    border-bottom: 1px solid var(--border-subtle);
}

.macos-table tbody tr:last-child {
    border-bottom: none;
}

.macos-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
}
[data-theme="light"] .macos-table tbody tr:hover { background: rgba(0,0,0,0.025); }

.macos-table tbody td {
    padding: 11px 16px;
    color: var(--text-primary);
    vertical-align: middle;
}

.macos-table tbody td.muted { color: var(--text-secondary); }
.macos-table tbody td.mono  { font-family: 'SF Mono', SFMono-Regular, 'Fira Code', Consolas, monospace; font-size: 0.82rem; }

/* Generic table style (for inline tables in templates) */
table.table-macos { border-collapse: collapse; width: 100%; font-size: .875rem; }
table.table-macos th,
table.table-macos td { padding: .65rem 1rem; }
table.table-macos th {
    font-size: .72rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: .05em; color: var(--text-secondary);
    background: rgba(255,255,255,.04);
    border-bottom: 1px solid var(--border-subtle);
}
[data-theme="light"] table.table-macos th { background: rgba(0,0,0,.03); }
table.table-macos tr { border-bottom: 1px solid var(--border-subtle); transition: background var(--transition-fast); }
table.table-macos tr:last-child { border-bottom: none; }
table.table-macos tr:hover td { background: rgba(255,255,255,.03); }
[data-theme="light"] table.table-macos tr:hover td { background: rgba(0,0,0,.02); }

/* ============================================================================
   Desktop Mode — scrivania trasparente (solo dashboard)
   ============================================================================ */
.window-wrap--desktop {
    padding: 0;
}

.macos-window--desktop {
    background: transparent !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    border: none !important;
    box-shadow: none !important;
    border-radius: 0 !important;
}

.macos-window--desktop .window-titlebar {
    display: none !important;
}

.macos-window--desktop .main-content {
    padding: var(--spacing-xl) var(--spacing-xl);
    min-height: calc(100vh - 28px - 108px);
}

/* Greeting desktop */
/* ── Infrastructure Alert Banner ─────────────────────────────── */
.infra-alert {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    border-radius: 10px;
    margin-bottom: 16px;
    font-size: 0.85rem;
    font-weight: 500;
}
.infra-alert--warning {
    background: rgba(255, 159, 10, 0.15);
    border: 1px solid rgba(255, 159, 10, 0.35);
    color: #ff9f0a;
}
.infra-alert--danger {
    background: rgba(255, 69, 58, 0.15);
    border: 1px solid rgba(255, 69, 58, 0.35);
    color: #ff453a;
}
.infra-alert-icon { flex-shrink: 0; font-size: 1rem; }
.infra-alert-link {
    margin-left: auto;
    font-size: 0.78rem;
    opacity: 0.8;
    text-decoration: none;
    white-space: nowrap;
}
.infra-alert--warning .infra-alert-link { color: #ff9f0a; }
.infra-alert--danger  .infra-alert-link { color: #ff453a; }
.infra-alert-link:hover { opacity: 1; text-decoration: underline; }

[data-theme="light"] .infra-alert--warning { color: #b87000; border-color: rgba(184,112,0,0.35); background: rgba(255,159,10,0.1); }
[data-theme="light"] .infra-alert--danger  { color: #c0392b; border-color: rgba(192,57,43,0.35);  background: rgba(255,69,58,0.08); }
[data-theme="light"] .infra-alert--warning .infra-alert-link { color: #b87000; }
[data-theme="light"] .infra-alert--danger  .infra-alert-link { color: #c0392b; }

.desktop-greeting {
    margin-bottom: 36px;
    padding: 0 6px;
}

.desktop-greeting-title {
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    margin: 0 0 6px;
    line-height: 1.1;
    text-shadow: 0 2px 10px rgba(0,0,0,0.35);
}

[data-theme="light"] .desktop-greeting-title {
    text-shadow: none;
}

.desktop-greeting-sub {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ─── macOS App Icon Grid ─── */
.macos-app-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 28px 24px;
    padding: 0 6px;
    align-content: flex-start;
    justify-content: center;
    margin-bottom: var(--spacing-xl);
}

/* Forza un a capo tra un gruppo tematico di icone e il successivo,
   restando dentro lo stesso flex container (nessun div annidato: le
   icone restano tutte figlie dirette di .macos-app-grid). */
.macos-app-row-break {
    flex-basis: 100%;
    height: 0;
    margin: 0;
    padding: 0;
}

.macos-app-group-label {
    flex-basis: 100%;
    text-align: center;
    color: rgba(255, 255, 255, 0.75);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin: 4px 0 -8px;
    /* Stesso accorgimento di .desktop-greeting-title: il wallpaper "scrivania"
       è la stessa immagine chiara (legno) in entrambi i temi, non un colore
       pieno legato al tema — var(--text-tertiary) è troppo debole (pensata
       per sfondi di superficie piatti) e sparisce quasi del tutto qui sopra. */
    text-shadow: 0 1px 6px rgba(0,0,0,0.5);
}
.macos-app-group-label:first-child { margin-top: 0; }

[data-theme="light"] .macos-app-group-label {
    color: rgba(40, 30, 20, 0.7);
    text-shadow: 0 1px 3px rgba(255,255,255,0.7);
}

.macos-app-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    text-decoration: none !important;
    cursor: pointer;
    position: relative;
    width: 80px;
    -webkit-tap-highlight-color: transparent;
    animation: iconAppear 0.4s var(--ease-spring) backwards;
    transition: transform 200ms var(--ease-spring);
}

.macos-app-icon:hover { transform: scale(1.1); }
.macos-app-icon:active { transform: scale(0.92) !important; }

/* Staggered entrance */
.macos-app-icon:nth-child(1)  { animation-delay: 0ms; }
.macos-app-icon:nth-child(2)  { animation-delay: 45ms; }
.macos-app-icon:nth-child(3)  { animation-delay: 90ms; }
.macos-app-icon:nth-child(4)  { animation-delay: 135ms; }
.macos-app-icon:nth-child(5)  { animation-delay: 180ms; }
.macos-app-icon:nth-child(6)  { animation-delay: 225ms; }
.macos-app-icon:nth-child(7)  { animation-delay: 270ms; }
.macos-app-icon:nth-child(8)  { animation-delay: 315ms; }
.macos-app-icon:nth-child(9)  { animation-delay: 360ms; }

@keyframes iconAppear {
    from {
        opacity: 0;
        transform: scale(0.65) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.app-icon {
    width: 76px;
    height: 76px;
    border-radius: 17px; /* fallback se clip-path non supportato */
    clip-path: url(#squircle-clip);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.3rem;
    color: white;
    position: relative;
    overflow: hidden;
    box-shadow:
        0 10px 22px rgba(0,0,0,0.38),
        0 2px 5px rgba(0,0,0,0.22);
    transition:
        box-shadow 200ms ease,
        transform 200ms var(--ease-spring);
    flex-shrink: 0;
}

/* Velo di luce superiore — sfumatura molto più tenue, coerente su tutte le icone */
.app-icon::before {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 52%;
    background: linear-gradient(180deg, rgba(255,255,255,0.32) 0%, rgba(255,255,255,0) 100%);
    pointer-events: none;
}

.macos-app-icon:hover .app-icon {
    box-shadow:
        0 12px 36px rgba(0,0,0,0.55),
        0 3px 6px rgba(0,0,0,0.25),
        0 1px 0 rgba(255,255,255,0.18) inset;
    transform: translateY(-3px);
}

.app-icon-label {
    font-size: 0.72rem;
    font-weight: 600;
    color: var(--text-primary);
    text-align: center;
    width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-shadow: 0 1px 5px rgba(0,0,0,0.4);
    letter-spacing: -0.01em;
    line-height: 1.3;
}

[data-theme="light"] .app-icon-label {
    text-shadow: none;
    color: #1c1c1e;
}

/* Inactive app (in sviluppo) */
.macos-app-icon.app-inactive {
    cursor: default;
    pointer-events: none;
}

.macos-app-icon.app-inactive .app-icon {
    filter: grayscale(55%) opacity(0.55);
}

.macos-app-icon.app-inactive .app-icon-label {
    color: var(--text-tertiary);
    text-shadow: none;
}

.app-inactive-badge {
    position: absolute;
    top: -5px;
    right: -9px;
    background: rgba(255,214,10,0.92);
    color: #000;
    font-size: 0.52rem;
    font-weight: 800;
    padding: 2px 5px;
    border-radius: 6px;
    white-space: nowrap;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    pointer-events: none;
    z-index: 5;
}

/* App icon backgrounds per modulo */
.app-icon.app-amministrazione  { background: var(--module-amministrazione); }
.app-icon.app-magazzino        { background: var(--module-magazzino); }
.app-icon.app-presenze         { background: var(--module-presenze); }
.app-icon.app-rendicontazione  { background: var(--module-rendicontazione); }
.app-icon.app-produzione       { background: var(--module-produzione); }
.app-icon.app-iot              { background: var(--module-iot); }
.app-icon.app-video            { background: var(--module-video); }
.app-icon.app-ai               { background: var(--module-ai); }
.app-icon.app-infrastruttura   { background: var(--module-infrastruttura); }
.app-icon.app-preventivazione  { background: var(--module-preventivazione); }
.app-icon.app-rt               { background: var(--module-rt); }
.app-icon.app-default          { background: linear-gradient(145deg, #3a3a3c, #2a2a2c); border: 1px solid rgba(255,255,255,0.08); }
.app-icon.app-sistema          { background: linear-gradient(145deg, #3d4f6b 0%, #4a5c7a 45%, #6b7fa0 100%); }
.app-icon.app-statistiche      { background: linear-gradient(145deg, #b45309 0%, #f59e0b 45%, #fde68a 100%); }
.app-icon.app-server           { background: linear-gradient(145deg, #0e7490 0%, #06b6d4 45%, #67e8f9 100%); }
.app-icon.app-credenziali      { background: linear-gradient(145deg, #166534 0%, #22c55e 45%, #86efac 100%); }
.app-icon.app-accessi          { background: linear-gradient(145deg, #9f1239 0%, #f43f5e 45%, #fda4af 100%); }
.app-icon.app-sicurezza        { background: linear-gradient(145deg, #7c1d1d 0%, #dc2626 45%, #fca5a5 100%); }
.app-icon.app-salute           { background: linear-gradient(145deg, #064e3b 0%, #059669 45%, #6ee7b7 100%); }
.app-icon.app-agenda           { background: linear-gradient(180deg, #47a3ff 0%, #0065cc 100%); }
.app-icon.app-amm              { background: linear-gradient(180deg, #47a3ff 0%, #0065cc 100%); }
.app-icon.app-api              { background: linear-gradient(145deg, #48484a 0%, #636366 45%, #8e8e93 100%); }
.app-icon.app-django           { background: linear-gradient(145deg, #064e3b 0%, #059669 45%, #6ee7b7 100%); }
.app-icon.app-email            { background: linear-gradient(145deg, #7c2d8e 0%, #a855f7 45%, #d8b4fe 100%); }
.app-icon.app-backup           { background: linear-gradient(145deg, #1e3a8a 0%, #3b82f6 45%, #93c5fd 100%); }
.app-icon.app-servizi          { background: linear-gradient(145deg, #78350f 0%, #d97706 45%, #fcd34d 100%); }
.app-icon.app-testsuite        { background: linear-gradient(145deg, #312e81 0%, #6366f1 45%, #a5b4fc 100%); }
.app-icon.app-connettivita      { background: linear-gradient(145deg, #0c4a6e 0%, #0ea5e9 45%, #7dd3fc 100%); }
.app-icon.app-watchdog-cnc      { background: linear-gradient(145deg, #7f1d1d 0%, #ef4444 45%, #fca5a5 100%); }
.app-icon.app-integrazioni      { background: linear-gradient(145deg, #134e4a 0%, #14b8a6 45%, #5eead4 100%); }
.app-icon.app-aggiornamenti     { background: linear-gradient(145deg, #064e3b 0%, #10b981 45%, #6ee7b7 100%); }
.app-icon-badge-avviso {
    position: absolute; top: -4px; right: -4px;
    width: 14px; height: 14px; border-radius: 50%;
    background: #ef4444; border: 2px solid var(--card-bg, #1c1c1e);
}
.app-icon.app-timbra           { background: linear-gradient(180deg, #1beba6 0%, #0b815a 100%); }

/* ─── Desktop Info Panels (statistiche/admin sotto le icone) ─── */
.desktop-section-label {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--text-tertiary);
    margin: var(--spacing-xl) 0 var(--spacing-md) 6px;
}

.desktop-panel-header {
    display: flex;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-md) var(--spacing-lg);
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    cursor: pointer;
    user-select: none;
    transition: background var(--transition-fast);
    margin-bottom: var(--spacing-sm);
}

.desktop-panel-header:hover { background: var(--card-hover); }

/* ============================================================================
   14. macOS Forms
   ============================================================================ */
.macos-form-group {
    margin-bottom: var(--spacing-lg);
}

.macos-label {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: var(--spacing-sm);
}
.macos-label i { color: var(--accent); }

.macos-input,
.macos-select,
.macos-textarea {
    width: 100%;
    padding: 9px 13px;
    font-size: 0.9rem;
    font-family: inherit;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    transition:
        border-color var(--transition-fast),
        box-shadow var(--transition-fast),
        background var(--transition-fast);
    -webkit-appearance: none;
    appearance: none;
}

[data-theme="light"] .macos-input,
[data-theme="light"] .macos-select,
[data-theme="light"] .macos-textarea {
    background: rgba(0, 0, 0, 0.04);
}

.macos-input:focus,
.macos-select:focus,
.macos-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.20);
    background: rgba(255, 255, 255, 0.09);
}

[data-theme="light"] .macos-input:focus,
[data-theme="light"] .macos-select:focus,
[data-theme="light"] .macos-textarea:focus {
    background: rgba(0, 0, 0, 0.05);
}

.macos-input::placeholder,
.macos-textarea::placeholder { color: var(--text-tertiary); }

.macos-textarea { resize: vertical; min-height: 90px; }

.macos-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='rgba(255,255,255,0.4)' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14L2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 34px;
}

/* ============================================================================
   15. Brand Header (compat) + legacy styles
   ============================================================================ */
.brand-header {
    background: var(--card-bg);
    backdrop-filter: blur(8px);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-xl);
    padding: var(--spacing-md) var(--spacing-lg);
    margin-bottom: var(--spacing-lg);
    display: flex; align-items: center; justify-content: space-between;
}
.brand-header-content { display: flex; align-items: center; gap: var(--spacing-md); }
.brand-logo-container { width: 48px; height: 48px; flex-shrink: 0; }
.brand-logo-img { width: 48px; height: 48px; border-radius: var(--radius-lg); }
.brand-version-badge { display: flex; align-items: center; padding: 4px 10px; background: rgba(10,132,255,0.08); border: 1px solid rgba(10,132,255,0.2); border-radius: var(--radius-md); font-size: 0.75rem; font-weight: 700; }
.version-label { color: #0a84ff; }
.brand-text { flex: 1; }
.brand-title { font-size: 1.4rem; font-weight: 700; margin: 0; display: flex; align-items: baseline; gap: 6px; line-height: 1.2; }
.brand-balz { color: #0a84ff; }
.brand-os { color: #5ac8fa; }
.brand-separator { color: var(--border-subtle); }
.brand-dash { color: var(--text-secondary); font-weight: 500; font-size: 1rem; }
.brand-welcome { display: flex; align-items: center; gap: var(--spacing-xs); color: var(--text-secondary); font-size: 0.8rem; margin: 2px 0 0 0; }
.brand-welcome i { color: var(--accent); }
.brand-actions { display: flex; align-items: center; gap: var(--spacing-sm); }
.brand-badge { display: flex; align-items: center; gap: 4px; padding: 4px 10px; background: rgba(48,209,88,0.08); border: 1px solid rgba(48,209,88,0.2); border-radius: var(--radius-md); color: #30d158; font-size: 0.75rem; font-weight: 600; }
.page-header { margin-bottom: var(--spacing-xl); }
.page-title { font-size: 2rem; font-weight: 700; color: var(--text-primary); margin-bottom: var(--spacing-xs); }
.page-subtitle { color: var(--text-secondary); font-size: 1rem; }

/* ============================================================================
   16. Mobile Bottom Navigation (hidden on desktop)
   ============================================================================ */
.mobile-nav         { display: none; }
.mobile-nav-sheet   { display: none; }
.mobile-nav-overlay { display: none; }

/* ============================================================================
   17. Responsive
   ============================================================================ */
@media (max-width: 1200px) {
    .modules-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 992px) {
    .modules-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    /* Base spacing */
    body { padding-top: 28px; padding-bottom: 74px; }

    /* Window chrome — slim, no radius waste */
    .macos-window-wrap { padding: 4px 4px 0; }
    .macos-window { border-radius: 10px; }
    .main-content { padding: var(--spacing-md); }

    /* Hide desktop-only elements */
    .macos-dock     { display: none !important; }
    .window-titlebar { display: none !important; }
    .menubar-username { display: none; }
    .menubar-time { min-width: 32px; font-size: 0.72rem; }

    /* Content grids */
    .modules-grid { grid-template-columns: 1fr; gap: var(--spacing-md); }
    .stats-grid   { grid-template-columns: 1fr; gap: var(--spacing-md); }
    .module-card  { padding: var(--spacing-md); }
    .section-title { font-size: 1.1rem; }
    .greeting-title { font-size: 1.4rem; }
    .page-title { font-size: 1.5rem; }

    /* ── Mobile Bottom Nav ── */
    .mobile-nav {
        display: flex;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        height: 60px;
        background: rgba(22, 22, 24, 0.96);
        backdrop-filter: blur(30px) saturate(200%);
        -webkit-backdrop-filter: blur(30px) saturate(200%);
        border-top: 1px solid rgba(255, 255, 255, 0.1);
        z-index: 500;
        align-items: stretch;
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }
    [data-theme="light"] .mobile-nav {
        background: rgba(242, 242, 247, 0.96);
        border-top: 1px solid rgba(0,0,0,0.1);
    }

    .mobile-nav-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        color: rgba(255, 255, 255, 0.4);
        text-decoration: none !important;
        font-size: 0.58rem;
        font-weight: 600;
        letter-spacing: 0.01em;
        background: none;
        border: none;
        cursor: pointer;
        padding: 6px 2px 4px;
        -webkit-tap-highlight-color: transparent;
        transition: color 0.15s ease, transform 0.1s ease;
        font-family: inherit;
        min-height: 44px;
    }
    [data-theme="light"] .mobile-nav-item { color: rgba(0,0,0,0.38); }

    .mobile-nav-item i { font-size: 1.35rem; line-height: 1; }

    .mobile-nav-item.active       { color: #0a84ff; }
    .mobile-nav-item:active       { transform: scale(0.88); }
    [data-theme="light"] .mobile-nav-item.active { color: #007aff; }

    /* Dot indicator under active icon */
    .mobile-nav-item.active::after {
        content: '';
        display: block;
        width: 4px; height: 4px;
        border-radius: 50%;
        background: #0a84ff;
        margin-top: -1px;
    }
    .mobile-nav-item span { margin-top: 1px; }

    /* ── Slide-up Sheet overlay ── */
    .mobile-nav-overlay {
        display: block;
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, 0);
        z-index: 600;
        pointer-events: none;
        transition: background 0.25s ease;
    }
    .mobile-nav-overlay.active {
        background: rgba(0, 0, 0, 0.55);
        pointer-events: all;
        backdrop-filter: blur(2px);
        -webkit-backdrop-filter: blur(2px);
    }

    /* ── Slide-up Sheet ── */
    .mobile-nav-sheet {
        display: flex;
        flex-direction: column;
        position: fixed;
        bottom: 0; left: 0; right: 0;
        background: rgba(28, 28, 30, 0.99);
        backdrop-filter: blur(40px) saturate(200%);
        -webkit-backdrop-filter: blur(40px) saturate(200%);
        border-radius: 20px 20px 0 0;
        border-top: 1px solid rgba(255, 255, 255, 0.12);
        z-index: 700;
        padding: 12px 20px;
        padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
        transform: translateY(100%);
        transition: transform 0.38s cubic-bezier(0.34, 1.2, 0.64, 1);
        max-height: 75vh;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    [data-theme="light"] .mobile-nav-sheet {
        background: rgba(242, 242, 247, 0.99);
        border-top: 1px solid rgba(0,0,0,0.1);
    }
    .mobile-nav-sheet.open { transform: translateY(0); }

    .mobile-sheet-handle {
        width: 40px; height: 4px;
        border-radius: 2px;
        background: rgba(255, 255, 255, 0.22);
        margin: 0 auto 14px;
        flex-shrink: 0;
    }
    [data-theme="light"] .mobile-sheet-handle { background: rgba(0,0,0,0.18); }

    .mobile-sheet-title {
        font-size: 0.68rem;
        font-weight: 700;
        color: var(--text-tertiary);
        text-transform: uppercase;
        letter-spacing: 0.07em;
        margin-bottom: 18px;
        text-align: center;
    }

    .mobile-sheet-grid {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 20px 8px;
        padding-bottom: 8px;
    }

    .mobile-sheet-item {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 6px;
        text-decoration: none !important;
        color: var(--text-secondary);
        font-size: 0.62rem;
        font-weight: 500;
        text-align: center;
        -webkit-tap-highlight-color: transparent;
        transition: transform 0.12s ease;
    }
    .mobile-sheet-item:active { transform: scale(0.88); }

    .mobile-sheet-item .dock-icon {
        width: 54px; height: 54px;
        border-radius: 14px;
        font-size: 1.45rem;
        box-shadow: 0 3px 10px rgba(0, 0, 0, 0.4);
    }
}

@media (max-width: 480px) {
    .main-content { padding: var(--spacing-sm) var(--spacing-md); }
    .stat-card { padding: var(--spacing-md); }
    .stat-value { font-size: 1.5rem; }
    .stat-icon { width: 38px; height: 38px; font-size: 1.1rem; }
    .module-card { padding: var(--spacing-sm) var(--spacing-md); }
    .module-icon-container { width: 44px; height: 44px; }
    .module-icon { font-size: 1.2rem; }
    .module-title { font-size: 0.95rem; }
    .greeting-title { font-size: 1.25rem; }
    .page-title { font-size: 1.25rem; }
    .page-subtitle { font-size: 0.875rem; }
    .menubar-logout-text { display: none; }
    .mobile-sheet-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (hover: none) and (pointer: coarse) {
    .module-card:hover { background: var(--card-bg); box-shadow: var(--shadow-sm); transform: none; }
    .stat-card:hover   { background: var(--card-bg); box-shadow: var(--shadow-sm); transform: none; }
}

/* ============================================================================
   17. Animations + Utilities
   ============================================================================ */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.module-card,
.stat-card {
    animation: fadeIn var(--transition-normal) ease-out backwards;
}

.module-card:nth-child(1) { animation-delay: 0ms; }
.module-card:nth-child(2) { animation-delay: 45ms; }
.module-card:nth-child(3) { animation-delay: 90ms; }
.module-card:nth-child(4) { animation-delay: 135ms; }
.module-card:nth-child(5) { animation-delay: 180ms; }
.module-card:nth-child(6) { animation-delay: 225ms; }
.module-card:nth-child(7) { animation-delay: 270ms; }
.module-card:nth-child(8) { animation-delay: 315ms; }

.skeleton {
    background: linear-gradient(90deg, var(--card-bg) 25%, var(--card-hover) 50%, var(--card-bg) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    border-radius: var(--radius-sm);
}

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

.is-loading { position: relative; pointer-events: none; opacity: 0.6; }
.is-loading::after {
    content: '';
    position: absolute;
    top: 50%; left: 50%;
    width: 20px; height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid var(--accent);
    border-top-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ============================================================================
   18. Login Page
   ============================================================================ */
.login-page-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 0;
}

.login-container {
    --bg-primary:   rgba(20, 20, 22, 0.8);
    --bg-secondary: rgba(40, 40, 42, 0.55);
    --text-primary: #f2f2f7;
    --text-secondary: rgba(255, 255, 255, 0.55);
    --border-color: rgba(255, 255, 255, 0.1);
    --secondary-color: #0a84ff;
    --success-color: #30d158;
}

/* ============================================================================
   Traffic Light Controls — functional
   ============================================================================ */
.traffic-light { cursor: pointer; }

/* ============================================================================
   Minimized window dock item
   ============================================================================ */
.dock-icon.dock-minimized-win {
    background: linear-gradient(145deg, #374151 0%, #4b5563 55%, #6b7280 100%);
}
.minimized-in-dock {
    animation: dockItemBounceIn 0.45s cubic-bezier(0.34,1.56,0.64,1) both;
}
.minimized-in-dock .dock-dot {
    background: #fbbf24 !important;
    opacity: 1 !important;
    visibility: visible !important;
}
@keyframes dockItemBounceIn {
    from { opacity: 0; transform: translateY(18px) scale(0.5); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================================
   Mini Dock — legacy, unused
   ============================================================================ */
.macos-minidock {
    position: fixed;
    bottom: 92px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 900;
    pointer-events: none;
}
.minidock-pill {
    pointer-events: all;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 13px 5px 10px;
    background: rgba(28, 28, 32, 0.90);
    backdrop-filter: blur(24px) saturate(1.8);
    -webkit-backdrop-filter: blur(24px) saturate(1.8);
    border: 1px solid rgba(255,255,255,0.13);
    border-radius: 22px;
    cursor: pointer;
    font-size: .76rem;
    font-weight: 500;
    color: rgba(255,255,255,0.84);
    user-select: none;
    animation: pillAppear .35s cubic-bezier(0.34,1.56,0.64,1) both;
    transition: background .15s, transform .15s;
}
.minidock-pill:hover {
    background: rgba(52, 52, 58, 0.96);
    transform: translateY(-3px);
}
.minidock-pill .pill-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #fbbf24;
    flex-shrink: 0;
}
@keyframes pillAppear {
    from { opacity: 0; transform: translateY(14px) scale(.75); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================================================
   Context Menu (right-click on mini dock pill)
   ============================================================================ */
.balzos-ctxmenu {
    position: fixed;
    background: rgba(30, 30, 34, 0.97);
    backdrop-filter: blur(28px) saturate(2);
    -webkit-backdrop-filter: blur(28px) saturate(2);
    border: 1px solid rgba(255,255,255,0.13);
    border-radius: 10px;
    padding: 4px;
    z-index: 20000;
    min-width: 148px;
    box-shadow: 0 10px 44px rgba(0,0,0,0.60), 0 2px 8px rgba(0,0,0,0.30);
    animation: ctxAppear .12s ease both;
    transform-origin: bottom center;
}
@keyframes ctxAppear {
    from { opacity: 0; transform: scale(.92); }
    to   { opacity: 1; transform: scale(1); }
}
.balzos-ctxmenu-item {
    padding: 7px 13px;
    border-radius: 7px;
    cursor: pointer;
    font-size: .8rem;
    font-weight: 500;
    color: rgba(255,255,255,0.85);
    transition: background .1s;
    white-space: nowrap;
}
.balzos-ctxmenu-item:hover { background: rgba(255,255,255,0.08); }
.balzos-ctxmenu-item.danger { color: #f87171; }
.balzos-ctxmenu-sep {
    height: 1px;
    background: rgba(255,255,255,0.09);
    margin: 3px 2px;
}

/* ============================================================================
   Security Alarm Banner
   ============================================================================ */
#security-alarm-banner {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 9999;
    background: linear-gradient(90deg, #7f1d1d, #dc2626, #7f1d1d);
    background-size: 200% 100%;
    animation: alarmScroll 3s linear infinite, alarmFlash 1s ease-in-out infinite alternate;
    border-bottom: 2px solid #ff453a;
    box-shadow: 0 4px 30px rgba(255, 69, 58, 0.6);
}
@keyframes alarmScroll {
    0%   { background-position: 0% 50%; }
    100% { background-position: 200% 50%; }
}
@keyframes alarmFlash {
    from { box-shadow: 0 4px 20px rgba(255,69,58,.4); }
    to   { box-shadow: 0 4px 40px rgba(255,69,58,.9); }
}
.alarm-inner {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 20px;
    max-width: 100%;
    flex-wrap: wrap;
}
.alarm-pulse {
    width: 10px; height: 10px;
    border-radius: 50%;
    background: #fff;
    flex-shrink: 0;
    animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%       { opacity: 0.4; transform: scale(0.7); }
}
.alarm-icon {
    font-size: 1.2rem;
    color: #fff;
    flex-shrink: 0;
}
.alarm-text {
    flex: 1;
    font-size: 0.85rem;
    color: #fff;
    font-weight: 500;
    min-width: 0;
}
.alarm-text code {
    background: rgba(0,0,0,.3);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.82rem;
    color: #ffd60a;
}
.alarm-text em {
    color: #ffd60a;
    font-style: normal;
    font-weight: 700;
}
.alarm-btn-detail {
    display: inline-flex; align-items: center;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    background: rgba(255,255,255,.15);
    color: #fff;
    text-decoration: none;
    border: 1px solid rgba(255,255,255,.3);
    white-space: nowrap;
    transition: background .15s;
}
.alarm-btn-detail:hover { background: rgba(255,255,255,.25); color: #fff; }
.alarm-btn-dismiss {
    display: inline-flex; align-items: center; gap: 5px;
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    background: rgba(0,0,0,.25);
    color: #fff;
    border: 1px solid rgba(255,255,255,.2);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s;
}
.alarm-btn-dismiss:hover { background: rgba(0,0,0,.4); }

/* Spinge il contenuto sotto il banner quando attivo */
body:has(#security-alarm-banner) .macos-menubar { top: 44px; }
body:has(#security-alarm-banner) .macos-window-wrap { padding-top: calc(28px + 44px); }
@media (max-width: 768px) {
    body:has(#security-alarm-banner) { padding-top: calc(28px + 44px); }
    .alarm-text { font-size: 0.75rem; }
}

/* ============================================================================
   GLOBAL MOBILE FIX — overflow e tabelle responsive
   ============================================================================ */

/* Previeni overflow orizzontale su tutte le pagine */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}
.main-content {
    overflow-x: hidden;
    max-width: 100%;
}

/* Tabelle responsive su mobile */
@media (max-width: 768px) {
    /* Tutte le tabelle diventano scrollabili */
    .table-responsive-mobile {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 10px;
    }
    table {
        min-width: 500px;
    }

    /* Griglia app dashboard: 4 icone per riga su mobile */
    .macos-app-grid {
        grid-template-columns: repeat(4, 1fr) !important;
        gap: .75rem !important;
        padding: .75rem !important;
    }
    .macos-app-icon .app-icon {
        width: 52px !important;
        height: 52px !important;
        font-size: 1.4rem !important;
    }
    .app-icon-label {
        font-size: .6rem !important;
    }

    /* Card e pannelli */
    .glass-card, .card {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    /* Form input touch-friendly */
    input, select, textarea, button {
        min-height: 40px;
    }

    /* Bottoni azione affiancati in orizzontale */
    .btn-group-mobile {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }
}

@media (max-width: 480px) {
    /* Testo pagina più compatto */
    h1 { font-size: 1.4rem !important; }
    h2 { font-size: 1.2rem !important; }

    /* Nascondi colonne secondarie nelle tabelle se hanno la classe */
    .col-hide-mobile { display: none !important; }
}
