/* ============================================================================
   AI Quant Desk — Timeline module (multi-year story chart)
   Tokens + components per DESIGN.md (slots 1-5 + semantics CVD-validated
   2026-07-09; extended slots 6-8 carry measured dE00 floors, full CVD pass
   pending -- see DESIGN.md).
   Scoped under .aiqd-tl — self-contained; safe to load next to aiqd-sankey.css
   on the same page (no shared class names, identical token values by canon).
   ========================================================================== */

.aiqd-tl {
  /* -- surfaces & ink (light) -- */
  --aiqd-bg: #ffffff;
  --aiqd-panel: #f6f6f4;
  --aiqd-panel-2: #efefec;
  --aiqd-border: #e4e4e0;
  --aiqd-ink: #1b1d1a;
  --aiqd-ink-2: #5a5c55;
  /* muted TEXT at 4.9:1 on white (WCAG AA at 11-12px); deliberate darkening of
     DESIGN.md's #8a8c84, which stays available for decorative marks */
  --aiqd-ink-3: #6f716a;
  --aiqd-ink-3-deco: #8a8c84; /* decorative marks only, never text */
  --aiqd-dream-text: #79601a;
  --aiqd-tooltip-bg: #23251f;
  --aiqd-tooltip-ink: #f2f3ee;

  /* -- brand & semantic -- */
  --aiqd-value: #5e8a33;
  --aiqd-value-text: #47691f;
  --aiqd-value-tint: rgba(94, 138, 51, 0.10);
  --aiqd-chip-on: #ffffff; /* text on the solid moss chip (4.7:1) */
  --aiqd-cost: #98928b;
  --aiqd-agg: #b7bab2;
  --aiqd-deficit: #d03b3b;
  --aiqd-dream: #b08828;
  --aiqd-warn-ink: #7d621b; /* 5.2:1 on the chip tint (AA at 11px) */
  --aiqd-warn-bg: #faf3dc;
  --aiqd-warn-border: #ecdfb4;
  --aiqd-col-alpha: 0.9;

  /* -- categorical parts ramp "Dusk editorial" (fixed order; expert-derived
        2026-07-09: ink/wash alternation, worst adjacent CVD dE 28.0 light /
        15.7 dark, dE00 >= 23 vs moss/dream/deficit; the four pale washes sit
        below 3:1 on white by design -- relief carried structurally by the 2px
        segment gaps, direct labels, legend, and SR table) -- */
  --aiqd-part-1: #27568f;  /* oxford ink */
  --aiqd-part-2: #3cb9b9;  /* verdigris wash */
  --aiqd-part-3: #7e4172;  /* mulberry plum */
  --aiqd-part-4: #90a3eb;  /* periwinkle wash */
  --aiqd-part-5: #8a4b01;  /* burnt umber */
  --aiqd-part-6: #6db6ec;  /* dusk sky wash */
  --aiqd-part-7: #5b4e95;  /* slate iris */
  --aiqd-part-8: #bb91d5;  /* dusty orchid wash */

  /* -- geometry & motion -- */
  --aiqd-r-card: 10px;
  --aiqd-r-chip: 8px;
  --aiqd-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --aiqd-t: 180ms;
  --aiqd-t-fast: 120ms;
  --aiqd-shadow: 0 1px 2px rgb(0 0 0 / 0.05);
  --aiqd-shadow-2: 0 4px 16px rgb(0 0 0 / 0.07);

  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--aiqd-ink);
  background: var(--aiqd-bg);
  border: 1px solid var(--aiqd-border);
  border-radius: var(--aiqd-r-card);
  box-sizing: border-box;
  container-type: inline-size;
  display: block;
  font-size: 13px;
  line-height: 1.45;
  max-width: 960px;
  min-width: 300px;
  padding: 20px 20px 14px;
  position: relative;
}
.aiqd-tl *, .aiqd-tl *::before, .aiqd-tl *::after { box-sizing: border-box; }
.aiqd-tl .num, .aiqd-tl text {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ---- dark theme: media default + explicit override wins both ways ---- */
@media (prefers-color-scheme: dark) {
  .aiqd-tl:not([data-theme="light"]) {
    --aiqd-bg: #121212; --aiqd-panel: #1b1b1a; --aiqd-panel-2: #232322;
    --aiqd-border: #2c2c2a; --aiqd-ink: #edeee9; --aiqd-ink-2: #b0b2a8; --aiqd-ink-3: #979990;
    --aiqd-ink-3-deco: #7c7e76;
    --aiqd-dream-text: #d8b654;
    --aiqd-tooltip-bg: #f2f3ee; --aiqd-tooltip-ink: #23251f;
    --aiqd-value: #78a34b; --aiqd-value-text: #a4cd7c; --aiqd-value-tint: rgba(120, 163, 75, 0.14);
    --aiqd-chip-on: #121212; /* dark ink on the brighter dark moss (6.9:1) */
    --aiqd-cost: #8a837c; --aiqd-agg: #4c4e48; --aiqd-deficit: #e05252; --aiqd-dream: #c9a03a;
    --aiqd-warn-ink: #e8c55b; --aiqd-warn-bg: #2a2513; --aiqd-warn-border: #4a4122;
    --aiqd-col-alpha: 0.82;
    --aiqd-part-1: #3c6da9; --aiqd-part-2: #25a6a6; --aiqd-part-3: #904e83;
    --aiqd-part-4: #7c8ed3; --aiqd-part-5: #9d5b18; --aiqd-part-6: #549bcf;
    --aiqd-part-7: #695da5; --aiqd-part-8: #a980c2; /* Dusk editorial, dark steps (six-checks PASS on #121212) */
    --aiqd-shadow: none; --aiqd-shadow-2: none;
  }
}
.aiqd-tl[data-theme="dark"] {
  --aiqd-bg: #121212; --aiqd-panel: #1b1b1a; --aiqd-panel-2: #232322;
  --aiqd-border: #2c2c2a; --aiqd-ink: #edeee9; --aiqd-ink-2: #b0b2a8; --aiqd-ink-3: #979990;
  --aiqd-ink-3-deco: #7c7e76;
  --aiqd-dream-text: #d8b654;
  --aiqd-tooltip-bg: #f2f3ee; --aiqd-tooltip-ink: #23251f;
  --aiqd-value: #78a34b; --aiqd-value-text: #a4cd7c; --aiqd-value-tint: rgba(120, 163, 75, 0.14);
  --aiqd-chip-on: #121212; /* dark ink on the brighter dark moss (6.9:1) */
  --aiqd-cost: #8a837c; --aiqd-agg: #4c4e48; --aiqd-deficit: #e05252; --aiqd-dream: #c9a03a;
  --aiqd-warn-ink: #e8c55b; --aiqd-warn-bg: #2a2513; --aiqd-warn-border: #4a4122;
  --aiqd-col-alpha: 0.82;
  --aiqd-part-1: #3c6da9; --aiqd-part-2: #25a6a6; --aiqd-part-3: #904e83;
  --aiqd-part-4: #7c8ed3; --aiqd-part-5: #9d5b18; --aiqd-part-6: #549bcf;
  --aiqd-part-7: #695da5; --aiqd-part-8: #a980c2; /* Dusk editorial, dark steps (six-checks PASS on #121212) */
  --aiqd-shadow: none; --aiqd-shadow-2: none;
}

/* ============================== HEADER ============================== */
.aiqd-tl-header { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.aiqd-tl-title { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
.aiqd-tl-units { color: var(--aiqd-ink-3); font-size: 11px; }
.aiqd-tl-vps { font-size: 22px; font-weight: 600; letter-spacing: -0.01em; }
.aiqd-tl-vps-lbl { color: var(--aiqd-ink-2); font-size: 14px; font-weight: 500; }
.aiqd-tl-coverage { color: var(--aiqd-ink-2); font-size: 13px; }
.aiqd-tl-coverage strong { color: var(--aiqd-ink); font-weight: 600; }
/* the dotted rule hugs the text (text-decoration, not border), so tall touch
   targets never show a detached underline */
.aiqd-tl-belief { background: none; border: 0; color: var(--aiqd-ink-2); cursor: pointer; font: inherit; font-size: 12px; padding: 0; text-decoration: underline dotted; text-underline-offset: 3px; }
.aiqd-tl-belief::before { content: "\00B7\2002"; color: var(--aiqd-ink-3-deco); text-decoration: none; display: inline-block; }
.aiqd-tl-belief--static { cursor: default; text-decoration: none; }
.aiqd-tl-framing { color: var(--aiqd-ink-3); font-size: 12px; margin-top: 2px; width: 100%; }
.aiqd-tl-priceframe { color: var(--aiqd-ink-2); font-size: 12px; margin-top: 6px; width: 100%; }
.aiqd-tl-priceframe strong { color: var(--aiqd-ink); font-weight: 600; }
.aiqd-tl-dream-banner {
  background: color-mix(in srgb, var(--aiqd-dream) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--aiqd-dream) 45%, transparent);
  border-radius: var(--aiqd-r-chip); color: var(--aiqd-dream-text); /* AA on the tint */
  font-size: 12px; font-weight: 500; margin-top: 8px; padding: 6px 10px; width: 100%;
}
.aiqd-tl-sr {
  border: 0; clip: rect(0 0 0 0); clip-path: inset(50%); height: 1px;
  margin: -1px; overflow: hidden; padding: 0; position: absolute; width: 1px;
}
.aiqd-tl-result { display: none; }

/* ============================== FLAGS ============================== */
.aiqd-tl-flags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.aiqd-tl-flags[hidden] { display: none; } /* the author flex rule must not defeat [hidden] */
.aiqd-tl-flag {
  align-items: center; white-space: nowrap; background: var(--aiqd-warn-bg); border: 1px solid var(--aiqd-warn-border);
  border-radius: 999px; color: var(--aiqd-warn-ink); display: inline-flex; font-size: 11px;
  font-weight: 500; gap: 5px; letter-spacing: 0.01em; padding: 3px 9px;
}
.aiqd-tl-flag::before { content: ""; background: currentColor; border-radius: 50%; height: 5px; width: 5px; }

/* ============================== CONTROLS ============================== */
.aiqd-tl-controls { border-top: 1px solid var(--aiqd-border); margin-top: 14px; padding-top: 14px; }
.aiqd-tl-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.aiqd-tl-chip {
  background: var(--aiqd-panel); border: 1px solid var(--aiqd-border); border-radius: 999px;
  color: var(--aiqd-ink-2); cursor: pointer; font: inherit; font-size: 12px; font-weight: 500;
  min-height: 30px; padding: 4px 12px; transition: background var(--aiqd-t-fast) var(--aiqd-ease),
  border-color var(--aiqd-t-fast) var(--aiqd-ease), color var(--aiqd-t-fast) var(--aiqd-ease);
}
.aiqd-tl-chip:hover { border-color: var(--aiqd-ink-3-deco); color: var(--aiqd-ink); }
.aiqd-tl-chip[aria-pressed="true"] {
  background: var(--aiqd-value-tint); border-color: var(--aiqd-value); color: var(--aiqd-value-text); font-weight: 600;
}
.aiqd-tl-chip--implies { border-style: dashed; }
.aiqd-tl-chip--dream[aria-pressed="true"] {
  background: color-mix(in srgb, var(--aiqd-dream) 12%, transparent);
  border-color: var(--aiqd-dream); color: var(--aiqd-warn-ink);
}
.aiqd-tl-believe { color: var(--aiqd-ink-2); font-size: 13px; margin: 10px 0 0; max-width: 64ch; }
.aiqd-tl-believe em { color: var(--aiqd-ink); font-style: normal; font-weight: 500; }

.aiqd-tl-selectors { display: grid; gap: 8px 20px; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-top: 12px; }
.aiqd-tl-selector { align-items: center; display: flex; gap: 8px; justify-content: space-between; }
.aiqd-tl-selector-name { align-items: center; display: inline-flex; font-size: 12px; font-weight: 500; gap: 6px; }
.aiqd-tl-part-dot { border-radius: 50%; display: inline-block; flex: none; height: 8px; width: 8px; }
.aiqd-tl-seg { background: var(--aiqd-panel); border: 1px solid var(--aiqd-border); border-radius: var(--aiqd-r-chip); display: inline-flex; padding: 2px; }
.aiqd-tl-seg button {
  background: transparent; border: 0; border-radius: 6px; color: var(--aiqd-ink-2); cursor: pointer;
  font: inherit; font-size: 12px; min-height: 26px; min-width: 44px; padding: 2px 10px;
  transition: background var(--aiqd-t-fast) var(--aiqd-ease), color var(--aiqd-t-fast) var(--aiqd-ease);
}
.aiqd-tl-seg button:hover { color: var(--aiqd-ink); }
.aiqd-tl-seg button[aria-pressed="true"] { background: var(--seg-tint); color: var(--aiqd-ink); font-weight: 600; }
.aiqd-tl-finding-dot { color: var(--aiqd-warn-ink); font-size: 11px; line-height: 0; margin-left: 2px; }
.aiqd-tl-transient { color: var(--aiqd-ink-2); font-size: 12px; margin-top: 8px; min-height: 1.2em; transition: opacity 400ms var(--aiqd-ease); }
.aiqd-tl-transient:empty { margin-top: 0; min-height: 0; }
.aiqd-tl-transient em { color: var(--aiqd-ink); font-style: normal; font-weight: 500; }

/* ============================== BAR (select + forecast badge) ============================== */
.aiqd-tl-bar { align-items: center; border-top: 1px solid var(--aiqd-border); display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between; margin-top: 14px; padding-top: 10px; }
/* badge-only bar (single-scenario payloads): no orphaned divider */
.aiqd-tl-bar--bare { border-top: 0; margin-top: 6px; padding-top: 0; }
.aiqd-tl-scensel {
  appearance: none; -webkit-appearance: none;
  background: var(--aiqd-panel) url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='8' height='5'%3E%3Cpath d='M0 0l4 5 4-5z' fill='%23888'/%3E%3C/svg%3E") no-repeat right 10px center;
  border: 1px solid var(--aiqd-border); border-radius: 999px; color: var(--aiqd-ink);
  cursor: pointer; font: inherit; font-size: 12px; font-weight: 500;
  max-width: 220px; min-height: 30px; padding: 4px 26px 4px 12px;
}
.aiqd-tl-scensel--mobileonly { display: none; }
.aiqd-tl-badge { white-space: nowrap; background: var(--aiqd-panel); border: 1px solid var(--aiqd-border); border-radius: 999px; color: var(--aiqd-ink-2); font-size: 10px; font-weight: 600; letter-spacing: 0.03em; padding: 2px 8px; text-transform: uppercase; }

/* ============================== LEGEND (compact canvas; JS toggles .show) ============================== */
.aiqd-tl-legend { display: none; flex-wrap: wrap; gap: 4px 14px; margin-top: 10px; }
.aiqd-tl-legend.show { display: flex; }
.aiqd-tl-badge--own { display: inline-block; margin-top: 10px; }
.aiqd-tl-badge--own[hidden] { display: none; }
.aiqd-tl-legend > span { align-items: center; color: var(--aiqd-ink-2); display: inline-flex; font-size: 11px; font-weight: 500; gap: 5px; }
.aiqd-tl-legend .lg-line { background: var(--aiqd-value); border-radius: 999px; display: inline-block; height: 3px; width: 14px; }
.aiqd-tl-legend .lg-val { color: var(--aiqd-ink); font-weight: 600; }
.aiqd-tl-legend .lg-title { color: var(--aiqd-ink-3); font-size: 10px; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase; }

/* ============================== CANVAS ============================== */
.aiqd-tl-canvas { margin-top: 10px; position: relative; }
.aiqd-tl-canvas svg { display: block; height: auto; width: 100%; }
.aiqd-tl svg text { paint-order: stroke; stroke: var(--aiqd-bg); stroke-width: 3px; stroke-linejoin: round; }
.aiqd-tl svg .lbl-tick { fill: var(--aiqd-ink-3); font-size: 11px; }
.aiqd-tl svg .lbl-tick-sub { fill: var(--aiqd-ink-3); font-size: 10px; font-style: italic; }
.aiqd-tl svg .lbl-end-name { fill: var(--aiqd-ink-2); font-size: 11px; font-weight: 500; }
.aiqd-tl svg .lbl-end-val { fill: var(--aiqd-ink); font-size: 11px; font-weight: 600; }
.aiqd-tl svg .lbl-total { fill: var(--aiqd-ink); font-size: 12px; font-weight: 600; }
.aiqd-tl svg .lbl-fcf { fill: var(--aiqd-value-text); font-size: 11px; font-weight: 600; }
.aiqd-tl svg .lbl-chiprow { fill: var(--aiqd-ink-3); font-size: 10px; }
.aiqd-tl svg .lbl-chip { fill: var(--aiqd-chip-on); font-size: 11px; font-weight: 600; paint-order: normal; stroke: none; }
.aiqd-tl svg .lbl-chip-neg { fill: #ffffff; }
.aiqd-tl svg .chip-bg { fill: var(--aiqd-value); }
.aiqd-tl svg .chip-bg-neg { fill: var(--aiqd-deficit); }
.aiqd-tl svg .lbl-cagr { fill: var(--aiqd-value-text); font-size: 12px; font-weight: 600; }
.aiqd-tl svg .lbl-cagr-sub { fill: var(--aiqd-ink-3); font-size: 10px; }
.aiqd-tl svg .lbl-neg-val { fill: var(--aiqd-deficit); font-size: 10px; font-weight: 600; }
.aiqd-tl-scalebreak { fill: var(--aiqd-ink-3); font-size: 11px; font-style: italic; }
.aiqd-tl-year { outline: none; }
.aiqd-tl-year rect.seg { transition: opacity var(--aiqd-t-fast) var(--aiqd-ease); }
.aiqd-tl svg.is-hot .aiqd-tl-year:not(.is-active) { opacity: 0.45; }
.aiqd-tl svg .aiqd-tl-year { transition: opacity var(--aiqd-t-fast) var(--aiqd-ease); }
.aiqd-tl svg .aiqd-tl-year:focus-visible .col-hit { stroke: var(--aiqd-value); stroke-width: 2; }

/* ============================== FOOTER ============================== */
.aiqd-tl-delta { color: var(--aiqd-ink-2); font-size: 12px; margin-top: 8px; min-height: 1.2em; opacity: 0; transition: opacity 400ms var(--aiqd-ease); }
.aiqd-tl-delta.show { opacity: 1; }
.aiqd-tl-footnotes { border-top: 1px solid var(--aiqd-border); color: var(--aiqd-ink-2); font-size: 11px; margin-top: 12px; padding-top: 8px; }
.aiqd-tl-footnotes p { margin: 2px 0; }
.aiqd-tl-stamps { color: var(--aiqd-ink-3); display: flex; flex-wrap: wrap; font-size: 11px; gap: 4px 14px; justify-content: space-between; margin-top: 6px; }

/* ============================== TOOLTIP ============================== */
.aiqd-tl-tip {
  background: var(--aiqd-tooltip-bg); border-radius: 8px; box-shadow: var(--aiqd-shadow-2);
  color: var(--aiqd-tooltip-ink); font-size: 12px; left: 0; line-height: 1.45; max-width: 300px;
  opacity: 0; padding: 8px 10px; pointer-events: none; position: absolute; top: 0; visibility: hidden;
  transition: opacity var(--aiqd-t-fast) var(--aiqd-ease), visibility 0s linear var(--aiqd-t-fast); z-index: 30;
}
.aiqd-tl-tip.show { opacity: 1; transition-delay: 0s; visibility: visible; }
.aiqd-tl-tip .t-name { font-weight: 600; }
.aiqd-tl-tip .t-sub { opacity: 0.75; }
.aiqd-tl-tip .t-row { align-items: baseline; display: flex; gap: 8px; justify-content: space-between; white-space: nowrap; }
.aiqd-tl-tip .t-dot { border-radius: 50%; display: inline-block; height: 7px; margin-right: 5px; width: 7px; }
.aiqd-tl-tip .t-total { border-top: 1px solid color-mix(in srgb, var(--aiqd-tooltip-ink) 25%, transparent); margin-top: 4px; padding-top: 4px; }

/* ============================== STATES ============================== */
.aiqd-tl-skeleton { display: grid; gap: 12px; }
.aiqd-tl-skeleton .sk { animation: aiqd-tl-shimmer 1.4s ease-in-out infinite; background: linear-gradient(90deg, var(--aiqd-panel) 25%, var(--aiqd-panel-2) 50%, var(--aiqd-panel) 75%); background-size: 200% 100%; border-radius: 8px; }
@keyframes aiqd-tl-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.aiqd-tl-error { border: 1px solid var(--aiqd-border); border-radius: var(--aiqd-r-card); padding: 20px; }
.aiqd-tl-error h3 { font-size: 14px; font-weight: 600; margin: 0 0 6px; }
.aiqd-tl-error p { color: var(--aiqd-ink-2); font-size: 13px; margin: 0 0 8px; }
.aiqd-tl-error code { background: var(--aiqd-panel); border-radius: 4px; color: var(--aiqd-ink-2); display: inline-block; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; padding: 2px 6px; }

.aiqd-tl :focus-visible { outline: 2px solid var(--aiqd-value); outline-offset: 2px; }

/* ============================== RESPONSIVE ============================== */
/* control collapse at 480 per method §5; the canvas-compact threshold (~520,
   end labels -> legend) lives in JS and toggles .aiqd-tl-legend.show */
@container (max-width: 480px) {
  .aiqd-tl { padding: 14px 14px 10px; }
  .aiqd-tl-vps { font-size: 19px; }
  .aiqd-tl-selectors { grid-template-columns: 1fr; }
  /* chips collapse to the story select on phones */
  .aiqd-tl-chips { display: none; }
  .aiqd-tl-scensel--mobileonly { display: inline-block; }
  /* the conclusion never hides behind the fold */
  .aiqd-tl-result { display: block; background: var(--aiqd-panel); border: 1px solid var(--aiqd-border);
    border-radius: var(--aiqd-r-chip); color: var(--aiqd-ink); font-size: 13px; font-weight: 600;
    margin-top: 10px; padding: 8px 12px; }
  /* touch ergonomics: ≥44px targets */
  .aiqd-tl-chip { min-height: 44px; }
  .aiqd-tl-seg button { min-height: 44px; min-width: 52px; }
  .aiqd-tl-belief { min-height: 44px; }
  .aiqd-tl-scensel { min-height: 44px; }
}

/* ============================== REDUCED MOTION ============================== */
@media (prefers-reduced-motion: reduce) {
  .aiqd-tl *, .aiqd-tl *::before, .aiqd-tl *::after { animation: none !important; transition: none !important; }
}
