/* Desktop calendar workspace — header toolbar, rail and the native board
   (web/assets/js/calendar-board.js). No page scroll: the board scrolls. */

.cal-page {
  --cb-ink: var(--neutral-900);
  --cb-ink-2: var(--neutral-700);
  --cb-muted: var(--neutral-500);
  --cb-faint: var(--neutral-400);
  --cb-surface: var(--neutral-0);
  --cb-surface-2: var(--neutral-50);
  --cb-line: rgba(var(--rgb-ink), 0.06);
  --cb-line-strong: rgba(var(--rgb-ink), 0.11);
  --cb-accent: var(--brand-green);
  --cb-accent-ink: var(--brand-green-strong);
  --cb-accent-soft: rgba(var(--brand-green-rgb), 0.08);
  --cb-accent-softer: rgba(var(--brand-green-rgb), 0.045);
  --cb-radius: 14px;
  --cb-shadow: var(--shadow-card);
  --cb-display: var(--font-family-display);
}

@media (min-width: 769px) {
  /* The board is a fixed-height app filling the viewport under the topbar:
     .cal-page carries its own gutters, so the shell's 2.5rem vertical padding
     would only shorten it. The signed-in legal strip (base.html) sits below
     the board and is reached by scrolling the page, so it costs the grid no
     height. */
  body.page-calendar .app-content .app-content-container {
    --cal-board-height: calc(100vh - var(--topbar-height));
    display: flex;
    flex-direction: column;
    padding-top: 0 !important;
    padding-bottom: 0 !important;
  }

  body.page-calendar.impersonating .app-content .app-content-container,
  body.page-calendar.is-impersonating .app-content .app-content-container {
    --cal-board-height: calc(100vh - var(--topbar-height) - var(--impersonation-banner-height));
  }

  body.page-calendar .cal-page {
    display: flex;
    flex-direction: column;
    flex: 0 0 auto;
    /* Fixed, not just capped: month view has little natural height and must
       still stretch the board to the bottom of the viewport. */
    height: var(--cal-board-height);
    min-height: 0;
    overflow: hidden;
    padding: 0.75rem 1.125rem;
    gap: 0.625rem;
  }

  body.page-calendar .app-legal-strip {
    flex-shrink: 0;
    margin: 0;
    padding: 0.75rem 1.125rem 1rem;
  }

  body.page-calendar .cal-desktop-only {
    display: flex;
  }

  /* ---------- Header: one toolbar row (title · sync · google | nav · range | views · new) ----------
     Narrower screens wrap it into two tidy rows: identity + sync on top,
     navigation left and views right underneath. */

  body.page-calendar .cal-title-box {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 1.5rem;
    padding: 0.5rem 0.75rem 0.5rem 1.125rem;
    margin: 0;
    background: var(--cb-surface);
    border: 1px solid var(--cb-line);
    border-radius: var(--cb-radius);
    box-shadow: var(--cb-shadow);
    flex-shrink: 0;
  }

  body.page-calendar .cal-title-box__row {
    display: flex;
    align-items: center;
    gap: 0.5rem 0.75rem;
    flex: 0 1 auto;
    min-width: 0;
  }

  body.page-calendar .cal-title-box__start {
    display: flex;
    align-items: center;
    gap: 0.5rem 0.625rem;
    flex: 0 1 auto;
    min-width: 0;
  }

  body.page-calendar .cal-title-box__title {
    margin: 0;
    font-family: var(--cb-display);
    font-size: var(--font-size-lg);
    font-weight: 600;
    letter-spacing: -0.015em;
    line-height: 1.25;
    white-space: nowrap;
    color: var(--cb-ink);
  }

  body.page-calendar .cal-title-box__sync .calendar-status-pill {
    gap: 0.3rem;
    font-size: var(--font-size-xs);
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-pill);
    white-space: nowrap;
  }

  body.page-calendar .cal-title-box__google-slot {
    display: flex;
    align-items: center;
    min-width: 0;
  }

  body.page-calendar .cal-title-box__google-slot:empty {
    display: none;
  }

  body.page-calendar .cal-title-box__google-slot .google-connect-banner {
    margin: 0;
    padding: 0;
    border: none;
    box-shadow: none;
    background: transparent;
  }

  body.page-calendar .cal-title-box__google-slot .google-connect-banner__inner {
    flex-wrap: nowrap;
    gap: 0.5rem;
    align-items: center;
  }

  body.page-calendar .cal-title-box__google-slot .google-connect-banner__icon,
  body.page-calendar .cal-title-box__google-slot .google-connect-banner__body,
  body.page-calendar .cal-title-box__google-slot .google-connect-banner__text,
  body.page-calendar .cal-title-box__google-slot .google-connect-banner__eyebrow,
  body.page-calendar .cal-title-box__google-slot .google-connect-banner__title {
    display: none;
  }

  body.page-calendar .cal-title-box__google-slot .google-connect-banner__actions {
    display: flex;
    align-items: center;
    margin: 0;
    gap: 0.125rem;
  }

  /* A quiet outlined button: "Nuovo evento" stays the one primary action. */
  body.page-calendar .cal-title-box__google-slot .btn-connect-google {
    gap: 0.45rem;
    height: 2rem;
    min-height: 0;
    padding: 0 0.8rem 0 0.35rem;
    border: 1px solid var(--cb-line-strong);
    border-radius: var(--radius-pill);
    background: var(--cb-surface);
    color: var(--cb-ink);
    font-size: var(--font-size-caption);
    font-weight: 600;
    box-shadow: none;
  }

  body.page-calendar .cal-title-box__google-slot .btn-connect-google:hover {
    background: var(--cb-surface-2);
    border-color: rgba(var(--rgb-ink), 0.18);
    color: var(--cb-ink);
  }

  body.page-calendar .cal-title-box__google-slot .btn-connect-google__icon {
    width: 1.375rem;
    height: 1.375rem;
    box-shadow: none;
  }

  /* "Perché collegare?" becomes a help icon; the label lives in title/aria-label. */
  body.page-calendar .cal-title-box__google-slot .btn-connect-google-ghost {
    width: 2rem;
    height: 2rem;
    min-height: 0;
    padding: 0;
    border-radius: var(--radius-round);
    color: var(--cb-faint);
    font-size: 0;
  }

  body.page-calendar .cal-title-box__google-slot .btn-connect-google-ghost i {
    font-size: var(--font-size-base);
  }

  body.page-calendar .cal-title-box__google-slot .btn-connect-google-ghost:hover {
    background: var(--cb-accent-soft);
    color: var(--cb-accent-ink);
  }

  body.page-calendar .cal-title-box__status {
    flex-shrink: 0;
  }

  body.page-calendar .cal-title-box__status:empty {
    display: none;
  }

  body.page-calendar .cal-title-box__status .calendar-loading-status {
    font-size: var(--font-size-xs);
    color: var(--cb-faint);
  }

  /* "Caricati N eventi" repeats what the board already shows: only loading
     and errors earn header space. */
  body.page-calendar .cal-title-box__status #calendar-status:has(.is-success) {
    display: none;
  }

  body.page-calendar .cal-title-box__status .calendar-loading-status.is-error {
    color: var(--color-danger-bright);
  }

  /* Grows to take the rest of the row; drops to its own line when the header
     is narrower than title + toolbar. */
  body.page-calendar .cal-toolbar {
    flex: 1 1 36rem;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
    min-width: 0;
  }

  body.page-calendar .cal-title-box__nav {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    min-width: 0;
  }

  body.page-calendar .cal-title-box__range {
    font-family: var(--cb-display);
    font-size: var(--font-size-base);
    font-weight: 500;
    letter-spacing: -0.01em;
    color: var(--cb-ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    text-align: left;
  }

  body.page-calendar .cal-nav-pair {
    display: inline-flex;
    border: 1px solid var(--cb-line-strong);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--cb-surface);
  }

  body.page-calendar .cal-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    padding: 0;
    border: none;
    background: transparent;
    color: var(--cb-ink-2);
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
  }

  body.page-calendar .cal-nav-pair .cal-nav-btn + .cal-nav-btn {
    border-left: 1px solid var(--cb-line-strong);
  }

  body.page-calendar .cal-nav-btn:hover {
    background: var(--cb-accent-soft);
    color: var(--cb-accent-ink);
  }

  body.page-calendar .cal-nav-btn:focus-visible,
  body.page-calendar .cal-nav-today:focus-visible,
  body.page-calendar .cal-view-switch button:focus-visible {
    outline: 2px solid var(--cb-accent);
    outline-offset: 1px;
  }

  body.page-calendar .cal-nav-today {
    height: 2rem;
    padding: 0 0.875rem;
    border: 1px solid var(--cb-line-strong);
    border-radius: var(--radius-pill);
    background: var(--cb-surface);
    color: var(--cb-ink);
    font-size: var(--font-size-caption);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease;
  }

  body.page-calendar .cal-nav-today:hover {
    background: var(--cb-surface-2);
    border-color: rgba(var(--rgb-ink), 0.18);
  }

  body.page-calendar .cal-toolbar__end {
    display: flex;
    align-items: center;
    gap: 0.625rem;
  }

  body.page-calendar .cal-view-switch {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--neutral-100);
    border-radius: var(--radius-sm);
  }

  body.page-calendar .cal-view-switch button {
    height: var(--control-height-sm);
    padding: 0 0.8rem;
    border: none;
    border-radius: var(--radius-pill);
    background: transparent;
    color: var(--cb-muted);
    font-size: var(--font-size-caption);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  }

  body.page-calendar .cal-view-switch button:hover {
    color: var(--cb-ink);
  }

  body.page-calendar .cal-view-switch button.is-active {
    background: var(--cb-surface);
    color: var(--cb-ink);
    font-weight: 600;
    box-shadow: var(--shadow-xs);
  }

  body.page-calendar .cal-new-event {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    height: 2rem;
    padding: 0 0.875rem 0 0.7rem;
    border-radius: var(--radius-pill);
    font-size: var(--font-size-caption);
    font-weight: 600;
  }

  /* ---------- Workspace + rail ---------- */

  body.page-calendar .cal-workspace {
    flex: 1 1 auto;
    min-height: 0;
    gap: 0.75rem;
    overflow: hidden;
  }

  body.page-calendar .cal-rail {
    flex: 0 0 232px;
    width: 232px;
    display: flex;
    flex-direction: column;
    min-height: 0;
    gap: 0.75rem;
    overflow-y: auto;
    scrollbar-width: thin;
  }

  body.page-calendar .cal-mini-month-wrap,
  body.page-calendar .cal-client-switcher,
  body.page-calendar .cal-legend {
    background: var(--cb-surface);
    border: 1px solid var(--cb-line);
    border-radius: var(--cb-radius);
    box-shadow: var(--cb-shadow);
  }

  body.page-calendar .cal-mini-month-wrap {
    flex-shrink: 0;
    padding: 0.75rem 0.625rem 0.625rem;
  }

  body.page-calendar .cal-mini-month-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.25rem;
    padding: 0 0.125rem 0.5rem 0.25rem;
  }

  body.page-calendar .cal-mini-month-label {
    font-family: var(--cb-display);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--cb-ink);
    text-transform: capitalize;
  }

  body.page-calendar .cal-nav-pair--mini {
    border: none;
    gap: 2px;
  }

  body.page-calendar .cal-nav-pair--mini .cal-nav-btn {
    width: 1.625rem;
    height: 1.625rem;
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
  }

  body.page-calendar .cal-nav-pair--mini .cal-nav-btn + .cal-nav-btn {
    border-left: none;
  }

  /* Mini month grid */
  body.page-calendar .cb-mini__grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    row-gap: 1px;
  }

  body.page-calendar .cb-mini__dow {
    text-align: center;
    font-size: var(--font-size-3xs);
    font-weight: 600;
    text-transform: uppercase;
    color: var(--cb-faint);
    padding: 0 0 0.3rem;
  }

  body.page-calendar .cb-mini__day {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1px;
    height: 1.875rem;
    padding: 0.2rem 0 0;
    border: none;
    background: transparent;
    color: var(--cb-ink-2);
    font-size: var(--font-size-xs);
    font-variant-numeric: tabular-nums;
    cursor: pointer;
  }

  body.page-calendar .cb-mini__num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.375rem;
    height: 1.375rem;
    border-radius: var(--radius-pill);
    line-height: 1;
    transition: background 0.12s ease;
  }

  body.page-calendar .cb-mini__day:hover .cb-mini__num {
    background: var(--neutral-100);
  }

  body.page-calendar .cb-mini__day.is-outside {
    color: var(--neutral-300);
  }

  body.page-calendar .cb-mini__day.is-in-range {
    background: var(--cb-accent-soft);
  }

  body.page-calendar .cb-mini__day.is-range-start {
    border-top-left-radius: var(--radius-sm);
    border-bottom-left-radius: var(--radius-sm);
  }

  body.page-calendar .cb-mini__day.is-range-end {
    border-top-right-radius: var(--radius-sm);
    border-bottom-right-radius: var(--radius-sm);
  }

  body.page-calendar .cb-mini__day.is-today .cb-mini__num {
    background: var(--cb-accent);
    color: var(--neutral-0);
    font-weight: 700;
  }

  body.page-calendar .cb-mini__day:focus-visible {
    outline: 2px solid var(--cb-accent);
    outline-offset: -2px;
    border-radius: var(--radius-sm);
  }

  body.page-calendar .cb-mini__dots {
    display: flex;
    gap: 2px;
    height: 4px;
  }

  body.page-calendar .cb-mini__dots i {
    width: 4px;
    height: 4px;
    border-radius: var(--radius-pill);
    background: var(--ev, var(--cb-accent));
  }

  body.page-calendar .cal-rail__heading {
    margin: 0 0 0.5rem;
    font-size: var(--font-size-2xs);
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--cb-faint);
  }

  /* Client switcher (staff) */
  body.page-calendar .cal-client-switcher {
    flex: 1 1 auto;
    min-height: 14rem;
    display: flex;
    flex-direction: column;
    padding: 0.75rem 0.625rem 0.5rem;
    overflow: hidden;
  }

  body.page-calendar .cal-client-switcher .cal-rail__heading {
    padding-left: 0.25rem;
  }

  body.page-calendar .cal-client-search-wrap {
    position: relative;
    flex-shrink: 0;
    margin-bottom: 0.375rem;
  }

  body.page-calendar .cal-client-search-wrap .bi-search {
    position: absolute;
    left: 0.6rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: var(--font-size-xs);
    color: var(--cb-faint);
    pointer-events: none;
  }

  body.page-calendar .cal-client-search {
    padding-left: 1.75rem;
    border-radius: var(--radius-sm);
    border-color: var(--cb-line-strong);
    background: var(--cb-surface-2);
    font-size: var(--font-size-caption);
  }

  body.page-calendar .cal-client-list {
    list-style: none;
    margin: 0;
    padding: 0;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
    scrollbar-width: thin;
  }

  body.page-calendar .cal-client-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    text-align: left;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    padding: 0.35rem 0.4rem;
    font-size: var(--font-size-caption);
    font-weight: 500;
    color: var(--cb-ink-2);
    cursor: pointer;
    transition: background 0.12s ease;
  }

  body.page-calendar .cal-client-item:hover {
    background: var(--cb-surface-2);
  }

  body.page-calendar .cal-client-item.is-active {
    background: var(--cb-accent-soft);
    color: var(--brand-green-ink);
    font-weight: 600;
  }

  body.page-calendar .cal-client-item__avatar {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: var(--radius-pill);
    background: var(--color-border-faint);
    color: var(--cb-muted);
    font-size: var(--font-size-2xs);
    font-weight: 700;
  }

  body.page-calendar .cal-client-item.is-active .cal-client-item__avatar {
    background: var(--cb-accent);
    color: var(--neutral-0);
  }

  body.page-calendar .cal-client-item__name {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  /* Legend */
  body.page-calendar .cal-legend {
    flex-shrink: 0;
    margin-top: auto;
    padding: 0.5rem 0.875rem;
  }

  body.page-calendar .cal-legend__toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin: 0;
    padding: 0.125rem 0;
    list-style: none;
    cursor: pointer;
    user-select: none;
  }

  body.page-calendar .cal-legend__toggle::-webkit-details-marker {
    display: none;
  }

  body.page-calendar .cal-legend__toggle:hover {
    color: var(--cb-muted);
  }

  body.page-calendar .cal-legend__dots {
    display: inline-flex;
    gap: 3px;
  }

  body.page-calendar .cal-legend__dots i {
    width: 7px;
    height: 7px;
    border-radius: var(--radius-pill);
    background: var(--sw);
  }

  body.page-calendar .cal-legend__chevron {
    margin-left: auto;
    font-size: var(--font-size-2xs);
    transition: transform 0.15s ease;
  }

  body.page-calendar .cal-legend[open] .cal-legend__chevron {
    transform: rotate(180deg);
  }

  body.page-calendar .cal-legend[open] .cal-legend__toggle {
    margin-bottom: 0.5rem;
  }

  body.page-calendar .cal-legend__list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.35rem;
    font-size: var(--font-size-xs);
    color: var(--cb-ink-2);
  }

  body.page-calendar .cal-legend__list li {
    display: flex;
    align-items: center;
    gap: 0.5rem;
  }

  body.page-calendar .cal-legend__swatch {
    width: 0.75rem;
    height: 0.75rem;
    border-radius: var(--radius-xs);
    --cb-rule: inset 3px 0 0 var(--sw);
    background: color-mix(in srgb, var(--sw) 18%, var(--neutral-0));
    box-shadow: var(--cb-rule);
  }

  body.page-calendar .cal-legend__swatch--manual { --sw: var(--brand-green); }
  body.page-calendar .cal-legend__swatch--carla { --sw: var(--brand-green-300); }
  body.page-calendar .cal-legend__swatch--website { --sw: var(--color-warning); }
  body.page-calendar .cal-legend__swatch--allday { --sw: var(--color-ai); }

  body.page-calendar .cal-legend__note {
    margin: 0.5rem 0 0;
    font-size: var(--font-size-2xs);
    line-height: 1.35;
    color: var(--cb-faint);
  }

  /* ---------- Board pane ---------- */

  body.page-calendar .cal-week-pane {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* Legacy calendar/layout sheets card these wrappers; the board has one frame. */
  body.page-calendar .cal-week-pane .calendar-container {
    flex: 1 1 auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 0 !important;
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;
  }

  /* customer-layout-optimization.css forces a 600px !important floor and a
     bottom margin on these two; inside the pane that clips the last rows. */
  body.page-calendar .cal-workspace .calendar-main-container {
    flex: 1 1 auto;
    min-height: 0 !important;
    height: auto;
    max-height: none;
    padding: 0 !important;
    margin: 0 !important;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: var(--cb-radius);
    border: 1px solid var(--cb-line);
    box-shadow: var(--cb-shadow);
    background: var(--cb-surface);
  }

  body.page-calendar .cal-workspace #calendar-container {
    position: relative;
    padding: 0 !important;
    margin: 0 !important;
    flex: 1 1 auto;
    min-height: 0 !important;
    height: 100%;
    overflow: hidden;
  }
}

