/* =============================================================================
 * TICKER SPARKLINE MODAL — shared between easycompare and discover
 * =============================================================================
 *
 * Multi-period sparkline grid for a single ticker. The JS lives at
 * `js/sparkline/tickerSparklineModal.js` (also shared).
 *
 * Why standalone:
 *   - Originally lived in css/betterthanspy.css alongside the discover-app
 *     styles. When easycompare started using the same modal we had two
 *     options: (a) load all of betterthanspy.css from index.html (drags in
 *     hundreds of unrelated discover styles, plus name-collision risk on
 *     shared classes like .sparkline-cell), or (b) extract just the modal-
 *     specific block into its own file. We picked (b).
 *   - Both `discover.html` and `index.html` now load this file directly.
 *     `betterthanspy.css` no longer contains the modal block — see the
 *     "TICKER SPARKLINE MODAL" section there for the (now removed) origin.
 *   - The cell-sparkline styles (`.sparkline-cell` rules in
 *     `#discover-table` / `#ranking-table`) STAY in their respective app
 *     stylesheets because they're table-scoped, not modal-scoped.
 *
 * Theming:
 *   - All colors source from CSS custom properties (`--bg-primary`,
 *     `--success`, etc.) defined globally — light/dark mode "just works"
 *     without any media queries here.
 *   - Animation `compare-spin` is keyframe-defined at the bottom so this
 *     file is fully self-contained (originally lived in betterthanspy.css
 *     and was implicitly inherited).
 * ============================================================================= */

.ticker-sparkline-modal {
  position: fixed;
  inset: 0;
  z-index: 10001;
  display: none;
  align-items: center;
  justify-content: center;
}

.ticker-sparkline-modal.open {
  display: flex;
}

.ticker-sparkline-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
}

