/**
 * BACKTEST DISPLAY CSS
 * =====================
 * Comprehensive styling for backtest results display.
 * Pair with backtest-display.js
 */

/* =========================================================================
   CSS VARIABLES
   ========================================================================= */

:root {
  --bt-bg: #1a1b26;
  --bt-bg-card: #24253a;
  --bt-bg-section: #2a2b42;
  --bt-bg-hover: #32334a;
  --bt-border: #3a3b52;
  --bt-text: #e4e4e7;
  --bt-text-muted: #888;
  --bt-positive: #10b981;
  --bt-negative: #ef4444;
  --bt-warning: #f59e0b;
  --bt-highlight: #7c3aed;
  --bt-accent: #6366f1;

  /* Study side accents (bull/bear/neutral) */
  --bt-side-bull: #10b981;
  --bt-side-bear: #ef4444;
  --bt-side-neutral: #60a5fa;
}

/* =========================================================================
   BULL / BEAR / NEUTRAL DIFFERENTIATION
   ========================================================================= */

.bt-study-bull { --bt-side-color: var(--bt-side-bull); }
.bt-study-bear { --bt-side-color: var(--bt-side-bear); }
.bt-study-neutral { --bt-side-color: var(--bt-side-neutral); }

.bt-preview-card.bt-study-bull,
.bt-preview-card.bt-study-bear,
.bt-preview-card.bt-study-neutral {
  border-left: 4px solid var(--bt-side-color);
}

/* Also color-code the full detail card if present */
.backtest-card.bt-study-bull,
.backtest-card.bt-study-bear,
.backtest-card.bt-study-neutral {
  border-left: 4px solid var(--bt-side-color);
}

.bt-side-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  line-height: 1;
  margin-right: 8px;
  transform: translateY(-1px);
  border: 1px solid rgba(148, 163, 184, 0.25);
  background: rgba(148, 163, 184, 0.10);
  color: var(--bt-text);
}

.bt-side-pill.bt-side-bull {
  border-color: rgba(16, 185, 129, 0.35);
  background: rgba(16, 185, 129, 0.18);
  color: var(--bt-side-bull);
}

.bt-side-pill.bt-side-bear {
  border-color: rgba(239, 68, 68, 0.35);
  background: rgba(239, 68, 68, 0.16);
  color: var(--bt-side-bear);
}

.bt-side-pill.bt-side-neutral {
  border-color: rgba(96, 165, 250, 0.35);
  background: rgba(96, 165, 250, 0.16);
  color: var(--bt-side-neutral);
}

/* =========================================================================
   UTILITY CLASSES
   ========================================================================= */

.bt-positive { color: var(--bt-positive) !important; }
.bt-negative { color: var(--bt-negative) !important; }
.bt-bold { font-weight: 600; }
.bt-muted { color: var(--bt-text-muted); font-size: 0.85em; }
.bt-center { text-align: center; }

/* =========================================================================
   PREVIEW CARD (Compact List View)
   ========================================================================= */

.bt-preview-card {
  background: var(--bt-bg-card);
  border: 1px solid var(--bt-border);
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 12px;
  transition: all 0.2s ease;
}

.bt-preview-card:hover {
  border-color: var(--bt-accent);
  background: var(--bt-bg-hover);
}

.bt-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.bt-preview-title-area {
  flex: 1;
}

.bt-preview-title {
  margin: 0 0 4px 0;
  font-size: 1.1em;
  font-weight: 600;
  color: var(--bt-text);
}

.bt-preview-desc {
  margin: 0;
  font-size: 0.85em;
  color: var(--bt-text-muted);
  line-height: 1.4;
}

.bt-preview-badge {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 0.8em;
  font-weight: 600;
  white-space: nowrap;
}

.bt-badge-success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--bt-positive);
}

.bt-badge-warning {
  background: rgba(245, 158, 11, 0.2);
  color: var(--bt-warning);
}

.bt-badge-gold {
  background: linear-gradient(135deg, rgba(255, 215, 0, 0.3), rgba(255, 165, 0, 0.2));
  color: #ffd700;
  border: 1px solid rgba(255, 215, 0, 0.4);
  text-shadow: 0 0 8px rgba(255, 215, 0, 0.5);
}

.bt-badge-danger {
  background: rgba(239, 68, 68, 0.2);
  color: var(--bt-negative);
}

.bt-badge-info {
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
}

.bt-preview-stats {
  display: flex;
  gap: 16px;
  padding: 12px 0;
  border-top: 1px solid var(--bt-border);
  border-bottom: 1px solid var(--bt-border);
  margin-bottom: 12px;
}

.bt-preview-stat {
  flex: 1;
  text-align: center;
}

.bt-preview-stat-value {
  display: block;
  font-size: 1.1em;
  font-weight: 600;
  color: var(--bt-text);
}

