/* Timeline canvas (js/canvas/canvas.js). One DOM, two orientations:
   .tlc--h lays the time axis out horizontally (desktop), .tlc--v vertically
   (calendar-day, compact). canvas.js positions everything with three custom
   properties — --pos / --len (percent along the time axis) and --cross-off
   (px across it) — and the orientation blocks below map them onto
   left/width/top or top/height/left. No other geometry lives here. */

.tlc {
  display: flex;
  gap: var(--space-4);
  align-items: flex-start;
}

.tlc-main {
  flex: 1 1 auto;
  min-width: 0;
}

.tlc-scroll {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

/* ---- Frame: axis + bands ------------------------------------------------- */

.tlc-frame {
  position: relative;
  display: flex;
}

/* Main-axis padding gives the overhanging half of the first/last hour
   labels room to render inside the scroll clip. */
.tlc--h .tlc-frame {
  flex-direction: column;
  width: var(--span-px);
  min-width: 100%;
  padding: 0 12px;
}

.tlc--v .tlc-frame {
  flex-direction: row;
  height: var(--span-px);
  min-width: 100%;
  padding: 10px 0;
}

.tlc-axis {
  position: relative;
  flex: none;
}

.tlc--h .tlc-axis { height: 22px; }
.tlc--v .tlc-axis { width: 36px; }

.tlc-axis-label {
  position: absolute;
  color: var(--muted);
  font-size: var(--font-xs);
  font-variant-numeric: tabular-nums;
}

.tlc--h .tlc-axis-label {
  left: var(--pos);
  top: 3px;
  transform: translateX(-50%);
}

.tlc--v .tlc-axis-label {
  top: var(--pos);
  right: 8px;
  transform: translateY(-50%);
}

.tlc-bands {
  position: relative;
  flex: 1 1 auto;
  display: flex;
  gap: var(--space-2);
  min-height: 60px;
}

.tlc--h .tlc-bands {
  flex-direction: column;
  padding: var(--space-2) 0 var(--space-3);
}

/* Staff rows are frameless single bars sitting directly on each other, so the
   inter-band gap collapses — each bar's symmetric band padding is its only
   halo, giving an even space above and below every bar. */
.tlc--staffrows .tlc-bands,
.tlc--staffrows .tlc-gutter-cells {
  gap: 0;
}

.tlc--v .tlc-bands {
  flex-direction: row;
  padding: 0 var(--space-3) 0 var(--space-2);
}

/* ---- Grid layer: hour lines, off-hours shading, drop indicator ------------ */

.tlc-gridlayer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.tlc-gridline {
  position: absolute;
  background: var(--border);
  opacity: 0.55;
}

.tlc--h .tlc-gridline { left: var(--pos); top: 0; bottom: 0; width: 1px; }
.tlc--v .tlc-gridline { top: var(--pos); left: 0; right: 0; height: 1px; }

.tlc-offhours {
  position: absolute;
  background: repeating-linear-gradient(
    135deg,
    transparent 0 6px,
    var(--hatch) 6px 12px
  );
}

.tlc--h .tlc-offhours { left: var(--pos); width: var(--len); top: 0; bottom: 0; }
.tlc--v .tlc-offhours { top: var(--pos); height: var(--len); left: 0; right: 0; }

/* Per-staff unavailability underlay (staff-row mode). Distinct from the job
   bars: full band height, square corners, flat translucent grey, and inert —
   it sits behind the bars (z 2) and above the grid layer. */
.tlc-unavail {
  position: absolute;
  z-index: 1;
  pointer-events: none;
  display: flex;
  align-items: center;
  overflow: hidden;
  padding: 0 0.375rem;
  background: color-mix(in srgb, var(--muted) 22%, transparent);
}

.tlc--h .tlc-unavail { left: var(--pos); width: var(--len); top: 0; bottom: 0; }
.tlc--v .tlc-unavail { top: var(--pos); height: var(--len); left: 0; right: 0; }

/* Names the reason (Holiday / Rest / Outside availability). Wraps to at most
   two lines on a narrow band, then ellipsises rather than overflowing. */
.tlc-unavail-label {
  font-size: var(--font-xs);
  font-weight: 500;
  color: var(--muted);
  line-height: 1.2;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  overflow: hidden;
}

.tlc-dropline {
  position: absolute;
  background: var(--accent);
  z-index: 5;
}

.tlc--h .tlc-dropline { left: var(--pos); top: 0; bottom: 0; width: 2px; }
.tlc--v .tlc-dropline { top: var(--pos); left: 0; right: 0; height: 2px; }

.tlc-dropline-time {
  position: absolute;
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--font-xs);
  font-weight: 600;
  padding: 0 0.375rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
}

