:root {
  color-scheme: light;
  --bg: #f4f6f4;
  --panel: #ffffff;
  --panel-2: #edf2ee;
  --ink: #15201b;
  --muted: #66726b;
  --line: #d8e0dc;
  --line-strong: #afbeb6;
  --accent: #0f766e;
  --accent-hover: #0b5f59;
  --accent-soft: #dff5f1;
  --green: #067647;
  --green-soft: #e4f7ec;
  --red: #c43232;
  --red-soft: #fdecec;
  --amber: #9f6a05;
  --amber-soft: #fff4d8;
  --control-bg: #ffffff;
  --control-hover: #f8fbf9;
  --topbar-bg: rgba(244, 246, 244, 0.94);
  --table-head: #f8faf9;
  --row-hover: #fbfdfc;
  --disabled-bg: #eef2ef;
  --disabled-ink: #98a49d;
  --brand-bg: #15201b;
  --brand-ink: #ffffff;
  --focus-shadow: rgba(15, 118, 110, 0.14);
  --shadow: 0 12px 28px rgba(21, 32, 27, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1210;
  --panel: #171c19;
  --panel-2: #202722;
  --ink: #edf4ef;
  --muted: #98a59d;
  --line: #2d3731;
  --line-strong: #465248;
  --accent: #5eead4;
  --accent-hover: #7cf4df;
  --accent-soft: rgba(94, 234, 212, 0.13);
  --green: #4ade80;
  --green-soft: rgba(74, 222, 128, 0.14);
  --red: #ff7777;
  --red-soft: rgba(255, 119, 119, 0.14);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.15);
  --control-bg: #111612;
  --control-hover: #1d241f;
  --topbar-bg: rgba(15, 18, 16, 0.92);
  --table-head: #111612;
  --row-hover: #1a211d;
  --disabled-bg: #202720;
  --disabled-ink: #68746d;
  --brand-bg: #5eead4;
  --brand-ink: #08110e;
  --focus-shadow: rgba(94, 234, 212, 0.18);
  --shadow: 0 18px 34px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
  color: var(--ink);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

body {
  min-width: 320px;
  margin: 0;
}

button,
input {
  font: inherit;
}

button,
input {
  border: 1px solid var(--line);
  border-radius: 8px;
}

button {
  min-height: 36px;
  padding: 0 14px;
  background: var(--panel);
  color: var(--ink);
  cursor: pointer;
  transition:
    background 0.15s ease,
    border-color 0.15s ease,
    color 0.15s ease,
    transform 0.15s ease;
}

button:hover {
  border-color: var(--line-strong);
  background: var(--control-hover);
}

button:active {
  transform: translateY(1px);
}

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

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

:root[data-theme="dark"] button.primary {
  color: #06201b;
}

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

input {
  width: 100%;
  min-height: 36px;
  padding: 0 10px;
  background: var(--control-bg);
  color: var(--ink);
  outline: none;
}

input:focus,
button:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-shadow);
}

input:disabled {
  background: var(--disabled-bg);
  color: var(--disabled-ink);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 14px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: var(--topbar-bg);
  backdrop-filter: blur(14px);
}

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

.brand-mark {
  display: grid;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 8px;
  background: var(--brand-bg);
  color: var(--brand-ink);
  font-weight: 800;
}

h1 {
  margin: 0;
  font-size: clamp(20px, 2vw, 26px);
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.top-actions {
  display: flex;
  flex: 0 0 auto;
  gap: 8px;
}

main {
  width: min(1560px, 100%);
  margin: 0 auto;
  padding: 18px clamp(12px, 2.5vw, 28px) 34px;
}

.mobile-controls-toggle {
  display: none;
}

.control-band,
.exchange-band,
.metrics,
.table-section,
.error-panel {
  margin-top: 14px;
}

.control-band {
  display: grid;
  grid-template-columns: auto minmax(250px, 1.4fr) minmax(260px, 1fr) minmax(220px, 0.8fr);
  gap: 12px;
  align-items: end;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.field {
  display: grid;
  min-width: 0;
  gap: 6px;
}

.field span,
.toggle span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.toggle {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  gap: 8px;
  padding: 0 8px;
  white-space: nowrap;
}

.toggle input,
.exchange-pill input {
  width: 16px;
  height: 16px;
  min-height: 16px;
  accent-color: var(--accent);
}

.volume-field > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.volume-field strong {
  color: var(--ink);
  font-size: 12px;
}

.volume-range {
  height: 36px;
  padding: 0;
  accent-color: var(--accent);
}

.volume-ticks {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  color: var(--muted);
  font-size: 11px;
}

.volume-ticks span {
  overflow: hidden;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.volume-ticks span:first-child {
  text-align: left;
}

.volume-ticks span:last-child {
  text-align: right;
}

.exchange-band {
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.exchange-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.exchange-pill {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  gap: 8px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--ink);
}

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

.metric {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

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

.metric strong {
  overflow: hidden;
  font-size: 20px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.error-panel {
  display: grid;
  gap: 8px;
  padding: 12px 14px;
  border: 1px solid color-mix(in srgb, var(--amber), transparent 58%);
  border-radius: 8px;
  background: var(--amber-soft);
  color: var(--ink);
}

.error-panel.hidden {
  display: none;
}

.error-item {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.error-item strong {
  color: var(--amber);
}

.table-section {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.table-scroll {
  overflow: auto;
  max-height: calc(100vh - 280px);
}

table {
  width: 100%;
  min-width: 1240px;
  border-collapse: separate;
  border-spacing: 0;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  border-bottom: 1px solid var(--line);
  background: var(--table-head);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

tbody tr:hover {
  background: var(--row-hover);
}

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

th[data-sort] {
  cursor: pointer;
  user-select: none;
}

th[data-sort]::after {
  display: inline-block;
  width: 12px;
  margin-left: 4px;
  color: var(--muted);
  content: "";
}

th[data-sort][data-dir="asc"]::after {
  content: "↑";
}

th[data-sort][data-dir="desc"]::after {
  content: "↓";
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.price {
  color: var(--ink);
  font-weight: 650;
}

.positive {
  color: var(--green);
  font-weight: 700;
}

.negative {
  color: var(--red);
  font-weight: 700;
}

.flat {
  color: var(--muted);
  font-weight: 650;
}

.symbol-cell {
  display: grid;
  gap: 2px;
}

.symbol-cell strong {
  font-size: 14px;
  line-height: 1.2;
}

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

.exchange-tag {
  display: inline-grid;
  min-width: 70px;
  min-height: 26px;
  place-items: center;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 750;
}

code {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.pair-link {
  color: var(--accent);
  text-decoration: none;
}

.pair-link:hover {
  text-decoration: underline;
}

.pair-link code {
  color: inherit;
}

.empty {
  height: 180px;
  color: var(--muted);
  text-align: center;
}

.row-limit td {
  background: var(--table-head);
  color: var(--muted);
  text-align: center;
}

.row-limit span {
  display: inline-block;
  margin-right: 10px;
}

.row-limit button {
  min-height: 30px;
  padding: 0 12px;
}

@media (max-width: 980px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .top-actions button {
    flex: 1 1 0;
  }

  .mobile-controls-toggle {
    display: block;
    width: 100%;
  }

  .dashboard-controls {
    display: none;
  }

  .dashboard-controls.open {
    display: block;
  }

  .control-band {
    grid-template-columns: 1fr;
  }

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

  .table-scroll {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .metrics {
    grid-template-columns: 1fr;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
  }

  h1 {
    font-size: 20px;
  }
}
