/* ============================================================================
   FUND DETAIL — Competitor Modal (design-system styling)

   Markup is rendered server-side at the bottom of page-fund-detail.php.
   Container IDs/classes preserved exactly; this file is a pure visual layer.

     .fd-modal-overlay (#fdAddCompetitorModal)  Full-page backdrop
       └ .fd-modal                              Centred dialog
         ├ .fd-modal-header                     Title + close
         ├ .fd-modal-body                       Search + filters + fund list
         │   ├ .fd-modal-search                 Input with leading icon
         │   ├ .fd-modal-synthetic-section      My Portfolios (optional)
         │   ├ .fd-modal-category-filter        Pill tabs
         │   └ .fd-modal-fund-list              Selectable fund rows
         └ .fd-modal-footer                     Cancel + Apply CTA

   Visual language:
   - Dialog floats with shadow-elevated, 16px radius, 1px border
   - Backdrop: rgba(10,10,11,0.7) + 8px blur
   - Animation: 0.32s cubic-bezier(.16,1,.3,1) scale + fade-in
   - Active state on rows: gold-15 background, gold border-left bar
   - Selected count badge: solid gold pill with obsidian numerals
   ============================================================================ */

/* ── Overlay (backdrop) ──────────────────────────────────────────────── */
.fd-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(10, 10, 11, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-5);

  /* Hidden by default — JS toggles .visible to open. */
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-slow) var(--ease);
}
.fd-modal-overlay.visible {
  opacity: 1;
  pointer-events: auto;
}
[data-theme="light"] .fd-modal-overlay {
  background: rgba(248, 248, 250, 0.6);
}

/* ── Modal dialog ────────────────────────────────────────────────────── */
.fd-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-elevated);
  width: 100%;
  max-width: 600px;
  max-height: calc(100vh - 80px);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Entrance animation: scale up + fade in. */
  transform: translateY(16px) scale(0.96);
  opacity: 0;
  transition: transform var(--dur-slow) var(--ease), opacity var(--dur-slow) var(--ease);
}
.fd-modal-overlay.visible .fd-modal {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* ── Header ──────────────────────────────────────────────────────────── */
.fd-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.fd-modal-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  letter-spacing: var(--tracking-display);
  color: var(--text);
  margin: 0;
}
.fd-modal-close {
  width: 32px;
  height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.fd-modal-close:hover {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}
.fd-modal-close svg {
  width: 16px;
  height: 16px;
  stroke: currentColor;
  stroke-width: 2;
  fill: none;
}

/* ── Body (scrolls if content exceeds modal height) ──────────────────── */
.fd-modal-body {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5);
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

/* Search input with leading icon */
.fd-modal-search {
  position: relative;
  display: flex;
  align-items: center;
}
.fd-modal-search > svg {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  stroke: var(--text-muted);
  stroke-width: 2;
  fill: none;
  pointer-events: none;
}
.fd-modal-search input {
  width: 100%;
  padding: 10px 12px 10px 38px;
  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-modal-search input:focus {
  border-color: var(--accent);
  outline: none;
}
.fd-modal-search input::placeholder { color: var(--text-muted); }

/* Synthetic ("My Portfolios") section */
.fd-modal-synthetic-section {
  background: var(--gold-08);
  border: 1px solid var(--accent);
  border-radius: var(--r-md);
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}
.fd-modal-synthetic-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
}
.fd-modal-synthetic-header svg { color: var(--accent); }
.fd-modal-synthetic-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}
.fd-synthetic-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-2) var(--sp-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: var(--font-body);
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: border-color var(--dur) var(--ease);
}
.fd-synthetic-item:hover { border-color: var(--accent); }
.fd-synthetic-item.selected {
  background: var(--gold-15);
  border-color: var(--accent);
}

/* Category filter pill tabs */
.fd-modal-category-filter {
  display: flex;
  gap: var(--sp-1);
  overflow-x: auto;
  padding-bottom: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.fd-modal-category-filter::-webkit-scrollbar { display: none; }
.fd-category-filter-btn {
  flex-shrink: 0;
  padding: 6px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text-2);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.04em;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--dur) var(--ease);
}
.fd-category-filter-btn:hover:not(.active) {
  border-color: var(--accent);
  color: var(--accent);
}
.fd-category-filter-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* ── Fund list (selectable rows) ─────────────────────────────────────── */
.fd-modal-fund-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-1);
}

/* Each row — JS emits: [logo] [info name + meta] [perf] [check]
   Grid: 4 columns auto/auto-fill on the side elements, name+meta flexes. */
