/* App "Orario" (public/js/calendar.js): Calendario in stile iOS/macOS con pannelli "liquid glass".
   Dietro ai pannelli si muovono luci colorate (i colori delle materie); il vetro le sfoca e le
   rifrange. Una luce morbida segue il puntatore e i blocchi delle lezioni hanno un riflesso. */

.cal-window .window-body {
  overflow: hidden;
  background: transparent;
}

.cal {
  --hour: 60px;
  --glass: rgba(255, 255, 255, 0.52);
  --glass-strong: rgba(255, 255, 255, 0.72);
  --glass-edge: rgba(255, 255, 255, 0.75);
  --glass-shadow: 0 10px 40px -12px rgba(30, 40, 90, 0.28);
  --line: rgba(60, 60, 67, 0.12);
  --line-strong: rgba(60, 60, 67, 0.2);
  --base: #f2f3f8;
  /* Pannelli in primo piano (dettaglio, scelta): quasi opachi, perché il browser non sfoca
     ciò che sta dietro a più strati di vetro sovrapposti */
  --sheet: rgba(250, 250, 253, 0.95);
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
  background: var(--base);
  color: var(--text);
}

:root[data-theme='dark'] .cal {
  --glass: rgba(44, 44, 52, 0.5);
  --glass-strong: rgba(54, 54, 64, 0.72);
  --glass-edge: rgba(255, 255, 255, 0.16);
  --glass-shadow: 0 14px 44px -12px rgba(0, 0, 0, 0.6);
  --line: rgba(235, 235, 245, 0.1);
  --line-strong: rgba(235, 235, 245, 0.18);
  --base: #121218;
  --sheet: rgba(36, 36, 44, 0.95);
  /* Sul vetro scuro con le luci dietro i grigi standard si leggono poco: qui sono più chiari */
  --text-2: rgba(235, 235, 245, 0.8);
  --text-3: rgba(235, 235, 245, 0.58);
}

/* Lezioni in modalità scura: fondo più pieno (le luci dietro non lo slavano) e titolo quasi bianco
   con solo un velo del colore della materia */
:root[data-theme='dark'] .cal-lesson {
  background: linear-gradient(150deg, color-mix(in srgb, var(--c) 34%, rgba(30, 30, 38, 0.86)), color-mix(in srgb, var(--c) 18%, rgba(22, 22, 28, 0.86)));
}

