/*!
 * @fileoverview Chart-only styles for the SVG Gantt renderer (js/timeline.js).
 *   Defines the --tt-* token set (light/dark chart chrome + the 8-step phase
 *   colour ramp) and every `.tt-tl-*` component style. Owns nothing outside
 *   the `.tt-tl` root the renderer builds inside its container — the
 *   integration agent's css/app.css includes this file alongside its own.
 * @module css/timeline
 */

/* ---------------------------------------------------------------------
   Tokens — light (default), dark (prefers-color-scheme + [data-theme]).
   Chart chrome values match the dataviz skill's reference palette; the
   phase ramp is a validated one-hue ordinal ramp (see js/timeline.js
   header comment) with separate light/dark steps so each mode clears the
   2:1 light-end-contrast floor against its own chart surface.
   --------------------------------------------------------------------- */
:root {
  color-scheme: light;
  --tt-surface: #fcfcfb;
  --tt-page: #f3f3f0;
  --tt-ink: #0b0b0b;
  --tt-ink-secondary: #52514e;
  --tt-ink-muted: #898781;
  --tt-grid: #e1e0d9;
  --tt-axis: #c3c2b7;
  --tt-border: rgba(11, 11, 11, 0.1);
  --tt-tooltip-bg: #0b0b0b;
  --tt-tooltip-ink: #fcfcfb;
  --tt-focus-ring: #52514e;

  --tt-phase-0: #8fb0db;
  --tt-phase-1: #719ad1;
  --tt-phase-2: #5585c3;
  --tt-phase-3: #3b70b3;
  --tt-phase-4: #275b9d;
  --tt-phase-5: #184882;
  --tt-phase-6: #0d3666;
  --tt-phase-7: #05244a;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    color-scheme: dark;
    --tt-surface: #1a1a19;
    --tt-page: #0d0d0d;
    --tt-ink: #ffffff;
    --tt-ink-secondary: #c3c2b7;
    --tt-ink-muted: #898781;
    --tt-grid: #2c2c2a;
    --tt-axis: #383835;
    --tt-border: rgba(255, 255, 255, 0.1);
    --tt-tooltip-bg: #ffffff;
    --tt-tooltip-ink: #1a1a19;
    --tt-focus-ring: #c3c2b7;

    --tt-phase-0: #c7e0ff;
    --tt-phase-1: #aacbf6;
    --tt-phase-2: #90b5e6;
    --tt-phase-3: #78a0d5;
    --tt-phase-4: #648bbf;
    --tt-phase-5: #5477a5;
    --tt-phase-6: #46648b;
    --tt-phase-7: #395170;
  }
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --tt-surface: #1a1a19;
  --tt-page: #0d0d0d;
  --tt-ink: #ffffff;
  --tt-ink-secondary: #c3c2b7;
  --tt-ink-muted: #898781;
  --tt-grid: #2c2c2a;
  --tt-axis: #383835;
  --tt-border: rgba(255, 255, 255, 0.1);
  --tt-tooltip-bg: #ffffff;
  --tt-tooltip-ink: #1a1a19;
  --tt-focus-ring: #c3c2b7;

  --tt-phase-0: #c7e0ff;
  --tt-phase-1: #aacbf6;
  --tt-phase-2: #90b5e6;
  --tt-phase-3: #78a0d5;
  --tt-phase-4: #648bbf;
  --tt-phase-5: #5477a5;
  --tt-phase-6: #46648b;
  --tt-phase-7: #395170;
}

/* ---------------------------------------------------------------------
   Root & layout
   --------------------------------------------------------------------- */
.tt-tl {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--tt-surface);
  color: var(--tt-ink);
  font: 13px/1.4 var(--tt-font, Inter, ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif);
  font-variant-numeric: tabular-nums;
  border: 1px solid var(--tt-border);
  border-radius: var(--tt-radius, 10px);
  padding: 12px;
  box-sizing: border-box;
}
.tt-tl *,
.tt-tl *::before,
.tt-tl *::after {
  box-sizing: border-box;
}
/* Several descendants set their own `display` (flex/grid/etc.) at the same
   specificity as the UA `[hidden]{display:none}` rule, which lets the
   author rule win by origin and defeats `el.hidden = true`. Force it back. */
.tt-tl [hidden] {
  display: none !important;
}

