/* Latentra market trends (/analytics). Builds on landing.css tokens and the
   jobs.css chrome (topbar, results head, pulse tiles, chips). Only the chart
   pieces live here. Chart colours are a small validated set: one blue for every
   single-series chart, three categorical slots for the segmented bar, a
   seven-step blue ramp for the ordered seniority scale. */

/* ── Chart tokens (dark default, light under the theme toggle) ───────── */
.app {
  --viz-1: #3D7EFF; --viz-2: #D9742A; --viz-3: #11A66E; --viz-other: #4A5B78;
  --viz-grid: #1E3354; --viz-axis: #35507F; --viz-on: #FFFFFF;
  --ord-1: #285CC2; --ord-2: #3C71DA; --ord-3: #5087F2; --ord-4: #6D9FFE; --ord-5: #91B7FE; --ord-6: #B5CFFC; --ord-7: #D8E5FD;
  --viz-lift: color-mix(in srgb, var(--viz-1) 78%, #FFFFFF);
}
:root[data-theme="light"] .app {
  --viz-1: #2563EB; --viz-2: #D9731A; --viz-3: #0F9D6A; --viz-other: #AAB6C8;
  --viz-grid: #E6ECF5; --viz-axis: #B9C6DA; --viz-on: #FFFFFF;
  --ord-1: #92B7FE; --ord-2: #6E9FFF; --ord-3: #4B85FE; --ord-4: #376FE5; --ord-5: #2358CD; --ord-6: #0E42B5; --ord-7: #002A9E;
  --viz-lift: color-mix(in srgb, var(--viz-1) 82%, #000000);
}

/* ── Grid of floating cards ──────────────────────── */
.viz-grid { display: grid; gap: var(--s-200); grid-template-columns: minmax(0, 1fr); }
@media (min-width: 768px) { .viz-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .viz-card.span-4, .viz-card.span-6 { grid-column: 1 / -1; } }
@media (min-width: 1024px) {
  .viz-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .viz-card { grid-column: span 3; }
  .viz-card.span-2 { grid-column: span 2; }
  .viz-card.span-3 { grid-column: span 3; }
  .viz-card.span-4 { grid-column: span 4; }
  .viz-card.span-6 { grid-column: span 6; }
}
.viz-card {
  position: relative; min-width: 0;
  display: grid; grid-template-rows: auto 1fr auto; gap: var(--s-200);
  padding: var(--s-200);
  background: var(--surface);
  background-image: radial-gradient(520px 140px at 12% -10%, var(--blue-soft), transparent 70%);
  border: 1px solid var(--line); border-radius: var(--r-2xl);
  box-shadow: var(--lit), var(--drop);
  transition: transform var(--d-layout) var(--ease), border-color var(--d-color) var(--ease), box-shadow var(--d-layout) var(--ease);
  animation: rowIn 600ms var(--ease) both; animation-delay: calc(var(--i, 0) * 70ms);
}
@media (min-width: 768px) { .viz-card { padding: var(--s-300); } }
.viz-card:hover { transform: translateY(-3px); border-color: color-mix(in srgb, var(--blue) 40%, var(--line)); box-shadow: var(--lit), 0 24px 56px -22px var(--glow-blue); }
.viz-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s-100); }
.viz-head > div { display: grid; gap: var(--s-25); min-width: 0; }
.viz-key { display: inline-flex; align-items: center; gap: var(--s-50); white-space: nowrap; }
.viz-body { min-width: 0; }
.viz-body-center { display: grid; align-content: center; gap: var(--s-200); }
.viz-note { text-wrap: pretty; }
.viz-foot { display: grid; gap: var(--s-100); }
.viz-empty { padding: var(--s-200) 0; }
.viz-about { max-width: 720px; margin-top: var(--s-400); }

/* Swatches and legend (rect for bars, a short stroke for the line) */
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--viz-1)); flex: none; }
.swatch.is-line { width: 14px; height: 3px; border-radius: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: var(--s-75) var(--s-200); }
.legend li { display: inline-flex; align-items: center; gap: var(--s-50); }

