/**
 * css/views/report-timeline.css
 * -----------------------------
 * Right-edge rail that indexes every audit report card in the conversation.
 * ChatGPT-style dot navigation, but each node is a snapshot with its own stats.
 */

.report-timeline {
  position: absolute;
  top: 88px;
  right: 8px;
  bottom: 226px;
  width: 46px;
  z-index: 32;
  display: flex;
  justify-content: center;
  pointer-events: none;
}

.report-timeline.is-empty {
  display: none;
}

.rt-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  max-height: 100%;
  pointer-events: auto;
  /* A finger on the rail scrubs snapshots, so the browser must not claim the
     vertical drag as a page scroll part-way through the preview. */
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Snapshot counter chip */
.rt-count {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(13, 18, 31, 0.9);
  border: 1px solid var(--border-color);
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.6rem;
  line-height: 1;
  flex-shrink: 0;
}

.rt-count i {
  font-size: 0.55rem;
  color: var(--accent-emerald);
}

/* Overflow chip when older snapshots are windowed out of the rail */
.rt-more {
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.55rem;
  color: var(--text-dim);
  padding: 1px 4px;
  border-radius: 6px;
  border: 1px dashed var(--border-color);
  line-height: 1.3;
}

/* Scrollable dot track */
.rt-track {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  padding: 8px 0;
  /* Must stay visible so hover tooltips can extend left over the conversation. */
  overflow: visible;
  scrollbar-width: none;
  -ms-overflow-style: none;
  flex: 1 1 auto;
  min-height: 0;
}

.rt-track::-webkit-scrollbar {
  display: none;
}

/* Vertical spine behind the dots */
.rt-track::before {
  content: '';
  position: absolute;
  top: 6px;
  bottom: 6px;
  left: 50%;
  width: 1px;
  transform: translateX(-50%);
  background: linear-gradient(
    to bottom,
    transparent,
    var(--border-color) 6%,
    var(--border-color) 94%,
    transparent
  );
  pointer-events: none;
}

/* ─── Nodes ────────────────────────────────────────────────────────────────── */
.rt-node {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  /* Nodes share the track evenly. Density is decided in JS from the measured
     rail height, so this never needs to scroll and dots never collide. */
  flex: 1 1 0;
  min-height: 12px;
  max-height: 22px;
  height: auto;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  z-index: 1;
  -webkit-tap-highlight-color: transparent;
}

.rt-dot {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--rt-color, var(--accent-emerald));
  border: 1px solid rgba(7, 9, 14, 0.9);
  box-shadow: 0 0 0 0 rgba(0, 0, 0, 0);
  /* --rt-scale is written per node by rtApplyDock(); every other visual change
     in the rail is derived from it so the swell stays perfectly in sync. */
  transform: scale(var(--rt-scale, 1));
  transition: transform 0.14s cubic-bezier(0.22, 1, 0.36, 1),
    box-shadow 0.18s ease, opacity 0.18s ease;
  will-change: transform;
  opacity: 0.62;
}

/* Grade letter lives inside the dot and only fades in once the dot is big
   enough to hold it legibly. */
.rt-dot-grade {
  font-family: var(--font-mono);
  font-size: 5.2px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.02em;
  color: #07090e;
  opacity: var(--rt-fade, 0);
  transition: opacity 0.12s ease;
  pointer-events: none;
  user-select: none;
}

/* Elapsed-hour tick label — only for the hovered or current node, so tight
   spacing never causes label collisions. */
.rt-tick {
  position: absolute;
  right: 100%;
  margin-right: 4px;
  font-family: var(--font-mono);
  font-size: 0.56rem;
  color: var(--text-dim);
  opacity: 0;
  transform: translateX(4px);
  transition: opacity 0.16s ease, transform 0.16s ease;
  pointer-events: none;
  white-space: nowrap;
}

.rt-node.is-active .rt-tick {
  opacity: 1;
  transform: translateX(0);
}

/* While the hover card is up the elapsed time is already inside it, and the
   tick would collide with the card's edge, so the card takes precedence. */
.rt-node.is-hot .rt-tick,
.rt-node:hover .rt-tick,
.rt-node:focus-visible .rt-tick {
  opacity: 0;
}

/* Size changes are owned by rtApplyDock(); these rules only add the glow ring
   and full opacity, otherwise a CSS scale would fight the dock's inline scale.
   The ring follows .is-hot rather than :hover so the ring and the swell can
   never disagree when two swollen dots overlap. */
.rt-node.is-hot .rt-dot,
.rt-node:focus-visible .rt-dot {
  opacity: 1;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--rt-color) 22%, transparent);
}