/* ---------------------------------------------------------------------
   Legend
   --------------------------------------------------------------------- */
.tt-tl-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 28px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--tt-border);
}
.tt-tl-legend-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
}
.tt-tl-legend-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--tt-ink-muted);
  margin-right: 4px;
}
.tt-tl-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--tt-ink-secondary);
  white-space: nowrap;
}
.tt-tl-legend-swatch {
  width: 14px;
  height: 8px;
  border-radius: 3px;
  flex: none;
  display: inline-block;
}
.tt-tl-legend-swatch-outline {
  background: none;
  border: 2px dashed var(--tt-phase-4);
  height: 6px;
}
.tt-tl-legend-swatch-solid {
  background: var(--tt-phase-4);
}
.tt-tl-legend-swatch-check {
  background: var(--tt-phase-6);
  position: relative;
}
.tt-tl-legend-swatch-check::after {
  content: '\2713';
  position: absolute;
  inset: -3px -4px auto auto;
  font-size: 8px;
  color: var(--tt-surface);
  line-height: 1;
}
.tt-tl-legend-swatch-hatch {
  background-image: repeating-linear-gradient(
    45deg,
    var(--tt-phase-4),
    var(--tt-phase-4) 2px,
    var(--tt-phase-6) 2px,
    var(--tt-phase-6) 4px
  );
}
.tt-tl-legend-swatch-estimated {
  background: none;
  border: 1.5px dotted var(--tt-ink-muted);
  height: 6px;
}

/* Legend chips — the swatch/label pairs above double as phase/status filter
   toggles. `aria-pressed="false"` (mirrored by .tt-tl-legend-chip-dim) marks
   a hidden series; text stays on ink tokens even when dim (never recolour
   text to signal state — see the dataviz skill's marks-and-anatomy.md). */
.tt-tl-legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font: inherit;
  color: var(--tt-ink-secondary);
  background: none;
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 2px 6px 2px 2px;
  margin: 0;
  cursor: pointer;
  white-space: nowrap;
}
.tt-tl-legend-chip:hover {
  background: var(--tt-page);
  border-color: var(--tt-border);
}
.tt-tl-legend-chip:focus-visible {
  outline: 2px solid var(--tt-focus-ring);
  outline-offset: 1px;
}
.tt-tl-legend-chip-dim {
  opacity: 0.4;
}
.tt-tl-legend-chip-showall {
  color: var(--tt-ink);
  border-color: var(--tt-border);
  background: var(--tt-page);
  font-weight: 600;
  padding: 2px 8px;
}

/* ---------------------------------------------------------------------
   Toolbar
   --------------------------------------------------------------------- */
.tt-tl-toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
.tt-tl-btn {
  font: inherit;
  color: var(--tt-ink);
  background: var(--tt-surface);
  border: 1px solid var(--tt-border-strong, var(--tt-border));
  border-radius: var(--tt-radius-sm, 7px);
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.12s ease;
}
.tt-tl-btn:hover {
  background: var(--tt-surface-2, var(--tt-grid));
}
.tt-tl-btn:focus-visible {
  outline: 2px solid var(--tt-focus-ring);
  outline-offset: 1px;
}
.tt-tl-toolbar-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--tt-ink-secondary);
}
.tt-tl-select {
  font: inherit;
  color: var(--tt-ink);
  background: var(--tt-surface);
  border: 1px solid var(--tt-border-strong, var(--tt-border));
  border-radius: var(--tt-radius-sm, 7px);
  padding: 4px 6px;
  font-size: 12px;
  cursor: pointer;
}
.tt-tl-select:focus-visible {
  outline: 2px solid var(--tt-focus-ring);
  outline-offset: 1px;
}

/* Export menu — a small anchored dropdown off the toolbar button. */
.tt-tl-export {
  position: relative;
  display: inline-flex;
}
.tt-tl-export-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  padding: 4px;
  background: var(--tt-surface);
  border: 1px solid var(--tt-border);
  border-radius: 6px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.18);
}
.tt-tl-export-item {
  font: inherit;
  text-align: left;
  color: var(--tt-ink);
  background: none;
  border: none;
  border-radius: 4px;
  padding: 6px 8px;
  cursor: pointer;
}
.tt-tl-export-item:hover {
  background: var(--tt-page);
}
.tt-tl-export-item:focus-visible {
  outline: 2px solid var(--tt-focus-ring);
  outline-offset: -2px;
}

