:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #181c20;
  --panel-2: #20262c;
  --text: #edf1f5;
  --muted: #8f9aa6;
  --line: #303941;
  --green: #22b573;
  --red: #e05b5b;
  --accent: #4aa8ff;
  --amber: #f4b942;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, Segoe UI, Arial, sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 12px;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: var(--accent);
}

button.is-loading {
  position: relative;
  opacity: 0.78;
  pointer-events: none;
}

button.is-loading::before {
  content: "";
  display: inline-block;
  width: 12px;
  height: 12px;
  margin-right: 7px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 999px;
  vertical-align: -2px;
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

button.primary {
  border-color: #2e8f64;
  background: var(--green);
  color: #06140e;
  font-weight: 700;
}

button.danger {
  border-color: #8f3737;
  color: #ffd8d8;
}

button.active {
  border-color: var(--accent);
  background: #17324a;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #0f1316;
  color: var(--text);
}

textarea {
  resize: vertical;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}

.app {
  display: grid;
  gap: 16px;
  max-width: 100vw;
  overflow-x: hidden;
  padding: 16px;
}

.topbar,
.market-toolbar,
.workspace,
.trade-row,
.automation,
.tables,
.panel-head,
.chart-head,
.token-form,
.grid {
  display: grid;
  gap: 12px;
}

.topbar {
  grid-template-columns: 1fr minmax(360px, 520px) minmax(260px, 430px);
  align-items: center;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 26px;
}

h2 {
  font-size: 16px;
}

h3 {
  margin: 0;
  font-size: 14px;
}

.muted,
#health {
  color: var(--muted);
}

.token-form {
  grid-template-columns: 1fr auto auto;
}

.token-form:has(#tokenInput[hidden]) {
  grid-template-columns: auto auto;
  justify-content: end;
}

.market-kind {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  margin-right: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.param-title {
  color: var(--muted);
  font-weight: 700;
}

.market-toolbar {
  grid-template-columns: 170px minmax(160px, 1fr);
  align-items: end;
}

.market-picker {
  position: relative;
}

.symbol-picker-button {
  display: flex;
  justify-content: space-between;
  width: 100%;
  min-height: 42px;
  text-align: left;
}

.symbol-picker-button::after {
  content: "▾";
  color: var(--muted);
}

.symbol-picker-panel {
  position: absolute;
  z-index: 20;
  top: calc(100% + 6px);
  left: 0;
  width: min(360px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: #101419;
  box-shadow: 0 16px 42px rgba(0, 0, 0, 0.42);
}

.symbol-picker-panel input {
  width: 100%;
  margin-bottom: 8px;
}

.symbol-picker-list {
  display: grid;
  gap: 2px;
  max-height: 320px;
  overflow: auto;
}

.symbol-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 8px;
  align-items: center;
  border: 0;
  border-radius: 6px;
  padding: 7px 8px;
  background: transparent;
  color: var(--text);
}

.symbol-row:hover,
.symbol-row.active {
  background: var(--panel-2);
}

.symbol-star {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 17px;
}

.symbol-star.active {
  color: #f0c45d;
}

.plain-symbol {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 800;
}

.symbol-row .muted {
  font-size: 12px;
}

.market-strip {
  display: flex;
  gap: 8px;
  max-width: 100%;
  overflow-x: auto;
  padding-bottom: 2px;
}

.strategy-pair-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.strategy-pair {
  display: grid;
  gap: 3px;
  position: relative;
  min-width: 128px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px 34px 8px 10px;
  background: #11161a;
  color: var(--text);
  text-align: left;
}

.strategy-pair.active {
  border-color: var(--accent);
  background: #12314a;
}

.strategy-pair span {
  color: var(--muted);
  font-size: 11px;
}

.strategy-pair em {
  position: absolute;
  top: 8px;
  right: 10px;
  color: #48ff73;
  font-style: normal;
  font-size: 12px;
  line-height: 1;
}

.empty-strip {
  border: 1px dashed var(--line);
  border-radius: 7px;
  padding: 12px;
  color: var(--muted);
}

.ticker {
  position: relative;
  min-width: 130px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel);
  overflow: hidden;
}

