/* Backtest Lab — 3-panel layout. Tokens only, no private palette layer. */
.lab-shell { max-width: 1720px; margin: 0 auto; padding: 18px clamp(24px, 3.5vw, 64px) 80px; }

/* Compact header: title + description on one baseline row instead of the
   shared .page-header band, so the panels start higher. */
.lab-shell .page-header { display: flex; align-items: baseline; gap: 14px; padding: 0 0 12px; margin-bottom: 16px; }
.lab-shell .page-header h1 { font-size: 1.15rem; margin: 0; white-space: nowrap; }
.lab-shell .page-header .subtitle { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 700px) { .lab-shell .page-header .subtitle { display: none; } }
/* Anchored to the viewport, not the top of the document: the Run button can
   sit a screenful below where this banner used to render, so the old inline
   version was invisible at the moment it mattered. */
.notice { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 60;
  display: flex; align-items: flex-start; gap: 12px; margin: 0;
  max-width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--down); border-left-width: 4px; border-radius: 8px;
  padding: 12px 14px; font-size: 0.9rem; color: var(--text); background: var(--bg-panel);
  box-shadow: var(--shadow-2);
  animation: notice-in 0.18s ease-out; }
/* A class selector outranks the UA's [hidden] rule, so restate it. */
.notice[hidden] { display: none; }
.notice.ok { border-color: var(--accent); }
.notice-close { flex: none; margin-left: auto; background: none; border: 0; padding: 0 2px;
  color: var(--muted); font-size: 1.15rem; line-height: 1; cursor: pointer; }
.notice-close:hover { color: var(--text-strong); }
@keyframes notice-in { from { opacity: 0; transform: translate(-50%, 10px); }
                       to   { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { .notice { animation: none; } }
.flag-notice { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; margin: 0 0 16px; font-size: 0.9rem; color: var(--muted); background: var(--bg-card); }
.auth-gate { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); padding: 18px 22px; margin-bottom: 20px; }
.auth-gate h2 { margin: 0 0 6px; font-size: 1.05rem; }
.auth-gate p { margin: 0 0 10px; color: var(--muted); font-size: 0.9rem; }
.auth-gate a { color: var(--accent); font-weight: 600; text-decoration: none; }

/* 3-panel workspace: strategies | workspace | history */
.workspace { display: grid; grid-template-columns: 320px minmax(0, 1fr) 280px; gap: 18px; align-items: start; }
.panel-left, .panel-right { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow-y: auto;
  /* Breathing room inside the scroll clip: without it the card borders sit on
     the clip edge and the scrollbar overlays the right border. */
  padding: 2px 10px 14px 2px; scrollbar-gutter: stable; }
.panel-title { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin: 0 0 10px; font-weight: 600; }

@media (max-width: 1399px) {
  .workspace { grid-template-columns: 280px minmax(0, 1fr); }
  .panel-right { grid-column: 1 / -1; position: static; max-height: none; display: grid; grid-template-columns: 1fr 1fr; gap: 18px; align-items: start; }
}
@media (max-width: 979px) {
  .workspace { grid-template-columns: 1fr; }
  .panel-left { position: static; max-height: none; }
  .panel-right { grid-template-columns: 1fr; }
}

/* Strategy list (left panel) */
.strategy-list { display: flex; flex-direction: column; gap: 8px; }
.strat-item { display: grid; grid-template-columns: 36px minmax(0,1fr); gap: 10px; align-items: start; width: 100%;
  text-align: left; border: 1px solid var(--border); border-left-width: 3px; border-radius: 10px;
  background: var(--bg-card); padding: 11px 12px; cursor: pointer; color: var(--text); font: inherit; }
.strat-item:hover { background: var(--bg-panel); }
.strat-item.active { border-left-color: var(--accent); background: var(--bg-panel); }
.strat-item.active .strat-rank { color: var(--accent); }
.strat-rank { font-family: var(--font-mono); font-size: 1.05rem; color: var(--muted); line-height: 1.3; }
.strat-name { display: block; font-weight: 600; font-size: 0.92rem; }
.strat-teaser { color: var(--muted); font-size: 0.78rem; margin-top: 2px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.strat-engine { display: inline-block; font-family: var(--font-mono); font-size: 0.66rem; color: var(--muted);
  border: 1px solid var(--border); border-radius: 20px; padding: 2px 8px; margin-top: 6px; white-space: nowrap; }

/* Workspace (middle panel) */
.strat-header h2 { margin: 0 0 8px; font-size: 1.25rem; }
.strat-about { margin: 0 0 14px; }
.strat-about summary {
  display: inline-flex; align-items: center; gap: 7px; cursor: pointer; list-style: none;
  color: var(--accent); font-size: 0.8rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
  border: 1px solid var(--border); border-radius: 20px; padding: 5px 14px; background: var(--bg-card); user-select: none; }
.strat-about summary::-webkit-details-marker { display: none; }
.strat-about summary:hover { border-color: var(--accent); }
.about-chevron { display: inline-block; transition: transform 0.15s; font-size: 0.9rem; }
.strat-about[open] .about-chevron { transform: rotate(90deg); }
.strat-about[open] { border-left: 3px solid var(--accent); padding-left: 12px; }
.strat-philosophy { color: var(--text); font-size: 0.92rem; line-height: 1.55; margin: 10px 0 4px; max-width: 80ch; }
.about-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); font-weight: 600; margin: 12px 0 4px; }
.about-list { margin: 0; padding-left: 18px; color: var(--text); font-size: 0.88rem; line-height: 1.55; max-width: 80ch; }
.about-list li { margin: 2px 0; }
.about-tradeoff { color: var(--text); font-size: 0.88rem; line-height: 1.55; margin: 0; max-width: 80ch; }
.strat-datanote { color: var(--muted); font-size: 0.78rem; margin: 10px 0 0; }
#formSlot form { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); padding: 16px; margin-bottom: 18px; }
.empty-state { border: 1px dashed var(--border); border-radius: 10px; background: var(--bg-card); padding: 28px 22px;
  color: var(--muted); font-size: 0.9rem; text-align: center; }

