:root {
  color-scheme: dark;
  --bg: #07111f;
  --surface: #0d1b2e;
  --surface-2: #13243a;
  --surface-3: #1b3656;
  --text: #edf6ff;
  --muted: #8aa5c2;
  --line: #1b3656;
  --buy: #00c2a8;
  --buy-soft: rgba(14, 203, 129, 0.16);
  --sell: #ff5f73;
  --sell-soft: rgba(246, 70, 93, 0.16);
  --accent: #00a7ff;
  --accent-2: #6dd6ff;
  --accent-soft: rgba(0, 167, 255, 0.14);
  --warning: #4dbdff;
  --warning-soft: rgba(77, 189, 255, 0.14);
}

* {
  box-sizing: border-box;
}

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

.app {
  width: min(1440px, calc(100% - 24px));
  margin: 0 auto;
  padding: 14px 0 28px;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 62px;
  margin-bottom: 10px;
  padding: 0 2px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(22px, 2.4vw, 32px);
  line-height: 1.12;
  font-weight: 800;
}

.controls {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.field {
  display: grid;
  gap: 4px;
}

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

select,
button,
input {
  height: 34px;
  border: 1px solid var(--surface-3);
  border-radius: 4px;
  color: var(--text);
  font: inherit;
}

select,
input {
  min-width: 104px;
  padding: 0 10px;
  background: var(--surface-2);
}

input {
  width: 160px;
}

button {
  padding: 0 16px;
  border-color: var(--accent);
  background: var(--accent);
  color: #03111f;
  font-weight: 800;
  cursor: pointer;
}

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

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

.summary article,
.panel {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}

.summary article {
  position: relative;
  min-height: 106px;
  overflow: hidden;
  padding: 14px 14px 12px;
}

.summary article::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: var(--accent);
}

.summary article:nth-child(1)::before {
  background: var(--sell);
}

.summary article:nth-child(2)::before {
  background: var(--buy);
}

.summary article:nth-child(4)::before {
  background: var(--accent);
}

.summary span,
.summary small,
.panel-title span,
td small {
  display: block;
  color: var(--muted);
}

.summary span,
.arb-summary span {
  font-size: 12px;
  font-weight: 800;
}

.summary strong {
  display: block;
  margin: 8px 0 5px;
  font-size: 28px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  margin-bottom: 8px;
  padding: 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--muted);
}

.status-dot.ok {
  background: var(--buy);
  box-shadow: 0 0 0 3px rgba(14, 203, 129, 0.12);
}

.status-dot.error {
  background: var(--warning);
  box-shadow: 0 0 0 3px rgba(77, 189, 255, 0.14);
}

#updatedAt {
  margin-left: auto;
}

.module-nav {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin: 6px 0 14px;
  padding: 0 22px;
}

.module-nav button {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 66px;
  padding: 0 18px;
  border: 1px solid #244768;
  background: linear-gradient(180deg, #142a45 0%, var(--surface) 100%);
  color: var(--text);
  font-size: 16px;
  font-weight: 900;
  text-align: center;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  transition:
    border-color 0.16s ease,
    background 0.16s ease,
    color 0.16s ease,
    transform 0.16s ease;
}

.module-nav button::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: transparent;
}

.module-nav button:hover {
  border-color: var(--accent);
  background: #162f4d;
  color: var(--accent);
  transform: translateY(-1px);
}

.module-nav button.active {
  border-color: var(--accent);
  background: linear-gradient(180deg, var(--accent-2) 0%, var(--accent) 100%);
  color: #03111f;
  box-shadow:
    0 0 0 1px rgba(0, 167, 255, 0.36),
    0 8px 20px rgba(0, 167, 255, 0.18);
}

.module-nav button.active::before {
  background: #03111f;
}

.quick-board {
  margin-bottom: 8px;
}

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

.quick-grid article {
  min-height: 104px;
  padding: 14px;
  border-right: 1px solid var(--line);
  background: #0a1728;
}

.quick-grid article:last-child {
  border-right: 0;
}

.quick-grid span,
.quick-grid small {
  display: block;
  color: var(--muted);
}

.quick-grid span {
  font-size: 12px;
  font-weight: 800;
}

