:root {
  --bg: #f4f7fb;
  --bg-accent: #d8e9ff;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --line: #dbe3ee;
  --up: #047857;
  --down: #b91c1c;
  --table-head: #eef4ff;
  --mw-bg: #f6f9fd;
  --mw-card: #ffffff;
  --mw-text: #0f172a;
  --mw-muted: #4b6179;
  --mw-line: #d4e0ec;
  --mw-input-bg: #ffffff;
  --mw-input-line: #c8d7e6;
  --mw-link: #1d4ed8;
}

[data-theme="dark"] {
  --bg: #0b1420;
  --bg-accent: #12263f;
  --card: #111c2b;
  --text: #dbe8f8;
  --muted: #9ab0c7;
  --line: #2a3b50;
  --up: #34d399;
  --down: #ff6b6b;
  --table-head: #132133;
  --mw-bg: #03090f;
  --mw-card: #07131b;
  --mw-text: #d4dde8;
  --mw-muted: #8ea1b5;
  --mw-line: #203241;
  --mw-input-bg: #08131d;
  --mw-input-line: #223444;
  --mw-link: #7aa2ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Avenir Next", "PingFang SC", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at top right, var(--bg-accent), var(--bg));
}

.container {
  max-width: 1400px;
  margin: 24px auto;
  padding: 16px;
}

h1 {
  margin: 0 0 12px;
}

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 12px;
  color: var(--muted);
  flex-wrap: wrap;
}

button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

input[type="text"] {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 220px;
}

select {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 8px;
  padding: 8px 10px;
}

.limit-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

#sortControls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sort-btn.active {
  background: #dbeafe;
  border-color: #93c5fd;
  color: #1e3a8a;
}

[data-theme="dark"] .sort-btn {
  background: #1a2638;
  border-color: #31455f;
  color: #d4dde8;
}

[data-theme="dark"] .sort-btn.active {
  background: #2a3a50;
  border-color: #4a6486;
  color: #e5eefb;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  min-width: 1320px;
  border-collapse: collapse;
  background: var(--card);
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.metrics-board {
  display: block;
  margin-bottom: 12px;
}

.metrics-table {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.metrics-overview {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 10px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
}

.metrics-overview-title {
  color: var(--muted);
}

.metric-row {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
}

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

.metric-title {
  color: var(--muted);
  font-size: 13px;
}

.metric-inline {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: center;
  column-gap: 12px;
}

.metric-value {
  font-size: 13px;
  font-weight: 400;
}

.metric-moves {
  font-size: 12px;
  color: var(--muted);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
  gap: 4px 8px;
  line-height: 1.25;
}

.metric-moves span {
  text-align: right;
  white-space: nowrap;
}

.metric-placeholder {
  color: #94a3b8;
}

.chart-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.chart-card h3 {
  margin: 0 0 8px;
  font-size: 14px;
}

.chart-svg {
  width: 100%;
  height: auto;
  display: block;
}

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

.sub-metric {
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
  display: flex;
  gap: 6px;
  align-items: center;
}

.sub-change {
  font-weight: 600;
}

.price-line {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.symbol-cell a {
  display: inline-block;
  margin-bottom: 2px;
}

.cap-line {
  color: var(--muted);
  font-size: 10px;
  line-height: 1.2;
  white-space: nowrap;
}

.move-cell {
  font-size: 11px;
  padding-left: 6px;
  padding-right: 6px;
  text-align: right;
}

.withdraw-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 14px;
  height: 14px;
  padding: 0 3px;
  border-radius: 10px;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
}

th { background: var(--table-head); }

.up {
  color: var(--up);
  font-weight: 600;
}

.down {
  color: var(--down);
  font-weight: 600;
}

@media (max-width: 960px) {
  .container {
    width: 100%;
    margin: 0;
    padding: 10px;
  }

  h1 {
    font-size: 22px;
    line-height: 1.2;
  }

  .toolbar {
    gap: 8px;
  }

  #sortControls {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  button,
  input[type="text"] {
    min-height: 38px;
  }

  .sort-btn {
    padding: 8px 6px;
    font-size: 12px;
  }

  input[type="text"] {
    width: 100%;
    min-width: 0;
  }

  .table-wrap {
    border-radius: 8px;
  }

  .metrics-board {
    display: block;
  }

  .metric-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .metric-inline {
    grid-template-columns: 1fr;
    row-gap: 4px;
  }

  .metric-moves {
    font-size: 11px;
    grid-template-columns: repeat(3, minmax(56px, 1fr));
    gap: 4px 6px;
  }

  .metric-moves span {
    text-align: left;
  }

  .arb-blacklist-form {
    grid-template-columns: 1fr;
  }

  th, td {
    padding: 7px 8px;
    font-size: 11px;
  }

  .sub-metric {
    font-size: 10px;
  }
}

@media (max-width: 520px) {
  body {
    background: radial-gradient(circle at top right, var(--bg-accent), var(--bg));
  }

  .container {
    padding: 8px;
  }

  h1 {
    font-size: 19px;
  }

  #lastUpdated,
  #streamStatus,
  .toolbar a {
    font-size: 12px;
  }

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

  table {
    min-width: 1580px;
  }
}

.mw-body {
  background: var(--mw-bg);
  color: var(--mw-text);
}

.mw-container {
  max-width: 1880px;
  margin: 10px auto;
  padding: 10px;
}

.mw-toolbar {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.mw-back {
  color: var(--mw-link);
  text-decoration: none;
  font-size: 14px;
}

.mw-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mw-field label {
  font-size: 12px;
  color: var(--mw-muted);
}

.mw-field input,
.mw-field select {
  min-width: 180px;
  border: 1px solid var(--mw-input-line);
  background: var(--mw-input-bg);
  color: var(--mw-text);
  border-radius: 2px;
  padding: 8px 10px;
}

#saveRefreshBtn {
  background: #16c7c1;
  color: #001417;
  border: 1px solid #0ea8a2;
  border-radius: 2px;
  font-weight: 700;
}

#refreshBtn {
  background: var(--mw-card);
  border: 1px solid var(--mw-input-line);
  color: var(--mw-text);
  border-radius: 2px;
  font-weight: 700;
}

#updatedAt {
  color: var(--mw-muted);
  font-size: 12px;
}

