:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef3f8;
  --ink: #152033;
  --muted: #667085;
  --line: #d8e0ea;
  --line-strong: #b8c4d2;
  --blue: #2457d6;
  --blue-soft: #e8eefc;
  --green: #067647;
  --green-soft: #e7f6ee;
  --red: #c43232;
  --red-soft: #fdecec;
  --amber: #a15c00;
  --amber-soft: #fff4dc;
  --control-bg: #ffffff;
  --control-hover: #f9fbfe;
  --topbar-bg: rgba(245, 247, 251, 0.94);
  --table-head: #f8fafc;
  --row-hover: #fbfdff;
  --disabled-bg: #f1f4f8;
  --disabled-ink: #98a2b3;
  --error-border: #efc6a7;
  --primary-hover: #1e4bbb;
  --primary-ink: #ffffff;
  --brand-bg: #152033;
  --brand-ink: #ffffff;
  --spark-zero: #d8e0ea;
  --focus-shadow: rgba(36, 87, 214, 0.12);
  --shadow: 0 12px 28px rgba(21, 32, 51, 0.08);
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c0f0d;
  --panel: #151a17;
  --panel-2: #1c231f;
  --ink: #edf4ef;
  --muted: #94a39a;
  --line: #2a332e;
  --line-strong: #3d4a43;
  --blue: #6f8dff;
  --blue-soft: rgba(111, 141, 255, 0.16);
  --green: #39d98a;
  --green-soft: rgba(57, 217, 138, 0.14);
  --red: #ff7373;
  --red-soft: rgba(255, 115, 115, 0.14);
  --amber: #ffb454;
  --amber-soft: rgba(255, 180, 84, 0.14);
  --control-bg: #111612;
  --control-hover: #1b231e;
  --topbar-bg: rgba(12, 15, 13, 0.92);
  --table-head: #101511;
  --row-hover: #18201b;
  --disabled-bg: #202720;
  --disabled-ink: #657269;
  --error-border: rgba(255, 180, 84, 0.34);
  --primary-hover: #5d78e6;
  --primary-ink: #08100c;
  --brand-bg: #6f8dff;
  --brand-ink: #08100c;
  --spark-zero: #3a4540;
  --focus-shadow: rgba(111, 141, 255, 0.2);
  --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 {
  margin: 0;
  min-width: 320px;
}

button,
input,
select {
  font: inherit;
}

button,
select,
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.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: var(--primary-ink);
}

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

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

input:focus,
select:focus,
button:focus-visible {
  border-color: var(--blue);
  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;
  align-items: center;
  min-width: 0;
  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,
.tabs,
.table-section,
.error-panel {
  margin-top: 14px;
}

.control-band {
  display: grid;
  grid-template-columns:
    auto minmax(250px, 2fr) minmax(230px, 1fr) minmax(120px, 0.6fr)
    minmax(180px, 1fr);
  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;
  gap: 6px;
  min-width: 0;
}

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

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

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

.volume-range {
  width: 100%;
  min-height: 20px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  accent-color: var(--blue);
  cursor: pointer;
}

.volume-range:focus {
  box-shadow: none;
}

.volume-ticks {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.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;
}

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

.toggle input {
  width: 17px;
  min-height: 17px;
  accent-color: var(--blue);
}

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

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

.exchange-option {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--control-bg);
  color: var(--ink);
  cursor: pointer;
}

.exchange-option input {
  width: 15px;
  min-height: 15px;
  accent-color: var(--blue);
}

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

.metric {
  min-height: 74px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--ink);
  font-size: 20px;
  line-height: 1.2;
  white-space: nowrap;
}

.error-panel {
  padding: 10px 12px;
  border: 1px solid var(--error-border);
  border-radius: 8px;
  background: var(--amber-soft);
  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 - 310px);
}

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

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

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

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

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

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

th[data-sort]::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 6px;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  vertical-align: middle;
}

th.sorted-asc::after {
  border-bottom: 5px solid var(--blue);
}

th.sorted-desc::after {
  border-top: 5px solid var(--blue);
}

.num {
  text-align: right;
}

.symbol-cell {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 96px;
}

.symbol-pill,
.tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--control-bg);
  font-weight: 750;
  white-space: nowrap;
}

.tag {
  min-height: 22px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.rate-positive {
  color: var(--green);
}

.rate-negative {
  color: var(--red);
}

.rate-flat {
  color: var(--muted);
}

.soft-positive,
.soft-negative,
.soft-flat {
  display: inline-block;
  min-width: 78px;
  padding: 3px 7px;
  border-radius: 8px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.soft-positive {
  background: var(--green-soft);
  color: var(--green);
}

.soft-negative {
  background: var(--red-soft);
  color: var(--red);
}

.soft-flat {
  background: var(--panel-2);
  color: var(--muted);
}

.mono {
  font-variant-numeric: tabular-nums;
}

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

.direction {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.direction strong {
  font-weight: 760;
}

.spark {
  width: 118px;
  height: 28px;
}

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

.hidden {
  display: none !important;
}

.loading {
  opacity: 0.58;
  pointer-events: none;
}

@media (max-width: 980px) {
  .control-band {
    grid-template-columns: 1fr 1fr;
  }

  .field.wide {
    grid-column: 1 / -1;
  }

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

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

@media (max-width: 620px) {
  .topbar {
    position: static;
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

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

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

  .mobile-controls-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    min-height: 42px;
    margin-top: 2px;
    border-color: var(--line);
    background: var(--panel);
    color: var(--ink);
    font-weight: 750;
  }

  .mobile-controls-toggle::after {
    content: "+";
    color: var(--blue);
    font-size: 20px;
    line-height: 1;
  }

  .dashboard-controls {
    display: none;
  }

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

  body.mobile-controls-open .mobile-controls-toggle::after {
    content: "-";
  }

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