.tlc--h .tlc-dropline-time { top: 0; left: 4px; }
.tlc--v .tlc-dropline-time { left: 2px; top: 4px; }

/* Floating chip that follows the pointer during a palette drag. */
.tlc-dragchip {
  position: fixed;
  z-index: 200;
  pointer-events: none;
  background: var(--accent);
  color: var(--on-accent);
  font-size: var(--font-sm);
  font-weight: 500;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-full);
  box-shadow: var(--shadow-pop);
}

/* ---- Bands ----------------------------------------------------------------- */

.tlc-band {
  position: relative;
  flex: none;
}

.tlc--h .tlc-band { height: var(--band-cross); }
.tlc--v .tlc-band { width: var(--band-cross); }

/* Doubled class so this beats `.tlc-bar { display: flex }` below (equal
   specificity but later in source order would otherwise win). */
.tlc-bar.tlc-bar--collapsed { display: none; }

/* ---- Placement box ----------------------------------------------------------- */

/* No z-index here: the box must not create a stacking context, so its edge
   handles (z 3) can sit above sibling bars (z 2) — a bar ending flush with
   the box edge would otherwise swallow the resize grab. The box body is the
   move handle / tap target (bars sit above it and keep their own gestures). */
.tlc-box {
  position: absolute;
  border: 1.5px solid var(--accent);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--accent) 5%, transparent);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.tlc-box:active { cursor: grabbing; }
.tlc--readonly .tlc-box { cursor: pointer; }

.tlc--h .tlc-box { left: var(--pos); width: var(--len); top: 0; bottom: 0; }
.tlc--v .tlc-box { top: var(--pos); height: var(--len); left: 0; right: 0; }

.tlc-box--dragging {
  box-shadow: var(--shadow-pop);
  opacity: 0.95;
}

/* Vertical only — horizontal rows carry their label in the gutter instead. */
.tlc-box-head {
  position: absolute;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  overflow: hidden;
  color: var(--accent);
}

.tlc--v .tlc-box-head {
  top: 0;
  bottom: 0;
  left: 0;
  width: 22px;
  writing-mode: vertical-rl;
  padding: 0.375rem 0;
}

.tlc-box-toggle {
  flex: none;
  background: transparent;
  color: inherit;
  border: none;
  padding: 0 0.125rem;
  font-size: var(--font-xs);
  line-height: 1;
  cursor: pointer;
}