.bt-preview-stat-label {
  display: block;
  font-size: 0.7em;
  color: var(--bt-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 2px;
}

.bt-preview-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.bt-preview-tags {
  display: flex;
  gap: 6px;
}

.bt-tag {
  padding: 2px 8px;
  background: var(--bt-bg-section);
  border-radius: 4px;
  font-size: 0.75em;
  color: var(--bt-text-muted);
}

.bt-preview-link {
  color: var(--bt-accent);
  font-size: 0.85em;
  text-decoration: none;
  font-weight: 500;
}

.bt-preview-link:hover {
  text-decoration: underline;
}

/* =========================================================================
   FULL POST
   ========================================================================= */

.bt-full-post {
  background: var(--bt-bg-card);
  border-radius: 12px;
  padding: 24px;
  max-width: 1000px;
  margin: 0 auto;
}

.bt-post-header {
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--bt-border);
}

.bt-post-title {
  margin: 0 0 8px 0;
  font-size: 1.6em;
  font-weight: 700;
  color: var(--bt-text);
}

.bt-post-desc {
  margin: 0 0 12px 0;
  color: var(--bt-text-muted);
  line-height: 1.5;
}

.bt-post-meta {
  display: flex;
  gap: 20px;
  font-size: 0.85em;
  color: var(--bt-text-muted);
}

/* =========================================================================
   EQUITY CHART
   ========================================================================= */

.bt-chart-container {
  background: var(--bt-bg-section);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 24px;
}

.bt-equity-canvas {
  width: 100%;
  height: auto;
  display: block;
}

/* =========================================================================
   KPI DASHBOARD
   ========================================================================= */

.bt-kpi-dashboard {
  margin-bottom: 24px;
}

.bt-kpi-section {
  margin-bottom: 16px;
}

.bt-kpi-section-title {
  margin: 0 0 12px 0;
  font-size: 1em;
  font-weight: 600;
  color: var(--bt-text);
}

.bt-kpi-grid {
  display: grid;
  gap: 12px;
}

.bt-kpi-grid-6 { grid-template-columns: repeat(6, 1fr); }
.bt-kpi-grid-4 { grid-template-columns: repeat(4, 1fr); }
.bt-kpi-grid-3 { grid-template-columns: repeat(3, 1fr); }

@media (max-width: 768px) {
  .bt-kpi-grid-6 { grid-template-columns: repeat(3, 1fr); }
  .bt-kpi-grid-4 { grid-template-columns: repeat(2, 1fr); }
}

.bt-kpi-card {
  background: var(--bt-bg-section);
  border-radius: 8px;
  padding: 16px;
  text-align: center;
}

.bt-kpi-value {
  font-size: 1.4em;
  font-weight: 700;
  color: var(--bt-text);
  margin-bottom: 4px;
}

.bt-kpi-label {
  font-size: 0.7em;
  color: var(--bt-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.bt-kpi-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.bt-kpi-group {
  background: var(--bt-bg-section);
  border-radius: 8px;
  padding: 16px;
}

.bt-kpi-group-title {
  margin: 0 0 12px 0;
  font-size: 0.85em;
  font-weight: 600;
  color: var(--bt-text-muted);
}

.bt-kpi-item {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid var(--bt-border);
}

.bt-kpi-item:last-child {
  border-bottom: none;
}

.bt-kpi-item-label {
  color: var(--bt-text-muted);
  font-size: 0.85em;
}

.bt-kpi-item-value {
  font-weight: 600;
  font-size: 0.9em;
}

/* =========================================================================
   SECTIONS
   ========================================================================= */

.bt-section {
  margin-bottom: 24px;
  padding: 20px;
  background: var(--bt-bg-section);
  border-radius: 8px;
}

.bt-section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.bt-section-title {
  margin: 0;
  font-size: 1.1em;
  font-weight: 600;
  color: var(--bt-text);
}

.bt-section-desc {
  margin: 0 0 16px 0;
  font-size: 0.9em;
  color: var(--bt-text-muted);
  line-height: 1.5;
}

.bt-badge {
  padding: 4px 10px;
  background: var(--bt-bg-card);
  border-radius: 6px;
  font-size: 0.8em;
  color: var(--bt-text-muted);
}

.bt-badge-success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--bt-positive);
}

.bt-subsection-title {
  margin: 0 0 12px 0;
  font-size: 0.9em;
  font-weight: 600;
  color: var(--bt-text-muted);
}

/* =========================================================================
   TABLES
   ========================================================================= */

.bt-table-wrap {
  overflow-x: auto;
  margin: 0 -8px;
  padding: 0 8px;
}

.bt-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85em;
}

.bt-table th {
  text-align: left;
  padding: 10px 12px;
  background: var(--bt-bg-card);
  color: var(--bt-text-muted);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 0.75em;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--bt-border);
}

.bt-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--bt-border);
  color: var(--bt-text);
}

.bt-table tr:hover td {
  background: var(--bt-bg-hover);
}

.bt-table-compact td {
  padding: 8px 10px;
  font-size: 0.9em;
}

.bt-row-aggressive {
  background: rgba(239, 68, 68, 0.05);
}

.bt-row-conservative {
  background: rgba(16, 185, 129, 0.05);
}

.bt-mode-name {
  font-weight: 500;
  white-space: nowrap;
}

.bt-legend {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  font-size: 0.8em;
  color: var(--bt-text-muted);
}

/* =========================================================================
   TRADE ANALYSIS
   ========================================================================= */

