:root {
  --bg: #131722;
  --panel: #1e222d;
  --panel-2: #181c25;
  --panel-3: #222633;
  --border: #2a2e39;
  --border-soft: #232733;
  --text: #d1d4dc;
  --text-strong: #f0f3fa;
  --dim: #787b86;
  --dim-2: #5d606b;
  --green: #26a69a;
  --green-soft: rgba(38, 166, 154, 0.18);
  --red: #ef5350;
  --red-soft: rgba(239, 83, 80, 0.18);
  --blue: #2962ff;
  --blue-soft: rgba(41, 98, 255, 0.18);
  --toolbar-h: 48px;
  --status-h: 24px;
  --sidebar-w: 262px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

button, select, input { font-family: inherit; }

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
}
body.split-host { overflow: hidden; }
.split-layout { display: flex; width: 100%; height: 100%; }
.split-layout iframe { flex: 1 1 0; width: 0; min-width: 0; height: 100%; border: 0; }
.split-layout iframe + iframe { border-left: 2px solid var(--border); }
.split-close { position: fixed; z-index: 100; right: 8px; bottom: 4px; border: 1px solid var(--border); background: var(--panel-3); color: var(--text); border-radius: 4px; cursor: pointer; padding: 3px 8px; }
body.split-child .toolbar { overflow-x: auto; gap: 5px; }
body.split-child .toolbar > * { flex-shrink: 0; }
body.split-child .sidebar { display: flex; width: 200px; min-width: 200px; }
body.split-child.bybit-selected .sidebar { display: flex; width: 200px; min-width: 200px; }

/* ---------------------------------- toolbar --------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--toolbar-h);
  min-height: var(--toolbar-h);
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  user-select: none;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--text-strong);
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: 14px;
  padding-right: 2px;
}
.brand svg { color: var(--blue); }

.symbol-area {
  display: flex;
  align-items: center;
  gap: 6px;
}
.symbol-search { width: 110px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 5px; padding: 5px 7px; outline: none; }
.symbol-search:focus { border-color: var(--blue); }

.select {
  appearance: none;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 5px;
  padding: 5px 24px 5px 8px;
  cursor: pointer;
  outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23787b86' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
}
.select:hover { background-color: var(--panel-3); }
.select:focus { border-color: var(--blue); }
.select option { background: var(--panel); color: var(--text); }

.symbol-select {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-strong);
  letter-spacing: 0.3px;
}
.date-select {
  font-size: 12px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
}

.last-price {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-left: 8px;
  font-variant-numeric: tabular-nums;
}
.last-price .price {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-strong);
}
.last-price .change {
  font-size: 12px;
  font-weight: 600;
  color: var(--dim);
}
.last-price .change.up { color: var(--green); }
.last-price .change.down { color: var(--red); }

.v-divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 2px;
}

.intervals {
  display: flex;
  align-items: center;
  gap: 1px;
}
.intervals button {
  background: transparent;
  border: none;
  color: #b2b5be;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s;
}
.intervals button:hover { background: var(--panel-3); color: var(--text-strong); }
.intervals button.active { background: var(--blue); color: #fff; }

.toolbar-spacer { flex: 1 1 auto; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--dim);
  cursor: pointer;
  padding: 4px 4px;
  border-radius: 4px;
  white-space: nowrap;
}
.switch:hover { color: var(--text); }
.switch input {
  accent-color: var(--blue);
  width: 14px;
  height: 14px;
  cursor: pointer;
  margin: 0;
}

.bubble-size {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--dim);
  padding-left: 6px;
  white-space: nowrap;
}
.bubble-size input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 74px;
  height: 3px;
  border-radius: 2px;
  background: #363a45;
  outline: none;
  cursor: pointer;
}
.bubble-size input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #b2b5be;
  border: none;
  cursor: pointer;
}
.bubble-size input[type="range"]::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #b2b5be;
  border: none;
  cursor: pointer;
}

.tool-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: transparent;
  color: #b2b5be;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  margin-left: 2px;
}
.tool-btn.hidden { display: none; }
.rps-setting { display: flex; align-items: center; gap: 3px; font-size: 11px; white-space: nowrap; }
.rps-setting input { width: 55px; }
.rps-status { font-size: 11px; max-width: 200px; white-space: normal; }
.tool-btn:hover { background: var(--panel-3); color: var(--text-strong); }

/* --------------------------------- workspace -------------------------------- */

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

.chart-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  background: var(--bg);
  cursor: crosshair;
}
.chart-wrap.dragging { cursor: grabbing; }

.chart-wrap canvas {
  position: absolute;
  inset: 0;
  display: block;
}
#chartOverlay { pointer-events: none; }

.legend {
  position: absolute;
  top: 8px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  color: var(--dim);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  max-width: calc(100% - 90px);
}
.legend .lg-symbol {
  color: var(--text-strong);
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.2px;
}
.legend .lg-sep { color: var(--dim-2); }
.legend .lg-item b { color: var(--text); font-weight: 500; }
.legend .lg-item.up b { color: var(--green); }
.legend .lg-item.down b { color: var(--red); }
.legend .lg-vol b { color: var(--text); }

