/*
 * Gantt timeline.
 *
 * One scroll container with a frozen label column (sticky left) and a frozen
 * two-tier header (sticky top). Labels and bars are the same DOM rows, so the
 * panes cannot drift and there is no scroll-sync JS.
 *
 * Zoom is --gantt-period-w alone. Bar geometry is percentage-based against the
 * track width, so changing granularity never touches a bar.
 */

.gantt {
  --gantt-label-w: 260px;
  --gantt-row-h: 38px;
  --gantt-bar-h: 18px;
  --gantt-head-h: 46px;
  --gantt-max-h: 70vh;

  position: relative;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background: var(--bg-primary);
  overflow: hidden;
}

.gantt--compact {
  --gantt-label-w: 190px;
  --gantt-row-h: 26px;
  --gantt-bar-h: 13px;
  --gantt-head-h: 38px;
  --gantt-max-h: 340px;
}

/* The single scroll container. Both axes live here so sticky works on both. */
.gantt-scroll {
  overflow: auto;
  max-height: var(--gantt-max-h);
  scrollbar-gutter: stable;
}

.gantt-scroll:focus-visible {
  outline: 2px solid var(--vmdo-teal);
  outline-offset: -2px;
}

.gantt-canvas {
  position: relative;
  width: calc(var(--gantt-label-w) + var(--gantt-periods) * var(--gantt-period-w));
  min-width: 100%;
}

/* ── Header ───────────────────────────────────────────────────────────────── */

.gantt-headrow {
  position: sticky;
  top: 0;
  z-index: 3;
  display: flex;
  height: var(--gantt-head-h);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
}

