/* ════════════════════════════════════════════════════════════════════
   Hint primitive — the inline `?` glyph + popover/bottom-sheet tooltip
   ────────────────────────────────────────────────────────────────────
   Shape:

     <span class="hint" tabindex="0" role="button"
           aria-describedby="my-tip-id">?
       <span class="hint-tip" id="my-tip-id" role="tooltip">
         body html …
       </span>
     </span>

   Desktop (≥ 720px): hover/focus pops a 360px-wide popover above the
   glyph. Mobile (< 720px): tap toggles a bottom-sheet pinned to the
   viewport bottom — full width minus 12px gutters, never clips, mirrors
   familiar mobile UX. The toggle behaviour is wired in
   js/components/hint.js (initHints() runs once at boot).

   Body conventions (rendered inside `.hint-tip`):
     .tip-section          ← horizontal-rule separated block
     .tip-section-head     ← header line (label + weight) for rubrics
     .tip-rows             ← flex-column of band rows
     .tip-row              ← key/value row
     .tip-row .k           ← key column (muted, nowrap on desktop)
     .tip-row.is-active    ← highlighted band (uses --hint-accent)
     .tip-tier .good/.warn/.risk    ← coloured pill badge
     .tip-formula          ← monospace box naming the calculation
     .hint-term            ← inline term with a coloured dot. Pass a
                              colour via --hint-term-color (e.g. for
                              "uPNL •" vs "rPNL •" inside chart hints).
   ════════════════════════════════════════════════════════════════════ */

.hint {
  position: relative;
  display: inline-grid; place-content: center;
  width: 14px; height: 14px;
  /* Force line-height: 1 so inherited line-height from parents (which
     varies — KPI labels, headings, body) cannot inflate the glyph's
     line-box and push the "?" off the geometric centre of the circle.
     Without this, the same hint icon renders centred in some surfaces
     and visibly high/low in others. */
  line-height: 1;
  font-family: var(--font-mono);
  font-size: 9px; font-weight: 600;
  color: var(--muted-foreground);
  background: transparent;
  border: 1px solid var(--border-strong);
  border-radius: 50%;
  cursor: help;
  text-align: center;
  text-transform: none; letter-spacing: 0;
  transition: color .15s, border-color .15s, background .15s;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}
.hint:hover, .hint:focus-visible, .hint.is-open {
  color: var(--foreground);
  border-color: var(--ring);
  background: var(--surface-tinted, rgba(255,255,255,.04));
  outline: none;
}

.hint-tip {
  position: absolute;
  top: calc(100% + 8px); left: calc(50% + var(--hint-shift, 0px));
  transform: translateX(-50%) translateY(-4px);
  /* 360px so the longest rubric row ("< 5 / Concentrated — heavy
     single-ticker risk") fits on one line. .tip-row .k below is also
     pinned `white-space: nowrap` so the short range labels never break. */
  width: 360px; max-width: 80vw;
  padding: 10px 12px;
  background: var(--popover); color: var(--popover-foreground);
  border: 1px solid var(--border); border-radius: var(--radius);
  font-family: var(--font-mono);
  font-size: 11px; font-weight: 400;
  line-height: 1.5;
  letter-spacing: 0;
  text-transform: none;
  text-align: left;
  white-space: normal;
  opacity: 0; pointer-events: none;
  transition: opacity .12s ease, transform .12s ease;
  z-index: 60;
}
.hint:hover .hint-tip,
.hint:focus-visible .hint-tip,
.hint.is-open .hint-tip {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

/* Top layer — while a tip is shown, hint.js promotes it with the Popover
   API (popover="manual") so no ancestor's stacking context (a bento cell's
   z-index, a hover transform) can let a neighbouring card or chart paint
   over it, and writes `left` / `top` in viewport px. These rules undo the
   UA popover sheet (inset: 0 + margin: auto centring, overflow: auto). The
   horizontal centring is baked into those coordinates, so only the 4px
   slide stays a transform. left / top 0 is the measuring origin: the full
   viewport width is available while hint.js reads the tip's size. */
.hint-tip:popover-open {
  position: fixed;
  inset: auto;
  top: 0; left: 0;
  margin: 0;
  overflow: visible;
  transform: translateY(-4px);
}
.hint:hover > .hint-tip:popover-open,
.hint:focus-visible > .hint-tip:popover-open,
.hint.is-open > .hint-tip:popover-open {
  transform: translateY(0);
}
/* Entering the top layer flips the tip from display: none, which leaves no
   before-change style to fade from; start the fade-in explicitly. */
@starting-style {
  .hint:is(:hover, :focus-visible, .is-open) > .hint-tip:popover-open {
    opacity: 0;
    transform: translateY(-4px);
  }
}

/* Body internals — deliberately scoped under .hint-tip so authors can
   reuse the .tip-row / .tip-section names without leaking style elsewhere. */
.hint-tip .tip-section {
  margin-top: 8px; padding-top: 8px;
  border-top: 1px solid var(--border);
}
.hint-tip .tip-section-head {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--muted-foreground);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 8px;
}
.hint-tip .tip-section-head strong {
  color: var(--foreground);
  font-weight: 700;
}
/* Multi-row groups — either an explicit `.tip-rows` wrapper, or any
   `.tip-section` whose direct children are two-or-more `.tip-row`s — lay
   out as a 2-column grid (`max-content 1fr`) and let each `.tip-row`
   adopt the parent grid via `subgrid`. Result: column 1 sizes to the
   widest key across the whole group, so every value column shares a
   single left edge instead of floating wherever flex `space-between`
   pushes it on a per-row basis. */
