/* ============================================================================
   FUND DETAIL — Radial Wheel Competitor Modal

   Replaces the broken multi-row filter modal with the design-system's
   signature radial-wheel pattern. Drill-down narrows the 12k-fund universe
   one ring at a time:

     Level 0 — Quick Screens (Hidden Gems / Steady / etc.)
     Level 1 — Management Style (Active / Passive)
     Level 2 — Asset Class (Equity / Bonds / Multi-Asset / …)
     Level 3 — Geographic Region (UK / US / Europe / Asia / EM / Global / …)
     Level 4 — Final fund list (selectable rows + Apply)

   Per design system: spring-in animation 0.04s stagger, gold accent on
   selected slice, breadcrumb showing the trail of choices.
   ============================================================================ */

/* Modal fills the viewport top-to-bottom. The base .fd-modal cascade in
   fund-detail-modal.css sets max-height: calc(100vh - 80px) which was
   capping the height regardless of our overrides — we use absolute
   positioning here to guarantee the modal stretches edge-to-edge of the
   overlay padding. */
#fdAddCompetitorModal {
  padding: 16px !important;
  align-items: stretch !important;
  justify-content: center !important;
}
#fdAddCompetitorModal .fd-modal {
  position: absolute !important;
  top: 16px !important;
  bottom: 16px !important;
  left: 50% !important;
  transform: translateX(-50%) !important;
  width: calc(100% - 32px) !important;
  max-width: 820px !important;
  height: auto !important;
  max-height: none !important;
  min-height: 0 !important;
  margin: 0 !important;
}
#fdAddCompetitorModal .fd-modal-body {
  padding: var(--sp-4) var(--sp-5);
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}
/* Wheel view: the wheel-wrap is the flex-growing child inside .fd-radial-
   modal — banner, search, header, breadcrumb, status all stay their natural
   sizes; the wheel takes whatever vertical space is left and centres
   itself. The list view (level 4) keeps its natural top-aligned scrolling. */
.fd-radial-wheel-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-2) 0;
}
#fdAddCompetitorModal[data-stage="list"] .fd-radial-wheel-wrap {
  flex: 0 0 auto;
}

/* ── Container that replaces the modal body content ──────────────────── */
.fd-radial-modal {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: var(--sp-3);
  width: 100%;
  /* Fill the modal body — without this, content sits at the top and the
     body has empty space between it and the footer (the "chin"). */
  flex: 1 1 auto;
  min-height: 100%;
  /* Override the legacy modal body padding */
  padding: 0;
}

/* Current-fund context banner — sits above the wheel so the user always
   sees what fund they're benchmarking against. Logo, name, brand, badges. */