:root[data-theme='dark'] .cal-lesson strong {
  color: color-mix(in srgb, var(--c) 20%, #fff);
}

:root[data-theme='dark'] .cal-lesson.past:not(:hover) {
  opacity: 0.82;
}

:root[data-theme='dark'] .cal-next.live .cal-next-when {
  color: color-mix(in srgb, var(--c) 55%, #fff);
}

/* --- luci di sfondo ----------------------------------------------------------------------- */

.cal-aurora {
  position: absolute;
  inset: -20%;
  z-index: -2;
  pointer-events: none;
  filter: blur(60px) saturate(1.2);
  opacity: 0.42;
}

:root[data-theme='dark'] .cal-aurora {
  opacity: 0.26;
}

.cal-aurora i {
  position: absolute;
  width: 46%;
  height: 52%;
  border-radius: 50%;
  animation: cal-drift 22s ease-in-out infinite alternate;
}

.cal-aurora i:nth-child(1) {
  left: 4%;
  top: 6%;
  background: var(--a1, #0a84ff);
}

.cal-aurora i:nth-child(2) {
  right: 2%;
  top: 22%;
  background: var(--a2, #bf5af2);
  animation-duration: 27s;
  animation-delay: -8s;
}

.cal-aurora i:nth-child(3) {
  left: 30%;
  bottom: 0;
  background: var(--a3, #ff9f0a);
  animation-duration: 31s;
  animation-delay: -15s;
}

@keyframes cal-drift {
  0% {
    transform: translate(0, 0) scale(1);
  }
  50% {
    transform: translate(8%, -6%) scale(1.12);
  }
  100% {
    transform: translate(-6%, 8%) scale(0.94);
  }
}

/* Luce morbida che segue il puntatore */
.cal-light {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: radial-gradient(420px circle at var(--lx, 50%) var(--ly, -200px), rgba(255, 255, 255, 0.22), transparent 60%);
  mix-blend-mode: soft-light;
  transition: background 0.08s;
}

/* --- vetro ---------------------------------------------------------------------------------- */

.cal-glass {
  position: relative;
  background: var(--glass);
  -webkit-backdrop-filter: blur(28px) saturate(1.8);
  backdrop-filter: blur(28px) saturate(1.8);
  border: 0.5px solid var(--glass-edge);
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

:root[data-theme='dark'] .cal-glass {
  box-shadow: var(--glass-shadow), inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

/* Riflesso sul bordo superiore, come il vetro curvo di iOS */
.cal-glass::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.35), transparent 22%);
  mix-blend-mode: overlay;
}

/* --- intestazione ------------------------------------------------------------------------------ */

.cal-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px 12px 92px;
  flex-shrink: 0;
}

.cal-titles {
  min-width: 0;
}

.cal-titles h1 {
  margin: 0;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.cal-titles p {
  margin: 1px 0 0;
  font-size: 12.5px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-sem {
  color: var(--text-3);
}

.cal-next-spacer {
  flex: 1;
}

/* "Prossima lezione": una pillola di vetro con il colore della materia */
.cal-next {
  flex: 1;
  min-width: 0;
  max-width: 460px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 14px 0 12px;
  border: 0.5px solid var(--glass-edge);
  border-radius: 17px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 22%, var(--glass-strong)), var(--glass-strong));
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  backdrop-filter: blur(20px) saturate(1.8);
  box-shadow: 0 6px 20px -8px color-mix(in srgb, var(--c) 60%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  color: var(--text);
  font-size: 12.5px;
  cursor: pointer;
  animation: cal-rise 0.5s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
  transition: transform 0.2s;
}

.cal-next:hover {
  transform: translateY(-1px);
}

.cal-next strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cal-next-when {
  flex-shrink: 0;
  color: var(--text-2);
  font-weight: 600;
}

.cal-next-dot {
  flex-shrink: 0;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 25%, transparent);
}

.cal-next.live .cal-next-dot {
  animation: cal-pulse 1.6s ease-out infinite;
}

.cal-next.live .cal-next-when {
  color: color-mix(in srgb, var(--c) 75%, var(--text));
}

.cal-next-room {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  color: var(--text-2);
}

.cal-next-room .svg,
.cal-lesson-room .svg {
  width: 12px;
  height: 12px;
}

.cal-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.cal-glass-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 30px;
  padding: 0 12px;
  border: 0.5px solid var(--glass-edge);
  border-radius: 15px;
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(20px) saturate(1.8);
  backdrop-filter: blur(20px) saturate(1.8);
  box-shadow: 0 4px 14px -6px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.5);
  color: var(--text);
  font-size: 12.5px;
  font-weight: 500;
  transition: transform 0.15s, background 0.15s;
}

.cal-glass-btn:hover {
  transform: translateY(-1px);
}

.cal-glass-btn:active {
  transform: scale(0.97);
}

.cal-glass-btn .svg {
  width: 14px;
  height: 14px;
}

.cal-glass-btn.on {
  color: var(--accent);
}

/* --- corpo ------------------------------------------------------------------------------------ */

.cal-main {
  flex: 1;
  min-height: 0;
  display: flex;
  padding: 0 14px 14px;
}

.cal-week,
.cal-dayview {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border-radius: 20px;
  overflow: hidden;
  animation: cal-rise 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.1) both;
}

.cal-dayheads {
  display: grid;
  grid-template-columns: 52px repeat(var(--cols), 1fr);
  flex-shrink: 0;
  border-bottom: 0.5px solid var(--line-strong);
}

.cal-dayhead {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 6px;
  padding: 10px 0 9px;
  font-size: 12px;
  color: var(--text-2);
}