.hint-tip .tip-rows,
.hint-tip .tip-section:has(> .tip-row + .tip-row) {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 12px;
  row-gap: 4px;
  align-items: center;
}
.hint-tip .tip-rows > .tip-row,
.hint-tip .tip-section:has(> .tip-row + .tip-row) > .tip-row {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: 1 / -1;
  align-items: center;
  gap: 0;
  /* Override the standalone-row flex defaults below. */
  justify-content: initial;
}
.hint-tip .tip-rows > .tip-row {
  padding: 2px 4px;
  border-radius: 4px;
}

/* Standalone rows (a `.tip-row` that's a lone child of a `.tip-section`,
   not part of a multi-row group) still use flex space-between since
   there's no sibling to align against. */
.hint-tip .tip-row {
  display: flex; justify-content: space-between; gap: 12px;
  align-items: baseline;
}
.hint-tip .tip-row.is-active {
  background: color-mix(in srgb, var(--hint-accent, var(--foreground)) 14%, transparent);
}
.hint-tip .tip-row .k {
  color: var(--muted-foreground);
  /* Without nowrap+flex-shrink:0, "< 5" can break onto two lines when the
     value span on the right wraps and the flex layout squeezes the .k. */
  white-space: nowrap;
  flex-shrink: 0;
}
.hint-tip .tip-tier {
  display: inline-block;
  padding: 1px 6px; border-radius: 3px;
  font-size: 10px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em;
}
.hint-tip .tip-tier.good { color: var(--profit);  border: 1px solid color-mix(in srgb, var(--profit)  35%, transparent); }
.hint-tip .tip-tier.warn { color: var(--chart-3); border: 1px solid color-mix(in srgb, var(--chart-3) 35%, transparent); }
.hint-tip .tip-tier.risk { color: var(--loss);    border: 1px solid color-mix(in srgb, var(--loss)    35%, transparent); }
.hint-tip .tip-rows .tip-row .tip-tier {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  /* Spacing to the label sibling now comes from the parent grid's
     column-gap (12px); no extra margin-right needed. flex-shrink is
     irrelevant in the grid context. */
  justify-self: start;
}

/* Formula callout — a line inside a hint body that names the calculation
   behind the number ("AUM = Positions + Other assets − Liabilities"). The
   hint body is already monospace; the tinted box just sets the maths apart
   from the prose as its own beat. Authored as a <div> to match the other
   .tip-* block conventions above. */
.hint-tip .tip-formula {
  display: block;
  margin: 8px 0;
  padding: 7px 9px;
  background: var(--surface-tinted, rgba(255, 255, 255, .04));
  border: 1px solid var(--border);
  border-radius: 5px;
  line-height: 1.6;
}

/* Inline term-with-dot — mirrors the colour a chart series uses so the
   reader can map "uPNL" in prose to the purple band on the canvas
   without re-reading the legend. The dot sits before the label and
   inherits its colour from --hint-term-color. */
.hint-term {
  display: inline-flex; align-items: center; gap: 5px;
  white-space: nowrap;
  color: var(--foreground);
  font-weight: 600;
}
.hint-term::before {
  content: "";
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--hint-term-color, var(--foreground));
  flex-shrink: 0;
}
/* Dashed-line variant — for series rendered as a dashed reference (avg /
   median lines). Renders a tiny dashed stroke instead of a solid dot. */
.hint-term.is-dashed::before {
  width: 14px; height: 0;
  border-radius: 0;
  background: transparent;
  border-top: 2px dashed var(--hint-term-color, var(--foreground));
}

