/* ============================================
   AMBRA AREA UTENTE - Mobile-First Styles
   ============================================ */

:root {
    /* ---- Palette Studio27 (immagine coordinata, feb 2025) ---- */
    --s27-blu-notte: #072E41;   /* contesti eleganti e sobri */
    --s27-ardesia: #233E52;
    --s27-blu: #2D6281;
    --s27-principale: #3A84A0;  /* soluzione principale */
    --s27-arancio: #D77E3B;
    --s27-rosso: #B62E2E;

    /* Ruoli UI. Il principale #3A84A0 sta a 4.2:1 su bianco: identità e
       superfici sì, testo no — per quello si usa il blu #2D6281 (6.6:1). */
    --primary: #2D6281;
    --primary-rgb: 45, 98, 129;
    --primary-light: #3A84A0;
    --primary-dark: #072E41;
    --brand-rgb: 58, 132, 160;
    --accent: #2D6281;
    --accent-light: #3A84A0;
    --success: #27ae60;
    --success-dark: #1D7A4C;   /* verde leggibile come testo */
    --warning: #D77E3B;
    --warning-dark: #9C5522;    /* arancio leggibile come testo */
    --danger: #B62E2E;
    --gray-50: #f8f9fa;
    --gray-100: #f1f3f5;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-400: #ced4da;
    --gray-500: #adb5bd;
    --gray-600: #868e96;
    --gray-700: #495057;
    --gray-800: #343a40;
    --header-height: 56px;
    --alerts-banner-height: 0px;
    --bottom-nav-height: 64px;
    --sidebar-width: 240px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ---- Reset & Base ---- */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-100);
    color: var(--gray-800);
}

/* ---- Bootstrap Primary Override ---- */
.bg-primary { background-color: var(--primary) !important; }
.btn-primary { background-color: var(--primary); border-color: var(--primary); }
.btn-primary:hover, .btn-primary:focus { background-color: var(--primary-dark); border-color: var(--primary-dark); }
.btn-outline-primary { color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background-color: var(--primary); border-color: var(--primary); color: white; }
.text-primary { color: var(--primary) !important; }
.form-control:focus, .form-select:focus { border-color: var(--primary); box-shadow: 0 0 0 0.2rem rgba(var(--primary-rgb),0.15); }

/* ---- Splash Screen ---- */
.splash-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    transition: opacity 0.3s ease;
}

.splash-screen.fade-out {
    opacity: 0;
    pointer-events: none;
}

.splash-content {
    text-align: center;
    color: white;
}

.splash-icon { margin-bottom: 1rem; }

.letter-spacing-wide { letter-spacing: 0.4em; }

/* ---- Login ---- */
.login-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
}

.login-header {
    text-align: center;
    color: white;
    margin-bottom: 2rem;
}

.login-logo { max-height: 80px; max-width: 200px; object-fit: contain; }

/* La form vive dentro una card bianca staccata dal fondo scuro di brand:
   così i controlli restano sul tema chiaro standard e il gradiente fa da sfondo. */
.login-card {
    width: 100%;
    max-width: 380px;
    background: #fff;
    border-radius: 16px;
    padding: 1.5rem 1.25rem;
    box-shadow: 0 12px 32px rgba(7, 46, 65, 0.28);
}

#login-form {
    width: 100%;
}

#login-form .input-group-text { background: white; border-right: 0; color: var(--gray-600); }
#login-form .form-control { border-left: 0; font-size: 1rem; padding: 0.75rem; }
#login-form .form-control:focus { box-shadow: none; border-color: var(--primary); }
#login-form .btn-primary { padding: 0.75rem; font-size: 1.1rem; font-weight: 600; }

/* Marchio Studio27, due forme e due varianti cromatiche:
     logo-studio27*    — completo (barre + wordmark), per gli spazi ampi
     logotipo-studio27* — solo wordmark, per le barre strette (ratio 6.6:1)
   Il suffisso -inverso è la versione #3A84A0+bianco per i fondi scuri;
   senza suffisso è #072E41+#3A84A0 per i fondi chiari.
   Altezza esplicita, non max-height: dentro i contenitori flex l'SVG verrebbe
   compresso sotto la dimensione voluta. */
.splash-logo { display: block; height: 60px; width: auto; margin: 0 auto; }
.sidebar-logo { height: 24px; width: auto; flex-shrink: 0; }
.login-header .brand-logo { height: 76px; width: auto; max-width: 100%; }

/* ---- App Shell ---- */
#app-shell {
    height: 100%;
    display: flex;
    flex-direction: column;
}

/* ---- Header ---- */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--header-height);
    background: var(--primary);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#app-header h1 { font-size: 1.2rem; font-weight: 600; margin: 0; }
.header-left, .header-right { display: flex; align-items: center; gap: 0.5rem; }
.header-right .btn-link { font-size: 1.3rem; padding: 0.25rem; text-decoration: none; }

#chat-badge {
    position: absolute;
    top: -2px;
    right: -4px;
    font-size: 0.65rem;
    padding: 0.2em 0.45em;
}