/* =====================================================================
   Board — calendar-board.js
   ===================================================================== */

.cb {
  --cb-gutter-w: 3.5rem;
  --cb-hour-h: 48px;
  position: relative;
  display: flex;
  flex-direction: column;
  font-family: var(--font-family);
  color: var(--cb-ink, var(--neutral-900));
  user-select: none;
  -webkit-user-select: none;
}

.cb-root {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.cb.is-dragging,
.cb.is-dragging * {
  cursor: grabbing !important;
}

.cb::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--cb-accent, var(--brand-green)), transparent);
  background-size: 40% 100%;
  background-repeat: no-repeat;
  opacity: 0;
  pointer-events: none;
  z-index: 8;
}

.cb.is-loading::after {
  opacity: 0.7;
  animation: cb-loading 1.1s ease-in-out infinite;
}

@keyframes cb-loading {
  from { background-position: -40% 0; }
  to { background-position: 140% 0; }
}

.cb-gutter {
  flex: 0 0 var(--cb-gutter-w);
  width: var(--cb-gutter-w);
}

/* Day headers */
.cb-head {
  display: flex;
  flex-shrink: 0;
  padding-right: var(--cb-scrollbar, 0px);
  border-bottom: 1px solid var(--cb-line, rgba(var(--rgb-ink), 0.06));
}