/* ════════════════════════════════════════════════════════════════════
   Rich bodies — the card-hover vocabulary, inside a hint
   ────────────────────────────────────────────────────────────────────
   The chart / card hovers (AUM tooltip, funding tooltip, the OTC-yield
   progress tooltip) share one look: an uppercase eyebrow, a token header,
   a tinted "walk" box (from → to, delta on the right), key/value rows with
   a brand icon in the label, a dashed rule above the total, a small muted
   foot. These are those pieces as hint-body conventions, so a `(?)` hint
   and a data popover are ONE surface:

     .hint-tip.is-rich       ← card-hover shell (8px radius + lifted shadow)
     .hint-tip.is-wide       ← 680px, for tabular bodies
     .hint-tip.is-floating   ← a MANAGED popover: same surface, positioned
                                by JS (fixed), for triggers that cannot hold
                                a child tip (a table cell morphed per tick)
     .tip-eyebrow            ← uppercase title line (+ optional .tip-pill)
     .tip-head               ← icon · name · sub, meta pushed right
     .tip-pill               ← rounded tag; .is-accent / .is-live / .is-warn
     .tip-walk               ← tinted box: label  from → to      delta
     .tip-grid               ← source | mark | value rows; .is-active row
                                is tinted, .is-delta sits under a dashed rule
     .tip-table              ← real <table> for multi-column bodies
     .tip-bar                ← 3px magnitude bar under a value
     .tip-note / .tip-foot   ← prose above / muted foot below
     .is-positive / .is-negative on any value
   ════════════════════════════════════════════════════════════════════ */
.hint-tip.is-rich,
.hint-tip.is-floating {
  border-radius: 8px;
  border-color: color-mix(in srgb, var(--foreground) 14%, transparent);
  box-shadow:
    0 12px 32px rgba(0, 0, 0, .32),
    0 2px 6px rgba(0, 0, 0, .18);
  font-variant-numeric: tabular-nums;
}
.hint-tip.is-wide {
  width: 680px;
  max-width: min(680px, calc(100vw - 24px));
  max-height: min(80vh, 640px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
@media (min-width: 721px) {
  .hint-tip.is-floating {
    position: fixed;
    top: 0; left: 0;
    transform: none;
    width: max-content;
    min-width: 320px;
    max-width: min(480px, calc(100vw - 16px));
    z-index: 1000;
  }
}
.hint-tip.is-floating {
  opacity: 1;
  pointer-events: none;
  transition: none;
  animation: hint-tip-in .12s ease both;
}
.hint-tip.is-floating[hidden] { display: none; }
@keyframes hint-tip-in {
  from { opacity: 0; translate: 0 -4px; }
  to   { opacity: 1; translate: 0 0; }
}
@media (prefers-reduced-motion: reduce) {
  .hint-tip.is-floating { animation: none; }
}

.hint-tip .tip-eyebrow {
  display: flex; align-items: center; gap: 8px;
  font-size: 10px;
  text-transform: uppercase; letter-spacing: .12em;
  color: var(--muted-foreground);
  margin-bottom: 8px;
  white-space: nowrap;
}
.hint-tip .tip-eyebrow .tip-pill { margin-left: auto; }

.hint-tip .tip-head {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
  white-space: nowrap;
}
.hint-tip .tip-head-icon {
  width: 18px; height: 18px;
  flex: none;
}
.hint-tip .tip-head-name {
  font-size: 15px; font-weight: 600;
  letter-spacing: .01em;
  color: var(--foreground);
}
.hint-tip .tip-head-sub {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11px;
  color: var(--muted-foreground);
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis;
}
.hint-tip .tip-head-meta { margin-left: auto; padding-left: 12px; }

.hint-tip .tip-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 9.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .12em;
  background: color-mix(in srgb, var(--foreground) 8%, transparent);
  color: var(--muted-foreground);
  white-space: nowrap;
}
.hint-tip .tip-pill::before {
  content: "";
  width: 5px; height: 5px; border-radius: 50%;
  background: currentColor;
}
.hint-tip .tip-pill.is-accent {
  --tip-pill-color: var(--hint-accent, var(--chart-1));
  background: color-mix(in srgb, var(--tip-pill-color) 16%, transparent);
  color: var(--tip-pill-color);
}
.hint-tip .tip-pill.is-live {
  background: color-mix(in srgb, var(--status-live, var(--profit)) 16%, transparent);
  color: var(--status-live, var(--profit));
}
.hint-tip .tip-pill.is-warn {
  background: color-mix(in srgb, var(--chart-3) 16%, transparent);
  color: var(--chart-3);
}

.hint-tip .tip-walk {
  display: flex; align-items: baseline; flex-wrap: wrap;
  gap: 6px;
  padding: 7px 9px;
  margin-bottom: 8px;
  border-radius: 6px;
  background: color-mix(in srgb, var(--foreground) 4%, transparent);
  border: 1px solid color-mix(in srgb, var(--foreground) 6%, transparent);
}
.hint-tip .tip-walk-label {
  font-size: 9.5px;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted-foreground);
  margin-right: 4px;
}
.hint-tip .tip-walk-from { color: var(--muted-foreground); }
.hint-tip .tip-walk-arrow { color: var(--muted-foreground); opacity: .7; }
.hint-tip .tip-walk-to { color: var(--foreground); font-weight: 600; }
.hint-tip .tip-walk-delta {
  margin-left: auto; padding-left: 12px;
  font-weight: 600;
  color: var(--foreground);
  white-space: nowrap;
}
.hint-tip .tip-walk-delta small,
.hint-tip .tip-num small {
  font-size: 9.5px; font-weight: 400;
  opacity: .85;
  margin-left: 4px;
}

