:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #607080;
  --line: #dce3e8;
  --blue: #1f5f99;
  --green: #08764b;
  --red: #b13232;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 18px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 16px;
}

.topbar p,
.panel-title span,
.metrics span {
  color: var(--muted);
  font-size: 13px;
}

.source,
button {
  border: 1px solid var(--blue);
  border-radius: 6px;
  background: var(--blue);
  color: white;
  font-weight: 700;
  text-decoration: none;
}

.source {
  padding: 9px 12px;
}

button {
  min-height: 38px;
  padding: 0 16px;
  cursor: pointer;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

button.secondary {
  background: white;
  color: var(--blue);
}

button.danger {
  border-color: var(--red);
  background: var(--red);
}

button.stop {
  border-color: #4b5563;
  background: #4b5563;
  color: #ffffff;
}

button.mini {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
}

main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 20px 24px 32px;
}

.controls {
  display: grid;
  grid-template-columns: 180px 220px minmax(180px, 1fr) auto;
  gap: 12px;
  margin-bottom: 16px;
  align-items: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

select,
input {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: white;
  color: var(--text);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metrics div,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.metrics div {
  padding: 14px 16px;
}

.metrics strong {
  display: block;
  margin-top: 6px;
  font-size: 18px;
}

.panel-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.grid-panels {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 16px;
  margin-top: 16px;
}

.form-grid {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.api-form {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.trade-form {
  grid-template-columns: 1fr;
}

.monitor-panel {
  margin-top: 16px;
}

.monitor-form {
  grid-template-columns: 160px 1fr 180px 140px;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding-top: 20px;
}

.checkbox-line input {
  width: auto;
  min-height: auto;
}

.saved-exchanges {
  display: flex;
  align-items: center;
  min-height: 38px;
  gap: 8px;
  flex-wrap: wrap;
}

.saved-exchange.active {
  background: var(--blue);
  color: #ffffff;
}

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

.button-row {
  display: flex;
  gap: 10px;
  padding: 0 16px 16px;
  flex-wrap: wrap;
}

.output {
  min-height: 120px;
  max-height: 260px;
  margin: 0 16px 16px;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
  color: var(--text);
  font-size: 12px;
  white-space: pre-wrap;
}

.table-wrap {
  overflow-x: auto;
}

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

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

th:first-child,
td:first-child,
th:nth-child(3),
td:nth-child(3) {
  text-align: left;
}

th {
  color: var(--muted);
  font-size: 12px;
}

td strong,
td span {
  display: block;
}

td span {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.positive {
  color: var(--green);
  font-weight: 750;
}

.negative {
  color: var(--red);
  font-weight: 750;
}

.empty {
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

@media (max-width: 860px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  main {
    padding: 14px;
  }

  .controls,
  .metrics,
  .grid-panels,
  .api-form,
  .monitor-form {
    grid-template-columns: 1fr;
  }
}
