/* Shared styles for /lab and /live. */
:root {
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  font: 13px/1.4 -apple-system, system-ui, sans-serif;
  background: #0e1116;
  color: #c9d1d9;
}

#stage {
  flex: 1 1 0%;
  min-height: 0;
  overflow: hidden;
}

/* header / controls */
header {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  background: #161b22;
  border-bottom: 1px solid #21262d;
  flex-wrap: wrap;
}

input,
select,
button {
  background: #0e1116;
  color: #c9d1d9;
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 5px 8px;
  font: inherit;
}

button {
  cursor: pointer;
}

button.primary {
  background: #238636;
  border-color: #238636;
  color: #fff;
}

button.primary:hover {
  background: #2ea043;
}

button.danger {
  background: #da3633;
  border-color: #da3633;
  color: #fff;
}

a.link {
  color: #58a6ff;
  text-decoration: none;
  padding: 5px 8px;
}

/* borderless little arrow that copies times between chart and config */
button.arrow-btn {
  background: none;
  border: none;
  color: #fff;
  padding: 0 4px;
  font-size: 13px;
  line-height: 1;
}

button.arrow-btn:hover {
  color: #58a6ff;
}

#meta {
  margin-left: auto;
  color: #8b949e;
  font-variant-numeric: tabular-nums;
}

.pill {
  padding: 2px 6px;
  border-radius: 10px;
  background: #21262d;
}

.bull {
  color: #26a69a;
}

.bear {
  color: #ef5350;
}

.neutral {
  color: #8b949e;
}

/* chart + volume-profile overlay */
#chart {
  flex: 1 1 0%;
  min-height: 0;
}

canvas.vp {
  position: fixed;
  pointer-events: none;
  z-index: 50;
}

/* /lab time cursor: a draggable vertical line; wide transparent hit area, 1px visible center */
#lab-cursor {
  position: fixed;
  display: none;
  width: 9px;
  margin-left: -4px;
  z-index: 55;
  cursor: ew-resize;
  pointer-events: auto;
}

#lab-cursor::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 0;
  bottom: 0;
  width: 5px;
  background: rgba(88, 166, 255, 0.3);
}

/* floating panel: reusable runtime-info window, draggable + vertically resizable, shown via a
   header toggle button. Used by the readout panel and the live metrics panel. */
.floater {
  position: fixed;
  top: 58px;
  left: 14px;
  z-index: 60;
  width: 282px;
  height: 220px;
  min-width: 180px;
  min-height: 56px;
  max-height: 70vh;
  overflow: hidden;
  resize: both;
  display: flex;
  flex-direction: column;
  background: rgba(22, 27, 34, 0.92);
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  font-variant-numeric: tabular-nums;
}

.floater-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: move;
  user-select: none;
  color: #6e7681;
  font-weight: 600;
  letter-spacing: 0.04em;
  padding-bottom: 6px;
  margin-bottom: 4px;
  border-bottom: 1px solid #30363d;
  text-transform: capitalize;
}

.floater-close {
  cursor: pointer;
  background: none;
  border: none;
  color: #6e7681;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
}

.floater-close:hover {
  color: #c9d1d9;
}

.floater-body {
  flex: 1 1 auto;
  overflow: auto;
}

/* show/hide toggle buttons injected into the tagged leaf header (right-aligned) */
.floater-buttons {
  margin-left: auto;
  display: flex;
  gap: 4px;
}

.floater-toggle {
  color: #8b949e;
  border: 1px solid transparent;
  border-radius: 6px 6px 0 0;
  font-size: 12px;
  padding: 4px 12px;
  text-transform: capitalize;
}

.floater-toggle[aria-pressed="true"] {
  color: #c9d1d9;
  background: #0e1116;
  border-color: #21262d;
}

/* readout content (rendered by readoutPanelHtml) inside any floater body */
.floater .rd-group {
  margin: 6px 0;
}

.floater .rd-head {
  color: #8b949e;
  font-weight: 600;
  margin: 4px 0 2px;
}

.floater .rd-group .rd-row {
  padding-left: 8px;
}

.floater .rd-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 1px 0;
  flex-wrap: nowrap;
}

.floater .rd-k {
  color: #8b949e;
  flex-shrink: 0;
  white-space: nowrap;
}

.floater .rd-v {
  color: #c9d1d9;
  text-align: right;
  min-width: 0;
  flex: 1;
}

/* metrics panel — dot-prefix sections (cache, infer, lab, …) */
.metric-section {
  margin-bottom: 10px;
}

.metric-section:last-child {
  margin-bottom: 0;
}

.metric-section-title {
  font-size: 11px;
  font-weight: 600;
  color: #58a6ff;
  margin-bottom: 4px;
}

.metric-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 11px;
  line-height: 1.45;
}

