:root {
  color-scheme: dark;
  --bg: #0f1417;
  --band: #151b1f;
  --panel: #1b2328;
  --panel-soft: #202a30;
  --ink: #e8eef1;
  --muted: #94a2aa;
  --faint: #63727b;
  --line: #2d3941;
  --line-strong: #3d4c55;
  --accent: #11a79a;
  --accent-strong: #17c3b5;
  --amber: #e1a83c;
  --blue: #5d7ed9;
  --green: #34c28d;
  --red: #ee6262;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: wait;
  opacity: 0.68;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 70px;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(15, 20, 23, 0.94);
  backdrop-filter: blur(16px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid #314048;
  border-radius: 8px;
  background: #141c20;
  color: var(--amber);
  font-weight: 900;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 19px;
  line-height: 1.15;
}

.brand p {
  overflow: hidden;
  max-width: 760px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-actions {
  display: grid;
  grid-template-columns: repeat(4, auto);
  align-items: center;
  gap: 6px;
}

#csvInput,
#strategyInput,
#moduleInput,
#decisionPacketInput,
#accountStateInput {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.icon-button,
.run-button,
.mini-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel-soft);
  color: var(--ink);
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
  transition:
    border-color 120ms ease,
    background 120ms ease,
    color 120ms ease;
}

.icon-button {
  min-width: 86px;
  min-height: 36px;
  padding: 0 12px;
  font-size: 13px;
}

.mini-button {
  min-height: 32px;
  padding: 0 11px;
  font-size: 12px;
}

.mini-button.primary-lite {
  border-color: rgba(17, 167, 154, 0.68);
  background: rgba(17, 167, 154, 0.16);
  color: var(--accent-strong);
}

.account-state-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 9px;
  padding-top: 9px;
  border-top: 1px solid rgba(68, 88, 98, 0.62);
}

.account-state-tools output {
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.3;
}

.account-state-tools output.is-loaded {
  color: var(--accent-strong);
}

.icon-button:hover,
.mini-button:hover,
.run-button.secondary:hover {
  border-color: #50636e;
  background: #253139;
}

.icon-button.primary,
.run-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #071311;
}

.icon-button.primary:hover,
.run-button:hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
}

.run-button.secondary {
  border-color: var(--line-strong);
  background: var(--panel-soft);
  color: var(--ink);
}

.market-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: end;
  padding: 12px 18px;
  border-bottom: 1px solid var(--line);
  background: #12191d;
}

.market-field {
  flex: 1 1 260px;
  min-width: 0;
}

.source-field {
  flex: 0.9 1 240px;
}

.dataset-field {
  flex: 1.2 1 300px;
}

.source-policy-field {
  flex: 0.85 1 190px;
}

.symbol-select-field,
.symbol-input-field {
  flex: 1 1 300px;
}

.market-bar .field span {
  color: #8da6b1;
  font-size: 11px;
}

.market-bar .field input,
.market-bar .field select {
  min-height: 36px;
  border-radius: 6px;
  background: #0d1519;
}

.market-actions {
  display: grid;
  flex: 0 0 260px;
  grid-template-columns: 126px 126px;
  gap: 8px;
  align-items: end;
  margin-left: auto;
}

.market-actions .run-button {
  width: 100%;
  min-height: 36px;
  border-radius: 6px;
}

.symbol-input-field {
  transition: opacity 120ms ease;
}

.quick-ranges {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: max-content;
  min-height: 36px;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #10181c;
  padding: 3px;
}

.quick-ranges button {
  min-width: 40px;
  min-height: 28px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.quick-ranges button:hover {
  color: var(--ink);
  border-color: #536672;
}

.live-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #11191d;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.live-toggle input {
  accent-color: var(--accent);
}

.live-toggle:has(input:checked) {
  border-color: var(--accent);
  background: rgba(17, 167, 154, 0.15);
  color: var(--accent-strong);
}

.refresh-field {
  min-width: 94px;
}

.workspace {
  display: grid;
  grid-template-columns: 292px minmax(0, 1fr);
  gap: 14px;
  padding: 14px;
}

.control-panel {
  position: sticky;
  /* The market bar scrolls away; keep the sidebar directly below the
     sticky topbar instead of reserving the removed second header row. */
  top: 84px;
  align-self: start;
  display: grid;
  gap: 12px;
}

.control-section,
.metric,
.chart-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.control-section {
  display: grid;
  gap: 12px;
  padding: 13px;
}

.data-card {
  background: #172026;
}

.strategy-card {
  align-content: start;
  gap: 13px;
  background: #172026;
}

.strategy-details {
  display: grid;
  gap: 8px;
}

.strategy-library {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid #2b3941;
  border-radius: 7px;
  background: #11191d;
}

.strategy-library-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.strategy-library-head > span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 900;
}

.strategy-library-head small {
  color: var(--muted);
  font-size: 10px;
  text-align: right;
}

.strategy-library .field {
  gap: 4px;
}

.strategy-library-actions {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 7px;
}

/* Keep strategy selection and the local library in one compact control. */
.strategy-card {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.strategy-card > .section-title,
.strategy-card > .strategy-details,
.strategy-card > .strategy-detail-button,
.strategy-card > .account-state-tools,
.strategy-card .strategy-library-actions {
  grid-column: 1 / -1;
}

.strategy-card .strategy-library > .field {
  order: 1;
}

.strategy-card > .field {
  order: 2;
}

.strategy-card .strategy-library-actions {
  order: 3;
}

.strategy-card > .strategy-details {
  order: 4;
}

.strategy-card > .strategy-detail-button {
  order: 5;
}

.strategy-card > .account-state-tools {
  order: 6;
}

/* The library is the only visible strategy selector. The legacy engine
   select stays in the DOM as an internal compatibility control. */
.strategy-card {
  grid-template-columns: 1fr;
}

.strategy-card > .field:has(#strategy) {
  display: none;
}

.strategy-card .strategy-library > .field {
  grid-column: 1 / -1;
}

.strategy-card > .strategy-library {
  display: contents;
}

.strategy-card .strategy-library-head {
  display: none;
}

.strategy-card > .field,
.strategy-card .strategy-library > .field {
  min-width: 0;
}

/* Keep the strategy list and its save/delete actions in one library row. */
.strategy-card > .strategy-library {
  display: grid;
  grid-column: 1 / -1;
  grid-template-columns: minmax(0, 1fr);
  align-items: stretch;
  order: 1;
  min-width: 0;
}

.strategy-card .strategy-library > .field {
  grid-column: 1;
  order: 0;
  min-width: 0;
}

.strategy-card .strategy-library-actions {
  grid-column: 1;
  grid-template-columns: repeat(2, max-content);
  justify-content: end;
  align-self: stretch;
  order: 0;
  margin: 0;
}

.factor-library-section {
  gap: 9px;
}

.factor-library-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.factor-library-list {
  display: grid;
  gap: 6px;
  max-height: 260px;
  overflow: auto;
}

.factor-library-item {
  display: grid;
  gap: 3px;
  padding: 8px 9px;
  border: 1px solid #2b3941;
  border-radius: 7px;
  background: #11191d;
}

.factor-library-item header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.factor-library-item-tools {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.factor-save-button {
  min-height: 22px;
  padding: 2px 7px;
  font-size: 10px;
}

.factor-library-item strong {
  color: var(--ink);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.factor-library-item small,
.factor-library-item p {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
  margin: 0;
}

.factor-library-item p b {
  color: var(--ink);
  font-weight: 600;
}

.factor-library-item .factor-library-formula {
  color: #a9d9d4;
  overflow-wrap: anywhere;
}

.factor-library-item header small {
  color: var(--accent-strong);
  white-space: nowrap;
}

.factor-library-item[data-factor-chart-index] {
  cursor: pointer;
}

.factor-library-item[data-factor-chart-index]:hover {
  border-color: #3a7772;
  background: #132124;
}

.factor-library-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1080px, 100%);
  max-height: min(860px, calc(100vh - 36px));
  border: 1px solid #314149;
  border-radius: 8px;
  background: #10181c;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.46);
  overflow: hidden;
}

.factor-library-modal-body {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding: 14px;
}

.factor-library-modal-body .factor-library-item {
  min-width: 0;
}

.factor-chart-button {
  border-color: rgba(52, 194, 141, 0.55);
  background: rgba(52, 194, 141, 0.08);
  color: #a9e6d4;
}

.chart-analysis-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  min-height: 34px;
  margin-bottom: 8px;
  border: 1px solid #26343b;
  border-radius: 7px;
  background: #11191d;
  padding: 6px 9px;
}

