:root {
  --bg: #0c1016;
  --panel: #11151c;
  --line: #222a38;
  --text: #d7dde6;
  --muted: #7d889a;
  --accent: #3d8bfd;
  --sell: #ff8a3d;
  --good: #2ecc71;
  --bad: #ef5350;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif;
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
  color: inherit;
}

button {
  background: #1a2130;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 10px;
  cursor: pointer;
}

button:hover {
  border-color: #3a4558;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

button.link {
  background: none;
  border: none;
  color: var(--muted);
  padding: 2px 4px;
}

input {
  background: #0f141b;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 4px 8px;
}

/* -- login ---------------------------------------------------------------- */

#login {
  height: 100%;
  display: grid;
  place-items: center;
}

#login-form {
  width: min(320px, 90vw);
  display: grid;
  gap: 10px;
  padding: 24px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

#login-form h1 {
  margin: 0 0 8px;
  font-size: 20px;
}

.error {
  color: var(--bad);
  min-height: 1.4em;
  margin: 0;
}

/* -- layout ----------------------------------------------------------------- */

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
}

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  flex-wrap: wrap;
}

#menu-button {
  font-size: 18px;
  line-height: 1;
  padding: 4px 9px;
  position: relative;
}

#menu-button.active {
  border-color: var(--accent, #3d8bfd);
}

/* History loading: a pulsing dot on the ☰ button. */
#menu-button.busy::after {
  content: "";
  position: absolute;
  top: 3px;
  right: 3px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #f5c542;
  animation: blink 1s steps(2) infinite;
}

.menu-panel {
  position: fixed;
  z-index: 30;
  top: 44px;
  left: 8px;
  width: min(400px, calc(100vw - 16px));
  max-height: calc(100vh - 60px);
  overflow-y: auto;
  padding: 10px 12px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
}

.menu-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.menu-search {
  position: relative;
}

.menu-search input {
  width: 100%;
  box-sizing: border-box;
}

.menu-results {
  position: absolute;
  z-index: 5;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  max-height: 50vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.menu-results .result {
  display: grid;
  grid-template-columns: 34px 80px 1fr;
  align-items: center;
  gap: 2px 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.menu-results .result:hover {
  background: #1a2231;
}

.menu-results .result .muted {
  grid-column: 2 / 4;
  color: var(--muted);
  font-size: 12px;
}

.menu-results .result.unsupported {
  opacity: 0.5;
  cursor: default;
}

.menu-results .note,
.menu-results .group-title {
  padding: 6px 10px;
  color: var(--muted);
  font-size: 12px;
}

.menu-results .badge {
  font-size: 10px;
  text-align: center;
  border-radius: 3px;
  background: #2a3345;
  color: var(--muted);
}

.menu-card {
  margin: 10px 0 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.menu-panel .muted {
  color: var(--muted);
  font-size: 12px;
}

.menu-panel .hint {
  color: var(--muted);
  font-size: 12px;
}

.menu-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.menu-panel .rec {
  font-size: 12px;
  color: var(--muted);
}

.menu-panel .rec.on {
  color: var(--good);
}

.menu-panel button.record {
  border-color: var(--good);
  color: var(--good);
}

.menu-panel button.danger {
  border-color: var(--bad);
  color: var(--bad);
}

.menu-section {
  margin: 14px 0 6px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.menu-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.menu-item b {
  cursor: pointer;
}

.menu-item .muted {
  flex: 1 1 auto;
}

.menu-job {
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.menu-job.running {
  border-color: #f5c542;
}

.menu-job.failed .hint {
  color: var(--bad);
}

.menu-progress {
  height: 5px;
  margin: 5px 0 3px;
  background: #1b2230;
  border-radius: 3px;
  overflow: hidden;
}

.menu-progress i {
  display: block;
  height: 100%;
  background: #f5c542;
}

.menu-job.cancelled .menu-progress i,
.menu-job.failed .menu-progress i {
  background: #56606f;
}

.menu-job .menu-item button.icon {
  padding: 0 7px;
  font-size: 15px;
  line-height: 1.4;
}

.menu-job.done .menu-progress i {
  background: var(--good);
}

#tabs {
  display: flex;
  gap: 4px;
  flex: 1 1 auto;
  overflow-x: auto;
  min-width: 0;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 10px;
  border: 1px solid var(--line);
  border-radius: 6px 6px 0 0;
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}

.tab.active {
  background: #1c2433;
  border-color: #34405a;
}

.tab .close {
  min-width: 24px;
  min-height: 24px;
  margin: -4px -2px; /* the bigger target does not make the tab taller */
  background: none;
  border: none;
  padding: 0 4px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: #56606f;
}

.dot.on {
  background: var(--good);
}

#search-box {
  position: relative;
}

#search {
  width: 220px;
}

#search-results {
  position: absolute;
  z-index: 10;
  top: calc(100% + 4px);
  right: 0;
  width: 360px;
  max-height: 60vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

#search-results .result {
  display: grid;
  grid-template-columns: 34px 80px 1fr;
  align-items: center;
  gap: 2px 8px;
  padding: 6px 10px;
  cursor: pointer;
}

#search-results .result .muted {
  grid-column: 2 / 4;
  color: var(--muted);
  font-size: 12px;
}