.rt-node.is-active .rt-dot {
  opacity: 1;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--rt-color) 26%, transparent);
}

.rt-node:focus-visible {
  outline: none;
}

.rt-node.is-active .rt-tick {
  color: var(--text-muted);
}

/* ─── Hover / focus card ───────────────────────────────────────────────────── */
/* One card for the whole rail, created by rtHoverCard() and positioned by JS.
   It lives on <body> rather than inside a node: the rail rebuilds its
   innerHTML every time a snapshot lands, and a card nested in a dot was being
   destroyed mid-hover (the card would vanish until the cursor moved again).
   Being an overlay also means no ancestor can clip it. */
.rt-tooltip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 90;
  width: 208px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(13, 18, 31, 0.98);
  border: 1px solid var(--border-color);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.12s ease, visibility 0.12s ease;
  will-change: opacity;
}

.rt-hover-card.is-visible {
  opacity: 1;
  visibility: visible;
}

.rt-tip-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.rt-tip-grade {
  font-size: 0.78rem;
  font-weight: 800;
}

.rt-tip-verdict {
  margin-top: 4px;
  font-size: 0.68rem;
  line-height: 1.35;
  color: var(--text-muted);
}

.rt-tip-risk {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-top: 8px;
  font-size: 0.64rem;
  color: var(--text-dim);
}

.rt-tip-risk strong {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.rt-tip-bar {
  height: 3px;
  margin-top: 5px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.rt-tip-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
}

.rt-tip-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--border-color);
}

.rt-tip-stats div {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.rt-tip-stats span {
  font-size: 0.55rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.rt-tip-stats strong {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-main);
}

.rt-tip-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 0.58rem;
  color: var(--text-dim);
}

/* ─── Card flash when jumping to a snapshot ────────────────────────────────── */
@keyframes rtFlashPulse {
  0% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.45);
  }
  60% {
    box-shadow: 0 0 0 6px rgba(16, 185, 129, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
  }
}

.chat-msg.rt-flash .audit-report-container {
  animation: rtFlashPulse 1.3s ease-out;
  border-color: var(--border-accent);
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
/* Honour reduced-motion by snapping the dock instead of easing through it. */
@media (prefers-reduced-motion: reduce) {
  .rt-dot,
  .rt-dot-grade,
  .rt-tick,
  .rt-tooltip {
    transition-duration: 0.01ms !important;
  }

  .chat-msg.rt-flash .audit-report-container {
    animation: none;
  }
}

/* The rail stays available down to laptop widths; the message column reserves
   room for it so dots never sit on top of report text. */
@media (max-width: 1320px) {
  .report-timeline {
    right: 2px;
    width: 32px;
  }

  .rt-tooltip {
    width: 190px;
  }

  .chat-workspace.has-rt .messages-column-v4 {
    padding-right: 28px;
  }
}

/* The rail stays available at every width the rail is useful at. Hiding it
   entirely below 900px made the feature look broken on any window narrower
   than a maximised desktop one, so it now slims down instead of disappearing:
   the dots are the only way to jump between snapshots. */
@media (max-width: 900px) {
  .report-timeline {
    right: 0;
    width: 26px;
  }

  .rt-rail {
    gap: 6px;
  }

  /* The counter and overflow chips are wider than this strip, and being inside
     a centred column they used to widen the whole rail past the viewport edge.
     Drop the icon and tighten the padding so they fit the dots. */
  .rt-count {
    padding: 2px 4px;
    font-size: 0.55rem;
  }

  .rt-count i {
    display: none;
  }

  .rt-more {
    padding: 0 3px;
    font-size: 0.5rem;
  }

  .rt-node {
    width: 26px;
  }

  .rt-tooltip {
    width: 172px;
  }

  .chat-workspace.has-rt .messages-column-v4 {
    padding-right: 22px;
  }
}

/* Phones: the rail is the fastest way to reach a report on a small screen, so
   it stays — slimmed to a bare strip of dots. The counter chips cannot fit in
   this width, and the rail keeps a finger-width target while costing the
   conversation as little room as possible. */
@media (max-width: 560px) {
  .report-timeline {
    right: 0;
    width: 22px;
  }

  .rt-rail {
    gap: 4px;
  }

  .rt-node {
    width: 22px;
    min-height: 14px;
  }

  .rt-count,
  .rt-more {
    display: none;
  }

  .rt-tooltip {
    width: 158px;
  }

  .chat-workspace.has-rt .messages-column-v4 {
    padding-right: 18px;
  }
}

/* While a finger is holding the rail the whole page is a scrub surface: stop
   iOS/Android opening a selection or callout under the finger. */
body.rt-scrubbing {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
