:root {
  color-scheme: dark;
  --bg: #050806;
  --panel: #09100c;
  --panel-2: #0e1712;
  --line: #183123;
  --muted: #7fa18d;
  --text: #ecfff4;
  --cyan: #8affd2;
  --green: #39ff88;
  --amber: #b7f75d;
  --red: #ff6b7a;
  --blue: #68ffc0;
  --shadow: 0 18px 70px rgba(0, 0, 0, 0.42), 0 0 34px rgba(57, 255, 136, 0.07);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(57, 255, 136, 0.08), transparent 42%),
    linear-gradient(180deg, rgba(5, 8, 6, 0.78), rgba(5, 8, 6, 1)),
    var(--bg);
  color: var(--text);
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background-image:
    linear-gradient(rgba(57, 255, 136, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(57, 255, 136, 0.045) 1px, transparent 1px);
  background-size: 52px 52px;
}

button,
input {
  font: inherit;
}

.shell {
  width: min(1480px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.topbar,
.controls,
.metric-grid,
.workspace,
.tables {
  display: grid;
  gap: 16px;
}

.topbar {
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 18px;
}

.kicker {
  margin: 0 0 6px;
  color: var(--cyan);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.14em;
}

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

h1 {
  font-size: clamp(38px, 6vw, 82px);
  line-height: 0.92;
}

h2 {
  font-size: 22px;
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
}

.badge {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(13, 18, 24, 0.75);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.badge.live {
  color: var(--green);
  border-color: rgba(57, 255, 136, 0.45);
}

.badge.demo {
  color: var(--amber);
  border-color: rgba(243, 188, 85, 0.45);
}

.icon-button {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.icon-button:hover,
.segmented button:hover {
  border-color: rgba(57, 255, 136, 0.55);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.panel-expand {
  position: relative;
  z-index: 1;
  flex: 0 0 auto;
}

.controls {
  grid-template-columns: auto minmax(145px, 180px) minmax(145px, 180px) auto minmax(150px, 240px);
  align-items: end;
  margin-bottom: 16px;
}

.segmented {
  display: flex;
  gap: 4px;
  min-height: 42px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 18, 24, 0.85);
}

.segmented button {
  min-width: 66px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.segmented button.active {
  background: #102219;
  color: var(--text);
  border-color: rgba(57, 255, 136, 0.36);
  box-shadow: inset 0 0 0 1px rgba(57, 255, 136, 0.1);
}

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.field input {
  height: 50px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13, 18, 24, 0.8);
  color: var(--text);
  color-scheme: dark;
  padding: 0 14px;
  outline: none;
}

.field input:focus {
  border-color: rgba(57, 255, 136, 0.75);
  box-shadow: 0 0 0 3px rgba(57, 255, 136, 0.08);
}

.metric-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 16px;
}

.metric,
.chart-panel,
.side-panel,
.tables > section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(14, 23, 18, 0.97), rgba(5, 10, 7, 0.97));
  box-shadow: var(--shadow);
}

.metric {
  min-height: 118px;
  padding: 18px;
  display: grid;
  align-content: space-between;
}

.metric span,
.metric small,
.flow span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric strong {
  font-size: clamp(24px, 3vw, 38px);
  letter-spacing: 0;
}

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

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

.workspace {
  grid-template-columns: minmax(0, 1fr) 330px;
  margin-bottom: 16px;
}

.chart-panel,
.side-panel,
.tables > section {
  overflow: hidden;
}

.side-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

.panel-head {
  min-height: 74px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-head.compact {
  min-height: 64px;
}

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

.toggles label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(8, 11, 15, 0.45);
  font-size: 12px;
  font-weight: 800;
}

.toggles input {
  accent-color: var(--cyan);
}

.canvas-wrap {
  position: relative;
  height: 440px;
  padding: 14px;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.tooltip {
  position: absolute;
  pointer-events: none;
  min-width: 160px;
  padding: 10px 12px;
  border: 1px solid rgba(57, 255, 136, 0.35);
  border-radius: 8px;
  background: rgba(8, 11, 15, 0.92);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 12px;
}

.flow {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  background: var(--line);
}

.flow div {
  min-height: 102px;
  padding: 18px;
  display: grid;
  align-content: space-between;
  background: rgba(13, 18, 24, 0.96);
}

.flow strong {
  font-size: 26px;
}

.liquidity-panel {
  display: grid;
  gap: 1px;
  padding: 18px;
  border-top: 1px solid var(--line);
  background: rgba(7, 13, 9, 0.92);
}

.liquidity-head {
  display: grid;
  gap: 4px;
  margin-bottom: 10px;
}

.liquidity-head span,
.liquidity-head small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.liquidity-list {
  display: grid;
  gap: 10px;
}

.liquidity-row {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
  border-bottom: 1px solid rgba(24, 49, 35, 0.65);
}

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

.liquidity-row span {
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
}

.liquidity-row strong {
  color: var(--green);
  font-size: 16px;
  font-weight: 900;
}

.tables {
  grid-template-columns: minmax(420px, 0.82fr) minmax(520px, 1.18fr);
}

.table-wrap {
  overflow-x: hidden;
  overflow-y: auto;
  max-height: 430px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 0;
  table-layout: fixed;
}

th,
td {
  padding: 12px 12px;
  border-bottom: 1px solid rgba(31, 42, 54, 0.8);
  text-align: right;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th:first-child,
td:first-child,
th:nth-child(2),
td:nth-child(2) {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: #0b140f;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

th.sortable {
  cursor: pointer;
  color: var(--green);
  user-select: none;
}

th.sortable::after {
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 7px;
  border-right: 4px solid transparent;
  border-left: 4px solid transparent;
  border-top: 6px solid currentColor;
  content: "";
  opacity: 0.58;
  transform: translateY(-1px);
  transition: transform 160ms ease, opacity 160ms ease;
}

th.sortable[data-sort="long-first"]::after {
  opacity: 1;
  transform: translateY(-1px) rotate(180deg);
}

th.sortable[data-sort="short-first"]::after {
  opacity: 1;
}

td {
  color: #d7fbe4;
  font-size: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  border: 1px solid var(--line);
  font-size: 12px;
  font-weight: 900;
}

.pill.long {
  color: var(--green);
  border-color: rgba(57, 255, 136, 0.35);
  background: rgba(57, 255, 136, 0.06);
}

.pill.short {
  color: var(--red);
  border-color: rgba(255, 107, 122, 0.35);
}

.error {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  max-width: 880px;
  margin: 0 auto;
  padding: 14px 16px;
  border: 1px solid rgba(255, 107, 122, 0.45);
  border-radius: 8px;
  background: rgba(36, 10, 16, 0.94);
  color: #ffd8dd;
  box-shadow: var(--shadow);
}

body.history-expanded-open {
  overflow: hidden;
}

body.history-expanded-open::after {
  position: fixed;
  inset: 0;
  z-index: 30;
  content: "";
  background: rgba(3, 7, 5, 0.7);
  backdrop-filter: blur(8px);
}

#historyPanel {
  position: relative;
  z-index: 1;
}

#historyPanel.history-expanded {
  position: fixed;
  inset: 24px;
  z-index: 40;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  border: 1px solid rgba(57, 255, 136, 0.24);
  border-radius: 8px;
  background: linear-gradient(180deg, rgba(14, 23, 18, 0.99), rgba(5, 10, 7, 0.99));
  box-shadow: 0 24px 110px rgba(0, 0, 0, 0.5), 0 0 40px rgba(57, 255, 136, 0.08);
}

#historyPanel.history-expanded .table-wrap {
  min-height: 0;
  max-height: none;
  overflow: auto;
}

#historyPanel.history-expanded table {
  table-layout: fixed;
}

