/* ==========================================================================
   news_timeline.css — Market timeline component (Dashboard + Markets + Desk)
   Single source of truth for `.dash-tl-*`. Loaded globally from base.html so
   every mount point of [data-news-timeline] gets the same tape.

   Shape: time gutter | kind rail | headline. Paper plates, hairline edges,
   no glass, no nested bubbles. Rows are quiet until you touch them.
   ========================================================================== */

/* ---------- live status ---------- */
.dash-live-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  white-space: nowrap;
}
.dash-live-dot {
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--success);
}
@media (prefers-reduced-motion: no-preference) {
  .dash-live-dot { animation: oc-tl-breathe 2.6s var(--ease-out, ease) infinite; }
}
.dash-live-meta.is-stale .dash-live-dot {
  background: var(--text-dim);
  animation: none;
}
.dash-live-meta.is-error .dash-live-dot {
  background: var(--danger);
  animation: none;
}
@keyframes oc-tl-breathe {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ---------- toolbar ---------- */
.dash-tl-toolbar {
  display: flex;
  flex-direction: row;
  align-items: center;
  flex: 0 0 auto;
  padding: 6px 12px 8px;
  border-bottom: 1px solid var(--border-muted);
}
/* One row: the All / Market / Watchlist switch, then the kind filters.
   Important stays at the right end. */
.dash-tl-scopes {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
}
.dash-tl-switch {
  display: inline-flex;
  align-items: center;
  flex: none;
  gap: 2px;
  min-width: 0;
}
.dash-tl-kinds {
  display: flex;
  flex: none;
  flex-wrap: nowrap;
  align-items: center;
  gap: 2px;
}
.dash-tl-kinds .dash-tl-chip {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 8px;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1;
  text-transform: none;
}
.dash-tl-tab,
.dash-tl-imp,
.dash-tl-chip {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1;
  cursor: pointer;
  border-radius: 6px;
  transition: background var(--dur-ui, .16s) var(--ease-out, ease),
              color var(--dur-ui, .16s) var(--ease-out, ease);
}
.dash-tl-tab,
.dash-tl-imp {
  height: 26px;
  padding: 0 10px;
}
.dash-tl-chip { padding: 4px 8px; }
.dash-tl-tab:hover,
.dash-tl-imp:hover,
.dash-tl-chip:hover {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--text-primary) 6%, transparent);
}
.dash-tl-tab.is-active {
  color: var(--text-primary);
  background: var(--bg-elevated-2);
  font-weight: 600;
}
.dash-tl-chip.is-active {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  font-weight: 600;
}
.dash-tl-imp {
  margin-left: auto;
  white-space: nowrap;
}
.dash-tl-imp.is-active {
  color: var(--warning);
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  font-weight: 600;
}
.dash-tl-tab:focus-visible,
.dash-tl-imp:focus-visible,
.dash-tl-chip:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
}

/* ---------- scroll body ---------- */
.dash-tl-body {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  min-height: 200px;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  scroll-behavior: smooth;
  padding: 0 10px 12px !important;
  box-sizing: border-box;
  -webkit-overflow-scrolling: touch;
}
.dash-tl-body .dash-loading,
.dash-tl-body .dash-empty,
.dash-tl-state {
  padding: 22px 8px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  text-align: center;
}

/* "{n} new" — sticky inside the scroller, so showing it shifts nothing */
.dash-tl-new {
  position: sticky;
  top: 6px;
  z-index: 5;
  display: block;
  margin: 6px auto 0;
  padding: 5px 12px;
  appearance: none;
  border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--border-default));
  border-radius: var(--r-full, 999px);
  background: color-mix(in srgb, var(--accent) 16%, var(--bg-elevated));
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: var(--fs-sm);
  font-weight: 500;
  line-height: 1.3;
  cursor: pointer;
  transition: background var(--dur-ui, .16s) var(--ease-out, ease);
}
.dash-tl-new:hover { background: color-mix(in srgb, var(--accent) 26%, var(--bg-elevated)); }
.dash-tl-new:focus-visible { outline: 1px solid var(--accent); outline-offset: 2px; }
.dash-tl-new[hidden] { display: none !important; }
@media (prefers-reduced-motion: no-preference) {
  .dash-tl-new:not([hidden]) { animation: oc-tl-chip-in 240ms var(--ease-out, ease) both; }
}
@keyframes oc-tl-chip-in {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: none; }
}

.dash-tl-entries {
  position: relative;
  min-width: 0;
  max-width: 100%;
  padding: 0;
  box-sizing: border-box;
}

