/* ============================================================================
   Contour · Timeline / Gantt view
   Every rule is scoped under .view-timeline. Colour, size, radius and motion
   come from css/tokens.css — there is no literal colour in this file.

   Layout: one scroll container holds a two-column grid. The record list is a
   sticky left column and the axis a sticky top row, so the two panes can never
   fall out of sync the way two independently scrolled panes do.
   ========================================================================== */

.view-timeline {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  min-width: 0;
  background: var(--canvas);
  color: var(--text);
  font-size: var(--fs-base);
  line-height: var(--lh-base);

  --tl-side: 280px;          /* the spec's 280px record list; mirrored by SIDE_W in js */
  --tl-axis-h: 44px;
  --tl-lane-h: 26px;
  --tl-canvas-w: 1200px;
  --tl-tray-w: 240px;
  --tl-bar-h: 24px;          /* >= the 24px WCAG 2.2 AA target size */
}

.view-timeline .tl-spacer { flex: 1 1 auto; }
.view-timeline .tl-ico { flex: 0 0 auto; }
.view-timeline .tl-ico.sm { width: 12px; height: 12px; }
.view-timeline .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.view-timeline .caps {
  font-size: var(--fs-xs);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--text-2);
  font-weight: var(--fw-semibold);
}

/* --------------------------------------------------------------- toolbar --- */

/* NB: the toolbar is .tl-toolbar, never .tl-bar — .tl-bar is a scheduled bar in a track. */
.view-timeline .tl-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;            /* narrow viewports wrap the controls instead of clipping them */
  gap: var(--sp-1) var(--sp-2);
  flex: 0 0 auto;
  padding: var(--sp-2) var(--sp-3);
  border-bottom: var(--border);
  background: var(--surface);
}

.view-timeline .tl-nav { display: inline-flex; gap: 2px; }

.view-timeline .tl-by {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  max-width: 260px;
  height: var(--control-h-sm);
  padding: 0 var(--sp-2);
  border-radius: var(--radius-pill);
  background: var(--sunken);
  color: var(--text-2);
  font-size: var(--fs-sm);
}

/* A mapping the store owns: the pill carries a lock so the missing drag handles read as a
   property of the data, not as a broken chart. */
.view-timeline .tl-by.is-locked { background: var(--hover); }

/* ------------------------------------------------------------------ body --- */

.view-timeline .tl-body {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
  min-width: 0;
}

.view-timeline .tl-scroll {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--surface);
}

.view-timeline .tl-inner {
  position: relative;
  display: grid;
  grid-template-columns: var(--tl-side) var(--tl-canvas-w);
  align-content: start;
  width: max-content;
  min-width: 100%;
}

/* -------------------------------------------------------------------- axis --- */

.view-timeline .tl-corner {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 5;
  display: flex;
  align-items: flex-end;
  height: var(--tl-axis-h);
  padding: 0 var(--sp-3) var(--sp-2);
  background: var(--surface);
  border-right: var(--border);
  border-bottom: var(--border);
}

.view-timeline .tl-axis {
  position: sticky;
  top: 0;
  z-index: 4;
  height: var(--tl-axis-h);
  background: var(--surface);
  border-bottom: var(--border);
}

.view-timeline .tl-axis-major,
.view-timeline .tl-axis-minor { position: relative; height: 22px; }
.view-timeline .tl-axis-major { border-bottom: var(--border-soft); }

.view-timeline .tl-tick-major {
  position: absolute;
  top: 0;
  height: 22px;
  display: flex;
  align-items: center;
  border-left: var(--border-w) solid var(--line);
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--text-2);
  white-space: nowrap;
  /* no overflow:hidden here — it would become a scroll container and kill the sticky label */
}

/* Keep the month/quarter name readable when its column is scrolled half off. */
.view-timeline .tl-tick-major > span {
  position: sticky;
  left: calc(var(--tl-side) + var(--sp-2));
  padding-right: var(--sp-2);
  background: var(--surface);
}

.view-timeline .tl-tick-minor {
  position: absolute;
  top: 0;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-left: var(--border-w) solid var(--line-2);
  font-size: var(--fs-xs);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
  overflow: hidden;
}

.view-timeline .tl-tick-minor.is-weekend { background: var(--sunken); }
.view-timeline .tl-tick-minor.is-today { background: var(--accent); color: var(--on-accent); font-weight: var(--fw-semibold); }

/* ------------------------------------------------------------------- rows --- */

.view-timeline .tl-lane-head {
  position: sticky;
  left: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: var(--tl-lane-h);
  padding: 0 var(--sp-3);
  background: var(--sunken);
  border-right: var(--border);
  border-bottom: var(--border-soft);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
}

.view-timeline .tl-lane-dot {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  border-radius: var(--radius-pill);
  background: var(--c, var(--accent));
}

.view-timeline .tl-lane-count { margin-left: auto; color: var(--text-2); font-weight: var(--fw-regular); }

.view-timeline .tl-lane-band {
  height: var(--tl-lane-h);
  background: var(--sunken);
  border-bottom: var(--border-soft);
}

