/* AlgoTree Pro Trader Desk v2 — layout fixes, no overlap */

:root {
  --at-rail-w: 228px;
  --at-command-h: 92px;
  --at-ws-h: 118px;
  --at-shell-gap: 0.75rem;
}

/* ── Scroll shell — header fixed, content scrolls below (no overlap) ── */
.at-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}

.at-sticky-chrome {
  flex-shrink: 0;
  z-index: 250;
  background: linear-gradient(180deg, #050810 0%, #050810 96%, rgba(5, 8, 16, 0.98) 100%);
  padding-bottom: 0.35rem;
  border-bottom: 1px solid rgba(56, 189, 248, 0.12);
}

.at-sticky-chrome .at-command-header {
  margin: 0.65rem 1.25rem 0;
}

.at-command-header {
  flex-shrink: 0;
  margin: 0.65rem 1.25rem 0;
  z-index: 30;
}

/* ── Workspace dock (2 rows — fully visible) ── */
.at-workspace-dock,
body.at-aurora .workspace-bar.at-workspace-dock {
  flex-shrink: 0;
  position: relative !important;
  top: auto !important;
  margin: 0.5rem 1.25rem 0;
  padding: 0.65rem 0.85rem 0.75rem;
  background: rgba(8, 14, 28, 0.96) !important;
  border: 1px solid rgba(56, 189, 248, 0.35) !important;
  border-radius: 10px !important;
  clip-path: none !important;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45) !important;
  z-index: 25;
  overflow: visible !important;
}

.at-workspace-dock::before,
body.at-aurora .workspace-bar::before {
  display: none !important;
  content: none !important;
}

.ws-dock-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.ws-dock-title {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: #38bdf8;
}

.ws-dock-context {
  font-size: 0.72rem;
  color: #94a3b8;
  font-family: "JetBrains Mono", monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55%;
}

.ws-toolbar-primary,
.ws-toolbar-secondary {
  display: grid !important;
  gap: 0.45rem;
  width: 100%;
  align-items: stretch;
}

.ws-toolbar-primary {
  grid-template-columns: repeat(auto-fill, minmax(148px, 1fr));
  margin-bottom: 0.45rem;
}

.ws-toolbar-secondary {
  grid-template-columns: repeat(3, minmax(100px, 130px)) minmax(0, 1fr) auto;
  align-items: center;
}

@media (max-width: 900px) {
  .ws-toolbar-primary,
  .ws-toolbar-secondary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

body.at-aurora .ws-field {
  display: flex !important;
  flex-direction: column !important;
  align-items: stretch !important;
  gap: 0.25rem !important;
  height: auto !important;
  min-height: 58px;
  padding: 0.45rem 0.55rem !important;
  background: rgba(0, 0, 0, 0.4) !important;
  border: 1px solid rgba(56, 189, 248, 0.2) !important;
  border-radius: 8px !important;
}

body.at-aurora .ws-label {
  font-size: 0.58rem !important;
  font-weight: 700 !important;
  letter-spacing: 0.1em !important;
  color: #94a3b8 !important;
  line-height: 1.2;
}

body.at-aurora .ws-field select,
body.at-aurora .ws-field input {
  width: 100% !important;
  min-width: 0 !important;
  max-width: none !important;
  height: 32px !important;
  padding: 0.35rem 0.5rem !important;
  font-size: 0.8rem !important;
  color: #f1f5f9 !important;
  background: rgba(2, 6, 16, 0.9) !important;
  border: 1px solid rgba(56, 189, 248, 0.25) !important;
  border-radius: 6px !important;
}

.ws-params-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  min-width: 0;
  overflow: hidden;
}

.ws-params-label {
  display: block;
}

body.at-aurora .ws-params-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  max-height: 72px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.15rem;
}

body.at-aurora .ws-param-chip {
  display: inline-flex !important;
  flex-direction: column !important;
  gap: 0.15rem;
  padding: 0.3rem 0.4rem !important;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  min-width: 72px;
}

body.module-manual .ws-strategy-field,
body.module-manual #preset-label,
body.module-manual .ws-params-wrap,
body.module-creator .ws-strategy-field,
body.module-creator #preset-label,
body.module-creator .ws-params-wrap {
  display: none !important;
}

body.module-manual .ws-toolbar-primary {
  grid-template-columns: repeat(3, minmax(120px, 1fr));
}

/* Main content — scrolls independently below header + workspace */
body.at-aurora .platform-shell {
  flex: 1;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0.75rem 1.25rem 2rem;
  min-width: 0;
  position: relative;
  z-index: 1;
}

body.at-aurora .module {
  position: relative;
  z-index: 1;
}

body.at-aurora .module-head.compact > div:first-child h1,
body.at-aurora .module-head.compact > div:first-child > p:not(.hint) {
  display: none;
}