/* ---------- day separator ---------- */
.dash-tl-date-sep {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 10px 4px 6px 0;
  background: var(--bg-elevated);
}
.dash-tl-date-sep span {
  font-size: var(--fs-sm);
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0;
}
.dash-tl-date-sep::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-muted);
}

/* ---------- entry ---------- */
.dash-tl-entry {
  position: relative;
  display: grid;
  /* 4.6rem holds a 12-hour clock ("10:23 AM") without touching the rail. */
  grid-template-columns: 4.6rem 12px minmax(0, 1fr);
  column-gap: 8px;
  align-items: start;
  margin: 0;
  padding: 7px 8px 7px 4px;
  border-radius: 6px;
  color: inherit;
  text-decoration: none;
  max-width: 100%;
  box-sizing: border-box;
  transition: background var(--dur-ui, .16s) var(--ease-out, ease);
}
.dash-tl-entry:hover,
.dash-tl-entry:focus-within,
.dash-tl-entry.is-open {
  background: color-mix(in srgb, var(--text-primary) 5%, transparent);
}
.dash-tl-entry:focus-visible {
  outline: 1px solid color-mix(in srgb, var(--accent) 55%, transparent);
  outline-offset: 1px;
}

.dash-tl-entry__time {
  grid-column: 1;
  padding: 1px 2px 0 0;
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.35;
  color: var(--text-muted);
  text-align: right;
  white-space: nowrap;
}

/* rail: one continuous hairline through the tape, dot punched out of it */
.dash-tl-entry__rail {
  grid-column: 2;
  position: relative;
  align-self: stretch;
  width: 12px;
  min-height: 20px;
}
.dash-tl-entry__rail::before {
  content: "";
  position: absolute;
  left: 5px;
  top: -7px;
  bottom: -7px;
  width: 1px;
  background: var(--border-muted);
}
.dash-tl-entry:first-child .dash-tl-entry__rail::before { top: 4px; }
.dash-tl-entry:last-child .dash-tl-entry__rail::before { bottom: auto; height: 14px; }
.dash-tl-entry__dot {
  position: absolute;
  left: 2px;
  top: 5px;
  z-index: 1;
  width: 7px;
  height: 7px;
  border: 0;
  border-radius: 50%;
  background: var(--text-dim);
  box-shadow: 0 0 0 3px var(--bg-elevated);
  box-sizing: border-box;
  transition: transform var(--dur-ui, .16s) var(--ease-out, ease);
}
.dash-tl-entry:hover .dash-tl-entry__dot {
  transform: scale(1.25);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--text-primary) 5%, var(--bg-elevated));
}
.dash-tl-entry__dot--market   { background: var(--text-dim); }
.dash-tl-entry__dot--ticker   { background: var(--info); }
.dash-tl-entry__dot--macro    { background: var(--clr-purple); }
.dash-tl-entry__dot--earnings { background: var(--success); }
.dash-tl-entry__dot--grade    { background: var(--warning); }

/* First live item: quiet breath so the tape's leading edge is findable.
   The ring is a filled disc that grows with `transform` and fades with
   `opacity`, so it runs on the compositor. Growing a box-shadow instead
   repainted the page every frame, for as long as the dashboard was open. */
.dash-tl-entries > .dash-tl-entry:first-of-type .dash-tl-entry__dot {
  background: var(--accent);
}
.dash-tl-entries > .dash-tl-entry:first-of-type .dash-tl-entry__dot::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 7px;
  height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  pointer-events: none;
  background: color-mix(in srgb, var(--accent) 45%, transparent);
  opacity: 0;
}
@media (prefers-reduced-motion: no-preference) {
  .dash-tl-entries > .dash-tl-entry:first-of-type .dash-tl-entry__dot {
    animation: oc-tl-breath 2.4s ease-in-out infinite;
  }
  .dash-tl-entries > .dash-tl-entry:first-of-type .dash-tl-entry__dot::after {
    animation: oc-tl-breath-ring 2.4s ease-out infinite;
  }
}
@keyframes oc-tl-breath {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.28); }
}
/* 7px out on every side: the disc grows from 7px to 21px across. */
@keyframes oc-tl-breath-ring {
  0% { transform: scale(1); opacity: 0.9; }
  70% { transform: scale(3); opacity: 0; }
  100% { transform: scale(3); opacity: 0; }
}

.dash-tl-entry__main {
  grid-column: 3;
  min-width: 0;
  max-width: 100%;
  padding-right: 2px;
}
.dash-tl-entry__head { display: none; }  /* legacy wrapper, no longer emitted */