.ticker.active {
  border-color: var(--accent);
}

.ticker-main {
  width: 100%;
  min-height: 56px;
  border: 0;
  padding: 9px 28px 9px 10px;
  background: transparent;
  text-align: center;
  cursor: pointer;
}

.ticker-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 22px;
  height: 22px;
  min-height: 0;
  border: 0;
  border-radius: 50%;
  padding: 0;
  background: rgba(74, 168, 255, 0.16);
  color: var(--amber);
  font-size: 13px;
  line-height: 1;
  opacity: 0;
}

.ticker:hover .ticker-remove,
.ticker:focus-within .ticker-remove {
  opacity: 1;
}

.ticker-remove:hover {
  background: rgba(224, 91, 91, 0.22);
  color: #ff858d;
}

.ticker strong,
.ticker span {
  display: block;
}

.ticker span {
  color: var(--muted);
  font-size: 12px;
}

.up {
  color: var(--green);
}

.down {
  color: var(--red);
}

.workspace {
  grid-template-columns: 1fr;
  align-items: stretch;
}

.trade-row {
  grid-template-columns: minmax(420px, 1fr) minmax(420px, 1fr);
  align-items: stretch;
}

.market-depth,
.automation {
  grid-template-columns: minmax(0, 1fr) minmax(360px, 0.75fr);
}

.tables {
  grid-template-columns: minmax(520px, 1.35fr) minmax(360px, 0.9fr);
  align-items: start;
}

.chart-panel,
.order-panel,
.table-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.chart-panel {
  min-height: 540px;
  padding: 14px;
}

.chart-head,
.panel-head {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px;
}

.segmented button {
  border: 0;
  padding: 6px 10px;
  background: transparent;
}

.segmented .active {
  background: var(--panel-2);
}

#chartCanvas {
  width: 100%;
  height: 520px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0b0f12;
}

.chart-wrap {
  position: relative;
  margin-top: 14px;
}

.indicator-legend {
  position: absolute;
  z-index: 2;
  top: 12px;
  left: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-width: calc(100% - 260px);
}

.chart-info {
  position: absolute;
  z-index: 2;
  top: 12px;
  right: 12px;
  display: grid;
  gap: 3px;
  min-width: 170px;
  border: 1px solid rgba(74, 168, 255, 0.25);
  border-radius: 7px;
  padding: 6px 8px;
  background: rgba(11, 15, 18, 0.46);
  backdrop-filter: blur(2px);
  color: var(--text);
  text-align: right;
  cursor: move;
  pointer-events: auto;
  user-select: none;
  opacity: 0.82;
  touch-action: none;
}

.chart-info strong {
  font-size: 14px;
}

.chart-info span {
  font-size: 11px;
  color: var(--muted);
}

.chart-info.buy {
  border-color: rgba(34, 181, 115, 0.36);
}

.chart-info.buy span,
.chart-info.buy strong {
  color: #2ee58c;
}

.chart-info.sell {
  border-color: rgba(224, 91, 91, 0.36);
}

.chart-info.sell span,
.chart-info.sell strong {
  color: #ff7777;
}

.chart-strategies {
  position: absolute;
  z-index: 2;
  right: 12px;
  bottom: 18px;
  display: grid;
  gap: 6px;
  width: min(310px, calc(100% - 28px));
  pointer-events: none;
}

.chart-strategy-chip {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 8px;
  align-items: center;
  border: 1px solid rgba(74, 168, 255, 0.24);
  border-radius: 7px;
  padding: 6px 8px;
  background: rgba(11, 15, 18, 0.48);
  color: var(--muted);
  font-size: 11px;
}

.chart-strategy-chip strong {
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chart-strategy-chip span:not(:last-child) {
  display: none;
}

.chart-hover-tooltip {
  position: absolute;
  z-index: 4;
  min-width: 210px;
  max-width: 280px;
  border: 1px solid rgba(74, 168, 255, 0.34);
  border-radius: 7px;
  padding: 8px 9px;
  background: rgba(8, 12, 15, 0.88);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
  color: var(--text);
  font-size: 11px;
  pointer-events: none;
}

.chart-hover-tooltip strong {
  display: block;
  margin-bottom: 6px;
  color: #fff;
  font-size: 12px;
}

.chart-hover-tooltip div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  line-height: 1.45;
}

