/* ==================================================================================================
   Schedule — project Calendar + Timeline (Gantt). Owner: schedule agent.
   Markup: templates/projects/{calendar,timeline}.html + partials/{calendar,timeline}_*.html
   Behaviour: static/js/schedule.js. Tokens only (var(--…)); everything is scoped under .schedule,
   .sched-* or .tl-* / .cal-* roots.

   .schedule            page root (#schedule; children swapped with morph:innerHTML)
   .sched-toolbar       nav + title (lead) and tools (My tasks, Filter, view switch)
   .sched-seg           morph-safe segmented control (server renders the active item)
   .cal / .cal-day …    month + week grid, chips (.cal-chip), "+N more" popover (.cal-more)
   .cal-agenda / .cal-row   phone agenda (< 768px) · .cal-tray  unscheduled tray (≥ 768px)
   .tl / .tl-*          timeline: sticky header + task column, lanes, bars, milestones, ghost
   .sched-pop           date popover · .tl-tip  bar tooltip (created by JS)
   ================================================================================================== */

/* -- Root & toolbar -------------------------------------------------------------------------------- */
.schedule {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  min-width: 0;
}

.sched-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2) var(--space-3);
  min-width: 0;
}
.sched-toolbar__lead,
.sched-toolbar__tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}
.sched-toolbar__lead {
  flex: 1 1 auto;
  gap: var(--space-3);
}
.sched-title {
  min-width: 0;
  font-family: var(--font-display);
  font-size: var(--fs-title-3);
  font-weight: var(--fw-bold);
  letter-spacing: var(--tracking-tight);
  line-height: 1.2;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.sched-title::first-letter {
  text-transform: uppercase;
}

/* ‹ Today › — one joined capsule */
.sched-nav {
  display: inline-flex;
  align-items: center;
  padding: 2px;
  border-radius: var(--radius-full);
  background: var(--surface);
  box-shadow:
    0 0 0 1px var(--card-ring),
    var(--shadow-xs);
}
.sched-nav .btn {
  border-radius: var(--radius-full);
  background: transparent;
  box-shadow: none;
}
.sched-nav .btn:hover {
  background: var(--fill-1);
}
.sched-nav .btn[aria-disabled="true"] {
  opacity: 0.35;
  pointer-events: none;
}
.sched-nav__today {
  padding-inline: 12px;
  font-weight: var(--fw-semibold);
}
.schedule--timeline .sched-nav__today {
  border-radius: var(--radius-full);
}

/* Toggle buttons (My tasks, Filter, Unscheduled) */
.sched-toggle {
  gap: 6px;
}
.sched-toggle .avatar {
  margin-left: -3px;
}
.sched-toggle[aria-pressed="true"],
.sched-toggle[aria-expanded="true"]:not([data-menu-trigger]) {
  background: var(--accent-soft);
  box-shadow: none;
  color: var(--accent-ink);
}
.sched-toggle[aria-pressed="true"] .icon,
.sched-toggle[aria-expanded="true"]:not([data-menu-trigger]) .icon {
  color: var(--accent);
}
.sched-toggle__count {
  display: inline-grid;
  place-items: center;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: var(--radius-full);
  background: var(--fill-2);
  color: var(--text-2);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
}
.sched-toggle[aria-pressed="true"] .sched-toggle__count,
.sched-toggle[aria-expanded="true"] .sched-toggle__count {
  background: var(--accent);
  color: var(--text-on-accent);
}
.sched-filter__panel {
  width: 280px;
}
.sched-filter__panel .menu__item .avatar,
.sched-filter__panel .menu__item .priority,
.sched-filter__panel .menu__item .dot {
  flex-shrink: 0;
}
.sched-group__btn {
  gap: 6px;
  color: var(--text-2);
}
.sched-group__label {
  color: var(--text);
  font-weight: var(--fw-medium);
}

/* Segmented control rendered by the server (no JS thumb → survives morph swaps) */
.sched-seg {
  display: inline-flex;
  flex-shrink: 0;
  gap: 2px;
  padding: 2px;
  border-radius: 9px;
  background: var(--fill-1);
}
.sched-seg__item {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 52px;
  height: calc(var(--control-h-sm) - 4px);
  padding: 0 12px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  white-space: nowrap;
  transition:
    background-color var(--dur-2) var(--ease-out),
    color var(--dur-1) ease,
    box-shadow var(--dur-2) var(--ease-out);
}
.sched-seg__item:hover {
  color: var(--text);
}
.sched-seg__item[aria-current="page"],
.sched-seg__item[aria-pressed="true"] {
  background: var(--surface);
  box-shadow:
    0 0 0 0.5px var(--card-ring),
    var(--shadow-sm);
  color: var(--text);
}

.sched-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

/* -- Calendar: layout ------------------------------------------------------------------------------ */
.cal-layout {
  display: grid;
  gap: var(--space-4);
  min-width: 0;
}
.cal-main {
  min-width: 0;
}
.cal,
.cal-tray {
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow:
    0 0 0 1px var(--card-ring),
    var(--shadow-sm);
}
.cal {
  display: none; /* phones use the agenda */
  overflow: hidden;
}
.cal-tray {
  display: none;
}
.cal-tray-toggle {
  display: none;
}
@media (min-width: 768px) {
  .cal {
    display: flex;
    flex-direction: column;
  }
  .cal-tray-toggle {
    display: inline-flex;
  }
  .cal-layout.is-tray-open .cal-tray {
    display: flex;
    flex-direction: column;
  }
}
@media (min-width: 1280px) {
  .cal-layout.is-tray-open {
    grid-template-columns: minmax(0, 1fr) 272px;
    align-items: start;
  }
  .cal-layout.is-tray-open .cal-tray {
    position: sticky;
    top: calc(var(--topbar-h) + 56px + var(--safe-top));
    max-height: var(--sched-fill, 640px);
  }
}

/* Month grid */
.cal__weekdays,
.cal__week {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}
.cal__weekdays {
  border-bottom: 1px solid var(--line);
}
.cal__weekday {
  padding: 8px 10px 7px;
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: 0.01em;
  text-align: left;
}
.cal__weekday abbr {
  text-decoration: none;
  cursor: default;
}
.cal__weekday.is-weekend {
  color: var(--text-3);
}
.cal__body {
  display: grid;
  grid-template-rows: repeat(var(--weeks, 5), minmax(118px, 1fr));
  min-height: max(560px, var(--sched-fill, 0px));
}
.cal__week + .cal__week {
  border-top: 1px solid var(--line);
}

.cal-day {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 6px 6px 8px;
  transition: background-color var(--dur-1) ease;
}
.cal-day + .cal-day,
.cal-wday + .cal-wday {
  box-shadow: inset 1px 0 0 var(--line);
}
.cal-day.is-weekend,
.cal-wday.is-weekend {
  background: color-mix(in srgb, var(--fill-1) 55%, transparent);
}
.cal-day.is-outside {
  background: color-mix(in srgb, var(--surface-sunken) 55%, transparent);
}
.cal-day.is-outside .cal-day__num {
  color: var(--text-3);
  font-weight: var(--fw-medium);
}
.cal-day.is-drop-target,
.cal-wday.is-drop-target {
  background: var(--accent-softer);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 45%, transparent);
}
.cal-day__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-height: 24px;
}
.cal-day__num {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cal-day.is-today .cal-day__num,
.cal-wday.is-today .cal-wday__num {
  background: var(--accent);
  color: var(--text-on-accent);
}
.cal-day__add {
  display: inline-grid;
  place-items: center;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-2);
  opacity: 0;
  transition:
    opacity var(--dur-1) ease,
    background-color var(--dur-1) ease;
}
.cal-day__add:hover {
  background: var(--fill-2);
  color: var(--text);
}
.cal-day__add:focus-visible,
.cal-day:hover .cal-day__add,
.cal-wday:hover .cal-day__add,
.cal-day:focus-within .cal-day__add,
.cal-wday:focus-within .cal-day__add {
  opacity: 1;
}
@media (hover: none) {
  .cal-day__add {
    opacity: 0.7;
  }
}
.cal-day__list {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  min-height: 22px;
}
.cal-day[data-clickable] {
  cursor: cell;
}
.cal-day__more {
  align-self: flex-start;
  height: 20px;
  margin-top: -1px;
  padding: 0 7px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}