.dash-tl-entry__title {
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  line-height: 1.35;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.dash-tl-entry__title-link {
  color: inherit;
  text-decoration: none;
}
.dash-tl-entry__title-link:hover {
  color: var(--accent);
  text-decoration: none;
}
.dash-tl-entry__title-link:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 1px;
  border-radius: 2px;
}
.dash-tl-entry__snippet {
  margin-top: 2px;
  font-size: var(--fs-xs);
  line-height: 1.4;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
[data-ntl-variant="hero"] .dash-tl-entry__snippet { -webkit-line-clamp: 2; }
.dash-tl-entry.is-open .dash-tl-entry__title { -webkit-line-clamp: 4; }
.dash-tl-entry.is-open .dash-tl-entry__snippet { -webkit-line-clamp: 8; }

.dash-tl-entry__meta {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  margin-top: 4px;
  min-width: 0;
  overflow: hidden;
}
.dash-tl-entry__site,
.dash-tl-entry__age {
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 12em;
}
.dash-tl-entry__kind {
  flex: none;
  padding: 0;
  background: transparent;
  border-radius: 0;
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1.3;
  letter-spacing: 0;
  text-transform: lowercase;
  color: var(--text-dim);
  white-space: nowrap;
}
.dash-tl-entry__kind--ticker   { color: var(--info); }
.dash-tl-entry__kind--macro    { color: var(--clr-purple); }
.dash-tl-entry__kind--earnings { color: var(--success); }
.dash-tl-entry__kind--grade    { color: var(--warning); }

.dash-tl-entry__syms {
  display: inline-flex;
  align-items: center;
  flex: none;
  gap: 3px;
  max-width: 46%;
  overflow: hidden;
}
.dash-tl-sym {
  display: inline-block;
  flex: none;
  height: 16px;
  padding: 0 5px;
  border-radius: 4px;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
  font-family: var(--font-sans);
  font-variant-numeric: tabular-nums;
  font-size: calc(10px * var(--ui-font-scale, 1));
  font-weight: var(--fw-semibold);
  line-height: 16px;
  text-decoration: none;
  white-space: nowrap;
  max-width: 5.5em;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background var(--dur-ui, .16s) var(--ease-out, ease);
}
.dash-tl-sym:hover { background: color-mix(in srgb, var(--accent) 24%, transparent); }

/* ---------- row actions (hover / focus / opened) ---------- */
/* Actions ride the bottom-right, level with the meta line — never over the
   headline, and no reflow when they appear. */
.dash-tl-entry__actions {
  position: absolute;
  right: 6px;
  bottom: 5px;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px;
  border-radius: 6px;
  border: 1px solid var(--border-muted);
  background: var(--bg-elevated);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-ui, .16s) var(--ease-out, ease);
}
.dash-tl-entry:hover .dash-tl-entry__actions,
.dash-tl-entry:focus-within .dash-tl-entry__actions,
.dash-tl-entry.is-open .dash-tl-entry__actions {
  opacity: 1;
  pointer-events: auto;
}
.dash-tl-act {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  line-height: 1;
  padding: 4px 7px;
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.dash-tl-act:hover {
  color: var(--text-primary);
  background: color-mix(in srgb, var(--text-primary) 8%, transparent);
}
.dash-tl-act:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }
.dash-tl-act.is-done { color: var(--success); }

/* ---------- arrival: slide the tape down; hold a wash 10s, then fade ---------- */
.dash-tl-entry.is-entering {
  overflow: hidden;
  will-change: height;
}
.dash-tl-entry.is-new {
  background: color-mix(in srgb, var(--accent) 10%, transparent);
}
@media (prefers-reduced-motion: no-preference) {
  .dash-tl-entry.is-new { animation: oc-tl-arrive 10s var(--ease-out, ease) both; }
}
@keyframes oc-tl-arrive {
  0%, 85% {
    background: color-mix(in srgb, var(--accent) 10%, transparent);
  }
  100% {
    background: transparent;
  }
}

/* ---------- narrow / phone ---------- */
@media (max-width: 560px) {
  .dash-tl-entry {
    grid-template-columns: 4.2rem 10px minmax(0, 1fr);
    column-gap: 6px;
  }
  .dash-tl-entry__actions { display: none; }
  .dash-tl-entry__site { max-width: 8em; }
  .dash-tl-body { padding: 0 6px 12px !important; }
}

/* ==========================================================================
   Hero variant — the Markets go-to tape under the chart. Larger type,
   thicker rail, roomier rows; same component, one scale up.
   ========================================================================== */
