/* ETF Intelligence Center
 *
 * Extends the institutional shell in css/market/market-portal.css. It adds only
 * what the Center needs and that shell does not already provide; every colour,
 * radius and shadow is inherited from the --market-* tokens so the section is
 * visually indistinguishable from the rest of the platform.
 *
 * All box geometry uses logical properties (inline-start/end) so the Arabic RTL
 * mirror is correct without a second stylesheet.
 */

:root {
  /* Categorical slots for allocation and identity encoding.
   *
   * Validated as a set against this platform's dark chart surface (#0f1319):
   * lightness band, chroma floor, adjacent CVD separation (worst ΔE 8.4 protan),
   * normal-vision floor (worst ΔE 19.3) and >=3:1 contrast all pass. Assigned in
   * fixed order and never cycled — a ninth category folds into "Other". */
  --etf-cat-1: #3987e5;
  --etf-cat-2: #d95926;
  --etf-cat-3: #199e70;
  --etf-cat-4: #c98500;
  --etf-cat-5: #d55181;
  --etf-cat-6: #008300;
  --etf-cat-7: #9085e9;
  --etf-cat-8: #e66767;
  --etf-cat-other: #5b646f;

  /* Magnitude ramp — one hue, light to dark, for score bars. */
  --etf-seq-strong: #f2d27b;
  --etf-seq-mid: #d8b15a;
  --etf-seq-soft: #8d7238;

  --etf-surface: #0f1319;
  --etf-gap-mark: 2px; /* surface gap between adjacent fills */
}

/* --------------------------------------------------------------------------
 * Responsive grids
 *
 * .market-grid in the base shell is a fixed 3-column rule, so the Center
 * declares its own auto-fitting grids rather than relying on modifier classes
 * that do not exist there.
 * -------------------------------------------------------------------------- */

.etf-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.etf-grid.narrow { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.etf-grid.wide { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.etf-split {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
}

@media (max-width: 900px) {
  .etf-split { grid-template-columns: minmax(0, 1fr); }
}

/* --------------------------------------------------------------------------
 * Stat tiles
 * -------------------------------------------------------------------------- */

.etf-stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--market-line);
  border-radius: var(--market-radius-sm);
  background: rgba(255, 255, 255, 0.02);
  min-width: 0;
}

.etf-stat-label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--market-muted);
}

.etf-stat-value {
  font-family: "Space Grotesk", "Inter", sans-serif;
  font-size: clamp(18px, 2.3vw, 22px);
  line-height: 1.15;
  color: var(--market-text);
  overflow-wrap: anywhere;
}

.etf-stat-note {
  font-size: 11px;
  color: var(--market-muted);
}

.etf-stat.positive .etf-stat-value { color: var(--market-green); }
.etf-stat.negative .etf-stat-value { color: var(--market-red); }

/* --------------------------------------------------------------------------
 * TradeAlpha Score gauge
 *
 * A single headline number with a radial track. The number is the mark; the arc
 * is supporting. Drawn with conic-gradient so it needs no SVG or script.
 * -------------------------------------------------------------------------- */

.etf-score {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
}

.etf-score-dial {
  --score: 0;
  position: relative;
  inline-size: 116px;
  block-size: 116px;
  border-radius: 50%;
  flex: none;
  background:
    conic-gradient(var(--etf-seq-mid) calc(var(--score) * 1%), rgba(255, 255, 255, 0.07) 0);
  display: grid;
  place-items: center;
}

.etf-score-dial::before {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: var(--etf-surface);
  border: 1px solid var(--market-line);
}

.etf-score-figure {
  position: relative;
  text-align: center;
  line-height: 1;
}

.etf-score-value {
  display: block;
  font-family: "Space Grotesk", "Inter", sans-serif;
  font-size: 30px;
  color: var(--market-text);
}

.etf-score-max {
  display: block;
  font-size: 11px;
  color: var(--market-muted);
  margin-block-start: 3px;
}

.etf-score-meta { min-width: 0; }