/* ---- Main Content ---- */
#app-content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    margin-top: calc(var(--header-height) + var(--alerts-banner-height));
    margin-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    padding: 1rem;
    /* Il pull-to-refresh e' gestito dall'app: quello nativo del browser si
       sommerebbe al gesto, ricaricando l'intera pagina invece dei soli dati */
    overscroll-behavior-y: contain;
}

/* ---- Pull to refresh ---- */
.ptr-indicatore {
    position: fixed;
    top: calc(var(--header-height) + var(--alerts-banner-height));
    left: 50%;
    transform: translateX(-50%) translateY(0);
    z-index: 999;
    opacity: 0;
    pointer-events: none;
    /* Nessuna transizione durante il trascinamento: l'indicatore deve stare
       incollato al dito. La classe la riattiva al rilascio. */
    transition: none;
}

.ptr-indicatore:not(.ptr-visibile),
.ptr-indicatore.ptr-caricamento {
    transition: transform 0.25s ease, opacity 0.25s ease;
}

.ptr-cerchio {
    width: 36px;
    height: 36px;
    margin-top: 8px;
    border-radius: 50%;
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 1.1rem;
}

.ptr-cerchio i {
    transition: transform 0.2s ease;
}

/* Oltre la soglia la freccia si gira: il rilascio ora ricarica */
.ptr-pronto .ptr-cerchio i {
    transform: rotate(180deg);
}

.ptr-caricamento .ptr-cerchio i {
    animation: ptr-gira 0.8s linear infinite;
}

@keyframes ptr-gira {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ---- Bottom Navigation ---- */
#bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background: white;
    display: flex;
    align-items: center;
    justify-content: space-around;
    border-top: 1px solid var(--gray-200);
    z-index: 1000;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
}

#bottom-nav .nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 0.4rem 0;
    color: var(--gray-500);
    text-decoration: none;
    font-size: 0.7rem;
    font-weight: 500;
    transition: color 0.2s;
}

#bottom-nav .nav-item i { font-size: 1.4rem; margin-bottom: 0.15rem; }
#bottom-nav .nav-item.active { color: var(--accent); }
#bottom-nav .nav-item:active { color: var(--accent-light); }

/* ---- Cards ---- */
.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    margin-bottom: 1rem;
}

.card-header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    border-radius: 12px 12px 0 0 !important;
    padding: 0.875rem 1rem;
}

.card-body { padding: 1rem; }

/* ---- Stat Cards (Dashboard) ---- */
.stat-card { text-align: center; padding: 1.25rem 0.75rem; }
.stat-card .stat-icon { font-size: 2rem; margin-bottom: 0.5rem; }
.stat-card .stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-card .stat-label { font-size: 0.8rem; color: var(--gray-600); margin-top: 0.25rem; }

/* ---- List Items ---- */
.list-item {
    display: flex;
    align-items: center;
    padding: 0.875rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}