/* ── Backtest Lab — professional desk ── */
.bt-pro-shell {
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.bt-pro-controls {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  position: relative;
  max-height: none;
  overflow: visible;
  padding-right: 0.15rem;
}

/* ── Full-width backtest period strip (always visible) ── */
body.module-backtest .bt-period-strip {
  position: sticky;
  top: 0;
  z-index: 60;
  margin-bottom: 0.85rem;
  padding: 1rem 1.1rem;
  border: 1px solid rgba(56, 189, 248, 0.45);
  background: linear-gradient(165deg, rgba(56, 189, 248, 0.14), rgba(6, 10, 22, 0.97));
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}

.bt-period-strip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem 1.25rem;
}

.bt-period-strip-kicker {
  display: block;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #38bdf8;
  margin-bottom: 0.25rem;
}

.bt-period-strip-label {
  margin: 0;
  font-size: 0.88rem;
  color: #cbd5e1;
  line-height: 1.4;
}

.bt-period-strip-range {
  margin: 0.35rem 0 0;
  font-size: 0.95rem;
  color: #94a3b8;
}

.bt-period-strip-range-lbl {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-right: 0.35rem;
}

.bt-period-strip-range strong,
.bt-period-strip-label strong {
  font-family: "JetBrains Mono", monospace;
  color: #38bdf8;
  font-size: 1rem;
}

.bt-period-strip-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.bt-period-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

body.module-backtest .bt-period-buttons .bt-simple-period {
  padding: 0.62rem 1.1rem;
  min-height: 44px;
  font-size: 0.88rem;
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.35);
  background: rgba(0, 0, 0, 0.45);
  color: #e2e8f0;
  cursor: pointer;
  white-space: nowrap;
}

body.module-backtest .bt-period-buttons .bt-simple-period.active {
  border-color: #38bdf8;
  background: rgba(56, 189, 248, 0.2);
  color: #fff;
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35) inset;
}

body.module-backtest .bt-period-buttons .bt-simple-period:hover {
  border-color: #38bdf8;
  color: #fff;
}

.bt-period-run {
  min-height: 44px;
  padding: 0.62rem 1.35rem;
  font-size: 0.95rem;
  font-weight: 700;
  white-space: nowrap;
}

.bt-period-status {
  margin: 0.65rem 0 0;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.82rem;
  color: #94a3b8;
  line-height: 1.45;
}

body.module-backtest .bt-period-strip.bt-range-stale {
  border-color: rgba(251, 191, 36, 0.55);
  background: linear-gradient(165deg, rgba(251, 191, 36, 0.12), rgba(40, 28, 8, 0.92));
}

.bt-wizard-note {
  margin: 0.75rem 0 0;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  background: rgba(56, 189, 248, 0.08);
  border: 1px solid rgba(56, 189, 248, 0.2);
}

.bt-pro-results {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.bt-pro-run-card {
  padding: 1rem;
  border: 1px solid rgba(56, 189, 248, 0.3);
  background: linear-gradient(160deg, rgba(56, 189, 248, 0.1), rgba(8, 12, 24, 0.85));
}

.bt-range-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: rgba(8, 14, 28, 0.9);
}

.bt-range-banner.bt-range-stale {
  border-color: rgba(251, 191, 36, 0.55);
  background: rgba(60, 40, 8, 0.35);
}

.bt-range-banner strong {
  font-family: "JetBrains Mono", monospace;
  color: #38bdf8;
}

.bt-range-mode {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #94a3b8;
  margin-right: 0.35rem;
}

.bt-wizard-title {
  margin: 0 0 0.75rem;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #38bdf8;
}

.bt-wizard-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.bt-wizard-step {
  display: flex;
  gap: 0.65rem;
  align-items: flex-start;
  padding: 0.55rem 0.6rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
  opacity: 0.72;
}

.bt-wizard-step.active {
  opacity: 1;
  border-color: rgba(56, 189, 248, 0.45);
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.12) inset;
}

.bt-wizard-step.done {
  opacity: 1;
  border-color: rgba(52, 211, 153, 0.35);
}

.bt-wizard-num {
  flex-shrink: 0;
  width: 1.55rem;
  height: 1.55rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  background: rgba(56, 189, 248, 0.15);
  color: #38bdf8;
}

.bt-wizard-step.done .bt-wizard-num {
  background: rgba(52, 211, 153, 0.2);
  color: #34d399;
}

.bt-wizard-step strong {
  display: block;
  font-size: 0.82rem;
  margin-bottom: 0.2rem;
}

.bt-simple-steps {
  text-align: left;
}

.bt-pro-results .sub-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(8, 12, 24, 0.98);
  padding: 0.35rem 0;
  margin: 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

body.module-backtest .bt-pro-results .sub-tabs {
  position: relative;
  top: auto;
  z-index: 1;
}

.bt-pro-results .bt-price-section {
  min-height: 320px;
}

.bt-pro-results #price-chart,
.bt-pro-results .price-chart-host {
  min-height: 440px;
}

.bt-pro-metrics-bar {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 0.45rem;
}

.bt-pro-metric {
  padding: 0.55rem;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  text-align: center;
}

.bt-pro-metric span {
  display: block;
  font-size: 0.55rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #94a3b8;
}

.bt-pro-metric strong {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.88rem;
  color: #fff;
}