.etf-score-label {
  font-family: "Space Grotesk", "Inter", sans-serif;
  font-size: clamp(19px, 2.6vw, 24px);
  color: var(--market-gold-bright);
  text-transform: capitalize;
}

.etf-score-coverage {
  font-size: 12px;
  color: var(--market-muted);
  margin-block-start: 6px;
  max-inline-size: 46ch;
}

/* Withheld score — no number, an explanation instead. */
.etf-score-dial.withheld { background: rgba(255, 255, 255, 0.05); }
.etf-score-dial.withheld .etf-score-value { font-size: 20px; color: var(--market-muted); }

/* --------------------------------------------------------------------------
 * Vertical rhythm
 *
 * The base shell spaces sections generously, which on data-dense Center pages
 * left large voids between panels. Tightened here only for Center surfaces so
 * the rest of the platform is untouched.
 * -------------------------------------------------------------------------- */

.market-shell .market-section + .market-section { margin-block-start: 0; }
.market-shell .market-section { margin-block-end: 22px; }
.market-shell .market-section-head { margin-block-end: 12px; }
.market-shell .market-hero { margin-block-end: 24px; }

/* --------------------------------------------------------------------------
 * Score meta row and coverage chip
 * -------------------------------------------------------------------------- */

.etf-score-meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-block-end: 16px;
}

.etf-coverage-chip {
  font-size: 11.5px;
  color: var(--market-soft);
  border: 1px solid var(--market-line);
  border-radius: 999px;
  padding: 4px 11px;
  background: rgba(255, 255, 255, 0.02);
}

.etf-method-link {
  font-size: 12.5px;
  color: var(--market-gold-bright);
  text-decoration: none;
}

.etf-method-link:hover { text-decoration: underline; }

/* One aggregated line replacing what used to be a repeated per-row status. */
.etf-pending-note {
  margin-block-start: 14px;
  padding: 10px 14px;
  border-radius: var(--market-radius-sm);
  background: rgba(255, 255, 255, 0.025);
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--market-muted);
}

.etf-pending-note a { color: var(--market-gold-bright); }

/* Evidence is available but not shouted: collapsed by default so the default
 * read is the measurement, not the audit trail. */
.etf-evidence { margin-block-start: 4px; }

.etf-evidence summary {
  cursor: pointer;
  font-size: 11.5px;
  color: var(--market-muted);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.etf-evidence summary::-webkit-details-marker { display: none; }
.etf-evidence summary::before { content: "▸"; font-size: 9px; transition: transform 140ms ease; }
.etf-evidence[open] summary::before { transform: rotate(90deg); }
.etf-evidence summary:hover { color: var(--market-soft); }

.etf-evidence ul {
  margin: 8px 0 0;
  padding-inline-start: 18px;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--market-muted);
}

@media (prefers-reduced-motion: reduce) {
  .etf-evidence summary::before { transition: none; }
}

/* --------------------------------------------------------------------------
 * Sub-score bars (magnitude — one hue)
 * -------------------------------------------------------------------------- */

.etf-subscores {
  display: grid;
  gap: 12px;
  margin-block-start: 4px;
}

.etf-subscore { display: grid; gap: 6px; }

.etf-subscore-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 13px;
}

.etf-subscore-name { color: var(--market-soft); }

.etf-subscore-number {
  font-family: "Space Grotesk", "Inter", sans-serif;
  color: var(--market-text);
}