#search-results .result.unsupported {
  cursor: default;
  opacity: 0.5;
}

#search-results .result.unsupported:hover {
  background: none;
}

#search-results .badge {
  font-size: 10px;
  text-align: center;
  border-radius: 3px;
  padding: 1px 0;
  background: #2a3345;
  color: var(--muted);
}

#search-results .badge.fut {
  background: #1d3a5c;
  color: #8ec5ff;
}

#search-results .badge.stk {
  background: #1f4a33;
  color: #8fe0b0;
}

#search-results .group-title {
  padding: 8px 10px 2px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

#search-results .group-title:first-child {
  border-top: none;
}

#search-results .note.back {
  cursor: pointer;
}

#data-banner {
  position: absolute;
  z-index: 5;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 120px);
  padding: 4px 12px;
  border-radius: 4px;
  font-size: 12px;
  background: rgba(120, 80, 0, 0.85);
  color: #ffe2a8;
  pointer-events: none;
  text-align: center;
}

#data-banner.bad {
  background: rgba(130, 30, 30, 0.88);
  color: #ffd0d0;
}

#search-results .result:hover {
  background: #1a2231;
}

#search-results .note {
  padding: 6px 10px;
  color: var(--muted);
}

#status-box {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

#status.bad {
  color: var(--bad);
}

#toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

#toolbar.disabled {
  opacity: 0.4;
  pointer-events: none;
}

.group {
  display: flex;
  align-items: center;
  gap: 4px;
}

#timeframes button.active {
  border-color: var(--accent);
  color: #fff;
}

#min-volume {
  width: 80px;
}

#record.on {
  border-color: var(--good);
  color: var(--good);
}

#notice {
  color: var(--muted);
}

main {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

#chart-area {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

#chart {
  position: absolute;
  inset: 0 0 0 38px; /* left column: drawing tools */
  display: grid;
  gap: 4px;
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

#chart.cols {
  grid-template-columns: 1fr 1fr;
}

#chart.rows {
  grid-template-rows: 1fr 1fr;
}

/* One chart of the layout; the tooltip and editors are positioned inside it. */
.pane {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

.pane[hidden] {
  display: none;
}

/* Split layout: the active chart (toolbar, indicators, drawing tools act on it). */
#chart.cols .pane.active,
#chart.rows .pane.active {
  outline: 1px solid var(--accent, #3d8bfd);
  outline-offset: -1px;
}

#layout button.active {
  border-color: var(--accent, #3d8bfd);
}

#sync-time-box {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  margin-left: 4px;
}

/* -- right panel ------------------------------------------------------------------- */

#cluster-box {
  gap: 6px;
  color: var(--text);
  font-size: 12px;
}

/* Big trades minimum and the clusters: the same look. What automatic mode takes
   over (the minimum, the cluster size) is grey; what can be changed is white. */
#min-box {
  color: var(--text);
  font-size: 12px;
}

#toolbar .inactive {
  color: var(--muted);
}

#toolbar input:disabled {
  color: var(--muted);
  opacity: 0.6;
}

