/* =========================================================
   Autoscuola G. B. Viotti — area riservata e gestionale
   ========================================================= */

:root {
  --bg: #f3f6fb;
  --panel: #ffffff;
  --ink: #0d1b2e;
  --muted: #5d6b82;
  --line: #e1e7f0;
  --line-2: #cfd9e8;
  --brand: #1663e0;
  --brand-hover: #0f55c7;
  --brand-soft: #e8f0fe;
  --accent: #4db8ff;
  --navy: #071328;

  --wait: #a15c00;   --wait-bg: #fff4dc;
  --ok: #117a45;     --ok-bg: #e2f5ea;
  --no: #b42318;     --no-bg: #fde8e6;
  --off: #5d6b82;    --off-bg: #eef1f6;

  --radius: 14px;
  --font-display: "Archivo", system-ui, sans-serif;
  --font-body: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--ink); font-family: var(--font-body); font-size: 15px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -.02em; line-height: 1.15; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

/* ---------- Bottoni e campi ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .62rem 1rem; border-radius: 10px; font-weight: 600; font-size: .9rem; white-space: nowrap;
  border: 1px solid transparent; transition: background .15s, border-color .15s, color .15s;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn-outline { border-color: var(--line-2); background: #fff; }
.btn-outline:hover:not(:disabled) { border-color: var(--brand); color: var(--brand); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-no { background: #fff; border-color: #f0c6c1; color: var(--no); }
.btn-no:hover { background: var(--no-bg); }
.btn-sm { padding: .38rem .7rem; font-size: .82rem; border-radius: 8px; }
.btn-link { color: var(--brand); font-weight: 600; }
.btn svg { width: 16px; height: 16px; }

label.field { display: grid; gap: .35rem; font-size: .85rem; font-weight: 600; color: #33435c; }
input, select, textarea {
  width: 100%; padding: .65rem .8rem; border-radius: 10px; border: 1px solid var(--line-2);
  background: #fff; color: var(--ink); font: inherit; font-size: .95rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(22, 99, 224, .15); }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--brand); }
.hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
.error { color: var(--no); font-size: .88rem; }

/* ---------- Logo ---------- */
.logo { display: flex; align-items: center; gap: .75rem; color: inherit; }
.logo-img { display: block; flex: none; width: 56px; height: auto; }
.logo strong { display: block; font-family: var(--font-display); font-weight: 800; font-stretch: 112%; text-transform: uppercase; line-height: 1; }
.logo small { font-size: .68rem; letter-spacing: .14em; text-transform: uppercase; opacity: .7; }