.fd-radial-current-fund {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: linear-gradient(180deg, var(--gold-08) 0%, var(--surface-2) 100%);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
}
.fd-radial-current-fund .logo {
  width: 36px;
  height: 36px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 12px;
  color: var(--accent);
}
.fd-radial-current-fund .info { min-width: 0; }
.fd-radial-current-fund .label {
  font-family: var(--font-body);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.fd-radial-current-fund .name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fd-radial-current-fund .badges {
  display: flex;
  align-items: center;
  gap: var(--sp-1);
  flex-shrink: 0;
}
.fd-radial-current-fund .badge {
  display: inline-flex;
  padding: 3px 7px;
  border-radius: var(--r-xs);
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.fd-radial-current-fund .badge.gold  { background: var(--gold-15);             color: var(--accent); }
.fd-radial-current-fund .badge.green { background: rgba(74,222,128,0.15);     color: var(--pos); }
.fd-radial-current-fund .badge.blue  { background: rgba(96,165,250,0.15);     color: var(--fb-info); }
.fd-radial-current-fund .badge.purple{ background: rgba(167,139,250,0.15);    color: #a78bfa; }

/* Top-of-modal search bar (always visible, not just on final list) */
.fd-radial-search-bar {
  position: relative;
  display: flex;
  align-items: center;
}
.fd-radial-search-bar > svg {
  position: absolute;
  left: 12px;
  width: 14px;
  height: 14px;
  stroke: var(--text-muted);
  stroke-width: 2;
  fill: none;
  pointer-events: none;
}
.fd-radial-search-bar input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 13px;
  transition: border-color var(--dur) var(--ease);
}
.fd-radial-search-bar input:focus {
  border-color: var(--accent);
  outline: none;
}
.fd-radial-search-bar input::placeholder { color: var(--text-muted); }
.fd-radial-search-bar .fd-radial-search-status {
  position: absolute;
  right: 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
}

/* Hide every legacy element from the old modal body so the wheel owns it. */
.fd-modal-overlay .fd-modal-synthetic-section,
.fd-modal-overlay .fd-modal-category-filter,
.fd-modal-overlay .fd-modal-search,
.fd-modal-overlay .fd-modal-fund-list:not(.fd-radial-funds) {
  display: none !important;
}

/* Title + selected match-count line */
.fd-radial-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--sp-1);
  text-align: center;
}
.fd-radial-title {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 16px;
  letter-spacing: var(--tracking-display);
  color: var(--text);
  margin: 0;
}
.fd-radial-subtitle {
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Breadcrumb (trail of selected slices) ───────────────────────────── */
.fd-radial-breadcrumb {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  justify-content: center;
  min-height: 26px;
}
.fd-radial-crumb {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--text-2);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.fd-radial-crumb:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.fd-radial-crumb.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.fd-radial-crumb-sep {
  color: var(--text-dim);
  font-size: 11px;
}

/* ── The wheel SVG ───────────────────────────────────────────────────── */
.fd-radial-wheel-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: var(--sp-2) 0;
}
.fd-radial-svg {
  /* Default 280px so the modal fits on ~720px-tall laptop viewports.
     Scales up to 340px on tall viewports for impact. */
  width: 280px;
  height: 280px;
  max-width: 100%;
  display: block;
  user-select: none;
  overflow: visible;
}
@media (min-height: 900px) {
  .fd-radial-svg { width: 340px; height: 340px; }
}
@media (max-width: 560px) {
  .fd-radial-svg { width: 260px; height: 260px; }
}

.fd-radial-slice {
  fill: var(--surface-2);
  stroke: var(--border);
  stroke-width: 1.5;
  cursor: pointer;
  transform-origin: center;
  transform-box: fill-box;
  transition: fill var(--dur) var(--ease),
              stroke var(--dur) var(--ease),
              transform var(--dur) var(--ease);
}
.fd-radial-slice:hover {
  fill: var(--gold-08);
  stroke: var(--accent);
}
.fd-radial-slice.selected {
  fill: var(--accent);
  stroke: var(--accent);
}
.fd-radial-slice.disabled {
  pointer-events: none;
  opacity: 0.3;
}

/* Slice label group — centred at midpoint of the slice */
.fd-radial-slice-label {
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  fill: var(--text);
  transition: fill var(--dur) var(--ease);
}
.fd-radial-slice.selected + .fd-radial-slice-label,
.fd-radial-slice.selected ~ .fd-radial-slice-label,
g.selected .fd-radial-slice-label {
  fill: var(--accent-ink);
}
g.fd-radial-slice-group:hover .fd-radial-slice-label {
  fill: var(--accent);
}
g.fd-radial-slice-group.selected .fd-radial-slice-label {
  fill: var(--accent-ink);
}

.fd-radial-slice-count {
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
  font-family: var(--font-mono);
  font-size: 9px;
  fill: var(--text-muted);
  letter-spacing: 0;
}
g.fd-radial-slice-group.selected .fd-radial-slice-count {
  fill: var(--accent-ink);
  opacity: 0.8;
}

/* Hub — center circle. Default: gold. When .can-back is set, dims +
   shows ← to indicate "click to step back a level". */
.fd-radial-hub-bg {
  fill: var(--accent);
  filter: drop-shadow(0 0 12px rgba(201, 169, 98, 0.3));
  transition: fill var(--dur) var(--ease);
}
.fd-radial-hub.can-back .fd-radial-hub-bg {
  fill: var(--surface-2);
  stroke: var(--accent);
  stroke-width: 1.5;
  cursor: pointer;
}
.fd-radial-hub.can-back:hover .fd-radial-hub-bg {
  fill: var(--gold-15);
}
.fd-radial-hub-icon {
  pointer-events: none;
  text-anchor: middle;
  dominant-baseline: middle;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
}
.fd-radial-hub:not(.can-back) .fd-radial-hub-icon { fill: var(--accent-ink); }
.fd-radial-hub.can-back .fd-radial-hub-icon { fill: var(--accent); }