.cal-day__more:hover,
.cal-day__more[aria-expanded="true"] {
  background: var(--fill-2);
  color: var(--text);
}

/* Chips */
.cal-chip {
  position: relative;
  display: flex;
  flex-shrink: 0;
  align-items: center;
  gap: 6px;
  min-width: 0;
  height: 23px;
  padding: 0 7px;
  border-radius: 7px;
  background: color-mix(in srgb, var(--tone) calc(var(--tint) * 0.65), var(--surface));
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.2;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition:
    background-color var(--dur-1) ease,
    box-shadow var(--dur-2) var(--ease-out),
    opacity var(--dur-2) ease,
    transform var(--dur-2) var(--ease-out);
}
.cal-chip[data-movable] {
  cursor: grab;
}
.cal-chip:hover {
  background: color-mix(in srgb, var(--tone) 22%, var(--surface));
}
.cal-chip:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px var(--accent),
    0 0 0 5px var(--focus-ring);
}
.cal-chip.is-current {
  box-shadow: 0 0 0 2px var(--accent);
}
.cal-chip__dot {
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--tone);
}
.cal-chip__icon {
  flex-shrink: 0;
}
.cal-chip__icon--done {
  color: var(--success);
}
.cal-chip__icon--milestone {
  color: var(--c-orange);
}
.cal-chip__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-chip.is-milestone .cal-chip__title {
  font-weight: var(--fw-semibold);
}
.cal-chip.is-overdue .cal-chip__title {
  color: var(--danger-ink);
}
.cal-chip.is-done {
  background: color-mix(in srgb, var(--fill-1) 70%, transparent);
  color: var(--text-3);
}
.cal-chip.is-done .cal-chip__title {
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, currentColor 55%, transparent);
}
.cal-chip.is-saving {
  opacity: 0.6;
}
@media (prefers-reduced-motion: no-preference) {
  .cal-chip.is-landed {
    animation: cal-land var(--dur-3) var(--ease-spring);
  }
  @keyframes cal-land {
    from {
      transform: scale(0.94);
    }
  }
  .cal-chip.is-shake {
    animation: cal-shake 360ms var(--ease-out);
  }
  @keyframes cal-shake {
    20%,
    60% {
      transform: translateX(-3px);
    }
    40%,
    80% {
      transform: translateX(3px);
    }
  }
}
/* Week-view cards */
.cal-chip--card {
  flex-wrap: wrap;
  align-items: flex-start;
  height: auto;
  padding: 7px 8px 6px;
  border-radius: 9px;
  row-gap: 5px;
}
.cal-chip--card .cal-chip__dot,
.cal-chip--card .cal-chip__icon {
  margin-top: 4px;
}
.cal-chip--card .cal-chip__title {
  flex-basis: calc(100% - 16px);
  display: -webkit-box;
  font-size: var(--fs-sm);
  line-height: 1.3;
  white-space: normal;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow-wrap: anywhere;
}
.cal-chip__meta {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  min-height: 20px;
  padding-left: 13px;
}
.cal-chip__avatar {
  margin-left: auto;
}
/* Drag & drop (SortableJS fallback mode) */
.cal-chip.sortable-ghost {
  background: var(--accent-softer);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 50%, transparent);
  opacity: 1;
}
.cal-chip.sortable-ghost > * {
  visibility: hidden;
}
.cal-chip.sortable-fallback,
.cal-chip.sortable-drag {
  z-index: var(--z-overlay);
  background: color-mix(in srgb, var(--tone) 16%, var(--surface));
  box-shadow:
    0 0 0 1px var(--card-ring),
    var(--shadow-lg) !important;
  transform: rotate(-1.5deg) scale(1.03);
  cursor: grabbing;
}
.schedule.is-dragging,
.schedule.is-dragging * {
  cursor: grabbing !important;
}