.cal-dayhead small,
.cal-daytab small {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.cal-dayhead b {
  font-size: 18px;
  font-weight: 500;
  color: var(--text);
}

/* Oggi: il numero in un cerchio rosso, come su iOS */
.cal-dayhead b.today,
.cal-daytab b.today {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  padding: 0 4px;
  border-radius: 14px;
  background: #ff3b30;
  color: #fff;
  font-weight: 600;
  box-shadow: 0 4px 12px rgba(255, 59, 48, 0.4);
}

.cal-dayhead.today small {
  color: #ff3b30;
}

.cal-scroll {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.cal-grid {
  position: relative;
  display: grid;
  grid-template-columns: 52px 1fr;
  height: calc(var(--rows) * var(--hour) + 24px);
  padding: 12px 0;
}

.cal-times {
  position: relative;
}

.cal-times span {
  position: absolute;
  right: 8px;
  top: calc(var(--r) * var(--hour) - 7px);
  font-size: 10.5px;
  font-variant-numeric: tabular-nums;
  color: var(--text-3);
}

.cal-cols {
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cols), 1fr);
  /* righe delle ore e delle mezz'ore */
  background-image:
    linear-gradient(to bottom, var(--line-strong) 0.5px, transparent 0.5px),
    linear-gradient(to bottom, transparent calc(50% - 0.25px), var(--line) calc(50% - 0.25px), var(--line) calc(50% + 0.25px), transparent calc(50% + 0.25px));
  background-size: 100% var(--hour);
}

.cal-col {
  position: relative;
  border-left: 0.5px solid var(--line);
}

.cal-col.today {
  background: linear-gradient(180deg, rgba(255, 59, 48, 0.05), rgba(255, 59, 48, 0.02));
}

/* --- lezioni ------------------------------------------------------------------------------------ */

.cal-lesson {
  --c: #0a84ff;
  position: absolute;
  left: 4px;
  right: 4px;
  top: calc(var(--top) * var(--hour) + 2px);
  height: calc(var(--len) * var(--hour) - 4px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 7px 9px 7px 12px;
  overflow: hidden;
  border: 0.5px solid color-mix(in srgb, var(--c) 45%, rgba(255, 255, 255, 0.5));
  border-radius: 12px;
  background: linear-gradient(150deg, color-mix(in srgb, var(--c) 30%, var(--glass-strong)), color-mix(in srgb, var(--c) 14%, var(--glass)));
  -webkit-backdrop-filter: blur(16px) saturate(1.7);
  backdrop-filter: blur(16px) saturate(1.7);
  box-shadow: 0 8px 22px -10px color-mix(in srgb, var(--c) 70%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.55);
  color: var(--text);
  text-align: left;
  cursor: pointer;
  animation: cal-pop 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.25) both;
  animation-delay: calc(var(--i) * 45ms + 80ms);
  transition: transform 0.25s cubic-bezier(0.2, 0.9, 0.3, 1.2), box-shadow 0.25s, filter 0.25s;
}

/* Barra colorata a sinistra, come gli eventi del Calendario */
.cal-lesson::before {
  content: '';
  position: absolute;
  left: 4px;
  top: 6px;
  bottom: 6px;
  width: 3.5px;
  border-radius: 2px;
  background: var(--c);
  box-shadow: 0 0 10px color-mix(in srgb, var(--c) 70%, transparent);
}

/* Riflesso di luce che segue il puntatore */
.cal-lesson::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(160px circle at var(--mx, 30%) var(--my, 0%), rgba(255, 255, 255, 0.5), transparent 60%);
  mix-blend-mode: overlay;
  opacity: 0;
  transition: opacity 0.25s;
}