.etf-subscore-track {
  block-size: 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.etf-subscore-fill {
  display: block;
  block-size: 100%;
  /* 4px rounded data-end, anchored flat against the baseline start. */
  border-start-end-radius: 4px;
  border-end-end-radius: 4px;
  background: var(--etf-seq-mid);
}

.etf-subscore.high .etf-subscore-fill { background: var(--etf-seq-strong); }
.etf-subscore.low .etf-subscore-fill { background: var(--etf-seq-soft); }

/* An indeterminate component states why, and shows no bar at all. */
.etf-subscore.indeterminate .etf-subscore-number { color: var(--market-muted); font-size: 12px; }
.etf-subscore-reason {
  font-size: 11.5px;
  color: var(--market-muted);
  font-style: italic;
}

/* --------------------------------------------------------------------------
 * Allocation bar (categorical, stacked)
 * -------------------------------------------------------------------------- */

.etf-alloc {
  display: flex;
  block-size: 26px;
  border-radius: 6px;
  overflow: hidden;
  /* 2px surface gap between adjacent fills, per mark spec. */
  gap: var(--etf-gap-mark);
  background: var(--etf-surface);
}

.etf-alloc-seg {
  block-size: 100%;
  min-inline-size: 2px;
}

.etf-alloc-seg:first-child { border-start-start-radius: 6px; border-end-start-radius: 6px; }
.etf-alloc-seg:last-child { border-start-end-radius: 6px; border-end-end-radius: 6px; }

.etf-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-block-start: 12px;
  font-size: 12.5px;
}

.etf-legend-item {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--market-soft);
}

.etf-legend-swatch {
  inline-size: 10px;
  block-size: 10px;
  border-radius: 3px;
  flex: none;
}

.etf-legend-value { color: var(--market-muted); }

/* --------------------------------------------------------------------------
 * Similarity rows
 * -------------------------------------------------------------------------- */

.etf-similar { display: grid; gap: 10px; }

.etf-similar-row {
  display: grid;
  grid-template-columns: minmax(88px, auto) minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border: 1px solid var(--market-line);
  border-radius: var(--market-radius-sm);
  background: rgba(255, 255, 255, 0.02);
}

.etf-similar-row:hover { border-color: var(--market-line-strong); }

.etf-similar-symbol {
  font-family: "Space Grotesk", "Inter", sans-serif;
  color: var(--market-gold-bright);
  text-decoration: none;
}

.etf-similar-track {
  block-size: 6px;
  border-radius: 3px;
  background: rgba(255, 255, 255, 0.07);
  overflow: hidden;
}

.etf-similar-fill {
  display: block;
  block-size: 100%;
  background: var(--etf-cat-3);
  border-start-end-radius: 3px;
  border-end-end-radius: 3px;
}

.etf-similar-pct {
  font-family: "Space Grotesk", "Inter", sans-serif;
  font-size: 13px;
  color: var(--market-text);
  min-inline-size: 46px;
  text-align: end;
}

@media (max-width: 560px) {
  .etf-similar-row { grid-template-columns: minmax(0, 1fr) auto; }
  .etf-similar-track { grid-column: 1 / -1; }
}

/* --------------------------------------------------------------------------
 * Tab strip — the base shell has no tab component
 * -------------------------------------------------------------------------- */

.etf-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  border-block-end: 1px solid var(--market-line);
  padding-block-end: 10px;
  margin-block-end: 18px;
}

.etf-tab {
  appearance: none;
  border: 1px solid var(--market-line);
  background: transparent;
  color: var(--market-soft);
  font: inherit;
  font-size: 13px;
  padding: 8px 15px;
  border-radius: 999px;
  cursor: pointer;
  transition: border-color 160ms ease, color 160ms ease, background 160ms ease;
}

.etf-tab:hover { color: var(--market-text); border-color: var(--market-line-strong); }

.etf-tab[aria-selected="true"] {
  color: #12100a;
  background: linear-gradient(180deg, var(--market-gold-bright), var(--market-gold));
  border-color: transparent;
}

.etf-tab:focus-visible { outline: 2px solid var(--market-gold-bright); outline-offset: 2px; }

.etf-tabpanel[hidden] { display: none; }

/* --------------------------------------------------------------------------
 * Tables — wide content scrolls inside its own container
 * -------------------------------------------------------------------------- */

.etf-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--market-line);
  border-radius: var(--market-radius-sm);
}

.etf-table {
  inline-size: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-inline-size: 560px;
}