/* Spring-in stagger for slices on level transition */
@keyframes fd-radial-slice-in {
  from {
    opacity: 0;
    transform: scale(0.7) rotate(-6deg);
  }
  to {
    opacity: 1;
    transform: scale(1) rotate(0);
  }
}
.fd-radial-slice-group {
  animation: fd-radial-slice-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.fd-radial-slice-group:nth-child(1)  { animation-delay: 0.00s; }
.fd-radial-slice-group:nth-child(2)  { animation-delay: 0.04s; }
.fd-radial-slice-group:nth-child(3)  { animation-delay: 0.08s; }
.fd-radial-slice-group:nth-child(4)  { animation-delay: 0.12s; }
.fd-radial-slice-group:nth-child(5)  { animation-delay: 0.16s; }
.fd-radial-slice-group:nth-child(6)  { animation-delay: 0.20s; }
.fd-radial-slice-group:nth-child(7)  { animation-delay: 0.24s; }
.fd-radial-slice-group:nth-child(8)  { animation-delay: 0.28s; }

/* ── Match count + Reset link ─────────────────────────────────────── */
.fd-radial-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-2);
}
.fd-radial-match-count {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
}
.fd-radial-match-count strong {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}
.fd-radial-reset {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 11px;
  cursor: pointer;
  text-decoration: underline;
  text-decoration-color: var(--border);
  text-underline-offset: 2px;
  transition: color var(--dur) var(--ease);
}
.fd-radial-reset:hover { color: var(--accent); }

/* Inline search at the bottom of the wheel — direct text-search fallback */
.fd-radial-search {
  position: relative;
  display: flex;
  align-items: center;
}
.fd-radial-search > svg {
  position: absolute;
  left: 12px;
  width: 14px;
  height: 14px;
  stroke: var(--text-muted);
  stroke-width: 2;
  fill: none;
  pointer-events: none;
}
.fd-radial-search input {
  width: 100%;
  padding: 8px 12px 8px 34px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 12px;
  transition: border-color var(--dur) var(--ease);
}
.fd-radial-search input:focus {
  border-color: var(--accent);
  outline: none;
}

/* ── Final-level fund list (visible at level 4) ───────────────────── */
.fd-radial-funds {
  display: none;
  flex-direction: column;
  gap: var(--sp-1);
  max-height: 400px;
  overflow-y: auto;
  padding-right: 4px;
}
.fd-radial-modal[data-level="4"] .fd-radial-funds { display: flex; }
.fd-radial-modal[data-level="4"] .fd-radial-wheel-wrap { display: none; }