.list-item:last-child { border-bottom: none; }
.list-item:active { background: var(--gray-50); }
.list-item-icon {
    width: 40px; height: 40px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 1.2rem; margin-right: 0.875rem; flex-shrink: 0;
}
.list-item-body { flex: 1; min-width: 0; }
.list-item-title { font-weight: 600; font-size: 0.95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-subtitle { font-size: 0.8rem; color: var(--gray-600); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item-right { text-align: right; flex-shrink: 0; margin-left: 0.5rem; }

/* ---- Page Container & Header ---- */
.page-container {
    padding: 0;
    max-width: 800px;
    margin: 0 auto;
}

.page-header {
    margin-bottom: 1.25rem;
}

.page-header h1 { font-size: 1.5rem; font-weight: 700; margin-bottom: 4px; }
.page-header p { color: var(--gray-600); font-size: 0.9rem; margin-bottom: 0; }

/* ---- Section Header ---- */
.section-header {
    display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.75rem;
}
.section-header h2 { font-size: 1.1rem; font-weight: 700; margin: 0; }
.section-header a { font-size: 0.85rem; text-decoration: none; color: var(--accent); }

/* ---- Badges ---- */
.badge-stato { font-size: 0.75rem; padding: 4px 10px; border-radius: 20px; }

/* ---- Empty State ---- */
.empty-state { text-align: center; padding: 3rem 1rem; color: var(--gray-500); }
.empty-state i { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; display: block; }
.empty-state p { margin: 0; font-size: 0.95rem; }

/* ---- Profile ---- */
.profile-avatar {
    width: 80px; height: 80px; border-radius: 50%;
    object-fit: cover; border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.profile-avatar-upload {
    position: relative;
    display: inline-block;
    cursor: pointer;
}

.profile-avatar-upload .overlay {
    position: absolute;
    bottom: 0; right: 0;
    background: var(--primary);
    color: white;
    width: 28px; height: 28px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 0.8rem;
    cursor: pointer;
}

/* ---- Lesson Cards ---- */
/* ---- Borsellino lezioni (anello stile minuti residui) ---- */

.borsellino {
    display: flex;
    align-items: center;
    gap: 1.25rem;
}

.borsellino-donut {
    position: relative;
    width: 128px;
    height: 128px;
    flex-shrink: 0;
}

.borsellino-donut svg { width: 100%; height: 100%; display: block; }

.donut-traccia {
    fill: none;
    stroke: var(--gray-200);
    stroke-width: 12;
}

.donut-quota {
    fill: none;
    stroke-width: 12;
    stroke-linecap: round;
    transition: stroke-dasharray 0.5s ease;
}

.donut-quota--primary { stroke: var(--primary); }
.donut-quota--warning { stroke: var(--warning); }
.donut-quota--danger  { stroke: var(--danger); }

/* Il numero sta dentro l'anello: è il dato che si cerca per primo */
.borsellino-centro {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: none;
    /* Il contenuto deve restare nel foro dell'anello, non sopra la traccia:
       raggio 52 meno metà dello spessore 12 => diametro utile ~92px.
       Il padding tiene il testo dentro quel foro e lo manda a capo da solo. */
    padding: 0 20px;
}

.borsellino-numero {
    font-size: 2.1rem;
    font-weight: 700;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.borsellino-unita {
    font-size: 0.62rem;
    line-height: 1.15;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 3px;
    /* "lezioni rimaste" non ci sta su una riga: va spezzato, non troncato.
       Il limite di larghezza tiene l'etichetta ben dentro il foro anche con
       unità più corte ("ore rimaste"), che altrimenti sfiorerebbero la traccia. */
    max-width: 4rem;
    overflow-wrap: break-word;
}

.borsellino-dati { flex: 1; min-width: 0; }

.borsellino-riga {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.85rem;
    padding: 0.3rem 0;
    border-bottom: 1px solid var(--gray-100);
}
.borsellino-riga:last-child { border-bottom: 0; }

@media (max-width: 400px) {
    /* Sotto i 400px l'anello e la tabella non ci stanno affiancati */
    .borsellino { flex-direction: column; gap: 1rem; }
    .borsellino-dati { width: 100%; }
}

/* ---- Righe lezione ---- */

.lezione-row {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.7rem 0.25rem;
    border-bottom: 1px solid var(--gray-100);
    background: none;
}
.lezione-row:last-child { border-bottom: 0; }
.lezione-row:hover { background: var(--gray-50); }

/* Blocco data compatto, come nell'elenco chiusure: la stessa informazione
   si legge nello stesso posto in tutta l'app. */
.lezione-data {
    width: 42px;
    flex-shrink: 0;
    text-align: center;
    line-height: 1.1;
}
.lezione-data-giorno {
    font-size: 1.15rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--gray-800);
}
.lezione-data-mese {
    font-size: 0.62rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
}

.lezione-corpo { flex: 1; min-width: 0; cursor: pointer; }
.lezione-ora { font-weight: 600; font-size: 0.9rem; color: var(--gray-800); }
.lezione-meta {
    font-size: 0.76rem;
    color: var(--gray-600);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lezione-azioni { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }

/* Lo stato sta in un pallino accanto alla data invece che in un bordo colorato:
   occupa meno spazio e non colora l'intera riga. */
.lezione-stato {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--gray-300);
}
.lezione-stato--presente { background: var(--success); }
.lezione-stato--assente  { background: var(--warning); }
.lezione-stato--eseguita { background: var(--success); }
.lezione-stato--annullata { background: var(--danger); }

.lezione-row--annullata { opacity: 0.55; }
.lezione-row--annullata .lezione-ora { text-decoration: line-through; }
.lezione-row--passata .lezione-data-giorno,
.lezione-row--passata .lezione-ora { color: var(--gray-600); font-weight: 500; }

.lezione-supplente { color: var(--warning-dark); font-weight: 500; }

/* ---- Filtri documenti ---- */
.doc-filtri .btn { font-size: 0.85rem; padding: 0.375rem 0.4rem; white-space: nowrap; }
@media (max-width: 380px) {
    .doc-filtri .btn { font-size: 0.75rem; padding: 0.375rem 0.25rem; }
}

/* ---- Raggruppamento lezioni per mese ---- */
.month-group + .month-group { margin-top: 4px; }
.month-header {
    display: flex; align-items: center; gap: 8px;
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 8px;
    border: none;
    border-radius: 8px;
    background: var(--gray-100);
    color: var(--gray-800);
    text-align: left;
    font-size: 0.95rem;
}
.month-header:hover { background: var(--gray-200); }
.month-chevron { font-size: 0.8rem; transition: transform 0.2s; }
.month-header[aria-expanded="false"] .month-chevron { transform: rotate(-90deg); }

/* ---- Chat ---- */

/* Lista */
.chat-list-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: background 0.15s;
    display: block;
    color: inherit;
    text-decoration: none;
    background: white;
}
.chat-list-item:last-child { border-bottom: none; }
.chat-list-item:hover { background: var(--gray-50); }
.chat-list-item.unread .chat-list-name { font-weight: 700; color: var(--gray-800); }
.chat-list-item.unread .chat-list-preview { font-weight: 600; color: var(--gray-700); }
.chat-list-name { font-size: 0.95rem; color: var(--gray-800); }
.chat-list-preview { font-size: 0.82rem; color: var(--gray-500); }
.chat-list-time { font-size: 0.75rem; color: var(--gray-500); white-space: nowrap; }

/* Avatar */
.chat-avatar {
    display: flex; align-items: center; justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    flex-shrink: 0;
}
.chat-avatar-md { width: 48px; height: 48px; font-size: 1rem; }
.chat-avatar-sm { width: 36px; height: 36px; font-size: 0.8rem; }
.chat-avatar-segreteria { background: #e1edf1; color: var(--primary); }
.chat-avatar-docente { background: #f9ece2; color: var(--warning-dark); }

/* Container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--header-height) - var(--alerts-banner-height) - var(--bottom-nav-height) - var(--safe-area-bottom));
    overflow: hidden;
    position: relative;
}

/* Header conversazione */
.chat-header {
    background: white;
    border-bottom: 1px solid var(--gray-200);
    padding: 8px 12px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    gap: 6px;
}

/* Area messaggi */
.chat-messages-wrap {
    flex: 1;
    position: relative;
    overflow: hidden;
}
.chat-messages {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    padding: 12px 12px 8px;
    display: flex;
    flex-direction: column;
    background: #eff5f7;
}

/* Separatore data */
.chat-date-sep {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 10px 0 6px;
}
.chat-date-sep span {
    background: rgba(255,255,255,0.85);
    color: var(--gray-600);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 12px;
    border-radius: 20px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

/* Bolle */
.chat-bubble {
    max-width: 78%;
    padding: 8px 12px;
    border-radius: 18px;
    font-size: 0.9rem;
    line-height: 1.45;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    margin-bottom: 2px;
    word-wrap: break-word;
}
.chat-bubble.sent {
    align-self: flex-end;
    background: var(--primary);
    color: white;
}
.chat-bubble.received {
    align-self: flex-start;
    background: white;
    color: var(--gray-800);
}
/* Coda (ultimo del gruppo) */
.chat-bubble.tail.sent { border-bottom-right-radius: 4px; }
.chat-bubble.tail.received { border-bottom-left-radius: 4px; }
/* Raggruppato (non-primo): angolo superiore ridotto */
.chat-bubble.grouped.sent { border-top-right-radius: 6px; margin-top: 1px; }
.chat-bubble.grouped.received { border-top-left-radius: 6px; margin-top: 1px; }

.chat-bubble .time {
    font-size: 0.65rem;
    opacity: 0.7;
    margin-top: 3px;
    text-align: right;
}
.chat-bubble.received .time { text-align: left; }

/* Empty state messaggi */
.chat-empty {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--gray-500);
    font-size: 0.88rem;
    text-align: center;
    padding: 2rem;
}
.chat-empty i { font-size: 2.5rem; margin-bottom: 0.75rem; opacity: 0.4; }

/* Pulsante scendi in fondo */
.chat-scroll-down {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: white;
    border: none;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    font-size: 1rem;
    z-index: 5;
    cursor: pointer;
    transition: transform 0.15s;
}
.chat-scroll-down:hover { transform: scale(1.08); }
.chat-scroll-down.d-none { display: none !important; }

/* Input bar */
.chat-input-bar {
    background: white;
    border-top: 1px solid var(--gray-200);
    padding: 8px 12px;
    padding-bottom: calc(8px + env(safe-area-inset-bottom, 0));
    flex-shrink: 0;
}
.chat-form-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}
.chat-textarea {
    flex: 1;
    border: 1.5px solid var(--gray-300);
    border-radius: 22px;
    padding: 9px 16px;
    font-size: 0.9rem;
    resize: none;
    max-height: 120px;
    overflow-y: auto;
    line-height: 1.45;
    outline: none;
    transition: border-color 0.15s;
    font-family: inherit;
    background: var(--gray-50);
}
.chat-textarea:focus { border-color: var(--primary); background: white; box-shadow: 0 0 0 3px rgba(var(--primary-rgb),0.1); }
.chat-send-btn {
    width: 42px;
    height: 42px;
    flex-shrink: 0;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.95rem;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}
.chat-send-btn:hover { background: var(--primary-dark); }
.chat-send-btn:active { transform: scale(0.92); }

/* ---- Chiusure struttura ---- */
.chiusura-item:last-child { border-bottom: none !important; }
.chiusura-data { width: 44px; }

/* ---- Menu List ---- */
.menu-list { list-style: none; padding: 0; margin: 0; }
.menu-list-item {
    display: flex; align-items: center;
    padding: 14px 16px;
    text-decoration: none; color: var(--gray-800);
    border-bottom: 1px solid var(--gray-100);
    transition: background 0.15s;
}
.menu-list-item:last-child { border-bottom: none; }
.menu-list-item:hover { background: var(--gray-50); }
.menu-list-item i { font-size: 1.2rem; width: 32px; color: var(--primary); }
.menu-list-item .menu-label { flex: 1; font-weight: 500; }
.menu-list-item .bi-chevron-right { color: var(--gray-400); font-size: 0.9rem; }

/* ---- Skeleton loading ---- */
.skeleton {
    background: linear-gradient(90deg, var(--gray-200) 25%, var(--gray-100) 50%, var(--gray-200) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
    border-radius: 6px;
}
@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}
.skeleton-text { height: 1em; margin-bottom: 0.5em; }
.skeleton-text.w-75 { width: 75%; }
.skeleton-text.w-50 { width: 50%; }

/* ---- Toast ---- */
.toast-container {
    position: fixed;
    top: calc(var(--header-height) + var(--alerts-banner-height) + 0.5rem);
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    width: calc(100% - 2rem);
    max-width: 400px;
}

/* ---- Alerts Banner ---- */
.alerts-banner {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    z-index: 1010;
    background: white;
    box-shadow: 0 2px 8px rgba(0,0,0,0.12);
    max-height: 40vh;
    overflow-y: auto;
}

.alert-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid var(--gray-200);
    transition: background 0.15s;
}
.alert-item:last-child { border-bottom: none; }
.alert-item:active { background: var(--gray-100); }

.alert-item--danger {
    background: #fff5f5;
    border-left: 4px solid var(--danger);
}
.alert-item--warning {
    background: #fffbf0;
    border-left: 4px solid var(--warning);
}

.alert-item__icon {
    font-size: 1.2rem;
    flex-shrink: 0;
}
.alert-item--danger .alert-item__icon { color: var(--danger); }
.alert-item--warning .alert-item__icon { color: var(--warning); }

.alert-item__body {
    flex: 1;
    min-width: 0;
}
.alert-item__title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--gray-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.alert-item__desc {
    font-size: 0.78rem;
    color: var(--gray-600);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.alert-item__chevron {
    font-size: 0.75rem;
    color: var(--gray-400);
    flex-shrink: 0;
}

.alert-item__close {
    background: none;
    border: none;
    padding: 0.1rem 0.25rem;
    color: var(--gray-500);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: 4px;
}
.alert-item__close:hover { color: var(--gray-800); background: var(--gray-200); }

/* ---- Utilities ---- */
.text-accent { color: var(--accent) !important; }
.bg-accent { background-color: var(--accent) !important; }
.bg-accent-light { background-color: rgba(var(--primary-rgb),0.1) !important; }
.bg-success-light { background-color: rgba(39,174,96,0.1) !important; }
.bg-warning-light { background-color: rgba(215,126,59,0.12) !important; }
.bg-danger-light { background-color: rgba(182,46,46,0.1) !important; }
.text-success { color: var(--success-dark) !important; }
.text-warning { color: var(--warning-dark) !important; }
.text-danger { color: var(--danger) !important; }
.fw-600 { font-weight: 600; }
.fs-sm { font-size: 0.85rem; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clickable { cursor: pointer; }

/* ---- Form ---- */
.form-label { font-weight: 600; font-size: 0.85rem; color: var(--gray-700); }
.form-control, .form-select { border-radius: 8px; padding: 0.625rem 0.875rem; border-color: var(--gray-300); }

/* ============================================
   SIDEBAR (hidden on mobile, visible on desktop)
   ============================================ */
#sidebar { display: none; }

.sidebar-brand {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 1rem 1.25rem; font-size: 1.1rem; font-weight: 700;
    color: white; border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand i { font-size: 1.5rem; }
.sidebar-nav { flex: 1; padding: 0.5rem 0; overflow-y: auto; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,0.1); padding: 0.5rem 0; }

.sidebar-item {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.65rem 1.25rem;
    color: rgba(255,255,255,0.7); text-decoration: none;
    font-size: 0.9rem; font-weight: 500;
    transition: background 0.15s, color 0.15s;
    border-left: 3px solid transparent;
}
.sidebar-item:hover { background: rgba(255,255,255,0.08); color: white; }
.sidebar-item.active { background: rgba(255,255,255,0.12); color: white; border-left-color: rgba(255,255,255,0.6); }
.sidebar-item i { font-size: 1.15rem; width: 1.5rem; text-align: center; }

/* ============================================
   DESKTOP LAYOUT (>=992px)
   ============================================ */
@media (min-width: 992px) {
    #sidebar {
        display: flex; flex-direction: column;
        position: fixed; top: 0; left: 0; bottom: 0;
        width: var(--sidebar-width);
        background: var(--primary);
        z-index: 1100;
        box-shadow: 2px 0 8px rgba(0,0,0,0.1);
    }
    #bottom-nav { display: none !important; }
    #app-header { left: var(--sidebar-width); }
    .alerts-banner { left: var(--sidebar-width); }
    #app-content {
        margin-left: var(--sidebar-width);
        margin-bottom: 0;
        padding: 1.5rem 2rem;
        max-width: calc(900px + var(--sidebar-width));
    }
    .toast-container {
        left: calc(var(--sidebar-width) + 50%);
        transform: translateX(calc(-50% - var(--sidebar-width) / 2));
    }
    html, body { overflow: auto; }
    .login-container { background: var(--gray-100); }
    #login-form {
        background: white; padding: 2rem;
        border-radius: 16px; box-shadow: 0 4px 24px rgba(0,0,0,0.1);
        max-width: 400px;
    }
    .login-header { color: var(--primary); }
    .stat-card .stat-value { font-size: 2rem; }
    .chat-container {
        height: calc(100vh - var(--header-height) - var(--alerts-banner-height));
    }
    .chat-bubble { max-width: 60%; }
}

/* ============================================
   CALENDARIO
   ============================================ */

.cal-layout { display: flex; flex-direction: column; gap: 0.75rem; }

.cal-month {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 16px;
    padding: 0.85rem 0.85rem 1rem;
}

/* ---- Testata ---- */

.cal-nav {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.5rem;
    margin-bottom: 0.85rem;
}

.cal-month-label {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--gray-800);
    line-height: 1.2;
}