.cb-dayhead {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.625rem 0.25rem 0.55rem;
  border: none;
  border-left: 1px solid var(--cb-line, rgba(var(--rgb-ink), 0.06));
  background: transparent;
  cursor: pointer;
  transition: background 0.12s ease;
}

.cb-dayhead:hover {
  background: var(--cb-surface-2, var(--neutral-50));
}

.cb-dayhead:focus-visible {
  outline: 2px solid var(--cb-accent, var(--brand-green));
  outline-offset: -2px;
}

.cb-dayhead__dow {
  font-size: var(--font-size-2xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cb-muted, var(--neutral-500));
}

.cb-dayhead__num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.875rem;
  height: 1.875rem;
  padding: 0 0.35rem;
  border-radius: var(--radius-pill);
  font-family: var(--cb-display, Poppins, Inter, sans-serif);
  font-size: var(--font-size-base);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--cb-ink, var(--neutral-900));
}

.cb-dayhead__month {
  font-size: var(--font-size-caption);
  color: var(--cb-muted, var(--neutral-500));
  text-transform: capitalize;
}

.cb-dayhead.is-past .cb-dayhead__num {
  color: var(--cb-faint, var(--neutral-400));
}

.cb-dayhead.is-today .cb-dayhead__dow {
  color: var(--cb-accent-ink, var(--brand-green-strong));
}