.metric-k {
  color: #8b949e;
  min-width: 0;
}

.metric-v {
  color: #c9d1d9;
  text-align: right;
  flex-shrink: 0;
}

.metric-empty {
  color: #6e7681;
  font-size: 11px;
}

/* legacy grid (unused by metricsPanel; kept for any older callers) */
.metric-gauge {
  position: relative;
  height: 18px;
  border-radius: 4px;
  background: #0e1116;
  border: 1px solid #30363d;
  overflow: hidden;
  margin-bottom: 8px;
}

.metric-gauge-fill {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  border-radius: 3px 0 0 3px;
  transition: width 0.3s ease, background 0.3s ease;
}

.metric-gauge-text {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 600;
  color: #c9d1d9;
  text-shadow: 0 0 3px rgba(0, 0, 0, 0.7);
}

.metric-grid {
  display: grid;
  grid-template-columns: 1fr repeat(4, max-content);
  column-gap: 12px;
  row-gap: 2px;
  align-items: baseline;
}

.metric-grid>div {
  color: #c9d1d9;
}

.metric-grid>.metric-th {
  color: #6e7681;
  font-size: 11px;
  font-weight: 600;
}

.metric-grid>.metric-sym {
  color: #8b949e;
  justify-self: start;
}

.metric-grid>.metric-num {
  justify-self: end;
}

/* progress box (/lab) */
#progress {
  position: fixed;
  right: 14px;
  bottom: 14px;
  width: 320px;
  max-height: 40vh;
  overflow: hidden;
  background: rgba(22, 27, 34, 0.96);
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.4);
  display: none;
  z-index: 9999;
  pointer-events: none;
}

#progress.show {
  display: block;
}

#progress .title {
  font-weight: 600;
  margin-bottom: 6px;
  color: #c9d1d9;
}

#progress .bar {
  height: 4px;
  background: #21262d;
  border-radius: 3px;
  overflow: hidden;
  margin: 6px 0;
}

#progress .bar>i {
  display: block;
  height: 100%;
  width: 0;
  background: #2ea043;
  transition: width .2s;
}

#progress .log {
  color: #8b949e;
  max-height: 26vh;
  overflow-y: auto;
  white-space: pre-wrap;
  line-height: 1.5;
}

/* right-side bar (used by PropertyPane) */
.bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid #21262d;
  background: #161b22;
}

#arm {
  font-weight: 700;
}

#arm.armed {
  background: #da3633;
  border-color: #da3633;
  color: #fff;
}

#tstatus {
  color: #8b949e;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 8px 12px 0;
}

.tabs button {
  color: #8b949e;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
}

.tabs button.active {
  color: #c9d1d9;
  background: #161b22;
}

.pane {
  flex: 1;
  overflow: auto;
  padding: 10px 12px;
}

#pane-orders:not(.hidden) {
  display: flex;
  flex-direction: column;
}

.hidden {
  display: none;
}

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

th,
td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid #21262d;
  white-space: nowrap;
}

th {
  color: #8b949e;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 1;
  background: #0e1116;
  box-shadow: 0 1px 0 #21262d;
}

.st-NEW,
.st-PARTIALLY_FILLED {
  color: #58a6ff;
}

.st-FILLED {
  color: #26a69a;
}

.st-CANCELED,
.st-EXPIRED,
.st-REJECTED {
  color: #8b949e;
}

.otime {
  color: #6e7681;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

#orders tr,
#runners tr {
  cursor: pointer;
}

.orders-scroll {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
}

.lab {
  border: 1px solid #21262d;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: #161b22;
}

.lab h3 {
  margin: 0 0 6px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.lab .sec {
  margin: 6px 0;
}

.lab .sec b {
  color: #8b949e;
  font-weight: 600;
}

.kv {
  color: #c9d1d9;
  font-variant-numeric: tabular-nums;
}

.muted {
  color: #6e7681;
}

/* editable lab config pane (ConfigGraph) — label-on-top flex grid */
.cfg {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.cfg-bar {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid #21262d;
}

.cfg-bar select {
  flex: 1;
}

.cfg-bar button {
  padding: 4px 9px;
}

#cfg-body {
  flex: 1;
  overflow-y: auto;
  padding: 2px 12px 12px;
}

.cfg-group {
  border-top: 1px solid #21262d;
  padding-top: 12px;
  margin-top: 14px;
}

.cfg-group h4 {
  color: #8b949e;
  font-weight: 700;
  font-size: 13px;
  margin: 0 0 10px;
  letter-spacing: 0.2px;
  text-transform: capitalize;
}

.cfg-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
}

.cfg-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1 1 110px;
  min-width: 96px;
}

.cfg-field label {
  color: #6e7681;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-transform: capitalize;
}