.cal-lesson:hover {
  z-index: 2;
  transform: translateY(-2px) scale(1.015);
  box-shadow: 0 16px 34px -12px color-mix(in srgb, var(--c) 80%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.cal-lesson:hover::after {
  opacity: 1;
}

.cal-lesson:active {
  transform: scale(0.98);
}

.cal-lesson:focus-visible {
  outline: 2px solid var(--c);
  outline-offset: 2px;
}

.cal-lesson strong {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 650;
  line-height: 1.25;
  color: color-mix(in srgb, var(--c) 45%, var(--text));
}

.cal-lesson-time,
.cal-lesson-room,
.cal-lesson-who {
  font-size: 11px;
  line-height: 1.3;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.cal-lesson-time {
  font-variant-numeric: tabular-nums;
}

.cal-lesson-room {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-weight: 600;
  color: var(--text);
}

.cal-lesson.short {
  gap: 0;
  padding-top: 5px;
}

.cal-lesson.short strong {
  -webkit-line-clamp: 1;
}

.cal-lesson.short .cal-lesson-who {
  display: none;
}

/* Lezione in corso: alone che "respira" */
.cal-lesson.live {
  border-color: var(--c);
  animation: cal-pop 0.55s cubic-bezier(0.2, 0.9, 0.3, 1.25) both, cal-glow 2.4s ease-in-out 0.8s infinite;
}

/* Lezioni già passate questa settimana, un po' più tenui */
.cal-lesson.past:not(:hover) {
  filter: saturate(0.6);
  opacity: 0.72;
}

.cal-lesson.flash {
  animation: cal-flash 1.1s ease-out;
}

/* --- linea dell'ora attuale ----------------------------------------------------------------------- */

.cal-now {
  position: absolute;
  z-index: 3;
  top: calc(var(--now) * var(--hour));
  left: calc(var(--col) * (100% / var(--cols)));
  width: calc(100% / var(--cols));
  height: 0;
  border-top: 2px solid #ff3b30;
  pointer-events: none;
  filter: drop-shadow(0 0 4px rgba(255, 59, 48, 0.6));
}

.cal-now i {
  position: absolute;
  left: -5px;
  top: -6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ff3b30;
  animation: cal-pulse 2s ease-out infinite;
}

.cal-now span {
  position: absolute;
  right: 4px;
  top: -18px;
  padding: 1px 6px;
  border-radius: 8px;
  background: #ff3b30;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

/* --- vista giorno ----------------------------------------------------------------------------------- */

.cal-dayview {
  --hour: 68px;
}

.cal-dayview.still {
  animation: none;
}

.cal-daytabs {
  display: flex;
  justify-content: space-around;
  gap: 4px;
  padding: 8px 8px 6px;
  flex-shrink: 0;
}

.cal-daytab {
  flex: 1;
  max-width: 76px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 7px 0 6px;
  border: 0;
  border-radius: 14px;
  background: none;
  color: var(--text-2);
  transition: background 0.25s, transform 0.2s;
}

.cal-daytab b {
  display: inline-grid;
  place-items: center;
  min-width: 28px;
  height: 28px;
  font-size: 16px;
  font-weight: 500;
  color: var(--text);
}

.cal-daytab.on {
  background: var(--glass-strong);
  box-shadow: 0 6px 16px -8px rgba(0, 0, 0, 0.3), inset 0 1px 0 rgba(255, 255, 255, 0.55);
}

.cal-daytab:active {
  transform: scale(0.95);
}

.cal-daytab-dots {
  display: flex;
  gap: 2px;
  height: 5px;
}

.cal-daytab-dots em {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--c);
}

.cal-daytitle {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 6px 16px 8px;
  border-bottom: 0.5px solid var(--line-strong);
  flex-shrink: 0;
}

.cal-daytitle strong {
  font-size: 17px;
}

.cal-daytitle span {
  font-size: 13px;
  color: var(--text-2);
}

.cal-dayview .cal-lesson {
  padding: 9px 12px 9px 15px;
}

.cal-dayview .cal-lesson strong {
  font-size: 14px;
}

.cal-dayview .cal-lesson-time,
.cal-dayview .cal-lesson-room,
.cal-dayview .cal-lesson-who {
  font-size: 12px;
}

.cal-scroll.from-right {
  animation: cal-slide-right 0.35s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.cal-scroll.from-left {
  animation: cal-slide-left 0.35s cubic-bezier(0.2, 0.9, 0.3, 1);
}

.cal-free {
  height: 100%;
  min-height: 220px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-2);
  text-align: center;
}

.cal-free-emoji {
  font-size: 44px;
  color: #ff9f0a;
  text-shadow: 0 0 24px rgba(255, 159, 10, 0.6);
  animation: cal-float 4s ease-in-out infinite;
}

.cal-free strong {
  font-size: 16px;
  color: var(--text);
}

/* --- stati vuoti e caricamento ---------------------------------------------------------------------- */

.cal-loading,
.cal-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
}

.cal-empty strong {
  font-size: 18px;
}

.cal-empty span {
  max-width: 420px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-2);
}

.cal-empty .btn {
  margin-top: 8px;
}

.cal-empty-icon {
  width: 84px;
  height: 84px;
  margin-bottom: 6px;
  filter: drop-shadow(0 14px 24px rgba(0, 0, 0, 0.22));
  animation: cal-float 5s ease-in-out infinite;
}

/* --- pannelli sovrapposti (dettaglio e scelta) ------------------------------------------------------- */

.cal-overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 16px;
}

.cal-scrim {
  position: absolute;
  inset: 0;
  background: rgba(10, 12, 30, 0.28);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition: opacity 0.22s;
}