.cb-dayhead.is-today .cb-dayhead__num {
  background: var(--cb-accent, var(--brand-green));
  color: var(--neutral-0);
  font-weight: 600;
}

.cb-root--day .cb-dayhead {
  justify-content: flex-start;
  padding-left: 1rem;
}

/* All-day lane */
.cb-allday {
  display: flex;
  flex-shrink: 0;
  padding-right: var(--cb-scrollbar, 0px);
  border-bottom: 1px solid var(--cb-line-strong, rgba(var(--rgb-ink), 0.11));
  background: var(--cb-surface-2, var(--neutral-50));
}

.cb-gutter--allday {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 0.5rem;
}

.cb-gutter--allday span {
  font-size: var(--font-size-3xs);
  font-weight: 600;
  line-height: 1.1;
  text-align: right;
  color: var(--cb-faint, var(--neutral-400));
}

.cb-allday__track {
  flex: 1 1 auto;
  min-width: 0;
  position: relative;
  display: grid;
  grid-template-columns: repeat(var(--cb-days, 7), minmax(0, 1fr));
  grid-auto-rows: 1.5rem;
  row-gap: 3px;
  padding: 4px 0;
  min-height: calc(1.5rem + 8px);
  max-height: calc(4 * 1.5rem + 3 * 3px + 8px);
  overflow-y: auto;
  scrollbar-width: thin;
}