#cluster-box b {
  color: var(--text, #d6dbe4);
  font-weight: 600;
}

#cluster-box label {
  display: inline-flex;
  align-items: center;
  gap: 3px;
}

#cluster-box input {
  width: 58px;
}

#cluster-box.off {
  opacity: 0.45;
}

#min-hint {
  color: #f5c542;
  font-size: 12px;
  white-space: nowrap;
}

#panel.collapsed {
  display: none;
}

#dot-scale-box {
  margin-left: auto;
  color: var(--muted);
  gap: 6px;
}

#dot-scale {
  width: 110px;
}

#dot-scale-value {
  min-width: 3.2em;
  font-size: 12px;
}

#panel-toggle.active {
  border-color: var(--accent, #3d8bfd);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
  color: var(--muted);
}

.pill i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #56606f;
}

.pill.ok i {
  background: var(--good);
}

.pill.warn i {
  background: #f5c542;
}

.pill.bad {
  color: var(--bad);
  border-color: var(--bad);
}

.pill.bad i {
  background: var(--bad);
  animation: blink 1s steps(2) infinite;
}

@keyframes blink {
  50% {
    opacity: 0.3;
  }
}

.depth-params .hint {
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0 8px;
}

.depth-params .hint.warn {
  color: #f5c542;
}

.depth-params .field.custom span {
  color: #f5c542;
}

.depth-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

#panel {
  width: 330px;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--line);
  background: var(--panel);
  min-height: 0;
}

.bt-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
}

.bt-filter {
  display: flex;
  gap: 2px;
}

.bt-filter button {
  padding: 2px 8px;
  font-size: 12px;
}

.bt-filter button.active {
  border-color: var(--accent);
  color: #fff;
}

.bt-cols,
.bt-row {
  display: grid;
  grid-template-columns: 64px 44px 1fr 96px;
  gap: 6px;
  padding: 2px 8px;
  align-items: center;
}

.bt-cols {
  color: var(--muted);
  font-size: 11px;
  border-bottom: 1px solid var(--line);
}

.bt-list {
  flex: 1 1 auto;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
}

.bt-row {
  cursor: pointer;
  font-size: 12px;
}

.bt-row:hover {
  background: #1a2231;
}

.bt-row.buy span:nth-child(2) {
  color: var(--accent);
}

.bt-row.sell span:nth-child(2) {
  color: var(--sell);
}

.bt-row.inferred {
  opacity: 0.55;
}

.num {
  text-align: right;
}

.vol {
  position: relative;
}

.vol i {
  position: absolute;
  right: 0;
  top: 2px;
  bottom: 2px;
  border-radius: 2px;
  opacity: 0.35;
}

.bt-row.buy .vol i {
  background: var(--accent);
}

.bt-row.sell .vol i {
  background: var(--sell);
}

.vol b {
  position: relative;
  font-weight: 500;
}

.bt-empty {
  padding: 12px 8px;
  color: var(--muted);
}

.bt-summary {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 10px;
  padding: 8px;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: var(--muted);
}

.bt-summary b {
  color: var(--text);
  font-weight: 600;
}

.bt-summary b.buy {
  color: var(--accent);
}

.bt-summary b.sell {
  color: var(--sell);
}

/* -- status bar ---------------------------------------------------------------------- */

#statusbar {
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 3px 10px;
  border-top: 1px solid var(--line);
  background: var(--panel);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow-x: auto;
}

.sb-warn {
  color: #ffcf5c;
}

/* -- indicators menu ------------------------------------------------------------------ */

.ind-wrap {
  position: relative;
}

