:root {
  color-scheme: light;
  --sidebar: #132127;
  --sidebar-hover: #1c3037;
  --sidebar-text: #9fb0b7;
  --bg: #f3f5f7;
  --surface: #ffffff;
  --text: #19232c;
  --muted: #71808d;
  --line: #e1e6ea;
  --line-strong: #cdd5db;
  --accent: #167c72;
  --accent-dark: #0f625a;
  --accent-soft: #e9f4f2;
  --danger: #b44040;
  --danger-soft: #fff0f0;
  --warning: #a76a16;
  --console: #172228;
  --sidebar-width: 220px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: #9eabb4;
  background: #f8fafb;
}

button:disabled,
button:disabled:hover {
  cursor: not-allowed;
  opacity: 0.45;
}

button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

button.primary:hover {
  border-color: var(--accent-dark);
  background: var(--accent-dark);
}

button.danger {
  border-color: #e6baba;
  color: var(--danger);
  background: var(--danger-soft);
}

input,
select {
  width: 100%;
  min-height: 36px;
  padding: 6px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  outline: none;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 19px;
  font-weight: 650;
}

h2 {
  font-size: 15px;
  font-weight: 650;
}

h3 {
  font-size: 13px;
}

code {
  font-family: Consolas, monospace;
  font-size: 12px;
}

.appShell {
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  display: flex;
  width: var(--sidebar-width);
  flex-direction: column;
  background: var(--sidebar);
  color: #fff;
}

.brand {
  display: flex;
  align-items: center;
  min-height: 72px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  gap: 11px;
}

.brandMark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 6px;
  background: #f4fbfa;
  color: var(--sidebar);
  font-size: 19px;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 16px;
}

.brand span {
  margin-top: 2px;
  color: var(--sidebar-text);
  font-size: 11px;
}

.navList {
  display: grid;
  gap: 3px;
  padding: 14px 10px;
}

.navItem {
  display: flex;
  min-height: 42px;
  align-items: center;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--sidebar-text);
  gap: 11px;
  text-align: left;
}

.navItem:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.navItem.active {
  background: #20373d;
  color: #fff;
}

.navItem.active::before {
  position: absolute;
  left: 0;
  width: 3px;
  height: 24px;
  background: #58b5a9;
  content: "";
}

.navIcon {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 4px;
  font-size: 9px;
  font-variant-numeric: tabular-nums;
}

.sidebarFoot {
  display: flex;
  align-items: center;
  margin-top: auto;
  padding: 16px 18px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  gap: 9px;
}

.sidebarFoot strong,
.sidebarFoot span {
  display: block;
}

.sidebarFoot strong {
  font-size: 12px;
  font-weight: 600;
}

.sidebarFoot span:last-child {
  margin-top: 2px;
  color: var(--sidebar-text);
  font-size: 10px;
}

.statusDot {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #35a77a;
  box-shadow: 0 0 0 3px rgba(53, 167, 122, 0.12);
}

.statusDot.error {
  background: var(--danger);
  box-shadow: 0 0 0 3px rgba(180, 64, 64, 0.14);
}

.workspace {
  min-height: 100vh;
  margin-left: var(--sidebar-width);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  padding: 0 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}

.topbarTitle,
.toolbar,
.buttonRow,
.orderActions {
  display: flex;
  align-items: center;
  gap: 9px;
}

.topbarTitle p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.runtimeBadge {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid #cfe4df;
  border-radius: 5px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  gap: 7px;
}

.menuButton {
  display: none;
}