.bt-trade-analysis {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

@media (max-width: 768px) {
  .bt-trade-analysis {
    grid-template-columns: 1fr;
  }
}

/* R-Distribution Histogram */
.bt-histogram {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 120px;
  padding-top: 20px;
}

.bt-hist-bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
}

.bt-hist-bar {
  width: 100%;
  min-height: 4px;
  border-radius: 4px 4px 0 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  transition: height 0.3s ease;
}

.bt-hist-win {
  background: var(--bt-positive);
}

.bt-hist-loss {
  background: var(--bt-negative);
}

.bt-hist-count {
  font-size: 0.7em;
  font-weight: 600;
  color: white;
  margin-top: 4px;
}

.bt-hist-label {
  margin-top: 8px;
  font-size: 0.7em;
  color: var(--bt-text-muted);
}

/* Crash Summary */
.bt-crash-list {
  background: var(--bt-bg-card);
  border-radius: 8px;
  overflow: hidden;
}

.bt-crash-row {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--bt-border);
}

.bt-crash-row:last-child {
  border-bottom: none;
}

.bt-crash-row.bt-crash-total {
  background: var(--bt-bg-hover);
  font-weight: 600;
  border-top: 2px solid var(--bt-border);
}

.bt-crash-name {
  flex: 1;
  font-size: 0.85em;
}

.bt-crash-trades {
  width: 70px;
  text-align: center;
  font-size: 0.8em;
  color: var(--bt-text-muted);
}

.bt-crash-r {
  width: 60px;
  text-align: right;
  font-weight: 600;
  font-size: 0.9em;
}

.bt-sim-btn {
  margin-left: 8px;
  width: 28px;
  height: 28px;
  border: none;
  background: var(--bt-accent);
  color: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.bt-sim-btn:hover {
  background: var(--bt-highlight);
}

/* =========================================================================
   METHODOLOGY
   ========================================================================= */

.bt-methodology-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  font-size: 0.9em;
}

.bt-methodology-grid div {
  color: var(--bt-text);
}

.bt-methodology-grid strong {
  color: var(--bt-text-muted);
}

/* =========================================================================
   CLASSIFICATION SYSTEM STYLES
   ========================================================================= */

.classification-badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.classification-badge:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.classification-badge-tag {
  background: rgba(139, 92, 246, 0.15);
  color: #8b5cf6;
  border: 1px solid rgba(139, 92, 246, 0.3);
  font-weight: 500;
  text-transform: none;
}

.classification-filter-section {
  background: var(--backtester-dim);
  padding: 16px;
  border-radius: 8px;
  margin-bottom: 20px;
  border: 1px solid var(--border);
}

.classification-filter-group {
  margin-bottom: 12px;
}

.classification-filter-group:last-child {
  margin-bottom: 0;
}

.classification-filter-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.classification-filter-options {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.classification-filter-btn {
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--backtester-dim);
  color: var(--fg);
  cursor: pointer;
  transition: all 0.2s ease;
}

.classification-filter-btn:hover {
  border-color: var(--backtester-purple);
  background: rgba(139, 92, 246, 0.1);
}

.classification-filter-btn.active {
  background: var(--backtester-purple);
  color: white;
  border-color: var(--backtester-purple);
  font-weight: 600;
}

.classification-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.classification-summary-card {
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.1), rgba(59, 130, 246, 0.1));
  padding: 16px;
  border-radius: 8px;
  border: 1px solid rgba(139, 92, 246, 0.2);
  text-align: center;
}

.classification-summary-value {
  font-size: 24px;
  font-weight: bold;
  color: var(--fg);
  margin-bottom: 4px;
}

.classification-summary-label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* =========================================================================
   RESPONSIVE
   ========================================================================= */

@media (max-width: 600px) {
  .bt-full-post {
    padding: 16px;
  }
  
  .bt-preview-stats {
    flex-wrap: wrap;
  }
  
  .bt-preview-stat {
    flex: 0 0 calc(50% - 8px);
  }
  
  .bt-kpi-row {
    grid-template-columns: 1fr;
  }
  
  .bt-methodology-grid {
    grid-template-columns: 1fr;
  }
}

/* =========================================================================
   PRINT STYLES
   ========================================================================= */

@media print {
  .bt-full-post {
    break-inside: avoid;
    background: white;
  }
  
  .bt-sim-btn {
    display: none;
  }
}

/* =========================================================================
   MODAL OVERLAY
   ========================================================================= */

.bt-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(4px);
  z-index: 1000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
  overflow-y: auto;
  padding: 24px;
}

.bt-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.bt-modal-content {
  max-width: 1000px;
  margin: 0 auto;
  background: var(--bt-bg-card);
  border-radius: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  animation: bt-modal-in 0.3s ease;
}

@keyframes bt-modal-in {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.bt-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bt-bg-section);
  color: var(--bt-text-muted);
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.bt-close-btn:hover {
  background: var(--bt-negative);
  color: white;
}

/* Make the card relative for close button positioning */
.backtest-card {
  position: relative;
  padding: 24px;
}

.backtest-card.protected {
  border-left: 4px solid var(--bt-warning);
}