.ind-menu {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  width: 340px;
  padding: 6px 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.ind-title {
  padding: 4px 12px 6px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ind-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px;
}

.ind-row:hover {
  background: #1a2231;
}

.ind-name {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.ind-name small {
  color: var(--muted);
  font-size: 11px;
}

button.icon {
  min-width: 24px; /* a target of at least 24 px (WCAG 2.5.8) */
  min-height: 24px;
  background: none;
  border: 1px solid transparent;
  padding: 2px 6px;
  font-size: 15px;
  color: var(--muted);
}

button.icon:hover {
  color: var(--text);
  border-color: var(--line);
}

button.primary {
  border-color: var(--accent);
  color: #fff;
  background: #1f3b66;
}

/* toggle switch */
.switch {
  position: relative;
  width: 32px;
  height: 18px;
  flex: 0 0 auto;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch span {
  position: absolute;
  inset: 0;
  border-radius: 9px;
  background: #3a4558;
  cursor: pointer;
  transition: background 0.15s;
}

.switch span::before {
  content: "";
  position: absolute;
  width: 14px;
  height: 14px;
  left: 2px;
  top: 2px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.15s;
}

.switch input:checked + span {
  background: var(--accent);
}

.switch input:checked + span::before {
  transform: translateX(14px);
}

/* -- settings dialog -------------------------------------------------------------------- */

.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.45);
}

.dialog {
  width: min(420px, 94vw);
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid #34405a;
  border-radius: 8px;
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.6);
}

.dialog-head,
.dialog-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
}

.dialog-head {
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.dialog-foot {
  border-top: 1px solid var(--line);
}

.dialog-body {
  overflow-y: auto;
  padding: 4px 14px 10px;
}

.dialog-section {
  margin: 12px 0 4px;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 0;
}

.field input[type="number"] {
  width: 84px;
}

.field input[type="color"] {
  width: 44px;
  height: 24px;
  padding: 0 2px;
  cursor: pointer;
}

.field .range {
  display: flex;
  align-items: center;
  gap: 8px;
}

.field .range input {
  width: 130px;
}

.field output {
  width: 38px;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

select {
  font: inherit;
  color: inherit;
  background: #0f141b;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 3px 6px;
}

#empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
}

/* -- tooltip ------------------------------------------------------------------- */

.tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  min-width: 200px;
  padding: 8px 10px;
  background: rgba(17, 21, 28, 0.96);
  border: 1px solid #34405a;
  border-radius: 6px;
  font-size: 12px;
  line-height: 1.5;
}

.tt-head {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
}

.tt-head.buy {
  color: var(--accent);
}

.tt-head.sell {
  color: var(--sell);
}

@media (max-width: 900px) {
  main {
    flex-direction: column;
  }
  #chart-area {
    flex: 1 1 60%;
  }
  #panel {
    width: auto;
    flex: 0 0 40%;
    border-left: none;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 700px) {
  #search {
    width: 140px;
  }
  #search-results {
    width: 90vw;
  }
}

button.small {
  padding: 2px 8px;
  font-size: 12px;
  white-space: nowrap;
}

/* -- replay bar (M10) ------------------------------------------------------------------- */

#replay-button.on {
  border-color: #ffcf5c;
  color: #ffcf5c;
}

#replay-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  background: #151a22;
  flex-wrap: wrap;
}

#replay-time {
  min-width: 190px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

#replay-time.active {
  color: #ffcf5c;
  font-weight: 600;
}

#replay-bar input[type="datetime-local"] {
  color-scheme: dark;
}

/* -- simulated trading (M11) ---------------------------------------------------------------- */

.sim {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.sim.disabled {
  opacity: 0.45;
}

.sim-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #ffcf5c;
}

.sim-qty {
  width: 56px;
}

.sim-price {
  width: 96px;
}

.sim-buy {
  border-color: var(--accent);
  color: #fff;
  background: #1f3b66;
}

.sim-sell {
  border-color: var(--sell);
  color: #fff;
  background: #5a3419;
}

.sim-status {
  font-size: 12px;
  color: var(--muted);
}

.sim-status.bad {
  color: var(--bad);
}

.sim-status .buy,
.results .buy {
  color: var(--accent);
}

.sim-status .sell,
.results .sell {
  color: var(--sell);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 2px 1px 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
}

.chip.buy {
  border-color: var(--accent);
}

.chip.sell {
  border-color: var(--sell);
}

.dialog.wide {
  width: min(760px, 96vw);
}