.mw-table-wrap {
  display: inline-block;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid var(--mw-line);
}

.mw-table {
  width: auto;
  min-width: 0;
  border-collapse: collapse;
  background: var(--mw-bg);
  table-layout: fixed;
}

.mw-table th,
.mw-table td {
  border: 1px solid var(--mw-line);
  padding: 8px 8px;
  vertical-align: top;
}

.mw-table th {
  color: var(--mw-muted);
  background: var(--mw-card);
  text-align: left;
  font-size: 13px;
}

.mw-table th,
.mw-table td {
  width: 120px;
}

.mw-table th.mw-contract-divider,
.mw-table td.mw-contract-divider {
  border-right: 5px double var(--mw-muted);
}

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

.mw-label {
  width: 72px;
  color: var(--mw-muted);
  font-weight: 700;
  background: var(--mw-card);
}

.mw-primary {
  color: var(--mw-text);
  font-size: 12px;
  line-height: 1.15;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.mw-secondary {
  color: var(--mw-muted);
  font-size: 11px;
  line-height: 1.15;
}

.mw-ask {
  color: var(--down);
}

.mw-bid {
  color: var(--up);
}

.mw-best-bid,
.mw-best-ask {
  margin: -4px;
  padding: 4px;
  border-radius: 6px;
}

.mw-best-bid {
  background: rgba(34, 197, 94, 0.16);
}

.mw-best-ask {
  background: rgba(239, 68, 68, 0.14);
}

[data-theme="dark"] .mw-best-bid {
  background: rgba(34, 197, 94, 0.24);
}

[data-theme="dark"] .mw-best-ask {
  background: rgba(239, 68, 68, 0.22);
}

.mw-error {
  margin-top: 8px;
  color: #f59e8b;
  font-size: 12px;
}

.mw-age {
  color: var(--mw-muted);
  font-size: 11px;
  margin-left: auto;
  text-align: right;
}

.mw-age-corner {
  color: var(--mw-muted);
  font-size: 11px;
  line-height: 1.1;
  text-align: right;
  margin-left: auto;
}

.mw-trade-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mw-up {
  color: var(--up);
}

.mw-down {
  color: var(--down);
}

.mw-settings-card {
  border: 1px solid var(--mw-line);
  background: var(--mw-card);
  padding: 12px;
  max-width: 640px;
}

.mw-settings-card h2 {
  margin: 0 0 6px;
  font-size: 18px;
}

.mw-settings-card p {
  margin: 0 0 10px;
  color: var(--mw-muted);
  font-size: 12px;
}

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

.mw-settings-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--mw-line);
  padding: 8px;
  font-size: 13px;
}

.mw-settings-item input {
  width: 90px;
  border: 1px solid var(--mw-input-line);
  background: var(--mw-input-bg);
  color: var(--mw-text);
  border-radius: 2px;
  padding: 6px 8px;
}

.mw-settings-actions {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.arb-blacklist-form {
  display: grid;
  grid-template-columns: 180px 160px 160px minmax(220px, 1fr) auto;
  gap: 8px;
  align-items: center;
}

.arb-blacklist-form input,
.arb-blacklist-form select {
  min-width: 0;
}

.mw-settings-hint {
  margin-top: 8px;
  color: var(--mw-muted);
  font-size: 11px;
}

.arb-summary {
  display: inline-block;
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid var(--mw-line);
  border-radius: 10px;
  background: var(--mw-card);
  color: var(--mw-muted);
}

.arb-table {
  min-width: 1260px;
}

.arb-table th,
.arb-table td {
  width: 118px;
}

.arb-table th:first-child,
.arb-table td:first-child {
  width: 110px;
}

.arb-ok {
  display: inline-block;
  padding: 3px 7px;
  border-radius: 999px;
  color: #052e1a;
  background: #86efac;
  font-size: 12px;
}

.arb-section-title {
  margin: 18px 0 10px;
  color: var(--mw-text);
  font-size: 18px;
}

.arb-trade-table {
  min-width: 1180px;
}

.theme-toggle-btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  cursor: pointer;
}

.theme-toggle-btn.theme-floating {
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 9999;
}

[data-theme="dark"] #marketTable tbody td:first-child a {
  color: #d4dde8;
}

[data-theme="dark"] #marketTable tbody td:first-child a:visited {
  color: #d4dde8;
}

[data-theme="dark"] .mw-back,
[data-theme="dark"] #openTable td,
[data-theme="dark"] #closedTable td,
[data-theme="dark"] #openTable th,
[data-theme="dark"] #closedTable th,
[data-theme="dark"] .mw-table th,
[data-theme="dark"] .mw-table td {
  color: #d4dde8;
}
