:root {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --secondary: #64748b;
    --accent: #0f172a; /* Colore scuro elegante */
    --bg: #f8fafc;
    --text: #334155;
    --danger: #ef4444;
    --success: #10b981;
}

* { box-sizing: border-box; }

body, html {
    margin: 0; padding: 0;
    font-family: 'Inter', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    height: 100%;
    overflow: hidden; /* Blocca scroll body per layout app */
}

/* --- LAYOUT --- */
.dashboard-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* --- SIDEBAR --- */
.sidebar {
    width: 260px;
    background: var(--accent);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    height: 100%;
    border-right: 1px solid rgba(255,255,255,0.05);
    flex-shrink: 0;
}

.sidebar-header {
    padding: 24px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: white;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar nav {
    flex: 1;
    padding: 20px 12px;
    overflow-y: auto;
}

.nav-section-label {
    padding: 0 12px;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: #94a3b8;
    font-weight: 700;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
    margin-top: 24px;
}
.nav-section-label:first-child { margin-top: 0; }

.nav-list {
    list-style: none; padding: 0; margin: 0;
}

.nav-link {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    color: #cbd5e1;
    text-decoration: none;
    transition: all 0.2s ease;
    font-weight: 500;
    border-radius: 8px;
    font-size: 0.92rem;
    margin-bottom: 4px;
    cursor: pointer; /* Importante per i toggle */
}

.nav-link:hover {
    background: rgba(255,255,255,0.08);
    color: white;
    transform: translateX(2px);
}

.nav-link.active {
    background: var(--primary);
    color: white;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

/* SOTTOMENU SIDEBAR */
.nav-group {
    margin-bottom: 4px;
}

.nav-toggle {
    justify-content: space-between;
}

.nav-sublist {
    list-style: none;
    margin: 0;
    padding-left: 12px; /* Indentazione */
    display: none;
    background: rgba(0,0,0,0.1); /* Sfondo leggermente più scuro per il gruppo */
    border-radius: 8px;
    padding-top: 4px;
    padding-bottom: 4px;
    margin-bottom: 4px;
}

.nav-group.open > .nav-sublist {
    display: block;
}

.nav-subitem {
    display: block;
    font-size: 0.85rem;
    padding: 8px 12px;
    border-radius: 6px;
    color: #94a3b8;
    text-decoration: none;
    margin-bottom: 2px;
}

.nav-subitem:hover {
    color: white;
    background: rgba(255,255,255,0.05);
}

.nav-subitem.active {
    color: white;
    font-weight: 600;
    background: rgba(255,255,255,0.1);
}

.toggle-icon {
    font-size: 0.8rem;
    opacity: 0.7;
}

.sidebar-footer {
    padding: 20px;
    background: rgba(0,0,0,0.2);
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* --- MAIN CONTENT --- */
.main-content {
    flex: 1;
    height: 100%;
    overflow-y: auto; /* Scroll indipendente del contenuto */
    padding: 30px;
    background: #f1f5f9;
}

/* --- CARDS & TABLES --- */
.card, .form-card {
    background: white;
    border-radius: 16px; /* Più arrotondato */
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
    border: 1px solid #e2e8f0;
    margin-bottom: 25px;
    overflow: hidden;
    display: block; /* Utile per i link-card */
    text-decoration: none; /* Rimuove sottolineatura dai link-card */
    color: inherit;
}

/* Hover effect per le card cliccabili (impostazioni) */
a.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    border-color: var(--primary);
    transition: all 0.2s ease;
}

.card-head, .card-header, .form-title {
    padding: 20px 25px;
    background: #ffffff;
    border-bottom: 1px solid #f1f5f9;
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--accent);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.form-body { padding: 25px; }

.table-responsive, .table-container {
    width: 100%;
    overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; }
th {
    text-align: left; padding: 16px 24px;
    background: #f8fafc; color: #64748b;
    font-size: 0.75rem; text-transform: uppercase;
    font-weight: 700; letter-spacing: 0.02em;
    border-bottom: 1px solid #e2e8f0;
}
td {
    padding: 16px 24px;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
    color: #334155;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background-color: #f8fafc; }

/* --- UTILS --- */
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 25px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 25px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 24px; }

.badge-inst {
    background: #eff6ff; color: #1d4ed8; padding: 4px 10px; 
    border-radius: 20px; font-size: 0.75rem; font-weight: 700; margin-right: 5px;
    border: 1px solid #dbeafe;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
}

.btn {
    display: inline-flex; justify-content: center; align-items: center;
    padding: 10px 20px; border-radius: 8px; font-weight: 600; cursor: pointer; 
    text-decoration: none; border: none; font-size: 0.9rem; transition: all 0.2s;
}
.btn-primary { background: var(--primary); color: white; box-shadow: 0 2px 4px rgba(59, 130, 246, 0.2); }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-secondary { background: white; border: 1px solid #cbd5e1; color: #475569; }
.btn-secondary:hover { background: #f8fafc; border-color: #94a3b8; }
.btn-danger { background: #fee2e2; color: #ef4444; }
.btn-danger:hover { background: #fecaca; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; border-radius: 6px; }

input, select {
    width: 100%; padding: 12px; border: 1px solid #cbd5e1;
    border-radius: 8px; margin-bottom: 16px; font-size: 0.95rem;
    transition: border-color 0.2s;
}
input:focus, select:focus { outline: none; border-color: var(--primary); ring: 2px solid rgba(59, 130, 246, 0.1); }
label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.85rem; color: var(--secondary); text-transform: uppercase; }

/* Login Page specific */
.login-container {
    height: 100vh; display: flex; align-items: center; justify-content: center; background: #f1f5f9;
}

/* ---------- PAGE TOOLBAR (Per le pagine interne) ---------- */
.page-toolbar {
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: 999px;
    border: 1px solid #cbd5e1;
    background: #e2e8f0;
    color: #1e293b;
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-back:hover {
    background: #cbd5e1;
}

.btn-back.secondary {
    background: white;
}

.btn-back.secondary:hover {
    background: #f1f5f9;
    border-color: #94a3b8;
}

/* --- AGGIUNTE PER DASHBOARD HEADER (Da mettere in style.css) --- */

/* --- LAYOUT HEADER --- */
.header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: center; /* Allinea verticalmente al centro */
    padding-top: 20px;
    margin-bottom: 40px;
}

/* --- FILTRO ANNO COMPATTO --- */
.year-filter-container {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    margin-right: 25px; /* Spazio tra anno e utente */
}

.compact-select {
    padding: 4px 8px;       /* Molto più piccolo */
    font-size: 0.8rem;      /* Font ridotto */
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    background-color: white;
    color: #334155;
    cursor: pointer;
    outline: none;
    min-width: auto;
}

.year-dates {
    font-size: 0.65rem;
    color: #94a3b8;
    margin-top: 2px;
}

/* --- MENU UTENTE A TENDINA (FIX "PONTE INVISIBILE") --- */
.user-menu-container {
    position: relative;
    height: 100%;
    display: flex;
    align-items: center;
    cursor: pointer;
    z-index: 5000;
}

/* ⬇️ QUESTA È LA MAGIA: IL PONTE INVISIBILE ⬇️ */
.user-menu-container::after {
    content: '';
    position: absolute;
    top: 100%;      /* Inizia dal fondo della foto */
    left: 0;
    width: 100%;
    height: 25px;   /* Altezza sufficiente a coprire lo spazio vuoto */
    background: transparent; /* Invisibile */
}

.user-pill {
    display: flex;
    align-items: center;
    gap: 12px;
    transition: opacity 0.2s;
}

.user-menu-container:hover .user-pill {
    opacity: 0.8;
}

/* Il menu appare quando si va in hover sul container */
.user-menu-container:hover .user-menu-dropdown {
    display: block;
    animation: fadeIn 0.2s ease-out;
}

.user-menu-dropdown {
    display: none; 
    position: absolute;
    top: 100%;          /* Posizione base */
    right: 0;
    width: 180px;
    background: white;
    border: 1px solid #e2e8f0;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    overflow: hidden;
    z-index: 5001;      /* Superiore al resto */
    margin-top: 10px;   /* Distanza visiva (coperta dal ponte invisibile) */
}

.user-menu-item {
    display: block;
    padding: 10px 15px;
    font-size: 0.9rem;
    color: #475569;
    text-decoration: none;
    transition: background 0.1s;
    border-bottom: 1px solid #f1f5f9;
}

.user-menu-item:last-child {
    border-bottom: none;
}

.user-menu-item:hover {
    background-color: #f8fafc;
    color: #1e293b;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* --- STILI DASHBOARD AGGIUNTIVI --- */

/* Wrapper Header */
.header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: flex-end; /* Allinea alla base per un look più pulito */
    padding: 30px 0 30px 0; /* Spaziatura verticale */
    margin-bottom: 20px;
    border-bottom: 1px solid #f1f5f9; /* Linea separatrice sottile */
}

/* Stat Card Styling */
.stat-card {
    background: white;
    padding: 25px;
    border-radius: 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.03);
    border: 1px solid #f1f5f9;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
}

.stat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.06);
}

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

.stat-title {
    font-size: 0.85rem;
    color: #64748b;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Icone con sfondo colorato */
.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-icon.blue   { background-color: #eff6ff; color: #3b82f6; }
.stat-icon.red    { background-color: #fef2f2; color: #ef4444; }
.stat-icon.green  { background-color: #f0fdf4; color: #10b981; }
.stat-icon.yellow { background-color: #fefce8; color: #eab308; }
.stat-icon.purple { background-color: #f3e8ff; color: #a855f7; }

.stat-value {
    font-size: 2.2rem;
    font-weight: 800;
    color: #0f172a;
    line-height: 1;
    margin-bottom: 5px;
}

.stat-sub {
    font-size: 0.9rem;
    color: #94a3b8;
    font-weight: 500;
}

/* Card Grandi (Grafici/Tabelle) */
.dashboard-section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #1e293b;
    margin-bottom: 20px;
    margin-top: 40px;
}

/* Griglia Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 40px;
}