.results {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.results th,
.results td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

.results th {
  color: var(--muted);
  font-weight: 500;
}

.results .num {
  text-align: right;
}

.muted {
  color: var(--muted);
}

/* -- drawing tools (M12) --------------------------------------------------------------------- */

#draw-toolbar {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 38px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding-top: 6px;
  border-right: 1px solid var(--line);
  background: var(--panel);
  z-index: 3;
}

#draw-toolbar button {
  width: 30px;
  height: 30px;
  padding: 0;
  background: none;
  border: 1px solid transparent;
  font-size: 15px;
  color: var(--muted);
}

#draw-toolbar button:hover {
  color: var(--text);
  border-color: var(--line);
}

#draw-toolbar button.active {
  color: #fff;
  border-color: var(--accent);
  background: #1f3b66;
}

#draw-clear {
  margin-top: auto;
  margin-bottom: 6px;
}

#draw-clear.armed {
  border-color: var(--bad) !important;
  color: var(--bad) !important;
}

#draw-props {
  position: absolute;
  top: 8px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(17, 21, 28, 0.95);
  border: 1px solid #34405a;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
}

#draw-props .swatches {
  display: flex;
  gap: 4px;
}

#draw-props .swatch {
  width: 18px;
  height: 18px;
  padding: 0;
  border-radius: 50%;
  border: 2px solid transparent;
}

#draw-props .swatch.active {
  border-color: #fff;
}

#draw-props .width {
  min-width: 34px;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
}

.draw-text-input {
  position: absolute;
  z-index: 7;
  width: 180px;
}

#draw-props .mirror {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

#draw-props .mirror[hidden] {
  display: none;
}

/* Indicators of a chart, top left (TradingView style): name, hide/show, settings. */
.legend {
  position: absolute;
  top: 6px;
  left: 8px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  pointer-events: none;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 1px 2px 1px 6px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 22px;
  color: var(--text);
  background: rgba(12, 16, 22, 0.55);
  pointer-events: auto;
}

.legend-row.off .legend-name {
  color: var(--muted);
  text-decoration: line-through;
}

.legend-row button {
  width: 23px;
  height: 20px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  line-height: 20px;
  cursor: pointer;
  opacity: 0;
}

.legend-row:hover button,
.legend-row.off button.eye {
  opacity: 1;
}

.legend-row button:hover {
  color: var(--text);
}

.legend-row svg {
  width: 15px;
  height: 15px;
  vertical-align: -3px;
}

/* Folds the list away and back (at its bottom). */
.legend-fold {
  pointer-events: auto;
  min-width: 30px;
  height: 22px;
  padding: 0 7px;
  border: 0;
  border-radius: 4px;
  background: rgba(12, 16, 22, 0.55);
  color: var(--muted);
  font-size: 15px;
  line-height: 22px;
  cursor: pointer;
}

.legend-fold svg {
  width: 15px;
  height: 15px;
  vertical-align: -3px;
}

.legend-fold span {
  margin-left: 2px;
  font-size: 13px;
}

.legend-fold:hover {
  color: var(--text);
}

@media (hover: none) {
  .legend-row button {
    opacity: 1;
  }
}

/* Automatic thresholds: "A" toggles next to the minimum fields, and their dialog. */
.auto-toggle {
  min-width: 22px;
  padding: 1px 5px;
  font-weight: 700;
  font-size: 11px;
  color: var(--muted);
}

.auto-toggle.on {
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

#min-auto-pct,
#cl-auto-pct {
  width: 72px; /* 0.01 fits next to the spinner */
}

.auto-dialog table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.auto-dialog th,
.auto-dialog td {
  padding: 3px 6px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

.auto-dialog td small {
  color: var(--muted);
}

.auto-dialog .zones input.name {
  width: 100px;
}

.auto-dialog .auto-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 8px 0;
}

.auto-dialog .auto-row input[type="number"] {
  width: 60px;
}

.auto-dialog .auto-msg,
.auto-dialog .hint {
  color: var(--muted);
  font-size: 12px;
}

/* MT5 trading panel (M16): on the right of the chart, the chart stays usable. */
.mt5-panel {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 8;
  width: 380px;
  max-width: calc(100% - 12px);
  max-height: calc(100% - 12px);
  overflow-y: auto;
  padding: 8px 10px;
  background: rgba(17, 21, 28, 0.97);
  border: 1px solid #34405a;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  font-size: 12px;
}