.hint-tip .tip-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  column-gap: 16px; row-gap: 2px;
  align-items: center;
}
.hint-tip .tip-grid-head,
.hint-tip .tip-grid-row {
  display: grid;
  grid-template-columns: subgrid;
  grid-column: 1 / -1;
  align-items: center;
}
.hint-tip .tip-grid-head {
  font-size: 9.5px;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted-foreground);
  padding: 0 6px 4px;
}
.hint-tip .tip-grid-head > :nth-child(n+2) { text-align: right; }
.hint-tip .tip-grid-row {
  padding: 4px 6px;
  border-radius: 5px;
}
.hint-tip .tip-grid-row.is-active {
  background: color-mix(in srgb, var(--hint-accent, var(--foreground)) 10%, transparent);
  box-shadow: inset 2px 0 0 var(--hint-accent, var(--foreground));
}
.hint-tip .tip-grid-row.is-delta {
  margin-top: 4px; padding-top: 7px;
  border-top: 1px dashed var(--border);
  border-radius: 0;
}
.hint-tip .tip-src {
  display: inline-flex; align-items: center; gap: 7px;
  min-width: 0;
}
/* Holds the icon column on a row that has no icon (the delta row). */
.hint-tip .tip-src-spacer { width: 12px; flex: none; }
.hint-tip .tip-src-basis {
  font-size: 9.5px;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted-foreground);
  flex: none;
  min-width: 62px;
}
.hint-tip .tip-grid-row.is-active .tip-src-basis { color: var(--foreground); }
.hint-tip .tip-src-name {
  color: var(--foreground);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hint-tip .tip-num {
  text-align: right;
  white-space: nowrap;
  color: var(--muted-foreground);
}
.hint-tip .tip-grid-row.is-active .tip-num,
.hint-tip .tip-grid-row.is-delta .tip-num { color: var(--foreground); font-weight: 600; }
.hint-tip .is-positive,
.hint-tip .tip-grid-row .tip-num.is-positive { color: var(--profit); }
.hint-tip .is-negative,
.hint-tip .tip-grid-row .tip-num.is-negative { color: var(--loss); }

.hint-tip .tip-table {
  width: 100%;
  /* Fixed layout: the columns hold their share and long source names
     ellipsize, so the last column (the delta) can never be pushed out. */
  table-layout: fixed;
  border-collapse: separate; border-spacing: 0;
  line-height: 1.35;
}
.hint-tip .tip-table th,
.hint-tip .tip-table td {
  padding: 3px 0 3px 12px;
  text-align: left; vertical-align: middle;
  white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.hint-tip .tip-table th:nth-child(1) { width: 17%; }
.hint-tip .tip-table th:nth-child(2) { width: 18%; }
.hint-tip .tip-table th:nth-child(3) { width: 21%; }
.hint-tip .tip-table th:nth-child(4) { width: 26%; }
.hint-tip .tip-table th:nth-child(5) { width: 18%; }
.hint-tip .tip-table th:first-child,
.hint-tip .tip-table td:first-child { padding-left: 6px; }
.hint-tip .tip-table th:last-child,
.hint-tip .tip-table td:last-child { padding-right: 6px; }
.hint-tip .tip-table th {
  position: sticky; top: -10px;          /* under the tip's own padding */
  background: var(--popover);
  font-size: 9.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  padding-top: 2px;
}
.hint-tip .tip-table .num { text-align: right; }
.hint-tip .tip-table tbody td { border-bottom: 1px solid color-mix(in srgb, var(--foreground) 5%, transparent); }
.hint-tip .tip-table tbody tr:last-child td { border-bottom: 0; }
.hint-tip .tip-table tbody tr:hover td { background: color-mix(in srgb, var(--foreground) 4%, transparent); }
.hint-tip .tip-table td { color: var(--foreground); position: relative; }
.hint-tip .tip-table td.is-positive { color: var(--profit); }
.hint-tip .tip-table td.is-negative { color: var(--loss); }
.hint-tip .tip-table td small {
  display: flex; align-items: center; gap: 5px;
  min-width: 0;
  font-size: 9.5px; font-weight: 400;
  color: var(--muted-foreground);
}
.hint-tip .tip-table td.num small { justify-content: flex-end; }
.hint-tip .tip-ell {
  min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.hint-tip .tip-table .tip-cell {
  display: flex; align-items: center; gap: 7px;
  min-width: 0;
  font-weight: 600;
}
.hint-tip .tip-table .tip-cell.is-muted { font-weight: 400; color: var(--muted-foreground); }
.hint-tip .tip-table .tip-cell .ticker-icon { width: 14px; height: 14px; flex: none; }
.hint-tip .tip-table sup { color: var(--chart-3); margin-left: 2px; font-weight: 600; }
.hint-tip .tip-table tr.is-rest td { color: var(--muted-foreground); font-style: italic; }
.hint-tip .tip-table tfoot td {
  border-top: 1px dashed var(--border);
  padding-top: 7px;
  font-weight: 600;
}
/* Magnitude bar — pinned to the cell's bottom edge so it costs no row
   height; width is the value's share of the largest in the column. */
.hint-tip .tip-bar {
  position: absolute;
  right: 6px; bottom: 0;
  height: 2px; border-radius: 1px;
  min-width: 2px; max-width: calc(100% - 18px);
  background: currentColor;
  opacity: .5;
  pointer-events: none;
}

.hint-tip .tip-note { color: color-mix(in srgb, var(--popover-foreground) 82%, transparent); margin-bottom: 8px; }
.hint-tip .tip-note strong { color: var(--foreground); font-weight: 600; }
.hint-tip .tip-foot {
  margin-top: 8px; padding-top: 7px;
  border-top: 1px solid color-mix(in srgb, var(--foreground) 8%, transparent);
  font-size: 10px;
  color: var(--muted-foreground);
  white-space: normal;
}
.hint-tip .tip-foot strong { color: var(--foreground); font-weight: 600; }
.hint-tip .tip-foot span + span::before { content: "·"; margin: 0 6px; opacity: .6; }

/* Mobile — bottom-sheet style so the tip can never clip past a viewport
   edge. Pinned to the bottom of the viewport with 12px gutters. The
   trigger glyph stays where it was; only the body relocates. */
@media (max-width: 720px) {
  .hint-tip {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 16px;
    width: auto;
    max-width: none;
    transform: translateY(8px);
    z-index: 100;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, .35);
  }
  .hint:hover .hint-tip,
  .hint:focus-visible .hint-tip,
  .hint.is-open .hint-tip {
    transform: translateY(0);
  }
  /* Lifted into the top layer it is the same bottom sheet; CSS owns the
     position here (hint.js writes no coordinates below 720px). */
  .hint-tip:popover-open {
    top: auto; left: 12px; right: 12px; bottom: 16px;
    transform: translateY(8px);
  }
  .hint:hover > .hint-tip:popover-open,
  .hint:focus-visible > .hint-tip:popover-open,
  .hint.is-open > .hint-tip:popover-open {
    transform: translateY(0);
  }
  @starting-style {
    .hint:is(:hover, :focus-visible, .is-open) > .hint-tip:popover-open {
      opacity: 0;
      transform: translateY(8px);
    }
  }
  /* Inside the bottom sheet there's enough room to let band labels wrap
     onto a second line — keep the layout readable on ~336px screens. */
  .hint-tip .tip-row {
    align-items: flex-start;
  }
  .hint-tip .tip-rows > .tip-row,
  .hint-tip .tip-section:has(> .tip-row + .tip-row) > .tip-row {
    align-items: start;
  }
  .hint-tip .tip-rows .tip-row .k {
    white-space: normal;
    word-break: break-word;
    text-align: right;
  }
  /* A managed popover is the same bottom sheet — CSS owns its position
     here, the module skips its own placement. */
  .hint-tip.is-floating { transform: none; }
  .hint-tip.is-wide { max-height: 70vh; }
}