.fd-radial-fund {
  display: grid;
  grid-template-columns: 28px 1fr auto 22px;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-3);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.fd-radial-fund:hover {
  border-color: var(--accent);
  background: var(--gold-08);
}
.fd-radial-fund.selected {
  background: var(--gold-15);
  border-color: var(--accent);
}
.fd-radial-fund-logo {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 10px;
  color: var(--accent);
}
.fd-radial-fund-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.fd-radial-fund-name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fd-radial-fund-meta {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  letter-spacing: 0.02em;
}
.fd-radial-fund-perf {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.fd-radial-fund-perf.pos { color: var(--pos); }
.fd-radial-fund-perf.neg { color: var(--neg); }
.fd-radial-fund-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: transparent;
  transition: all var(--dur) var(--ease);
}
.fd-radial-fund.selected .fd-radial-fund-check {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
.fd-radial-fund-check svg {
  width: 12px;
  height: 12px;
  stroke: currentColor;
  stroke-width: 3;
  fill: none;
}

/* Empty state when filters yield no funds */
.fd-radial-empty {
  text-align: center;
  padding: var(--sp-6) var(--sp-4);
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 13px;
}
.fd-radial-empty strong {
  display: block;
  font-family: var(--font-display);
  font-size: 14px;
  color: var(--text);
  margin-bottom: var(--sp-1);
}

/* ── Selected count badge inside Apply button — fix the black circle ── */
.fd-selected-count {
  display: none;  /* default hidden */
}
.fd-selected-count.has-selection {
  display: inline-flex;
}

/* ════════════════════════════════════════════════════════════════════════
   RADIAL WHEEL SKELETON — port of design-system component-skeleton.html.
   This is the canonical loading state for ANY radial-wheel context, and
   supersedes whatever spinner was here previously. Hub pulses, 8 spokes
   arc in one by one with stagger, endpoint dots light up at full extension.
   ════════════════════════════════════════════════════════════════════════ */
.fd-radial-skeleton {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-5);
  padding: var(--sp-6) var(--sp-4);
}
.fd-radial-skeleton-svg {
  width: 200px;
  height: 200px;
  flex-shrink: 0;
}
.fd-radial-skeleton-text {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  max-width: 320px;
}
.fd-radial-skeleton-text .line {
  height: 11px;
  border-radius: 3px;
  background: var(--surface-2);
  position: relative;
  overflow: hidden;
}
.fd-radial-skeleton-text .line::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(201, 169, 98, 0.10) 45%,
    rgba(255, 245, 216, 0.18) 50%,
    rgba(201, 169, 98, 0.10) 55%,
    transparent 100%
  );
  background-size: 240% 100%;
  animation: fb-slide 2s linear infinite;
}
.fd-radial-skeleton-text .line.long  { width: 84%; }
.fd-radial-skeleton-text .line.med   { width: 62%; }
.fd-radial-skeleton-text .line.short { width: 38%; }

/* Hub — solid gold pulse */
.fd-radial-skeleton-hub {
  fill: var(--gold);
  filter: drop-shadow(0 0 10px rgba(201, 169, 98, 0.7));
  animation: fd-radial-sk-hub-pulse 1.6s ease-in-out infinite;
}
@keyframes fd-radial-sk-hub-pulse {
  0%, 100% { r: 6; opacity: 0.85; }
  50%      { r: 8; opacity: 1; }
}

/* Spokes — stroke-dasharray draw from center outward, staggered */
.fd-radial-skeleton-spoke {
  fill: none;
  stroke: rgba(201, 169, 98, 0.55);
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-dasharray: 60;
  stroke-dashoffset: 60;
  animation: fd-radial-sk-spoke-in 2.4s cubic-bezier(0.16, 1, 0.3, 1) infinite;
}
@keyframes fd-radial-sk-spoke-in {
  0%, 8%   { stroke-dashoffset: 60; opacity: 0; }
  25%      { stroke-dashoffset: 0;  opacity: 1; }
  70%      { stroke-dashoffset: 0;  opacity: 1; }
  90%      { stroke-dashoffset: 0;  opacity: 0; }
  100%     { stroke-dashoffset: 60; opacity: 0; }
}

/* Endpoint dots — light up at full extension */
.fd-radial-skeleton-dot {
  fill: rgba(228, 212, 164, 0);
  animation: fd-radial-sk-dot-in 2.4s ease-in-out infinite;
  transform-origin: center;
  transform-box: fill-box;
}
@keyframes fd-radial-sk-dot-in {
  0%, 22% { fill: rgba(228, 212, 164, 0);    transform: scale(0.4); }
  35%     { fill: rgba(228, 212, 164, 1);    transform: scale(1); }
  72%     { fill: rgba(228, 212, 164, 0.85); }
  90%     { fill: rgba(228, 212, 164, 0);    transform: scale(0.4); }
}

/* Reduced-motion: collapse the loop to static gold hub + faded spokes. */
@media (prefers-reduced-motion: reduce) {
  .fd-radial-skeleton-hub,
  .fd-radial-skeleton-spoke,
  .fd-radial-skeleton-dot,
  .fd-radial-skeleton-text .line::after {
    animation: none !important;
  }
  .fd-radial-skeleton-spoke { stroke-dashoffset: 0; opacity: 0.35; }
  .fd-radial-skeleton-dot { fill: rgba(228, 212, 164, 0.6); transform: scale(1); }
}

/* ── Search-status text (results count inside the search bar) ───────── */
.fd-radial-search-bar input.has-results { padding-right: 110px; }