.mt5-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.mt5-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 4px 0;
}

.mt5-row input[type="number"] {
  width: 70px;
}

.mt5-stop-gap {
  width: 116px; /* the stop buttons under the limit ones */
}

.mt5-sym {
  font-size: 14px;
}

.mt5-last,
.mt5-line small {
  color: var(--muted);
}

.mt5-buy,
.mt5-buy-lmt,
.mt5-buy-stp {
  border-color: var(--good);
  color: var(--good);
}

.mt5-sell,
.mt5-sell-lmt,
.mt5-sell-stp {
  border-color: var(--bad);
  color: var(--bad);
}

.mt5-msg {
  color: var(--muted);
}

.mt5-msg.bad,
.mt5-line.bad {
  color: var(--bad);
}

.mt5-section {
  margin-top: 10px;
  padding-top: 6px;
  border-top: 1px solid var(--line);
  font-weight: 600;
}

.mt5-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 2px 0;
}

.mt5-line.other {
  opacity: 0.6;
}

.mt5-line .buy {
  color: var(--good);
}

.mt5-line .sell {
  color: var(--bad);
}

.mt5-account {
  margin: 6px 0;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.mt5-account .mt5-name {
  width: 130px;
}

.mt5-toggle.on {
  border-color: var(--good);
  color: var(--good);
}

.mt5-map {
  width: 100%;
  border-collapse: collapse;
}

.mt5-map th {
  text-align: left;
  font-weight: 400;
  color: var(--muted);
}

.mt5-map input {
  width: 100%;
  min-width: 0;
}

.mt5-key {
  margin: 6px 0;
  padding: 6px;
  border: 1px solid #f5c542;
  border-radius: 6px;
}

.mt5-key input {
  width: 100%;
  margin: 4px 0;
  font-family: monospace;
}

.mt5-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 4px;
  border-radius: 50%;
  background: var(--bad);
}

.mt5-dot.on {
  background: var(--good);
}

/* Trading on the chart (M16): the bar over the chart, the confirmation box. */
#trade-bar {
  position: absolute;
  top: 6px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 7;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(17, 21, 28, 0.95);
  border: 1px solid #34405a;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  font-size: 12px;
}

#trade-bar[hidden] {
  display: none;
}



#trade-msg {
  color: var(--muted);
  max-width: 260px;
}

#trade-msg.bad {
  color: var(--bad);
}

#trade-button.on {
  border-color: var(--accent);
  color: #fff;
}

.trade-confirm {
  position: absolute;
  z-index: 9;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: 250px;
  padding: 8px;
  background: rgba(17, 21, 28, 0.98);
  border: 1px solid #3d8bfd;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
  font-size: 12px;
}

.trade-confirm > div {
  width: 100%;
}

#trade-dest {
  color: var(--muted);
  max-width: 340px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#trade-dest.bad {
  color: var(--bad);
}

/* Toolbar groups (UX audit P1): mode | time | filters | view ... trading, apart on the right. */
.tb-sep {
  align-self: stretch;
  width: 1px;
  margin: 2px 0;
  background: var(--line);
}

#filter-box,
#view-box {
  gap: 10px;
}

.segmented {
  gap: 0;
}

.segmented button {
  border-radius: 0;
}

.segmented button:first-child {
  border-radius: 4px 0 0 4px;
}

.segmented button:last-child {
  border-radius: 0 4px 4px 0;
  margin-left: -1px;
}

#live-button.on {
  border-color: var(--good);
  color: var(--good);
}

#replay-button.open:not(.on) {
  color: var(--text);
}

#trading-box {
  margin-left: auto;
  gap: 6px;
  padding: 2px 4px 2px 10px;
  border-left: 2px solid rgba(255, 152, 0, 0.55);
}

/* MT5 panel tabs (UX audit P1) */
.mt5-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--line);
}

.mt5-tabs button {
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: none;
  color: var(--muted);
  padding: 4px 10px;
}

.mt5-tabs button.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.mt5-tab-note {
  font-size: 11px;
  color: var(--muted);
}