.cb-allday__cell {
  border-left: 1px solid var(--cb-line, rgba(var(--rgb-ink), 0.06));
  margin: -4px 0;
  cursor: cell;
}

.cb-allday__cell.is-today {
  background: var(--cb-accent-softer, rgba(var(--brand-green-rgb), 0.045));
}

.cb-allday__cell.is-selected {
  background: rgba(var(--brand-green-rgb), 0.16);
}

/* Shared event skin: tinted fill, accent rule, ink derived from the accent. */
.cb-chip {
  --cb-rule: inset 3px 0 0 var(--ev);
}

.cb-bar,
.cb-ev,
.cb-chip--allday {
  /* Accent rule on the left edge; declared here because --ev is per element. */
  --cb-rule: inset 3px 0 0 var(--ev);
  background: color-mix(in srgb, var(--ev) 15%, var(--neutral-0));
  color: color-mix(in srgb, var(--ev) 45%, var(--neutral-900));
  box-shadow: var(--cb-rule);
}

.cb-bar {
  position: relative;
  z-index: 1;
  display: flex;
  align-items: center;
  min-width: 0;
  margin: 0 3px;
  padding: 0 0.5rem 0 0.6rem;
  border-radius: var(--radius-xs);
  font-size: var(--font-size-xs);
  font-weight: 600;
  cursor: pointer;
  transition: background 0.12s ease, box-shadow 0.12s ease;
}

