:root {
    --colore-primario: #2b6cb0;
    --colore-primario-scuro: #1a4971;
    --colore-ok: #2f855a;
    --colore-warn: #c05621;
    --colore-errore: #c53030;
    --colore-sfondo: #f4f6f8;
    --colore-bordo: #dde3e8;
    --colore-testo: #1a202c;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    background: var(--colore-sfondo);
    color: var(--colore-testo);
}

/* ============================================================
   LAYOUT + SIDEBAR COLLASSABILE
   Collassata mostra solo le icone; all'hover si espande e
   compaiono le didascalie. Su mobile diventa un menu off-canvas
   comandato dall'hamburger.
   ============================================================ */
:root {
    --sidebar-collassata: 64px;
    --sidebar-espansa: 220px;
}

.layout { min-height: 100vh; }

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--sidebar-collassata);
    background: var(--colore-primario-scuro);
    color: #fff;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    white-space: nowrap;
    transition: width 0.2s ease;
    z-index: 40;
}
.sidebar:hover { width: var(--sidebar-espansa); }

.sidebar .icona {
    flex: none;
    width: 24px;
    font-size: 1.2rem;
    text-align: center;
}
/* Collassata: la didascalia non occupa spazio, cosi' l'icona resta
   centrata nel contenitore. All'espansione ricompare (vedi :hover). */
.sidebar .label {
    opacity: 0;
    width: 0;
    overflow: hidden;
    white-space: nowrap;
    transition: opacity 0.15s ease;
}

/* Righe della sidebar: centrate quando collassata, allineate a sinistra
   quando espansa (hover). L'icona non si sposta orizzontalmente. */
.sidebar-brand,
.sidebar-nav a,
.sidebar-user-info,
.sidebar-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    padding-left: 0;
    padding-right: 0;
}
.sidebar:hover .label { opacity: 1; width: auto; margin-left: 0.9rem; }
.sidebar:hover .sidebar-brand,
.sidebar:hover .sidebar-nav a,
.sidebar:hover .sidebar-user-info,
.sidebar:hover .sidebar-logout {
    justify-content: flex-start;
    padding-left: 1.2rem;
}

.sidebar-brand {
    padding-top: 1rem;
    padding-bottom: 1rem;
    font-weight: 700;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar-nav { flex: 1; padding: 0.5rem 0; overflow-y: auto; overflow-x: hidden; }
.sidebar-nav a {
    padding-top: 0.7rem;
    padding-bottom: 0.7rem;
    color: #fff;
    text-decoration: none;
    opacity: 0.85;
    border-left: 3px solid transparent;
}
.sidebar-nav a:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }
.sidebar-nav a.active {
    opacity: 1;
    background: rgba(255, 255, 255, 0.12);
    border-left-color: #fff;
}

.sidebar-user { border-top: 1px solid rgba(255, 255, 255, 0.12); padding: 0.5rem 0; }
.sidebar-user-info {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
}
.sidebar-user-info .label { line-height: 1.2; }
.sidebar:hover .sidebar-user-info .label { display: flex; flex-direction: column; }
.sidebar-user-info small { color: #cbd5e0; font-size: 0.75rem; }
.sidebar-logout {
    padding-top: 0.6rem;
    padding-bottom: 0.6rem;
    color: #fff;
    text-decoration: none;
    opacity: 0.85;
}
.sidebar-logout:hover { opacity: 1; background: rgba(255, 255, 255, 0.08); }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    z-index: 30;
}

.content { margin-left: var(--sidebar-collassata); }
.content-full { margin-left: 0; }