.ticker-sparkline-modal-content {
  position: relative;
  width: 95vw;
  max-width: 1400px;
  max-height: 90vh;
  /* Fallback `#ffffff` matters here: easycompare's main app stylesheet
   * (style.css) doesn't define --bg-primary — that variable is set in
   * betterthanspy.css, which only loads on /discover. Without the
   * fallback, the card resolves to a transparent background and the
   * underlying table bleeds through, defeating the modal entirely.
   * Same pattern repeats for every var() below. */
  background: var(--bg-primary, #ffffff);
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.ticker-sparkline-modal-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border, rgba(27, 31, 35, 0.1));
  background: var(--bg-secondary, #f8f9fa);
}

.ticker-sparkline-modal-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
  color: var(--text-primary, #1f2328);
}

.ticker-sparkline-modal-close {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
  font-size: 1.5rem;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.15s ease;
}

.ticker-sparkline-modal-close:hover {
  background: var(--bg-hover, #e9ecef);
  color: var(--text-primary, #1f2328);
}

/* Log scale toggle */
.ticker-sparkline-modal-controls {
  display: flex;
  align-items: center;
}

.log-scale-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-secondary, #4a5159);
  user-select: none;
}

.log-scale-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--accent-primary, #228be6);
}

.log-scale-toggle .toggle-label {
  white-space: nowrap;
}

.log-scale-toggle:hover {
  color: var(--text-primary, #1f2328);
}

/* =====================================================================
 * Benchmark "Compare vs:" strip
 *
 * Lives between the modal header and body. Stays hidden when no
 * `benchmarkOptions` is passed (the discover-app path), so this whole
 * block is dead code there. The strip is intentionally NOT scrollable
 * vertically — chips wrap to a second row on narrow widths so users
 * never have to "scroll to find a ticker." Horizontal scroll is also
 * disabled because (a) wrapping plays nicer with keyboard tab order
 * and (b) typical comparison sets max out around 10–15 tickers, not
 * 100. If we ever ship larger sets we can revisit overflow:auto.
 * ===================================================================== */
.ticker-sparkline-benchmark-strip {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border, rgba(31, 35, 40, 0.08));
  background: var(--bg-secondary, #f6f8fa);
  font-size: 13px;
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
}

.ticker-sparkline-benchmark-strip[hidden] {
  display: none;
}

.benchmark-strip-label {
  font-weight: 600;
  color: var(--text-primary, #1f2328);
  margin-right: 4px;
  white-space: nowrap;
}

.benchmark-strip-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1 1 auto;
  min-width: 0;
}

.benchmark-strip-chip {
  appearance: none;
  border: 1px solid var(--border, rgba(31, 35, 40, 0.15));
  background: var(--bg-primary, #ffffff);
  color: var(--text-primary, #1f2328);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease;
  white-space: nowrap;
}

.benchmark-strip-chip:hover {
  background: var(--bg-hover, rgba(31, 35, 40, 0.05));
  border-color: var(--accent-primary, #228be6);
}

/* Active = currently-displayed benchmark. Uses the accent color
 * filled rather than just an outline so it's unambiguous which chip
 * the grid below is being compared against — outline-only states
 * looked too similar to focus/hover at a glance. */
.benchmark-strip-chip.is-active {
  background: var(--accent-primary, #228be6);
  border-color: var(--accent-primary, #228be6);
  color: #ffffff;
  cursor: default;
}

.benchmark-strip-chip.is-active:hover {
  background: var(--accent-primary-hover, #1c7ed6);
  border-color: var(--accent-primary-hover, #1c7ed6);
}

.benchmark-strip-chip:focus-visible {
  outline: 2px solid var(--accent-primary, #228be6);
  outline-offset: 2px;
}

/* Reset link is a button-styled-as-text. We hide it (not just disable)
 * when the user is already on the original benchmark — see
 * _renderBenchmarkStrip. The leading "× " is in the markup, not a
 * pseudo-element, so screen readers announce it as part of the label. */
.benchmark-strip-reset {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
  font-size: 12px;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  white-space: nowrap;
  margin-left: auto;
}

.benchmark-strip-reset:hover {
  color: var(--danger, #dc2626);
  background: var(--bg-hover, rgba(31, 35, 40, 0.05));
}

.benchmark-strip-reset[hidden] {
  display: none;
}

.ticker-sparkline-modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* Loading state */
.ticker-sparkline-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 12px;
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
}

.ticker-sparkline-loading .spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border, rgba(27, 31, 35, 0.1));
  border-top-color: var(--accent-primary, #228be6);
  border-radius: 50%;
  animation: compare-spin 0.8s linear infinite;
}

/* Grid of sparkline cards */
.ticker-sparkline-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

@media (max-width: 768px) {
  .ticker-sparkline-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 500px) {
  .ticker-sparkline-grid {
    grid-template-columns: 1fr;
  }
}

/* Individual sparkline card */
.sparkline-card {
  background: var(--bg-secondary, #f8f9fa);
  border: 1px solid var(--border, rgba(27, 31, 35, 0.1));
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color 0.15s ease;
}

.sparkline-card.beat {
  border-color: var(--success, #16a34a);
  background: linear-gradient(135deg, rgba(16, 185, 129, 0.05) 0%, transparent 100%);
}

.sparkline-card.lost {
  border-color: var(--danger, #dc2626);
  background: linear-gradient(135deg, rgba(239, 68, 68, 0.05) 0%, transparent 100%);
}

.sparkline-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sparkline-preset {
  font-weight: 600;
  font-size: 1.1rem;
  color: var(--text-primary, #1f2328);
}

.sparkline-diff {
  font-size: 0.8rem;
  font-weight: 500;
  padding: 2px 6px;
  border-radius: 4px;
}

.sparkline-diff.positive {
  color: var(--success, #16a34a);
  background: rgba(16, 185, 129, 0.1);
}

.sparkline-diff.negative {
  color: var(--danger, #dc2626);
  background: rgba(239, 68, 68, 0.1);
}

.sparkline-chart {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}

.sparkline-chart .sparkline-svg {
  width: 100%;
  height: auto;
}

.sparkline-card-footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.85rem;
}

.sparkline-return {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sparkline-ticker-label,
.sparkline-benchmark-label {
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sparkline-ticker-value,
.sparkline-benchmark-value {
  font-weight: 600;
  font-size: 1rem;
}

.sparkline-ticker-value.positive {
  color: var(--success, #16a34a);
}

.sparkline-ticker-value.negative {
  color: var(--danger, #dc2626);
}

.sparkline-benchmark-value {
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
}

/* Trend ATH/ATL row inside a sparkline card. Sits below the ticker/benchmark
   return rows; flex-basis 100% forces it onto its own line in the existing
   row-flex footer without restructuring the markup. */
.sparkline-trend-ath-atl {
  flex-basis: 100%;
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 4px;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-family: var(--font-mono, ui-monospace, "SF Mono", Menlo, Consolas, monospace);
}

.sparkline-trend-ath-atl-label {
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
  font-family: var(--font-sans, inherit);
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.sparkline-trend-ath-atl-value {
  font-weight: 700;
  font-size: 0.9rem;
}

.sparkline-trend-ath-atl-rank {
  margin-left: auto;
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
  font-size: 0.7rem;
}

.sparkline-trend-ath-atl.trend-ath-atl-strong-up {
  background: rgba(34, 197, 94, 0.18);
  color: var(--success, #16a34a);
}

.sparkline-trend-ath-atl.trend-ath-atl-mild-up {
  background: rgba(34, 197, 94, 0.08);
  color: var(--success, #16a34a);
}

.sparkline-trend-ath-atl.trend-ath-atl-neutral {
  background: transparent;
  color: var(--text-secondary, #4a5159);
}

.sparkline-trend-ath-atl.trend-ath-atl-mild-down {
  background: rgba(239, 68, 68, 0.08);
  color: var(--danger, #dc2626);
}

.sparkline-trend-ath-atl.trend-ath-atl-strong-down {
  background: rgba(239, 68, 68, 0.18);
  color: var(--danger, #dc2626);
}

/* Summary section */
.ticker-sparkline-summary {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border, rgba(27, 31, 35, 0.1));
}

.sparkline-summary-content {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 40px;
}

@media (max-width: 600px) {
  .sparkline-summary-content {
    flex-direction: column;
    gap: 20px;
  }
}

.summary-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.summary-label {
  font-size: 0.75rem;
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.summary-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary, #1f2328);
}

.summary-value.positive {
  color: var(--success, #16a34a);
}

.summary-value.negative {
  color: var(--danger, #dc2626);
}

/* Verdict banner for social sharing appeal */
.summary-verdict {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 24px;
  border-radius: 8px;
  background: var(--bg-secondary, #f8f9fa);
}

.verdict-text {
  font-size: 1.3rem;
  font-weight: 700;
}

.verdict-ratio {
  font-size: 0.85rem;
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
}

.summary-verdict.verdict-excellent .verdict-text {
  color: var(--success, #16a34a);
}

.summary-verdict.verdict-good .verdict-text {
  color: #22c55e;
}

.summary-verdict.verdict-neutral .verdict-text {
  color: var(--text-secondary, #4a5159);
}

.summary-verdict.verdict-poor .verdict-text {
  color: var(--danger, #dc2626);
}

/* Streak dots visualization */
.streak-stat {
  flex-direction: column;
  gap: 12px;
}

.streak-dots {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: center;
}

.streak-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  cursor: help;
}

.streak-item:hover .streak-dot {
  transform: scale(1.2);
}

.streak-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  transition: transform 0.15s ease;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.streak-dot.win {
  background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
}

.streak-dot.loss {
  background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
}

.streak-dot.neutral {
  background: var(--text-muted, rgba(31, 35, 40, 0.55));
  opacity: 0.5;
}

.streak-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* Error state */
.ticker-sparkline-error {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 12px;
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
}

.ticker-sparkline-error .retry-btn {
  padding: 8px 16px;
  background: var(--accent-primary, #228be6);
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

.ticker-sparkline-error .retry-btn:hover {
  background: var(--accent-primary-hover, #1971c2);
}

/* Empty state */
.ticker-sparkline-empty {
  text-align: center;
  padding: 40px;
  color: var(--text-muted, rgba(31, 35, 40, 0.55));
}

/* Body scroll lock when modal open */
body.modal-open {
  overflow: hidden;
}

/* Spinner keyframe — kept local so this file is self-sufficient and the
 * loading spinner above renders correctly even when betterthanspy.css
 * isn't loaded (i.e. when easycompare uses just style.css + this file). */
@keyframes compare-spin {
  to { transform: rotate(360deg); }
}

/* Base sparkline SVG sizing (cell + modal both use this class). The
 * width/height defaults here are the safe modal-card values; the
 * narrower cell variant lives in each app's table-scoped CSS where
 * it's overridden via #ranking-table .sparkline-cell .sparkline-svg
 * or #discover-table .sparkline-cell .sparkline-svg. */
.sparkline-svg {
  display: block;
  width: 100%;
  height: 40px;
}