/* "+N more" popover */
.cal-more {
  width: 300px;
  padding: 8px;
}
.cal-more__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 2px 8px 6px;
}
.cal-more__title {
  font-size: var(--fs-md);
  font-weight: var(--fw-semibold);
}
.cal-more__title::first-letter {
  text-transform: uppercase;
}
.cal-more__list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.cal-more__item {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.cal-more__item .cal-chip {
  flex: 1 1 auto;
  height: 28px;
  font-size: var(--fs-sm);
}
.cal-more__move {
  flex-shrink: 0;
  color: var(--text-2);
}

/* Week view */
.cal--week .cal__week--days {
  min-height: max(520px, var(--sched-fill, 0px));
}
.cal-wday {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
  padding: 10px 8px 12px;
}
.cal-wday__head {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  column-gap: 4px;
  padding: 0 2px 6px;
  border-bottom: 1px solid var(--line);
}
.cal-wday__name {
  grid-column: 1;
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: capitalize;
}
.cal-wday__num {
  grid-column: 1;
  justify-self: start;
  display: inline-grid;
  place-items: center;
  min-width: 32px;
  height: 32px;
  margin-left: -4px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  font-family: var(--font-display);
  font-size: var(--fs-title-3);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-snug);
}
.cal-wday .cal-day__add {
  grid-column: 2;
  grid-row: 1 / span 2;
}
.cal-wday__list {
  gap: 6px;
}