.cal-month-count {
    font-size: 0.78rem;
    color: var(--gray-600);
    margin-top: 1px;
}

.cal-nav-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

.btn-icon {
    background: none;
    border: none;
    color: var(--gray-700);
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    font-size: 1rem;
    line-height: 1;
}
.btn-icon:hover { background: var(--gray-100); }

.btn-oggi {
    background: none;
    border: 1px solid var(--gray-300);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    margin-right: 0.25rem;
}
.btn-oggi:hover { background: var(--gray-100); }

/* ---- Griglia ---- */

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
}

.cal-weekdays { margin-bottom: 6px; }

.cal-weekdays > div {
    text-align: center;
    font-size: 0.65rem;
    font-weight: 700;
    color: var(--gray-600);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding-bottom: 4px;
}
.cal-weekdays .cal-weekend { color: var(--gray-500); }

.cal-day {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 3px;
    padding: 5px 2px;
    min-height: 52px;
    background: none;
    border: 1.5px solid transparent;
    border-radius: 12px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.cal-day:hover { background: var(--gray-100); }
.cal-day:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }

.cal-day--empty { cursor: default; pointer-events: none; }

/* Numeri in cifre a larghezza fissa: in una griglia le colonne restano allineate */
.cal-day-num {
    font-size: 0.85rem;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--gray-800);
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.cal-day--weekend .cal-day-num { color: var(--gray-500); }
.cal-day--past .cal-day-num { color: var(--gray-500); font-weight: 400; }