#historyPanel.history-expanded .panel-expand svg {
  transform: rotate(180deg);
}

#historyPanel.history-expanded th,
#historyPanel.history-expanded td {
  padding: 8px 10px;
  font-size: 11px;
}

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

@media (max-width: 980px) {
  .controls,
  .metric-grid,
  .workspace {
    grid-template-columns: 1fr;
  }

  .controls {
    align-items: stretch;
  }

  .segmented {
    overflow-x: auto;
  }

  .canvas-wrap {
    height: 360px;
  }
}

@media (max-width: 760px) {
  .table-wrap {
    max-height: none;
    overflow: visible;
  }

  table,
  thead,
  tbody,
  tr,
  td {
    display: block;
    width: 100%;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
    padding: 12px;
  }

  tr {
    border: 1px solid rgba(57, 255, 136, 0.14);
    border-radius: 8px;
    background: rgba(9, 16, 12, 0.76);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2);
    overflow: hidden;
  }

  td {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 10px 12px;
    border-bottom: 1px solid rgba(24, 49, 35, 0.65);
    text-align: right;
    white-space: normal;
  }

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

  td::before {
    flex: 0 0 auto;
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 900;
    text-transform: uppercase;
  }

  td[colspan]::before {
    content: "";
  }

  #historyPanel.history-expanded {
    inset: 10px;
  }
}

@media (max-width: 620px) {
  .shell {
    width: min(100% - 20px, 1480px);
    padding-top: 16px;
  }

  .topbar,
  .panel-head {
    align-items: start;
  }

  .topbar,
  .panel-head,
  .toggles {
    flex-direction: column;
  }

  .topbar {
    display: flex;
  }

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

  .segmented button {
    min-width: 76px;
  }

  .metric {
    min-height: 104px;
  }
}