/* Unscheduled tray (≥ 768px) */
.cal-tray {
  gap: var(--space-2);
  min-width: 0;
  padding: var(--space-3);
}
.cal-tray__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}
.cal-tray__title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--fs-lg);
  font-weight: var(--fw-semibold);
}
.cal-tray__hint,
.cal-tray__more {
  color: var(--text-2);
  font-size: var(--fs-xs);
  line-height: var(--lh-normal);
}
.cal-tray__list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(200px, 100%), 1fr));
  align-content: start;
  gap: 4px;
  min-height: 56px;
  padding: 6px;
  overflow: auto;
  overscroll-behavior: contain;
  border-radius: var(--radius-md);
  background: var(--surface-sunken);
  transition:
    background-color var(--dur-2) ease,
    box-shadow var(--dur-2) ease;
}
.cal-tray__list.is-drop-target {
  background: var(--accent-softer);
  box-shadow: inset 0 0 0 1.5px color-mix(in srgb, var(--accent) 45%, transparent);
}
.cal-tray__list .cal-chip {
  height: 28px;
  font-size: var(--fs-sm);
}
.cal-tray__empty {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: var(--fs-sm);
}
.cal-tray__empty .icon {
  color: var(--success);
}
@media (min-width: 1280px) {
  .cal-tray__list {
    grid-template-columns: minmax(0, 1fr);
    flex: 1 1 auto;
  }
}

/* -- Phone agenda ---------------------------------------------------------------------------------- */
.cal-agenda {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}
@media (min-width: 768px) {
  .cal-agenda {
    display: none;
  }
}
.cal-agenda__day {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow:
    0 0 0 1px var(--card-ring),
    var(--shadow-sm);
}
.cal-agenda__date {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 52px 10px 16px;
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  font-weight: var(--fw-regular);
  letter-spacing: 0;
}
.cal-agenda__num {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--fill-1);
  font-family: var(--font-display);
  font-size: var(--fs-xl);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
}
.cal-agenda__num--icon {
  color: var(--text-2);
}
.cal-agenda__day.is-today .cal-agenda__num {
  background: var(--accent);
  color: var(--text-on-accent);
}
.cal-agenda__name {
  display: flex;
  flex-direction: column;
  min-width: 0;
  font-weight: var(--fw-semibold);
  line-height: 1.25;
}
.cal-agenda__wd::first-letter {
  text-transform: uppercase;
}
.cal-agenda__month {
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-regular);
}
.cal-agenda__add {
  position: absolute;
  top: 12px;
  right: 10px;
  color: var(--accent);
}
.cal-agenda__list {
  margin: 0;
  padding: 0;
  list-style: none;
}
.cal-agenda__empty {
  padding: 4px 16px 14px 64px;
  color: var(--text-3);
  font-size: var(--fs-sm);
}
.cal-agenda__none {
  padding: var(--space-8) 0;
}
.cal-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 8px 8px 8px 16px;
  box-shadow: inset 0 1px 0 var(--line);
}
.cal-row__bar {
  align-self: stretch;
  width: 4px;
  flex-shrink: 0;
  border-radius: 2px;
  background: var(--tone);
}
.cal-row__main {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 2px 0;
}
.cal-row__main::after {
  content: "";
  position: absolute;
  inset: 0;
}
.cal-row__main:focus-visible {
  outline: none;
}
.cal-row:has(.cal-row__main:focus-visible) {
  box-shadow: inset 0 0 0 2px var(--accent);
}
.cal-row .avatar,
.cal-row__move {
  position: relative;
  z-index: 1;
}
.cal-row__title {
  display: -webkit-box;
  overflow: hidden;
  font-size: var(--fs-lg);
  font-weight: var(--fw-medium);
  line-height: 1.3;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow-wrap: anywhere;
}
.cal-row__title .icon {
  margin-right: 2px;
  vertical-align: -2px;
}
.cal-row__meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 8px;
  color: var(--text-2);
  font-size: var(--fs-xs);
}
.cal-row__status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}
.cal-row__status::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tone);
}
.cal-row__overdue {
  color: var(--danger-ink);
  font-weight: var(--fw-medium);
}
.cal-row__move {
  color: var(--text-2);
}
.cal-row.is-done .cal-row__title {
  color: var(--text-3);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, currentColor 50%, transparent);
}
.cal-row.is-done .cal-row__bar {
  opacity: 0.4;
}