.chart-analysis-bar label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.chart-analysis-bar label input {
  accent-color: var(--accent);
}

.chart-analysis-bar output {
  min-width: 0;
  color: var(--accent-strong);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.mini-button.danger-lite {
  border-color: rgba(238, 98, 98, 0.5);
  background: rgba(238, 98, 98, 0.08);
  color: #ff9b9b;
}

.mini-button.danger-lite:hover {
  border-color: #ee6262;
  background: rgba(238, 98, 98, 0.16);
}

.strategy-details > div {
  display: grid;
  gap: 4px;
  border: 1px solid #2b3941;
  border-radius: 7px;
  background: #11191d;
  padding: 9px 10px;
}

.strategy-details > div > span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.strategy-details > div > strong {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.strategy-module-bind {
  display: grid;
  gap: 8px;
}

.strategy-detail-button {
  width: 100%;
}

.modal-open {
  overflow: hidden;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(4, 8, 10, 0.72);
  padding: 18px;
}

.strategy-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1040px, 100%);
  max-height: min(860px, calc(100vh - 36px));
  border: 1px solid #314149;
  border-radius: 8px;
  background: #10181c;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.46);
  overflow: hidden;
}

.backtest-progress-backdrop {
  z-index: 90;
}

.backtest-progress-modal {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 16px;
  width: min(430px, calc(100vw - 36px));
  border: 1px solid #314149;
  border-radius: 8px;
  background: #10181c;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.46);
  padding: 20px;
}

.pool-coverage-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(580px, calc(100vw - 36px));
  max-height: min(620px, calc(100vh - 36px));
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.pool-coverage-body {
  display: grid;
  gap: 8px;
  overflow: auto;
  padding: 14px 16px;
}

.pool-coverage-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-soft);
}

.pool-coverage-symbol {
  color: var(--red);
  font-weight: 900;
}

.pool-coverage-reason {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.pool-coverage-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
}

.mini-button.danger {
  border-color: color-mix(in srgb, var(--red) 60%, var(--line));
  color: var(--red);
}

.mini-button.danger:hover {
  background: color-mix(in srgb, var(--red) 12%, var(--panel-soft));
}

.backtest-progress-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 1px solid #168f8a;
  border-radius: 50%;
  background: #0c2224;
}

.backtest-progress-icon span {
  width: 18px;
  height: 18px;
  border: 2px solid #3ac7bf;
  border-right-color: transparent;
  border-radius: 50%;
  animation: aix-progress-spin 0.8s linear infinite;
}

.backtest-progress-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.backtest-progress-head h2 {
  margin: 0;
  font-size: 16px;
}

.backtest-progress-head span {
  color: var(--accent);
  font-size: 12px;
  white-space: nowrap;
}

.backtest-progress-content p {
  margin: 6px 0 12px;
  color: var(--muted);
  font-size: 12px;
}

.backtest-progress-track {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #1f2c32;
}

.backtest-progress-track span {
  display: block;
  width: 36%;
  height: 100%;
  border-radius: inherit;
  background: #22b7ae;
  animation: aix-progress-sweep 1.4s ease-in-out infinite;
}

.backtest-progress-track span.determinate {
  animation: none;
  transition: width 180ms ease;
}

.backtest-progress-cancel {
  justify-self: end;
  margin-top: 12px;
}

@keyframes aix-progress-spin {
  to { transform: rotate(360deg); }
}