/* Table twin for every chart */
.viz-table summary { cursor: pointer; list-style: none; display: inline-flex; align-items: center; gap: var(--s-50); padding: var(--s-25) 0; border-radius: var(--r-md); }
.viz-table summary::-webkit-details-marker { display: none; }
.viz-table summary::before { content: ""; width: 0; height: 0; border: 4px solid transparent; border-left: 5px solid currentColor; transition: transform var(--d-color) var(--ease); }
.viz-table[open] summary::before { transform: rotate(90deg); }
.viz-table summary:hover { color: var(--text); }
.viz-table table { width: 100%; border-collapse: collapse; margin-top: var(--s-75); color: var(--text-2); }
.viz-table th, .viz-table td { text-align: left; padding: var(--s-50) var(--s-75); border-bottom: 1px solid var(--line); }
.viz-table th { color: var(--muted); font-weight: 500; }
.viz-table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ── Ranked bars (one hue, largest first, value at the tip) ─────────── */
.rbars { display: grid; gap: var(--s-25); }
.rbar-hit {
  display: grid; grid-template-columns: minmax(64px, 32%) minmax(0, 1fr) auto; align-items: center; gap: var(--s-100);
  min-height: 28px; padding: 0 var(--s-50); margin: 0 calc(-1 * var(--s-50));
  border-radius: var(--r-lg);
  transition: background-color var(--d-color) var(--ease);
}
a.rbar-hit { cursor: pointer; }
.rbar-hit:hover, .rbar-hit:focus-visible { background: var(--surface-2); }
.rbar-hit:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }
.rbar-label { color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: color var(--d-color) var(--ease); }
.rbar-hit:hover .rbar-label { color: var(--text); }
.rbar-track { display: block; height: 12px; min-width: 0; }
.rbar-fill {
  display: block; height: 100%; width: calc(var(--v) / var(--max) * 100%); min-width: 2px;
  border-radius: 0 4px 4px 0; background: var(--viz-1);
  transform-origin: left center;
  animation: growX 700ms var(--ease) both; animation-delay: calc(var(--i, 0) * 28ms + 120ms);
  transition: background-color var(--d-color) var(--ease), opacity var(--d-color) var(--ease), box-shadow var(--d-color) var(--ease);
}
.rbars:hover .rbar-fill { opacity: 0.55; }
.rbar-hit:hover .rbar-fill, .rbar-hit:focus-visible .rbar-fill { opacity: 1; background: var(--viz-lift); box-shadow: 0 6px 18px -6px var(--glow-blue); }
.rbar-val { font-variant-numeric: tabular-nums; white-space: nowrap; min-width: 3ch; text-align: right; }
.rbar-hit:hover .rbar-val { color: var(--text); }
@keyframes growX { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* ── Tall segmented bar (one whole, parts side by side) ─────────────── */
.segbar { display: flex; gap: 2px; width: 100%; height: 28px; }
.seg {
  position: relative; display: flex; align-items: center; justify-content: flex-start;
  flex: var(--w) 1 0; min-width: 3px; height: 100%; overflow: hidden;
  border-radius: 4px; background: var(--c);
  transform-origin: left center;
  animation: growX 800ms var(--ease) both; animation-delay: calc(var(--i, 0) * 90ms + 120ms);
  transition: filter var(--d-color) var(--ease), opacity var(--d-color) var(--ease), transform var(--d-color) var(--ease);
}
a.seg { cursor: pointer; }
.segbar:hover .seg { opacity: 0.6; }
.seg:hover, .seg:focus-visible { opacity: 1; filter: brightness(1.12); transform: scaleY(1.08); }
.seg:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.seg-label { padding: 0 var(--s-75); color: var(--viz-on); font-size: 12px; line-height: 16px; font-weight: 600; white-space: nowrap; }
.seg[style*="--viz-other"] .seg-label { color: var(--text); }
:root[data-theme="light"] .seg[style*="--viz-other"] .seg-label { color: #0A1628; }

/* ── Columns on an ordered scale (seniority ramp) ───────────────────── */
.cols { display: flex; flex-direction: column; gap: var(--s-75); height: 100%; }
.cols-plot { position: relative; flex: 1 1 220px; min-height: 220px; max-height: 420px; margin-top: var(--s-100); padding-left: 40px; }
.cols-grid span { position: absolute; left: 0; right: 0; bottom: calc(var(--y) * 1%); border-top: 1px solid var(--viz-grid); }
.cols-grid span:first-child { border-top-color: var(--viz-axis); }
.cols-grid i { position: absolute; left: 0; bottom: 2px; width: 32px; text-align: right; font-size: 11px; line-height: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.cols-bars { position: absolute; left: 40px; right: 0; top: 0; bottom: 0; display: flex; align-items: flex-end; gap: var(--s-50); }
.col { position: relative; flex: 1 1 0; min-width: 0; height: 100%; display: flex; align-items: flex-end; justify-content: center; border-radius: var(--r-md); }
.col:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.col-bar {
  display: block; width: min(24px, 100%); height: calc(var(--v) / var(--top) * 100%); min-height: 2px;
  border-radius: 4px 4px 0 0; background: var(--c);
  transform-origin: center bottom;
  animation: growY 800ms var(--ease) both; animation-delay: calc(var(--i, 0) * 60ms + 120ms);
  transition: opacity var(--d-color) var(--ease), filter var(--d-color) var(--ease);
}
.cols-bars:hover .col-bar { opacity: 0.55; }
.col:hover .col-bar, .col:focus-visible .col-bar { opacity: 1; filter: brightness(1.12); }
.col-val { position: absolute; left: 50%; bottom: calc(var(--v) / var(--top) * 100% + 4px); transform: translateX(-50%); color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.cols-x { display: flex; gap: var(--s-50); padding-left: 40px; }
.cols-x > span { flex: 1 1 0; min-width: 0; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cols-x .x-short { display: none; }
@media (max-width: 479px) { .cols-x .x-long { display: none; } .cols-x .x-short { display: inline; } }
@keyframes growY { from { transform: scaleY(0); } to { transform: scaleY(1); } }

/* ── Line over time (geometry in SVG, labels in HTML so text never scales) ── */
.line { display: grid; grid-template-columns: auto minmax(0, 1fr); grid-template-rows: auto auto; gap: var(--s-75) var(--s-75); }
.line-y { position: relative; width: 28px; grid-row: 1; }
.line-y span { position: absolute; right: 0; bottom: calc(var(--y) * 1%); transform: translateY(50%); font-size: 11px; line-height: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.line-plot { position: relative; height: 220px; grid-row: 1; grid-column: 2; border-bottom: 1px solid var(--viz-axis); border-radius: var(--r-md); cursor: crosshair; touch-action: pan-y; }
.line-plot:focus-visible { outline: 2px solid var(--focus); outline-offset: 4px; }
.line-grid i { position: absolute; left: 0; right: 0; bottom: calc(var(--y) * 1%); border-top: 1px solid var(--viz-grid); }
.line-plot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.line-plot .wash-a { stop-color: var(--viz-1); stop-opacity: 0.28; }
.line-plot .wash-b { stop-color: var(--viz-1); stop-opacity: 0; }
.line-area { animation: fadeIn 900ms var(--ease) 500ms both; }
.line-path { fill: none; stroke: var(--viz-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; stroke-dasharray: 1; stroke-dashoffset: 1; animation: draw 1400ms var(--ease) 150ms forwards; }
.line-dot { position: absolute; left: calc(var(--x) * 1%); top: calc(var(--y) * 1%); width: 10px; height: 10px; margin: -5px 0 0 -5px; border-radius: 50%; background: var(--viz-1); box-shadow: 0 0 0 2px var(--surface); animation: fadeIn 400ms var(--ease) 1300ms both; }
.line-dot.is-end { background: var(--accent); }
.line-lbl { position: absolute; left: calc(var(--x) * 1%); top: calc(var(--y) * 1%); transform: translate(-50%, calc(-100% - 8px)); color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; animation: fadeIn 400ms var(--ease) 1300ms both; }
.line-lbl.at-right { transform: translate(-100%, calc(-100% - 8px)); }
.line-lbl.at-left { transform: translate(0, calc(-100% - 8px)); }
.line-cross { position: absolute; top: 0; bottom: 0; left: calc(var(--x) * 1%); border-left: 1px solid var(--viz-axis); pointer-events: none; }
.line-cross i { position: absolute; left: 0; top: calc(var(--y) * 1%); width: 12px; height: 12px; margin: -6px 0 0 -6px; border-radius: 50%; background: var(--viz-1); box-shadow: 0 0 0 2px var(--surface), 0 0 0 6px var(--blue-soft); }
.line-x { position: relative; height: 16px; grid-column: 2; }
.line-x span { position: absolute; left: calc(var(--x) * 1%); transform: translateX(-50%); font-size: 11px; line-height: 14px; color: var(--muted); white-space: nowrap; }
.line-x span.at-left { transform: none; }
.line-x span.at-right { transform: translateX(-100%); }
@keyframes draw { to { stroke-dashoffset: 0; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ── Pointer tooltip (one for the page, follows the pointer) ───────── */
.viz-tip {
  position: fixed; left: 0; top: 0; z-index: 80;
  min-width: 120px; max-width: 240px; padding: var(--s-75) var(--s-100);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-xl);
  box-shadow: var(--lit), 0 16px 40px -12px rgba(2, 8, 20, 0.6);
  color: var(--text); pointer-events: none;
  opacity: 0; transform: translate(-50%, calc(-100% - 14px)) scale(0.98);
  transition: opacity 120ms var(--ease), transform 160ms var(--ease);
}
:root[data-theme="light"] .viz-tip { box-shadow: var(--lit), 0 16px 40px -12px rgba(10, 22, 40, 0.18); }
.viz-tip.show { opacity: 1; transform: translate(-50%, calc(-100% - 14px)) scale(1); }
.viz-tip.below { transform: translate(-50%, 16px) scale(0.98); }
.viz-tip.below.show { transform: translate(-50%, 16px) scale(1); }
.viz-tip-val { font-size: 16px; line-height: 24px; font-weight: 600; display: flex; align-items: center; gap: var(--s-75); }
.viz-tip-key { display: inline-block; width: 12px; height: 3px; border-radius: 2px; background: var(--k, var(--viz-1)); flex: none; }
.viz-tip-name { font-size: 12px; line-height: 16px; font-weight: 500; color: var(--text-2); }
.viz-tip-sub { font-size: 12px; line-height: 16px; color: var(--muted); margin-top: var(--s-25); }

/* ── Motion off ──────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .viz-card, .rbar-fill, .seg, .col-bar, .line-area, .line-dot, .line-lbl { animation: none !important; }
  .line-path { animation: none !important; stroke-dashoffset: 0; }
  .viz-card, .viz-card:hover, .seg:hover { transform: none; }
  .viz-tip { transition: none; }
}