.content {
  padding: 18px 22px 30px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.metricStrip {
  display: grid;
  grid-template-columns: repeat(6, minmax(112px, 1fr)) minmax(170px, 1.3fr);
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.metric {
  min-width: 0;
  min-height: 92px;
  padding: 14px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric span,
.metric strong,
.metric small {
  display: block;
}

.metric span {
  color: var(--muted);
  font-size: 11px;
}

.metric strong {
  overflow: hidden;
  margin-top: 8px;
  font-size: 21px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.metric small {
  margin-top: 4px;
  color: #94a0a9;
  font-size: 10px;
}

.sectionBlock {
  margin-bottom: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
}

.sectionHead {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  gap: 14px;
}

.sectionHead p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.detailGrid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 0;
  padding: 4px 14px 14px;
}

.detailGrid > div {
  min-width: 0;
  padding: 13px 12px 6px 0;
}

.detailGrid dt,
.detailGrid dd {
  margin: 0;
}

.detailGrid dt {
  color: var(--muted);
  font-size: 11px;
}

.detailGrid dd {
  overflow: hidden;
  margin-top: 5px;
  font-family: Consolas, monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.configRows {
  padding: 5px 14px 13px;
}

.configRows > div {
  display: grid;
  grid-template-columns: 170px 1fr;
  min-height: 31px;
  align-items: center;
  border-bottom: 1px solid #f0f2f4;
  font-size: 12px;
}

.configRows > div:last-child {
  border-bottom: 0;
}

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

.configRows strong {
  font-weight: 600;
}

.okText {
  color: var(--accent);
}

.badText {
  color: var(--danger);
}

.warnText {
  color: var(--warning);
}

.overviewColumns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.overviewColumns .sectionBlock {
  margin: 0;
}

.emptyState {
  display: grid;
  min-height: 120px;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.tradeLayout {
  display: grid;
  grid-template-columns: minmax(390px, 1.05fr) minmax(440px, 1.2fr);
  align-items: start;
  gap: 14px;
}

.marketFilters {
  display: grid;
  grid-template-columns: 1fr 115px 115px 145px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
}

.marketList {
  max-height: calc(100vh - 296px);
  min-height: 420px;
  overflow: auto;
}

.marketItem {
  display: grid;
  width: 100%;
  min-height: 92px;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  text-align: left;
}

.marketItem:hover,
.marketItem.active {
  background: #f3f8f7;
}

.marketItem strong,
.marketItem span {
  display: block;
}

.marketItem strong {
  overflow: hidden;
  font-size: 13px;
  line-height: 1.4;
  text-overflow: ellipsis;
}

.marketItem span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 10px;
}

.marketFacts {
  display: flex;
  flex-wrap: wrap;
  margin-top: 7px;
  gap: 6px 13px;
}

.marketFacts span {
  margin: 0;
  color: #64737e;
  font-size: 10px;
}

.marketFacts strong {
  display: inline;
  color: var(--text);
  font-size: 10px;
  font-weight: 600;
}

.rewardRate {
  min-width: 76px;
  color: var(--warning);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.marketPrice {
  min-width: 58px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-align: right;
}

.marketQuote {
  display: grid;
  justify-items: end;
  gap: 8px;
}

.marketPager {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  background: #f8fafb;
}

.marketPager span {
  color: var(--muted);
  font-size: 11px;
}

.formGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 14px;
  gap: 11px;
}

.marketStatsBar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #f8fafb;
}

.marketStatsBar > div {
  min-width: 0;
  padding: 10px 12px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.marketStatsBar > div:nth-child(3n) {
  border-right: 0;
}

.marketStatsBar > div:nth-last-child(-n + 3) {
  border-bottom: 0;
}

.marketStatsBar span,
.marketStatsBar strong {
  display: block;
}

.marketStatsBar span {
  color: var(--muted);
  font-size: 10px;
}

.marketStatsBar strong {
  overflow: hidden;
  margin-top: 5px;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.checkLabel {
  display: flex;
  min-height: 36px;
  align-items: center;
  align-self: end;
  color: var(--text);
  gap: 8px;
}

.checkLabel input {
  width: 17px;
  min-height: 17px;
}

.buttonRow {
  justify-content: flex-end;
  padding: 0 14px 14px;
}

.bookHead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.bookHead span {
  color: var(--muted);
  font-size: 10px;
}

.segmented {
  display: inline-flex;
  padding: 2px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #eef2f4;
}

.segmented button {
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
}

.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(20, 35, 42, 0.12);
}

.bookView {
  min-height: 250px;
  max-height: 360px;
  overflow: auto;
}

.bookColumns {
  display: grid;
  grid-template-columns: 1fr 1fr;
}

.bookSide {
  min-width: 0;
  overflow-x: auto;
  padding: 10px 14px;
}

.bookSide:first-child {
  border-right: 1px solid var(--line);
}

.bookSide h4 {
  margin: 0 0 8px;
  font-size: 11px;
}

.bookTableHead,
.bookRow {
  display: grid;
  min-width: 320px;
  grid-template-columns: 38px 44px minmax(54px, 0.8fr) minmax(78px, 1fr) minmax(86px, 1.1fr);
  align-items: center;
  gap: 4px;
}

.bookTableHead {
  padding: 5px 0 7px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 9px;
}

.bookRow {
  padding: 5px 0;
  border-bottom: 1px solid #f1f3f4;
  font-family: Consolas, monospace;
  font-size: 11px;
}

.bookRow strong {
  font-family: Inter, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  font-size: 10px;
}

.bookSide.bid h4,
.bookSide.bid .bookRow strong {
  color: var(--accent);
}

.bookSide.ask h4,
.bookSide.ask .bookRow strong {
  color: var(--danger);
}

.orderActions {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.orderActions input {
  flex: 1;
}

.tableWrap {
  width: 100%;
  overflow: auto;
}

.dataTable {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.dataTable th,
.dataTable td {
  max-width: 280px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dataTable th {
  background: #f8fafb;
  color: var(--muted);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
}

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

.pill {
  display: inline-flex;
  min-height: 22px;
  align-items: center;
  padding: 0 7px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 10px;
  font-weight: 600;
}

.pill.sell {
  background: var(--danger-soft);
  color: var(--danger);
}

.consoleOutput {
  min-height: 320px;
  max-height: 620px;
  margin: 0;
  overflow: auto;
  padding: 14px;
  border: 0;
  background: var(--console);
  color: #d7e3e7;
  font-family: Consolas, monospace;
  font-size: 11px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.narrowBlock {
  max-width: 1050px;
}

.settingsList {
  margin: 0;
}

.settingsList > div {
  display: grid;
  grid-template-columns: 190px 1fr;
  min-height: 48px;
  align-items: center;
  padding: 0 14px;
  border-bottom: 1px solid var(--line);
}

.settingsList dt,
.settingsList dd {
  margin: 0;
}

.settingsList dt {
  color: var(--muted);
  font-size: 11px;
}

.settingsList dd {
  overflow: hidden;
  font-family: Consolas, monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settingsHint {
  padding: 13px 14px;
  color: var(--muted);
  font-size: 11px;
}

@media (max-width: 1280px) {
  .metricStrip {
    grid-template-columns: repeat(4, minmax(120px, 1fr));
  }

  .metric {
    border-bottom: 1px solid var(--line);
  }

  .metric:nth-child(4n) {
    border-right: 0;
  }

  .metric:nth-last-child(-n + 3) {
    border-bottom: 0;
  }
}

@media (max-width: 980px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 160ms ease;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .workspace {
    margin-left: 0;
  }

  .menuButton {
    display: inline-block;
  }

  .tradeLayout,
  .overviewColumns {
    grid-template-columns: 1fr;
  }

  .marketList {
    max-height: 480px;
  }
}

@media (max-width: 720px) {
  .topbar {
    min-height: auto;
    align-items: flex-start;
    flex-direction: column;
    padding: 12px;
    gap: 10px;
  }

  .topbarTitle,
  .toolbar {
    width: 100%;
  }

  .topbarTitle > div {
    min-width: 0;
  }

  .topbarTitle p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

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

  .runtimeBadge {
    display: none;
  }

  .toolbar button {
    width: 100%;
  }

  .content {
    padding: 12px;
  }

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

  .metric,
  .metric:nth-child(4n),
  .metric:nth-last-child(-n + 3) {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .metric:nth-child(2n) {
    border-right: 0;
  }

  .metric:last-child {
    border-bottom: 0;
  }

  .metric.wide {
    grid-column: span 2;
    border-right: 0;
  }

  .detailGrid,
  .formGrid {
    grid-template-columns: 1fr;
  }

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

  .marketStatsBar > div,
  .marketStatsBar > div:nth-child(3n),
  .marketStatsBar > div:nth-last-child(-n + 3) {
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
  }

  .marketStatsBar > div:nth-child(2n) {
    border-right: 0;
  }

  .marketStatsBar > div:nth-last-child(-n + 2) {
    border-bottom: 0;
  }

  .marketFilters {
    grid-template-columns: 1fr;
  }

  .sectionHead,
  .orderActions {
    align-items: stretch;
    flex-direction: column;
  }

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

  .configRows > div,
  .settingsList > div {
    grid-template-columns: 1fr;
    align-content: center;
    gap: 4px;
  }
}
