/* Studio follows the existing EA register and Alerts surfaces and controls. */
body.ea-studio-page {
  --ea-ds-accent: var(--accent);
  --ea-ds-ink: var(--text);
  --ea-ds-weak: var(--text-2);
}
.ea-studio-page .workspace {
  --accent: var(--ea-ds-accent);
  --text: var(--ea-ds-ink);
  --muted: var(--ea-ds-weak);
  --line: var(--grid-line);
  --surface: var(--bg-raised);
  color: var(--text);
  background: var(--bg-deep);
  font: 400 13px/1.45 var(--font);
}
.ea-studio-page .topbar { min-height: 44px; height: 44px; padding: 5px 12px; background: var(--bg-base); border-color: var(--grid-line); }
.ea-studio-page #reset { min-height: 30px; }
.ea-studio-page .brand { display: inline-flex; align-items: center; gap: 6px; }
.ea-studio-page .brand strong { color: var(--text); }
.ea-studio-page .ea-mock-nav { background: var(--bg-base); padding: 3px 10px; }
.ea-studio-page .ea-mock-nav a { min-height: 26px; font-size: 12px; padding: 3px 8px; border-radius: 6px; }
#main:has(> .studio-wrap) { width: 100%; max-width: none; padding: 0; }
.studio-wrap { min-width: 0; }
.studio-workbar {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 8px 12px;
  padding: 8px 12px; background: var(--bg-base); border-bottom: 1px solid var(--grid-line);
}
.studio-identity { min-width: 0; }
.studio-identity h1 { font-size: 16px; line-height: 1.4; overflow-wrap: anywhere; }
.studio-identity p, .studio-state { color: var(--muted); font-size: 12px; }
.studio-state { justify-self: end; white-space: nowrap; }
.studio-steps {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); list-style: none;
  gap: 4px; margin: 0; padding: 4px 12px 0; border-bottom: 1px solid var(--grid-line);
}
.studio-steps li { padding: 7px 4px; color: var(--muted); }
.studio-steps li[aria-current] { border-bottom: 2px solid var(--accent); color: var(--accent); font-weight: 650; }
.studio-steps b { font-variant-numeric: tabular-nums; }
.studio-mobile-step { display: none; }
.studio-grid {
  display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
  gap: 9px; padding: 10px 12px;
}
.studio-panel { display: grid; align-content: start; min-width: 0; gap: 8px; padding: 11px; border: 1px solid var(--grid-line); border-radius: 6px; background: var(--bg-surface); }
.studio-panel h2, .studio-panel h3 { margin: 0; font-size: 14px; font-weight: 700; }
.studio-panel :is(p, dd, li) { overflow-wrap: anywhere; }
.studio-summary { align-self: start; }
.studio-summary dl, .studio-diff, .studio-result dl { margin: 0; }
.studio-summary dl { display: grid; gap: 6px; }
.studio-summary dd, .studio-diff dd, .studio-result dd { margin: 0; }
.studio-summary dt, .studio-diff dt, .studio-result dt { font-size: 12px; color: var(--muted); }
.studio-summary a, .studio-extra summary { color: var(--accent); }
.studio-check { padding-top: 6px; border-top: 1px solid var(--grid-line); color: var(--muted); }
.studio-field { min-width: 0; display: grid; align-content: start; gap: 3px; color: var(--text); }
:is(.studio-wrap, .branch-dialog) :is(input:not([type="file"]), textarea, select) {
  width: 100%; min-width: 0; max-width: 100%; min-height: 33px; padding: 5px 8px;
  border: 1px solid var(--border-hover); border-radius: 6px;
  background: var(--bg-deep); color: var(--text); font: inherit;
}
.studio-wrap input[type=date] { display: block; appearance: none; }
.studio-wrap textarea { display: block; resize: vertical; }
.studio-settings { display: grid; gap: 7px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.studio-test-settings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.studio-compose { display: flex; flex-wrap: wrap; gap: 5px 7px; align-items: center; }
.studio-compose label:not(.studio-attach) { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.studio-compose select { width: auto; }
.studio-compose input[type=file] { position: absolute; width: 1px; height: 1px; clip-path: inset(50%); white-space: nowrap; overflow: hidden; }
.studio-attach:has(+ input:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.studio-wrap .small-button, .studio-attach {
  display: inline-flex; align-items: center; justify-content: center; min-height: 30px; padding: 4px 7px;
  border: 1px solid var(--border-hover); border-radius: 6px; background: var(--bg-raised);
  color: var(--text); font: 500 12px/1.3 var(--font); cursor: pointer;
}
.studio-wrap .small-button:hover { border-color: var(--accent); }
.studio-wrap .studio-next {
  margin-left: auto; color: var(--accent); border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--bg-base));
}
.studio-actions {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
  padding: 7px 12px; background: var(--bg-base); border-top: 1px solid var(--grid-line);
}
.studio-actions .studio-quiet { background: transparent; border: 0; min-height: 30px; padding: 2px 3px; font-size: 12px; color: var(--muted); }
.studio-extra { border-top: 1px solid var(--grid-line); padding-top: 6px; }
.studio-extra summary { width: fit-content; cursor: pointer; min-height: 25px; }
.studio-messages { padding-left: 17px; margin: 6px 0 0; }
.studio-messages > li { margin-bottom: 5px; }
.studio-messages p { color: var(--muted); }
.studio-diff { display: grid; gap: 6px; }
.studio-diff > div { padding: 5px 0; border-top: 1px solid var(--grid-line); }
.studio-diff dd span { color: var(--muted); }
.studio-note, .studio-warning, .studio-result { padding: 7px 8px; border: 1px solid var(--grid-line); border-radius: 6px; background: var(--bg-base); }
.studio-warning { color: var(--amber); }
.studio-result dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 7px 0; }
.studio-result dd { font-size: 16px; font-weight: 700; }
.studio-empty { padding: 12px; }
.studio-empty h1 { font-size: 16px; margin-bottom: 6px; }
@media (max-width: 680px) {
  .ea-studio-page .topbar { min-height: 41px; height: 41px; padding: 4px 7px; }
  .ea-studio-page .brand strong { font-size: 14px; }
  .ea-studio-page .brand > span, .ea-studio-page #reset { font-size: 11px; }
  .ea-studio-page .ea-mock-nav { padding: 3px 6px; }
  .ea-studio-page .ea-mock-nav a { min-height: 32px; }
  .studio-workbar { grid-template-columns: minmax(0, 1fr) auto; gap: 4px 6px; padding: 5px 7px; }
  .studio-workbar > a { width: fit-content; }
  .studio-identity { grid-row: 2; grid-column: 1 / -1; }
  .studio-identity h1 { font-size: 15px; }
  .studio-state { grid-column: 2; grid-row: 1; }
  .studio-steps { display: none; }
  .studio-mobile-step { display: block; padding: 5px 7px; color: var(--accent); border-bottom: 1px solid var(--grid-line); }
  .studio-grid { grid-template-columns: minmax(0, 1fr); padding: 6px 7px; gap: 6px; }
  .studio-panel { padding: 8px; }
  #studio-heading { position: absolute; height: 1px; width: 1px; clip-path: inset(50%); overflow: hidden; }
  .studio-settings { grid-template-columns: minmax(0, 1fr); }
  :is(.studio-wrap, .branch-dialog) :is(input:not([type="file"]), textarea, select) { font-size: max(16px, 1em); }
  .studio-actions { position: sticky; bottom: 0; z-index: 1; gap: 4px; padding: 5px 6px max(5px, env(safe-area-inset-bottom)); }
  .studio-actions :is(.small-button, .studio-quiet) { min-height: 40px; }
  .studio-actions .studio-next { margin-left: auto; }
}
.studio-compose label:not(.studio-attach) { flex: 0 0 auto; white-space: nowrap; }
@media (max-width: 680px) {
  .studio-compose :is(.small-button, select) { min-height: 34px; }
}