.etf-table th,
.etf-table td {
  padding: 11px 14px;
  text-align: start;
  border-block-end: 1px solid var(--market-line);
  white-space: nowrap;
}

.etf-table thead th {
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--market-muted);
  background: rgba(255, 255, 255, 0.025);
  position: sticky;
  inset-block-start: 0;
}

.etf-table tbody tr:last-child td { border-block-end: none; }
.etf-table tbody tr:hover td { background: rgba(255, 255, 255, 0.03); }

.etf-table .num {
  text-align: end;
  font-family: "Space Grotesk", "Inter", sans-serif;
  font-variant-numeric: tabular-nums;
}

.etf-table .positive { color: var(--market-green); }
.etf-table .negative { color: var(--market-red); }

.etf-table th.sortable { cursor: pointer; user-select: none; }
.etf-table th.sortable:hover { color: var(--market-text); }
.etf-table .sort-icon { opacity: 0.5; font-size: 10px; margin-inline-start: 5px; }

/* --------------------------------------------------------------------------
 * Chart figures
 *
 * .market-chart is emitted by the existing ETF research generator but has no
 * rules anywhere in the base stylesheet, so those figures currently render
 * unstyled. Defining it here fixes the existing pages as well as new ones.
 * -------------------------------------------------------------------------- */

.market-chart,
.etf-chart {
  margin: 0 0 18px;
  padding: 16px;
  border: 1px solid var(--market-line);
  border-radius: var(--market-radius-md);
  background: var(--etf-surface);
}

.market-chart img,
.etf-chart img,
.etf-chart svg {
  inline-size: 100%;
  block-size: auto;
  display: block;
  border-radius: var(--market-radius-sm);
}

.market-chart figcaption,
.etf-chart figcaption {
  margin-block-start: 11px;
  font-size: 11.5px;
  line-height: 1.55;
  color: var(--market-muted);
}

/* --------------------------------------------------------------------------
 * Fund identity header
 * -------------------------------------------------------------------------- */

.etf-identity {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-block-end: 14px;
}

.etf-ticker-badge {
  font-family: "Space Grotesk", "Inter", sans-serif;
  font-size: 15px;
  letter-spacing: 0.04em;
  color: #12100a;
  background: linear-gradient(180deg, var(--market-gold-bright), var(--market-gold));
  padding: 6px 13px;
  border-radius: 8px;
  flex: none;
}

.etf-identity-name {
  font-size: 14px;
  color: var(--market-soft);
  min-width: 0;
}

.etf-chips { display: flex; flex-wrap: wrap; gap: 7px; margin-block-start: 12px; }

.etf-chip {
  font-size: 11.5px;
  color: var(--market-soft);
  border: 1px solid var(--market-line);
  border-radius: 999px;
  padding: 4px 11px;
  background: rgba(255, 255, 255, 0.02);
}

.etf-chip.accent { border-color: rgba(216, 177, 90, 0.45); color: var(--market-gold-bright); }

/* --------------------------------------------------------------------------
 * Provenance badges
 *
 * Every fact on a fund page is labelled with where it came from. The badge
 * carries a text label as well as colour, so the distinction survives
 * colourblindness, greyscale printing and forced-colors mode.
 * -------------------------------------------------------------------------- */

.etf-prov {
  display: inline-block;
  font-size: 11px;
  line-height: 1.4;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid currentColor;
  white-space: nowrap;
}

.etf-prov-fetched { color: var(--etf-cat-3); }
.etf-prov-derived { color: var(--etf-cat-1); }
.etf-prov-registry { color: var(--market-gold); }
.etf-prov-declared { color: var(--market-muted); }
.etf-prov-unavailable { color: var(--market-muted); border-style: dashed; }

/* An awaiting-data value is muted and italic — legible as a status, never
 * mistakable for a measurement. */
.etf-awaiting {
  color: var(--market-muted);
  font-style: italic;
  font-size: 12.5px;
}