.mobile-bar { display: none; }

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* ---- Mobile: sidebar off-canvas + hamburger ---- */
@media (max-width: 768px) {
    .sidebar {
        width: var(--sidebar-espansa);
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }
    /* Su mobile la sidebar e' sempre espansa: replico lo stato :hover. */
    .sidebar .label { opacity: 1; width: auto; margin-left: 0.9rem; }
    .sidebar-brand,
    .sidebar-nav a,
    .sidebar-user-info,
    .sidebar-logout {
        justify-content: flex-start;
        padding-left: 1.2rem;
    }
    .sidebar-user-info .label { display: flex; flex-direction: column; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-open .sidebar-overlay { display: block; }

    .content { margin-left: 0; }

    .mobile-bar {
        display: flex;
        align-items: center;
        gap: 0.75rem;
        background: var(--colore-primario-scuro);
        color: #fff;
        padding: 0.6rem 1rem;
        position: sticky;
        top: 0;
        z-index: 20;
    }
    .mobile-brand { font-weight: 700; }
    .hamburger {
        background: transparent;
        border: none;
        color: #fff;
        font-size: 1.4rem;
        line-height: 1;
        padding: 0.2rem 0.4rem;
        cursor: pointer;
    }
    .hamburger:hover { background: transparent; }
}

h1 { margin-top: 0; }

.login-box {
    max-width: 380px;
    margin: 4rem auto;
    background: #fff;
    padding: 2rem;
    border-radius: 8px;
    border: 1px solid var(--colore-bordo);
}

.form label {
    display: block;
    margin-top: 1rem;
    margin-bottom: 0.25rem;
    font-weight: 600;
    font-size: 0.9rem;
}

.form input,
.form select,
.form textarea {
    width: 100%;
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--colore-bordo);
    border-radius: 4px;
    font-size: 1rem;
}

.form-actions { margin-top: 1.5rem; display: flex; gap: 0.75rem; }

button, .button {
    display: inline-block;
    background: var(--colore-primario);
    color: #fff;
    border: none;
    padding: 0.55rem 1.1rem;
    border-radius: 4px;
    font-size: 0.95rem;
    cursor: pointer;
    text-decoration: none;
}
button:hover, .button:hover { background: var(--colore-primario-scuro); }

.button-secondary { background: #718096; }
.button-secondary:hover { background: #4a5568; }

.alert {
    padding: 0.65rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}
.alert-ok { background: #f0fff4; color: var(--colore-ok); border: 1px solid #c6f6d5; }
.alert-error { background: #fff5f5; color: var(--colore-errore); border: 1px solid #fed7d7; }

.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin: 1.5rem 0;
}
.card {
    background: #fff;
    border: 1px solid var(--colore-bordo);
    border-radius: 8px;
    padding: 1.25rem;
    text-align: center;
}
.card-highlight { border-color: var(--colore-primario); }
.card-value { display: block; font-size: 2rem; font-weight: 700; color: var(--colore-primario); }
.card-label { display: block; font-size: 0.85rem; color: #4a5568; margin-top: 0.25rem; }

.table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    margin-top: 1rem;
}
.table th, .table td {
    text-align: left;
    padding: 0.6rem 0.75rem;
    border-bottom: 1px solid var(--colore-bordo);
}
.table th { background: #edf2f7; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; }
.table-compact th, .table-compact td { padding: 0.4rem 0.6rem; font-size: 0.9rem; }
.table-actions a { margin-right: 0.75rem; font-size: 0.9rem; }
.table-actions form { display: inline; margin-right: 0.75rem; }
/* Bottone che si comporta da link (per azioni POST come "Disattiva"). */
.button-link {
    background: none;
    border: none;
    padding: 0;
    margin: 0;
    color: var(--colore-primario);
    font: inherit;
    font-size: 0.9rem;
    cursor: pointer;
    text-decoration: none;
}
.button-link:hover { background: none; color: var(--colore-primario-scuro); text-decoration: underline; }

.corsa-box {
    background: #fff;
    border: 1px solid var(--colore-bordo);
    border-radius: 8px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.badge {
    display: inline-block;
    font-size: 0.7rem;
    text-transform: uppercase;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: #edf2f7;
    color: #4a5568;
    margin-left: 0.4rem;
}

.stato { font-weight: 600; }
.stato-ok { color: var(--colore-ok); }
.stato-warn { color: var(--colore-warn); }
.stato-pending { color: #a0aec0; }

.footer {
    text-align: center;
    color: #a0aec0;
    padding: 2rem 0 1rem;
}