.gantt-corner {
  position: sticky;
  left: 0;
  z-index: 4;
  flex: 0 0 var(--gantt-label-w);
  display: flex;
  align-items: flex-end;
  padding: 0 var(--spacing-sm) 6px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.gantt-header {
  flex: 0 0 auto;
  width: calc(var(--gantt-periods) * var(--gantt-period-w));
  display: flex;
  flex-direction: column;
}

.gantt-header-years,
.gantt-header-periods {
  display: flex;
}

.gantt-header-years {
  height: 20px;
}

.gantt-year {
  width: calc(var(--span) * var(--gantt-period-w));
  flex: 0 0 auto;
  border-left: 1px solid var(--border-color);
  padding-left: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  overflow: hidden;
  white-space: nowrap;
}

.gantt-period {
  width: var(--gantt-period-w);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  color: var(--text-muted);
  border-left: 1px solid var(--border-color);
}

/* ── Rows ─────────────────────────────────────────────────────────────────── */

.gantt-row {
  display: flex;
  height: var(--gantt-row-h);
  border-bottom: 1px solid var(--border-color);
}

.gantt-row:last-child {
  border-bottom: none;
}

.gantt-row:hover .gantt-track {
  background-color: rgba(0, 156, 189, 0.045);
}

.gantt-row:hover .gantt-label {
  background: var(--bg-secondary);
}

.gantt-label {
  position: sticky;
  left: 0;
  z-index: 2;
  flex: 0 0 var(--gantt-label-w);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 1px;
  padding: 0 var(--spacing-sm);
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  overflow: hidden;
}

.gantt-label--dim .gantt-label-name {
  color: var(--text-muted);
}

.gantt-label-main {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.gantt-label-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-primary);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

a.gantt-label-name:hover {
  color: var(--link-color);
  text-decoration: underline;
}

.gantt-label-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gantt--compact .gantt-label-name {
  font-size: 0.75rem;
}

/* A 26px row cannot hold two lines. Showing the meta line here clips it
   against the row border and reads as a rendering fault. */
.gantt--compact .gantt-label-meta {
  display: none;
}

.gantt-nodate-chip {
  flex: 0 0 auto;
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

/* Gridlines are a background gradient, so period count costs zero DOM. */
.gantt-track {
  position: relative;
  flex: 0 0 auto;
  width: calc(var(--gantt-periods) * var(--gantt-period-w));
  background-image: repeating-linear-gradient(
    to right,
    var(--border-color) 0 1px,
    transparent 1px var(--gantt-period-w)
  );
}

/* ── Bars ─────────────────────────────────────────────────────────────────── */

.gantt-bar {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: var(--gantt-bar-h);
  min-width: 4px;
  border-radius: 3px;
  background: var(--bar-color);
  color: var(--bar-ink);
  display: flex;
  align-items: center;
  padding: 0 5px;
  overflow: hidden;
  transition: filter 0.12s ease;
}

.gantt-bar:hover {
  filter: brightness(1.08);
}

.gantt-bar-label {
  font-size: 0.65rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.gantt--compact .gantt-bar-label {
  display: none;
}

/* Scheduled-but-not-actual reads as hatched rather than solid. */
.gantt-bar--scheduled {
  background-image: repeating-linear-gradient(
    135deg,
    rgba(255, 255, 255, 0.32) 0 4px,
    transparent 4px 8px
  );
}

/* An unknown endpoint fades out. It never terminates on a guessed date. */
.gantt-bar--open-end {
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(to right, #000 calc(100% - 26px), transparent 100%);
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.gantt-bar--open-start {
  -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(to left, #000 calc(100% - 26px), transparent 100%);
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.gantt-bar--open-start.gantt-bar--open-end {
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 26px, #000 calc(100% - 26px), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 26px, #000 calc(100% - 26px), transparent 100%);
}

/* The scheduled hairline underlay: "we are two months behind" at a glance. */
.gantt-bar--underlay {
  height: 3px;
  top: calc(50% + var(--gantt-bar-h) / 2 + 3px);
  transform: none;
  opacity: 0.55;
  border-radius: 2px;
  padding: 0;
}

.gantt-bar--underlay .gantt-bar-label {
  display: none;
}

/* Coarse design/construction shown beneath real phase bars. */
.gantt-bar--secondary {
  height: 3px;
  top: calc(50% + var(--gantt-bar-h) / 2 + 3px);
  transform: none;
  opacity: 0.35;
  border-radius: 2px;
  padding: 0;
}

.gantt-bar--secondary .gantt-bar-label {
  display: none;
}

.gantt-bar--current {
  box-shadow: 0 0 0 1px rgba(17, 24, 32, 0.18);
}

/* Point milestones are diamonds. Drawing them as spans would assert a duration
   the data does not contain. */
.gantt-diamond {
  position: absolute;
  top: 50%;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  transform: translateY(-50%) rotate(45deg);
  background: var(--bar-color);
  border: 1px solid var(--bg-primary);
  border-radius: 1px;
}

/* ── Today ────────────────────────────────────────────────────────────────── */

.gantt-today {
  position: absolute;
  top: var(--gantt-head-h);
  bottom: 0;
  width: 2px;
  margin-left: -1px;
  left: calc(
    var(--gantt-label-w) +
    (var(--gantt-periods) * var(--gantt-period-w)) * var(--gantt-today-fraction)
  );
  background: var(--vmdo-gold);
  /* The halo keeps the marker readable where it crosses a gold phase bar. */
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85);
  z-index: 1;
  pointer-events: none;
}

.gantt-today::before {
  content: '';
  position: absolute;
  top: -4px;
  left: -3px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--vmdo-gold);
}

/* ── Footer and empty state ───────────────────────────────────────────────── */

.gantt-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--spacing-sm);
  flex-wrap: wrap;
  padding: 6px var(--spacing-sm);
  border-top: 1px solid var(--border-color);
  background: var(--bg-secondary);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.gantt-footer-link {
  color: var(--link-color);
  text-decoration: none;
}

.gantt-footer-link:hover {
  text-decoration: underline;
}

.gantt-empty {
  padding: var(--spacing-lg);
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

@media (prefers-reduced-motion: reduce) {
  .gantt-bar {
    transition: none;
  }
}

/* ── Print ────────────────────────────────────────────────────────────────── */

@media print {
  .gantt {
    border-color: #999;
    break-inside: auto;
  }

  /* Unroll the horizontal scroller and fit the whole domain onto the page. */
  .gantt-scroll {
    overflow: visible;
    max-height: none;
  }

  .gantt-canvas {
    width: 100% !important;
  }

  .gantt-track,
  .gantt-header {
    width: auto !important;
    flex: 1 1 auto !important;
  }

  .gantt-period,
  .gantt-year {
    width: auto !important;
    flex: 1 1 0 !important;
  }

  .gantt-row {
    break-inside: avoid;
  }

  .gantt-headrow {
    position: static;
  }

  .gantt-label,
  .gantt-corner {
    position: static;
  }

  /* Without this every bar prints white and the report is meaningless. */
  .gantt-bar,
  .gantt-diamond,
  .gantt-today {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