.chart-hover-tooltip span {
  color: var(--muted);
}

.chart-hover-tooltip b {
  color: #bfe4ff;
  font-weight: 700;
}

.legend-button {
  border: 0;
  padding: 3px 6px;
  background: rgba(11, 15, 18, 0.74);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.legend-button.disabled {
  color: var(--muted);
  text-decoration: line-through;
}

.order-panel,
.table-panel {
  padding: 14px;
}

.stack,
.strategy-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
}

.check-row input {
  width: auto;
}

.grid.two {
  grid-template-columns: 1fr 1fr;
}

.grid.three {
  grid-template-columns: repeat(3, 1fr);
}

.response-box {
  margin: 14px 0 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0d1013;
}

.response-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.response-head button {
  min-height: 28px;
  padding: 4px 8px;
  font-size: 12px;
}

.response {
  max-height: 180px;
  margin: 0;
  overflow: auto;
  padding: 10px;
  color: #cfe2f3;
  white-space: pre-wrap;
}

.app-toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 1000;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 14px;
  border: 1px solid rgba(35, 187, 111, 0.6);
  border-radius: 8px;
  background: rgba(13, 20, 18, 0.94);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  color: var(--green);
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.app-toast.visible {
  opacity: 1;
  transform: translateY(0);
}

.app-toast[data-type="error"] {
  border-color: rgba(255, 91, 91, 0.65);
  color: var(--red);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.loading-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.loading-line::before {
  content: "";
  width: 14px;
  height: 14px;
  border: 2px solid var(--accent);
  border-top-color: transparent;
  border-radius: 999px;
  animation: spin 0.75s linear infinite;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
}

.side-switch,
.percent-scale {
  display: grid;
  gap: 6px;
}

.side-switch {
  grid-template-columns: 1fr 1fr;
}

.side-switch button {
  border-color: var(--line);
  background: #11161a;
}

.side-switch button.active[data-order-side="Buy"] {
  border-color: rgba(34, 181, 115, 0.65);
  background: rgba(34, 181, 115, 0.2);
  color: #2ee58c;
}

.side-switch button.active[data-order-side="Sell"] {
  border-color: rgba(224, 91, 91, 0.65);
  background: rgba(224, 91, 91, 0.18);
  color: #ff7777;
}

.percent-scale {
  grid-template-columns: repeat(4, 1fr);
}

.percent-scale button {
  min-height: 34px;
  padding: 6px 8px;
  color: var(--muted);
}

.percent-scale button.active {
  border-color: var(--accent);
  color: var(--text);
}

#submitOrder.buy {
  background: var(--green);
}

#submitOrder.sell {
  background: var(--red);
}

.orderbook-panel {
  min-height: 0;
}

.orderbook-summary,
.orderbook-hint {
  margin-top: 10px;
  border: 1px solid rgba(74, 168, 255, 0.22);
  border-radius: 7px;
  padding: 8px 10px;
  background: rgba(11, 15, 18, 0.42);
  color: var(--muted);
  font-size: 12px;
}

.orderbook-summary {
  display: inline-flex;
  width: max-content;
  max-width: 100%;
}

.orderbook-hint {
  border-color: var(--line);
}

.orderbook-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}

.orderbook-title {
  margin-bottom: 6px;
  font-weight: 800;
}

.orderbook-title.sell {
  color: #ff7777;
}

.orderbook-title.buy {
  color: #2ee58c;
}

.orderbook-head,
.orderbook-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
  align-items: center;
}

.orderbook-head {
  color: var(--muted);
  font-size: 12px;
}

.orderbook-side {
  display: grid;
  gap: 2px;
  margin-top: 6px;
}

.orderbook-row {
  position: relative;
  overflow: hidden;
  border-radius: 4px;
  min-height: 26px;
  padding: 3px 6px;
  background: #101419;
  cursor: pointer;
  font-size: 12px;
}