.view-timeline .tl-side {
  position: sticky;
  left: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  height: var(--row-h, 44px);
  padding: 0 var(--sp-2) 0 var(--sp-3);
  background: var(--surface);
  border-right: var(--border);
  border-bottom: var(--border-w) solid var(--line-2);
  min-width: 0;
}

.view-timeline .tl-side-dot {
  flex: 0 0 auto;
  width: 6px;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--c, var(--accent));
}

.view-timeline .tl-side-name {
  /* max-content so the hit box is the text, not the whole column: a 245px-wide button
     with left-aligned text reads as a mis-centred label and over-claims the row. */
  flex: 0 1 auto;
  display: flex;
  align-items: center;
  align-self: stretch;
  width: max-content;
  max-width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.view-timeline .tl-side-name:hover { color: var(--accent); text-decoration: underline; }

.view-timeline .tl-side-meta {
  flex: 0 1 auto;
  margin-left: auto;
  padding-left: var(--sp-2);
  max-width: 45%;
  font-size: var(--fs-xs);
  color: var(--text-3);
}

.view-timeline .tl-track {
  position: relative;
  height: var(--row-h, 44px);
  border-bottom: var(--border-w) solid var(--line-2);
  background-repeat: repeat;
}

.view-timeline .tl-track.is-drop {
  outline: var(--focus-ring-w) solid var(--accent);
  outline-offset: -2px;
  background-color: var(--selected);
}

/* The empty state's single drop target — the tray's offer has to have somewhere to land. */
.view-timeline .tl-empty-drop {
  border-top: var(--border-w) solid var(--line-2);
}

.view-timeline .tl-empty-side {
  display: flex;
  align-items: center;
  height: var(--row-h, 44px);
}

/* -------------------------------------------------------------------- bar --- */

.view-timeline .tl-bar {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  height: var(--tl-bar-h);
  min-width: 8px;
  display: flex;
  align-items: center;
  padding: 0 var(--sp-2);
  border-radius: var(--radius-pill);
  background: color-mix(in srgb, var(--c, var(--accent)) var(--tint-strong), var(--surface));
  /* the leading cap and the hairline are one inset shadow — no decorative pseudo element */
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--c, var(--accent)) 55%, transparent),
              inset 4px 0 0 0 var(--c, var(--accent));
  color: var(--text);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.view-timeline .tl-bar:hover { background: color-mix(in srgb, var(--c, var(--accent)) 40%, var(--surface)); }
.view-timeline .tl-bar:focus-visible { outline: var(--focus-ring-w) solid var(--focus-ring); outline-offset: 2px; }
.view-timeline .tl-bar.is-locked { cursor: default; opacity: .8; }
.view-timeline .tl-bar.is-dragging { box-shadow: var(--shadow-md); z-index: 3; cursor: grabbing; }

.view-timeline .tl-bar-label {
  min-width: 0;
  pointer-events: none;
}

.view-timeline .tl-bar.is-milestone {
  padding: 0;
  border-radius: var(--radius-sm);
  background: var(--c, var(--accent));
  box-shadow: none;
}

/* Milestones and bars too short to hold text carry no label: the 280px record list on
   the left already names every row, and a spilled label would collide with neighbours. */
.view-timeline .tl-bar.is-milestone,
.view-timeline .tl-bar.is-narrow { padding: 0; }

.view-timeline .tl-handle {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: ew-resize;
  border-radius: var(--radius-pill);
}

.view-timeline .tl-handle.is-start { left: 0; }
.view-timeline .tl-handle.is-end { right: 0; }
.view-timeline .tl-bar:hover .tl-handle { background: color-mix(in srgb, var(--c, var(--accent)) 70%, transparent); }

/* --------------------------------------------------------------- overlays --- */

/* The inline `left` is canvas-relative (0 = the first day column), so the marker is
   pushed past the sticky record list the same way the dependency layer is. */
.view-timeline .tl-today {
  position: absolute;
  top: var(--tl-axis-h);
  bottom: 0;
  left: 0;
  margin-left: var(--tl-side);
  z-index: 1;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-left: 2px solid var(--accent);
  pointer-events: none;
}

.view-timeline .tl-today-flag {
  position: sticky;
  top: var(--tl-axis-h);
  display: inline-block;
  margin-left: -1px;
  padding: 0 var(--sp-1);
  border-radius: 0 0 var(--radius-sm) 0;
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--fs-xs);
  white-space: nowrap;
}

.view-timeline .tl-deps {
  position: absolute;
  top: var(--tl-axis-h);
  left: var(--tl-side);
  width: var(--tl-canvas-w);
  bottom: 0;
  z-index: 2;
  overflow: visible;
  pointer-events: none;
}

.view-timeline .tl-dep {
  fill: none;
  stroke: var(--text-3);
  stroke-width: 1.25;
  stroke-dasharray: 3 3;
}

.view-timeline .tl-dep-head { fill: var(--text-3); stroke: none; }

/* -------------------------------------------------------------- restricted --- */