.mt5-tab-note.bad {
  color: var(--bad);
}

.mt5-msg-row:has(.mt5-msg:empty) {
  display: none;
}

.mt5-section small {
  font-weight: 400;
  color: var(--muted);
}

/* The trade bar (UX): colour is the side, the style the order type -- MKT solid, LMT
   tinted, STP dashed (like the STP line on the chart). */
#trade-qty {
  width: 48px;
}

.tb-side {
  display: inline-flex;
  gap: 2px;
}

#trade-bar .tb-side button {
  min-width: 38px;
  padding: 2px 6px;
  font-weight: 600;
  font-size: 11px;
}

#trade-bar .tb-buy.tb-mkt {
  background: #26a69a;
  border-color: #26a69a;
  color: #fff;
}

#trade-bar .tb-buy.tb-lmt {
  background: rgba(38, 166, 154, 0.18);
  border-color: #26a69a;
  color: #7fe0d6;
}

#trade-bar .tb-buy.tb-stp {
  background: none;
  border: 1px dashed #26a69a;
  color: #26a69a;
}

#trade-bar .tb-sell.tb-mkt {
  background: #ef5350;
  border-color: #ef5350;
  color: #fff;
}

#trade-bar .tb-sell.tb-lmt {
  background: rgba(239, 83, 80, 0.18);
  border-color: #ef5350;
  color: #ff9d9b;
}

#trade-bar .tb-sell.tb-stp {
  background: none;
  border: 1px dashed #ef5350;
  color: #ef5350;
}

#trade-bar button.armed {
  box-shadow: 0 0 0 2px #3d8bfd;
}

#trade-bar .tb-closeall,
.mt5-flat {
  border-color: #ffcf5c;
  color: #ffcf5c;
  font-weight: 600;
}

#trade-dest {
  display: inline-flex;
  gap: 8px;
  max-width: none;
}

#trade-dest .acct {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text);
}

#trade-dest .acct i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--good);
}

#trade-dest .acct.off i {
  background: var(--bad);
}

/* Big trade / cluster parameters folded under a summary each (UX). */
.fold {
  position: relative;
}

.fold-btn .fold-val {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.fold-btn.auto .fold-val {
  color: #ffcf5c;
}

.fold-btn.off {
  opacity: 0.55;
}

.fold-btn[aria-expanded="true"] {
  border-color: var(--accent);
}

.fold-pop {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 20;
  display: flex;
  padding: 8px 10px;
  background: rgba(17, 21, 28, 0.98);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}

.fold-pop[hidden] {
  display: none;
}

/* A paused mapping row (its symbol's orders skip the account). */
.mt5-map tr.paused input {
  opacity: 0.45;
  text-decoration: line-through;
}

.mt5-map-play {
  color: var(--good);
}

.mt5-map tr.paused .mt5-map-play {
  color: #ffcf5c;
}

/* Heatmap thresholds in the toolbar */
#hm-box input[type="range"] {
  width: 70px;
}

#hm-val {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  min-width: 64px;
}

/* The chart's own box; the DOM ladder (dom.ts) takes the right edge when on. */
.chart-plot {
  position: absolute;
  inset: 0;
}

.dom-ladder {
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
  border-left: 1px solid #2a3344;
}

/* Backtest results panel (research.ts) */
.research-panel {
  position: absolute;
  top: 6px;
  left: 60px;
  z-index: 8;
  width: 340px;
  max-width: calc(100% - 12px);
  max-height: calc(100% - 12px);
  overflow-y: auto;
  padding: 8px 10px;
  background: rgba(17, 21, 28, 0.97);
  border: 1px solid #34405a;
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45);
  font-size: 12px;
}

.research-panel select {
  width: 100%;
  margin: 4px 0;
}

.research-summary {
  margin: 4px 0 6px;
  color: var(--muted);
}

.research-row {
  display: grid;
  grid-template-columns: 90px 44px 56px 1fr;
  gap: 4px;
  cursor: pointer;
  padding: 2px 3px;
  border-radius: 3px;
}

.research-row:hover,
.research-row.on {
  background: #1b2433;
}
