:root {
  color-scheme: dark;
  --bg: #0d1218;
  --bg-deep: #090d12;
  --panel: #121a23;
  --panel-raised: #17222d;
  --panel-soft: #101820;
  --line: #263441;
  --line-bright: #344554;
  --text: #eef3f6;
  --muted: #8797a5;
  --muted-strong: #b3c0c9;
  --cyan: #42d6cf;
  --cyan-soft: rgba(66, 214, 207, 0.14);
  --amber: #f2b463;
  --amber-soft: rgba(242, 180, 99, 0.14);
  --red: #ef7a72;
  --red-soft: rgba(239, 122, 114, 0.13);
  --blue: #71a8ff;
  --green: #8ed7a4;
  --shadow: 0 16px 44px rgba(0, 0, 0, 0.2);
  --radius: 8px;
  --font-sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Microsoft YaHei", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg-deep); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button, input, select { font: inherit; }
button { color: inherit; }
a { color: inherit; text-decoration: none; }

.app-shell { min-height: 100vh; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 68px;
  padding: 0 32px;
  background: rgba(13, 18, 24, 0.95);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.brand { display: inline-flex; align-items: center; gap: 12px; min-width: 180px; }
.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid rgba(66, 214, 207, 0.7);
  color: var(--cyan);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0;
  background: var(--cyan-soft);
}
.brand-copy { display: grid; gap: 1px; }
.brand-copy strong { font-size: 17px; letter-spacing: 0.08em; }
.eyebrow { color: var(--muted); font-family: var(--font-mono); font-size: 10px; font-weight: 700; letter-spacing: 0.11em; text-transform: uppercase; }
.topbar-status { display: flex; align-items: center; gap: 9px; color: var(--muted-strong); font-family: var(--font-mono); font-size: 11px; }
.status-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.status-dot.ok { background: var(--cyan); box-shadow: 0 0 0 3px var(--cyan-soft); }
.status-dot.warn { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.status-dot.error { background: var(--red); box-shadow: 0 0 0 3px var(--red-soft); }
.icon-button { display: grid; width: 32px; height: 32px; margin-left: 7px; place-items: center; border: 1px solid var(--line-bright); border-radius: 50%; background: transparent; color: var(--muted-strong); cursor: pointer; font-size: 18px; line-height: 1; }
.icon-button:hover { border-color: var(--cyan); color: var(--cyan); }
.icon-button:disabled { cursor: wait; opacity: 0.45; }

.workspace { width: min(1600px, calc(100% - 64px)); margin: 0 auto; padding: 28px 0 44px; }
.hero-strip { display: flex; justify-content: space-between; gap: 40px; padding: 24px 0 26px; border-bottom: 1px solid var(--line); }
.hero-strip h1 { max-width: 660px; margin: 8px 0 6px; font-size: clamp(27px, 3vw, 40px); letter-spacing: 0; line-height: 1.12; }
.hero-subtitle { margin: 0; color: var(--muted-strong); font-family: var(--font-mono); font-size: 12px; }
.tag-row { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 19px; }
.tag, .paper-badge, .live-pill, .anchor-badge { display: inline-flex; align-items: center; border: 1px solid var(--line-bright); border-radius: 999px; padding: 4px 9px; font-family: var(--font-mono); font-size: 10px; font-weight: 700; letter-spacing: 0.02em; }
.tag-cyan { border-color: rgba(66, 214, 207, 0.45); color: var(--cyan); background: var(--cyan-soft); }
.tag-amber { border-color: rgba(242, 180, 99, 0.45); color: var(--amber); background: var(--amber-soft); }
.tag-red { border-color: rgba(239, 122, 114, 0.45); color: var(--red); background: var(--red-soft); }
.hero-callout { align-self: flex-end; display: grid; gap: 5px; width: min(330px, 100%); padding-left: 17px; border-left: 2px solid var(--amber); color: var(--muted-strong); font-size: 12px; }
.hero-callout strong { color: var(--text); font-size: 14px; }

.metrics-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin: 20px 0; }
.metric-card { min-height: 116px; padding: 16px 17px 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.metric-card-accent { border-color: rgba(66, 214, 207, 0.42); background: linear-gradient(135deg, rgba(66, 214, 207, 0.08), var(--panel) 70%); }
.metric-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: 0.03em; }
.asset-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; }
.dot-brent { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-soft); }
.dot-wti { background: var(--blue); box-shadow: 0 0 0 3px rgba(113, 168, 255, 0.14); }
.metric-unit { color: var(--muted); font-family: var(--font-mono); font-size: 9px; font-weight: 400; }
.metric-value { display: block; margin: 10px 0 5px; color: var(--text); font-family: var(--font-mono); font-size: 25px; font-weight: 700; letter-spacing: 0; }
.metric-detail { display: block; overflow: hidden; color: var(--muted); font-family: var(--font-mono); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(320px, 0.75fr); align-items: start; gap: 14px; }
.main-column, .side-column { display: grid; gap: 14px; min-width: 0; }
.panel { min-width: 0; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 18px 19px 0; }
.panel-heading h2 { margin: 5px 0 0; font-size: 17px; letter-spacing: 0; }
.control-stack { display: grid; justify-items: end; gap: 8px; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-soft); }
.segment { min-height: 27px; padding: 0 9px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); cursor: pointer; font-size: 11px; font-weight: 700; }
.segment:hover { color: var(--text); }
.segment.active { background: var(--panel-raised); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-bright); }
.segmented.compact .segment { min-width: 42px; font-family: var(--font-mono); font-size: 10px; }
.legend-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin: 17px 19px 0; color: var(--muted-strong); font-size: 10px; }
.legend-row > span { display: inline-flex; align-items: center; gap: 5px; }
.legend-line { display: inline-block; width: 19px; height: 2px; }
.legend-spread { background: var(--cyan); }
.legend-baseline { border-top: 2px dashed var(--amber); }
.legend-band { display: inline-block; width: 19px; height: 7px; border-top: 1px solid var(--amber); border-bottom: 1px solid var(--amber); background: var(--amber-soft); }
.legend-muted { margin-left: auto; color: var(--muted); font-family: var(--font-mono); }
.chart-wrap { position: relative; height: 425px; margin: 10px 11px 0; }
#spread-chart, #equity-chart { display: block; width: 100%; height: 100%; }
.chart-tooltip { position: absolute; z-index: 2; min-width: 150px; padding: 8px 10px; border: 1px solid var(--line-bright); border-radius: 5px; background: rgba(9, 13, 18, 0.95); box-shadow: var(--shadow); color: var(--text); font-family: var(--font-mono); font-size: 10px; pointer-events: none; }
.chart-tooltip strong { display: block; margin-bottom: 3px; color: var(--cyan); font-size: 11px; }
.chart-tooltip span { display: block; color: var(--muted-strong); }
.chart-footnote { display: flex; justify-content: space-between; gap: 16px; margin: 0 19px; padding: 11px 0 15px; border-top: 1px solid var(--line); color: var(--muted); font-size: 10px; }
.data-source-label { flex: 0 0 auto; color: var(--muted-strong); font-family: var(--font-mono); }

