/* Agenda: calendario Mese / Settimana, pannello del giorno e transizioni. */

.cal-toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 14px 16px; }
.cal-nav { display: flex; align-items: center; gap: 6px; }
.cal-title { font-size: 24px; font-weight: 400; letter-spacing: -0.03em; min-width: 210px; transition: opacity 0.2s, transform 0.3s var(--ease), filter 0.3s; }
.cal-title.flip { opacity: 0.25; transform: translateY(4px); filter: blur(2px); }
.seg-switch { position: relative; display: inline-flex; padding: 4px; border-radius: 999px; background: rgb(var(--text-rgb) / 0.05); box-shadow: inset 0 0 0 1px var(--line); margin-left: auto; }
.seg-switch button { position: relative; z-index: 1; height: 32px; padding: 0 15px; border: 0; border-radius: 999px; background: none; cursor: pointer; font-size: 13.5px; color: var(--muted); transition: color 0.3s; }
.seg-switch button[aria-selected="true"] { color: var(--page); }
.seg-pill { position: absolute; top: 4px; left: 4px; height: 32px; border-radius: 999px; background: var(--text); box-shadow: 0 6px 16px -8px rgb(var(--text-rgb) / 0.6); }
.seg-pill.ready { transition: transform 0.45s var(--ease), width 0.45s var(--ease); }
.cal-search { position: relative; display: block; flex: 0 1 260px; }
.cal-search .ico { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--label); width: 16px; height: 16px; }
.cal-search input { padding-left: 36px; border-radius: 999px; height: 40px; }
.cal-filters { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.45s var(--ease); }
.cal-filters > div { min-height: 0; overflow: hidden; }
.cal-filters .filters { margin-top: 12px; opacity: 0; transform: translateY(-8px); transition: opacity 0.25s, transform 0.4s var(--ease); }
.cal-filters.open { grid-template-rows: 1fr; }
.cal-filters.open .filters { opacity: 1; transform: none; }
.cal-filters + .totals-bar { margin-top: 14px; }

.cal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 350px; gap: 16px; align-items: start; margin-top: 16px; }
.cal-layout > .panel { margin-top: 0; }
.cal-board { padding: 14px; overflow: hidden; }
.cal-week-head { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; padding: 2px 4px 10px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); grid-auto-rows: 128px; gap: 6px; }

/* entrata e uscita del periodo */
.cal-body.leave { transition: opacity 0.16s ease, transform 0.18s ease; opacity: 0; }
.cal-body.leave[data-dir="next"] { transform: translateX(-18px); }
.cal-body.leave[data-dir="prev"] { transform: translateX(18px); }
.cal-body.leave[data-dir="fade"] { transform: scale(0.99); }
.cal-body.enter .cal-cell, .cal-body.enter .wk-col { animation: cal-in 0.5s var(--ease) both; animation-delay: calc(var(--i, 0) * 9ms); }
.cal-body.enter[data-dir="next"] .cal-cell, .cal-body.enter[data-dir="next"] .wk-col { --from: 16px; }
.cal-body.enter[data-dir="prev"] .cal-cell, .cal-body.enter[data-dir="prev"] .wk-col { --from: -16px; }
@keyframes cal-in { from { opacity: 0; transform: translate(var(--from, 0), 8px) scale(0.985); } }