.quick-grid strong {
  display: block;
  margin: 8px 0 6px;
  color: var(--accent);
  font-size: 20px;
}

.quick-grid small {
  line-height: 1.5;
}

.app > .module-panel {
  display: none;
}

.app > .module-panel.active {
  display: block;
}

.app > .exchange-books.module-panel.active {
  display: grid;
}

.comparison,
.decision-panel,
.arbitrage {
  margin-bottom: 8px;
  overflow: hidden;
}

.decision-panel {
  border-color: rgba(0, 167, 255, 0.5);
}

.decision-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: #0a1728;
}

.decision-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.decision-summary article {
  min-height: 98px;
  padding: 14px;
  border-right: 1px solid var(--line);
}

.decision-summary article:last-child {
  border-right: 0;
}

.decision-summary span,
.decision-summary small {
  display: block;
  color: var(--muted);
}

.decision-summary span {
  font-size: 12px;
  font-weight: 800;
}

.decision-summary strong {
  display: block;
  margin: 7px 0 4px;
  color: var(--accent);
  font-size: 25px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.split-plan {
  border-bottom: 1px solid var(--line);
  background: #0a1728;
}

.split-plan-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.split-plan-head h3 {
  padding: 0;
  color: var(--text);
}

.split-plan-head span {
  color: var(--accent);
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.fee-config {
  border-top: 1px solid var(--line);
  background: #0a1728;
}

.fee-config-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
}

.fee-config-head h3 {
  padding: 0;
  color: var(--text);
}

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

.fee-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0;
}

.fee-item {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border-right: 1px solid var(--line);
}

.fee-item:last-child {
  border-right: 0;
}

.fee-item strong {
  font-size: 13px;
}

.fee-item label {
  display: grid;
  gap: 4px;
}

.fee-item input {
  width: 100%;
  min-width: 0;
  height: 30px;
}

.arbitrage {
  border-color: rgba(0, 167, 255, 0.35);
}

.arb-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.arb-summary article {
  min-height: 92px;
  padding: 14px;
  border-right: 1px solid var(--line);
}

.arb-summary article:last-child {
  border-right: 0;
}

.arb-summary span,
.arb-summary small {
  display: block;
  color: var(--muted);
}

.arb-summary strong {
  display: block;
  margin: 7px 0 4px;
  font-size: 24px;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

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

.exchange-books {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.fx-panel {
  margin-top: 8px;
  overflow: hidden;
}

.market-chart {
  margin-top: 8px;
  overflow: hidden;
}

.chart-layout {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(320px, 0.9fr);
  gap: 0;
  min-height: 340px;
}

.chart-area {
  min-height: 340px;
  padding: 14px;
  border-right: 1px solid var(--line);
}

#priceChart {
  display: block;
  width: 100%;
  height: 320px;
}

.depth-legend {
  display: grid;
  align-content: start;
}

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

.depth-item:last-child {
  border-bottom: 0;
}

.depth-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 9px;
}

.depth-head span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 800;
}

.depth-head i {
  width: 8px;
  height: 8px;
  border-radius: 999px;
}

.depth-head strong {
  color: var(--muted);
  font-size: 12px;
}

.depth-bars {
  display: grid;
  gap: 6px;
  margin-bottom: 8px;
}

.depth-bar {
  position: relative;
  min-height: 28px;
  overflow: hidden;
  padding: 6px 8px;
  background: #0a1728;
  color: var(--text);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.depth-bar::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: var(--bar-width, 0%);
  opacity: 0.92;
}

.depth-bar.bid::before {
  background: var(--buy-soft);
}

.depth-bar.ask::before {
  background: var(--sell-soft);
}

.depth-bar span {
  position: relative;
  z-index: 1;
}

.depth-item small {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.ai-summary {
  border-top: 1px solid var(--line);
  background: #0a1728;
}

.ai-summary-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px 8px;
}

.ai-summary-head h3 {
  padding: 0;
  color: var(--accent-2);
  font-size: 13px;
  letter-spacing: 0;
  text-transform: none;
}

.ai-summary-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-align: right;
}

.ai-summary-body {
  display: grid;
  gap: 8px;
  padding: 0 14px 14px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.62;
}