.view-timeline .tl-restricted {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 0 var(--sp-1);
  border: 1px dashed var(--line);
  border-radius: var(--radius-sm);
  background: repeating-linear-gradient(
    135deg,
    var(--sunken) 0 4px,
    transparent 4px 8px
  );
  color: var(--text-3);
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
  font-style: italic;
  white-space: nowrap;
}

/* --------------------------------------------------------------- dragging --- */

.view-timeline.is-dragging { cursor: grabbing; }
.view-timeline.is-dragging .tl-tray-chip { pointer-events: none; }

.view-timeline .tl-ghost {
  position: fixed;
  top: 0;
  left: 0;
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  max-width: 240px;
  padding: var(--sp-1) var(--sp-2);
  border-left: 3px solid var(--c, var(--accent));
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--c, var(--accent)) var(--tint-chip), var(--raised));
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
  white-space: nowrap;
  pointer-events: none;
}

.view-timeline .tl-ghost::after {
  content: attr(data-day);
  color: var(--text-2);
  font-variant-numeric: tabular-nums;
}

.view-timeline .tl-hint {
  position: absolute;
  z-index: var(--z-popover);
  padding: 2px var(--sp-2);
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--text-inverse);
  font-size: var(--fs-xs);
  white-space: nowrap;
  pointer-events: none;
}

/* ------------------------------------------------------------------- tray --- */

.view-timeline .tl-tray {
  flex: 0 0 var(--tl-tray-w);
  width: var(--tl-tray-w);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: var(--border);
  background: var(--surface);
}

.view-timeline .tl-tray.is-closed { display: none; }

.view-timeline .tl-tray-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex: 0 0 auto;
  padding: var(--sp-2) var(--sp-2) var(--sp-2) var(--sp-3);
  border-bottom: var(--border-soft);
}

.view-timeline .tl-tray-body {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-2);
  overflow-y: auto;
}

.view-timeline .tl-tray-note {
  flex: 0 0 auto;
  margin: var(--sp-1) 0 0;
  font-size: var(--fs-xs);
  line-height: var(--lh-xs);
  color: var(--text-2);
}

.view-timeline .tl-tray-empty {
  display: flex;
  flex: 0 0 auto;
  flex-direction: column;
  gap: var(--sp-1);
  padding: var(--sp-4) var(--sp-2);
  text-align: center;
}

.view-timeline .tl-tray-title { margin: 0; font-weight: var(--fw-medium); }
.view-timeline .tl-tray-empty .panel-hint { margin: 0; }

.view-timeline .tl-tray-chip {
  display: flex;
  flex: 0 0 auto;             /* a scrolling flex column must not squash its rows */
  align-items: center;
  gap: var(--sp-1);
  width: 100%;
  min-height: 28px;
  padding: 0 var(--sp-2) 0 var(--sp-1);
  border: var(--border-soft);
  border-left: 3px solid var(--c, var(--line));
  border-radius: var(--radius-sm);
  background: var(--canvas);
  color: var(--text);
  font: inherit;
  font-size: var(--fs-sm);
  text-align: left;
  cursor: grab;
  touch-action: none;
}

.view-timeline .tl-tray-chip:hover { background: var(--hover); }
.view-timeline .tl-tray-chip:focus-visible { outline: var(--focus-ring-w) solid var(--focus-ring); outline-offset: 1px; }
.view-timeline .tl-tray-chip.is-locked { cursor: default; color: var(--text-2); }
.view-timeline .tl-tray-chip .grip { color: var(--text-3); }

/* ----------------------------------------------------------------- footer --- */

.view-timeline .tl-foot {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex: 0 0 auto;
  padding: var(--sp-1) var(--sp-3);
  border-top: var(--border);
  background: var(--surface);
}

.view-timeline .tl-foot-text { font-size: var(--fs-xs); color: var(--text-2); }

/* ------------------------------------------------------------------ flash --- */

.view-timeline .tl-flash {
  position: absolute;
  left: 50%;
  bottom: var(--sp-6);
  transform: translateX(-50%);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  max-width: min(420px, 80%);
  padding: var(--sp-2) var(--sp-3);
  border: var(--border);
  border-radius: var(--radius-lg);
  background: var(--raised);
  box-shadow: var(--shadow-md);
  font-size: var(--fs-sm);
}

.view-timeline .tl-flash[hidden] { display: none; }
.view-timeline .tl-flash.bad { border-color: var(--danger-line); background: var(--danger-soft); color: var(--danger); }
.view-timeline .tl-flash.ok { border-color: var(--success-line); background: var(--success-soft); color: var(--success); }

/* ------------------------------------------------------------ config panel --- */
/* Renders OUTSIDE .view-timeline: the shell mounts configPanel() into its Configure rail.
   The tl- prefix keeps it collision-free. */

.tl-cfg { display: flex; flex-direction: column; gap: var(--sp-3); }
.tl-cfg-field { display: flex; flex-direction: column; gap: var(--sp-1); min-width: 0; }
.tl-cfg-field .panel-hint { margin: 0; }
.tl-cfg-field .select[disabled] { opacity: .6; cursor: not-allowed; }

/* ----------------------------------------------------------------- narrow --- */