.cfg-field input,
.cfg-field select {
  width: 100%;
  font-variant-numeric: tabular-nums;
}

.cfg-field input:disabled,
.cfg-field select:disabled {
  opacity: 0.55;
}

.cfg-field .finder {
  width: 100%;
}

.cfg-field.cfg-bool {
  justify-content: flex-end;
}

.cfg-field.cfg-bool input {
  width: auto;
  align-self: flex-start;
  height: 18px;
}

.cfg-range-now {
  align-self: flex-end;
  flex: 0 0 auto;
  margin-bottom: 1px;
}

/* Array item row: field + remove button */
.cfg-array-item {
  display: flex;
  align-items: flex-end;
  gap: 4px;
}

.cfg-array-item .cfg-field {
  flex: 1;
  min-width: 80px;
}

/* Remove button: subtle ×, red on hover */
.cfg-remove-item {
  background: none;
  border: 1px solid #30363d;
  color: #8b949e;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 6px;
  flex-shrink: 0;
  margin-bottom: 1px;
}

.cfg-remove-item:hover {
  color: #f85149;
  border-color: #f85149;
}

/* Add button: green inline button in group header */
.cfg-add-item {
  background: none;
  border: 1px solid #30363d;
  color: #7ee787;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 400;
  padding: 1px 7px;
  margin-left: 8px;
  vertical-align: middle;
}

.cfg-add-item:hover {
  background: #1a3a2a;
  border-color: #3fb950;
}

.cfg-foot {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-top: 1px solid #21262d;
}

