/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --panel: #12151c;
  --border: #232833;
  --text: #c9d1d9;
  --muted: #8b949e;
  --accent: #58a6ff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.app-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.app-nav .brand { font-weight: 700; letter-spacing: 0.02em; }
.app-nav a { color: var(--muted); text-decoration: none; }

main { max-width: 1100px; margin: 0 auto; padding: 24px; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-header > form, .page-header .btn-primary, .page-header .btn-secondary { flex-shrink: 0; }
.page-header h1 { margin: 0 0 4px; font-size: 22px; }
.muted { color: var(--muted); margin: 0; }
.action { color: var(--accent); text-decoration: none; white-space: nowrap; }
.action:hover { text-decoration: underline; }

.grid { width: 100%; border-collapse: collapse; }
.grid th, .grid td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.grid th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
.grid td.num, .grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .strong { font-weight: 700; }
.grid tr[data-controller="row-link"] { cursor: pointer; }
.grid tr[data-controller="row-link"]:hover td { background: rgba(88, 166, 255, 0.07); }
.mono, code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: rgba(38, 166, 154, 0.16); color: #4cd0c0; }
.badge.warn { background: rgba(239, 83, 80, 0.16); color: #ff8a87; }

.chart-panel { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; }
.controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 14px; margin-bottom: 14px; }
.controls label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.controls select, .controls input:not([type="submit"]) {
  background: #0e1116; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: 13px;
}
.presets { display: flex; gap: 6px; }
.presets button {
  background: #0e1116; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; cursor: pointer; font-size: 12px;
}
.presets button:hover { border-color: var(--accent); color: var(--accent); }

.chart { height: 520px; width: 100%; }
.equity-chart { height: 340px; width: 100%; }
.osc-chart { height: 150px; width: 100%; margin-top: 6px; }
.chart-bands { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
.chart-band { position: absolute; top: 0; bottom: 30px; }
.legend-toggle { cursor: pointer; user-select: none; }
.legend-toggle:hover { color: var(--text); }
.legend-off { opacity: 0.4; text-decoration: line-through; }

.chart-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 12px; flex-wrap: wrap; gap: 8px; }
.legend { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; font-size: 12px; }
.legend-name { font-weight: 700; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); }
.legend-item i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; }
.legend-item i.marker { width: 0; height: 0; background: none; border-left: 5px solid transparent; border-right: 5px solid transparent; }
.legend-item i.marker.up { border-bottom: 8px solid #26a69a; }
.legend-item i.marker.down { border-top: 8px solid #ef5350; }
.status { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.status.error { color: #ff8a87; }
.empty { color: var(--muted); }
.empty.error { color: #ff8a87; }

.badge.info { background: rgba(88, 166, 255, 0.16); color: var(--accent); }

.section { font-size: 16px; margin: 28px 0 12px; }
.pos { color: #4cd0c0; }
.neg { color: #ff8a87; }

.btn-primary {
  background: var(--accent); color: #06121f; border: 0; border-radius: 6px;
  padding: 9px 16px; font-size: 13px; font-weight: 700; cursor: pointer; align-self: flex-end;
}
.btn-primary:hover { filter: brightness(1.08); }

.backtest-launch { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-top: 20px; }
.recent-backtests { list-style: none; padding: 0; margin: 10px 0 0; display: flex; flex-direction: column; gap: 6px; }
.recent-backtests li { display: flex; align-items: center; gap: 10px; font-size: 13px; }

.overfit-banner {
  display: flex; align-items: center; gap: 24px; flex-wrap: wrap;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 20px; margin-bottom: 18px;
}
.overfit-banner .lbl { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); }
.overfit-banner .big { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; }
.overfit-banner .arrow { font-size: 22px; color: var(--muted); }
.overfit-banner .gap { margin-left: auto; text-align: right; }
.overfit-banner .hint { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }

.grid.metrics td.num, .grid.trades td.num { font-variant-numeric: tabular-nums; }

.split-charts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin: 18px 0 8px; }
.split-col { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.split-col h3 { margin: 0 0 8px; font-size: 14px; text-transform: capitalize; }
.mini-chart { width: 100%; }
.mini-chart.equity { height: 190px; }
.mini-chart.drawdown { height: 110px; }
.mini-label { font-size: 11px; color: var(--muted); margin: 8px 0 2px; }
.mini-empty { display: block; padding: 24px 0; text-align: center; color: var(--muted); font-size: 12px; }

.table-scroll { max-height: 460px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
.grid.trades { font-size: 12px; }
.grid.trades th { position: sticky; top: 0; background: var(--panel); }
.reason { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: rgba(139,148,158,0.16); }
.reason.stop_loss { background: rgba(239,83,80,0.18); color: #ff8a87; }
.reason.take_profit { background: rgba(38,166,154,0.18); color: #4cd0c0; }
.reason.end_of_data { background: rgba(88,166,255,0.16); color: var(--accent); }

@media (max-width: 800px) { .split-charts { grid-template-columns: 1fr; } }

.small { font-size: 12px; }
.grid td.small, .grid td.mono.small { color: var(--muted); }

.spec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.spec-card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 16px 20px; }
.spec-card .section { margin-top: 0; }
.spec-list { margin: 0; display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; }
.spec-list dt { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; padding-top: 2px; }
.spec-list dd { margin: 0; }
.spec-list dd div { margin-bottom: 2px; }

.prose { line-height: 1.6; }
.prose p { margin: 0 0 10px; }
.prose ul, .prose ol { margin: 0 0 10px; padding-left: 20px; }
.prose li { margin-bottom: 4px; }
.prose li > ul, .prose li > ol { margin: 4px 0 0; }
.prose strong { color: #e6edf3; }
.prose code { background: #0e1116; border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.prose pre { background: #0e1116; border: 1px solid var(--border); border-radius: 6px; padding: 12px; overflow-x: auto; }
.prose pre code { border: 0; padding: 0; }
.prose h1, .prose h2, .prose h3, .prose h4 { margin: 14px 0 8px; font-size: 15px; }
.prose a { color: var(--accent); }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }

.stacked-form { display: flex; flex-direction: column; gap: 12px; }
.field-row { display: flex; gap: 14px; flex-wrap: wrap; }
.field-row label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.stacked-form input:not([type="submit"]) {
  background: #0e1116; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 8px; font-size: 13px;
}
.stacked-form .btn-primary { align-self: flex-start; }

@media (max-width: 800px) { .spec-grid { grid-template-columns: 1fr; } }

.stacked-form textarea {
  background: #0e1116; color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 8px; font-size: 13px; font-family: inherit; resize: vertical; width: 100%;
}
.stacked-form label { width: 100%; }
.stacked-form textarea.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.btn-secondary {
  background: var(--accent); color: #06121f; border: 1px solid var(--accent);
  border-radius: 6px; padding: 8px 14px; font-size: 13px; font-weight: 700; cursor: pointer; align-self: flex-start;
}
.btn-secondary:hover { filter: brightness(1.08); }
.link-button {
  background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px;
}
.link-button:hover { text-decoration: underline; }
.compile-error { border-color: #ef5350; }
.compile-error ul { margin: 6px 0 0; padding-left: 18px; }
pre.json {
  background: #0e1116; border: 1px solid var(--border); border-radius: 6px; padding: 12px;
  overflow-x: auto; font-size: 12px; margin-top: 8px; max-height: 320px;
}
details summary { cursor: pointer; margin-top: 10px; }
.flash { padding: 10px 24px; border-bottom: 1px solid var(--border); font-size: 13px; }
.flash.notice { background: rgba(38,166,154,0.12); color: #4cd0c0; }
.flash.alert { background: rgba(239,83,80,0.14); color: #ff8a87; }
.header-actions { display: flex; align-items: center; gap: 16px; }
.link-button.danger { color: #ff8a87; }
.grid td .link-button { font-size: 12px; }
.baseline-row { background: rgba(88,166,255,0.06); }
.baseline-row td { border-bottom: 2px solid var(--border); }
tr.flagged { background: rgba(239,83,80,0.07); }
tr.flagged td:first-child { border-left: 3px solid #ef5350; }

.candidate-rationale { margin: 0; white-space: pre-line; line-height: 1.6; }