.orderbook-row::before {
  content: "";
  position: absolute;
  inset: 0 0 0 auto;
  width: var(--depth, 0%);
  opacity: 0.35;
  pointer-events: none;
}

.asks .orderbook-row::before {
  background: #6b252a;
}

.bids .orderbook-row::before {
  background: #143f2b;
}

.orderbook-row span {
  position: relative;
  z-index: 1;
  text-align: right;
}

.orderbook-row span:first-child {
  text-align: left;
}

.asks .orderbook-row span:first-child {
  color: #ff7777;
}

.bids .orderbook-row span:first-child {
  color: #2ee58c;
}

.orderbook-mid {
  margin: 8px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 7px 6px;
  color: var(--text);
  font-size: 16px;
  font-weight: 700;
}

.param-grid {
  display: grid;
  gap: 12px;
}

.strategy-config-section,
.param-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: rgba(7, 11, 14, 0.35);
}

.strategy-config-section {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.section-title {
  color: var(--text);
  font-weight: 800;
}

.section-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.param-section-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.param-grid label,
.param-section-grid label {
  min-width: 0;
}

.strategy-config-section label > span,
.param-section-grid label > span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.param-grid input,
.param-grid select,
.param-section-grid input,
.param-section-grid select {
  padding: 8px 9px;
}

.field-help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 4px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  vertical-align: text-top;
  cursor: help;
}

.balance-box {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #101419;
}

.balance-box .panel-head {
  grid-template-columns: 1fr auto;
}

.balance-box button {
  padding: 6px 9px;
}

.balance-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.balance-item {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px;
  background: #0d1013;
}

.balance-item strong {
  font-size: 16px;
}

.balance-item span {
  color: var(--muted);
  font-size: 12px;
}

.balance-accounts {
  display: grid;
  grid-column: 1 / -1;
  gap: 6px;
}

.balance-account {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  border-top: 1px solid var(--line);
  padding-top: 6px;
  color: var(--muted);
  font-size: 12px;
  min-width: 0;
}

.balance-account strong {
  color: var(--text);
}

.balance-account.error span {
  color: var(--amber);
  overflow-wrap: anywhere;
}

.balance-warning {
  grid-column: 1 / -1;
  border: 1px solid #6f5a26;
  border-radius: 6px;
  padding: 8px;
  background: #17140d;
  color: var(--amber);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow: auto;
  margin-top: 12px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
  font-size: clamp(11px, 0.72vw, 13px);
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px 7px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
}

.open-orders-wrap {
  overflow-x: hidden;
}

.open-orders-table {
  min-width: 0;
  table-layout: fixed;
  font-size: clamp(10px, 0.58vw, 12px);
}

.open-orders-table th,
.open-orders-table td {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding-inline: clamp(4px, 0.42vw, 8px);
}

.open-orders-table th:nth-child(1),
.open-orders-table td:nth-child(1) {
  width: 20%;
}

.open-orders-table th:nth-child(2),
.open-orders-table td:nth-child(2) {
  width: 9%;
}

.open-orders-table th:nth-child(3),
.open-orders-table td:nth-child(3),
.open-orders-table th:nth-child(4),
.open-orders-table td:nth-child(4) {
  width: 8%;
}

.open-orders-table th:nth-child(5),
.open-orders-table td:nth-child(5),
.open-orders-table th:nth-child(6),
.open-orders-table td:nth-child(6),
.open-orders-table th:nth-child(7),
.open-orders-table td:nth-child(7),
.open-orders-table th:nth-child(8),
.open-orders-table td:nth-child(8) {
  width: 7%;
}

.open-orders-table th:nth-child(9),
.open-orders-table td:nth-child(9) {
  width: 16%;
}

.open-orders-table th:nth-child(10),
.open-orders-table td:nth-child(10) {
  width: 8%;
}

.open-orders-table th:nth-child(11),
.open-orders-table td:nth-child(11) {
  width: 10%;
}

.open-orders-table td:last-child button {
  max-width: 100%;
  min-height: 30px;
  padding: 6px 9px;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: inherit;
}

.strategy-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

#activeStrategies {
  grid-template-columns: repeat(3, minmax(260px, 1fr));
}

