:root {
  color-scheme: dark;
  --bg: #07090d;
  --surface: #0d1118;
  --surface-2: #121822;
  --line: #202837;
  --text: #f4f7fb;
  --muted: #7f8b9d;
  --green: #86f0b1;
  --green-strong: #37d980;
  --green-dim: rgb(55 217 128 / 12%);
  --red: #ff727b;
  --red-dim: rgb(255 114 123 / 12%);
  --blue: #6fa7ff;
  --amber: #ffc86b;
  --radius: 16px;
  --font: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-family: var(--font);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { min-height: 100%; background: var(--bg); -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(900px 420px at 18% -12%, rgb(55 217 128 / 9%), transparent 68%),
    radial-gradient(700px 420px at 94% 8%, rgb(111 167 255 / 7%), transparent 70%),
    var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1, h2, p, dl, dd { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid rgb(32 40 55 / 82%);
  background: rgb(7 9 13 / 80%);
  backdrop-filter: blur(18px) saturate(140%);
}
.top-inner {
  width: min(1440px, 100%);
  height: 58px;
  margin: auto;
  padding: 0 max(16px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand { display: inline-flex; align-items: center; gap: 10px; }
.brand > span:last-child { display: flex; flex-direction: column; line-height: 1.05; }
.brand b { font-size: 15px; letter-spacing: .08em; }
.brand small { margin-top: 4px; color: var(--muted); font-size: 8px; letter-spacing: .15em; }
.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: linear-gradient(145deg, #a5ffd0, var(--green-strong));
  color: #07110b;
  font-weight: 950;
  box-shadow: 0 8px 30px rgb(55 217 128 / 23%);
}
.brand-mark.large { width: 48px; height: 48px; border-radius: 14px; font-size: 21px; }
.connection { margin-left: auto; display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.connection i, .status-dot { width: 7px; height: 7px; border-radius: 50%; background: #4c5666; }
.connection i.on, .status-dot.on { background: var(--green-strong); box-shadow: 0 0 0 4px rgb(55 217 128 / 12%); }
.connection i.off, .status-dot.off { background: var(--red); box-shadow: 0 0 0 4px rgb(255 114 123 / 10%); }
.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--muted);
}

.shell {
  width: min(1440px, 100%);
  margin: auto;
  padding: 28px max(16px, env(safe-area-inset-left)) calc(44px + env(safe-area-inset-bottom));
}
.headline { display: flex; align-items: flex-end; gap: 20px; margin-bottom: 20px; }
.headline h1 { font-size: clamp(26px, 4vw, 42px); line-height: 1; letter-spacing: -.045em; }
.headline p { margin-top: 9px; color: var(--muted); }
.eyebrow { margin-bottom: 9px; color: var(--green); font-size: 10px; font-weight: 800; letter-spacing: .16em; }
.headline-actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.mode-pill, .side-pill {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 10px;
  font-weight: 850;
  letter-spacing: .08em;
}
.mode-pill.paper { color: var(--blue); background: rgb(111 167 255 / 9%); border-color: rgb(111 167 255 / 24%); }
.mode-pill.live, .side-pill.Short { color: var(--red); background: var(--red-dim); border-color: rgb(255 114 123 / 25%); }
.side-pill.Long { color: var(--green); background: var(--green-dim); border-color: rgb(55 217 128 / 25%); }

.alert { margin-bottom: 14px; padding: 11px 13px; border: 1px solid rgb(255 114 123 / 30%); border-radius: 11px; background: var(--red-dim); color: #ffb0b6; }
.strategy-tabs { margin-bottom: 14px; display: flex; gap: 6px; border-bottom: 1px solid var(--line); }
.strategy-tab {
  min-height: 40px;
  padding: 0 12px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .08em;
}
.strategy-tab.active { border-bottom-color: var(--green-strong); color: var(--text); }
.strategy-intro { margin: 4px 0 18px; display: flex; align-items: flex-end; gap: 20px; }
.strategy-intro h2 { font-size: clamp(20px, 3vw, 30px); letter-spacing: -.035em; }
.strategy-intro p { margin-top: 7px; color: var(--muted); }
.strategy-intro .headline-actions { margin-left: auto; }
.metrics { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.metric, .panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: linear-gradient(150deg, rgb(18 24 34 / 93%), rgb(11 15 21 / 96%));
  box-shadow: 0 18px 60px rgb(0 0 0 / 14%);
}
.metric { min-height: 118px; padding: 16px; display: flex; flex-direction: column; }
.metric.primary { border-color: rgb(55 217 128 / 26%); background: linear-gradient(150deg, rgb(55 217 128 / 12%), rgb(11 15 21 / 95%) 64%); }
.metric span { color: var(--muted); font-size: 11px; font-weight: 650; }
.metric strong { margin-top: auto; font-size: clamp(20px, 2.1vw, 30px); line-height: 1; letter-spacing: -.045em; font-variant-numeric: tabular-nums; }
.metric small { margin-top: 7px; color: var(--muted); font-size: 10px; }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }

.grid-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(290px, .72fr); gap: 10px; margin-bottom: 10px; }
.grid-main.lower { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.panel { min-width: 0; overflow: hidden; }
.panel-head { min-height: 68px; padding: 14px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.panel-head h2 { font-size: 14px; letter-spacing: -.01em; }
.panel-head p { margin-top: 4px; color: var(--muted); font-size: 10px; }
.panel-head > span { margin-left: auto; font-variant-numeric: tabular-nums; font-weight: 800; }
.chart-wrap { position: relative; min-height: 300px; padding: 10px; }
.chart-wrap canvas { display: block; width: 100%; height: 280px; }
#chart-empty, #hidden-chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; pointer-events: none; }
.control-panel { padding-bottom: 12px; }
.control-values { padding: 6px 16px 12px; }
.control-values > div { display: flex; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.control-values span { color: var(--muted); font-size: 11px; }
.control-values b { margin-left: auto; font-variant-numeric: tabular-nums; }
.control-panel > .button { width: calc(100% - 32px); margin: 8px 16px 0; }
.button {
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-weight: 760;
  color: var(--text);
  transition: transform .12s, opacity .12s, background .12s;
}
.button:active { transform: translateY(1px); }
.button:disabled { opacity: .38; cursor: not-allowed; }
.button.primary { background: linear-gradient(135deg, #71efaa, #34ce79); color: #06120b; }
.button.subtle { border-color: var(--line); background: var(--surface-2); }
.button.danger { border-color: rgb(255 114 123 / 22%); background: var(--red-dim); color: var(--red); }

.signal-grid { padding: 5px 16px 14px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.signal-grid > div { min-width: 0; padding: 11px 8px 9px 0; border-bottom: 1px solid var(--line); }
.signal-grid dt { color: var(--muted); font-size: 10px; }
.signal-grid dd { margin-top: 5px; overflow: hidden; text-overflow: ellipsis; font-weight: 750; font-variant-numeric: tabular-nums; }
.transport-panel { margin-bottom: 10px; }
.rest-health { margin-left: auto; display: grid; grid-template-columns: auto auto; gap: 1px 8px; text-align: right; }
.rest-health span { grid-row: span 2; align-self: center; color: var(--muted); font-size: 9px; letter-spacing: .08em; }
.rest-health b { font-size: 11px; }
.rest-health small { color: var(--muted); font-size: 9px; }
.batch-grid { padding: 12px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.batch-card { min-width: 0; padding: 10px 11px; border: 1px solid var(--line); border-radius: 11px; background: rgb(7 10 15 / 48%); }
.batch-top { display: flex; align-items: center; gap: 7px; }
.batch-top i { width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--muted); }
.batch-card.connected .batch-top i { background: var(--green-strong); }
.batch-card.error .batch-top i, .batch-card.disconnected .batch-top i { background: var(--red); }
.batch-card.reconnecting .batch-top i, .batch-card.connecting .batch-top i { background: var(--amber); }
.batch-top b { min-width: 0; overflow: hidden; text-overflow: ellipsis; font-size: 11px; }
.batch-top span { margin-left: auto; color: var(--muted); font-size: 9px; }
.batch-meta { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 4px 9px; color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; }
.batch-error { margin-top: 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--red); font-size: 9px; }
.batch-empty { padding: 18px; color: var(--muted); text-align: center; }
.trades-panel { margin-top: 0; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; white-space: nowrap; }
th, td { padding: 11px 14px; border-bottom: 1px solid var(--line); text-align: left; font-size: 11px; font-variant-numeric: tabular-nums; }
th { color: var(--muted); font-size: 9px; letter-spacing: .07em; text-transform: uppercase; }
td.number, th.number { text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
tr.empty td { height: 86px; text-align: center; color: var(--muted); }
.source-tag { display: inline-block; padding: 3px 6px; border-radius: 5px; background: var(--surface-2); color: var(--muted); font-size: 9px; }

dialog { width: min(480px, calc(100% - 24px)); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); color: var(--text); box-shadow: 0 32px 100px #000b; }
dialog::backdrop { background: rgb(0 0 0 / 76%); backdrop-filter: blur(5px); }
.dialog-card { padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.dialog-card header { display: flex; align-items: flex-start; gap: 10px; }
.dialog-card header .icon-button { margin-left: auto; }
.dialog-card h2 { font-size: 17px; }
.dialog-card header p { margin-top: 4px; color: var(--muted); font-size: 11px; }
.dialog-card label, .login-card label { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: 10px; font-weight: 650; }
input, select { width: 100%; height: 43px; padding: 0 11px; border: 1px solid var(--line); border-radius: 10px; background: #090d13; color: var(--text); }
.form-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 10px; }
.margin-preview { padding: 10px 12px; display: flex; background: var(--green-dim); border-radius: 10px; color: var(--muted); font-size: 11px; }
.margin-preview b { margin-left: auto; color: var(--green); }
.dialog-card hr { width: 100%; height: 1px; margin: 2px 0; border: 0; background: var(--line); }
.credential-state { color: var(--muted); font-size: 10px; }
.reset-button { width: 100%; }
.dialog-card footer { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 4px; }

.login-shell { min-height: calc(100dvh - 58px); padding: 20px; display: grid; place-items: center; }
.login-card { width: min(380px, 100%); padding: 28px; display: flex; flex-direction: column; gap: 18px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); }
.login-card h1 { margin: 0; font-size: 26px; }
.login-card p { color: var(--muted); }

@media (max-width: 1040px) {
  .metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: 1fr; }
}

@media (max-width: 680px) {
  body { font-size: 13px; }
  .top-inner { height: 52px; }
  .shell { padding-top: 18px; }
  .headline { align-items: flex-start; }
  .headline p { max-width: 270px; font-size: 11px; }
  .headline-actions { flex-direction: column; align-items: flex-end; }
  .strategy-tabs { overflow-x: auto; }
  .strategy-tab { flex: 1 0 auto; }
  .strategy-intro { align-items: flex-start; }
  .strategy-intro p { max-width: 270px; font-size: 11px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { min-height: 104px; padding: 13px; }
  .metric:first-child { grid-column: span 2; }
  .grid-main.lower { grid-template-columns: 1fr; }
  .batch-grid { grid-template-columns: 1fr; }
  .signal-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-wrap { min-height: 240px; }
  .chart-wrap canvas { height: 220px; }
  .trades-panel .table-scroll { overflow: visible; }
  .trades-panel table, .trades-panel tbody { display: block; }
  .trades-panel thead { display: none; }
  .trades-panel tr { margin: 10px; padding: 10px 12px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 12px; border: 1px solid var(--line); border-radius: 12px; background: rgb(8 12 17 / 55%); }
  .trades-panel td { min-width: 0; padding: 0; display: flex; flex-direction: column; border: 0; text-align: left !important; white-space: normal; }
  .trades-panel td::before { content: attr(data-label); margin-bottom: 2px; color: var(--muted); font-size: 8px; letter-spacing: .07em; text-transform: uppercase; }
  .trades-panel td:nth-child(1), .trades-panel td:nth-child(9) { grid-column: span 2; }
  .trades-panel tr.empty { display: block; padding: 24px; }
  .trades-panel tr.empty td { height: auto; }
  .trades-panel tr.empty td::before { content: none; }
}

@media (max-width: 390px) {
  .brand small { display: none; }
  .connection span { display: none; }
  .headline h1 { font-size: 27px; }
  .headline-actions .button { min-height: 36px; padding: 0 10px; }
  .form-grid { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
