:root {
  color-scheme: dark;
  --bg: #101214;
  --panel: #181b1f;
  --panel-2: #20242a;
  --line: #30363d;
  --text: #eff3f7;
  --muted: #9aa4ae;
  --green: #28c76f;
  --red: #ff5c5c;
  --amber: #ffb020;
  --blue: #44a3ff;
  --cyan: #4fd1c5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 22px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1 {
  margin: 0;
  font-size: 24px;
  font-weight: 760;
  letter-spacing: 0;
}

p {
  margin: 0;
}

.topbar p,
.subtext,
dt {
  color: var(--muted);
}

.top-actions,
.button-row,
.legend,
.score-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  overflow-x: auto;
}

.tab {
  min-width: 116px;
  padding: 0 14px;
}

.tab.active {
  background: var(--text);
  border-color: var(--text);
  color: #101214;
  font-weight: 780;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
  margin-bottom: 12px;
  color: var(--muted);
}

.panel-head strong {
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}

.status-grid {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 12px;
}

.chart-panel {
  min-width: 0;
}

.chart {
  height: 520px;
  width: 100%;
}

.side {
  display: grid;
  gap: 12px;
  align-content: start;
}

.controls {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 12px;
  margin-top: 12px;
}

.backtest-controls {
  grid-template-columns: 1fr 1fr;
}

.backtest-form {
  grid-template-columns: minmax(220px, 1fr) 160px;
}

.live-grid {
  grid-template-columns: minmax(0, 1fr) 460px;
}

.table-list {
  display: grid;
  gap: 8px;
}

.table-row {
  display: grid;
  gap: 4px;
  padding: 10px;
  border-radius: 6px;
  background: var(--panel-2);
  min-width: 0;
}

.table-row.four {
  grid-template-columns: 90px repeat(3, minmax(0, 1fr));
  align-items: center;
}

.table-row.empty {
  color: var(--muted);
}

.table-row span,
.table-row small {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.log-output {
  min-height: 420px;
  max-height: 620px;
  overflow: auto;
  margin: 0;
  padding: 12px;
  border-radius: 6px;
  background: #0e1114;
  border: 1px solid var(--line);
  color: #dce3ea;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
}

.signal-panel {
  min-height: 152px;
}

.score-ring {
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--green) 0deg, var(--panel-2) 0deg);
  position: relative;
  flex: 0 0 auto;
}

.score-ring::after {
  content: "";
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--panel);
  position: absolute;
}

.score-ring span {
  position: relative;
  z-index: 1;
  font-size: 18px;
  font-weight: 800;
}

.price {
  font-size: 30px;
  font-weight: 780;
  line-height: 1.1;
}

.signal-row {
  margin-top: 10px;
  padding: 9px 10px;
  border-radius: 6px;
  background: var(--panel-2);
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin: 0;
}

.metrics div {
  min-width: 0;
}

dt {
  font-size: 12px;
  margin-bottom: 4px;
}

dd {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 720;
}

.legend span {
  color: var(--muted);
  font-size: 12px;
}

.legend i {
  display: inline-block;
  width: 16px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
}

.ema50 {
  background: var(--blue);
}

.ema100 {
  background: var(--amber);
}

.ema200 {
  background: var(--cyan);
}

.check-list,
.positions {
  display: grid;
  gap: 8px;
}

.check {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: start;
  padding: 8px;
  border-radius: 6px;
  background: var(--panel-2);
}

.check b {
  width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 12px;
  background: #3a3f45;
}

.check.ok b {
  background: color-mix(in srgb, var(--green) 22%, #223027);
  color: var(--green);
}

.check.bad b {
  background: color-mix(in srgb, var(--red) 18%, #332729);
  color: var(--red);
}

.check small {
  display: block;
  color: var(--muted);
  margin-top: 2px;
}

.position {
  padding: 10px;
  border-radius: 6px;
  background: var(--panel-2);
}

.position strong {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.trade-form {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

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

input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: #121518;
  padding: 0 10px;
}

button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text);
  background: var(--panel-2);
  cursor: pointer;
}

button:hover {
  border-color: #4a535c;
}

.primary {
  background: var(--green);
  border-color: var(--green);
  color: #06140d;
  font-weight: 780;
}

.danger {
  background: var(--red);
  border-color: var(--red);
  color: #1b0606;
  font-weight: 780;
}

.danger-soft {
  background: #ffd15a;
  border-color: #ffd15a;
  color: #1a1202;
}

.icon-btn {
  width: 38px;
  font-size: 18px;
}

.text-btn {
  padding: 0 12px;
}

.pill {
  display: inline-grid;
  place-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  font-size: 12px;
}

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

.dryrun {
  color: var(--amber) !important;
}

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

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

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

.login-dialog {
  width: min(420px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  padding: 0;
}

.login-dialog::backdrop {
  background: rgba(0, 0, 0, 0.72);
}

.login-dialog form {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.login-dialog h2 {
  margin: 0;
  font-size: 20px;
}

.error {
  color: var(--red);
  min-height: 20px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(460px, calc(100vw - 36px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #0f1712;
  border: 1px solid #25583b;
  color: var(--text);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.28);
}

@media (max-width: 1080px) {
  .status-grid,
  .workspace,
  .controls,
  .live-grid,
  .backtest-controls {
    grid-template-columns: 1fr;
  }

  .chart {
    height: 430px;
  }

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

  .table-row.four {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 640px) {
  .shell {
    width: min(100vw - 20px, 1480px);
    padding-top: 12px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .chart {
    height: 360px;
  }
}