[data-ntl-variant="hero"] .dash-tl-body { padding: 4px 12px 16px !important; }
[data-ntl-variant="hero"] .dash-tl-entry {
  grid-template-columns: 5.2rem 16px minmax(0, 1fr);
  column-gap: 12px;
  padding: 11px 10px 11px 4px;
  border-radius: 8px;
}
[data-ntl-variant="hero"] .dash-tl-entry__time {
  padding-top: 3px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
}
[data-ntl-variant="hero"] .dash-tl-entry__rail { width: 16px; }
[data-ntl-variant="hero"] .dash-tl-entry__rail::before {
  left: 7px;
  width: 2px;
  background: color-mix(in srgb, var(--text-primary) 14%, var(--border-muted));
}
[data-ntl-variant="hero"] .dash-tl-entry__dot {
  left: 3px;
  top: 8px;
  width: 10px;
  height: 10px;
  box-shadow: 0 0 0 4px var(--bg-elevated);
}
[data-ntl-variant="hero"] .dash-tl-entry:hover .dash-tl-entry__dot {
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--text-primary) 5%, var(--bg-elevated));
}
[data-ntl-variant="hero"] .dash-tl-entry__title {
  font-size: var(--fs-md);
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.4;
  -webkit-line-clamp: 3;
}
[data-ntl-variant="hero"] .dash-tl-entry__snippet {
  margin-top: 5px;
  font-size: var(--fs-sm);
  line-height: 1.45;
  color: var(--text-secondary);
}
[data-ntl-variant="hero"] .dash-tl-entry__meta { margin-top: 6px; }
[data-ntl-variant="hero"] .dash-tl-date-sep { padding: 16px 8px 8px 0; }
[data-ntl-variant="hero"] .dash-tl-date-sep span {
  font-size: var(--fs-sm);
  color: var(--text-primary);
}
[data-ntl-variant="hero"] .dash-tl-entry__actions { right: 8px; bottom: 8px; }


/* ==========================================================================
   Off-screen work (Phase 5)
   The tape holds up to 80 rows. content-visibility lets the browser skip
   layout and paint for rows nobody is looking at; contain-intrinsic-size
   supplies a placeholder height so the scrollbar does not jump as they come
   in and out of view.
   ========================================================================== */
.dash-tl-entry {
  content-visibility: auto;
  contain-intrinsic-size: auto 76px;
}
[data-ntl-variant="hero"] .dash-tl-entry {
  contain-intrinsic-size: auto 104px;
}

/* First paint only: rows arrive in sequence instead of all at once. The class
   comes off once the run finishes, so a poll-driven re-render never replays
   it; prepended rows keep their own arrival animation. */
@media (prefers-reduced-motion: no-preference) {
  .dash-tl-entries.is-first-paint .dash-tl-entry:nth-child(-n+14) {
    animation: oc-tl-stagger var(--dur-ui, 160ms) var(--ease-out, ease) both;
    animation-delay: calc((var(--row, 0) - 1) * 22ms);
  }
}
@keyframes oc-tl-stagger {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: none; }
}

/* ==========================================================================
   Phase 6 — the shape of the news that has not arrived yet
   --------------------------------------------------------------------------
   A skeleton row is the same height as a real one, so the list does not grow
   from one line to twenty when the fetch lands.
   ========================================================================== */
.dash-tl-entry.is-skeleton {
  pointer-events: none;
  cursor: default;
  min-height: 52px;
  padding-block: 10px;
  display: flex;
  align-items: center;
}
.dash-tl-entry.is-skeleton::before,
.dash-tl-entry.is-skeleton::after { content: none; }
.dash-tl-entry.is-skeleton .oc-sk { --oc-sk-gap: 7px; }
.dash-tl-entry.is-skeleton .oc-sk-line:last-child { --w: 38%; }

/* ---- Agent enrichment (M9) --------------------------------------------
   A summary written to say what happened and why it matters reads as prose,
   not as a truncated wire lede, so it gets normal text colour rather than the
   dimmed treatment a clipped snippet earns. */
.dash-tl-entry__snippet.is-ai {
  color: var(--text-secondary);
  font-style: normal;
}
.dash-tl-entry__chips {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
.dash-tl-chip {
  font-size: 10px;
  line-height: 1.6;
  padding: 0 5px;
  border-radius: 4px;
  background: var(--bg-elevated-2);
  color: var(--text-muted);
  text-transform: lowercase;
  white-space: nowrap;
}
/* The same story from three wires collapses to one row; this is the count of
   what was folded in, not a badge worth shouting about. */
.dash-tl-chip--dupes {
  background: var(--accent-muted);
  color: var(--accent);
  cursor: help;
}