/* -- Timeline -------------------------------------------------------------------------------------- */
.tl,
.cal-layout {
  --tint: 20%;
  --tint-strong: 46%;
}
:root[data-theme="dark"] :is(.tl, .cal-layout) {
  --tint: 30%;
  --tint-strong: 52%;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) :is(.tl, .cal-layout) {
    --tint: 30%;
    --tint-strong: 52%;
  }
}
.tl {
  --day: 12px;
  --left-w: 148px;
  --row-h: 36px;
  --bar-h: 22px;
  --head-h: 52px;
  --ms: 15px;
  --weekend-fill: color-mix(in srgb, var(--fill-1) 70%, transparent);
  position: relative;
  min-width: 0;
  overflow: hidden;
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow:
    0 0 0 1px var(--card-ring),
    var(--shadow-sm);
}
.schedule[data-zoom="day"] .tl {
  --day: 32px;
}
.schedule[data-zoom="month"] .tl {
  --day: 4px;
}
@media (max-width: 767px) {
  .schedule[data-zoom="auto"] .tl {
    --day: 4px;
  }
}
@media (min-width: 768px) {
  .tl {
    --left-w: 232px;
    --row-h: 40px;
    --bar-h: 26px;
    --head-h: 56px;
  }
}
@media (min-width: 1280px) {
  .tl {
    --left-w: 280px;
  }
}
.tl-scroll {
  position: relative;
  max-height: max(320px, var(--sched-fill, calc(100dvh - 240px)));
  overflow: auto;
  overscroll-behavior: contain;
  outline: none;
}
.tl-scroll:focus-visible {
  box-shadow: inset 0 0 0 2px var(--accent);
}
.tl-canvas {
  position: relative;
  width: calc(var(--left-w) + var(--days) * var(--day));
  min-width: 100%;
}

/* Header */
.tl-headrow {
  position: sticky;
  top: 0;
  z-index: 6;
  display: flex;
  height: var(--head-h);
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.tl-corner {
  position: sticky;
  left: 0;
  z-index: 7;
  display: flex;
  flex: none;
  align-items: flex-end;
  gap: 8px;
  width: var(--left-w);
  padding: 0 12px 9px 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.tl-head {
  position: relative;
  flex: none;
  width: calc(var(--days) * var(--day));
}
.tl-head__set {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
}
.schedule[data-zoom="day"] .tl-head__set--day,
.schedule[data-zoom="week"] .tl-head__set--week,
.schedule[data-zoom="auto"] .tl-head__set--week,
.schedule[data-zoom="month"] .tl-head__set--month {
  display: flex;
}
@media (max-width: 767px) {
  .schedule[data-zoom="auto"] .tl-head__set--week {
    display: none;
  }
  .schedule[data-zoom="auto"] .tl-head__set--month {
    display: flex;
  }
}
.tl-head__row {
  position: relative;
  flex: 1 1 auto;
}
.tl-head__row--top {
  flex: 0 0 24px;
  border-bottom: 1px solid var(--line);
}
.tl-hcell {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--x) * var(--day));
  width: calc(var(--w) * var(--day));
  display: flex;
  align-items: center;
  overflow: clip;
  box-shadow: inset 1px 0 0 var(--line);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  white-space: nowrap;
}
.tl-hcell__label {
  position: sticky;
  left: calc(var(--left-w) + 8px);
  padding: 0 8px;
}
.tl-hcell__label::first-letter {
  text-transform: uppercase;
}
.tl-hcell--sub {
  color: var(--text-2);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
}
.tl-hday {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--x) * var(--day));
  width: var(--day);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  line-height: 1;
}
.tl-hday__wd {
  font-size: 9px;
  font-weight: var(--fw-medium);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  opacity: 0.8;
}
.tl-hday__n {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 18px;
  border-radius: var(--radius-full);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.tl-hday.is-weekend {
  background: var(--weekend-fill);
  color: var(--text-3);
}
.tl-hday.is-today {
  color: var(--accent-ink);
}
.tl-hday.is-today .tl-hday__n {
  background: var(--accent);
  color: var(--text-on-accent);
}
.tl-hcell.is-today {
  color: var(--accent-ink);
  font-weight: var(--fw-semibold);
}

/* Body: background (weekends, month lines, today) */
.tl-body {
  position: relative;
}
.tl-bg {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--left-w);
  z-index: 0;
  width: calc(var(--days) * var(--day));
  pointer-events: none;
  background-image: linear-gradient(
    90deg,
    transparent 0 calc(var(--day) * 5),
    var(--weekend-fill) calc(var(--day) * 5) calc(var(--day) * 7)
  );
  background-position: calc(var(--wk-shift) * var(--day)) 0;
  background-size: calc(var(--day) * 7) 100%;
}
.schedule[data-zoom="day"] .tl-bg {
  background-image:
    linear-gradient(
      90deg,
      transparent 0 calc(var(--day) * 5),
      var(--weekend-fill) calc(var(--day) * 5) calc(var(--day) * 7)
    ),
    linear-gradient(90deg, color-mix(in srgb, var(--line) 70%, transparent) 0 1px, transparent 1px);
  background-position:
    calc(var(--wk-shift) * var(--day)) 0,
    0 0;
  background-size:
    calc(var(--day) * 7) 100%,
    var(--day) 100%;
}
.schedule[data-zoom="month"] .tl-bg {
  background-image: none;
}
@media (max-width: 767px) {
  .schedule[data-zoom="auto"] .tl-bg {
    background-image: none;
  }
}
.tl-mline {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc(var(--x) * var(--day));
  width: 1px;
  background: var(--line);
}
.tl-today {
  position: absolute;
  top: 0;
  bottom: 0;
  left: calc((var(--x) + 0.5) * var(--day) - 1px);
  z-index: 1;
  width: 2px;
  border-radius: 1px;
  background: var(--accent);
  opacity: 0.85;
}
.tl-today::before {
  content: "";
  position: absolute;
  top: -1px;
  left: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
}