.chart-badge {
  position: absolute;
  right: 82px;
  top: 10px;
  font-size: 11px;
  color: var(--dim);
  background: rgba(30, 34, 45, 0.7);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  opacity: 0;
  transition: opacity 0.15s;
}
.chart-badge.show { opacity: 1; }

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

.tooltip {
  position: absolute;
  z-index: 8;
  min-width: 178px;
  max-width: 260px;
  background: rgba(24, 28, 37, 0.97);
  border: 1px solid #363a45;
  border-radius: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  padding: 8px 10px;
  font-size: 11.5px;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(6px);
}
.tooltip.hidden { display: none; }
.tooltip .tt-head {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--dim);
  margin-bottom: 6px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.tooltip .tt-head b { color: var(--text); font-weight: 600; }
.tooltip .tt-row {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  line-height: 18px;
}
.tooltip .tt-row span { color: var(--dim); }
.tooltip .tt-row b { color: var(--text-strong); font-weight: 500; }
.tooltip .tt-row b.buy { color: var(--green); }
.tooltip .tt-row b.sell { color: var(--red); }
.tooltip .tt-foot {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--border);
  color: var(--dim);
  font-size: 10.5px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex: none;
}
.dot.buy { background: var(--green); }
.dot.sell { background: var(--red); }

/* ---------------------------------- sidebar --------------------------------- */

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--panel-2);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { background: #363a45; border-radius: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.panel {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.panel.grow { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 120px; }
.panel.hidden { display: none; }
.book-setting { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 8px; color: var(--dim); font-size: 11px; }
.book-setting input[type="number"] { width: 85px; background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 4px; padding: 4px; }
.book-setting input[type="checkbox"] { accent-color: var(--blue); }
.panel .loader-retry { margin-top: 0; }
.panel .loader-retry:disabled { opacity: .5; cursor: default; }

.panel-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--dim);
  margin-bottom: 10px;
}
.panel-sub {
  font-size: 10px;
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0.2px;
  color: var(--dim-2);
}

.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
  margin-bottom: 10px;
}
.stat-grid > div {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.stat-grid span { font-size: 10.5px; color: var(--dim); }
.stat-grid b {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
}
.stat-grid b.buy { color: var(--green); }
.stat-grid b.sell { color: var(--red); }

.ratio-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--dim);
  margin-bottom: 4px;
}
.ratio-labels b { font-weight: 600; }
.ratio-labels .buy b { color: var(--green); }
.ratio-labels .sell b { color: var(--red); }

.ratio-bar {
  height: 5px;
  border-radius: 3px;
  background: var(--red-soft);
  overflow: hidden;
}
.ratio-buy {
  height: 100%;
  width: 50%;
  background: var(--green);
  border-radius: 3px 0 0 3px;
  transition: width 0.25s ease;
}

.hint {
  font-size: 10.5px;
  color: var(--dim-2);
  margin-top: 2px;
  line-height: 1.4;
}

.read-legend {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 11px;
  color: var(--dim);
}
.read-row {
  display: flex;
  align-items: center;
  gap: 7px;
}
.read-row.muted {
  color: var(--dim-2);
  padding-left: 1px;
}

