:root {
  --bg: #0a0d11;
  --panel: #0e131a;
  --panel-2: #121a22;
  --head: #0c1117;
  --line: #1d2630;
  --line-2: #28333f;
  --text: #dce5ec;
  --muted: #7d8a97;
  --dim: #56616c;
  --faint: #3a434d;
  --green: #3fe090;
  --green-d: #1c7a4e;
  --green-glow: rgba(63, 224, 144, .16);
  --blue: #5b9dff;
  --blue-glow: rgba(91, 157, 255, .16);
  --red: #ff5d6a;
  --red-glow: rgba(255, 93, 106, .16);
  --amber: #f6b73c;
  --amber-glow: rgba(246, 183, 60, .16);
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 12px;
  letter-spacing: 0;
}

button,
input {
  font: inherit;
}

.terminal {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: radial-gradient(circle at 50% -20%, rgba(91, 157, 255, .10), transparent 28rem), var(--bg);
}

.topbar {
  min-height: 48px;
  display: grid;
  grid-template-columns: auto minmax(260px, auto) 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 0 14px;
  background: linear-gradient(var(--head), var(--panel));
  border-bottom: 1px solid var(--line-2);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  font-family: var(--mono);
  font-weight: 800;
  letter-spacing: .8px;
  white-space: nowrap;
}

.brand-mark {
  width: 9px;
  height: 9px;
  display: inline-block;
  border-radius: 2px;
  transform: rotate(45deg);
}

.brand-blue {
  margin-left: -5px;
  background: var(--blue);
}

.brand-green {
  background: var(--green);
}

.brand-text span {
  color: var(--green);
}

.status-cluster,
.actions,
.top-stats,
.filter-row {
  display: flex;
  align-items: center;
}

.status-cluster {
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}

.lamp {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 9px var(--green);
}

.lamp.off {
  background: var(--red);
  box-shadow: 0 0 9px var(--red);
}

.chip,
.filter,
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  background: var(--panel-2);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1;
  letter-spacing: .4px;
  text-transform: uppercase;
  white-space: nowrap;
}

.chip {
  padding: 2px 6px;
}

.chip.warn {
  color: var(--amber);
  border-color: rgba(246, 183, 60, .55);
}

.chip.danger {
  color: var(--red);
  border-color: rgba(255, 93, 106, .55);
}

.top-stats {
  justify-content: flex-end;
  gap: 18px;
  min-width: 0;
}

.top-stats div {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  min-width: 46px;
}

.top-stats span {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 9px;
  text-transform: uppercase;
}

.top-stats b {
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 700;
}

.actions {
  gap: 8px;
}

.logout-form {
  margin: 0;
}

.btn {
  padding: 0 10px;
  cursor: pointer;
  transition: background .12s, border-color .12s, color .12s, filter .12s;
}

.btn:hover {
  color: var(--text);
  border-color: var(--dim);
  background: #16202a;
}

.btn.primary {
  color: #06120c;
  border-color: var(--green);
  background: var(--green);
  font-weight: 800;
}

.btn.primary:hover {
  filter: brightness(1.08);
}

.btn.danger {
  color: var(--red);
  border-color: rgba(255, 93, 106, .55);
}

.btn.danger:hover {
  background: var(--red-glow);
}

.btn.wide {
  width: 100%;
  min-height: 34px;
}

.ticker-row {
  min-height: 27px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--head);
  overflow: hidden;
}

.ticker-label {
  height: 27px;
  display: inline-flex;
  align-items: center;
  flex: 0 0 auto;
  padding: 0 12px;
  border-right: 1px solid var(--line);
  color: var(--green);
  font-family: var(--mono);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1px;
}

.ticker-window {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.ticker-track {
  display: inline-flex;
  align-items: center;
  min-width: 100%;
  animation: ticker 48s linear infinite;
}

.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 27px;
  padding: 0 18px;
  border-right: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
  white-space: nowrap;
}

.ticker-item strong {
  color: var(--text);
  max-width: 20ch;
  overflow: hidden;
  text-overflow: ellipsis;
}

@keyframes ticker {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

.workspace {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 392px);
  gap: 8px;
  padding: 8px;
}

.left-stack {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: minmax(320px, 1fr) minmax(240px, 34vh);
  gap: 8px;
}

.panel {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(14, 19, 26, .96);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.panel-head {
  min-height: 31px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  padding: 0 10px;
  background: linear-gradient(var(--head), var(--panel));
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.1px;
  text-transform: uppercase;
}

.accent {
  width: 3px;
  height: 12px;
  flex: 0 0 auto;
  border-radius: 2px;
  background: var(--green);
}

.accent.blue {
  background: var(--blue);
}

.accent.amber {
  background: var(--amber);
}

.panel-note {
  margin-left: auto;
  min-width: 0;
  color: var(--dim);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filter-row {
  gap: 6px;
  flex-wrap: wrap;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
}

.filter {
  padding: 0 8px;
  cursor: pointer;
}

.filter.active {
  color: var(--green);
  border-color: var(--green-d);
  background: var(--green-glow);
  font-weight: 800;
}

.table-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.edge-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-family: var(--mono);
}

.edge-table th,
.edge-table td {
  height: 32px;
  padding: 0 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edge-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  height: 27px;
  background: var(--head);
  color: var(--dim);
  font-family: var(--sans);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .7px;
  text-transform: uppercase;
}

.edge-table tr {
  cursor: pointer;
}

.edge-table tbody tr:hover {
  background: var(--panel-2);
}

.edge-table tbody tr.selected {
  background: var(--blue-glow);
  box-shadow: inset 2px 0 0 var(--blue);
}

.edge-table .num {
  text-align: right;
}

.score {
  display: inline-flex;
  min-width: 31px;
  height: 20px;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  color: #06120c;
  background: var(--green);
  font-weight: 900;
}

.score.watch {
  background: var(--amber);
}

.score.log {
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line-2);
}

