/**
 * Backtest (home) page — aligns with investor tools (screener / analyze / rank).
 * BEM: backtest-page, backtest-page__*
 */

/* Same shell as .screener-page / .rank-page (inside .main-container) */
.backtest-page {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem;
}

@media (max-width: 768px) {
  .backtest-page {
    padding: 2rem 1rem;
  }
}

/* —— Hero —— */
.backtest-page__hero {
  margin-bottom: 2rem;
}

.backtest-page__hero-row {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

.backtest-page__hero-title-group {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
}

.backtest-page__hero-title-group .tenachine-beta {
  position: relative;
  top: 0.06rem;
}

.backtest-page__hero-icon {
  flex-shrink: 0;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md, 10px);
  border: 1px solid rgba(50, 205, 50, 0.45);
  background: var(--bg-tertiary, #252525);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-color, #32cd32);
  font-size: 1.2rem;
}

.backtest-page__title {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-primary, #fff);
  line-height: 1;
}

.backtest-page__lede {
  margin: 0 0 1rem 0;
  max-width: 42rem;
  font-size: 0.9375rem;
  line-height: 1.55;
  color: var(--text-secondary, #a3a3a3);
}

.backtest-page__legal-note {
  margin: 0 0 1.25rem 0;
  max-width: 42rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md, 10px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.75rem;
  line-height: 1.5;
  color: rgba(255, 255, 255, 0.55);
}

.backtest-page__legal-note a {
  color: var(--primary-color, #32cd32);
  font-weight: 600;
  text-decoration: none;
}

.backtest-page__legal-note a:hover,
.backtest-page__legal-note a:focus-visible {
  text-decoration: underline;
  outline: none;
}

.backtest-page__meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.65rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.backtest-page__pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 9999px;
  background: var(--bg-tertiary, #252525);
  border: 1px solid var(--border-color, #333);
  font-size: 0.6875rem;
  font-weight: 500;
  color: var(--text-secondary, #b0b0b0);
  letter-spacing: 0.02em;
}

.backtest-page__pill i {
  color: var(--primary-color, #32cd32);
  font-size: 0.6rem;
}

/* —— Main card —— */
.backtest-page__card {
  background: rgba(26, 26, 26, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 14px;
  padding: 1.5rem 1.5rem 1.75rem;
  margin-bottom: 1.75rem;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

.backtest-page__card .form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem 1.25rem;
  margin-bottom: 1.35rem;
}

.backtest-page__card .form-group--full-width {
  grid-column: 1 / -1;
}

.backtest-page__card .form-group--batch {
  padding-top: 0;
  margin-top: 0;
}

.backtest-page__card .batch-tickers__chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  min-height: 2rem;
  margin-bottom: 0.65rem;
}

.backtest-page__card .batch-ticker-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.5rem 0.28rem 0.65rem;
  background: rgba(50, 205, 50, 0.12);
  border: 1px solid rgba(50, 205, 50, 0.25);
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 600;
  color: var(--primary-color, #32cd32);
}

.backtest-page__card .batch-ticker-chip__remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.25);
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  font-size: 0.65rem;
  transition: background 0.12s ease, color 0.12s ease;
}

.backtest-page__card .batch-ticker-chip__remove:hover {
  background: rgba(248, 113, 113, 0.35);
  color: #fff;
}

.backtest-page__card .batch-tickers__row {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.85rem;
}

.backtest-page__card .batch-tickers__row--add {
  align-items: center;
}

.backtest-page__card .batch-ticker-combo {
  position: relative;
  flex: 1;
  min-width: min(100%, 220px);
  max-width: 100%;
}

.backtest-page__card .batch-ticker-input {
  width: 100%;
  box-sizing: border-box;
}

.backtest-page__card .batch-ticker-suggest {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 55;
  max-height: min(240px, 40vh);
  overflow-y: auto;
  background: rgba(22, 22, 22, 0.98);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  padding: 0.25rem 0;
}

.backtest-page__card .batch-ticker-suggest__opt {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.45rem 0.75rem;
  border: none;
  background: transparent;
  color: #fff;
  font-size: 0.875rem;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.1s ease;
}

.backtest-page__card .batch-ticker-suggest__opt:hover,
.backtest-page__card .batch-ticker-suggest__opt:focus-visible {
  background: rgba(50, 205, 50, 0.12);
  outline: none;
}

.backtest-page__card .batch-tickers__count {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.45);
  margin-left: auto;
  flex-shrink: 0;
  align-self: center;
}

.report--batch .report__batch-table-wrap {
  overflow-x: auto;
  margin-top: 0.35rem;
}

.report--batch .report__batch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.report--batch .report__batch-table th,
.report--batch .report__batch-table td {
  padding: 0.5rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.report--batch .report__batch-table th {
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(255, 255, 255, 0.45);
}

.report--batch .report__batch-num {
  font-variant-numeric: tabular-nums;
}

.report--batch .report__batch-ok {
  color: #86efac;
  font-weight: 600;
  font-size: 0.8125rem;
}

.report--batch .report__batch-fail {
  color: #f87171;
  font-weight: 600;
  font-size: 0.8125rem;
  cursor: help;
}

.backtest-page__card .form-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.4rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.backtest-page__card .form-label i {
  color: var(--primary-color, #32cd32);
  font-size: 0.75rem;
  opacity: 0.85;
}

.backtest-page__card .form-input,
.backtest-page__card .form-select {
  width: 100%;
  background: rgba(15, 15, 15, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #fff;
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  font-size: 0.875rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.backtest-page__card .form-input:focus,
.backtest-page__card .form-select:focus {
  outline: none;
  border-color: var(--primary-color, #32cd32);
  box-shadow: 0 0 0 1px rgba(50, 205, 50, 0.15);
}

.backtest-page__card .form-input--date {
  cursor: pointer;
}

.backtest-page__card .strategy-section {
  margin-bottom: 1.1rem;
}

.backtest-page__card .strategy-label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.45);
}

.backtest-page__card .strategy-label i {
  color: var(--primary-color, #32cd32);
}

.backtest-page__card .strategy-textarea {
  min-height: 180px;
  background: rgba(15, 15, 15, 0.92);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  color: #e5e5e5;
  font-size: 0.875rem;
  line-height: 1.5;
  padding: 1rem 1.1rem;
  resize: vertical;
  transition: border-color 0.15s ease;
}

.backtest-page__card .strategy-textarea:focus {
  outline: none;
  border-color: var(--primary-color, #32cd32);
}

.backtest-page__card .strategy-textarea::placeholder {
  color: rgba(255, 255, 255, 0.28);
}

.backtest-page__card .action-section {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  gap: 0.65rem 1rem;
  width: 100%;
  padding-top: 0.15rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  margin-top: 0.1rem;
}

.backtest-page__card .btn-group-left,
.backtest-page__card .btn-group-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.backtest-page__card .btn-group-right {
  margin-left: auto;
  flex-shrink: 0;
}

.backtest-page__card .btn-utility {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: var(--text-primary, #e5e5e5);
  padding: 0.55rem 1rem;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.backtest-page__card .btn-utility:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.14);
}

/* —— Progress (shell only while visible) —— */
.backtest-page__progress-wrap:has(.progress-indicator.active),
.backtest-page__progress-wrap:has(.progress-indicator.hiding) {
  margin-bottom: 1.5rem;
  padding: 1rem;
  background:
    radial-gradient(circle at top left, rgba(50, 205, 50, 0.14), transparent 34%),
    radial-gradient(circle at top right, rgba(16, 185, 129, 0.08), transparent 28%),
    linear-gradient(180deg, rgba(24, 24, 24, 0.94), rgba(15, 15, 15, 0.88));
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 18px;
  box-shadow:
    0 18px 50px rgba(0, 0, 0, 0.32),
    inset 0 1px 0 rgba(255, 255, 255, 0.04);
  position: relative;
  overflow: hidden;
}

.backtest-page__progress-wrap:has(.progress-indicator.active)::before,
.backtest-page__progress-wrap:has(.progress-indicator.hiding)::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(120deg, transparent 0%, rgba(255, 255, 255, 0.03) 50%, transparent 100%);
  pointer-events: none;
}

.backtest-page__progress-wrap .progress-indicator.active,
.backtest-page__progress-wrap .progress-indicator.hiding {
  margin: 0 auto;
  padding: 1.15rem 1.2rem 1.1rem;
  max-width: 100%;
  background: rgba(9, 9, 9, 0.42);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 16px;
  backdrop-filter: blur(10px);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.backtest-page__progress-wrap .progress-indicator__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.1rem;
}

.backtest-page__progress-wrap .progress-indicator__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.6875rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.52);
}

.backtest-page__progress-wrap .progress-indicator__eyebrow::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--primary-color, #32cd32);
  box-shadow: 0 0 0 6px rgba(50, 205, 50, 0.08);
}

.backtest-page__progress-wrap .progress-indicator__title {
  margin-top: 0.25rem;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: rgba(255, 255, 255, 0.96);
}

.backtest-page__progress-wrap .progress-indicator__status {
  flex-shrink: 0;
  padding: 0.45rem 0.8rem;
  border-radius: 999px;
  border: 1px solid rgba(50, 205, 50, 0.28);
  background: linear-gradient(180deg, rgba(50, 205, 50, 0.16), rgba(50, 205, 50, 0.08));
  color: #b6ffb6;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.18);
}

.backtest-page__progress-wrap .progress-indicator__status::before {
  content: "";
  display: inline-block;
  width: 0.45rem;
  height: 0.45rem;
  margin-right: 0.45rem;
  border-radius: 999px;
  background: currentColor;
  box-shadow: 0 0 0 4px rgba(182, 255, 182, 0.08);
  vertical-align: middle;
}

.backtest-page__progress-wrap .progress-phases {
  margin-bottom: 0;
  padding: 0.35rem 0 0.1rem;
}

.backtest-page__progress-wrap .progress-line {
  top: 18px;
  height: 3px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.backtest-page__progress-wrap .progress-line-fill {
  background: linear-gradient(90deg, #22c55e 0%, #32cd32 45%, #86efac 100%);
  box-shadow: 0 0 18px rgba(50, 205, 50, 0.35);
}

.backtest-page__progress-wrap .progress-dot {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.7) 30%, rgba(255, 255, 255, 0.98) 31%),
    linear-gradient(180deg, #f8fafc 0%, #e5e7eb 100%);
  border: 3px solid rgba(255, 255, 255, 0.18);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: rgba(15, 15, 15, 0.72);
  transition: transform 0.25s ease, box-shadow 0.25s ease, border-color 0.25s ease, background 0.25s ease;
  position: relative;
  box-shadow:
    0 8px 18px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.65);
}

.backtest-page__progress-wrap .progress-phase.active .progress-dot {
  border-color: rgba(50, 205, 50, 0.8);
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.9) 30%, rgba(240, 253, 244, 1) 31%),
    linear-gradient(180deg, #ffffff 0%, #dcfce7 100%);
  color: #16a34a;
  box-shadow:
    0 0 0 7px rgba(50, 205, 50, 0.12),
    0 12px 24px rgba(50, 205, 50, 0.22);
  animation: pulse-dot 1.6s ease-in-out infinite;
}

.backtest-page__progress-wrap .progress-phase.completed .progress-dot {
  border-color: rgba(34, 197, 94, 0.95);
  background: linear-gradient(180deg, #34d399 0%, #22c55e 100%);
  color: #ffffff;
  box-shadow:
    0 0 0 6px rgba(34, 197, 94, 0.1),
    0 12px 24px rgba(34, 197, 94, 0.24);
}

.backtest-page__progress-wrap .progress-phase.pending .progress-dot {
  border-color: rgba(255, 255, 255, 0.12);
  background:
    radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.98), rgba(255, 255, 255, 0.82) 30%, rgba(255, 255, 255, 0.96) 31%),
    linear-gradient(180deg, #f8fafc 0%, #e5e7eb 100%);
  color: rgba(107, 114, 128, 0.9);
}

.backtest-page__progress-wrap .progress-label {
  font-size: 0.875rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: rgba(203, 213, 225, 0.82);
}

.backtest-page__progress-wrap .progress-phase.active .progress-label {
  color: #86efac;
}

.backtest-page__progress-wrap .progress-phase.completed .progress-label {
  color: rgba(167, 243, 208, 0.98);
}

.backtest-page__progress-wrap .progress-eta {
  font-size: 0.72rem;
  color: rgba(148, 163, 184, 0.96);
  margin-top: 0.3rem;
  font-weight: 500;
}

.backtest-page__progress-wrap .progress-phase.active .progress-eta {
  color: #86efac;
  font-weight: 600;
}

.backtest-page__progress-wrap .progress-phase.completed .progress-eta {
  color: rgba(167, 243, 208, 0.9);
}

/* —— Results block —— */
.backtest-page__results-zone {
  margin-top: 0.5rem;
}

.backtest-page__results-zone .results-container {
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  overflow: hidden;
  background: rgba(20, 20, 20, 0.5);
}

@media (max-width: 640px) {
  .backtest-page__title {
    font-size: 1.45rem;
  }

  .backtest-page__card .action-section {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  .backtest-page__card .btn-group-right {
    margin-left: 0;
    width: 100%;
  }

  .backtest-page__card .btn-group-right .btn-primary-action {
    flex: 1;
    justify-content: center;
  }
}

/* —— Marketing iframe (?embed=landing): real backtest UI + API, minimal chrome —— */
body.backtest-embed-landing .skip-link,
body.backtest-embed-landing > header.header,
body.backtest-embed-landing > footer.site-footer,
body.backtest-embed-landing .backtest-page__hero {
  display: none !important;
}

body.backtest-embed-landing .main-container {
  max-width: none;
  padding: 0.5rem 0.65rem 1.25rem;
}

body.backtest-embed-landing .backtest-page {
  max-width: none;
  padding: 0.5rem 0;
}

body.backtest-embed-landing .backtest-page__card .btn-group-left {
  display: none;
}

body.backtest-embed-landing #tradeSimulateBtn {
  display: none !important;
}

/* Landing iframe: hide symbols + dates so the preview reads as “plain English in” */
body.backtest-embed-landing .backtest-page__card .form-grid {
  display: none !important;
}

body.backtest-embed-landing .backtest-page__card .form-section {
  padding-top: 0.65rem;
  padding-bottom: 1rem;
}

body.backtest-embed-landing .backtest-page__card .strategy-section {
  margin-bottom: 0.85rem;
}

body.backtest-embed-landing .backtest-page__card .strategy-label span {
  font-size: 0.7rem;
  letter-spacing: 0.12em;
}

body.backtest-embed-landing .backtest-page__card .strategy-textarea {
  min-height: 200px;
  scroll-margin-top: 0.75rem;
}

@media (min-width: 640px) {
  body.backtest-embed-landing .backtest-page__card .strategy-textarea {
    min-height: 240px;
  }
}

body.backtest-embed-landing .backtest-page__card .action-section {
  margin-top: 0.35rem;
  padding-top: 0.65rem;
}