.ai-summary-body p {
  margin: 0;
}

.ai-summary-body strong {
  color: var(--accent-2);
}

.fx-note {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  background: #0a1728;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.fx-panel > .fx-note {
  border-top: 0;
  border-bottom: 1px solid var(--line);
}

.panel {
  overflow: hidden;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.panel-title h2 {
  font-size: 16px;
  font-weight: 800;
}

.panel-title strong {
  padding: 5px 9px;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart-tools {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chart-tools select {
  height: 30px;
  min-width: 86px;
  font-size: 13px;
}

.book-error {
  margin: 0;
  padding: 9px 14px;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 12px;
}

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

.book-grid > div:first-child {
  border-right: 1px solid var(--line);
}

h3 {
  padding: 10px 12px 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

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

th:first-child,
td:first-child {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

td {
  font-size: 13px;
}

tbody tr:hover {
  background: rgba(43, 49, 57, 0.56);
}

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

.ask-price {
  color: var(--sell);
  font-weight: 700;
}

.bid-price {
  color: var(--buy);
  font-weight: 700;
}

.status-good,
.status-bad,
.status-muted,
.opportunity-good,
.opportunity-none {
  max-width: 320px;
  white-space: normal;
}

.status-good {
  color: var(--buy);
  font-weight: 800;
}

.status-bad {
  color: var(--warning);
}

.status-muted,
.opportunity-none {
  color: var(--muted);
}

.opportunity-good {
  color: var(--buy);
  font-weight: 800;
}

.depth-cell {
  position: relative;
  overflow: hidden;
}

.depth-cell span {
  position: relative;
  z-index: 1;
}

.depth-cell::before {
  content: "";
  position: absolute;
  inset: 3px 0 3px auto;
  width: var(--depth-width, 0%);
  opacity: 0.9;
}

.ask-row .depth-cell::before {
  background: var(--sell-soft);
}

.bid-row .depth-cell::before {
  background: var(--buy-soft);
}

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

a {
  color: var(--accent);
  font-weight: 700;
  text-decoration: none;
}

a:hover {
  color: var(--accent-2);
}

.toast-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
}

.toast-modal.hidden {
  display: none;
}

.toast-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.toast-dialog {
  position: relative;
  z-index: 1;
  width: min(420px, calc(100% - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

.toast-header {
  padding: 14px 16px 10px;
  border-bottom: 1px solid var(--line);
}

.toast-header strong {
  color: var(--accent);
  font-size: 16px;
}

.toast-body {
  padding: 16px;
}

.toast-body p {
  margin: 0 0 10px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
}

.toast-body small {
  color: var(--muted);
  font-size: 12px;
}

.toast-actions {
  display: flex;
  justify-content: flex-end;
  padding: 0 16px 16px;
}

#toastConfirm {
  min-width: 92px;
}

@media (max-width: 1000px) {
  .summary,
  .module-nav,
  .quick-grid,
  .decision-summary,
  .fee-grid,
  .arb-summary,
  .exchange-books {
    grid-template-columns: 1fr 1fr;
  }

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

  .chart-layout {
    grid-template-columns: 1fr;
  }

  .chart-area {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .book-grid > div:first-child {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 720px) {
  .toolbar,
  .panel-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .chart-tools {
    width: 100%;
    justify-content: space-between;
  }

  .controls {
    width: 100%;
    justify-content: space-between;
  }

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

  .split-plan-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .split-plan-head span {
    text-align: left;
  }

  .decision-controls input,
  .decision-controls select {
    width: 100%;
  }

  .summary,
  .module-nav,
  .quick-grid,
  .decision-summary,
  .fee-grid,
  .arb-summary,
  .exchange-books {
    grid-template-columns: 1fr;
  }

  .fee-config-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .fee-item {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .fee-item:last-child {
    border-bottom: 0;
  }

  .decision-summary article {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .decision-summary article:last-child {
    border-bottom: 0;
  }

  .arb-summary article {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .arb-summary article:last-child {
    border-bottom: 0;
  }

  #updatedAt {
    margin-left: 0;
  }

  .module-nav button {
    text-align: center;
  }

  .quick-grid article {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .quick-grid article:last-child {
    border-bottom: 0;
  }
}