/* Rows */
.tl-row,
.tl-group__head {
  position: relative;
  display: flex;
  height: var(--row-h);
}
.tl-row {
  box-shadow: inset 0 -1px 0 color-mix(in srgb, var(--line) 60%, transparent);
}
.tl-cell {
  position: sticky;
  left: 0;
  z-index: 3;
  display: flex;
  flex: none;
  align-items: center;
  gap: 8px;
  width: var(--left-w);
  min-width: 0;
  padding: 0 6px 0 14px;
  border-right: 1px solid var(--line);
  background: var(--surface);
}
.tl-lane {
  position: relative;
  flex: none;
  width: calc(var(--days) * var(--day));
}
.tl-row:hover .tl-cell {
  background: linear-gradient(var(--fill-1), var(--fill-1)), var(--surface);
}
.tl-row:hover .tl-lane {
  background: color-mix(in srgb, var(--fill-1) 60%, transparent);
}
.tl-row.is-current .tl-cell {
  background: linear-gradient(var(--accent-soft), var(--accent-soft)), var(--surface);
}
.tl-cell__icon {
  flex-shrink: 0;
}
.tl-cell__icon--done {
  color: var(--success);
}
.tl-cell__icon--milestone {
  color: var(--c-orange);
}
.tl-cell__title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tl-cell__title:hover {
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.tl-row.is-done .tl-cell__title {
  color: var(--text-3);
  text-decoration: line-through;
  text-decoration-color: color-mix(in srgb, currentColor 50%, transparent);
}
.tl-cell__avatar {
  flex-shrink: 0;
}
.tl-cell__dates {
  flex-shrink: 0;
  margin-left: -4px;
  color: var(--text-2);
  opacity: 0;
}
.tl-row:hover .tl-cell__dates,
.tl-cell__dates:focus-visible,
.tl-group--unscheduled .tl-cell__dates {
  opacity: 1;
}
@media (hover: none) {
  .tl-cell__dates {
    opacity: 1;
  }
}
@media (max-width: 767px) {
  .tl-cell {
    gap: 6px;
    padding-left: 10px;
  }
  .tl-cell__avatar {
    display: none;
  }
  .tl-cell__title {
    font-size: var(--fs-xs);
  }
}

/* Group headers */
.tl-group__head {
  z-index: 2;
}
.tl-cell--group {
  padding-left: 6px;
  background: linear-gradient(var(--fill-1), var(--fill-1)), var(--surface);
}
.tl-lane--group {
  background: color-mix(in srgb, var(--fill-1) 70%, transparent);
}
.tl-group__toggle {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  gap: 8px;
  min-width: 0;
  height: 30px;
  padding: 0 8px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  text-align: left;
}
.tl-group__toggle:hover {
  background: var(--fill-1);
}
.tl-group__chev {
  flex-shrink: 0;
  color: var(--text-3);
  transition: transform var(--dur-2) var(--ease-out);
}
.tl-group.is-collapsed .tl-group__chev {
  transform: rotate(-90deg);
}
.tl-group.is-collapsed .tl-row {
  display: none;
}
.tl-group__label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tl-group__count {
  color: var(--text-3);
  font-weight: var(--fw-medium);
  font-variant-numeric: tabular-nums;
}
.tl-lane__hint {
  position: sticky;
  left: calc(var(--left-w) + 12px);
  display: inline-flex;
  align-items: center;
  height: 100%;
  padding: 0 12px;
  color: var(--text-3);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

/* Bars */
.tl-bar {
  position: absolute;
  top: calc((var(--row-h) - var(--bar-h)) / 2);
  left: calc(var(--x) * var(--day));
  z-index: 2;
  display: flex;
  align-items: center;
  width: max(calc(var(--w) * var(--day)), 6px);
  height: var(--bar-h);
  border-radius: 7px;
  background: color-mix(in srgb, var(--tone) var(--tint), var(--surface));
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tone) 42%, transparent);
  color: var(--text);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition:
    box-shadow var(--dur-2) var(--ease-out),
    opacity var(--dur-2) ease;
}
.tl-bar[data-movable] {
  cursor: grab;
}
.tl-bar:hover {
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--tone) 60%, transparent),
    var(--shadow-sm);
}
.tl-bar:focus-visible {
  outline: none;
  box-shadow:
    0 0 0 2px var(--accent),
    0 0 0 5px var(--focus-ring);
}
.tl-bar.is-current {
  box-shadow:
    0 0 0 2px var(--accent),
    var(--shadow-sm);
}
.tl-bar__fill {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--p, 0%);
  border-radius: inherit;
  background: color-mix(in srgb, var(--tone) var(--tint-strong), var(--surface));
  pointer-events: none;
}
.tl-bar__label {
  position: sticky;
  left: calc(var(--left-w) + 2px);
  z-index: 1;
  min-width: 0;
  overflow: hidden;
  padding: 0 9px;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}