/* Parameter form */
.param-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px 14px; margin-bottom: 14px; }
.param-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.param-grid label[hidden] { display: none; }  /* display:flex above would otherwise override the hidden attribute */
.param-grid input, .param-grid select, .positions-editor input, .run-name {
  background: var(--bg-panel); color: var(--text-strong); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px 10px; font: 500 0.9rem var(--font-mono); min-width: 0; }
.param-grid input:focus, .param-grid select:focus, .run-name:focus { outline: none; border-color: var(--accent); }
.param-help { font-size: 0.72rem; color: var(--muted); text-transform: none; letter-spacing: 0; }

/* "?" bubble + hover/focus tooltip on parameter labels */
.param-name { display: inline-flex; align-items: center; gap: 6px; }
.param-tip { position: relative; display: inline-flex; align-items: center; justify-content: center;
  width: 15px; height: 15px; border-radius: 50%; border: 1px solid var(--border);
  color: var(--muted); background: var(--bg-panel); font: 600 0.62rem var(--font-ui);
  cursor: help; text-transform: none; letter-spacing: 0; }
.param-tip:hover, .param-tip:focus { color: var(--accent); border-color: var(--accent); outline: none; }
.param-tip::after { content: attr(data-tip); position: absolute; bottom: calc(100% + 8px); left: 50%;
  transform: translateX(-50%); width: max-content; max-width: 280px;
  background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 11px; font: 400 0.76rem/1.5 var(--font-ui); color: var(--text);
  text-transform: none; letter-spacing: 0; white-space: normal;
  opacity: 0; visibility: hidden; transition: opacity 0.12s; z-index: 40;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.35); }