@keyframes aix-progress-sweep {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

@media (prefers-reduced-motion: reduce) {
  .backtest-progress-icon span,
  .backtest-progress-track span {
    animation: none;
  }
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid #26343b;
  background: #121b20;
  padding: 14px 16px;
}

.modal-head h2 {
  margin: 0;
  font-size: 16px;
}

.modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.strategy-modal-body {
  display: grid;
  gap: 12px;
  overflow: auto;
  padding: 14px;
}

.account-button {
  min-width: 118px;
}

.account-modal {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(560px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  border: 1px solid #314149;
  border-radius: 8px;
  background: #10181c;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.46);
  overflow: hidden;
}

.account-modal-body {
  display: grid;
  align-content: start;
  gap: 14px;
  overflow: auto;
  padding: 16px;
}

.account-status,
.account-note {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.account-status {
  border: 1px solid rgba(52, 194, 141, 0.32);
  border-radius: 6px;
  background: rgba(52, 194, 141, 0.08);
  color: #b9eadb;
  padding: 9px 10px;
}

.account-auth-form,
.account-profile {
  display: grid;
  gap: 12px;
}

.account-auth-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.account-profile-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.account-profile-stats > div {
  display: grid;
  gap: 3px;
  border: 1px solid #26343b;
  border-radius: 6px;
  background: #0d1418;
  padding: 10px;
}

.account-profile-stats strong {
  color: var(--accent-strong);
  font-size: 20px;
}

.account-profile-stats span {
  color: var(--muted);
  font-size: 11px;
}

.account-history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.account-history-head h3 {
  margin: 0;
  font-size: 14px;
}

.account-history {
  display: grid;
  gap: 7px;
  max-height: 360px;
  overflow: auto;
}

.account-history-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 3px 10px;
  border: 1px solid #26343b;
  border-radius: 6px;
  background: #0d1418;
  padding: 9px 10px;
}

.account-history-row strong,
.account-history-row span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
}

.account-history-row span {
  color: var(--accent-strong);
}

.account-history-row small {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 11px;
}

.modal-section {
  display: grid;
  gap: 10px;
  border: 1px solid #26343b;
  border-radius: 8px;
  background: #0d1418;
  padding: 12px;
}

.modal-section h3 {
  margin: 0;
  color: var(--ink);
  font-size: 13px;
}

.contract-section {
  border-color: #315d5b;
  background: #0d1819;
}

.contract-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.contract-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.contract-status {
  flex: 0 0 auto;
  border: 1px solid #2d8f82;
  border-radius: 999px;
  padding: 4px 8px;
  color: #071311;
  background: #35c5b0;
  font-size: 11px;
  white-space: nowrap;
}

.contract-status.partial {
  border-color: #bd8e2c;
  background: #e1a83c;
}

.contract-status.blocked {
  border-color: #b44747;
  color: #210909;
  background: #ee6262;
}

.contract-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.contract-columns > div {
  min-width: 0;
  border: 1px solid #263f42;
  border-radius: 7px;
  background: #101d1e;
  padding: 9px;
}

.contract-columns h4 {
  margin: 0 0 7px;
  color: var(--ink);
  font-size: 12px;
}

.contract-rule-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.contract-rule-list li {
  display: grid;
  gap: 2px;
  border-left: 2px solid #2b6d68;
  padding-left: 7px;
}

.contract-rule-list strong {
  color: #cfe1e3;
  font-size: 11px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.contract-rule-list em {
  color: #7d969d;
  font-size: 10px;
  font-style: normal;
}

.contract-alert {
  display: grid;
  gap: 7px;
  border: 1px solid #735d29;
  border-radius: 7px;
  background: #171613;
  padding: 9px;
}

.contract-alert.blocked {
  border-color: #713c3c;
  background: #1b1415;
}

.contract-alert > strong {
  color: #e1a83c;
  font-size: 12px;
}

.contract-alert.blocked > strong {
  color: #ee8585;
}

.modal-section.two-col {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.binding-flow {
  display: grid;
  grid-template-columns: 92px minmax(0, 1fr);
  gap: 8px 12px;
  border: 1px solid #2b3941;
  border-radius: 7px;
  background: #111a1f;
  padding: 10px;
}

.binding-flow span,
.kv-item span,
.prompt-block span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.binding-flow strong,
.kv-item strong {
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.kv-item {
  display: grid;
  gap: 5px;
  border: 1px solid #28363d;
  border-radius: 7px;
  background: #11191d;
  padding: 9px 10px;
}

.prompt-list {
  display: grid;
  gap: 8px;
}

.prompt-block {
  display: grid;
  gap: 6px;
  border: 1px solid #28363d;
  border-radius: 7px;
  background: #11191d;
  padding: 10px;
}

.prompt-block p {
  margin: 0;
  color: var(--ink);
  font-size: 12px;
  font-weight: 750;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip-list span,
.empty-box {
  border: 1px solid #2b3941;
  border-radius: 6px;
  background: #11191d;
  color: #c8d5da;
  padding: 7px 9px;
  font-size: 12px;
  font-weight: 850;
}

.modal-table-wrap {
  overflow: auto;
  max-height: 220px;
}

.modal-table-wrap table {
  min-width: 680px;
}

.module-bind-editor {
  display: grid;
  gap: 10px;
}

.module-bind-editor.compact {
  gap: 8px;
}

.module-bind-list {
  display: grid;
  gap: 8px;
}

.module-bind-editor.compact .module-bind-list {
  max-height: 170px;
  overflow: auto;
  padding-right: 2px;
}

.module-bind-option {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  align-items: start;
  gap: 10px;
  border: 1px solid #28363d;
  border-radius: 7px;
  background: #11191d;
  padding: 10px;
}

.module-bind-editor.compact .module-bind-option {
  gap: 8px;
  padding: 8px;
}

.module-bind-option input {
  margin-top: 2px;
  accent-color: var(--accent);
}

.module-bind-option span {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.module-bind-option strong {
  color: var(--ink);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.module-bind-editor.compact .module-bind-option strong {
  font-size: 12px;
}

.module-bind-option em,
.module-bind-editor p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.35;
}

.module-bind-editor.compact .module-bind-option em {
  font-size: 11px;
}

.module-bind-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.module-bind-editor.compact .module-bind-actions .mini-button {
  flex: 1;
}

.compact-empty {
  padding: 9px 10px;
  font-size: 12px;
}

.module-insight-list {
  display: grid;
  gap: 10px;
}

.module-insight {
  display: grid;
  gap: 10px;
  border: 1px solid #2b3941;
  border-radius: 8px;
  background: #11191d;
  padding: 11px;
}

.module-insight.is-warning {
  border-color: #58443a;
  background: #171613;
}

.module-insight header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.module-insight header div,
.module-insight-grid div {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.module-insight strong {
  color: var(--ink);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.module-insight span,
.module-insight-grid span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.module-insight-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.module-insight-grid div {
  border: 1px solid #26343b;
  border-radius: 7px;
  background: #0e171b;
  padding: 8px 9px;
}

.module-insight-grid strong {
  font-size: 12px;
  line-height: 1.45;
}

.module-conclusions {
  display: grid;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.module-conclusions li,
.module-error {
  margin: 0;
  border: 1px solid #26343b;
  border-radius: 7px;
  background: #0e171b;
  color: #c8d5da;
  padding: 8px 9px;
  font-size: 12px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.primary-action {
  border-color: rgba(23, 198, 183, 0.55);
  background: rgba(17, 167, 154, 0.2);
  color: var(--accent-strong);
}

.section-title,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-title span,
.panel-head h2 {
  font-size: 14px;
  font-weight: 900;
}

.section-title output,
.panel-head > span {
  color: var(--muted);
  font-size: 12px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field.compact {
  gap: 5px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #11191d;
  color: var(--ink);
  padding: 0 10px;
  outline: none;
}

.field textarea {
  resize: vertical;
  min-height: 76px;
  line-height: 1.45;
}

.field input::placeholder,
.field textarea::placeholder {
  color: #6f7e87;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(17, 167, 154, 0.14);
}

.symbol-manual {
  margin-top: 6px;
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #11191d;
  color: var(--ink);
  padding: 0 10px;
  font-size: 13px;
  font-weight: 900;
}

.switch-row input {
  accent-color: var(--accent);
}

.portfolio-select {
  width: 100%;
  min-height: 176px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #11191d;
  color: var(--ink);
  padding: 6px;
  outline: none;
}

.portfolio-select option {
  padding: 7px 8px;
  border-radius: 6px;
}

.strategy-lock-note {
  display: none;
  border: 1px solid rgba(17, 167, 154, 0.28);
  border-radius: 7px;
  background: rgba(17, 167, 154, 0.09);
  color: var(--accent-strong);
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 900;
  line-height: 1.35;
}

#portfolioSection.strategy-locked .strategy-lock-note {
  display: block;
}

#portfolioSection.strategy-locked .switch-row {
  display: none;
}

.portfolio-select.strategy-locked {
  border-color: rgba(17, 167, 154, 0.4);
  background: #101b1e;
}

.portfolio-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pool-editor-field textarea {
  font-size: 12px;
  font-weight: 800;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #121a1e;
}

.segmented button {
  min-height: 36px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 900;
}

.segmented button.active {
  background: rgba(17, 167, 154, 0.18);
  color: var(--accent-strong);
}

.run-button {
  min-height: 36px;
  padding: 0 14px;
}

.hidden {
  display: none !important;
}

.status-list {
  display: grid;
  gap: 12px;
  margin: 0;
}

.status-list div {
  display: grid;
  gap: 4px;
}

.status-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.status-list dd {
  overflow-wrap: anywhere;
  margin: 0;
  color: var(--ink);
  font-size: 14px;
  font-weight: 900;
}

.dashboard {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(132px, 1fr));
  gap: 10px;
}

.metric {
  display: grid;
  min-height: 98px;
  gap: 8px;
  padding: 13px;
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.metric strong {
  font-size: 25px;
  line-height: 1;
}

.metric small {
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: normal;
}

.metric.positive strong {
  color: var(--green);
}

.metric.negative strong {
  color: var(--red);
}

.chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.chart-panel,
.table-panel {
  min-width: 0;
  padding: 13px;
}

.chart-panel.main-chart {
  grid-row: span 1;
}

.chart-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 12px;
}

/* Keep chart controls available while the chart is being inspected. */
.main-chart .chart-toolbar {
  position: sticky;
  top: 84px;
  z-index: 10;
  background: var(--panel);
  box-shadow: 0 6px 14px rgba(25, 43, 61, 0.08);
  padding: 8px 0;
}

.toolbar-group {
  display: inline-flex;
  align-items: end;
  gap: 8px;
  min-height: 58px;
  min-width: 0;
  border: 1px solid #26333a;
  border-radius: 8px;
  background: #11191d;
  padding: 8px;
}

.toolbar-label {
  align-self: center;
  flex: 0 0 auto;
  min-width: 58px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.period-group {
  flex: 1 1 520px;
}

.range-group {
  flex: 2 1 640px;
}

.live-group {
  flex: 0 1 248px;
}

.toolbar-group .field {
  min-width: 104px;
}

.toolbar-group .field input,
.toolbar-group .field select {
  min-height: 34px;
  border-radius: 6px;
}

.range-group .field {
  min-width: 178px;
}

.chart-symbol-field {
  min-width: 138px;
}

.chart-display-field {
  min-width: 112px;
}

.aux-periods {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  flex: 0 1 470px;
  min-height: 58px;
}

.aux-periods label {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 46px;
  min-height: 32px;
  border: 1px solid #2b3a42;
  border-radius: 5px;
  background: #151f24;
  color: var(--ink);
  padding: 0 9px;
  font-size: 12px;
  font-weight: 900;
}

.aux-periods input {
  position: absolute;
  opacity: 0;
}

.aux-periods label:has(input:checked) {
  border-color: rgba(17, 167, 154, 0.72);
  background: rgba(17, 167, 154, 0.18);
  color: var(--accent-strong);
}

.mini-button.ghost {
  min-height: 36px;
  border-color: #33414a;
  background: #151f24;
  color: var(--muted);
}

.exchange-chart {
  height: 650px;
  overflow: hidden;
  border: 1px solid #28343b;
  border-radius: 8px;
  background: #0f171b;
}

#priceChart {
  height: 650px;
}

.result-panel {
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(320px, 0.6fr);
  column-gap: 16px;
  row-gap: 10px;
  align-content: start;
}

.result-panel > .panel-head:first-child {
  grid-column: 1;
  grid-row: 1;
}

.result-panel .result-table {
  grid-column: 1;
  grid-row: 2;
}

.panel-head.subhead {
  grid-column: 2;
  grid-row: 1;
  margin-top: 0;
}

.result-panel .compact-table {
  grid-column: 2;
  grid-row: 2;
}

.backtest-diagnostics {
  grid-column: 1 / -1;
  display: grid;
  gap: 8px;
  border: 1px solid #26343b;
  border-radius: 8px;
  background: #0d1418;
  padding: 10px;
}

.effectiveness-panel {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  border: 1px solid #26343b;
  border-radius: 8px;
  background: #0d1418;
  padding: 12px;
}

.effectiveness-panel .panel-head {
  margin: 0;
}

.strategy-composite-score {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(0, 2fr);
  gap: 14px;
  align-items: stretch;
  border: 1px solid #2b3941;
  border-radius: 7px;
  background: #11191d;
  padding: 13px;
}

.strategy-composite-main {
  display: grid;
  align-content: center;
  gap: 5px;
  min-height: 118px;
  border-right: 1px solid #26343b;
  padding-right: 14px;
}

.strategy-composite-main header,
.strategy-composite-summary header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.strategy-composite-main header strong,
.strategy-composite-summary header strong {
  color: var(--ink);
  font-size: 14px;
}

.strategy-composite-main header span,
.strategy-composite-summary header span {
  color: var(--muted);
  font-size: 11px;
}

.strategy-composite-value {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.strategy-composite-value strong {
  color: var(--accent);
  font-size: 42px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.strategy-composite-value strong.warn {
  color: #e1a83c;
}

.strategy-composite-value strong.risk {
  color: #ee6262;
}

.strategy-composite-value small {
  color: var(--muted);
  font-size: 12px;
}

.strategy-composite-main p,
.strategy-composite-summary p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.strategy-composite-summary {
  display: grid;
  align-content: center;
  gap: 8px;
}

.strategy-dimension-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.strategy-dimension-card {
  display: grid;
  gap: 6px;
  min-width: 0;
  border: 1px solid #2b3941;
  border-radius: 6px;
  background: #10181c;
  padding: 9px;
}

.strategy-dimension-card.good {
  border-color: rgba(52, 194, 141, 0.54);
}

.strategy-dimension-card.warn {
  border-color: rgba(225, 168, 60, 0.54);
}

.strategy-dimension-card.risk {
  border-color: rgba(238, 98, 98, 0.54);
}

.strategy-dimension-card header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.strategy-dimension-card header strong {
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strategy-dimension-card header span {
  color: var(--muted);
  font-size: 10px;
  white-space: nowrap;
}

.strategy-dimension-value {
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.strategy-dimension-value strong {
  color: var(--accent);
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.strategy-dimension-card.warn .strategy-dimension-value strong {
  color: #e1a83c;
}

.strategy-dimension-card.risk .strategy-dimension-value strong {
  color: #ee6262;
}

.strategy-dimension-value small {
  color: var(--muted);
  font-size: 10px;
}

.strategy-dimension-meter {
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: #26343b;
}

.strategy-dimension-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.strategy-dimension-card.warn .strategy-dimension-meter span {
  background: #e1a83c;
}

.strategy-dimension-card.risk .strategy-dimension-meter span {
  background: #ee6262;
}

.strategy-dimension-card p {
  min-height: 30px;
  margin: 0;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.4;
}

.effectiveness-score-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.effectiveness-score-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  border: 1px solid #2b3941;
  border-radius: 7px;
  background: #11191d;
  padding: 11px;
}

.effectiveness-score-card.good {
  border-color: rgba(52, 194, 141, 0.62);
}

.effectiveness-score-card.warn {
  border-color: rgba(225, 168, 60, 0.62);
}

.effectiveness-score-card.risk {
  border-color: rgba(238, 98, 98, 0.62);
}

.effectiveness-score-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.effectiveness-score-head strong {
  color: var(--ink);
  font-size: 14px;
}

.effectiveness-score-head span {
  color: var(--muted);
  font-size: 11px;
  text-align: right;
  white-space: nowrap;
}

.effectiveness-score-value {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.effectiveness-score-value strong {
  color: var(--accent);
  font-size: 34px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.effectiveness-score-card.warn .effectiveness-score-value strong {
  color: #e1a83c;
}

.effectiveness-score-card.risk .effectiveness-score-value strong {
  color: #ee6262;
}

.effectiveness-score-value span {
  color: var(--muted);
  font-size: 12px;
}

.effectiveness-meter {
  height: 6px;
  overflow: hidden;
  border-radius: 999px;
  background: #26343b;
}

.effectiveness-meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.effectiveness-score-card.warn .effectiveness-meter span {
  background: #e1a83c;
}

.effectiveness-score-card.risk .effectiveness-meter span {
  background: #ee6262;
}

.effectiveness-score-evidence,
.effectiveness-score-note {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.effectiveness-score-evidence b {
  color: var(--ink);
  font-weight: 750;
}

.effectiveness-empty {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  padding: 6px 2px;
}

.diagnostic-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.diagnostic-head strong {
  color: var(--ink);
  font-size: 13px;
}

.diagnostic-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.diagnostic-list {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.diagnostic-item {
  display: grid;
  gap: 5px;
  min-height: 72px;
  border: 1px solid #2b3941;
  border-radius: 7px;
  background: #11191d;
  padding: 8px 9px;
}

.diagnostic-item em {
  width: fit-content;
  border-radius: 999px;
  padding: 2px 7px;
  color: #071311;
  background: var(--accent);
  font-style: normal;
  font-size: 11px;
  font-weight: 950;
}

.diagnostic-item.warn em {
  background: #e1a83c;
}

.diagnostic-item.risk em {
  background: #ee6262;
  color: #170909;
}

.diagnostic-item strong {
  color: var(--ink);
  font-size: 12px;
}

.diagnostic-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.result-table {
  max-height: none;
}

.result-table table {
  min-width: 0;
}

.result-table td {
  padding: 9px 8px;
}

.result-table td:first-child {
  color: var(--muted);
  font-weight: 900;
}

.result-table td:last-child {
  color: var(--ink);
  font-weight: 900;
}

.panel-head {
  margin-bottom: 10px;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 3px;
}

.swatch.equity {
  background: var(--accent);
}

.swatch.hold {
  background: var(--blue);
}

.swatch.entry {
  background: var(--green);
}

.swatch.candle-up {
  background: #33bd8c;
}

.swatch.candle-down {
  background: #e05d5d;
}

.swatch.exit {
  background: var(--amber);
}

.swatch.drawdown {
  background: var(--red);
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
}

.table-wrap {
    overflow: auto;
    max-height: 420px;
  }

  .table-pagination {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 34px;
    padding-top: 10px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

  .table-page-button {
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #182329;
    color: var(--text);
    cursor: pointer;
    font: inherit;
  }

  .table-page-button:hover:not(:disabled) {
    border-color: var(--accent);
    color: var(--accent);
  }

  .table-page-button:disabled {
    cursor: not-allowed;
    opacity: .45;
  }

  .table-pagination-current {
    color: var(--text);
  }

.compact-table {
  max-height: 360px;
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
}

.trade-table {
  min-width: 1420px;
}

.compact-table table {
  min-width: 360px;
}

th,
td {
  border-bottom: 1px solid #27343b;
  padding: 10px 8px;
  text-align: right;
  font-size: 13px;
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

td.long,
td.profit {
  color: var(--green);
  font-weight: 800;
}

td.short,
td.loss {
  color: var(--red);
  font-weight: 800;
}

.decision-cell {
  width: 96px;
  min-width: 96px;
  text-align: center;
  white-space: nowrap;
}

.trade-time {
  white-space: nowrap;
  color: #c3d0d5;
  font-variant-numeric: tabular-nums;
}

.decision-popover {
  min-width: 70px;
  min-height: 26px;
  border: 1px solid #32434b;
  border-radius: 5px;
  background: #111a1e;
  color: #b9cbd1;
  font-size: 12px;
  font-weight: 900;
  cursor: help;
}

.decision-popover:hover,
.decision-popover:focus-visible {
  border-color: var(--accent);
  color: var(--accent-strong);
  outline: none;
}

.decision-floating-tip {
  position: fixed;
  z-index: 80;
  display: none;
  max-width: min(380px, calc(100vw - 24px));
  border: 1px solid #3a4d55;
  border-radius: 7px;
  background: #0b1114;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.38);
  color: var(--ink);
  padding: 10px 12px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.55;
  pointer-events: none;
  white-space: normal;
}

.decision-floating-tip.visible {
  display: block;
}

.empty-cell {
  color: var(--muted);
  padding: 24px;
  text-align: center !important;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 40;
  max-width: min(430px, calc(100vw - 36px));
  transform: translateY(18px);
  border: 1px solid #33424a;
  border-radius: 8px;
  background: #e8eef1;
  color: #10171b;
  box-shadow: var(--shadow);
  opacity: 0;
  padding: 12px 14px;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 1320px) {
  .market-bar {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
  }

  .market-actions {
    grid-column: span 2;
    grid-template-columns: 1fr 1fr;
  }

  .metric-grid {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
  }

  .diagnostic-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .effectiveness-score-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .strategy-dimension-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .chart-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .chart-toolbar {
    gap: 8px;
  }

  .period-group,
  .range-group {
    flex-basis: 100%;
  }

  .aux-periods {
    flex: 1 1 360px;
  }

  .live-group {
    flex: 1 1 240px;
  }

  .chart-panel.main-chart {
    grid-row: auto;
  }

  #priceChart {
    height: 520px;
  }
}

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

  .contract-head {
    flex-direction: column;
  }

  .topbar {
    position: static;
    flex-direction: column;
    align-items: stretch;
  }

  .brand p {
    max-width: 100%;
  }

  .top-actions {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
  }

  .market-bar {
    display: grid;
    grid-template-columns: 1fr 1fr;
    padding: 12px;
  }

  .market-actions {
    grid-column: 1 / -1;
    margin-left: 0;
  }

  .quick-ranges {
    width: 100%;
  }

  .quick-ranges button {
    flex: 1 1 0;
  }

  .chart-toolbar {
    gap: 8px;
    min-width: 0;
    width: 100%;
  }

  .main-chart .chart-toolbar {
    top: 12px;
  }

  .toolbar-group {
    flex: 1 1 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  .period-group,
  .range-group,
  .live-group,
  .aux-periods {
    flex-basis: 100%;
  }

  .period-group {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
    overflow: hidden;
  }

  .period-group > .toolbar-label {
    grid-column: 1 / -1;
  }

  .period-group .field,
  .period-group .chart-symbol-field,
  .period-group > .mini-button {
    width: 100%;
    min-width: 0;
  }

  .range-group {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    align-items: end;
    overflow: hidden;
  }

  .range-group > .toolbar-label {
    grid-column: 1 / -1;
  }

  .range-group .field {
    width: 100%;
    min-width: 0;
  }

  .range-group .quick-ranges {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
  }

  .live-group {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
    align-items: end;
  }

  .live-group .refresh-field {
    min-width: 0;
    width: 100%;
  }

  .result-panel {
    grid-template-columns: 1fr;
  }

  .diagnostic-list {
    grid-template-columns: 1fr;
  }

  .effectiveness-score-grid {
    grid-template-columns: 1fr;
  }

  .strategy-composite-score {
    grid-template-columns: 1fr;
  }

  .strategy-composite-main {
    min-height: 0;
    border-right: 0;
    border-bottom: 1px solid #26343b;
    padding: 0 0 12px;
  }

  .strategy-dimension-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .factor-library-modal-body {
    grid-template-columns: 1fr;
  }

  .result-panel > .panel-head:first-child,
  .result-panel .result-table,
  .panel-head.subhead,
  .result-panel .compact-table {
    grid-column: 1;
    grid-row: auto;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .control-panel {
    position: static;
  }

  .strategy-card {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 560px) {
  .brand {
    align-items: flex-start;
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    flex-basis: 38px;
  }

  h1 {
    font-size: 18px;
  }

  .top-actions,
  .market-bar,
  .metric-grid {
    grid-template-columns: 1fr;
  }

  .strategy-dimension-grid {
    grid-template-columns: 1fr;
  }

  .market-actions {
    grid-column: auto;
    grid-template-columns: 1fr;
  }

  .chart-toolbar {
    display: grid;
  }

  .toolbar-group {
    display: grid;
    grid-template-columns: 1fr;
    align-items: stretch;
  }

  .toolbar-label {
    min-width: 0;
  }

  .module-insight-grid {
    grid-template-columns: 1fr;
  }

  .toolbar-group .field,
  .range-group .field,
  .chart-symbol-field {
    min-width: 0;
  }

  .aux-periods {
    grid-template-columns: repeat(4, 1fr);
  }

  .aux-periods .toolbar-label {
    grid-column: 1 / -1;
  }

  .period-group {
    grid-template-columns: 1fr;
  }

  #priceChart {
    height: 440px;
  }

  .metric strong {
    font-size: 23px;
  }
}

/* Theme previews: the data and strategy state stay untouched. */
:root {
  --theme-topbar: rgba(15, 20, 23, 0.94);
  --theme-band: #12191d;
  --theme-card: #172026;
  --theme-soft: #11191d;
  --theme-input: #0d1519;
  --theme-hover: #253139;
  --theme-focus: rgba(17, 167, 154, 0.14);
  --chart-bg: #0f171b;
  --chart-grid: rgba(45, 57, 65, 0.62);
  --chart-text: #94a2aa;
  --chart-up: #34c28d;
  --chart-down: #ee6262;
  --chart-fast: #11a79a;
  --chart-slow: #e1a83c;
  --chart-band: #5d7ed9;
}

:root[data-theme="tech"] {
  --bg: #071015;
  --band: #0b171e;
  --panel: #0e1e26;
  --panel-soft: #132932;
  --ink: #e4fbff;
  --muted: #8aabb7;
  --faint: #557987;
  --line: #214451;
  --line-strong: #326675;
  --accent: #00cfc0;
  --accent-strong: #5cf5df;
  --amber: #f6c765;
  --blue: #73a9ff;
  --green: #2edaa0;
  --red: #ff6e82;
  --shadow: 0 18px 46px rgba(0, 10, 18, 0.42);
  --theme-topbar: rgba(7, 16, 21, 0.95);
  --theme-band: #0a171e;
  --theme-card: #0e1e26;
  --theme-soft: #10252f;
  --theme-input: #08161c;
  --theme-hover: #183744;
  --theme-focus: rgba(0, 207, 192, 0.2);
  --chart-bg: #08151b;
  --chart-grid: rgba(48, 101, 116, 0.5);
  --chart-text: #8aabb7;
  --chart-up: #2edaa0;
  --chart-down: #ff6e82;
  --chart-fast: #00cfc0;
  --chart-slow: #f6c765;
  --chart-band: #73a9ff;
}

:root[data-theme="premium"] {
  --bg: #0d0e10;
  --band: #151619;
  --panel: #1b1c1f;
  --panel-soft: #242528;
  --ink: #f3f0e9;
  --muted: #b4b1aa;
  --faint: #777873;
  --line: #37383b;
  --line-strong: #55565a;
  --accent: #d6a94c;
  --accent-strong: #f2ca72;
  --amber: #f2c36d;
  --blue: #9aaed8;
  --green: #62c99d;
  --red: #ed7772;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.48);
  --theme-topbar: rgba(13, 14, 16, 0.96);
  --theme-band: #151619;
  --theme-card: #1b1c1f;
  --theme-soft: #242528;
  --theme-input: #111214;
  --theme-hover: #343336;
  --theme-focus: rgba(214, 169, 76, 0.18);
  --chart-bg: #111214;
  --chart-grid: rgba(130, 126, 116, 0.3);
  --chart-text: #b4b1aa;
  --chart-up: #62c99d;
  --chart-down: #ed7772;
  --chart-fast: #d6a94c;
  --chart-slow: #f2ca72;
  --chart-band: #9aaed8;
}

:root[data-theme="terminal"] {
  --bg: #050807;
  --band: #090d0b;
  --panel: #0d1210;
  --panel-soft: #121a16;
  --ink: #e5ffed;
  --muted: #88a392;
  --faint: #557061;
  --line: #24372b;
  --line-strong: #365541;
  --accent: #59e29b;
  --accent-strong: #9bffc5;
  --amber: #f1d36d;
  --blue: #88b6ff;
  --green: #63eaaa;
  --red: #ff7186;
  --shadow: 0 18px 46px rgba(0, 0, 0, 0.5);
  --theme-topbar: rgba(5, 8, 7, 0.96);
  --theme-band: #090d0b;
  --theme-card: #0d1210;
  --theme-soft: #121a16;
  --theme-input: #080d0a;
  --theme-hover: #1b2a21;
  --theme-focus: rgba(89, 226, 155, 0.18);
  --chart-bg: #080d0a;
  --chart-grid: rgba(62, 99, 73, 0.44);
  --chart-text: #88a392;
  --chart-up: #63eaaa;
  --chart-down: #ff7186;
  --chart-fast: #59e29b;
  --chart-slow: #f1d36d;
  --chart-band: #88b6ff;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --band: #ffffff;
  --panel: #ffffff;
  --panel-soft: #f7f9fb;
  --ink: #17212b;
  --muted: #6c7884;
  --faint: #9aa5af;
  --line: #dce2e8;
  --line-strong: #c5ced7;
  --accent: #256ed1;
  --accent-strong: #1559b8;
  --amber: #b47b08;
  --blue: #5078bd;
  --green: #1a9b70;
  --red: #d94f58;
  --shadow: 0 10px 28px rgba(25, 43, 61, 0.08);
  --theme-topbar: rgba(255, 255, 255, 0.96);
  --theme-band: #f7f9fb;
  --theme-card: #ffffff;
  --theme-soft: #f7f9fb;
  --theme-input: #ffffff;
  --theme-hover: #eef3f7;
  --theme-focus: rgba(37, 110, 209, 0.14);
  --chart-bg: #ffffff;
  --chart-grid: rgba(170, 181, 192, 0.34);
  --chart-text: #6c7884;
  --chart-up: #1a9b70;
  --chart-down: #d94f58;
  --chart-fast: #256ed1;
  --chart-slow: #b47b08;
  --chart-band: #5078bd;
}

:root[data-theme="light"] .topbar {
  box-shadow: 0 1px 0 rgba(30, 45, 60, 0.05);
}

:root[data-theme="light"] .metric,
:root[data-theme="light"] .chart-panel,
:root[data-theme="light"] .table-panel,
:root[data-theme="light"] .control-section {
  box-shadow: 0 8px 22px rgba(25, 43, 61, 0.06);
}

:root[data-theme="light"] .section-title,
:root[data-theme="light"] .panel-head,
:root[data-theme="light"] .toolbar-group {
  border-color: var(--line);
}

:root[data-theme="light"] .brand-mark {
  background: #f2f5f8;
  border-color: var(--line-strong);
}

:root[data-theme="light"] .market-bar .field span {
  color: var(--muted);
}

:root[data-theme="light"] .icon-button.primary,
:root[data-theme="light"] .run-button {
  color: #ffffff;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
}

:root[data-theme] .topbar {
  background: var(--theme-topbar);
}

:root[data-theme] .market-bar,
:root[data-theme] .data-card,
:root[data-theme] .strategy-card {
  background: var(--theme-band);
}

:root[data-theme] .data-card,
:root[data-theme] .strategy-card {
  background: var(--theme-card);
}

:root[data-theme] .strategy-library,
:root[data-theme] .factor-library-item,
:root[data-theme] .module-insight,
:root[data-theme] .strategy-dimension-card,
:root[data-theme] .strategy-composite-summary {
  background: var(--theme-soft);
  border-color: var(--line);
}

:root[data-theme] .field input,
:root[data-theme] .field select,
:root[data-theme] .field textarea,
:root[data-theme] .switch-row,
:root[data-theme] .live-toggle,
:root[data-theme] .quick-ranges {
  background: var(--theme-input);
}

:root[data-theme] .icon-button,
:root[data-theme] .mini-button,
:root[data-theme] .run-button.secondary {
  background: var(--panel-soft);
}

:root[data-theme] .icon-button:hover,
:root[data-theme] .mini-button:hover,
:root[data-theme] .run-button.secondary:hover {
  border-color: var(--line-strong);
  background: var(--theme-hover);
}

:root[data-theme] .icon-button.primary,
:root[data-theme] .run-button {
  background: var(--accent);
  border-color: var(--accent);
}

:root[data-theme] .icon-button.primary:hover,
:root[data-theme] .run-button:hover {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
}

:root[data-theme] .mini-button.primary-lite,
:root[data-theme] .live-toggle:has(input:checked) {
  background: var(--theme-focus);
  border-color: var(--accent);
  color: var(--accent-strong);
}

:root[data-theme] .field input:focus,
:root[data-theme] .field select:focus,
:root[data-theme] .field textarea:focus {
  box-shadow: 0 0 0 3px var(--theme-focus);
}

/* Light workspace: keep the chart and its controls readable instead of
   leaving the old dark-surface defaults visible inside the white shell. */
:root[data-theme="light"] .strategy-details > div,
:root[data-theme="light"] .toolbar-group,
:root[data-theme="light"] .chart-analysis-bar,
:root[data-theme="light"] .backtest-diagnostics,
:root[data-theme="light"] .effectiveness-panel,
:root[data-theme="light"] .strategy-composite-score,
:root[data-theme="light"] .strategy-composite-main,
:root[data-theme="light"] .strategy-composite-summary,
:root[data-theme="light"] .strategy-dimension-card {
  background: var(--theme-soft) !important;
  border-color: var(--line) !important;
  color: var(--ink);
}

:root[data-theme="light"] .strategy-details > div > span,
:root[data-theme="light"] .chart-analysis-bar label,
:root[data-theme="light"] .toolbar-label,
:root[data-theme="light"] .strategy-composite-main p,
:root[data-theme="light"] .strategy-composite-summary p,
:root[data-theme="light"] .strategy-dimension-card p {
  color: var(--muted);
}

:root[data-theme="light"] .aux-periods label,
:root[data-theme="light"] .mini-button.ghost {
  background: var(--theme-input);
  border-color: var(--line-strong);
  color: var(--ink);
}

:root[data-theme="light"] .aux-periods label:has(input:checked) {
  background: var(--theme-focus);
  border-color: var(--accent);
  color: var(--accent-strong);
}

:root[data-theme="light"] .exchange-chart,
:root[data-theme="light"] #priceChart {
  background: var(--chart-bg) !important;
  border-color: var(--line) !important;
}

:root[data-theme="light"] .strategy-composite-main {
  border-right-color: var(--line) !important;
}

/* The audit panels contain nested cards whose legacy dark-surface defaults
   otherwise overpower the light workspace and make their text unreadable. */
:root[data-theme="light"] .backtest-diagnostics .diagnostic-item,
:root[data-theme="light"] .effectiveness-score-card {
  background: #f8fafc !important;
  border-color: var(--line) !important;
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(25, 43, 61, 0.04);
}

:root[data-theme="light"] .backtest-diagnostics .diagnostic-item strong,
:root[data-theme="light"] .effectiveness-score-card strong,
:root[data-theme="light"] .effectiveness-score-evidence b {
  color: #172b43 !important;
}

:root[data-theme="light"] .backtest-diagnostics .diagnostic-item span,
:root[data-theme="light"] .effectiveness-score-card .effectiveness-score-evidence,
:root[data-theme="light"] .effectiveness-score-card .effectiveness-score-note,
:root[data-theme="light"] .effectiveness-score-value span,
:root[data-theme="light"] .effectiveness-score-head span {
  color: #5d7084 !important;
}

:root[data-theme="light"] .effectiveness-meter,
:root[data-theme="light"] .strategy-dimension-meter {
  background: #dfe7ef;
}

:root[data-theme="light"] .backtest-diagnostics .diagnostic-item.ok,
:root[data-theme="light"] .backtest-diagnostics .diagnostic-item.good,
:root[data-theme="light"] .effectiveness-score-card.good {
  border-color: rgba(25, 145, 105, 0.55) !important;
}

:root[data-theme="light"] .backtest-diagnostics .diagnostic-item.warn,
:root[data-theme="light"] .effectiveness-score-card.warn {
  border-color: rgba(190, 133, 24, 0.62) !important;
}

:root[data-theme="light"] .backtest-diagnostics .diagnostic-item.risk,
:root[data-theme="light"] .effectiveness-score-card.risk {
  border-color: rgba(210, 69, 80, 0.62) !important;
}

:root[data-theme="light"] .chart-toolbar {
  gap: 10px;
  margin-bottom: 10px;
}

:root[data-theme="light"] .toolbar-group {
  box-shadow: 0 2px 8px rgba(25, 43, 61, 0.04);
}

:root[data-theme="light"] .chart-analysis-bar {
  box-shadow: 0 2px 8px rgba(25, 43, 61, 0.04);
}

:root[data-theme="light"] .brand-mark {
  position: relative;
  overflow: hidden;
  padding: 0;
  background: #ffffff;
}

.brand-mark img {
  position: absolute;
  top: 50%;
  left: 50%;
  display: block;
  width: 92px;
  height: 92px;
  max-width: none;
  object-fit: contain;
  transform: translate(-50%, -50%);
}

:root[data-theme="light"] .portfolio-select {
  background: #fbfcff !important;
  border-color: var(--line-strong) !important;
  color: var(--ink) !important;
  padding: 5px;
}

:root[data-theme="light"] .portfolio-select option {
  border-radius: 0;
  background: #fbfcff;
  color: var(--ink);
  padding: 7px 9px;
}

:root[data-theme="light"] .portfolio-select option:checked {
  background: #edf4fc linear-gradient(0deg, #edf4fc, #edf4fc);
  color: #28588f;
  font-weight: 800;
}

:root[data-theme="light"] .strategy-details > div:nth-child(1),
:root[data-theme="light"] .metric:nth-child(1) {
  background: #f3f8ff !important;
  border-top-color: #70a7e8 !important;
}

:root[data-theme="light"] .strategy-details > div:nth-child(2),
:root[data-theme="light"] .metric:nth-child(2) {
  background: #f2fbf8 !important;
  border-top-color: #63c2a6 !important;
}

:root[data-theme="light"] .strategy-details > div:nth-child(3),
:root[data-theme="light"] .metric:nth-child(3) {
  background: #f8f5ff !important;
  border-top-color: #9d8bdb !important;
}

:root[data-theme="light"] .strategy-details > div:nth-child(4),
:root[data-theme="light"] .metric:nth-child(4) {
  background: #fff9ef !important;
  border-top-color: #e7b45a !important;
}

:root[data-theme="light"] .strategy-details > div:nth-child(5),
:root[data-theme="light"] .metric:nth-child(5) {
  background: #fff4f4 !important;
  border-top-color: #e68b91 !important;
}

:root[data-theme="light"] .strategy-details > div:nth-child(6),
:root[data-theme="light"] .metric:nth-child(6) {
  background: #f4f7f9 !important;
  border-top-color: #8fa1b2 !important;
}

:root[data-theme="light"] .factor-library-section {
  background: #fbfdfd;
}

:root[data-theme="light"] #portfolioSection {
  background: #fbfcff;
}

:root[data-theme="light"] .chip-list span,
:root[data-theme="light"] .empty-box,
:root[data-theme="light"] .compact-empty {
  background: #f5f8fb !important;
  border-color: var(--line) !important;
  color: var(--muted) !important;
}

:root[data-theme="light"] .strategy-lock-note {
  background: #eaf8f5;
  border-color: #b8e4d9;
  color: #167968;
}

:root[data-theme="light"] .portfolio-actions,
:root[data-theme="light"] .pool-editor-field {
  position: relative;
}

.strategy-library-engine-select {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.strategy-library-list {
  display: grid;
  gap: 8px;
  padding: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-soft);
}

.strategy-library-rows {
  display: grid;
  gap: 8px;
  max-height: 246px;
  overflow: auto;
  padding-right: 3px;
}

.strategy-library-group {
  display: grid;
  gap: 4px;
}

.strategy-library-group-title {
  padding: 2px 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.strategy-library-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 5px;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--theme-input, #ffffff);
  overflow: hidden;
}

.strategy-library-row.is-active {
  border-color: #9dc0eb;
  background: #f0f6ff;
  box-shadow: inset 3px 0 0 #4d8ddc;
}

.strategy-library-row-select,
.strategy-library-row-delete {
  min-width: 0;
  min-height: 32px;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-size: 12px;
  font-weight: 800;
  text-align: left;
  cursor: pointer;
}

.strategy-library-row-select {
  padding: 5px 8px 5px 10px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strategy-library-row-select:hover {
  color: var(--accent-strong);
}

.strategy-library-row-delete {
  padding: 5px 8px;
  border-left: 1px solid var(--line);
  color: var(--red);
  font-size: 11px;
  font-weight: 900;
}

.strategy-library-row-delete:hover {
  background: #fff1f2;
}

.strategy-library-empty {
  padding: 12px 8px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.strategy-library-list .strategy-library-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 7px;
  margin: 0;
}

:root[data-theme="light"] .strategy-library-list {
  background: #fbfcff;
  border-color: var(--line-strong);
}

/* Keep the strategy library as one clean surface inside the strategy card. */
.strategy-card > .strategy-library {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  padding: 0;
  border: 0;
  background: transparent;
}

.strategy-card .strategy-library-head {
  display: flex;
  padding: 0 2px;
}

.strategy-card .strategy-library-head > span {
  font-size: 11px;
  font-weight: 850;
}

.strategy-card .strategy-library-head small {
  max-width: 58%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.strategy-library-list {
  gap: 0;
  padding: 4px;
  border-radius: 6px;
  background: #f7faff;
}

.strategy-library-rows {
  gap: 2px;
  padding-right: 2px;
}

.strategy-library-group {
  gap: 2px;
}

.strategy-library-group-title {
  padding: 3px 6px 4px;
  font-size: 10px;
}

.strategy-library-row {
  gap: 0;
  border: 0;
  border-bottom: 1px solid #e7edf4;
  border-radius: 4px;
  background: transparent;
}

.strategy-library-row:last-child {
  border-bottom: 0;
}

.strategy-library-row.is-active {
  border-color: transparent;
  background: #e4efff;
  box-shadow: inset 3px 0 0 #4d8ddc;
}

.strategy-library-row-select,
.strategy-library-row-delete {
  min-height: 30px;
}

.strategy-library-row-select {
  padding-left: 9px;
}

.strategy-library-row-delete {
  border-left: 0;
  padding-right: 7px;
  background: transparent;
}

.strategy-library-list .strategy-library-actions {
  display: none;
}

:root[data-theme="light"] .run-button.secondary {
  background: var(--theme-input) !important;
  border-color: var(--accent) !important;
  color: var(--ink) !important;
}

:root[data-theme="light"] .run-button.secondary:hover {
  background: var(--theme-hover) !important;
  border-color: var(--accent-strong) !important;
  color: var(--ink) !important;
}

:root[data-theme="light"] .run-button.secondary:disabled {
  background: #f4f6f8 !important;
  border-color: var(--line-strong) !important;
  color: var(--muted) !important;
  opacity: 1;
}

@media (min-width: 1000px) {
  .brand p {
    max-width: 540px;
  }
}