.top-trades {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow-y: auto;
  min-height: 0;
}
.top-trades::-webkit-scrollbar { width: 6px; }
.top-trades::-webkit-scrollbar-thumb { background: #363a45; border-radius: 3px; }

.trade-row {
  display: grid;
  grid-template-columns: 8px 52px 1fr auto;
  align-items: center;
  gap: 7px;
  width: 100%;
  padding: 5px 6px;
  background: transparent;
  border: none;
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  cursor: pointer;
  text-align: left;
}
.trade-row:hover { background: var(--panel-3); }
.trade-row .tr-time { color: var(--dim); }
.trade-row .tr-price { color: var(--text); text-align: right; }
.trade-row .tr-value { color: var(--text-strong); font-weight: 600; text-align: right; }
.trade-row .tr-value.buy { color: var(--green); }
.trade-row .tr-value.sell { color: var(--red); }

/* ---------------------------------- loader ---------------------------------- */

.loader {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(19, 23, 34, 0.72);
  backdrop-filter: blur(3px);
}
.loader.hidden { display: none; }

.loader-card {
  width: 340px;
  max-width: calc(100% - 40px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}
.loader-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-strong);
  margin-bottom: 4px;
}
.loader-sub {
  font-size: 12px;
  color: var(--dim);
  margin-bottom: 12px;
  font-variant-numeric: tabular-nums;
}
.progress {
  height: 4px;
  border-radius: 2px;
  background: #2a2e39;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--blue);
  border-radius: 2px;
  transition: width 0.18s ease;
}
.loader-meta {
  margin-top: 9px;
  font-size: 11px;
  color: var(--dim-2);
  font-variant-numeric: tabular-nums;
  min-height: 14px;
}
.loader-retry {
  margin-top: 14px;
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 5px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.loader-retry:hover { filter: brightness(1.1); }
.loader-retry.hidden { display: none; }

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

.ind-btn {
  font-weight: 600;
  font-style: italic;
  font-size: 13px;
  letter-spacing: 0.2px;
}

.ind-legend {
  position: absolute;
  top: 27px;
  left: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
  color: var(--dim);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  max-width: calc(100% - 90px);
}
.ind-legend.hidden { display: none; }
.ind-legend .ind-item { display: inline-flex; align-items: center; gap: 5px; }
.ind-legend .ind-item i {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 2px;
}
.ind-legend .ind-item b { color: var(--text); font-weight: 500; }
.ind-legend .ind-err { color: var(--red); }

/* ---------------------------------- modal ----------------------------------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(9, 11, 16, 0.66);
  backdrop-filter: blur(2px);
}
.modal.hidden { display: none; }

.modal-card {
  width: min(940px, 100%);
  max-height: min(680px, 92vh);
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-2);
}
.modal-head h2 { margin: 0; font-size: 15px; font-weight: 600; color: var(--text-strong); }
.modal-sub { margin-top: 3px; font-size: 11.5px; color: var(--dim); }
.modal-close {
  background: transparent;
  border: none;
  color: var(--dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 2px;
}
.modal-close:hover { color: var(--text-strong); }

.ind-body {
  display: grid;
  grid-template-columns: 236px 1fr;
  min-height: 0;
  flex: 1 1 auto;
}

.ind-list {
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 8px;
  background: var(--panel-2);
}

.ind-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 12.5px;
  color: var(--text);
  border: 1px solid transparent;
}
.ind-row:hover { background: var(--panel-3); }
.ind-row.active { background: var(--blue-soft); border-color: rgba(41, 98, 255, 0.5); }
.ind-row.error .ind-row-name { color: var(--red); }
.ind-row-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ind-pane-tag {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--dim-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 1px 4px;
}
.ind-toggle { accent-color: var(--blue); cursor: pointer; }

.ind-editor {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 12px 14px 14px;
  gap: 10px;
}

.ind-fields { display: flex; gap: 10px; }
.ind-field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 auto; }
.ind-field > span {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--dim);
}
.ind-field input,
.ind-field select,
.ind-field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 6px 8px;
  font-size: 12.5px;
  outline: none;
}
.ind-field input:focus,
.ind-field select:focus,
.ind-field textarea:focus { border-color: var(--blue); }
.ind-field textarea {
  flex: 1 1 auto;
  min-height: 220px;
  resize: vertical;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  white-space: pre;
  tab-size: 2;
}
.ind-code-field { flex: 1 1 auto; min-height: 0; }

.ind-help {
  font-size: 11px;
  line-height: 1.6;
  color: var(--dim);
}
.ind-help code {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 0 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 10.5px;
}

.ind-error { min-height: 15px; font-size: 11.5px; color: var(--red); }
.ind-error.ok { color: var(--green); }

.ind-actions { display: flex; align-items: center; gap: 8px; }
.ind-actions button {
  background: var(--panel-3);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
}
.ind-actions button:hover { filter: brightness(1.15); }
.ind-actions button.primary { background: var(--blue); border-color: var(--blue); color: #fff; font-weight: 600; }
.ind-actions button:disabled { opacity: 0.45; cursor: default; filter: none; }
.ind-spacer { flex: 1 1 auto; }

@media (max-width: 760px) {
  .ind-body { grid-template-columns: 1fr; }
  .ind-list { max-height: 150px; border-right: none; border-bottom: 1px solid var(--border); }
}

/* ---------------------------------- empty ----------------------------------- */

.empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 30px;
  color: var(--dim);
  background: var(--bg);
  z-index: 9;
}
.empty.hidden { display: none; }
.empty-icon {
  font-size: 40px;
  color: var(--border);
  margin-bottom: 10px;
  line-height: 1;
}
.empty h2 { color: var(--text); font-size: 18px; margin: 0 0 12px; font-weight: 600; }
.empty p { margin: 4px 0; font-size: 12.5px; max-width: 460px; line-height: 1.5; }
.empty code, .empty pre {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 11.5px;
}
.empty pre { padding: 8px 14px; margin: 8px 0; }

/* --------------------------------- statusbar -------------------------------- */

.statusbar {
  display: flex;
  align-items: center;
  gap: 16px;
  height: var(--status-h);
  min-height: var(--status-h);
  padding: 0 12px;
  background: var(--panel);
  border-top: 1px solid var(--border);
  font-size: 10.5px;
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
}
#statusLeft { overflow: hidden; text-overflow: ellipsis; }
#statusCenter { flex: 1 1 auto; text-align: center; overflow: hidden; text-overflow: ellipsis; }
#statusRight { flex: none; }

@media (max-width: 1180px) {
  .bubble-size span { display: none; }
  .bubble-size input[type="range"] { width: 56px; }
  .last-price .change { display: none; }
}

@media (max-width: 1020px) {
  .sidebar { display: none; }
  .bybit-selected .sidebar { display: flex; }
  .switch span { display: none; }
}

@media (max-width: 820px) {
  .brand span { display: none; }
  .intervals button { padding: 5px 6px; }
}