.strategy {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #11161a;
}

.strategy.template {
  cursor: pointer;
}

.strategy-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.strategy strong {
  display: block;
  margin-bottom: 6px;
}

.strategy code {
  display: block;
  margin-top: 6px;
  overflow-wrap: anywhere;
  color: #a8d7ff;
}

.active-strategy-card {
  display: grid;
  gap: 9px;
  position: relative;
  padding-right: 42px;
  min-width: 0;
  font-size: clamp(11px, 0.75vw, 13px);
}

.strategy-cycle-corner {
  position: absolute;
  top: 12px;
  right: 14px;
  color: #48ff73;
  font-style: normal;
  font-size: 13px;
  line-height: 1;
}

.strategy-card-head,
.strategy-meta,
.strategy-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.strategy-card-head {
  justify-content: space-between;
}

.strategy-symbol {
  color: #ffffff;
  letter-spacing: 0;
}

.strategy-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.strategy-controls button,
.cycle-pill {
  min-height: 28px;
  padding: 4px 9px;
  font-size: 12px;
}

.strategy-controls .danger {
  border-color: rgba(224, 91, 91, 0.5);
  color: #ff858d;
}

.strategy-metrics {
  display: grid;
  grid-template-columns: repeat(3, minmax(90px, 1fr));
  gap: 8px;
}

.strategy-metrics div {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 8px;
  background: #0d1216;
}

.strategy-metrics b,
.strategy-metrics span {
  display: block;
}

.strategy-metrics b {
  color: #dbe9f6;
  font-size: clamp(12px, 0.82vw, 13px);
  white-space: nowrap;
}

.strategy-metrics .profit b {
  color: #2ee58c;
}

.strategy-metrics .loss b {
  color: #ff7c86;
}

.strategy-metrics span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.strategy-progress {
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: #0a0f13;
  border: 1px solid var(--line);
}

.strategy-progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1a7dbd, #2ee58c);
}