.cal-day--today .cal-day-num {
    background: var(--primary);
    color: #fff;
    font-weight: 700;
}

.cal-day--selected {
    background: rgba(var(--primary-rgb), 0.07);
    border-color: var(--primary);
}

/* Giorno di chiusura: fondo tenue e numero in rosso, riconoscibile a colpo
   d'occhio senza rubare il posto ai segni delle lezioni. */
.cal-day--chiuso { background: rgba(182, 46, 46, 0.07); }
.cal-day--chiuso:hover { background: rgba(182, 46, 46, 0.13); }
.cal-day--chiuso .cal-day-num { color: var(--danger); }
.cal-day--chiuso.cal-day--today .cal-day-num { background: var(--danger); color: #fff; }

.cal-day-chiuso {
    position: absolute;
    top: 4px;
    right: 5px;
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--danger);
}

/* ---- Segni delle lezioni ---- */

.cal-marks {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 3px;
    min-height: 4px;
    max-width: 100%;
    overflow: hidden;
}

.cal-mark {
    width: 12px;
    min-width: 6px;
    height: 3px;
    border-radius: 2px;
    background: var(--primary);
    flex: 0 1 auto;
}

.cal-mark--past { background: var(--gray-400); }

.cal-mark-more {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--gray-600);
    line-height: 1;
    margin-left: 2px;
    flex-shrink: 0;
}