/* ---------------------------------------------------------------------
   Chart scroll region — vertical scroll on the outer container (sticky
   group headers stick within it), horizontal scroll on the inner content
   (the time axis can exceed the container's width; the page body never
   scrolls horizontally, only this region does).
   --------------------------------------------------------------------- */
.tt-tl-chart-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tt-tl-scroll {
  overflow: auto;
  border: 1px solid var(--tt-border);
  border-radius: 6px;
  position: relative;
  background: var(--tt-surface);
  touch-action: pan-y;
}
.tt-tl-content {
  position: relative;
  min-width: 100%;
}
.tt-tl-svg {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
}
.tt-tl-header-stack {
  position: relative;
  pointer-events: none;
}

.tt-tl-group-header {
  position: sticky;
  left: 0;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  max-width: 100%;
  padding: 4px 10px;
  background: var(--tt-surface);
  border-bottom: 1px solid var(--tt-border);
  border-radius: 0 0 6px 0;
  font-size: 12px;
  pointer-events: auto;
  box-shadow: 0 1px 0 var(--tt-border);
}
.tt-tl-group-chevron {
  font: inherit;
  font-size: 10px;
  line-height: 1;
  color: var(--tt-ink-secondary);
  background: none;
  border: none;
  padding: 2px;
  margin: 0 -2px 0 0;
  cursor: pointer;
  flex: none;
}
.tt-tl-group-chevron:focus-visible,
.tt-tl-group-name:focus-visible {
  outline: 2px solid var(--tt-focus-ring);
  outline-offset: 1px;
}
.tt-tl-group-name {
  font: inherit;
  font-weight: 600;
  color: var(--tt-ink);
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-align: left;
}
.tt-tl-group-name:hover {
  text-decoration: underline;
}
.tt-tl-group-dist {
  display: inline-flex;
  width: 40px;
  height: 6px;
  border-radius: 3px;
  overflow: hidden;
  background: var(--tt-grid);
  flex: none;
}
.tt-tl-group-dist-seg {
  height: 100%;
}
.tt-tl-group-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 4px;
  background: var(--tt-grid);
  color: var(--tt-ink-secondary);
  font-size: 10px;
  font-weight: 700;
}
.tt-tl-group-count {
  color: var(--tt-ink-muted);
  font-variant-numeric: tabular-nums;
}

.tt-tl-axis-spacer {
  pointer-events: none;
}

