:root {
  --bg: #06050f;
  --bg2: #0d1117;
  --panel: rgba(255, 255, 255, 0.055);
  --panel2: rgba(255, 255, 255, 0.08);
  --control: rgba(8, 10, 20, 0.94);
  --text: #ffffff;
  --text2: #b6bdd4;
  --muted: #777f99;
  --line: rgba(255, 255, 255, 0.12);
  --line2: rgba(99, 142, 255, 0.34);
  --blue: #638eff;
  --green: #39ff8a;
  --red: #ff5370;
  --amber: #ffb74d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
  --radius: 8px;
  --font-head: "Syne", sans-serif;
  --font-body: "Instrument Sans", sans-serif;
  --mono: "Space Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 12% -12%, rgba(99, 142, 255, 0.2), transparent 34rem),
    radial-gradient(circle at 88% 0%, rgba(57, 255, 138, 0.14), transparent 30rem),
    var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--panel2);
  color: var(--text);
  padding: 0 12px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

button:hover {
  border-color: var(--line2);
  background: rgba(99, 142, 255, 0.16);
}

button:active {
  transform: translateY(1px);
}

button.primary {
  background: var(--green);
  border-color: var(--green);
  color: #06100a;
  font-weight: 800;
}

button.danger {
  background: rgba(255, 83, 112, 0.16);
  border-color: rgba(255, 83, 112, 0.5);
  color: #ffd7df;
}

input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--control);
  color: var(--text);
  padding: 7px 9px;
  outline: none;
}

input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(99, 142, 255, 0.16);
}

input[type="checkbox"] {
  width: 16px;
  min-height: 16px;
  accent-color: var(--green);
}

a {
  color: inherit;
  text-decoration: none;
}

h1,
h2,
p {
  margin: 0;
}

h1,
h2,
.brand {
  font-family: var(--font-head);
}

h1 {
  font-size: clamp(32px, 5vw, 64px);
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  font-size: 14px;
  line-height: 1.2;
}

code {
  font-family: var(--mono);
  color: #ddfbe8;
}

.bots-header {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 68px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(6, 5, 15, 0.82);
  backdrop-filter: blur(22px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 800;
  min-width: 0;
}

.brand img {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  object-fit: cover;
}

.brand span {
  background: linear-gradient(90deg, #c7d7ff, var(--green));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  white-space: nowrap;
}

.brand em {
  font-style: normal;
}

.brand small {
  color: var(--muted);
  -webkit-text-fill-color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.bots-nav {
  display: flex;
  gap: 6px;
  align-items: center;
  overflow-x: auto;
  scrollbar-width: none;
}

.bots-nav::-webkit-scrollbar {
  display: none;
}

.bots-nav a {
  border-radius: 8px;
  color: var(--muted);
  font-family: var(--font-head);
  font-size: 12px;
  font-weight: 700;
  padding: 8px 12px;
  white-space: nowrap;
}

.bots-nav a:hover,
.bots-nav a[aria-current="page"] {
  background: var(--panel2);
  color: var(--text2);
}

main {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 28px 24px 44px;
}

.command-band {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 420px);
  gap: 24px;
  align-items: end;
  margin-bottom: 18px;
}

.command-title {
  display: grid;
  gap: 10px;
}

.command-title p:not(.eyebrow) {
  max-width: 620px;
  color: var(--text2);
  font-size: 16px;
}

.eyebrow {
  color: var(--green);
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.connection-panel,
.runbar,
.metrics div,
.config-panel,
.levels-panel,
.signal-panel,
.settings-panel,
.log-panel,
.chart-panel,
.orders-panel,
.notice,
.error-box,
.modal {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(13, 17, 23, 0.78);
  box-shadow: var(--shadow);
}

.connection-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.connection-state {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text2);
}

.state-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  box-shadow: 0 0 14px rgba(255, 83, 112, 0.42);
}

body.is-connected .state-dot {
  background: var(--green);
  box-shadow: 0 0 14px rgba(57, 255, 138, 0.4);
}

.endpoint-field span,
label span,
.metrics span,
.settings-status span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.connection-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.notice,
.error-box {
  color: #f7e5bd;
  margin-bottom: 16px;
  padding: 11px 12px;
}

.notice.compact {
  margin-bottom: 12px;
  box-shadow: none;
}

.error-box {
  color: #ffd7df;
  border-color: rgba(255, 83, 112, 0.42);
  background: rgba(255, 83, 112, 0.12);
}

.runbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px;
}

.segmented {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
}

.segmented button {
  min-width: 106px;
  border: 0;
  border-radius: 0;
}

.segmented button.is-active {
  background: var(--blue);
  color: #fff;
}