.tl-bar__check {
  margin-right: 4px;
  vertical-align: -1px;
  color: var(--success);
}
/* Narrow bars (per zoom): the label moves outside, to the right */
.schedule[data-zoom="day"] .tl-bar[data-narrow~="day"] .tl-bar__label,
.schedule[data-zoom="week"] .tl-bar[data-narrow~="week"] .tl-bar__label,
.schedule[data-zoom="auto"] .tl-bar[data-narrow~="week"] .tl-bar__label,
.schedule[data-zoom="month"] .tl-bar[data-narrow~="month"] .tl-bar__label {
  position: absolute;
  left: 100%;
  max-width: 260px;
  padding-left: 8px;
  overflow: visible;
  color: var(--text-2);
}
@media (max-width: 767px) {
  .schedule[data-zoom="auto"] .tl-bar[data-narrow~="month"] .tl-bar__label {
    position: absolute;
    left: 100%;
    max-width: 260px;
    padding-left: 8px;
    overflow: visible;
    color: var(--text-2);
  }
}
.tl-bar__handle {
  position: absolute;
  top: -2px;
  bottom: -2px;
  z-index: 3;
  width: 12px;
  cursor: ew-resize;
  touch-action: none;
}
.tl-bar__handle--start {
  left: -5px;
}
.tl-bar__handle--end {
  right: -5px;
}
.tl-bar__handle::after {
  content: "";
  position: absolute;
  top: 7px;
  bottom: 7px;
  left: 5px;
  width: 2px;
  border-radius: 1px;
  background: var(--tone-ink);
  opacity: 0;
  transition: opacity var(--dur-1) ease;
}
.tl-bar:hover .tl-bar__handle::after,
.tl-bar.is-dragging .tl-bar__handle::after {
  opacity: 0.55;
}
.tl-bar.is-done {
  opacity: 0.62;
}
.tl-bar.is-overdue {
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--tone) 42%, transparent),
    inset -3px 0 0 var(--c-red);
}
.tl-bar.is-clipped-start {
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}
.tl-bar.is-clipped-end {
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}
.tl-bar--open {
  box-shadow: inset 1px 0 0 color-mix(in srgb, var(--tone) 60%, transparent);
  -webkit-mask-image: linear-gradient(90deg, var(--text) 55%, transparent);
  mask-image: linear-gradient(90deg, var(--text) 55%, transparent);
}
.tl-bar--open .tl-bar__label {
  overflow: visible;
}
.tl-bar--milestone {
  left: calc((var(--x) + 0.5) * var(--day) - var(--ms) / 2);
  top: calc((var(--row-h) - var(--ms)) / 2);
  width: var(--ms);
  height: var(--ms);
  background: none;
  box-shadow: none;
}
.tl-bar--milestone:hover {
  box-shadow: none;
}
.tl-bar__diamond {
  position: absolute;
  inset: 1px;
  border-radius: 3px;
  background: var(--tone);
  box-shadow: 0 0 0 2px var(--surface);
  transform: rotate(45deg);
  transition: transform var(--dur-2) var(--ease-spring);
}
.tl-bar--milestone:hover .tl-bar__diamond {
  transform: rotate(45deg) scale(1.15);
}
.tl-bar--milestone .tl-bar__label {
  position: absolute;
  left: 100%;
  max-width: 260px;
  padding-left: 9px;
  overflow: visible;
  font-weight: var(--fw-semibold);
}
.tl-bar.is-dragging {
  z-index: 5;
  box-shadow:
    inset 0 0 0 1px color-mix(in srgb, var(--tone) 70%, transparent),
    var(--shadow-lg);
  cursor: grabbing;
}
.tl-bar.is-saving {
  opacity: 0.7;
}
@media (prefers-reduced-motion: no-preference) {
  .tl-bar.is-reverting {
    transition:
      left var(--dur-3) var(--ease-out),
      width var(--dur-3) var(--ease-out);
  }
}
.tl-drag-label {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  z-index: 6;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--tooltip-bg);
  color: var(--tooltip-fg);
  font-size: var(--fs-2xs);
  font-weight: var(--fw-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  pointer-events: none;
}