.tag {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 0 4px;
  border: 1px solid currentColor;
  border-radius: 3px;
  color: var(--blue);
  font-size: 9px;
  font-weight: 800;
}

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

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

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

.detail-grid {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(240px, .9fr) minmax(210px, .65fr) minmax(260px, .8fr);
}

.selected-card,
.book-card,
.execution-card {
  min-width: 0;
  min-height: 0;
  padding: 12px;
  border-right: 1px solid var(--line);
}

.execution-card {
  border-right: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.selected-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin-bottom: 8px;
}

.selected-title strong {
  font-family: var(--mono);
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.selected-meta {
  color: var(--dim);
  font-family: var(--mono);
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.book-title {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .7px;
  margin-bottom: 7px;
  text-transform: uppercase;
}

.book-ladder {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.book-row {
  position: relative;
  min-height: 20px;
  display: grid;
  grid-template-columns: 54px 1fr;
  align-items: center;
  gap: 8px;
  padding: 0 7px;
  overflow: hidden;
  font-family: var(--mono);
}

.book-row::before {
  content: "";
  position: absolute;
  inset: 2px 0 2px auto;
  width: var(--depth, 0%);
  background: var(--depth-color, var(--green-glow));
  border-right: 2px solid var(--depth-border, var(--green-d));
  opacity: .9;
}

.book-row span {
  position: relative;
  z-index: 1;
}

.book-row .price {
  font-weight: 800;
}

.book-row .size {
  color: var(--muted);
  text-align: right;
}

.book-row.ask {
  color: var(--red);
  --depth-color: var(--red-glow);
  --depth-border: rgba(255, 93, 106, .55);
}

.book-row.bid {
  color: var(--green);
}

.spread-row {
  min-height: 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 7px;
  margin: 2px 0;
  background: var(--head);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-family: var(--mono);
}

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

.metric {
  min-width: 0;
}

.metric span {
  display: block;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .6px;
  text-transform: uppercase;
}

.metric b {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 15px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
  line-height: 1.45;
  text-align: center;
}

.wire-panel {
  min-height: 0;
}

.wire-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.wire-item {
  display: grid;
  grid-template-columns: 5px 1fr auto;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
}

.wire-sev {
  border-radius: 2px;
  background: var(--blue);
}

.wire-item.alert .wire-sev {
  background: var(--red);
}

.wire-item.warn .wire-sev {
  background: var(--amber);
}

.wire-body {
  min-width: 0;
}

.wire-kind {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .6px;
  text-transform: uppercase;
}

.wire-title {
  margin-top: 2px;
  color: var(--text);
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.wire-detail {
  margin-top: 2px;
  color: var(--muted);
  line-height: 1.35;
}

.wire-time {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 10px;
}

.empty {
  padding: 28px 16px;
  color: var(--dim);
  font-family: var(--mono);
  text-align: center;
}

.command-bar {
  min-height: 38px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 5px 10px;
  border-top: 1px solid var(--line);
  background: var(--head);
}

.prompt {
  color: var(--green);
  font-family: var(--mono);
}

.command-bar input {
  flex: 1;
  min-width: 0;
  height: 27px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  caret-color: var(--green);
  font-family: var(--mono);
}

.command-bar input::placeholder {
  color: var(--faint);
}

.command-result {
  max-width: 32vw;
  color: var(--muted);
  font-family: var(--mono);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.token-box {
  display: grid;
  grid-template-columns: auto 150px auto auto;
  gap: 6px;
  align-items: center;
  margin-left: auto;
  padding: 0;
  background: rgba(14, 19, 26, .94);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}

.token-box label {
  color: var(--dim);
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
}

.token-box input {
  min-width: 0;
  height: 25px;
  border: 1px solid var(--line-2);
  border-radius: 4px;
  outline: 0;
  background: var(--bg);
  color: var(--text);
  padding: 0 7px;
  font-family: var(--mono);
}

@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: 1fr auto;
  }

  .status-cluster,
  .top-stats {
    grid-column: 1 / -1;
    justify-content: flex-start;
  }

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

  .wire-panel {
    min-height: 280px;
  }
}

@media (max-width: 780px) {
  .topbar {
    grid-template-columns: 1fr;
    align-items: stretch;
    padding: 10px;
  }

  .actions,
  .top-stats {
    justify-content: space-between;
  }

  .ticker-row {
    display: none;
  }

  .left-stack {
    grid-template-rows: minmax(320px, 1fr) auto;
  }

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

  .selected-card,
  .book-card,
  .execution-card {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .execution-card {
    border-bottom: 0;
  }

  .edge-table {
    min-width: 900px;
  }

  .token-box {
    grid-template-columns: 1fr;
    width: 100%;
    margin-left: 0;
    padding-top: 6px;
    border-top: 1px solid var(--line);
  }

  .command-result {
    display: none;
  }
}