.strategy-progress.exit span {
  background: linear-gradient(90deg, #7756d9, #f4b942, #2ee58c);
}

.strategy-progress.done span {
  background: linear-gradient(90deg, #1f9f69, #2ee58c);
}

.strategy-progress.blocked span {
  background: linear-gradient(90deg, #25313b, #8f9aa6);
}

.strategy-condition {
  border: 1px solid rgba(74, 168, 255, 0.18);
  border-radius: 7px;
  padding: 8px;
  background: #0d1216;
  color: var(--muted);
  font-size: 12px;
}

.strategy-condition strong {
  margin: 0 0 4px;
  color: #cfe2f3;
}

.strategy-condition span {
  display: block;
  line-height: 1.35;
}

.status-pill,
.strategy-badges span,
.strategy-meta span {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  font-size: clamp(10px, 0.72vw, 12px);
  white-space: nowrap;
}

.status-pill {
  border-color: rgba(34, 181, 115, 0.4);
  color: #2ee58c;
}

.status-pill.off {
  border-color: rgba(244, 185, 66, 0.35);
  color: var(--amber);
}

.status-pill.done {
  border-color: rgba(74, 168, 255, 0.35);
  color: #a8d7ff;
}

.strategy-badges span {
  border-color: rgba(74, 168, 255, 0.24);
  color: #cfe2f3;
}

.strategy-badges .warning-pill {
  border-color: rgba(244, 185, 66, 0.35);
  color: var(--amber);
}

.strategy-badges .success-pill {
  border-color: rgba(34, 181, 115, 0.4);
  color: #2ee58c;
}

.executor-status {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  background: #101419;
  color: var(--muted);
}

.executor-status div {
  display: grid;
  gap: 4px;
}

.executor-status strong {
  color: var(--amber);
}

.executor-status.on strong {
  color: #2ee58c;
}

.executor-toggle {
  white-space: nowrap;
}

.executor-toggle[disabled] {
  cursor: not-allowed;
  opacity: 0.72;
}

.executor-toggle.on[disabled] {
  border-color: rgba(34, 181, 115, 0.45);
  color: #2ee58c;
  opacity: 1;
}

.strategy-pnl {
  border-color: rgba(34, 181, 115, 0.42) !important;
  color: #2ee58c !important;
  cursor: pointer;
}

.strategy-pnl.loss {
  border-color: rgba(224, 91, 91, 0.48) !important;
  color: #ff7c86 !important;
}

.close-summary {
  display: grid;
  gap: 8px;
}

.close-row {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
}

.close-row strong.profit {
  color: #2ee58c;
}

.close-row strong.loss {
  color: #ff7c86;
}

.profit-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.profit-card {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 12px;
  background: #101419;
}

.profit-card strong {
  display: block;
  margin-bottom: 8px;
}

.profit-card .profit-net {
  color: #2ee58c;
  font-size: 18px;
  font-weight: 700;
}

.profit-card.loss .profit-net {
  color: #ff7c86;
}

.trades-modal {
  width: min(1760px, calc(100vw - 18px));
  max-width: calc(100vw - 18px);
}

.trade-history-wrap {
  max-height: calc(100dvh - 190px);
  overflow: auto;
  scrollbar-width: thin;
}

.trade-history-table {
  width: 100%;
  min-width: 0;
  table-layout: fixed;
  font-size: clamp(9px, 0.58vw, 12px);
}

.trade-history-table td,
.trade-history-table th {
  vertical-align: top;
  padding: clamp(5px, 0.55vw, 8px) clamp(4px, 0.45vw, 7px);
  font-size: inherit;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
}

.trade-history-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #101419;
}

.trade-history-table th:nth-child(1),
.trade-history-table td:nth-child(1) {
  width: 8.2%;
}

.trade-history-table th:nth-child(2),
.trade-history-table td:nth-child(2) {
  width: 7.5%;
}

.trade-history-table th:nth-child(3),
.trade-history-table td:nth-child(3) {
  width: 13%;
}

.trade-history-table th:nth-child(4),
.trade-history-table td:nth-child(4),
.trade-history-table th:nth-child(5),
.trade-history-table td:nth-child(5) {
  width: 4%;
}

.trade-history-table th:nth-child(6),
.trade-history-table td:nth-child(6),
.trade-history-table th:nth-child(7),
.trade-history-table td:nth-child(7),
.trade-history-table th:nth-child(8),
.trade-history-table td:nth-child(8),
.trade-history-table th:nth-child(9),
.trade-history-table td:nth-child(9),
.trade-history-table th:nth-child(10),
.trade-history-table td:nth-child(10),
.trade-history-table th:nth-child(11),
.trade-history-table td:nth-child(11) {
  width: 6.2%;
}

.trade-history-table th:nth-child(12),
.trade-history-table td:nth-child(12) {
  width: 8%;
}

.trade-history-table th:nth-child(13),
.trade-history-table td:nth-child(13) {
  width: 12%;
}

.trade-history-table th:nth-child(14),
.trade-history-table td:nth-child(14) {
  width: 12%;
}

.trade-history-table td:nth-child(2),
.trade-history-table td:nth-child(3),
.trade-history-table td:nth-child(13),
.trade-history-table td:nth-child(14) {
  hyphens: auto;
}

.trade-history-table .profit {
  color: #2ee58c;
}

.trade-history-table .loss {
  color: #ff7c86;
}

.trade-params {
  max-width: none;
  white-space: normal;
  line-height: 1.45;
}

@media (max-width: 1100px) {
  .trades-modal {
    width: calc(100vw - 10px);
  }

  .trade-history-wrap {
    max-height: calc(100dvh - 150px);
    overflow-x: hidden;
  }

  .trade-history-table,
  .trade-history-table thead,
  .trade-history-table tbody,
  .trade-history-table tr,
  .trade-history-table th,
  .trade-history-table td {
    display: block;
    width: 100% !important;
    min-width: 0;
  }

  .trade-history-table {
    border-collapse: separate;
    border-spacing: 0 8px;
    font-size: clamp(10px, 2.4vw, 12px);
  }

  .trade-history-table thead {
    display: none;
  }

  .trade-history-table tr {
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 8px 10px;
    background: #101419;
  }

  .trade-history-table td {
    display: grid;
    grid-template-columns: minmax(96px, 34%) minmax(0, 1fr);
    gap: 10px;
    border-bottom: 1px solid rgba(47, 62, 76, 0.55);
    padding: 7px 0;
    white-space: normal;
  }

  .trade-history-table td:last-child {
    border-bottom: 0;
  }

  .trade-history-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
  }
}

.balance-list {
  display: grid;
  gap: 8px;
  max-height: 62vh;
  overflow: auto;
}

.balance-row {
  display: grid;
  grid-template-columns: 90px repeat(3, minmax(120px, 1fr));
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px;
  background: #101419;
}

.liquidity-controls {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) 280px;
  gap: 10px;
}