.cal-loading {
    grid-column: span 7;
    text-align: center;
    padding: 2.5rem 0;
}

/* ---- Pannello del giorno ---- */

.cal-day-events {
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 16px;
    overflow: hidden;
}
.cal-day-events:empty { display: none; }

.cal-day-header {
    display: flex;
    align-items: baseline;
    gap: 0.4rem;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-200);
}

.cal-day-weekday {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--primary);
}

.cal-day-date {
    font-size: 0.85rem;
    color: var(--gray-600);
    margin-left: auto;
}

/* Chiusura del giorno selezionato: sta sotto la testata, prima delle lezioni */
.cal-chiusura-banner {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: rgba(182, 46, 46, 0.08);
    border-bottom: 1px solid var(--gray-200);
    color: var(--danger);
    font-size: 0.82rem;
}

.cal-day-empty {
    text-align: center;
    padding: 1.5rem 1rem;
}
.cal-day-empty p {
    color: var(--gray-600);
    font-size: 0.88rem;
    margin-bottom: 0.75rem;
}

/* Le lezioni del giorno lette come una sequenza di orari: la linea verticale
   tiene insieme gli slot, gli orari restano incolonnati a sinistra. */
.cal-timeline {
    list-style: none;
    margin: 0;
    padding: 0.5rem 1rem 0.75rem;
}