body.at-aurora .bt-advanced { display: block !important; }
body.at-aurora .advanced-only { display: inline-flex !important; }
body.at-aurora .ws-field.advanced-only { display: flex !important; }

#pipeline-backtest:not(.hidden) {
  display: flex !important;
  margin-bottom: 0.5rem;
}

/* ── Chart Research Desk ── */
.research-command-bar {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(0, 1fr) auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.65rem 0.85rem;
  margin-bottom: 0.65rem;
  border: 1px solid rgba(167, 139, 250, 0.35);
  background: linear-gradient(135deg, rgba(167, 139, 250, 0.08), rgba(8, 12, 24, 0.9));
}

.research-command-label {
  display: block;
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: #a78bfa;
  margin-bottom: 0.2rem;
}

.research-command-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  justify-content: flex-end;
}

.research-desk-shell {
  margin-bottom: 0.65rem;
}

body.at-aurora .manual-workspace {
  display: grid;
  grid-template-columns: 180px minmax(0, 1.75fr) minmax(260px, 320px);
  gap: 0.75rem;
  align-items: stretch;
  min-height: calc(100vh - 300px);
}

body.at-aurora .manual-overlay-nav {
  position: relative !important;
  top: auto !important;
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  padding: 0.75rem;
}

body.at-aurora .manual-chart-col {
  display: flex;
  flex-direction: column;
  min-height: 640px;
  min-width: 0;
  border: 1px solid rgba(56, 189, 248, 0.25);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

body.at-aurora .manual-chart-host {
  flex: 1;
  min-height: 620px !important;
  height: auto !important;
}

body.at-aurora .manual-chart-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.25);
}

body.at-aurora .manual-side-col {
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  min-width: 0;
}

body.at-aurora #pro-deskboard:not(.hidden) {
  margin-top: 0.65rem;
  border: 1px solid rgba(167, 139, 250, 0.3);
}

body.at-aurora .methods-snapshot-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  min-height: 2rem;
}

body.at-aurora .manual-price {
  font-family: "JetBrains Mono", monospace;
  font-weight: 700;
  color: #38bdf8;
}

body.at-aurora .manual-bias-pill {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.12);
}

/* Studio grid spacing */
body.at-aurora .at-studio-grid {
  min-height: calc(100vh - 280px);
}

/* Prevent sticky overlap from legacy platform.css */
body.at-aurora .at-sticky-chrome .workspace-bar,
body.at-aurora.module-backtest .workspace-bar,
body.at-aurora.module-manual .workspace-bar,
body.module-backtest .workspace-bar {
  position: relative !important;
  top: auto !important;
}

body.at-aurora .platform-header,
body.at-aurora .platform-hero-strip {
  display: none !important;
}

@media (max-width: 1200px) {
  .research-command-bar {
    grid-template-columns: 1fr;
  }
  body.at-aurora .manual-workspace {
    grid-template-columns: 1fr;
  }
  .bt-pro-shell {
    grid-template-columns: 1fr;
  }
  .bt-period-strip-row {
    flex-direction: column;
    align-items: stretch;
  }
  .bt-period-strip-controls {
    flex-direction: column;
    align-items: stretch;
  }
  .bt-period-buttons {
    width: 100%;
  }
  body.module-backtest .bt-period-buttons .bt-simple-period {
    flex: 1 1 calc(50% - 0.5rem);
    text-align: center;
  }
  .bt-period-run {
    width: 100%;
  }
}

/* ── Mobile: bigger chart, no clip, stacked desk ── */
@media (max-width: 1200px) {
  body.at-aurora .manual-workspace {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  body.at-aurora .manual-chart-col {
    order: 1;
    min-height: min(72vh, 780px);
  }

  body.at-aurora .manual-chart-host,
  body.at-aurora #manual-chart.price-chart-host {
    min-height: min(65vh, 720px) !important;
    height: min(65vh, 720px) !important;
  }

  body.at-aurora .manual-overlay-nav {
    order: 2;
    max-height: none;
    overflow: visible;
  }

  body.at-aurora .manual-side-col {
    order: 3;
    max-height: none;
    overflow: visible;
  }

  body.at-aurora .at-rail {
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    max-height: none;
    border-right: none;
    border-bottom: 1px solid rgba(56, 189, 248, 0.15);
  }

  body.at-aurora .at-app {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }

  body.at-aurora .module-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  body.at-aurora .module-btn {
    flex: 1 1 calc(50% - 0.35rem);
    min-width: 8rem;
    font-size: 0.72rem;
  }
}

@media (max-width: 640px) {
  body.at-aurora .manual-chart-col {
    min-height: min(68vh, 640px);
  }

  body.at-aurora .manual-chart-host,
  body.at-aurora #manual-chart.price-chart-host {
    min-height: min(62vh, 600px) !important;
    height: min(62vh, 600px) !important;
  }

  body.at-aurora .ws-dock-context {
    max-width: 100%;
  }

  body.at-aurora .research-command-bar {
    grid-template-columns: 1fr;
  }

  .price-chart-host {
    min-height: 360px;
  }
}
