:root {
  --bg:       #0f1117;
  --surface:  #161b27;
  --elevated: #1e2536;
  --border:   #21293d;
  --border2:  #2d3a52;
  --grid:     #141922;
  --accent:   #00f0ff;
  --green:    #00ffb2;
  --text:     #d4d4d8;
  --text2:    #8b95a8;
  --text3:    #5c6a82;
  --text4:    #3d4a60;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--bg); overflow-x: clip; }
body { background: var(--bg); color: var(--text); font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif; font-size: 14px; line-height: 1.45; padding: 20px 32px; max-width: 1280px; margin: 0 auto; }
h2 { color: var(--text); font-size: 10px; letter-spacing: 2px; text-transform: uppercase; margin: 28px 0 12px; opacity: 0.7; }
#status {
  font-size: 11px;
  color: var(--text2);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
#status.disconnected { color: var(--text3); }
#status.disconnected .live-dot {
  background: var(--text3);
  animation: none;
  opacity: 0.5;
}
.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  font-size: 10px;
}
#status.disconnected .live-pill { color: var(--text3); }
#status.archived .live-pill { color: var(--text3); }
#status.archived .live-dot {
  background: var(--text3);
  box-shadow: none;
  animation: none;
}
.live-dot-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
}
.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(0, 240, 255, 0.4);
  animation: live-breathe 1.8s ease-in-out infinite;
}
@keyframes live-breathe {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(0.72); }
}
.live-ts {
  color: var(--text2);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
  text-transform: none;
}
.live-ts-label { color: var(--text3); margin-right: 4px; text-transform: uppercase; font-size: 9px; letter-spacing: 0.08em; }
#wall-chart { width: 100%; min-height: 460px; }
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 3fr;
  gap: 28px;
  align-items: start;
  margin: 4px 0 8px;
}
/* Prevent grid items from expanding to content min-width; lets overflow-x:auto work */
.dashboard-grid > * { min-width: 0; }
/* Scroll containers must be explicitly bounded to their grid/block parent */
.table-scroll { width: 100%; }
#wall-chart svg { display: block; overflow: visible; }
.axis path, .axis line { stroke: var(--border2); }
.axis text { fill: var(--text); font-size: 11px; font-family: inherit; }
.grid line { stroke: rgba(255,255,255,0.05); }
.grid path { stroke: none; }
/* Headline stats strip (item 1) — replaces the LST price ticker. */
#stats-strip {
  display: flex; flex-wrap: wrap; gap: 14px 40px;
  margin: 10px 0 18px; padding: 14px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
}
#stats-strip .stat { display: flex; flex-direction: column; gap: 3px; }
#stats-strip .stat-num {
  font-size: 22px; font-weight: 600; color: var(--text);
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
#stats-strip .stat-label {
  font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--text3);
}
#stats-strip .stat-price { margin-left: auto; text-align: right; }
/* Subtle per-tick flash: a faint background tint that fades out (ag-Grid / ticker
   convention). Text stays calm; padding/negative-margin keeps the tint from shifting layout. */