.cal-cell {
  position: relative; display: flex; flex-direction: column; gap: 6px; min-width: 0; padding: 9px 10px; text-align: left; cursor: pointer;
  border: 0; border-radius: 13px; background: rgb(var(--text-rgb) / 0.025); box-shadow: inset 0 0 0 1px var(--line);
  transition: background 0.25s, box-shadow 0.25s, transform 0.35s var(--ease); overflow: hidden;
}
.cal-cell:hover { background: rgb(var(--text-rgb) / 0.05); transform: translateY(-2px); }
.cal-cell:active { transform: scale(0.98); }
.cal-cell.weekend { background: rgb(var(--text-rgb) / 0.012); }
.cal-cell.out { opacity: 0.38; }
.cal-cell.out:hover { opacity: 0.7; }
.cal-cell.sel { background: var(--raised); box-shadow: inset 0 0 0 1.5px var(--text), 0 14px 30px -18px rgb(var(--text-rgb) / 0.55); }
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.cal-num { display: grid; place-items: center; min-width: 28px; height: 28px; border-radius: 50%; font-family: var(--font-mono); font-size: 14px; color: var(--muted); transition: background 0.25s, color 0.25s; }
.cal-cell.has .cal-num { color: var(--text); }
.cal-cell.today .cal-num { background: var(--text); color: var(--page); }
.cal-count { font-size: 11px; color: var(--label); }
.cal-bar { display: flex; height: 4px; border-radius: 2px; overflow: hidden; gap: 1px; background: rgb(var(--text-rgb) / 0.06); flex: none; }
.cal-bar i { display: block; background: rgb(var(--todo) / 0.75); min-width: 0; }
.cal-bar i.ok { background: rgb(var(--done)); }
.cal-bar i.ko { background: rgb(var(--notdone)); }
.cal-bar i.late { background: rgb(var(--late)); }
.cal-items { display: grid; gap: 3px; min-width: 0; }
.cal-item { --c: var(--todo); position: relative; display: block; padding-left: 9px; font-size: 12px; line-height: 1.35; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal-item::before { content: ""; position: absolute; left: 0; top: 5px; width: 4px; height: 4px; border-radius: 50%; background: rgb(var(--c)); }
.cal-item.is-late { --c: var(--late); }
.cal-item b { font-weight: 400; color: var(--text); font-size: 11px; margin-right: 2px; }
.cal-more { font-size: 11.5px; color: var(--label); padding-left: 9px; }
.cal-dots { display: none; gap: 3px; }
.cal-dots i { width: 5px; height: 5px; border-radius: 50%; background: rgb(var(--c, var(--todo))); }
.cal-dots i.s-done { --c: var(--done); }
.cal-dots i.s-notdone { --c: var(--notdone); }
.cal-undated { display: flex; align-items: center; gap: 8px; width: 100%; margin-top: 12px; padding: 10px 12px; border: 0; border-radius: 11px; cursor: pointer; font-size: 13.5px; color: rgb(var(--todo)); background: rgb(var(--todo) / 0.08); text-align: left; }
.cal-undated .ico { width: 16px; height: 16px; }

/* settimana */
.wk-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.wk-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; padding: 8px; border-radius: 14px; background: rgb(var(--text-rgb) / 0.02); box-shadow: inset 0 0 0 1px var(--line); transition: box-shadow 0.25s, background 0.25s; }
.wk-col.sel { background: var(--raised); box-shadow: inset 0 0 0 1.5px var(--text); }
.wk-head { display: flex; align-items: center; gap: 8px; padding: 4px 4px 2px; border: 0; background: none; cursor: pointer; text-align: left; }
.wk-num { font-family: var(--font-mono); font-size: 20px; letter-spacing: -0.04em; }
.wk-col.today .wk-num { display: inline-grid; place-items: center; min-width: 32px; height: 32px; border-radius: 50%; background: var(--text); color: var(--page); font-size: 16px; }
.wk-head .cal-count { margin-left: auto; }
.wk-slot { display: grid; gap: 5px; }
.wk-slot > .label { padding: 4px 4px 0; }
.wk-item { --c: var(--todo); position: relative; display: grid; gap: 1px; padding: 8px 9px 8px 12px; border-radius: 10px; color: var(--text); background: var(--panel-top); box-shadow: inset 0 0 0 1px var(--line); font-size: 12.5px; transition: transform 0.3s var(--ease), box-shadow 0.25s; }
.wk-item::before { content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: rgb(var(--c)); }
.wk-item.s-done { --c: var(--done); }
.wk-item.s-notdone { --c: var(--notdone); }
.wk-item.is-late { --c: var(--late); }
.wk-item:hover { text-decoration: none; transform: translateY(-2px); box-shadow: inset 0 0 0 1px var(--line-strong), 0 10px 20px -14px rgb(0 0 0 / 0.5); }
.wk-item b { font-weight: 500; }
.wk-time { font-size: 10.5px; color: var(--label); }
.wk-meta { font-size: 11px; color: var(--muted); }
.wk-meta .ico { width: 11px; height: 11px; vertical-align: -1px; color: rgb(var(--todo)); }
.wk-more { border: 0; background: none; cursor: pointer; font-size: 12px; color: var(--muted); text-align: left; padding: 2px 4px; }
.wk-more:hover { color: var(--text); }
.wk-empty { color: var(--label); font-size: 12px; padding: 2px 4px; }
.cal-item.s-done { --c: var(--done); }
.cal-item.s-notdone { --c: var(--notdone); }

/* pannello del giorno */
.cal-day { position: sticky; top: 104px; max-height: calc(100vh - 124px); overflow-y: auto; overscroll-behavior: contain; padding: 0; scrollbar-width: none; }
.cal-day::-webkit-scrollbar { display: none; }
.cd-inner { animation: cd-in 0.45s var(--ease) both; }
.cd-inner.leaving { animation: cd-out 0.14s ease both; }
@keyframes cd-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes cd-out { to { opacity: 0; transform: translateY(-6px); } }
.cd-head { position: sticky; top: 0; z-index: 2; padding: 20px 20px 14px; background: linear-gradient(180deg, var(--panel-top) 82%, transparent); }
.cd-head h3 { font-size: 26px; font-weight: 400; letter-spacing: -0.035em; margin: 4px 0 12px; }
.cd-stats { display: flex; flex-wrap: wrap; gap: 6px; }
.cd-list { padding: 0 14px 16px; }
.cd-list .appt-card { padding: 13px 14px 13px 18px; }
.cd-list .ac-order { margin-left: 0; width: 100%; }
.cd-list.loaded .appt-card { animation: rise 0.45s var(--ease) both; }
.cd-list.loaded .appt-card:nth-child(2) { animation-delay: 40ms; }
.cd-list.loaded .appt-card:nth-child(3) { animation-delay: 80ms; }
.cd-list.loaded .appt-card:nth-child(4) { animation-delay: 120ms; }
.cd-list.loaded .appt-card:nth-child(n+5) { animation-delay: 160ms; }
.cd-skel { height: 92px; margin-top: 8px; border-radius: 14px; background: linear-gradient(90deg, rgb(var(--text-rgb) / 0.04), rgb(var(--text-rgb) / 0.08), rgb(var(--text-rgb) / 0.04)); background-size: 200% 100%; animation: shimmer 1.2s linear infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }
.cd-empty { padding: 34px 10px; text-align: center; color: var(--muted); border-radius: 14px; box-shadow: inset 0 0 0 1px var(--line); }