/* ---------- Login ---------- */
.login-page { min-height: 100svh; display: grid; grid-template-columns: 1fr 1fr; }
.login-side {
  position: relative; overflow: hidden; color: #fff; padding: 48px;
  display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(80% 60% at 30% 20%, rgba(77, 184, 255, .25), transparent 60%), linear-gradient(160deg, #0a1a36, var(--navy));
}
.login-side h1 { font-size: clamp(2rem, 3.4vw, 3rem); font-weight: 900; text-transform: uppercase; max-width: 12ch; }
.login-side h1 span { color: var(--accent); }
.login-side p { color: #b8c6dc; max-width: 40ch; margin-top: 1rem; }
.login-side ul { list-style: none; display: grid; gap: .6rem; margin-top: 2rem; color: #d6e0ee; font-size: .95rem; }
.login-side li::before { content: "→ "; color: var(--accent); }
.login-main { display: grid; place-items: center; padding: 32px 20px; }
.login-card { width: min(400px, 100%); }
.login-card h2 { font-size: 1.8rem; margin-bottom: .4rem; }
.login-card > p { color: var(--muted); margin-bottom: 1.8rem; }
.login-card form { display: grid; gap: 1rem; }
.pw-wrap { position: relative; }
.pw-wrap button { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); font-size: .8rem; font-weight: 600; color: var(--brand); padding: .3rem .4rem; }
.login-card .btn { width: 100%; padding: .8rem; font-size: 1rem; }
.login-foot { margin-top: 1.6rem; font-size: .88rem; color: var(--muted); text-align: center; }

/* ---------- Pagina presenza (dopo aver inquadrato il QR) ---------- */
.checkin-page { background: var(--navy); }
.checkin { min-height: 100svh; display: grid; place-items: center; align-content: center; gap: 1.5rem; padding: 24px 16px; color: #fff; }
.checkin-card { width: min(420px, 100%); padding: 2rem 1.5rem; border-radius: 20px; background: #fff; color: var(--ink); text-align: center; }
.checkin-card h1 { font-size: 1.5rem; margin: 1rem 0 .5rem; }
.checkin-card p { color: var(--muted); }
.checkin-icon { width: 76px; height: 76px; margin: 0 auto; border-radius: 50%; display: grid; place-items: center; font-size: 2.4rem; font-weight: 800; color: #fff; }
.checkin-icon.ok { background: var(--ok); }
.checkin-icon.no { background: var(--no); }
.checkin-icon.wait { background: var(--brand); }
.checkin-note { max-width: 420px; margin: 0; font-size: .85rem; text-align: center; color: rgba(255,255,255,.7); }
.checkin-note a { color: #fff; }
.checkin .btn-outline { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.check-row { display: flex; gap: .5rem; align-items: center; font-size: .9rem; color: #33435c; }

/* ---------- Schermo QR in autoscuola ---------- */
.qr-sheet-page { background: var(--bg, #f4f6fb); }
.qr-sheet-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 1rem; padding: 24px clamp(16px, 4vw, 48px) 0; }
.qr-sheet-head h1 { font-size: 1.6rem; }
.qr-sheet-head p { color: var(--muted); }
.qr-sheet-actions { display: flex; gap: .6rem; }
.qr-sheet-page > .qr-warn { margin: 1rem clamp(16px, 4vw, 48px) 0; }
.qr-sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 20px; padding: 24px clamp(16px, 4vw, 48px) 48px; }
.qr-sheet-card { margin: 0; border: 1px solid var(--line); border-radius: 16px; overflow: hidden; background: #fff; }
.qr-sheet-card img { display: block; width: 100%; height: auto; }
.qr-sheet.one { grid-template-columns: minmax(0, 420px); justify-content: center; }
.qr-share { display: grid; justify-items: center; gap: .8rem; }
.qr-share img { width: min(300px, 100%); border: 1px solid var(--line); border-radius: 14px; }
.qr-warn { padding: .7rem 1rem; border-radius: 10px; background: #fff4e0; color: #8a5a00; font-size: .95rem; }
@media print {
  .qr-sheet-head, .qr-sheet-page > .qr-warn { display: none !important; }
  .qr-sheet-page { background: #fff; }
  .qr-sheet { grid-template-columns: repeat(3, 1fr); gap: 8mm; padding: 0; }
  .qr-sheet.one { grid-template-columns: 140mm; justify-content: center; }
  .qr-sheet-card { break-inside: avoid; border-color: #ccc; }
}

/* ---------- Layout area allievo ---------- */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1.5rem; padding: .7rem clamp(16px, 3vw, 32px);
  background: var(--navy); color: #fff;
}
.tabs { display: flex; gap: .25rem; margin-left: 1rem; }
.tab { padding: .55rem .9rem; border-radius: 9px; color: #b8c6dc; font-weight: 600; font-size: .92rem; }
.tab:hover { color: #fff; background: rgba(255,255,255,.06); }
.tab[aria-selected="true"] { color: #fff; background: rgba(77, 184, 255, .16); }
.user-box { margin-left: auto; display: flex; align-items: center; gap: .9rem; font-size: .88rem; color: #d6e0ee; }
.user-box .btn-link { color: var(--accent); }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--brand); color: #fff; font-weight: 700; font-size: .85rem; }

.main { max-width: 1240px; margin: 0 auto; padding: 28px clamp(16px, 3vw, 32px) 80px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.4rem; }
.page-head h1 { font-size: 1.7rem; }
.page-head p { color: var(--muted); margin-top: .25rem; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.3rem; }
.card + .card { margin-top: 1rem; }
.card h2 { font-size: 1.15rem; margin-bottom: .9rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.stack { display: grid; gap: .9rem; }

/* Banner settimana */
.notice { display: flex; gap: .4rem 1rem; flex-wrap: wrap; align-items: baseline; margin-bottom: 1.2rem; padding: .9rem 1.1rem; border-radius: 12px; background: #fff4e0; border: 1px solid #ffd28a; color: #6b4500; }
.notice b { font-weight: 700; }
.notice span { white-space: pre-line; }

.banner {
  display: flex; align-items: center; gap: 1.2rem; flex-wrap: wrap;
  padding: 1.1rem 1.3rem; border-radius: var(--radius); margin-bottom: 1rem;
  background: linear-gradient(120deg, var(--brand), #0d4fbf); color: #fff;
}
/* Colore del riquadro in base al tempo rimasto (data-level impostato da area.js):
   blu > 3 giorni · arancione 3 giorni–24 ore · rosso-arancio 24–3 ore · rosso nelle ultime 3 ore */
#deadline { position: relative; overflow: hidden; isolation: isolate; }
#deadline::before {
  content: ""; position: absolute; inset: 0; z-index: -1; opacity: 0; transition: opacity .8s, background .8s;
}
#deadline[data-level="1"]::before { opacity: 1; background: linear-gradient(120deg, #e8890c, #c76a05); }
#deadline[data-level="2"]::before { opacity: 1; background: linear-gradient(120deg, #e8590c, #c2410c); }
#deadline[data-level="3"]::before { opacity: 1; background: linear-gradient(120deg, #e03131, #a51c12); }
#deadline.last-hours b { animation: deadline-pulse 1.4s ease-in-out infinite; }
@keyframes deadline-pulse { 50% { opacity: .45; } }
@media (prefers-reduced-motion: reduce) { #deadline.last-hours b { animation: none; } }
.banner strong { font-size: 1.1rem; font-family: var(--font-display); }
.banner .count { margin-left: auto; text-align: right; font-size: .85rem; opacity: .9; }
.banner .count b { display: block; font-size: 1.2rem; font-family: var(--font-display); }
/* Tendina con regole della prenotazione e regolamento del corso */
.rules-box { margin-bottom: 1rem; border: 1px solid var(--line); border-radius: 14px; background: #fff; }
.rules-box summary { display: flex; align-items: center; justify-content: space-between; gap: .8rem; padding: .9rem 1.1rem; cursor: pointer; font-weight: 600; list-style: none; }
.rules-box summary::-webkit-details-marker { display: none; }
.rules-box summary::after { content: ""; width: 9px; height: 9px; flex: none; margin-left: .2rem; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .2s; }
.rules-box[open] summary::after { transform: rotate(-135deg); }
.rules-box summary span:first-child { flex: 1; }
.rules-body { padding: 0 1.1rem 1.1rem; display: grid; gap: .7rem; }
.rules-body h3 { font-size: .95rem; margin-top: .4rem; }
.rules-body ul { padding-left: 1.1rem; display: grid; gap: .4rem; color: #33435c; font-size: .92rem; }
.reg-text { max-height: 320px; overflow-y: auto; padding: .9rem 1rem; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); white-space: pre-line; font-size: .9rem; color: #33435c; }
.reg-ok { color: var(--ok); font-weight: 600; font-size: .92rem; }
.check { display: flex; gap: .6rem; align-items: flex-start; font-size: .92rem; cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: .1rem; flex: none; }
.rules-body .btn { justify-self: start; }
.rules { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; }
.rule { padding: .4rem .75rem; border-radius: 999px; background: #fff; border: 1px solid var(--line); font-size: .82rem; color: #33435c; }
.rule.warn { background: var(--wait-bg); border-color: #f3d79b; color: var(--wait); }

/* Calendario settimanale */
.cal-wrap { overflow-x: auto; }
.cal { display: grid; grid-template-columns: 56px repeat(6, minmax(110px, 1fr)); min-width: 760px; }
.cal-h { position: sticky; top: 0; padding: .6rem .5rem; text-align: center; font-size: .82rem; font-weight: 700; border-bottom: 1px solid var(--line); background: #fff; }
.cal-h small { display: block; font-weight: 500; color: var(--muted); }
.cal-h .tot { display: inline-block; margin-top: .25rem; padding: .05rem .45rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand); font-size: .72rem; }
.cal-t { font-size: .75rem; color: var(--muted); text-align: right; padding: .3rem .5rem 0 0; border-top: 1px solid var(--line); }
.slot {
  position: relative; height: 44px; margin: 2px; border-radius: 8px; font-size: .75rem;
  display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.2;
}
.slot.closed { background: repeating-linear-gradient(-45deg, #f6f8fb 0 6px, #eef2f7 6px 12px); }
.slot.free { background: #fff; border: 1px solid var(--line); color: var(--muted); }
.slot.free:hover { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.slot.full { background: var(--off-bg); color: #8a96aa; }
.slot.mine { background: var(--brand); color: #fff; font-weight: 600; }
.slot.mine.wait { background: #ffb547; color: #4a2c00; }
.slot.mine.ok { background: var(--ok); }
.legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .9rem; font-size: .8rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }

/* Tabelle */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); padding: .6rem .7rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
td.actions { white-space: nowrap; text-align: right; }
td.actions .btn + .btn { margin-left: .3rem; }
.sub { display: block; font-size: .78rem; color: var(--muted); }
.empty { padding: 2rem 1rem; text-align: center; color: var(--muted); }

.badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; }
.badge-in_attesa { color: var(--wait); background: var(--wait-bg); }
.badge-confermata { color: var(--ok); background: var(--ok-bg); }
.badge-rifiutata { color: var(--no); background: var(--no-bg); }
.badge-annullata { color: var(--off); background: var(--off-bg); }

/* Gestionale: vista calendario con i posti occupati */
.view-toggle { flex: none; }
.view-toggle button { flex: none; padding: .45rem .9rem; font-size: .85rem; }
.occ-cal .slot.occ { flex-direction: column; gap: .05rem; border: 1px solid transparent; cursor: pointer; transition: transform .1s, box-shadow .1s; }
.occ-cal .slot.occ:hover { transform: translateY(-1px); box-shadow: 0 4px 12px -4px rgba(7, 19, 40, .35); }
.occ-cal .slot.occ b { font-size: .9rem; }
.occ-cal .slot.occ b span { font-weight: 500; opacity: .65; font-size: .75rem; }
.occ-cal .slot.occ small { font-size: .66rem; font-weight: 600; }
.occ-0 { background: #fff; border-color: var(--line) !important; color: var(--muted); }
.occ-1 { background: #e3eefe; color: #1d3f78; }
.occ-2 { background: #b9d3fb; color: #12305e; }
.occ-3 { background: #6fa3f2; color: #fff; }
.occ-4 { background: #2f6fd8; color: #fff; }
.occ-5 { background: #c0392b; color: #fff; }
.legend i.occ-0 { border: 1px solid var(--line-2); }

/* Lezioni del medico */
.ev-chip { display: inline-block; margin-top: .25rem; padding: .05rem .45rem; border-radius: 999px; background: #efeaff; color: #5b3fd6; font-size: .7rem; font-weight: 700; white-space: nowrap; }
.slot.mine.med { background: #7c5cff; color: #fff; }
.slot.mine.med.wait { background: #c9bbff; color: #2b1b74; }
.events { display: grid; gap: .6rem; }
.event { display: grid; grid-template-columns: 56px 1fr auto; gap: .9rem; align-items: center; padding: .8rem; border: 1px solid var(--line); border-radius: 12px; }
.event-date { display: grid; justify-items: center; padding: .4rem 0; border-radius: 10px; background: #efeaff; color: #5b3fd6; font-size: .72rem; font-weight: 700; text-transform: uppercase; }
.event-date b { font-size: 1.3rem; line-height: 1; font-family: var(--font-display); }
.event-action { text-align: right; }
.course-warn { padding: .6rem .8rem; border-radius: 10px; background: #efeaff; color: #3d2a99; font-size: .85rem; }
@media (max-width: 700px) {
  .event { grid-template-columns: 48px 1fr; }
  .event-action { grid-column: 1 / -1; text-align: left; }
}

/* Avvisi per l'allievo */
.bell { position: relative; display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; color: #d6e0ee; }
.bell:hover { background: rgba(255,255,255,.08); color: #fff; }
.bell svg { width: 20px; height: 20px; }
.bell-count {
  position: absolute; top: 3px; right: 2px; min-width: 18px; height: 18px; padding: 0 4px; border-radius: 999px;
  display: grid; place-items: center; background: #e03131; color: #fff; font-size: .68rem; font-weight: 800;
  box-shadow: 0 0 0 2px var(--navy);
}
.notif-panel {
  position: fixed; top: 62px; right: clamp(12px, 3vw, 32px); z-index: 30;
  width: min(380px, calc(100vw - 24px)); max-height: min(70svh, 520px); overflow-y: auto;
  background: #fff; border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 24px 60px -20px rgba(7, 19, 40, .45);
}
.notif-head { position: sticky; top: 0; display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; background: #fff; border-bottom: 1px solid var(--line); }
.notif { padding: .75rem 1rem .75rem calc(1rem - 3px); border-left: 3px solid var(--line-2); border-bottom: 1px solid var(--line); }
.notif:last-child { border-bottom: 0; }
.notif p { font-size: .9rem; }
.notif.unread { background: #f4f8ff; }
.notif.unread p { font-weight: 600; }
.notif-ok { border-left-color: var(--ok); }
.notif-no { border-left-color: var(--no); }
.notif-info { border-left-color: #ffb547; }

/* Registro attività */
.nowrap { white-space: nowrap; }
.log-table td { font-size: .86rem; }
.log-act { display: inline-block; font-weight: 600; padding-left: .55rem; border-left: 3px solid var(--line-2); }
.log-prenotazioni { border-color: var(--brand); }
.log-allievi { border-color: #7c5cff; }
.log-materiali { border-color: #ffb547; }
.log-impostazioni { border-color: var(--muted); }

/* Monte ore */
.hbar { display: grid; gap: .3rem; min-width: 150px; }
.hbar-track { display: flex; height: 8px; border-radius: 999px; background: #e6ebf3; overflow: hidden; }
.hbar-track i { display: block; height: 100%; }
.hbar-track .done { background: var(--ok); }
.hbar-track .conf { background: #74c69d; }
.hbar-track .wait { background: #ffb547; }
.hbar-label { font-size: .78rem; color: var(--muted); white-space: nowrap; }
.hbar-label b { color: var(--ink); }
.hbar.full .hbar-label::after { content: " · completo"; color: var(--ok); font-weight: 700; }
.hbar.compact { min-width: 110px; gap: .15rem; margin-top: .3rem; }
.hbar.compact .hbar-track { height: 5px; }
.hbar.compact .hbar-label { font-size: .72rem; }
.course { display: grid; gap: .9rem; margin-bottom: 1rem; }
.course-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; }
.course-head h2 { margin: .15rem 0 0; font-size: 1.15rem; }
.course-num { text-align: right; font-size: .85rem; color: var(--muted); }
.course-num b { display: block; font-size: 1.6rem; font-family: var(--font-display); color: var(--brand); line-height: 1.1; }
.course .hbar-track { height: 12px; }
.course-legend { display: flex; gap: 1.1rem; flex-wrap: wrap; font-size: .82rem; color: #33435c; }
.course-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: .35rem; vertical-align: -1px; }

/* Materiali */
.module { margin-bottom: 1.6rem; }
.module h2 { font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-family: var(--font-body); margin-bottom: .7rem; }
.mat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .8rem; }
.mat { display: flex; gap: .9rem; align-items: flex-start; padding: 1rem; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.mat-ico { width: 42px; height: 42px; flex: none; border-radius: 10px; display: grid; place-items: center; font-size: .72rem; font-weight: 800; color: #fff; }
.mat-ico.pdf { background: #d93b30; }
.mat-ico.video { background: var(--brand); }
.mat-ico.link { background: #5d6b82; }
.mat strong { display: block; }
.mat p { font-size: .85rem; color: var(--muted); margin: .2rem 0 .6rem; }

/* Quiz */
.quiz-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .8rem; }
.quiz-card { display: flex; flex-direction: column; gap: .5rem; }
.quiz-card .meta { font-size: .82rem; color: var(--muted); }
.quiz-card .btn { align-self: flex-start; margin-top: .4rem; }
.q { padding: 1rem 0; border-bottom: 1px solid var(--line); }
.q:last-of-type { border-bottom: 0; }
.q-text { font-weight: 500; margin-bottom: .6rem; }
.q-text b { color: var(--brand); margin-right: .4rem; }
.vf { display: flex; gap: .5rem; }
.vf button { min-width: 84px; padding: .5rem .9rem; border-radius: 9px; border: 1px solid var(--line-2); background: #fff; font-weight: 700; }
.vf button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: #fff; }
.q.right .q-text::after { content: "  ✓ corretta"; color: var(--ok); font-weight: 700; font-size: .85rem; }
.q.wrong .q-text::after { content: "  ✗ sbagliata"; color: var(--no); font-weight: 700; font-size: .85rem; }
.score { display: flex; align-items: center; gap: 1rem; padding: 1rem 1.2rem; border-radius: var(--radius); background: var(--brand-soft); margin-bottom: 1rem; }
.score b { font-size: 1.8rem; font-family: var(--font-display); color: var(--brand); }

/* Dialog */
dialog {
  width: min(480px, calc(100vw - 24px)); max-height: calc(100svh - 24px);
  margin: auto; border: 0; border-radius: 18px; padding: 0;
  box-shadow: 0 30px 80px -20px rgba(7, 19, 40, .45);
}
dialog::backdrop { background: rgba(7, 19, 40, .5); backdrop-filter: blur(2px); }
dialog.wide { width: min(900px, calc(100vw - 24px)); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 1.1rem 1.3rem; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 1.15rem; }
.dlg-x { width: 32px; height: 32px; border-radius: 8px; font-size: 1.4rem; line-height: 1; color: var(--muted); }
.dlg-x:hover { background: var(--bg); }
.dlg-body { padding: 1.3rem; display: grid; gap: 1rem; }
.dlg-foot { display: flex; justify-content: flex-end; gap: .5rem; padding: 1rem 1.3rem; border-top: 1px solid var(--line); background: #fafbfd; }
.seg { display: flex; gap: .5rem; }
.seg button { flex: 1; padding: .7rem; border-radius: 10px; border: 1px solid var(--line-2); background: #fff; font-weight: 700; }
.seg button[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.seg button:disabled { opacity: .4; cursor: not-allowed; }
.summary { padding: .9rem 1rem; border-radius: 10px; background: var(--bg); font-size: .92rem; }
.summary b { color: var(--brand); }
.secret { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.05rem; padding: .7rem .9rem; border-radius: 10px; background: var(--brand-soft); color: var(--brand); user-select: all; }

/* Toast */
.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 100; display: grid; gap: .5rem; }
.toast { padding: .75rem 1rem; border-radius: 10px; background: var(--navy); color: #fff; font-size: .9rem; box-shadow: 0 10px 30px -10px rgba(0,0,0,.4); animation: toast-in .25s ease-out; max-width: 360px; }
.toast.err { background: var(--no); }
@keyframes toast-in { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Gestionale ---------- */
.admin { display: grid; grid-template-columns: 240px 1fr; min-height: 100svh; }
.side { position: sticky; top: 0; height: 100svh; display: flex; flex-direction: column; gap: 1.5rem; padding: 1.2rem 1rem; background: var(--navy); color: #fff; }
.side nav { display: grid; gap: .2rem; }
.side-link { display: flex; align-items: center; gap: .7rem; padding: .62rem .8rem; border-radius: 9px; color: #b8c6dc; font-weight: 600; font-size: .92rem; text-align: left; }
.side-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-link[aria-current="page"] { background: rgba(77, 184, 255, .16); color: #fff; }
.side-link .count { margin-left: auto; min-width: 22px; padding: .05rem .4rem; border-radius: 999px; background: #ffb547; color: #4a2c00; font-size: .72rem; text-align: center; }
.side-foot { margin-top: auto; font-size: .85rem; color: #b8c6dc; display: grid; gap: .5rem; }
.side-menu, .m-label { display: none; }
.side-foot a, .side-foot button { color: var(--accent); font-weight: 600; text-align: left; }
.admin .main { max-width: none; margin: 0; width: 100%; min-width: 0; }

.toolbar { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .spacer { flex: 1; }
.week-nav { display: flex; align-items: center; gap: .4rem; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: .25rem; }
.week-nav button { width: 32px; height: 32px; border-radius: 7px; font-size: 1.1rem; }
.week-nav button:hover { background: var(--bg); }
.week-nav span { padding: 0 .5rem; font-weight: 700; font-size: .9rem; white-space: nowrap; }
.filters { display: flex; gap: .3rem; flex-wrap: wrap; }
.filter { padding: .42rem .8rem; border-radius: 999px; border: 1px solid var(--line-2); background: #fff; font-size: .82rem; font-weight: 600; color: #33435c; }
.ap-layout { display: grid; gap: 1.2rem; align-items: start; }
@media (min-width: 1100px) { .ap-layout { grid-template-columns: minmax(320px, 380px) 1fr; } }
.ap-layout > * { min-width: 0; }
.ap-types { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: -.4rem; }
.filter[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .8rem; margin-bottom: 1rem; }
.stat { padding: 1rem 1.1rem; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.stat span { font-size: .8rem; color: var(--muted); }
.stat b { display: block; font-size: 1.6rem; font-family: var(--font-display); }
.stat.wait b { color: var(--wait); }
.stat.ok b { color: var(--ok); }
.day-row td { background: #eef3fb; font-weight: 700; font-size: .85rem; color: #1d2d47; padding: .55rem .7rem; border-bottom: 1px solid var(--line-2); }
.day-row .sub-inline { margin-left: .7rem; font-weight: 500; color: var(--muted); font-size: .8rem; }
.search { width: 260px; padding: .48rem .75rem; font-size: .88rem; }

/* Prenotazioni: riga allievo + tendina con le singole lezioni */
.bk-table .grp:hover td { background: #f8fafd; }
.bk-table .grp.open td { background: #f4f8ff; border-bottom-color: transparent; }
.exp { display: flex; align-items: center; gap: .65rem; text-align: left; }
.chev {
  display: grid; place-items: center; flex: none; width: 24px; height: 24px; border-radius: 7px;
  background: var(--bg); color: var(--muted); font-weight: 800; transition: transform .2s, background .2s, color .2s;
}
.grp.open .chev { transform: rotate(90deg); background: var(--brand-soft); color: var(--brand); }
.exp:hover .chev { background: var(--brand-soft); color: var(--brand); }
.uname { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; color: var(--brand); font-size: .9em; }
.ranges { font-variant-numeric: tabular-nums; font-size: .85rem; }
.ranges span { display: inline-block; margin: 0 .5rem .1rem 0; white-space: nowrap; }
.ranges .struck { text-decoration: line-through; color: var(--muted); }
.chips { display: flex; gap: .25rem; flex-wrap: wrap; }
.bk-table .det td { background: #fafcff; font-size: .86rem; padding: .5rem .7rem; }
.bk-table .det .ind { padding-left: 3rem; color: #33435c; }
.bk-table .det-foot td { padding-top: .3rem; padding-bottom: .7rem; }
.mini-check { display: flex; gap: .4rem; align-items: center; font-size: .82rem; }
.btn-link.small { font-size: .82rem; }
.bulk { display: flex; align-items: center; gap: .6rem; padding: .7rem 1rem; margin-bottom: .8rem; border-radius: 10px; background: var(--brand-soft); font-size: .9rem; }
.q-row { display: grid; grid-template-columns: 1fr auto auto; gap: .5rem; align-items: center; }
.q-row .seg button { padding: .55rem .8rem; flex: none; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .login-page { grid-template-columns: 1fr; }
  .login-side { display: none; }
  .admin { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .admin .main { padding-top: 18px; }
  .admin .search { width: 100%; order: 5; }
  .admin .toolbar .spacer { display: none; }
  .admin .bk-table { min-width: 760px; }
  .admin .page-head p { font-size: .88rem; }
  /* Barra in alto: logo, sezione attuale e menu a tendina con tutte le sezioni */
  .side { position: sticky; z-index: 20; height: auto; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: .6rem; padding: .55rem 12px; }
  .side .logo small, .side-foot span { display: none; }
  .side .logo span strong { font-size: .95rem; }
  .side-menu { display: flex; align-items: center; justify-content: space-between; gap: .6rem; padding: .55rem .8rem; border-radius: 10px; background: rgba(255,255,255,.08); color: #fff; font-weight: 600; font-size: .92rem; }
  .side-menu-ico { width: 10px; height: 10px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(45deg) translateY(-3px); transition: transform .2s; }
  .side.open .side-menu-ico { transform: rotate(-135deg) translateY(-3px); }
  .side nav { display: none; grid-column: 1 / -1; grid-template-columns: 1fr 1fr; gap: .3rem; padding: .3rem 0 .5rem; }
  .side.open nav { display: grid; }
  .side-link { padding: .7rem .8rem; background: rgba(255,255,255,.04); }
  .side-foot { margin: 0; display: flex; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
/* ---------- Gestionale su telefono: più compatto, prenotazioni a schede ---------- */
@media (max-width: 700px) {
  .admin .desk-only { display: none; }
  .admin .page-head { margin-bottom: .9rem; }
  .admin .toolbar { gap: .45rem; margin-bottom: .7rem; }
  .admin .week-nav { flex: 1; justify-content: space-between; }
  .admin .filters { display: flex; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; width: 100%; padding-bottom: 2px; }
  .admin .filters::-webkit-scrollbar { display: none; }
  .admin .filter { flex: none; }
  .admin .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .35rem; margin-bottom: .7rem; }
  .admin .stat { padding: .5rem .45rem; text-align: center; border-radius: 10px; }
  .admin .stat span { display: block; font-size: .66rem; line-height: 1.2; }
  .admin .stat b { font-size: 1.15rem; }
  .admin .card { padding: .8rem; }
  .admin .bulk { flex-wrap: wrap; position: sticky; top: 58px; z-index: 5; }

  /* Tabella prenotazioni → una scheda per allievo e giorno */
  .admin .bk-table { min-width: 0; }
  .bk-table thead { display: none; }
  .bk-table, .bk-table tbody { display: block; }
  .bk-table tr.day-row { display: block; margin: .9rem -.2rem .4rem; }
  .bk-table tr.day-row:first-child { margin-top: 0; }
  .bk-table tr.day-row td { display: block; border-radius: 8px; }
  .bk-table tr.grp { display: grid; grid-template-columns: 28px 1fr auto; gap: .35rem .5rem; align-items: center; padding: .7rem .6rem; border: 1px solid var(--line); border-radius: 12px; margin-bottom: .4rem; background: #fff; }
  .bk-table tr.grp.open { border-color: #bcd3f5; border-bottom-left-radius: 0; border-bottom-right-radius: 0; margin-bottom: 0; }
  .bk-table tr.grp td { display: block; padding: 0; border: 0; background: none !important; }
  .bk-table tr.grp td:nth-child(2) { grid-column: 2; }
  .bk-table tr.grp .c-ore { grid-column: 3; grid-row: 1; text-align: right; }
  .bk-table tr.grp .c-corso, .bk-table tr.grp .ranges, .bk-table tr.grp .c-stato, .bk-table tr.grp .c-portale, .bk-table tr.grp .actions { grid-column: 2 / -1; font-size: .84rem; }
  .bk-table tr.grp .c-corso { color: var(--muted); }
  .bk-table tr.grp .c-portale:empty, .bk-table tr.grp .actions:empty { display: none; }
  .bk-table tr.grp .actions { display: flex; gap: .4rem; margin-top: .2rem; }
  .bk-table tr.grp .actions .btn { flex: 1; justify-content: center; }
  .m-label { display: inline; color: var(--muted); }
  .bk-table tr.det { display: grid; grid-template-columns: 28px 1fr; gap: .25rem .5rem; padding: .6rem; border: 1px solid #bcd3f5; border-top: 0; background: #fafcff; }
  .bk-table tr.det td { display: block; padding: 0; border: 0; background: none; }
  .bk-table tr.det td:empty { display: none; }
  .bk-table tr.det td:not(:first-child) { grid-column: 2; }
  .bk-table tr.det .ind { padding-left: 0; }
  .bk-table tr.det td:nth-child(4), .bk-table tr.det td:nth-child(5) { display: none; } /* orario e ore già nel titolo */
  .bk-table tr.det .actions { display: flex; flex-wrap: wrap; gap: .4rem; }
  .bk-table tr.det-foot { display: block; margin-bottom: .5rem; border-radius: 0 0 12px 12px; }
  .bk-table tr.det-foot td:first-child { display: none; }
}
@media (max-width: 700px) {
  .top { flex-wrap: wrap; gap: .5rem; padding-block: .55rem; }
  .tabs { order: 3; width: 100%; margin: 0; overflow-x: auto; scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: none; white-space: nowrap; padding: .5rem .8rem; }
  .user-box { gap: .5rem; }
  .user-box span.name { display: none; }
  .main { padding-top: 18px; }
  .page-head h1 { font-size: 1.45rem; }
  .card { padding: 1rem; }
  .banner { padding: 1rem; gap: .6rem; }
  .banner .count { margin-left: 0; text-align: left; }
  .course-num { text-align: left; }
  .rules { gap: .35rem; }
  .rule { font-size: .78rem; }
  .notif-panel { top: 104px; }

  /* Le mie prenotazioni: una scheda per riga */
  table.stack-phone thead { display: none; }
  table.stack-phone, table.stack-phone tbody, table.stack-phone tr, table.stack-phone td { display: block; }
  table.stack-phone tr { display: grid; grid-template-columns: 1fr auto; gap: .2rem .8rem; padding: .8rem 0; border-bottom: 1px solid var(--line); }
  table.stack-phone tr:last-child { border-bottom: 0; }
  table.stack-phone td { padding: 0; border: 0; }
  table.stack-phone td:nth-child(1) { grid-column: 1 / -1; }
  table.stack-phone td:nth-child(2) { font-variant-numeric: tabular-nums; }
  table.stack-phone td:nth-child(3) { color: var(--muted); font-size: .85rem; text-align: right; }
  table.stack-phone td:nth-child(4) { grid-column: 1 / -1; }
  table.stack-phone td.actions { grid-column: 1 / -1; text-align: left; padding-top: .3rem; }

  /* Registro: una scheda per evento */
  .log-table thead { display: none; }
  .log-table, .log-table tbody, .log-table tr, .log-table td { display: block; }
  .log-table tr { padding: .7rem .2rem; border-bottom: 1px solid var(--line); }
  .log-table tr:last-child { border-bottom: 0; }
  .log-table td { border: 0; padding: .1rem 0; }
  .log-table td:first-child { font-size: .75rem; color: var(--muted); }

  dialog { width: calc(100vw - 16px); }
  .dlg-body, .dlg-head, .dlg-foot { padding-left: 1rem; padding-right: 1rem; }
}

/* Vista per giorno (telefono) */
.day-pick { display: grid; grid-template-columns: repeat(6, 1fr); gap: .3rem; margin-bottom: .6rem; }
.day-pick button {
  display: grid; justify-items: center; gap: .05rem; padding: .45rem 0; border-radius: 10px;
  border: 1px solid var(--line); background: #fff; font-size: .74rem; font-weight: 600; color: var(--muted);
}
.day-pick button b { font-size: 1.05rem; color: var(--ink); font-family: var(--font-display); }
.day-pick button small { font-size: .66rem; color: var(--brand); font-weight: 700; }
.day-pick button[aria-selected="true"] { background: var(--brand); border-color: var(--brand); color: #dce8ff; }
.day-pick button[aria-selected="true"] b, .day-pick button[aria-selected="true"] small { color: #fff; }
.day-total { margin-bottom: .5rem; }
.day-slots { display: grid; gap: .3rem; }
.day-row-slot { display: grid; grid-template-columns: 48px 1fr; align-items: center; }
.day-row-slot .cal-t { border: 0; padding: 0; text-align: left; font-variant-numeric: tabular-nums; }
.day-row-slot .slot { margin: 0; height: 46px; font-size: .85rem; }
.day-row-slot .slot.closed { font-size: .75rem; color: var(--muted); }
.head-actions { display: flex; gap: .6rem; flex-wrap: wrap; }

/* Nessun campo o riquadro più largo dello schermo (es. testi d'esempio lunghi nei campi) */
.grid-2 > *, .stack > *, .field { min-width: 0; }
input, select, textarea { min-width: 0; max-width: 100%; }
@media (max-width: 700px) {
  .side-menu span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
/* Presenze su telefono: una scheda per allievo, pulsanti sotto */
@media (max-width: 700px) {
  .pres-table thead { display: none; }
  .pres-table, .pres-table tbody { display: block; }
  .pres-table tr { display: grid; grid-template-columns: 1fr auto; gap: .3rem .6rem; align-items: center; padding: .7rem .2rem; border-bottom: 1px solid var(--line); }
  .pres-table tr.day-row { display: block; padding: 0; border: 0; margin-top: .6rem; }
  .pres-table td { display: block; padding: 0; border: 0; }
  .pres-table tr.day-row td { padding: .5rem .7rem; border-radius: 8px; }
  .pres-table td:nth-child(2) { grid-column: 1; font-size: .86rem; }
  .pres-table td:nth-child(3) { grid-column: 2; grid-row: 1; }
  .pres-table td.actions { grid-column: 1 / -1; display: flex; gap: .4rem; flex-wrap: wrap; }
  .pres-table td.actions .btn { flex: 1; justify-content: center; }
}

/* Area allievo: i miei appuntamenti divisi per stato */
.my-appointments { margin-bottom: 1rem; }
.ap-groups { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.ap-group { border: 1px solid var(--line); border-top: 4px solid var(--line-2); border-radius: 12px; padding: .9rem; min-width: 0; }
.ap-group h3 { display: flex; justify-content: space-between; align-items: center; font-size: .95rem; margin-bottom: .6rem; }
.ap-group h3 span { min-width: 1.7rem; padding: .1rem .5rem; border-radius: 999px; text-align: center; font-size: .8rem; }
.ap-ok { border-top-color: var(--ok); }      .ap-ok h3 span { color: var(--ok); background: var(--ok-bg); }
.ap-wait { border-top-color: #ffb547; }      .ap-wait h3 span { color: var(--wait); background: var(--wait-bg); }
.ap-no { border-top-color: var(--no); }      .ap-no h3 span { color: var(--no); background: var(--no-bg); }
.ap-group ul { list-style: none; display: grid; gap: .55rem; }
.ap-group li { display: grid; gap: .35rem; padding: .6rem .7rem; border-radius: 10px; background: #f6f8fc; }
.ap-when { display: flex; justify-content: space-between; gap: .5rem; flex-wrap: wrap; }
.ap-when span { font-weight: 600; color: var(--brand); }
.ap-what { display: grid; gap: .15rem; font-size: .88rem; }
.ap-what .ev-chip { justify-self: start; }
.ap-what .ap-room { justify-self: start; padding: .1rem .55rem; border-radius: 999px; background: rgba(77, 184, 255, .16); color: var(--brand); font-size: .85rem; }
.ap-act { display: flex; gap: .4rem; flex-wrap: wrap; }
.ap-group .empty { padding: .4rem 0; font-size: .88rem; }
.final-warn { margin-bottom: 1rem; }
.history summary { display: flex; align-items: baseline; gap: .7rem; flex-wrap: wrap; cursor: pointer; list-style: none; }
.history summary::-webkit-details-marker { display: none; }
.history summary h2 { margin: 0; }
.history summary h2::before { content: "▸ "; color: var(--muted); }
.history[open] summary h2::before { content: "▾ "; }
.history[open] summary { margin-bottom: .9rem; }

/* Gestionale: ore di assenza nel monte ore (rosse oltre il limite) */
.hbar-label .abs { color: var(--wait); }
.hbar-label .abs-alert { color: var(--no); background: var(--no-bg); font-weight: 700; padding: 0 .35rem; border-radius: 6px; }

/* Registro: presenze in verde, assenze in rosso */
.log-table tr.log-row-presente td { background: var(--ok-bg); }
.log-table tr.log-row-assente td { background: var(--no-bg); }
.log-presente { border-color: var(--ok); color: var(--ok); }
.log-assente { border-color: var(--no); color: var(--no); }