.cal-overlay.open .cal-scrim {
  opacity: 1;
}

.cal-sheet {
  position: relative;
  width: min(440px, 100%);
  max-height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 0.5px solid var(--glass-edge);
  border-radius: 24px;
  background: var(--sheet);
  -webkit-backdrop-filter: blur(40px) saturate(1.9);
  backdrop-filter: blur(40px) saturate(1.9);
  box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.22s, transform 0.35s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}

/* Il dettaglio nasce dal blocco toccato */
.cal-sheet.from-origin {
  transform-origin: var(--ox) var(--oy);
  transform: scale(0.6);
}

.cal-overlay.open .cal-sheet {
  opacity: 1;
  transform: none;
}

.cal-close {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--hover);
  color: var(--text-2);
}

.cal-close .svg {
  width: 14px;
  height: 14px;
}

.cal-detail {
  --c: #0a84ff;
  background: linear-gradient(170deg, color-mix(in srgb, var(--c) 16%, var(--sheet)) 0%, var(--sheet) 50%);
}

.cal-detail-head {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 18px 16px 12px 18px;
}

.cal-detail-head > div {
  flex: 1;
  min-width: 0;
}

.cal-detail-bar {
  flex-shrink: 0;
  width: 5px;
  align-self: stretch;
  border-radius: 3px;
  background: var(--c);
  box-shadow: 0 0 12px color-mix(in srgb, var(--c) 70%, transparent);
}

.cal-detail h2 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
  letter-spacing: -0.01em;
}

.cal-detail-head p {
  margin: 3px 0 0;
  font-size: 13px;
  color: var(--text-2);
}

.cal-rows {
  margin: 0 14px;
  border-radius: 14px;
  background: color-mix(in srgb, var(--glass) 80%, transparent);
  border: 0.5px solid var(--line);
}

.cal-row {
  display: grid;
  grid-template-columns: 18px 72px 1fr;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-size: 13px;
}

.cal-row + .cal-row {
  border-top: 0.5px solid var(--line);
}

.cal-row .svg {
  width: 16px;
  height: 16px;
  color: var(--c, var(--accent));
}

.cal-row span {
  color: var(--text-2);
}

.cal-row strong {
  font-weight: 500;
}

.cal-also {
  padding: 12px 18px 0;
}

.cal-also small {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
}

.cal-also div {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cal-chip {
  height: 26px;
  padding: 0 10px;
  border: 0.5px solid color-mix(in srgb, var(--c) 40%, transparent);
  border-radius: 13px;
  background: color-mix(in srgb, var(--c) 14%, transparent);
  color: var(--text);
  font-size: 12px;
}

.cal-detail-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 16px 18px 18px;
}

.cal-detail-actions .btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cal-note {
  font-size: 12px;
  color: var(--text-2);
}

/* Scelta di corso, anno e canale */
.cal-setup {
  width: min(560px, 100%);
}

.cal-setup-head {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 18px 10px 20px;
  flex-shrink: 0;
}

.cal-setup-head > div:nth-child(2) {
  flex: 1;
  min-width: 0;
}

.cal-setup-icon {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.2));
}

.cal-setup-head h2 {
  margin: 0;
  font-size: 19px;
}

.cal-setup-head p {
  margin: 3px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--text-2);
}

.cal-setup-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 20px 8px;
}

.cal-step {
  padding: 10px 0;
}

.cal-step.appear {
  animation: cal-rise 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.15) both;
}

.cal-step h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 14px;
}

.cal-step h3 b {
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
}

.cal-group + .cal-group {
  margin-top: 10px;
}

.cal-group > small {
  display: block;
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-3);
}

.cal-opts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}

.cal-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.cal-opt {
  --c: var(--accent);
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 7px 10px;
  border: 0.5px solid var(--line-strong);
  border-radius: 12px;
  background: color-mix(in srgb, var(--glass) 85%, transparent);
  color: var(--text);
  text-align: left;
  transition: transform 0.18s, box-shadow 0.2s, background 0.2s, border-color 0.2s;
}

.cal-pills .cal-opt {
  min-height: 34px;
  padding: 0 14px;
  border-radius: 17px;
}

.cal-opt:hover {
  transform: translateY(-1px);
}

.cal-opt:active {
  transform: scale(0.97);
}