.inline-field {
  display: grid;
  grid-template-columns: auto 82px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.inline-field span {
  margin: 0;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(7, minmax(118px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.metrics div {
  min-height: 76px;
  padding: 12px;
  display: grid;
  align-content: center;
  gap: 6px;
}

.metrics strong {
  font-size: 17px;
  line-height: 1.18;
  overflow-wrap: anywhere;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(290px, 340px) minmax(480px, 1fr) minmax(280px, 360px);
  gap: 16px;
  align-items: start;
}

.dashboard-grid > *,
.market-workspace > * {
  min-width: 0;
}

.market-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 460px);
  gap: 16px;
  margin-bottom: 16px;
  align-items: stretch;
}

.chart-panel,
.orders-panel {
  min-width: 0;
  padding: 14px;
}

.chart-head {
  align-items: flex-start;
}

.chart-head > div:first-child {
  display: grid;
  gap: 5px;
}

.chart-timeframes {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.chart-timeframes button {
  min-width: 44px;
  min-height: 30px;
  padding: 0 8px;
  font-family: var(--mono);
  font-size: 11px;
}

.chart-timeframes button.is-active {
  border-color: var(--blue);
  background: rgba(99, 142, 255, 0.22);
  color: #dbe6ff;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 11px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.legend-swatch {
  width: 14px;
  height: 3px;
  border-radius: 2px;
}

.legend-swatch.price-up {
  background: var(--green);
}

.legend-swatch.price-down {
  background: var(--red);
}

.legend-swatch.order-buy {
  border-top: 2px dashed var(--green);
}

.legend-swatch.order-sell {
  border-top: 2px dashed var(--red);
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 390px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(6, 5, 15, 0.66);
}

#marketChart {
  display: block;
  width: 100%;
  height: 100%;
}

.chart-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.chart-empty[hidden] {
  display: none;
}

.orders-table-wrap {
  max-height: 446px;
}

.order-side {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 800;
}

.order-side.buy {
  color: var(--green);
}

.order-side.sell {
  color: var(--red);
}

.config-panel,
.levels-panel,
.signal-panel,
.settings-panel,
.log-panel {
  padding: 14px;
}

.config-panel section + section {
  border-top: 1px solid var(--line);
  margin-top: 18px;
  padding-top: 18px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.toggle-row {
  display: grid;
  gap: 9px;
  margin: 12px 0;
}

.toggle-row label,
.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text2);
}

.table-wrap {
  max-height: calc(100vh - 278px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(6, 5, 15, 0.6);
}

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

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #111827;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  margin: 1px;
  padding: 2px 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-size: 12px;
}

.pill.buy {
  color: #c9fadd;
  background: rgba(57, 255, 138, 0.12);
  border-color: rgba(57, 255, 138, 0.36);
}

.pill.sell {
  color: #ffd7df;
  background: rgba(255, 83, 112, 0.12);
  border-color: rgba(255, 83, 112, 0.34);
}

.pill.wait {
  color: #ffe0aa;
  background: rgba(255, 183, 77, 0.12);
  border-color: rgba(255, 183, 77, 0.34);
}

.side-column {
  display: grid;
  gap: 16px;
}

.signal-panel dl {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 14px;
  margin: 12px 0 0;
}

.signal-panel dt {
  color: var(--muted);
}

.signal-panel dd {
  margin: 0;
  font-weight: 800;
}

.settings-status {
  display: grid;
  gap: 8px;
}

.settings-status div {
  min-height: 58px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.04);
  padding: 9px;
}

.settings-status strong,
.subtle {
  color: var(--text2);
  overflow-wrap: anywhere;
}

.log-panel {
  min-height: 320px;
}

#logs {
  display: grid;
  gap: 7px;
  max-height: 420px;
  margin-top: 12px;
  overflow: auto;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: 12px;
}

.log-line {
  color: var(--text2);
  overflow-wrap: anywhere;
}

.log-line.ERROR,
.log-line.WARNING {
  color: #ffd7df;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.54);
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  width: min(680px, 100%);
  padding: 16px;
}

.icon-button {
  width: 36px;
  min-width: 36px;
  padding: 0;
}

.settings-grid {
  margin-top: 8px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

@media (max-width: 1180px) {
  .command-band,
  .market-workspace,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .metrics {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }

  .table-wrap {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .bots-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    padding: 14px 16px;
  }

  main {
    padding: 22px 14px 36px;
  }

  .command-title p:not(.eyebrow) {
    font-size: 14px;
  }

  .runbar,
  .connection-actions,
  .form-grid,
  .metrics {
    grid-template-columns: 1fr;
  }

  .runbar {
    display: grid;
  }

  .segmented,
  .inline-field {
    width: 100%;
  }

  .inline-field {
    grid-template-columns: 1fr;
  }

  .chart-head {
    align-items: stretch;
    flex-direction: column;
  }

  .chart-timeframes {
    justify-content: flex-start;
  }

  .chart-wrap {
    height: 310px;
  }
}