.cal-tl-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.6rem 0 0.6rem 0;
    cursor: pointer;
    border-radius: 10px;
}

.cal-tl-item:hover { background: var(--gray-50); }
.cal-tl-item:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.cal-tl-time {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    width: 46px;
    flex-shrink: 0;
    font-variant-numeric: tabular-nums;
    position: relative;
}

.cal-tl-start { font-size: 0.9rem; font-weight: 700; color: var(--gray-800); line-height: 1.2; }
.cal-tl-end   { font-size: 0.72rem; color: var(--gray-500); line-height: 1.2; }

/* Filo verticale + pallino: disegnati sul contenitore, non su elementi extra */
.cal-tl-item::before {
    content: '';
    position: absolute;
    left: 56px;
    top: 0;
    bottom: 0;
    width: 1px;
    background: var(--gray-200);
}
.cal-tl-item:first-child::before { top: 50%; }
.cal-tl-item:last-child::before  { bottom: 50%; }

.cal-tl-item::after {
    content: '';
    position: absolute;
    left: 53px;
    top: 50%;
    transform: translateY(-50%);
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 0 3px #fff;
}

.cal-tl-body { flex-grow: 1; min-width: 0; padding-left: 1rem; }

.cal-tl-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: var(--gray-800);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cal-tl-meta { font-size: 0.75rem; color: var(--gray-600); margin-top: 1px; }

/* Il supplente è un cambio rispetto a quanto atteso: si segnala in ambra,
   non in rosso — è un avviso, non un errore. */
.cal-tl-supplente { color: var(--warning); font-size: 0.85rem; margin-left: 0.25rem; }
.cal-tl-meta--supplente { color: var(--warning-dark); font-weight: 500; }

.cal-tl-chevron { color: var(--gray-400); font-size: 0.9rem; flex-shrink: 0; }

.cal-tl-entra { flex-shrink: 0; }

/* Le lezioni già svolte restano leggibili ma arretrano di un piano */
.cal-tl-item--past .cal-tl-start,
.cal-tl-item--past .cal-tl-title { color: var(--gray-600); font-weight: 500; }
.cal-tl-item--past::after { background: var(--gray-400); }

@media (min-width: 992px) {
    /* Su desktop mese e giorno stanno affiancati: la selezione non spinge
       più il dettaglio sotto la piega. */
    .cal-layout {
        flex-direction: row;
        align-items: flex-start;
        gap: 1.25rem;
    }
    .cal-month { flex: 1 1 auto; padding: 1.25rem; }
    .cal-day-events { flex: 0 0 320px; position: sticky; top: 1rem; }

    .cal-grid { gap: 4px; }
    .cal-day { min-height: 68px; padding: 8px 4px; gap: 5px; }
    .cal-day-num { font-size: 0.92rem; width: 30px; height: 30px; }
    .cal-mark { width: 16px; }
    .cal-month-label { font-size: 1.3rem; }
}

@media (prefers-reduced-motion: reduce) {
    .cal-day { transition: none; }
}
/* ============================================
   WIZARD PRENOTAZIONE
   ============================================ */

.wizard-steps {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
}

.wizard-step {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.wizard-step-num {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--gray-200);
    color: var(--gray-600);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
    transition: background 0.2s;
}

.wizard-step--active .wizard-step-num {
    background: var(--primary);
    color: #fff;
}

.wizard-step--done .wizard-step-num {
    background: #198754;
    color: #fff;
}

.wizard-step-label {
    font-size: 0.68rem;
    color: var(--gray-500);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.wizard-step--active .wizard-step-label { color: var(--primary); }
.wizard-step--done .wizard-step-label { color: #198754; }

.wizard-step-line {
    flex: 1;
    height: 2px;
    background: var(--gray-200);
    margin: 0 6px;
    margin-bottom: 14px;
    min-width: 24px;
}

/* Docente cards */
.docenti-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.docente-card {
    display: block;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    border: 2px solid var(--gray-200);
    background: #fff;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.docente-card:hover { border-color: var(--primary-light); background: rgba(var(--primary-rgb),0.04); }
.docente-card--usuale { border-color: var(--primary); background: rgba(var(--primary-rgb),0.05); }
.docente-card--selected { border-color: var(--primary); background: rgba(var(--primary-rgb),0.08); }

/* Prima data disponibile */
.prima-data-card {
    border-radius: 14px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: #fff;
    padding: 1rem 1.25rem;
    transition: opacity 0.15s;
}
.prima-data-card:hover { opacity: 0.92; }
.prima-data-card .prima-data-icon {
    font-size: 1.8rem;
    opacity: 0.9;
}
.prima-data-card .text-muted { color: rgba(255,255,255,0.75) !important; }

/* ============================================
   QR CODE OVERLAY
   ============================================ */

.qr-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1rem;
}

.qr-box {
    background: #fff;
    border-radius: 20px;
    padding: 1.5rem 2rem 1.75rem;
    text-align: center;
    max-width: 300px;
    width: 100%;
    box-shadow: 0 8px 40px rgba(0,0,0,0.25);
}

.qr-box-title {
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 1.25rem;
    color: var(--gray-800);
}

#qr-canvas-container img,
#qr-canvas-container canvas {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
    border-radius: 8px;
}


/* ---- Topbar alert dot ---- */
.topbar-alert-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.2rem;
    height: 1.2rem;
    background: #dc3545;
    color: #fff;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 1;
    border: 2px solid rgba(255,255,255,0.5);
}