/* Rows listed below a ranking because their measure is not yet verified. They
 * stay fully readable — the fund is still covered, only the one value is
 * missing — but are visually separated from the ranked block above. */
.etf-row-awaiting td { opacity: 0.72; }
.etf-row-awaiting:first-of-type td { border-block-start: 1px solid var(--market-line-strong); }

/* --------------------------------------------------------------------------
 * Provenance — every sourced figure links to where it came from
 * -------------------------------------------------------------------------- */

.etf-source {
  font-size: 11px;
  color: var(--market-muted);
}

.etf-source a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.etf-source a:hover { color: var(--market-gold-bright); }

.etf-note {
  border-inline-start: 3px solid rgba(216, 177, 90, 0.5);
  padding: 10px 14px;
  margin-block-start: 14px;
  background: rgba(216, 177, 90, 0.05);
  border-radius: 0 var(--market-radius-sm) var(--market-radius-sm) 0;
  font-size: 12.5px;
  line-height: 1.6;
  color: var(--market-soft);
}

[dir="rtl"] .etf-note { border-radius: var(--market-radius-sm) 0 0 var(--market-radius-sm); }

/* --------------------------------------------------------------------------
 * Finder / screener controls
 * -------------------------------------------------------------------------- */

.etf-filters {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  margin-block-end: 18px;
}

.etf-field { display: grid; gap: 5px; }

.etf-field label {
  font-size: 11px;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--market-muted);
}

.etf-field input,
.etf-field select {
  font: inherit;
  font-size: 13.5px;
  color: var(--market-text);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--market-line);
  border-radius: var(--market-radius-sm);
  padding: 9px 12px;
  inline-size: 100%;
}

.etf-field input:focus-visible,
.etf-field select:focus-visible {
  outline: 2px solid var(--market-gold-bright);
  outline-offset: 1px;
}

.etf-field select option { background: var(--etf-surface); color: var(--market-text); }

.etf-result-count { font-size: 12.5px; color: var(--market-muted); margin-block-end: 10px; }

.etf-empty {
  padding: 26px;
  text-align: center;
  color: var(--market-muted);
  font-size: 13.5px;
}

/* --------------------------------------------------------------------------
 * Compare tray
 * -------------------------------------------------------------------------- */

.etf-compare-tray {
  position: sticky;
  inset-block-end: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  margin-block-start: 20px;
  border: 1px solid var(--market-line-strong);
  border-radius: var(--market-radius-md);
  background: rgba(9, 11, 15, 0.96);
  backdrop-filter: blur(14px);
  box-shadow: var(--market-shadow);
}

.etf-compare-tray[hidden] { display: none; }

.etf-compare-slots { display: flex; gap: 8px; flex-wrap: wrap; flex: 1 1 auto; }

.etf-compare-slot {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12.5px;
  color: var(--market-text);
  border: 1px solid var(--market-line);
  border-radius: 999px;
  padding: 5px 11px;
}

.etf-compare-remove {
  appearance: none;
  border: none;
  background: none;
  color: var(--market-muted);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  padding: 0 2px;
}

.etf-compare-remove:hover { color: var(--market-red); }

/* --------------------------------------------------------------------------
 * Motion — respect the reader's preference
 * -------------------------------------------------------------------------- */

.etf-card-link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: transform 180ms ease, border-color 180ms ease;
}

.etf-card-link:hover { transform: translateY(-2px); border-color: var(--market-line-strong); }

@media (prefers-reduced-motion: reduce) {
  .etf-card-link,
  .etf-tab { transition: none; }
  .etf-card-link:hover { transform: none; }
}

/* --------------------------------------------------------------------------
 * Forced colors / print — identity must survive without colour
 * -------------------------------------------------------------------------- */

@media (forced-colors: active) {
  .etf-alloc-seg,
  .etf-subscore-fill,
  .etf-similar-fill { forced-color-adjust: none; border: 1px solid CanvasText; }
  .etf-legend-swatch { border: 1px solid CanvasText; }
}
