:root {
    /* Tavolozza cromatica bilanciata per interfacce software moderne */
    --c-primary: #005aff;
    --c-primary-light: #2575ff;
    --c-accent: #22B14C;
    --c-accent-hover: #1b933e;
    --c-bg: #f8fafc;                  /* Grigio ardesia chiarissimo al posto del bianco piatto */
    --c-surface: #ffffff;             /* Bianco per i blocchi sopra lo sfondo */
    --c-text: #0f172a;                /* Blu/Nero profondo, molto leggibile ed elegante */
    --c-text-muted: #64748b;          /* Grigio intermedio per testi secondari */
    --c-text-opposite: #f8fafc;
    --c-secondary: #0f172a;           /* Sostituito il blu elettrico anni '90 con un navy scuro */
    --sidebar-width: 250px;
    --radius-md: 8px;                 /* Arrotondamenti standard moderni */
    --radius-lg: 12px;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.05), 0 1px 2px rgba(0,0,0,0.02);
    --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.04);
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    color-scheme: light;
}

@font-face {
    font-family: CustomFont;
    font-weight: bold;
    src: url("/assets/SpaceGrotesk-Bold.ttf");
}

@font-face {
    font-family: CustomFont;
    font-weight: normal;
    src: url("/assets/SpaceGrotesk-Regular.ttf");
}

html, body {
    margin: 0;
    padding: 0;
    font-family: CustomFont, system-ui, sans-serif;
    font-size: 18px; /* 16px è lo standard UI; puoi scalarlo dinamicamente */
    box-sizing: border-box;
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    background: var(--c-bg); /* Corretto il vecchio bug var(--c) */
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
}

body {
    overflow: auto !important;
    position: initial;
}

/* --- LOGO TEXT (Stile Tech Pulito) --- */
.text-logo { 
    padding: 40px 24px; 
    background: var(--c-secondary); /* Rimosso il vecchio gradiente violento */
    max-height: 190px; 
    height: auto; 
    text-align: center; 
    box-sizing: border-box; 
    width: 100%;
    margin: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
}

.text-logo span { 
    font-weight: bold; 
    width: 100%; 
    display: block; 
}

.text-logo span.upper { 
    line-height: 1; 
    color: #00B2FF; 
    font-size: clamp(1.8rem, 6vw, 3.5rem); /* Scalato per evitare rotture di layout */
    letter-spacing: -0.03em;
}