.liquidity-table {
  display: grid;
  gap: 4px;
  max-height: calc(100dvh - 220px);
  overflow: auto;
  padding-bottom: 4px;
}

.liquidity-head,
.liquidity-row {
  display: grid;
  grid-template-columns: 38px minmax(130px, 1.2fr) minmax(96px, 1fr) minmax(92px, 0.9fr) minmax(132px, 1.1fr) repeat(6, minmax(96px, 1fr));
  gap: 8px;
  align-items: center;
  width: 100%;
  min-width: 1120px;
  padding: 8px 10px;
}

.liquidity-head {
  position: sticky;
  z-index: 1;
  top: 0;
  color: var(--muted);
  background: #101419;
  font-size: clamp(11px, 0.72vw, 12px);
}

.liquidity-sort-head {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  font-size: 12px;
  font-weight: 700;
}

.liquidity-sort-head:hover,
.liquidity-sort-head.active {
  color: var(--accent);
}

.liquidity-row {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #101419;
}

.liquidity-row span {
  min-height: 30px;
  border-radius: 5px;
  padding: 5px 7px;
}

.liquidity-row span.profit {
  background: rgba(34, 181, 115, 0.16);
  color: #54f0a0;
}

.liquidity-row span.loss {
  background: rgba(224, 91, 91, 0.17);
  color: #ff8d96;
}

.liquidity-symbol {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
  font-weight: 800;
}

.liquidity-symbol:hover {
  color: var(--accent);
}

.arbitrage-results {
  display: grid;
  gap: 8px;
  max-height: 58vh;
  overflow: auto;
}

.arbitrage-row {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(160px, auto) minmax(210px, auto);
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 10px 12px;
  background: #101419;
}

.arbitrage-row div:first-child {
  display: grid;
  gap: 4px;
}

.arbitrage-row .profit {
  color: #54f0a0;
  font-weight: 800;
}

.arbitrage-row .loss {
  color: #ff8d96;
  font-weight: 800;
}

.balance-row strong {
  color: var(--text);
}

@media (max-width: 1280px) {
  #activeStrategies {
    grid-template-columns: repeat(2, minmax(260px, 1fr));
  }
}

@media (max-width: 760px) {
  #activeStrategies {
    grid-template-columns: 1fr;
  }
}

.strategy-help {
  display: grid;
  gap: 10px;
}

.strategy-help ul {
  margin: 0;
  padding-left: 18px;
}

.log-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
  margin-top: 12px;
}

.log-item {
  display: grid;
  gap: 4px;
  border-left: 3px solid var(--accent);
  padding: 9px 10px;
  background: #101419;
}

.log-item.warning {
  border-left-color: var(--amber);
}

.log-item.error {
  border-left-color: var(--red);
}

.log-meta {
  color: var(--muted);
  font-size: 12px;
}

.log-meta .hide-extra {
  display: none;
}