.fd-modal-fund-item,
.fd-modal-fund-row {
  display: grid;
  grid-template-columns: 32px 1fr auto 22px;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3) var(--sp-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.fd-modal-fund-item:hover,
.fd-modal-fund-row:hover {
  border-color: var(--accent);
  border-left-color: var(--accent);
  background: var(--gold-08);
}
.fd-modal-fund-item.selected,
.fd-modal-fund-row.selected {
  background: var(--gold-15);
  border-color: var(--accent);
  border-left-color: var(--accent);
}

/* Selection check — circle by default, gold tick when selected. The JS
   swaps the SVG path between empty circle and check-in-circle, so we
   only style the wrapper + colour state. */
.fd-modal-fund-check {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
  transition: color var(--dur) var(--ease);
}
.fd-modal-fund-item:hover .fd-modal-fund-check { color: var(--text-2); }
.fd-modal-fund-item.selected .fd-modal-fund-check { color: var(--accent); }
.fd-modal-fund-check svg {
  width: 100%;
  height: 100%;
  stroke: currentColor;
  fill: none;
}

/* Fund name + ISIN block */
.fd-modal-fund-info,
.fd-modal-fund-item .info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.fd-modal-fund-name,
.fd-modal-fund-item .name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.fd-modal-fund-isin,
.fd-modal-fund-meta,
.fd-modal-fund-item .meta {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: 0.02em;
  color: var(--text-muted);
}

/* 1Y return (right side) */
.fd-modal-fund-perf,
.fd-modal-fund-item .perf {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  text-align: right;
}
.fd-modal-fund-perf.pos { color: var(--pos); }
.fd-modal-fund-perf.neg { color: var(--neg); }

/* Fund logo (right of perf, optional small square) */
.fd-modal-fund-logo,
.fd-modal-fund-item .logo {
  width: 28px;
  height: 28px;
  border-radius: var(--r-sm);
  background: var(--surface);
  border: 1px solid var(--border);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

/* Empty / loading inside the modal list */
.fd-modal-fund-list:empty::before {
  content: 'Loading funds…';
  display: block;
  padding: var(--sp-5);
  text-align: center;
  font-family: var(--font-body);
  font-size: 12px;
  color: var(--text-muted);
}

/* ── Footer (Cancel + Apply with count badge) ────────────────────────── */
.fd-modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-2);
  padding: var(--sp-4) var(--sp-5);
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.fd-modal-btn {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 9px 16px;
  border-radius: var(--r-md);
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  border: 1px solid transparent;
}
.fd-modal-btn.secondary {
  background: transparent;
  color: var(--text-2);
  border-color: var(--border);
}
.fd-modal-btn.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.fd-modal-btn.primary {
  background: linear-gradient(180deg, var(--gold-light) 0%, var(--gold) 50%, var(--gold-dark) 100%);
  color: var(--accent-ink);
  border-color: var(--gold);
  box-shadow: var(--shadow-cta-gold);
}
.fd-modal-btn.primary:hover {
  background: linear-gradient(180deg, #ecdfb5 0%, var(--gold-light) 50%, var(--gold) 100%);
  box-shadow: 0 6px 18px rgba(201, 169, 98, 0.4);
}
.fd-modal-btn:disabled,
.fd-modal-btn.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  box-shadow: none;
}

/* Selected count badge inside the Apply button */
.fd-selected-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  background: var(--accent-ink);
  color: var(--accent);
  border-radius: var(--r-pill);
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.fd-selected-count[data-count="0"] {
  display: none;
}

/* ── Body scrollbar — keeps the rest of the page from jumping ────────── */
body.fb-modal-open {
  overflow: hidden;
}

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .fd-modal-overlay { padding: 0; align-items: flex-end; }
  .fd-modal {
    max-width: none;
    max-height: 92vh;
    border-radius: var(--r-card) var(--r-card) 0 0;
    border-bottom: none;
  }
  /* Slide-up entrance variant on small screens */
  .fd-modal-overlay.visible .fd-modal {
    animation: fb-sheet-up var(--dur-slow) var(--ease);
  }
  .fd-modal-fund-item,
  .fd-modal-fund-row {
    grid-template-columns: auto 1fr auto;
  }
  .fd-modal-fund-logo { display: none; }
}

/* ── Reduced-motion fallback ─────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .fd-modal-overlay,
  .fd-modal { transition-duration: 0.01ms; }
  .fd-modal-overlay.visible .fd-modal { animation: none; }
}