.text-logo span.lower { 
    line-height: 1.2; 
    color: var(--c-accent); 
    font-size: clamp(0.9rem, 3vw, 1.4rem);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

@media (max-width: 300px) { 
    .text-logo { display: none; }
}

/* --- LOADER (Design Fluido e Minimale) --- */
.loader {
    visibility: visible;
    opacity: 1;
    position: absolute;
    top: 50px;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(255, 255, 255);
    backdrop-filter: blur(12px); /* Effetto vetro smerigliato modernissimo */
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center; 
    transition: var(--transition);
    box-sizing: border-box;
    padding: 32px;
}

.loader.full { top: 0; }
.loader.closed { visibility: hidden; opacity: 0; }
.loader.hidden { display: none; }

.loader .loader-text {
    text-align: center;
    font-size: 1.1rem;
    color: var(--c-text-muted);
    font-weight: 500;
}

/* Animazione di caricamento svecchiata e pulita */
.loader .loader-element, .app-loader1 { 
    width: 40px; 
    aspect-ratio: 1; 
    display: grid; 
    border: 4px solid #0000; 
    border-radius: 50%; 
    border-color: var(--c-accent) #0000; 
    animation: l16 1s infinite linear; 
    margin-bottom: 16px;
}
.loader .loader-element::before, .loader .loader-element::after, .app-loader1::before, .app-loader1::after { 
    content: ""; 
    grid-area: 1/1; 
    margin: 2px; 
    border: inherit; 
    border-radius: 50%;
}
.loader .loader-element::before, .app-loader1::before { 
    border-color: var(--c-primary) #0000; 
    animation: inherit; 
    animation-duration: .5s; 
    animation-direction: reverse;
}
.loader .loader-element::after, .app-loader1::after { margin: 8px; }

@keyframes l16 { 100% {transform: rotate(1turn)} }
@keyframes rotation { 100% {transform: rotate(360deg)} }

.loader .loader-element.std, .app-loader2 {
    all: initial;
    width: 48px;
    aspect-ratio: 1;
    border-radius: 50%;
    background: 
        radial-gradient(farthest-side, var(--c-primary) 94%, #0000) top/8px 8px no-repeat,
        conic-gradient(#0000 30%, var(--c-primary));
    -webkit-mask: radial-gradient(farthest-side, #0000 calc(100% - 8px), #000 0);
    mask: radial-gradient(farthest-side, #0000 calc(100% - 8px), #000 0);
    animation: rotation 0.8s infinite linear;
    margin-bottom: 16px;
}

a {
    color: var(--c-primary);
    text-decoration: none;
    transition: var(--transition);
}
a:hover { color: var(--c-primary-light); }

/* --- SCHERMATE DI ERRORE --- */
.error-page {
    box-sizing: border-box;
    width: 100%;
    padding: 48px 24px;
    text-align: center;
}

.error-page .error-image {
    width: 80px;
    height: 80px;
    opacity: 0.9;
    margin-bottom: 24px;
}

.error-page .error-text {
    font-weight: bold;
    font-size: 1.5rem;
    color: #ef4444; /* Rosso desaturato, meno aggressivo */
    margin-bottom: 12px;
}

.error-page .error-message {
    font-size: 1.1rem;
    color: var(--c-text-muted);
}

.page { 
    display: flex; 
    min-height: 100%; 
    min-width: 100%; 
    flex-direction: column;
}

/* --- HEADER PRINCIPALE (Stile Minimal Vetro Fissato) --- */
.header {
    position: sticky;
    top: 0;
    box-sizing: border-box; 
    display: flex; 
    align-items: center; 
    justify-content: space-between; 
    flex-direction: row; 
    width: 100%; 
    padding: 16px 24px; 
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(15, 23, 42, 0.06); /* Separatore elegante al posto dell'ombra nera pesante */
    box-shadow: var(--shadow-sm);
    z-index: 500;
}

.header .logo { 
    font-weight: bold; 
    color: var(--c-text); 
    text-shadow: none; 
    display: flex; 
    align-items: flex-start; 
    justify-content: center; 
    flex-direction: column; 
    text-align: left; 
    font-size: 1.4rem; 
    line-height: 1;
    letter-spacing: 0.02em;
    height: 50px;
}

.header .logo img {
    max-height: 100%;
    border-radius: 8px;
}

.header .navbar {
    flex: 1; 
    display: flex; 
    flex-direction: row; 
    justify-content: flex-end; 
    align-items: center; 
    padding: 0; 
    gap: 8px;
}

/* Pulsanti della barra di navigazione svecchiati */
.header .navbar button {
    font-family: inherit;
    margin: 0; 
    border: none;
    padding: 8px 16px;
    box-sizing: border-box; 
    border-radius: var(--radius-md); 
    color: var(--c-text-muted); 
    transition: var(--transition); 
    font-size: 0.95rem; 
    font-weight: 500;
    background-color: transparent; 
    cursor: pointer; 
    line-height: 1.4;
}

.header .navbar button.active { 
    pointer-events: none; 
    background-color: rgba(0, 90, 255, 0.08); /* Effetto "pillola" attiva azzurrata */
    color: var(--c-primary); 
    font-weight: bold;
}

.header .navbar button:hover:not(.active) {
    background-color: rgba(15, 23, 42, 0.04);
    color: var(--c-text);
}

/* --- AREA CONTENUTO --- */
.page > .content {
    width: 100%; 
    padding: 24px; 
    box-sizing: border-box; 
    background: var(--c-bg); 
    flex: 1; 
    overflow: auto;
}

/* --- FOOTER --- */
.footer {
    width: 100%; 
    height: fit-content; 
    box-sizing: border-box; 
    background: var(--c-surface);
    color: var(--c-text-muted); 
    text-align: center; 
    padding: 24px;
    border-top: 1px solid rgba(15, 23, 42, 0.06);
}

.footer-brand { 
    font-weight: bold; 
    font-size: 1rem; 
    margin-bottom: 4px;
    color: var(--c-text);
}

.footer-legal { 
    font-size: 0.85rem; 
    color: var(--c-text-muted); 
}

.header .navbar button.hamburger {
    display: none;
    font-size: 1.3rem;
    color: var(--c-text);
    padding: 8px;
}

/* --- SIDEBAR MOBILE (Effetto Overlay Sfocato) --- */
.sidebar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    max-height: 100%;
    background-color: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    overflow-y: auto;
    padding-top: 80px;
    z-index: 499;
    transform: translateY(-100%);
    transition: transform 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: var(--shadow-md);
}

.sidebar-content { padding: 24px 0; }

.sidebar .sidebar-content .page-title {
    display: none;
    font-size: 1.3rem;
    margin-bottom: 24px;
    color: var(--c-text-opposite);
    font-weight: bold;
}

.sidebar .sidebar-content button {
    font: inherit;
    background-color: transparent;
    border: none;
    color: rgba(248, 250, 252, 0.8);
    font-size: 1.1rem;
    padding: 14px;
    width: 100%;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.sidebar .sidebar-content button.active {
    font-weight: bold;
    color: var(--c-primary-light);
    background: rgba(255, 255, 255, 0.05);
}

.sidebar .sidebar-content button:hover:not(.active) {
    color: #fff;
    background: rgba(255, 255, 255, 0.02);
}

@keyframes slideIn {
    0% { transform: translateY(-20px); opacity: 0; }
    100% { transform: translateY(0); opacity: 1; }
}

/* --- RESPONSIVE MODERNO --- */
@media screen and (max-width: 800px) {
    .header .navbar button.hamburger { display: block; }
    .header .navbar button:not(.hamburger) { display: none; }
    .header { padding: 12px 16px; }
    .header .logo { font-size: 1.25rem; }
    .sidebar.open { transform: translateY(0%); }
}

/* --- SCROLLBAR CUSTOMIZZATA TECH --- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background-color: transparent; }
::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.15);
    border-radius: 99px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(15, 23, 42, 0.3);
}