/* Unscheduled lanes: a ghost bar follows the pointer; click schedules on that day */
.tl-lane--place {
  cursor: pointer;
}
.tl-ghost {
  position: absolute;
  top: calc((var(--row-h) - var(--bar-h)) / 2);
  left: calc(var(--gx, 0) * var(--day));
  width: max(var(--day), 10px);
  height: var(--bar-h);
  border: 1.5px dashed color-mix(in srgb, var(--accent) 70%, transparent);
  border-radius: 7px;
  background: var(--accent-softer);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-1) ease;
}
.tl-lane--place.is-hovering .tl-ghost {
  opacity: 1;
}

.tl-empty {
  position: sticky;
  left: 0;
  width: min(100%, 560px);
  padding: var(--space-8) var(--space-4);
}

/* Tooltip (one element, created by schedule.js) */
.tl-tip {
  position: fixed;
  z-index: var(--z-tooltip);
  max-width: 300px;
  padding: 8px 11px 9px;
  border-radius: var(--radius-md);
  background: var(--tooltip-bg);
  box-shadow: var(--shadow-md);
  color: var(--tooltip-fg);
  font-size: var(--fs-xs);
  line-height: 1.35;
  pointer-events: none;
  opacity: 0;
  transform: translateY(2px);
  transition:
    opacity var(--dur-1) ease,
    transform var(--dur-2) var(--ease-out);
}
.tl-tip.is-visible {
  opacity: 1;
  transform: none;
}
.tl-tip__title {
  display: block;
  margin-bottom: 2px;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
}
.tl-tip__line {
  display: block;
  opacity: 0.82;
  font-variant-numeric: tabular-nums;
}

/* -- Date popover ---------------------------------------------------------------------------------- */
.sched-pop {
  width: min(320px, calc(100vw - 16px));
  padding: 14px;
}
.sched-pop__form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.sched-pop__head {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.sched-pop__eyebrow {
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
}
.sched-pop__title {
  display: -webkit-box;
  overflow: hidden;
  font-weight: var(--fw-semibold);
  line-height: 1.3;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.sched-pop__fields {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(128px, 1fr));
  gap: 10px;
}
.sched-pop__field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.sched-pop__label {
  color: var(--text-2);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
}
.sched-pop__field .input {
  width: 100%;
  min-width: 0;
}
.sched-pop__error {
  color: var(--danger-ink);
  font-size: var(--fs-xs);
}
.sched-pop__actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* -- Small screens --------------------------------------------------------------------------------- */
@media (max-width: 519px) {
  .sched-toggle__label {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
  }
  .sched-toggle {
    padding-inline: 10px;
  }
}
@media (max-width: 767px) {
  .tl-cell__dates {
    display: none;
  }
  .tl-group--unscheduled .tl-cell__dates {
    display: inline-flex;
  }
  .schedule {
    gap: var(--space-3);
  }
  .sched-toolbar__lead {
    flex-basis: 100%;
    justify-content: space-between;
  }
  .schedule--calendar .sched-toolbar__lead {
    flex-direction: row-reverse;
  }
  .sched-title {
    font-size: var(--fs-xl);
  }
  .sched-toolbar__tools {
    flex: 1 1 auto;
  }
  .sched-seg {
    margin-left: auto;
  }
  .sched-seg__item {
    min-width: 0;
    padding: 0 10px;
  }
}

/* Narrow month cells: titles first (priority stays visible in week cards, rows and the drawer) */
@media (max-width: 1279px) {
  .cal--month .cal-chip .priority {
    display: none;
  }
}