.param-tip:hover::after, .param-tip:focus::after { opacity: 1; visibility: visible; }
.param-wide { grid-column: 1 / -1; }
.positions-editor { display: flex; flex-direction: column; gap: 6px; }
.positions-editor .pos-row { display: grid; grid-template-columns: minmax(0,1fr) 90px 30px; gap: 6px; }
.pos-tools { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.weight-sum { font-family: var(--font-mono); font-size: 0.78rem; color: var(--muted); }
.weight-sum.bad { color: var(--down); }
.weight-sum.ok { color: var(--up); }

.form-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.run-btn { background: var(--accent); color: var(--bg, #0b0d10); border: 0; border-radius: 8px; padding: 10px 22px; font-weight: 700; font-size: 0.95rem; cursor: pointer; }
.run-btn:disabled { opacity: 0.5; cursor: default; }
.ghost-btn { background: transparent; color: var(--text); border: 1px solid var(--border); border-radius: 8px; padding: 9px 16px; cursor: pointer; font-size: 0.85rem; }
.ghost-btn:hover { border-color: var(--accent); color: var(--accent); }
.run-name { flex: 1; min-width: 140px; font-size: 0.85rem; font-family: var(--font-ui); }

/* Results */
.results { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); padding: 18px; }
/* A strategy switch replaces the header, the form and the results at once;
   the shared fade makes that read as one transition rather than three
   separate jumps, and signals that the panel below now belongs to the
   strategy just picked. */
.panel-enter { animation: panel-enter 0.16s ease-out; }
@keyframes panel-enter { from { opacity: 0; transform: translateY(5px); }
                         to   { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .panel-enter { animation: none; } }
.results-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.results-head h2 { margin: 0; font-size: 1.1rem; }
.status-chip { font-family: var(--font-mono); font-size: 0.75rem; border: 1px solid var(--border); border-radius: 20px; padding: 3px 12px; color: var(--muted); }
/* Running: the chip carries a pulsing dot and counts seconds, so a long daily
   backtest reads as working rather than stuck. */
.status-chip.busy { border-color: var(--accent-line); color: var(--accent); }
.status-chip.busy::before { content: ''; display: inline-block; width: 6px; height: 6px; margin-right: 7px;
  border-radius: 50%; background: var(--accent); vertical-align: middle; animation: bt-pulse 1.1s ease-in-out infinite; }
@keyframes bt-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* Loading placeholders hold the shape of the result that is coming: the same
   tile grid, the same chart box. */
.metric.skeleton { background: var(--bg-panel); }
.metric.skeleton b, .metric.skeleton .metric-label { display: block; border-radius: 4px; background: var(--bg-chip); }
.metric.skeleton b { height: 1.05rem; width: 68%; margin-bottom: 6px; }
.metric.skeleton .metric-label { height: 0.7rem; width: 46%; }
.metric.skeleton b, .metric.skeleton .metric-label, .equity-chart.loading { animation: bt-shimmer 1.4s ease-in-out infinite; }
.equity-chart.loading { border: 1px dashed var(--border); border-radius: 8px; background: var(--bg-panel); }
/* Absolute so the label never adds height to the chart host — ECharts owns
   that box and measures it. */
.equity-chart.loading::after { content: 'Simulating…'; position: absolute; inset: 0;
  display: grid; place-items: center; color: var(--muted); font-size: 0.8rem; letter-spacing: 0.04em; }
@keyframes bt-shimmer { 0%, 100% { opacity: 1; } 50% { opacity: 0.45; } }

/* The Run button stays busy for the whole run, not just the submit request. */
.run-btn.busy { position: relative; padding-left: 40px; }
.run-btn.busy::before { content: ''; position: absolute; left: 20px; top: 50%; width: 12px; height: 12px;
  margin: -6px 0 0 -6px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  animation: bt-spin 0.7s linear infinite; }
@keyframes bt-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .status-chip.busy::before, .metric.skeleton b, .metric.skeleton .metric-label,
  .equity-chart.loading, .run-btn.busy::before { animation: none; }
}
.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin: 16px 0; }
.metric { border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; background: var(--bg-panel); }
.metric b { display: block; font-family: var(--font-mono); font-size: 1.05rem; }
.metric .metric-label { display: inline-flex; align-items: center; gap: 5px; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.metric b.pos { color: var(--up); } .metric b.neg { color: var(--down); }
.equity-chart { width: 100%; height: 320px; position: relative; }
.footnotes { color: var(--muted); font-size: 0.76rem; line-height: 1.5; margin: 10px 0 0; }
.table-scroll { overflow-x: auto; }
.trade-table { width: 100%; border-collapse: collapse; font-size: 0.82rem; font-family: var(--font-mono); }
.trade-table th { text-align: left; color: var(--muted); font-weight: 500; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.trade-table td { padding: 7px 10px; border-bottom: 1px solid var(--border-soft, var(--border)); }
.trade-table .pos { color: var(--up); } .trade-table .neg { color: var(--down); }
.trade-table .muted { color: var(--muted); }
/* Realized return rides beside the P&L dollars without competing with them. */
.trade-table small { color: var(--muted); margin-left: 5px; font-size: 0.92em; }
/* Numbers right-align so magnitudes line up; the first three columns are labels. */
.trade-table td:nth-child(n+4), .trade-table th:nth-child(n+4) { text-align: right; }
.results h3 { font-size: 0.9rem; margin: 22px 0 10px; }

/* Right rail: recent runs + saved strategies */
.rail-section { border: 1px solid var(--border); border-radius: 10px; background: var(--bg-card); padding: 14px; }
.rail-section + .rail-section { margin-top: 18px; }
@media (max-width: 1399px) { .rail-section + .rail-section { margin-top: 0; } }
@media (max-width: 979px) { .rail-section + .rail-section { margin-top: 18px; } }
.rail-head { display: flex; justify-content: space-between; align-items: center; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 10px; }
.rail-head button { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 0.95rem; }
.rail-actions { display: inline-flex; align-items: center; gap: 8px; }
.rail-clear { font-size: 0.66rem !important; text-transform: uppercase; letter-spacing: 0.05em;
  border: 1px solid var(--border) !important; border-radius: 12px; padding: 2px 8px; }
.rail-clear:hover { color: var(--down); border-color: var(--down) !important; }
.run-history { display: flex; flex-direction: column; gap: 8px; }
.run-card { position: relative; text-align: left; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; cursor: pointer; color: var(--text); font-size: 0.78rem; }
.run-card:hover { border-color: var(--accent); }
.run-card strong { display: block; font-family: var(--font-mono); font-weight: 500; }
.run-card small { color: var(--muted); }
.run-card small.ok { color: var(--up); } .run-card small.bad { color: var(--down); }
.run-card .strat-chip { display: inline-block; font-size: 0.66rem; border: 1px solid var(--border); border-radius: 12px; padding: 1px 7px; margin-bottom: 3px; color: var(--muted); }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--muted); vertical-align: 1px; }
.status-dot.ok { background: var(--up); }
.status-dot.bad { background: var(--down); }
.status-dot.busy { background: var(--accent); }
.card-delete { position: absolute; top: 6px; right: 8px; background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 0.85rem; padding: 2px 4px; }
.card-delete:hover { color: var(--down); }
.muted { color: var(--muted); font-size: 0.82rem; }