/* calibration pane (readout of the set's calibration.json) */
.cal-pane {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.cal-status {
  flex: 0 0 auto;
  padding: 6px 12px;
  border-bottom: 1px solid #21262d;
  font-variant-numeric: tabular-nums;
}

.cal-body {
  flex: 1 1 0%;
  overflow: auto;
  padding: 8px 12px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.cal-body .rd-group {
  margin: 6px 0;
}

.cal-body .rd-head {
  color: #8b949e;
  font-weight: 600;
  margin: 4px 0 2px;
}

.cal-body .rd-group .rd-row {
  padding-left: 8px;
}

.cal-body .rd-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
  padding: 1px 0;
  flex-wrap: nowrap;
}

.cal-body .rd-k {
  color: #8b949e;
  flex-shrink: 0;
  white-space: nowrap;
}

.cal-body .rd-v {
  color: #c9d1d9;
  text-align: right;
  min-width: 0;
  flex: 1;
}

/* symbol quick-find dropdown */
.finder {
  position: relative;
}

.finder .menu {
  position: absolute;
  top: 110%;
  left: 0;
  min-width: 160px;
  max-height: 240px;
  overflow-y: auto;
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 6px;
  z-index: 100;
  display: none;
}

.finder .menu.show {
  display: block;
}

.finder .menu div {
  padding: 5px 10px;
  cursor: pointer;
}

.finder .menu div.sel,
.finder .menu div:hover {
  background: #21262d;
}


/* ---- declarative layout system ---- */
/* toolbar */
.layout-toolbar {
  display: flex;
  gap: 4px;
  padding: 4px 8px;
  background: #161b22;
  border-bottom: 1px solid #21262d;
}

.layout-toggle {
  font-size: 11px;
  padding: 3px 10px;
}

.layout-toggle[aria-pressed="true"] {
  background: #238636;
  border-color: #238636;
  color: #fff;
}

/* flex containers */
.layout-hbox {
  display: flex;
  flex-direction: row;
  height: 100%;
}

.layout-vbox {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.layout-panel {
  flex: 1 1 0%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}

/* split resize grips */
.layout-split-grip {
  flex: 0 0 auto;
  z-index: 30;
}

.layout-split-grip--ew {
  width: 5px;
  cursor: col-resize;
  background: #21262d;
}

.layout-split-grip--ew:hover,
.layout-split-grip--ew:active {
  background: #58a6ff;
}

.layout-split-grip--ns {
  height: 5px;
  cursor: row-resize;
  background: #21262d;
}

.layout-split-grip--ns:hover,
.layout-split-grip--ns:active {
  background: #58a6ff;
}

/* leaf (tabbed container) */
.layout-leaf {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* arm-bar leaf: content-sized, not an even vbox split. !important beats the inline
   flex the layout manager sets on every panel. */
.layout-panel:has(> .layout-tag-host--armbar) {
  flex: 0 0 auto !important;
}

.layout-tag-host--armbar {
  height: auto;
}

.layout-leaf-header {
  flex: 0 0 auto;
  display: flex;
  gap: 4px;
  padding: 4px 8px 0;
  background: #161b22;
  border-bottom: 1px solid #21262d;
}

.layout-leaf-toggle {
  color: #8b949e;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  font-size: 12px;
  padding: 4px 12px;
}

.layout-leaf-toggle[aria-pressed="true"] {
  color: #c9d1d9;
  background: #0e1116;
  border-color: #21262d;
}

.layout-leaf-body {
  flex: 1 1 0%;
  min-height: 0;
  position: relative;
}

.layout-leaf-pane-mount {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.layout-leaf-pane-mount[hidden] {
  display: none !important;
}

.layout-leaf-pane-mount:not([hidden]) {
  display: flex;
  flex-direction: column;
}

/* hover tooltip on chart */
.chart-tooltip {
  position: absolute;
  z-index: 50;
  pointer-events: none;
  background: rgba(13, 17, 23, 0.92);
  border: 1px solid #30363d;
  border-radius: 6px;
  padding: 6px 10px;
  font: 11px/1.45 -apple-system, system-ui, sans-serif;
  color: #c9d1d9;
  min-width: 180px;
  max-width: 240px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
}

.chart-tooltip .tip-time {
  color: #8b949e;
  font-size: 10px;
  margin-bottom: 3px;
}

.chart-tooltip .tip-ohlcv {
  font-variant-numeric: tabular-nums;
  margin-bottom: 1px;
}

.chart-tooltip .tip-vol {
  color: #8b949e;
  margin-bottom: 2px;
}

.chart-tooltip .tip-sig {
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px solid #21262d;
  font-weight: 600;
}

.chart-tooltip .tip-sig.buy {
  color: #26a69a;
}

.chart-tooltip .tip-sig.sell {
  color: #ef5350;
}

.chart-tooltip .tip-order {
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px solid #21262d;
  font-variant-numeric: tabular-nums;
}

.chart-tooltip .tip-order.buy {
  color: #26a69a;
}

.chart-tooltip .tip-order.sell {
  color: #ef5350;
}

.chart-tooltip .tip-pat {
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px solid #21262d;
  color: #a5d6ff;
}

.chart-tooltip .tip-ind {
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px solid #21262d;
  color: #58a6ff;
}

.chart-tooltip .tip-pane {
  margin-top: 3px;
  padding-top: 3px;
  border-top: 1px solid #21262d;
  color: #8b949e;
}

/* shared log panel (used by lib/log.js) */
.log-wrap {
  flex: 1 1 0%;
  min-height: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-top: 1px solid #21262d;
  background: #0b0e13;
  padding: 6px 10px;
  font: 11px/1.45 ui-monospace, Menlo, monospace;
  white-space: pre-wrap;
  position: relative;
}

.log-wrap .hdr {
  color: #6e7681;
  position: sticky;
  top: 0;
  background: #0b0e13;
  padding-bottom: 2px;
}

.log-wrap .lg-info {
  color: #8b949e;
}

.log-wrap .lg-warn {
  color: #e3b341;
}

.log-wrap .lg-error {
  color: #f85149;
}

.log-wrap .log-body {
  flex: 1 1 0%;
  min-height: 0;
  overflow-y: auto;
}

.log-wrap .log-follow {
  position: absolute;
  right: 16px;
  bottom: 12px;
  z-index: 40;
  cursor: pointer;
  background: #238636;
  border: 1px solid #2ea043;
  color: #fff;
  border-radius: 14px;
  padding: 4px 12px;
  font: 11px ui-monospace, Menlo, monospace;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}

.log-wrap .log-follow:hover {
  background: #2ea043;
}

/* ── prompt modal ── */
.pr-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(2px);
}

.pr-card {
  background: #161b22;
  border: 1px solid #30363d;
  border-radius: 8px;
  padding: 20px 24px;
  min-width: 300px;
  max-width: 420px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.pr-text {
  color: #c9d1d9;
  font-size: 13px;
  margin: 0 0 16px;
  line-height: 1.5;
}

.pr-input {
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 16px;
  padding: 6px 10px;
  font-size: 13px;
  color: #c9d1d9;
  background: #0d1117;
  border: 1px solid #30363d;
  border-radius: 6px;
}

.pr-input:focus {
  outline: none;
  border-color: #1f6feb;
}

.pr-btns {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

.pr-btns button {
  font-size: 12px;
  padding: 6px 14px;
}

.pr-btns button.danger {
  background: #da3633;
  border-color: #da3633;
  color: #fff;
}

.pr-btns button.danger:hover {
  background: #f85149;
}

/* ── calibrated (locked) config field ── */
.cfg-calibrated {
  position: relative;
}

.cfg-calibrated::after {
  content: "⚙";
  position: absolute;
  right: 4px;
  top: 18px;
  font-size: 10px;
  color: #6e7681;
  pointer-events: none;
}

.cfg-calibrated input:disabled,
.cfg-calibrated select:disabled,
.cfg-calibrated input[readonly] {
  color: #6e7681;
  cursor: pointer;
}