.modal {
  width: min(720px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
  background: var(--panel);
  color: var(--text);
}

.strategy-modal,
.templates-modal {
  width: min(960px, calc(100vw - 24px));
}

.liquidity-modal {
  width: calc(100vw - 24px);
  max-width: 1880px;
}

.trades-modal {
  width: calc(100vw - 24px);
  max-width: 1880px;
}

.liquidity-modal .modal-body {
  align-content: start;
  max-height: calc(100dvh - 56px);
  overflow: hidden;
}

.trades-modal .modal-body {
  align-content: start;
  max-height: calc(100dvh - 56px);
  overflow: hidden;
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.modal-body {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.indicator-settings {
  display: none;
  gap: 12px;
}

.indicator-settings.active {
  display: grid;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.json-actions {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  gap: 10px;
  align-items: center;
}

@media (max-width: 980px) {
  .topbar,
  .workspace,
  .trade-row,
  .market-depth,
  .automation,
  .tables {
    grid-template-columns: 1fr;
  }

  .token-form,
  .market-toolbar,
  .balance-grid,
  .orderbook-columns,
  .param-grid,
  .param-section-grid,
  .json-actions,
  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .chart-head,
  .panel-head {
    grid-template-columns: 1fr;
  }

  .chart-panel {
    min-height: auto;
  }
}

@media (max-width: 720px) {
  body {
    font-size: 13px;
  }

  .app {
    gap: 10px;
    padding: 10px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: 10px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .token-form {
    grid-template-columns: 1fr 1fr;
  }

  .token-form input {
    grid-column: 1 / -1;
  }

  .token-form button {
    min-height: 42px;
  }

  .market-toolbar {
    grid-template-columns: 1fr 1fr;
  }

  .market-strip,
  .strategy-pair-strip,
  .segmented {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 4px;
    scrollbar-width: thin;
    scroll-snap-type: x proximity;
  }

  .ticker,
  .strategy-pair,
  .segmented button {
    flex: 0 0 auto;
    scroll-snap-align: start;
  }

  .ticker {
    min-width: 118px;
  }

  .strategy-pair {
    min-width: 150px;
  }

  .chart-panel,
  .order-panel,
  .table-panel {
    border-radius: 8px;
  }

  .chart-head {
    gap: 8px;
  }

  .chart-wrap {
    min-height: 430px;
    overflow: hidden;
  }

  #chartCanvas {
    width: 100%;
    height: 430px;
  }

  .indicator-legend {
    max-width: calc(100% - 12px);
    overflow-x: auto;
    white-space: nowrap;
  }

  .chart-info {
    left: 10px;
    right: auto;
    top: 38px;
    max-width: 210px;
    padding: 8px 10px;
    opacity: 0.88;
  }

  .chart-strategies {
    right: 8px;
    bottom: 8px;
    left: 8px;
    max-width: none;
  }

  .chart-strategy-chip {
    grid-template-columns: 1fr auto;
    gap: 4px 8px;
    padding: 8px;
  }

  .trade-row,
  .automation,
  .tables {
    gap: 10px;
  }

  .orderbook-columns {
    grid-template-columns: 1fr;
  }

  .orderbook-row,
  .orderbook-head {
    grid-template-columns: 1fr 1fr 1fr;
  }

  .balance-grid,
  .profit-stats,
  .balance-row {
    grid-template-columns: 1fr;
  }

  .active-strategy-card {
    padding: 12px;
  }

  .strategy-card-head,
  .strategy-controls,
  .strategy-metrics,
  .strategy-meta,
  .strategy-badges {
    grid-template-columns: 1fr;
  }

  .strategy-controls {
    display: flex;
    flex-wrap: wrap;
  }

  .strategy-controls button,
  .strategy-controls .status-pill {
    flex: 1 1 98px;
  }

  .table-wrap {
    overflow-x: auto;
  }

  table {
    min-width: 900px;
  }

  .open-orders-wrap {
    overflow-x: hidden;
  }

  .open-orders-table {
    min-width: 0;
    font-size: clamp(9px, 2vw, 11px);
  }

  .open-orders-table th,
  .open-orders-table td {
    padding-inline: 3px;
  }

  .open-orders-table td:last-child button {
    padding-inline: 5px;
  }

  .modal {
    width: calc(100vw - 12px);
    max-height: calc(100dvh - 12px);
  }

  .modal-body {
    max-height: calc(100dvh - 12px);
    overflow: auto;
    padding: 12px;
  }

  .modal-actions,
  .json-actions {
    grid-template-columns: 1fr;
    display: grid;
  }

  .modal-actions button,
  .json-actions button {
    width: 100%;
  }

  .app-toast {
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    max-width: none;
  }
}