/* Backtest reuses the Studio layout and native table palette. */
.bt-wrap .ok { color: var(--up); }
.bt-wrap .bad { color: var(--down); }
.bt-values { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 0; }
.bt-values > div { min-width: 0; padding: 6px 8px; border: 1px solid var(--grid-line); border-radius: 5px; background: var(--bg-base); }
.bt-values dt { color: var(--text-2); font-size: 12px; }
.bt-values dd { margin: 1px 0 0; font-size: 17px; font-weight: 680; font-variant-numeric: tabular-nums; }
.bt-chart { padding: 8px; margin: 0; border: 1px solid var(--grid-line); border-radius: 5px; background: var(--grid-bg); color: var(--accent); }
.bt-chart.bt-negative { color: var(--down); }
.bt-chart :is(figcaption, .bt-chart-range) { color: var(--text-2); font-size: 12px; }
.bt-chart-range { display: flex; gap: 4px 8px; flex-wrap: wrap; justify-content: space-between; }
.bt-chart svg { display: block; width: 100%; height: 145px; }
.bt-guides { fill: none; stroke: var(--grid-line); }
.bt-trades { min-width: 0; }
.bt-trades table { table-layout: fixed; width: 100%; margin-top: 4px; color: var(--grid-text); background: var(--grid-bg); font-size: 12px; }
.bt-trades :is(th,td) { padding: 5px 4px; border-bottom: 1px solid var(--grid-line); overflow-wrap: anywhere; }
.bt-trades th { color: var(--grid-text); background: var(--grid-head); }
.bt-trades th:first-child { width: 9%; }
.bt-trades th:nth-child(2) { width: 22%; }
.bt-trades :is(th,td):nth-child(n+4) { text-align: right; }
.bt-recent { color: var(--text-2); }
.studio-test-settings + .bt-recent { margin-top: 2px; }
.workspace .bt-recent a { color: var(--accent); text-decoration: underline; }
@media (max-width: 680px) {
  .bt-values { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .bt-values dd { font-size: clamp(14px, 5vw, 17px); }
  .bt-chart svg { height: 104px; }
  .bt-chart-range { font-size: 11px; }
  .bt-trades :is(th,td):nth-child(3) { display: none; }
  .bt-trades :is(th,td) { padding-inline: 3px; font-size: 11px; }
  .bt-trades th:first-child { width: 11%; }
  .bt-trades th:nth-child(2) { width: 25%; }
  .bt-wrap .studio-actions a { min-height: 40px; }
}
.bt-result-title { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 2px 8px; }
.bt-result-title p { font-size: 12px; }
.bt-result-title .demo-entry { margin: 0; }
.demo-duration { margin: 0; padding: 0; border: 0; }
.demo-duration legend { padding: 0 0 3px; }
.demo-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.demo-options label { position: relative; text-align: center; }
.demo-options input[type=radio] {
  position: absolute; width: 1px; height: 1px; min-height: 0; padding: 0; margin: 0; clip-path: inset(50%);
}
.demo-options label:has(:checked) {
  color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg-base));
}
.demo-options label:has(:focus-visible) { outline: 2px solid var(--accent); outline-offset: 2px; }
.studio-summary .demo-source { border-top: 1px solid var(--grid-line); padding-top: 7px; }
.live-fields { min-inline-size: 0; margin: 0; padding: 0; border: 0; }
.live-wrap :is(input, button):disabled { opacity: .55; cursor: default; }
.live-status { align-items: center; }
.live-badge { padding: 3px 7px; border: 1px solid var(--grid-line); border-radius: 5px; font-size: 12px; }
.live-setup-actions > span { font-size: 12px; }
.live-wrap .bt-values dd { overflow-wrap: anywhere; }
.report-links { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.run-history-content { display: grid; gap: 6px; padding: 8px 12px; min-width: 0; }
.run-history-tabs { display: flex; flex-wrap: wrap; gap: 5px; }
.run-history-tabs .small-button { gap: 5px; min-width: 78px; }
.run-history-tabs span {
  padding: 1px 5px; border-radius: 10px; color: var(--muted); background: var(--bg-base);
  font-variant-numeric: tabular-nums;
}
.run-history-tabs [aria-current] {
  color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg-base));
}
.run-history-tabs [aria-current] span { color: var(--accent); }
.run-history-list { list-style: none; margin: 0; padding: 0; }
.run-history-head, .run-history-row {
  display: grid; grid-template-columns: minmax(0, 1.8fr) repeat(2, minmax(0, 1fr)) minmax(0, 1.2fr) auto;
  align-items: center; gap: 6px 10px; padding: 6px 8px;
}
.run-history-head { color: var(--muted); background: var(--grid-head); border-radius: 5px; font-size: 12px; }
.run-history-head > :last-child { min-width: 57px; }
.run-history-row { border-bottom: 1px solid var(--grid-line); overflow-wrap: anywhere; }
.run-history-row:hover { background: var(--row-hover); }
.run-history-period > strong, .run-history-row small { display: block; }
.run-history-row small { color: var(--muted); font-size: 11px; }
.run-history-capital, .run-history-net { font-variant-numeric: tabular-nums; }
.run-history-state .live-badge { display: inline-block; }
.run-history-row .run-history-open { min-width: 57px; }
.run-history-note { font-size: 12px; }
.run-history-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 5px 8px; }
.run-history-toolbar > .demo-entry { margin: 0; }
.run-compare form { display: grid; gap: 6px; }
.run-compare-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; }
.run-compare-side { gap: 4px; }
.run-compare-side .muted { font-size: 12px; }
.compare-round-dates { font-size: 12px; overflow-wrap: anywhere; }
.compare-version-choice { display: flex; align-items: center; gap: 5px; color: var(--muted); }
.run-compare .compare-version-choice select { width: auto; }
.run-compare .run-history-tabs [aria-current] { color: var(--accent); }
.run-compare-notice { color: var(--text); font-size: 12px; }
.run-compare-table { width: 100%; border-collapse: collapse; table-layout: fixed; font-variant-numeric: tabular-nums; }
.run-compare-table :is(td, th) { padding: 6px 8px; border-bottom: 1px solid var(--grid-line); overflow-wrap: anywhere; }
.run-compare-table thead { background: var(--grid-head); color: var(--text-2); font-size: 12px; }
.run-compare-table tbody th { text-align: left; color: var(--text-2); }
.run-compare-table tr > :not(:first-child) { text-align: right; }
.run-compare-table td small { display: block; font-size: 11px; }
.optimize-work { display: grid; min-width: 0; gap: 6px; align-content: start; }
.optimize-grid { align-items: start; }
.optimize-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.optimize-chips button[aria-pressed="true"] {
  color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg-base));
}
.optimize-source { display: grid; gap: 3px; border-top: 1px solid var(--grid-line); padding-top: 6px; }
#opt-chat-form { display: grid; gap: 6px; }
#opt-chat-form button { justify-self: start; }
.optimize-reply { display: grid; gap: 5px; }
.optimize-reply button { justify-self: start; }
.retest-conditions {
  display: grid; grid-template-columns: minmax(0, 1.6fr) repeat(2, minmax(0, 1fr)); gap: 6px; margin: 0;
}
.retest-conditions > div { padding: 6px 8px; border: 1px solid var(--grid-line); border-radius: 5px; }
.retest-conditions:has(> :nth-child(4)) { grid-template-columns: minmax(0, 1.6fr) repeat(3, minmax(0, 1fr)); }
.retest-conditions dt { color: var(--muted); font-size: 12px; }
.retest-conditions dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.retest-actions .small-button { width: fit-content; }
.run-history-state .retest-history-link { margin-top: 3px; }
.demo-retest-options { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.demo-retest-options > li { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; padding: 6px; border: 1px solid var(--grid-line); border-radius: 5px; }
.demo-retest-options .retest-conditions { flex: 1 1 220px; }
.demo-retest-options .small-button { margin-left: auto; }
.pdca-stages { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.pdca-stage { gap: 6px; }
.pdca-stage .muted { font-size: 12px; }
.pdca-stage .run-compare-table :is(th, td) { padding-inline: 4px; }
.pdca-stage .run-compare-table thead th:first-child { width: 28%; }
.pdca-stage .run-compare-table thead th:last-child { width: 27%; }
.pdca-summary { font-size: 13px; }
.pdca-brief { font-variant-numeric: tabular-nums; }
.pdca-brief th a { color: var(--accent); text-decoration: underline; text-underline-offset: 3px; }
.pdca-brief small { display: block; line-height: 1.35; }
.pdca-brief thead small, .pdca-brief tbody th small { color: var(--muted); }
.pdca-brief td strong { font-size: 15px; }