.tlc-box-label {
  font-size: var(--font-xs);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tlc-box-times {
  font-size: var(--font-xs);
  opacity: 0.75;
  white-space: nowrap;
}

.tlc-box-edge {
  position: absolute;
  z-index: 3;
}

.tlc--h .tlc-box-edge { top: 0; bottom: 0; width: 12px; cursor: ew-resize; }
.tlc--h .tlc-box-edge--start { left: -6px; }
.tlc--h .tlc-box-edge--end { right: -6px; }

.tlc--v .tlc-box-edge { left: 0; right: 0; height: 12px; cursor: ns-resize; }
.tlc--v .tlc-box-edge--start { top: -6px; }
.tlc--v .tlc-box-edge--end { bottom: -6px; }

/* ---- Bars ------------------------------------------------------------------------ */

.tlc-bar {
  position: absolute;
  z-index: 2;
  display: flex;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: var(--bar-color, #64748b);
  color: var(--on-accent);
  font-size: var(--font-xs);
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.tlc--h .tlc-bar {
  /* Trim the leading edge by 1px (the grid-line width) so back-to-back bars
     show a hairline gap that lands on the grid line between them, keeping the
     trailing edge on the true end time. */
  left: calc(var(--pos) + 1px);
  width: calc(var(--len) - 1px);
  top: var(--cross-off);
  height: 40px;
  align-items: center;
  gap: 0.375rem;
  padding: 0 1rem;
}

.tlc--v .tlc-bar {
  top: calc(var(--pos) + 1px);
  height: calc(var(--len) - 1px);
  left: var(--cross-off);
  width: 92px;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.125rem;
  padding: 0.5rem 0.375rem;
}

.tlc-bar--dragging {
  z-index: 4;
  box-shadow: var(--shadow-pop);
}

.tlc-bar--preview { opacity: 0.85; }

/* Pre-assignment seats and post-solve unassigned seats read as outlines. */
.tlc--solved .tlc-bar--unassigned {
  background: color-mix(in srgb, var(--bar-color, #64748b) 12%, var(--surface));
  color: var(--text);
  border: 1.5px dashed var(--bar-color, #64748b);
}

/* A rest/overlap breach: red ring so the offending bar stands out on the
   canvas, echoing the day-tab dot and the issues list. */
.tlc-bar--error {
  border: 1.5px solid var(--danger);
  box-shadow: inset 0 0 0 1px var(--danger);
}

/* Brief highlight when the issues list jumps to a bar. */
.tlc-bar--flash {
  animation: tlc-bar-flash 1.2s ease-out;
}

@keyframes tlc-bar-flash {
  0%,
  40% {
    box-shadow: 0 0 0 3px var(--accent);
  }
  100% {
    box-shadow: 0 0 0 0 transparent;
  }
}

/* Name over time-subtitle, stacked; badges sit alongside the whole stack. */
.tlc-bar-text {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  flex: 1 1 auto;
}

/* Vertical bars can be tall — keep the label at the top, not floating centre. */
.tlc--v .tlc-bar-text {
  justify-content: flex-start;
  flex: none;
  align-self: stretch;
}

.tlc-bar-primary {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Secondary treatment, iOS .secondary style: a grey tint plus opacity. On a
   solid capability-coloured bar the foreground is --on-accent (white), so we
   pull it toward the muted grey; on light (unassigned) bars use the token flat. */
.tlc-bar-secondary {
  color: color-mix(in srgb, var(--on-accent) 78%, var(--muted));
  opacity: 0.9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}

.tlc--solved .tlc-bar--unassigned .tlc-bar-secondary {
  color: var(--muted);
  opacity: 0.9;
}

.tlc-bar-badges {
  display: inline-flex;
  gap: 0.125rem;
  flex: none;
  margin-left: auto;
}

.tlc--v .tlc-bar-badges { margin-left: 0; margin-top: auto; }

.tlc-bar-badge { font-size: var(--font-xs); }

/* Each bar end is a widened grab zone carrying a single line (drawn from
   currentColor so it reads on both solid and outlined bars) so the stretch
   affordance is obvious and easy to hit, especially on touch. */
.tlc-bar-edge {
  position: absolute;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tlc-bar-edge::before {
  content: "";
  background: color-mix(in srgb, currentColor 60%, transparent);
  border-radius: 1px;
}

.tlc--h .tlc-bar-edge { top: 0; bottom: 0; width: 14px; cursor: ew-resize; }
.tlc--h .tlc-bar-edge--start { left: 0; }
.tlc--h .tlc-bar-edge--end { right: 0; }
.tlc--h .tlc-bar-edge::before { width: 2px; height: 16px; }

.tlc--v .tlc-bar-edge { left: 0; right: 0; height: 14px; cursor: ns-resize; }
.tlc--v .tlc-bar-edge--start { top: 0; }
.tlc--v .tlc-bar-edge--end { bottom: 0; }
.tlc--v .tlc-bar-edge::before { width: 16px; height: 2px; }

/* ---- Name gutter (horizontal): one labelled row per band ------------------- */
/* Every horizontal band gets a gutter cell — staff names in staff-row mode,
   preset names (plus the collapse toggle) in placement mode — so the two
   modes share one row geometry. tlc--gutter is set whenever a gutter renders
   (any horizontal canvas with bands). */

.tlc--gutter { --gutter-w: 128px; }

.tlc--gutter .tlc-scroll { display: flex; }

/* The frame normally insists on filling the scroller; leave room for the
   gutter so a short day doesn't force a permanent horizontal scroll. flex-shrink
   is killed so a zoomed --span-px wider than the viewport isn't collapsed back
   to min-width by the flex row — the scroller overflows and scrolls instead. */
.tlc--gutter .tlc-frame {
  flex: none;
  min-width: calc(100% - var(--gutter-w));
}

.tlc-gutter {
  position: sticky;
  left: 0;
  z-index: 5;
  flex: none;
  width: var(--gutter-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
}

/* The gutter mirrors the frame column: head = .tlc--h .tlc-axis height, cells
   = .tlc--h .tlc-bands padding/gap, each cell its band's --band-cross — so
   names stay level with their rows. */
.tlc-gutter-head { height: 22px; }

.tlc-gutter-cells {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-2) 0 var(--space-3);
}

.tlc-gutter-cell {
  flex: none;
  display: flex;
  align-items: flex-start;
  gap: 0.125rem;
  height: var(--band-cross);
  padding: 4px var(--space-2) 0 var(--space-3);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}

/* A placement row's collapse toggle sits in its gutter cell, on the same
   32px first-lane line as the name. */
.tlc-gutter-cell .tlc-box-toggle {
  line-height: 32px;
  margin-left: calc(-1 * var(--space-2));
}

.tlc-gutter-name {
  flex: 1 1 auto;
  min-width: 0;
  display: block;
  line-height: 32px; /* centred on the first 32px lane */
  font-size: var(--font-xs);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tlc-gutter-cell--muted .tlc-gutter-name {
  color: var(--muted);
  font-weight: 500;
}

/* Staff-row names are real buttons (tap to swap the person out); strip the
   native button chrome so they read as the same primary-colour label. The
   whole gutter cell is the hover/click target, so the affordance is on the
   cell, not this inset element. */
.tlc-gutter-name--btn {
  padding: 0;
  border: 0;
  background: none;
  font-family: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

/* Override the global button:hover fill — the hover affordance belongs to the
   whole cell, not this inset element (which would render as a capsule). */
.tlc-gutter-name--btn:hover:not(:disabled) {
  background: none;
}

.tlc-gutter-cell--tappable {
  cursor: pointer;
}

.tlc-gutter-cell--tappable:hover {
  background: var(--accent-soft);
}

.tlc-gutter-name--btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* Name over its assigned-hours sub-line, stacked in place of the single 32px
   name line. */
.tlc-gutter-label {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  height: 32px;
}

.tlc-gutter-label .tlc-gutter-name {
  flex: 0 0 auto;
  line-height: 1.25;
}

.tlc-gutter-sub {
  min-width: 0;
  font-size: var(--font-xs);
  font-weight: 500;
  line-height: 1.2;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Row separators run under bands and gutter cells alike, in every mode. */
.tlc--h .tlc-band { border-bottom: 1px solid var(--border); }

/* ---- Empty / closed states ----------------------------------------------------------- */

.tlc-empty {
  position: absolute;
  padding: var(--space-5);
  color: var(--muted);
  font-size: var(--font-sm);
  pointer-events: none;
  text-align: center;
  width: max-content;
  max-width: 90%;
}

.tlc--h .tlc-empty {
  left: var(--pos);
  top: 50%;
  transform: translate(-50%, -50%);
}

.tlc--v .tlc-empty {
  top: var(--pos);
  left: 50%;
  transform: translate(-50%, -50%);
}

.tlc-closed {
  padding: var(--space-6);
  text-align: center;
}

.tlc-closed-msg {
  color: var(--muted);
  margin: 0 0 var(--space-4);
}

/* Armed preset: the whole timeline is a drop target. */
.tlc--armed .tlc-bands { cursor: copy; }

/* ---- Palette --------------------------------------------------------------------------- */

.tlc-palette {
  flex: 0 0 220px;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
}

.tlc-palette-title {
  font-size: var(--font-sm);
  font-weight: 600;
}

.tlc-palette-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.tlc-preset {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.125rem;
  text-align: left;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}

.tlc-preset:hover { background: var(--accent-soft); }

.tlc-preset[aria-pressed="true"] {
  background: var(--accent-soft);
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.tlc-preset-name {
  font-size: var(--font-sm);
  font-weight: 600;
}

.tlc-preset-sub {
  font-size: var(--font-xs);
  color: var(--muted);
}

.tlc-palette-hint {
  display: none;
  font-size: var(--font-xs);
  color: var(--accent);
}

.tlc--armed .tlc-palette-hint { display: block; }

/* ---- Compact: palette docks at the bottom, canvas scrolls internally ------- */

@media (max-width: 720px) {
  .tlc {
    flex-direction: column;
    align-items: stretch;
  }

  .tlc-scroll {
    max-height: 65dvh;
  }

  .tlc-palette {
    flex: none;
    width: 100%;
  }

  .tlc-palette-list {
    flex-direction: row;
    overflow-x: auto;
    padding-bottom: var(--space-1);
  }

  .tlc-preset {
    min-width: 160px;
    min-height: var(--touch-target);
  }
}