/* SVG content */
.tt-tl-grid-line {
  stroke: var(--tt-grid);
  stroke-width: 1;
}
.tt-tl-grid-label {
  fill: var(--tt-ink-muted);
  font-size: 10px;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
.tt-tl-today-line {
  stroke: var(--tt-ink-secondary);
  stroke-width: 1.5;
  stroke-dasharray: 4, 3;
}
.tt-tl-today-label {
  fill: var(--tt-ink-secondary);
  font-size: 10px;
  font-weight: 600;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  paint-order: stroke;
  stroke: var(--tt-surface);
  stroke-width: 3px;
  stroke-linejoin: round;
}

.tt-tl-bar {
  cursor: pointer;
}
.tt-tl-bar-estimated {
  fill: none;
  stroke: var(--tt-ink-muted);
  stroke-width: 1.25;
  stroke-dasharray: 1, 3;
  pointer-events: none;
}
.tt-tl-glyph-mark {
  fill: var(--tt-surface);
  font-size: 8px;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
.tt-tl-milestone-diamond {
  pointer-events: none;
}
.tt-tl-milestone-tick {
  stroke: var(--tt-ink-secondary);
  stroke-width: 1.5;
  pointer-events: none;
}
.tt-tl-direct-label {
  fill: var(--tt-ink);
  font-size: 11px;
  dominant-baseline: central;
  pointer-events: none;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
}
.tt-tl-hit {
  fill: transparent;
  cursor: pointer;
}
.tt-tl-hit:focus-visible {
  outline: 2px solid var(--tt-focus-ring);
  outline-offset: 1px;
}
.tt-tl-row:hover .tt-tl-bar {
  filter: brightness(1.08);
}

/* ---------------------------------------------------------------------
   Brush (range selector strip below the chart)
   --------------------------------------------------------------------- */
.tt-tl-brush {
  padding: 2px 0;
}
.tt-tl-brush-track {
  position: relative;
  height: 14px;
  background: var(--tt-page);
  border: 1px solid var(--tt-border);
  border-radius: 7px;
}
.tt-tl-brush-window {
  position: absolute;
  top: -1px;
  bottom: -1px;
  background: var(--tt-phase-2);
  opacity: 0.35;
  border: 1px solid var(--tt-phase-4);
  border-radius: 7px;
  min-width: 12px;
}
.tt-tl-brush-handle {
  position: absolute;
  top: 50%;
  width: 10px;
  height: 18px;
  transform: translate(-50%, -50%);
  background: var(--tt-phase-4);
  border-radius: 3px;
  cursor: ew-resize;
}
.tt-tl-brush-handle-l {
  left: 0;
}
.tt-tl-brush-handle-r {
  left: 100%;
}
.tt-tl-brush-handle:focus-visible {
  outline: 2px solid var(--tt-focus-ring);
  outline-offset: 1px;
}

/* ---------------------------------------------------------------------
   Show-more affordance (row cap for very large result sets)
   --------------------------------------------------------------------- */
.tt-tl-show-more {
  display: flex;
  justify-content: center;
}

/* ---------------------------------------------------------------------
   Undated list
   --------------------------------------------------------------------- */
.tt-tl-undated {
  border-top: 1px solid var(--tt-border);
  padding-top: 8px;
}
.tt-tl-undated-heading {
  margin: 0 0 2px;
  font-size: 13px;
  font-weight: 600;
}
.tt-tl-undated-note {
  margin: 0 0 6px;
  color: var(--tt-ink-muted);
  font-size: 12px;
}
.tt-tl-undated-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 160px;
  overflow-y: auto;
}
.tt-tl-undated-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--tt-ink-secondary);
  font-size: 12px;
}
.tt-tl-undated-item:hover,
.tt-tl-undated-item:focus-visible {
  background: var(--tt-page);
  outline: none;
}
.tt-tl-undated-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex: none;
  background: var(--tt-swatch-color, var(--tt-phase-0));
}

/* ---------------------------------------------------------------------
   Tooltip (appended to <body>, positioned absolutely)
   --------------------------------------------------------------------- */
.tt-tl-tooltip {
  position: absolute;
  z-index: 1000;
  max-width: 280px;
  background: var(--tt-tooltip-bg);
  color: var(--tt-tooltip-ink);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.tt-tl-tooltip-title {
  font-weight: 700;
  margin-bottom: 1px;
}
.tt-tl-tooltip-sub {
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
  margin-bottom: 3px;
}

/* ---------------------------------------------------------------------
   Table view (accessibility fallback + copy/paste)
   --------------------------------------------------------------------- */
.tt-tl-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--tt-border);
  border-radius: 6px;
}
.tt-tl-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
.tt-tl-table th,
.tt-tl-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--tt-border);
  white-space: nowrap;
}
.tt-tl-table thead th {
  background: var(--tt-page);
  position: sticky;
  top: 0;
}
.tt-tl-table-sort {
  font: inherit;
  font-weight: 600;
  color: var(--tt-ink);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
}
.tt-tl-table tbody tr:hover {
  background: var(--tt-page);
}
.tt-tl-table tbody tr:focus-visible {
  outline: 2px solid var(--tt-focus-ring);
  outline-offset: -2px;
}

/* ---------------------------------------------------------------------
   Responsive — usable down to ~400px. The chart's own scroll container
   carries horizontal overflow; the page body never scrolls horizontally.
   --------------------------------------------------------------------- */
@media (max-width: 480px) {
  .tt-tl {
    padding: 8px;
    gap: 8px;
  }
  .tt-tl-legend {
    gap: 10px 16px;
  }
  .tt-tl-scroll {
    max-height: 420px !important;
  }
}

/* Gesture hint at the end of the toolbar row */
.tt-tl-gesture-hint {
  margin-left: auto;
  align-self: center;
  color: var(--tt-ink-muted);
  font-size: 11px;
  line-height: 1.4;
  white-space: normal;
  max-width: 100%;
}
@media (max-width: 640px) {
  .tt-tl-gesture-hint { display: none; }
}