/* la voce attiva del menu: anello nero invece del blu */
.rail nav a:focus-visible { outline: none; box-shadow: inset 0 0 0 2px rgb(var(--text-rgb) / 0.5); }

@media (max-width: 1180px) {
  .cal-layout { grid-template-columns: minmax(0, 1fr); }
  .cal-day { position: static; max-height: none; overflow: visible; }
  .wk-grid { grid-template-columns: repeat(7, minmax(150px, 1fr)); overflow-x: auto; padding-bottom: 6px; }
}
@media (max-width: 880px) {
  .cal-toolbar { gap: 10px; }
  .cal-title { min-width: 0; font-size: 20px; flex: 1; }
  .seg-switch { margin-left: 0; }
  .cal-search { flex: 1 1 100%; }
  .cal-grid { grid-auto-rows: 64px; gap: 4px; }
  .cal-board { padding: 8px; }
  .cal-cell { padding: 6px; border-radius: 10px; }
  .cal-items, .cal-bar, .cal-count { display: none; }
  .cal-dots { display: flex; }
  .cal-num { min-width: 24px; height: 24px; font-size: 12.5px; }
}

/* in settimana il calendario usa tutta la larghezza; il giorno scelto si apre sotto */
.cal-layout.is-week { grid-template-columns: minmax(0, 1fr); }
.cal-layout.is-week .cal-day { position: static; max-height: none; overflow: visible; }
.cal-layout.is-week .cd-head { position: static; }
.cal-layout.is-week .cd-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 0 12px; }

/* ------------------------------------------------------------------ solo mese, a tutta larghezza; il giorno si apre in un pannello laterale */
/* il mese a sinistra, il pannello del giorno fisso a destra (sotto, sugli schermi stretti) */
.cal-grid { grid-auto-rows: 132px; }
.cal-item { font-size: 12.5px; }

.cd-drawer-wrap { position: fixed; inset: 0; z-index: 110; pointer-events: none; }
.cd-backdrop { position: absolute; inset: 0; background: rgb(10 10 12 / 0.28); backdrop-filter: blur(3px); opacity: 0; transition: opacity 0.5s cubic-bezier(0.65, 0, 0.35, 1); }
.cd-drawer-wrap .cal-day {
  position: absolute; top: 12px; right: 12px; bottom: 12px; width: min(440px, calc(100vw - 24px)); max-height: none;
  margin: 0; padding: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: none;
  transform: translateX(calc(100% + 24px)); transition: transform 0.6s cubic-bezier(0.65, 0, 0.35, 1);
  box-shadow: 0 30px 80px -30px rgb(0 0 0 / 0.55);
}
.cd-drawer-wrap .cal-day::-webkit-scrollbar { display: none; }
.cd-drawer-wrap.open { pointer-events: auto; }
.cd-drawer-wrap.open .cd-backdrop { opacity: 1; }
.cd-drawer-wrap.open .cal-day { transform: none; transition: transform 0.7s cubic-bezier(0.22, 1, 0.36, 1); }
.cd-drawer-wrap .cd-head { position: sticky; top: 0; padding-right: 64px; }
.cd-close { position: absolute; top: 18px; right: 18px; display: grid; place-items: center; width: 36px; height: 36px; border: 0; border-radius: 11px; background: rgb(var(--text-rgb) / 0.06); color: var(--muted); cursor: pointer; transition: background 0.2s, color 0.2s, transform 0.3s var(--ease); }
.cd-close:hover { background: var(--text); color: var(--page); transform: rotate(90deg); }
.cd-close .ico { width: 16px; height: 16px; }

@media (max-width: 880px) {
  .cal-grid { grid-auto-rows: 64px; }
  .cd-drawer-wrap .cal-day { top: auto; left: 8px; right: 8px; bottom: 8px; width: auto; max-height: 82vh; transform: translateY(calc(100% + 16px)); }
}
@media (prefers-reduced-motion: reduce) { .cd-backdrop, .cd-drawer-wrap .cal-day { transition: none !important; } }

.cal-cell:focus-visible { outline: none; box-shadow: inset 0 0 0 2px rgb(var(--text-rgb) / 0.5); }

/* il pannello del giorno scorre per conto suo, ma arrivato in fondo (o se è corto) la rotella torna alla pagina */
.lenis.lenis-smooth .cal-day[data-lenis-prevent] { overscroll-behavior: auto; }