/* ---- Mini calendario prenota lezione ---- */
.mini-cal {
    border: 1px solid #dee2e6;
    border-radius: 0.5rem;
    overflow: hidden;
}
.mini-cal__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .4rem .75rem;
    background: #f8f9fa;
    border-bottom: 1px solid #dee2e6;
}
.mini-cal__weekdays, .mini-cal__grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
}
.mini-cal__weekdays {
    background: #f1f3f5;
}
.cal-weekday {
    text-align: center;
    font-size: .7rem;
    font-weight: 600;
    color: #6c757d;
    padding: .25rem 0;
}
.cal-cell {
    text-align: center;
    padding: .4rem 0;
    font-size: .82rem;
    border-radius: 4px;
    cursor: default;
    color: #adb5bd;
}
.cal-cell--clickable {
    color: #212529;
    cursor: pointer;
}
.cal-cell--clickable:hover {
    background: #e9ecef;
}
.cal-cell--prima {
    background: #e1edf1;
    color: var(--primary-dark);
    font-weight: 600;
}
.cal-cell--selected {
    background: var(--primary) !important;
    color: #fff !important;
    font-weight: 700;
}
@keyframes ctBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}
/* Calendario slot picker — stesso stile del backend */
.cs-cal-header { display:flex; align-items:center; justify-content:space-between; margin-bottom:.5rem; }
.cs-cal-title { font-weight:600; font-size:.95rem; }
.cs-cal-nav { background:none; border:1px solid #dee2e6; border-radius:.375rem; width:32px; height:32px; cursor:pointer; font-size:1.2rem; line-height:1; display:inline-flex; align-items:center; justify-content:center; }
.cs-cal-nav:disabled { opacity:.3; cursor:default; pointer-events:none; }
.cs-cal-grid { display:grid; grid-template-columns:repeat(7,1fr); gap:3px; }
.cs-cal-wd { text-align:center; font-size:.7rem; font-weight:600; color:#6c757d; padding:2px 0; }
.cs-cal-day { position:relative; text-align:center; font-size:.82rem; padding:5px 2px 3px; border:1px solid transparent; border-radius:.3rem; cursor:default; min-height:36px; display:flex; flex-direction:column; align-items:center; }
.cs-cal-day.cs-empty { cursor:default; }
.cs-cal-day.cs-past { opacity:.3; cursor:default; pointer-events:none; }
.cs-cal-day.cs-unavail { color:#d1d5db; }
.cs-cal-day.cs-avail { color:#212529; cursor:pointer; border-color:#dee2e6; }
.cs-cal-day.cs-avail:hover { background:#e1edf1; border-color:var(--primary-light); }
.cs-cal-day.cs-today:not(.active) { border:2px solid var(--primary) !important; font-weight:700; }
.cs-cal-day.active { background:var(--primary) !important; color:#fff !important; border-color:var(--primary) !important; }
.cs-cal-dot { width:5px; height:5px; border-radius:50%; background:var(--primary-light); margin-top:2px; }
.cs-cal-day.active .cs-cal-dot { background:rgba(255,255,255,.7); }
.cs-cal-day.skeleton { background:linear-gradient(90deg,#e0e0e0 25%,#f0f0f0 50%,#e0e0e0 75%); background-size:200% 100%; animation:cs-shimmer 1.2s infinite; }
@keyframes cs-shimmer { to { background-position:-200% 0; } }
.cs-slot-card { padding:.6rem .8rem; border:1.5px solid #dee2e6; border-radius:.4rem; cursor:pointer; background:#fff; transition:border-color .12s,background .12s; min-width:80px; }
.cs-slot-card:hover { border-color:var(--primary-light); background:#eff5f7; }
.cs-slot-card.active { border-color:var(--primary); background:#e1edf1; }
.cs-card-time { font-size:1.05rem; font-weight:700; color:var(--primary); }
.cs-card-end { font-size:.78rem; color:#6c757d; }
.cs-card-aula { font-size:.72rem; color:#495057; margin-top:.2rem; }

/* Compiti in dashboard: anteprima di due righe, il resto si legge nella lezione */
.compito-testo {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.compito-item:active { opacity: .6; }