#stats-strip .stat-price .stat-num {
  color: var(--accent);
  border-radius: 4px; padding: 0 4px; margin: 0 -4px;
}
#stats-strip .stat-price .stat-num.flash-up   { animation: px-up 0.5s ease-out; }
#stats-strip .stat-price .stat-num.flash-down { animation: px-down 0.5s ease-out; }
@keyframes px-up   { from { background-color: rgba(0,255,178,0.16); } to { background-color: transparent; } }
@keyframes px-down { from { background-color: rgba(255,92,122,0.16); } to { background-color: transparent; } }
@media (prefers-reduced-motion: reduce) {
  #stats-strip .stat-price .stat-num.flash-up,
  #stats-strip .stat-price .stat-num.flash-down { animation: none; }
}
table { width: 100%; border-collapse: collapse; }
th { color: var(--text); font-weight: 500; text-align: left; padding: 5px 10px; border-bottom: 1px solid var(--border2); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; position: sticky; top: 0; background: var(--surface); z-index: 1; }
.table-scroll {
  overflow-y: auto;
  scrollbar-gutter: stable;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 4px;
}
#wall-chart { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
#risk-summary { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; }
.table-scroll--liq { max-height: 360px; }
.table-scroll--pos { max-height: 400px; }
.table-scroll::-webkit-scrollbar { width: 6px; }
.table-scroll::-webkit-scrollbar-track { background: var(--surface); }
.table-scroll::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
.table-scroll::-webkit-scrollbar-thumb:hover { background: var(--text4); }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { background: var(--elevated); color: var(--text); }
th[data-sort]::after { content: ' ↕'; opacity: 0.25; margin-left: 3px; font-size: 9px; }
th[data-sort]:hover::after { opacity: 0.5; }
th[data-sort][data-active="1"] { color: var(--accent); }
th[data-sort][data-active="1"]::after { opacity: 1; color: var(--accent); }
th[data-sort][data-active="1"][data-dir="asc"]::after  { content: ' ↑'; }
th[data-sort][data-active="1"][data-dir="desc"]::after { content: ' ↓'; }
td { padding: 6px 10px; border-bottom: 1px solid var(--grid); font-variant-numeric: tabular-nums; font-size: 14px; line-height: 1.5; }
td.usd-col { text-align: right; }
td.wallet-col, th.wallet-col { text-align: center; white-space: nowrap; }
td.protocol-id { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; }
td.position-id { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; font-family: 'Consolas', 'Menlo', monospace; font-size: 12px; }
#liq-table td.position-id { max-width: unset; overflow: visible; }
td.wallet-col  { font-family: 'Consolas', 'Menlo', monospace; font-size: 12px; }
td.market-id   { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 0; }
td.updated-col { white-space: nowrap; font-size: 11px; color: var(--text3); }
.Liquidatable td { color: #ef4444; }
.Critical     td { color: #f97316; }
.High         td { color: #f59e0b; }
.Moderate     td { color: #eab308; }
.Safe         td { color: #22c55e; }
.tier-badge { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.02em; }
.tier-Liquidatable { background: rgba(239,68,68,0.12); color: #ef4444; }
.tier-Critical     { background: rgba(249,115,22,0.12); color: #f97316; }
.tier-High         { background: rgba(245,158,11,0.12); color: #f59e0b; }
.tier-Moderate     { background: rgba(234,179,8,0.12); color: #eab308; }
.tier-Safe         { background: rgba(34,197,94,0.12); color: #22c55e; }
#tooltip {
  position: fixed; background: rgba(15, 18, 30, 0.94); border: 1px solid var(--border2);
  padding: 8px 12px; font-size: 12px; color: var(--text);
  pointer-events: none; border-radius: 6px; display: none;
  max-width: 240px; line-height: 1.5;
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}
#risk-summary { max-width: 560px; margin-bottom: 8px; }
.risk-row { display: flex; align-items: center; gap: 10px; margin: 5px 0; font-size: 12px; }
.risk-label { width: 90px; color: var(--text); text-transform: uppercase; font-size: 10px; letter-spacing: 1px; flex-shrink: 0; }
.risk-bar-wrap { flex: 1; background: var(--grid); height: 14px; border-radius: 1px; overflow: hidden; }
.risk-bar { height: 100%; border-radius: 1px; transition: width 0.4s ease; }
.risk-meta { width: 160px; color: var(--text2); font-size: 11px; text-align: right; flex-shrink: 0; font-variant-numeric: tabular-nums; }
.bin-btn {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 2px 8px; font-family: inherit; font-size: 13px;
  cursor: pointer; margin-right: 4px; border-radius: 2px;
}
.bin-btn:hover { color: var(--accent); border-color: var(--border2); }
.bin-btn.active { color: var(--accent); border-color: var(--accent); background: var(--elevated); }
.proto-btn {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 2px 8px; font-family: inherit; font-size: 13px;
  cursor: pointer; margin-right: 4px; border-radius: 2px;
}
.proto-btn:hover { color: var(--accent); border-color: var(--border2); }
.proto-btn.active { color: var(--accent); border-color: var(--accent); background: var(--elevated); }
.legend-swatch { display: inline-block; width: 10px; height: 10px; margin-right: 4px; vertical-align: middle; border-radius: 1px; }
.copy-btn {
  background: none; border: none; color: var(--text3); cursor: pointer;
  font-family: inherit; font-size: 12px; padding: 0 4px;
  vertical-align: middle; line-height: 1;
}
.copy-btn:hover { color: var(--text); }
.copy-btn.copied { color: var(--accent); }
.loop-badge {
  display: inline-block; margin-left: 6px; padding: 0 5px;
  font-size: 9px; letter-spacing: 0.08em; color: var(--text2);
  border: 1px solid var(--border2); border-radius: 2px; vertical-align: middle;
}
tr.coupled td { color: var(--text3) !important; }
.risk-row.coupled .risk-label { opacity: 0.55; }
.risk-row.coupled .risk-bar { opacity: 0.35; }
.toggle-row { display: flex; align-items: center; gap: 12px; margin: 0 0 10px; font-size: 11px; color: var(--text2); flex-wrap: wrap; }
.toggle-row label { cursor: pointer; user-select: none; }
.toggle-row input { vertical-align: middle; margin-right: 4px; }
.filter-pill {
  display: none; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border2); border-radius: 4px;
  padding: 4px 9px; font-size: 11px; color: var(--text);
  font-variant-numeric: tabular-nums; flex-wrap: wrap;
}
.filter-pill.active { display: inline-flex; }
.filter-pill .filter-tag {
  display: inline-flex; align-items: center; gap: 6px;
  color: var(--text2);
  background: var(--elevated); border: 1px solid var(--border);
  border-radius: 4px; padding: 2px 5px 2px 9px;
}
.filter-pill .filter-tag b { color: var(--text); font-weight: normal; }
.filter-pill .filter-swatch {
  width: 8px; height: 8px; border-radius: 1px; display: inline-block;
}
.filter-pill .reset-btn {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font-family: inherit; font-size: 11px; padding: 0 2px; line-height: 1;
}
.filter-pill .reset-btn:hover { color: var(--green); }
rect.bin-selected { stroke: var(--text); stroke-width: 1.5; }
.risk-row { cursor: pointer; padding: 2px 6px; border-radius: 2px; }
.risk-row:hover { background: var(--elevated); }
.risk-row.active { background: var(--elevated); outline: 1px solid var(--accent); }
.risk-row.active .risk-label { color: var(--accent); }
.coupling-group { display: inline-flex; gap: 0; }
.coupling-btn {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 2px 8px; font-family: inherit; font-size: 13px;
  cursor: pointer; border-radius: 0; margin: 0;
}
.coupling-btn:first-child { border-radius: 2px 0 0 2px; }
.coupling-btn:last-child { border-radius: 0 2px 2px 0; }
.coupling-btn + .coupling-btn { border-left: none; }
.coupling-btn:hover { color: var(--accent); border-color: var(--border2); }
.coupling-btn.active { color: var(--accent); border-color: var(--accent); background: var(--elevated); }
/* Restore left border on active middle/right buttons and compensate for the extra pixel */
.coupling-btn + .coupling-btn.active { border-left: 1px solid var(--accent); margin-left: -1px; }
.pager {
  display: flex; align-items: center; gap: 12px;
  margin: 8px 0 0; font-size: 11px; color: var(--text2);
  font-variant-numeric: tabular-nums;
}
.pager button {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 2px 10px; font-family: inherit; font-size: 13px;
  cursor: pointer; border-radius: 2px;
}
.pager button:hover:not(:disabled) { color: var(--accent); border-color: var(--border2); }
.pager button:disabled { color: var(--text4); cursor: default; }
.pager .pager-summary { color: var(--text3); }

/* ─── Chart navigation hint (item 4) ─────────────────────────────────────────── */
.chart-hint {
  display: flex; align-items: center; gap: 10px;
  margin: 6px 2px 0; color: var(--text3); font-size: 10.5px; flex-wrap: wrap;
}
.chart-hint-icon { width: 13px; height: 13px; flex-shrink: 0; color: var(--text4); }
.chart-hint-chips { display: flex; gap: 6px 14px; flex-wrap: wrap; align-items: center; }
.chart-hint-chips > span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.chart-hint kbd {
  font-family: inherit; font-size: 9px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--text2); background: var(--elevated); border: 1px solid var(--border);
  border-radius: 3px; padding: 1px 5px; line-height: 1.5;
}

/* ─── Recent Liquidations — neutral rows, single semantic marker (item 5) ─────── */
#liq-table td { color: var(--text2); }
#liq-table .liq-mark {
  display: inline-block; width: 5px; height: 5px; border-radius: 50%;
  background: #ef4444; opacity: 0.55; margin-right: 7px; vertical-align: middle;
}
#liq-table .liq-time { color: var(--text3); font-size: 12px; white-space: nowrap; }
#liq-table .liq-seized { color: var(--text); }
#liq-table .liq-debt { color: var(--text2); }
#liq-table .liq-asset { color: var(--text3); font-size: 12px; }
.tx-link { color: var(--text3); font-family: 'Consolas', 'Menlo', monospace; font-size: 12px; }
.tx-link:hover { color: var(--accent); }
/* Partial vs full liquidation status (item 6). */
.position-id-dead { color: var(--text3); }
.liq-status {
  display: inline-block; font-size: 9px; letter-spacing: 0.06em; text-transform: uppercase;
  padding: 1px 5px; border-radius: 3px; vertical-align: middle; font-weight: 600;
}
.liq-status--full    { color: #ef4444; background: rgba(239,68,68,0.12); }
.liq-status--partial { color: var(--text2); background: var(--elevated); }

/* ─── Table protocol filter group (item 7c) — mirrors coupling buttons ────────── */
.tproto-btn {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 2px 8px; font-family: inherit; font-size: 13px;
  cursor: pointer; border-radius: 0; margin: 0;
}
.tproto-btn:first-child { border-radius: 2px 0 0 2px; }
.tproto-btn:last-child { border-radius: 0 2px 2px 0; }
.tproto-btn + .tproto-btn { border-left: none; }
.tproto-btn:hover { color: var(--accent); border-color: var(--border2); }
.tproto-btn.active { color: var(--accent); border-color: var(--accent); background: var(--elevated); }
.tproto-btn + .tproto-btn.active { border-left: 1px solid var(--accent); margin-left: -1px; }

/* ─── Liquidations table toolbar (protocol filter) ───────────────────────────── */
.liq-toolbar { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; flex-wrap: wrap; }
.liq-toolbar-label { color: #6e7686; font-size: 9px; letter-spacing: 0.08em; text-transform: uppercase; }
.lproto-btn {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  padding: 2px 8px; font-family: inherit; font-size: 12px; cursor: pointer; border-radius: 0; margin: 0;
}
.lproto-btn:first-child { border-radius: 2px 0 0 2px; }
.lproto-btn:last-child { border-radius: 0 2px 2px 0; }
.lproto-btn + .lproto-btn { border-left: none; }
.lproto-btn:hover { color: var(--accent); border-color: var(--border2); }
.lproto-btn.active { color: var(--accent); border-color: var(--accent); background: var(--elevated); }
.lproto-btn + .lproto-btn.active { border-left: 1px solid var(--accent); margin-left: -1px; }

/* ─── Per-tag removal × on filter chips (item 7a) ─────────────────────────────── */
.filter-pill .tag-x {
  background: none; border: none; color: var(--text3); cursor: pointer;
  font-family: inherit; font-size: 12px; line-height: 1; padding: 0 0 0 4px;
}
.filter-pill .tag-x:hover { color: var(--accent); }

/* ─── Footer (item 3) — frames the open API as a public good ──────────────────── */
#site-footer {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 16px;
  margin: 36px 0 8px; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: 11px; color: var(--text3);
}
#site-footer .footer-brand { letter-spacing: 0.02em; }
#site-footer .footer-links { display: flex; gap: 18px; }
#site-footer .footer-links a {
  color: var(--text2); text-decoration: none; letter-spacing: 0.04em;
}
#site-footer .footer-links a:hover { color: var(--accent); }

/* ─── Responsive ────────────────────────────────────────────────────────────── */

/* Y-zoom buttons: only on touch screens (≤1024px); desktop uses shift+scroll */
.yzoom-controls { display: none; }

/* Wide — give the layout more room */
@media (min-width: 1440px) {
  body { max-width: 1440px; padding: 24px 48px; }
  #wall-chart { min-height: 520px; }
}

/* Tablet/iPad — touch UX: show +/- zoom buttons, hide keyboard hint row */
@media (max-width: 1024px) {
  body { padding: 16px 24px; }
  .dashboard-grid { grid-template-columns: 1fr; }
  #risk-summary { max-width: none; }
  #wall-chart { min-height: 320px; }
  .table-scroll--liq { max-height: 260px; }
  .table-scroll--pos { max-height: 380px; }
  .table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-gutter: auto; }
  #pos-table { min-width: 1050px; }
  #liq-table { min-width: 540px; }
  .yzoom-controls { display: flex; }
  .chart-hint { display: none; }
}

/* Mobile — tighter spacing, bigger touch targets, narrower scroll floors */
@media (max-width: 640px) {
  body { padding: 12px 14px; font-size: 13px; overflow-x: clip; }
  #wall-chart { overflow: hidden; }
  h2 { margin: 18px 0 8px; }
  #wall-chart { min-height: 200px; }
  #stats-strip { gap: 12px 22px; padding: 12px 14px; }
  #stats-strip .stat-num { font-size: 17px; }
  #stats-strip .stat-price { margin-left: 0; text-align: left; }
  td { font-size: 13px; }
  #bin-buttons { gap: 6px; }
  .bin-btn, .proto-btn { font-size: 12px; padding: 5px 9px; }
  .coupling-btn, .tproto-btn, .lproto-btn { font-size: 12px; padding: 5px 9px; }
  .pager button { font-size: 12px; padding: 5px 10px; }
  .pager { flex-wrap: wrap; gap: 8px; }
  .toggle-row { gap: 8px; }
  #pos-table { min-width: 700px; }
  #liq-table { min-width: 520px; }
  .table-scroll--pos { max-height: 320px; }
  .table-scroll--liq { max-height: 220px; }
}
