:root {
  color-scheme: dark;
  --bg: #101214;
  --surface: #181c20;
  --surface-2: #20262b;
  --line: #303840;
  --text: #edf2f4;
  --muted: #95a1aa;
  --teal: #2fc7a6;
  --blue: #6ea8fe;
  --amber: #f4b74a;
  --red: #f87171;
  --green: #65d889;
  --shadow: rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  border-right: 1px solid var(--line);
  background: #121619;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--teal);
  color: #07110f;
  font-weight: 800;
}

.brand-title {
  font-size: 16px;
  font-weight: 750;
}

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

.nav {
  display: grid;
  gap: 4px;
  margin-top: 32px;
}

.nav-item {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 0 12px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
}

.nav-item.active,
.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.side-status {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
}

.dot.live {
  background: var(--green);
}

.dot.error {
  background: var(--red);
}

.main {
  min-width: 0;
  padding: 28px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 34px);
  line-height: 1.08;
  font-weight: 780;
}

h2 {
  font-size: 16px;
  line-height: 1.3;
}

p {
  color: var(--muted);
  line-height: 1.45;
}

#subline {
  margin-top: 8px;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.primary-button,
.secondary-button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-2);
}

.primary-button {
  min-height: 40px;
  padding: 0 16px;
  border-color: transparent;
  background: var(--teal);
  color: #07110f;
  font-weight: 750;
}

.secondary-button {
  min-height: 36px;
  padding: 0 12px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  font-weight: 800;
}

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

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

.metric-card,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 42px var(--shadow);
}

.metric-card {
  min-height: 118px;
  padding: 18px;
}

.metric-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.metric-card strong {
  display: block;
  margin-top: 12px;
  font-size: 26px;
  line-height: 1;
}

.metric-card small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 14px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel.wide {
  grid-row: span 2;
}

.panel.full {
  margin-top: 14px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-header p {
  margin-top: 4px;
  font-size: 13px;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  white-space: nowrap;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

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

.empty,
.empty-block {
  color: var(--muted);
  text-align: center;
}

.empty-block {
  display: grid;
  place-items: center;
  min-height: 120px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
}

.pill.buy,
.pill.live_buy,
.pill.dry_run_buy {
  color: var(--green);
}

.pill.sell,
.pill.live_sell,
.pill.dry_run_sell {
  color: var(--amber);
}

.pill.blocked,
.pill.skip {
  color: var(--red);
}

.risk-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.risk-list div,
.score-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  min-height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151a1e;
}

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

dd {
  margin: 0;
  font-weight: 700;
}

.score-list {
  display: grid;
  gap: 10px;
}

.score-row strong {
  font-size: 14px;
  overflow-wrap: anywhere;
}

.score-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.score-row span {
  color: var(--blue);
  font-weight: 800;
}

.score-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: right;
}

.mini-button {
  min-height: 28px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 12px;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 10;
  max-width: min(420px, calc(100vw - 44px));
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  box-shadow: 0 18px 42px var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1120px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
  }

  .nav {
    display: flex;
    margin-top: 0;
    overflow-x: auto;
  }

  .side-status {
    position: static;
    min-width: 136px;
  }

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

  .panel.wide {
    grid-column: 1 / -1;
    grid-row: auto;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 18px;
  }

  .topbar,
  .sidebar,
  .panel-header {
    align-items: stretch;
    flex-direction: column;
  }

  .metrics,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .top-actions {
    width: 100%;
  }

  .primary-button {
    flex: 1;
  }

  .leaderboard-row,
  .score-actions {
    align-items: stretch;
    flex-direction: column;
    text-align: left;
  }

  .side-status {
    width: 100%;
  }
}