.cal-opt span {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.cal-opt strong {
  font-size: 13px;
  font-weight: 600;
}

.cal-opt small {
  font-size: 11px;
  color: var(--text-2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cal-opt.on {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, var(--glass-strong));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent), 0 8px 20px -10px var(--accent);
}

.cal-opt-dot {
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--c);
  box-shadow: 0 0 8px color-mix(in srgb, var(--c) 70%, transparent);
}

/* Canale senza orario: cerchietto rosso con una X dagli angoli arrotondati */
.cal-opt-missing {
  flex-shrink: 0;
  display: grid;
  place-items: center;
  width: 16px;
  height: 16px;
  margin-left: 2px;
  border-radius: 50%;
  background: linear-gradient(180deg, #ff6b61, #e5281d);
  box-shadow: 0 2px 6px rgba(229, 40, 29, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  color: #fff;
}

.cal-opt-missing .svg {
  width: 10px;
  height: 10px;
}

.cal-opt-missing svg {
  stroke-width: 3.4;
}

.cal-setup-foot {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 20px 18px;
  border-top: 0.5px solid var(--line);
  flex-shrink: 0;
}

/* --- animazioni ---------------------------------------------------------------------------------- */

@keyframes cal-pop {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.92);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes cal-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes cal-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(255, 59, 48, 0.55);
  }
  100% {
    box-shadow: 0 0 0 10px rgba(255, 59, 48, 0);
  }
}

@keyframes cal-glow {
  0%,
  100% {
    box-shadow: 0 8px 22px -10px color-mix(in srgb, var(--c) 70%, transparent), 0 0 0 0 color-mix(in srgb, var(--c) 0%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.55);
  }
  50% {
    box-shadow: 0 12px 30px -10px color-mix(in srgb, var(--c) 90%, transparent), 0 0 0 4px color-mix(in srgb, var(--c) 28%, transparent), inset 0 1px 0 rgba(255, 255, 255, 0.55);
  }
}

@keyframes cal-flash {
  0%,
  40% {
    box-shadow: 0 0 0 4px var(--c), 0 0 30px var(--c);
  }
  100% {
    box-shadow: 0 8px 22px -10px color-mix(in srgb, var(--c) 70%, transparent);
  }
}

@keyframes cal-float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}

@keyframes cal-slide-right {
  from {
    opacity: 0;
    transform: translateX(30px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes cal-slide-left {
  from {
    opacity: 0;
    transform: translateX(-30px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .cal-aurora i,
  .cal-lesson,
  .cal-lesson.live,
  .cal-next,
  .cal-week,
  .cal-dayview,
  .cal-empty-icon,
  .cal-free-emoji,
  .cal-now i,
  .cal-next-dot,
  .cal-scroll.from-right,
  .cal-scroll.from-left {
    animation: none !important;
  }
}

/* --- schermi stretti (telefono) ------------------------------------------------------------------- */

.cal.compact .cal-head {
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 12px 12px 10px 84px;
}

.cal.compact .cal-titles {
  flex: 1;
}

.cal.compact .cal-titles h1 {
  font-size: 19px;
}

.cal.compact .cal-next {
  order: 3;
  flex-basis: 100%;
  max-width: none;
  margin: 0;
}

.cal.compact .cal-glass-btn span:not(.svg) {
  display: none;
}

.cal.compact .cal-glass-btn {
  padding: 0 10px;
}

.cal.compact .cal-main {
  padding: 0 8px 8px;
}

.cal.compact .cal-dayview {
  border-radius: 18px;
}

.cal.compact .cal-grid {
  grid-template-columns: 44px 1fr;
}

.cal.compact .cal-detail-actions .btn-primary {
  flex: 1;
  justify-content: center;
}

/* Barre di scorrimento sottili, come su macOS */
.cal-scroll,
.cal-setup-body {
  scrollbar-width: thin;
  scrollbar-color: var(--line-strong) transparent;
}

.cal-scroll::-webkit-scrollbar,
.cal-setup-body::-webkit-scrollbar {
  width: 8px;
}

.cal-scroll::-webkit-scrollbar-thumb,
.cal-setup-body::-webkit-scrollbar-thumb {
  border: 2px solid transparent;
  border-radius: 4px;
  background: var(--line-strong);
  background-clip: padding-box;
}