.cb-bar:hover {
  background: color-mix(in srgb, var(--ev) 24%, var(--neutral-0));
}

.cb-bar.is-clip-start {
  margin-left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  box-shadow: none;
}

.cb-bar.is-clip-end {
  margin-right: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.cb-bar__title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cb-bar__resize {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
}

/* Time grid */
.cb-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(var(--rgb-ink), 0.18) transparent;
}

.cb-grid {
  position: relative;
  display: flex;
}

.cb-times {
  position: relative;
}

.cb-time {
  position: relative;
  height: var(--cb-hour-h);
}

.cb-time span {
  position: absolute;
  top: 0;
  right: 0.5rem;
  transform: translateY(-50%);
  font-size: var(--font-size-2xs);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--cb-faint, var(--neutral-400));
}

.cb-cols {
  flex: 1 1 auto;
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(var(--cb-days, 7), minmax(0, 1fr));
  /* Hour lines + dashed half-hour lines */
  background-image:
    linear-gradient(to bottom, var(--cb-line-strong, rgba(var(--rgb-ink), 0.11)) 1px, transparent 1px),
    linear-gradient(to bottom, transparent calc(var(--cb-hour-h) / 2), var(--cb-line, rgba(var(--rgb-ink), 0.06)) calc(var(--cb-hour-h) / 2), var(--cb-line, rgba(var(--rgb-ink), 0.06)) calc(var(--cb-hour-h) / 2 + 1px), transparent calc(var(--cb-hour-h) / 2 + 1px));
  background-size: 100% var(--cb-hour-h);
}

.cb-col {
  position: relative;
  border-left: 1px solid var(--cb-line, rgba(var(--rgb-ink), 0.06));
  cursor: cell;
}

.cb-col.is-weekend {
  background: color-mix(in srgb, var(--neutral-50) 60%, transparent);
}

.cb-col.is-today {
  background: var(--cb-accent-softer, rgba(var(--brand-green-rgb), 0.045));
}

.cb-root--day .cb-col.is-today,
.cb-root--day .cb-allday__cell.is-today {
  background: transparent;
}

.cb-col__events {
  position: absolute;
  inset: 0 6px 0 2px;
}