.backtest-panel { overflow: hidden; }
.backtest-heading { align-items: center; }
.heading-actions { display: flex; align-items: center; gap: 9px; }
.paper-badge { border-color: rgba(142, 215, 164, 0.35); color: var(--green); background: rgba(142, 215, 164, 0.08); }
.button, .preset-button { border: 1px solid var(--line-bright); border-radius: 5px; cursor: pointer; font-size: 11px; font-weight: 700; }
.button { min-height: 31px; padding: 0 11px; }
.button-primary { border-color: rgba(66, 214, 207, 0.5); background: var(--cyan); color: #071013; }
.button-primary:hover { background: #6ae4de; }
.backtest-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; margin: 17px 19px 0; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.toolbar-label { color: var(--muted); font-family: var(--font-mono); font-size: 10px; }
.preset-button { min-height: 26px; padding: 0 9px; background: var(--panel-soft); color: var(--muted-strong); }
.preset-button:hover, .preset-button.active { border-color: var(--cyan); color: var(--cyan); background: var(--cyan-soft); }
.toolbar-note { margin-left: 5px; color: var(--muted); font-size: 10px; }
.backtest-grid { display: grid; grid-template-columns: minmax(260px, 0.85fr) minmax(0, 1.5fr); gap: 15px; padding: 15px 19px 0; }
.parameter-panel { padding: 14px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-soft); }
.parameter-header, .mini-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.parameter-state { color: var(--cyan); font-family: var(--font-mono); font-size: 10px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; margin-top: 15px; }
.form-grid label, .band-input-row label { display: grid; gap: 5px; min-width: 0; }
.form-grid label > span, .band-input-row label > span { color: var(--muted-strong); font-size: 10px; }
em { color: var(--muted); font-family: var(--font-mono); font-size: 9px; font-style: normal; }
input, select { width: 100%; min-width: 0; height: 32px; padding: 0 8px; border: 1px solid var(--line-bright); border-radius: 4px; outline: none; background: #0d141b; color: var(--text); font-family: var(--font-mono); font-size: 12px; }
input:focus, select:focus { border-color: var(--cyan); box-shadow: 0 0 0 2px var(--cyan-soft); }
.parameter-divider { height: 1px; margin: 15px 0 13px; background: var(--line); }
.band-title { display: flex; justify-content: space-between; gap: 10px; color: var(--muted-strong); font-size: 11px; font-weight: 700; }
.band-title-note { color: var(--muted); font-size: 9px; font-weight: 400; }
.band-input-row { display: flex; align-items: flex-end; gap: 7px; margin-top: 9px; }
.band-input-row label { flex: 1; }
.band-dash { padding-bottom: 8px; color: var(--muted); }
.band-unit { padding-bottom: 7px; color: var(--muted); font-family: var(--font-mono); font-size: 9px; white-space: nowrap; }
.toggle-row { display: flex; align-items: flex-start; gap: 9px; margin-top: 15px; cursor: pointer; }
.toggle-row input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.toggle-control { position: relative; flex: 0 0 auto; width: 29px; height: 17px; border: 1px solid var(--line-bright); border-radius: 999px; background: #0b1117; transition: 0.15s ease; }
.toggle-control::after { position: absolute; top: 3px; left: 3px; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); content: ""; transition: 0.15s ease; }
.toggle-row input:checked + .toggle-control { border-color: var(--cyan); background: var(--cyan-soft); }
.toggle-row input:checked + .toggle-control::after { left: 15px; background: var(--cyan); }
.toggle-row strong, .toggle-row small { display: block; }
.toggle-row strong { color: var(--muted-strong); font-size: 10px; }
.toggle-row small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.results-panel { min-width: 0; }
.result-metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
.result-metric { min-height: 76px; padding: 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-soft); }
.result-metric span, .result-metric small { display: block; color: var(--muted); font-size: 9px; }
.result-metric strong { display: block; margin: 6px 0 3px; color: var(--text); font-family: var(--font-mono); font-size: 18px; }
.result-metric small { overflow: hidden; font-family: var(--font-mono); text-overflow: ellipsis; white-space: nowrap; }
.equity-wrap { height: 216px; margin-top: 13px; padding: 11px 11px 7px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-soft); }
.mini-heading { color: var(--muted-strong); font-size: 10px; font-weight: 700; }
.mini-heading span:last-child { color: var(--muted); font-family: var(--font-mono); font-size: 9px; font-weight: 400; }
.trade-log { margin: 15px 19px 0; padding: 13px 0 19px; border-top: 1px solid var(--line); }
.table-scroll { overflow-x: auto; margin-top: 9px; }
table { width: 100%; min-width: 690px; border-collapse: collapse; font-size: 10px; }
th { padding: 7px 8px; border-bottom: 1px solid var(--line-bright); color: var(--muted); font-family: var(--font-mono); font-size: 9px; font-weight: 400; text-align: left; white-space: nowrap; }
td { padding: 8px; border-bottom: 1px solid rgba(38, 52, 65, 0.7); color: var(--muted-strong); font-family: var(--font-mono); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
.direction-long, .positive { color: var(--green) !important; }
.direction-short, .negative { color: var(--red) !important; }
.empty-row { padding: 20px 8px; color: var(--muted); text-align: center; }

.signal-panel, .basis-panel, .events-panel, .source-panel { overflow: hidden; }
.live-pill { gap: 7px; border-color: rgba(66, 214, 207, 0.35); color: var(--cyan); background: var(--cyan-soft); }
.live-pill .status-dot { width: 5px; height: 5px; box-shadow: none; background: var(--cyan); }
.signal-main { display: grid; gap: 2px; margin: 20px 19px 14px; padding: 17px; border-left: 2px solid var(--cyan); background: var(--cyan-soft); }
.signal-main.signal-warn { border-color: var(--amber); background: var(--amber-soft); }
.signal-main.signal-danger { border-color: var(--red); background: var(--red-soft); }
.signal-kicker { color: var(--muted); font-family: var(--font-mono); font-size: 10px; }
.signal-main strong { font-size: 27px; letter-spacing: 0; }
.signal-main > span:last-child { color: var(--muted-strong); font-size: 11px; }
.signal-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1px; margin: 0 19px; border: 1px solid var(--line); background: var(--line); }
.signal-grid > div { min-height: 58px; padding: 10px; background: var(--panel-soft); }
.signal-grid span, .signal-grid strong { display: block; }
.signal-grid span { color: var(--muted); font-size: 9px; }
.signal-grid strong { margin-top: 5px; color: var(--muted-strong); font-family: var(--font-mono); font-size: 12px; }
.signal-note { margin: 14px 19px 18px; color: var(--muted); font-size: 10px; }
.anchor-badge { border-color: rgba(242, 180, 99, 0.42); color: var(--amber); background: var(--amber-soft); }
.anchor-badge.anchor-ok { border-color: rgba(66, 214, 207, 0.42); color: var(--cyan); background: var(--cyan-soft); }
.anchor-badge.anchor-danger { border-color: rgba(239, 122, 114, 0.42); color: var(--red); background: var(--red-soft); }
.basis-meter { margin: 22px 19px 0; }
.meter-scale { display: flex; justify-content: space-between; color: var(--muted); font-family: var(--font-mono); font-size: 10px; }
.meter-track { position: relative; height: 8px; margin: 8px 0 9px; border: 1px solid var(--line-bright); background: #0b1117; }
.meter-range { position: absolute; top: 1px; bottom: 1px; left: 10%; width: 55%; background: var(--amber-soft); border-top: 1px solid var(--amber); border-bottom: 1px solid var(--amber); }
.meter-marker { position: absolute; top: -4px; width: 2px; height: 16px; background: var(--text); box-shadow: 0 0 0 2px rgba(238, 243, 246, 0.14); }
.meter-value { color: var(--amber); font-family: var(--font-mono); font-size: 20px; font-weight: 700; }
.basis-copy { margin: 12px 19px 0; color: var(--muted-strong); font-size: 11px; }
.risk-list { display: grid; gap: 8px; margin: 16px 19px 18px; padding-top: 13px; border-top: 1px solid var(--line); }
.risk-list > div { display: flex; gap: 8px; color: var(--muted); font-size: 10px; }
.risk-marker { flex: 0 0 auto; width: 7px; height: 7px; margin-top: 4px; border-radius: 50%; }
.risk-cyan { background: var(--cyan); }
.risk-amber { background: var(--amber); }
.risk-red { background: var(--red); }
.event-count { color: var(--muted); font-family: var(--font-mono); font-size: 10px; }
.event-list { display: grid; gap: 0; margin: 15px 19px 18px; }
.event-item { display: grid; grid-template-columns: 55px 1fr; gap: 11px; padding: 11px 0; border-top: 1px solid var(--line); }
.event-item:first-child { border-top: 0; }
.event-date { color: var(--muted); font-family: var(--font-mono); font-size: 9px; }
.event-body { min-width: 0; }
.event-title { display: flex; align-items: flex-start; gap: 6px; color: var(--muted-strong); font-size: 10px; font-weight: 700; }
.event-title a { color: var(--cyan); font-size: 10px; }
.event-detail { margin-top: 3px; color: var(--muted); font-size: 9px; }
.event-type { display: inline-block; margin-right: 5px; color: var(--amber); font-family: var(--font-mono); font-size: 9px; font-weight: 700; }
.source-list { display: grid; margin: 15px 19px 0; border-top: 1px solid var(--line); }
.source-list a { display: grid; grid-template-columns: 24px 1fr 18px; align-items: center; gap: 8px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.source-list a:hover strong, .source-list a:hover .source-arrow { color: var(--cyan); }
.source-index { color: var(--muted); font-family: var(--font-mono); font-size: 9px; }
.source-list strong, .source-list small { display: block; }
.source-list strong { color: var(--muted-strong); font-size: 10px; }
.source-list small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.source-arrow { color: var(--muted); font-size: 14px; text-align: right; }
.source-disclaimer { margin: 13px 19px 18px; color: var(--muted); font-size: 9px; }

.footer { display: flex; justify-content: space-between; gap: 15px; width: min(1600px, calc(100% - 64px)); margin: 0 auto; padding: 16px 0 22px; border-top: 1px solid var(--line); color: var(--muted); font-family: var(--font-mono); font-size: 9px; }

@media (max-width: 1120px) {
  .content-grid { grid-template-columns: minmax(0, 1fr); }
  .side-column { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .signal-panel { grid-column: span 2; }
  .source-panel { grid-column: span 2; }
}

@media (max-width: 820px) {
  .topbar { padding: 0 18px; }
  .workspace, .footer { width: min(100% - 36px, 1600px); }
  .hero-strip { display: grid; gap: 20px; }
  .hero-callout { align-self: auto; width: 100%; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .backtest-grid { grid-template-columns: 1fr; }
  .side-column { grid-template-columns: 1fr; }
  .signal-panel, .source-panel { grid-column: auto; }
}

@media (max-width: 560px) {
  .topbar { min-height: 60px; }
  .brand-copy .eyebrow { display: none; }
  .topbar-status { font-size: 10px; }
  .workspace { padding-top: 18px; }
  .hero-strip { padding-top: 10px; }
  .hero-strip h1 { font-size: 28px; }
  .metrics-grid { gap: 8px; margin: 14px 0; }
  .metric-card { min-height: 100px; padding: 12px; }
  .metric-value { font-size: 20px; }
  .panel-heading { display: grid; gap: 13px; padding: 15px 14px 0; }
  .control-stack { justify-items: start; }
  .legend-row { margin: 13px 14px 0; gap: 7px 10px; }
  .legend-muted { width: 100%; margin-left: 0; }
  .chart-wrap { height: 300px; margin: 8px 5px 0; }
  .chart-footnote { display: grid; margin: 0 14px; gap: 7px; }
  .backtest-toolbar { margin: 14px 14px 0; }
  .toolbar-note { width: 100%; margin-left: 0; }
  .backtest-grid { padding: 13px 14px 0; }
  .form-grid { gap: 9px; }
  .trade-log { margin-left: 14px; margin-right: 14px; }
  .result-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .signal-main, .signal-grid, .signal-note, .basis-meter, .basis-copy, .risk-list, .event-list, .source-list, .source-disclaimer { margin-left: 14px; margin-right: 14px; }
  .footer { display: grid; gap: 4px; }
}