.cb-ev {
  position: absolute;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  padding: 0.25rem 0.4rem 0.25rem 0.55rem;
  border-radius: var(--radius-sm);
  overflow: hidden;
  cursor: pointer;
  outline: 1.5px solid var(--cb-surface, var(--neutral-0));
  transition: background 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

.cb-ev:hover {
  z-index: 3;
  background: color-mix(in srgb, var(--ev) 24%, var(--neutral-0));
  box-shadow: var(--cb-rule), var(--shadow-md);
}

.cb-ev:focus-visible,
.cb-bar:focus-visible,
.cb-chip:focus-visible {
  outline: 2px solid var(--ev);
  outline-offset: 1px;
  z-index: 4;
}

.cb-ev.is-cont-top {
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.cb-ev.is-cont-bottom {
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.cb-ev.is-past,
.cb-chip.is-past {
  opacity: 0.74;
}

.cal-layers__select {
  min-width: 12rem;
  max-width: 100%;
}

/* Venditore calendars layered on the engine's: behind its own events, muted,
   dashed, read-only (docs/features/VENDITORE_SPEC.md §11). */
.cb-ev.is-secondary {
  z-index: 1;
  opacity: 0.72;
  outline-style: dashed;
  cursor: default;
}

.cb-ev.is-secondary:hover {
  z-index: 1;
  opacity: 0.9;
}

.cb-ev.is-past:hover,
.cb-chip.is-past:hover {
  opacity: 1;
}

.cb-ev__title {
  font-size: var(--font-size-xs);
  font-weight: 600;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cb-ev__time,
.cb-ev__meta {
  font-size: var(--font-size-2xs);
  font-weight: 500;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  opacity: 0.8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cb-ev__meta {
  font-variant-numeric: normal;
  opacity: 0.72;
}

.cb-ev.is-compact {
  justify-content: center;
  padding-top: 0;
  padding-bottom: 0;
}

.cb-ev__line {
  display: block;
  font-size: var(--font-size-2xs);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cb-ev__line .cb-ev__time {
  display: inline;
  font-weight: 600;
}

.cb-ev__line .cb-ev__title {
  display: inline;
  font-size: inherit;
}

.cb-root--day .cb-ev__title {
  font-size: var(--font-size-caption);
}

.cb-ev__resize {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 7px;
  cursor: ns-resize;
}

.cb-ev__resize::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: 2px;
  width: 18px;
  height: 3px;
  margin-left: -9px;
  border-radius: var(--radius-2xs);
  background: var(--ev);
  opacity: 0;
  transition: opacity 0.12s ease;
}

.cb-ev:hover .cb-ev__resize::after {
  opacity: 0.55;
}

.cb-ev.is-dragging,
.cb-bar.is-dragging,
.cb-chip.is-dragging {
  opacity: 0.3;
}

.cb-ev.is-ghost,
.cb-bar.is-ghost,
.cb-chip.is-ghost {
  z-index: 6;
  pointer-events: none;
  background: color-mix(in srgb, var(--ev) 26%, var(--neutral-0));
  box-shadow: var(--cb-rule), var(--shadow-popover);
}

.cb-select {
  position: absolute;
  left: 2px;
  right: 6px;
  z-index: 5;
  border-radius: var(--radius-sm);
  background: rgba(var(--brand-green-rgb), 0.14);
  border: 1.5px solid var(--cb-accent, var(--brand-green));
  pointer-events: none;
}

.cb-select span {
  display: block;
  padding: 0.2rem 0.45rem;
  font-size: var(--font-size-2xs);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--cb-accent-ink, var(--brand-green-strong));
}

.cb-now {
  position: absolute;
  left: -1px;
  right: 0;
  z-index: 4;
  height: 0;
  border-top: 2px solid var(--color-danger);
  pointer-events: none;
}

.cb-now::before {
  content: '';
  position: absolute;
  left: -5px;
  top: -6px;
  width: 10px;
  height: 10px;
  border-radius: var(--radius-pill);
  background: var(--color-danger);
  --cb-ring: 0 0 0 2px var(--cb-surface, var(--neutral-0));
  box-shadow: var(--cb-ring);
}

/* Month */
.cb-mhead {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  flex-shrink: 0;
  border-bottom: 1px solid var(--cb-line, rgba(var(--rgb-ink), 0.06));
}

.cb-mhead__dow {
  padding: 0.6rem 0.75rem 0.5rem;
  font-size: var(--font-size-2xs);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--cb-muted, var(--neutral-500));
}

.cb-month {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(var(--cb-weeks, 5), minmax(0, 1fr));
}

.cb-mcell {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 0.3rem 0.3rem 0.25rem;
  border-left: 1px solid var(--cb-line, rgba(var(--rgb-ink), 0.06));
  border-bottom: 1px solid var(--cb-line, rgba(var(--rgb-ink), 0.06));
  overflow: hidden;
  cursor: cell;
  transition: background 0.12s ease;
}

.cb-mcell:nth-child(7n + 1) {
  border-left: none;
}

.cb-mcell.is-weekend {
  background: color-mix(in srgb, var(--neutral-50) 70%, transparent);
}

.cb-mcell.is-outside {
  background: var(--cb-surface-2, var(--neutral-50));
}

.cb-mcell.is-outside .cb-mcell__num {
  color: var(--neutral-300);
}

.cb-mcell.is-selected,
.cb-mcell.is-drop-target {
  background: rgba(var(--brand-green-rgb), 0.1);
}

.cb-mcell__num {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.625rem;
  height: 1.625rem;
  margin-bottom: 2px;
  padding: 0 0.3rem;
  border: none;
  border-radius: var(--radius-pill);
  background: transparent;
  font-size: var(--font-size-caption);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--cb-ink-2, var(--neutral-700));
  cursor: pointer;
}

.cb-mcell__num:hover {
  background: var(--neutral-100);
}

.cb-mcell.is-past:not(.is-outside) .cb-mcell__num {
  color: var(--cb-faint, var(--neutral-400));
}

.cb-mcell.is-today .cb-mcell__num {
  background: var(--cb-accent, var(--brand-green));
  color: var(--neutral-0);
  font-weight: 600;
}

.cb-mcell__list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
}

.cb-chip {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  height: 20px;
  padding: 0 0.35rem;
  border-radius: var(--radius-xs);
  font-size: var(--font-size-2xs);
  color: var(--cb-ink-2, var(--neutral-700));
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.12s ease;
}

.cb-chip:hover {
  background: var(--neutral-100);
}

.cb-chip--allday {
  padding-left: 0.5rem;
  font-weight: 600;
}

.cb-chip--allday:hover {
  background: color-mix(in srgb, var(--ev) 24%, var(--neutral-0));
}

.cb-chip--allday.is-cont-left {
  margin-left: -0.3rem;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
  box-shadow: none;
}

.cb-chip--allday.is-cont-right {
  margin-right: -0.3rem;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.cb-chip__dot {
  flex: 0 0 auto;
  width: 7px;
  height: 7px;
  border-radius: var(--radius-pill);
  background: var(--ev);
}

.cb-chip__time {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  color: var(--cb-muted, var(--neutral-500));
}

.cb-chip__title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.cb-chip--allday .cb-chip__title {
  font-weight: 600;
}

.cb-more {
  align-self: flex-start;
  margin-top: 1px;
  padding: 0 0.35rem;
  height: 18px;
  border: none;
  border-radius: var(--radius-xs);
  background: transparent;
  font-size: var(--font-size-2xs);
  font-weight: 600;
  color: var(--cb-muted, var(--neutral-500));
  cursor: pointer;
}

.cb-more:hover {
  background: var(--neutral-100);
  color: var(--cb-ink, var(--neutral-900));
}

/* "+N altri" popover */
.cb-popover {
  position: absolute;
  z-index: 20;
  max-height: 60%;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  border: 1px solid var(--cb-line-strong, rgba(var(--rgb-ink), 0.11));
  border-radius: var(--radius-md);
  background: var(--cb-surface, var(--neutral-0));
  box-shadow: var(--shadow-modal);
  user-select: text;
}

.cb-popover__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0 0 0.4rem 0.25rem;
}

.cb-popover__day {
  border: none;
  background: transparent;
  padding: 0;
  font-family: var(--cb-display, Poppins, Inter, sans-serif);
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--cb-ink, var(--neutral-900));
  cursor: pointer;
}

.cb-popover__day:hover {
  color: var(--cb-accent-ink, var(--brand-green-strong));
}

.cb-popover__close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  border: none;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--cb-muted, var(--neutral-500));
  font-size: var(--font-size-xs);
  cursor: pointer;
}

.cb-popover__close:hover {
  background: var(--neutral-100);
}

.cb-popover__list {
  display: flex;
  flex-direction: column;
  gap: 3px;
  overflow-y: auto;
}

.cb-popover .cb-chip {
  height: 24px;
}

@media (prefers-reduced-motion: reduce) {
  .cb *,
  .cb::after {
    transition: none !important;
    animation: none !important;
  }
}

@media (max-width: 768px) {
  .cal-desktop-only {
    display: none !important;
  }

  body.page-calendar .cal-page {
    padding: 0;
  }

  body.page-calendar .cal-title-box {
    display: none;
  }
}
