:root {
  --bg: #02070a;
  --panel: #071116;
  --panel-2: #0b1c24;
  --panel-3: #09171e;
  --line: #1a343f;
  --line-soft: #102630;
  --text: #e9f4f6;
  --muted: #7f99a1;
  --teal: #13d6ac;
  --red: #ff4e63;
  --amber: #f2b84b;
  --blue: #e2e8eb;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.terminal-top {
  height: 46px;
  display: grid;
  grid-template-columns: 190px 76px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  background: rgba(4, 12, 17, 0.96);
}
.brand { display: flex; align-items: center; gap: 9px; }
.top-brand strong { font-size: 15px; letter-spacing: 0; }
.top-brand span { color: var(--muted); font-size: 11px; margin-left: 7px; }
.pulse-mark {
  width: 22px; height: 22px; border-radius: 5px;
  background: linear-gradient(135deg, var(--teal), #5fd5ff);
}
.live-pill {
  height: 28px; border: 1px solid var(--line); border-radius: 7px;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  color: var(--teal); font-weight: 800; font-size: 12px; background: var(--panel);
}
.live-pill span { width: 7px; height: 7px; background: var(--teal); border-radius: 50%; }
.polling { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.top-controls { display: flex; align-items: center; gap: 8px; }
.segmented {
  height: 32px; border: 1px solid var(--line); border-radius: 7px; display: flex; align-items: center; gap: 4px; padding: 3px 5px; background: var(--panel);
}
.segmented b { color: var(--muted); font-size: 12px; padding: 0 7px; }
.segmented button { height: 24px; padding: 0 9px; }

.app {
  height: calc(100vh - 46px);
  min-height: 820px;
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
}

.sidebar {
  border-right: 1px solid var(--line);
  background: #030b0f;
  padding: 10px 8px;
  overflow: hidden;
}
.side-row { margin: 0 0 10px; }
input, select, button {
  border: 1px solid var(--line);
  background: #040d12;
  color: var(--text);
  border-radius: 4px;
  height: 30px;
  padding: 0 9px;
  font-size: 12px;
}
input { width: 100%; }
button { cursor: pointer; }
.side-head {
  display: grid; grid-template-columns: 1fr 78px 70px;
  color: var(--muted); text-transform: uppercase; font-weight: 800; font-size: 10px;
  padding: 7px 8px; border-bottom: 1px solid var(--line);
}
.section-title {
  color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 800;
  margin: 12px 4px 8px;
}
.watch-custom-head {
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  padding: 0 4px;
}
.watch-custom-head button { height: 22px; padding: 0 7px; color: var(--muted); }
.observe-list {
  max-height: 180px;
  min-height: 42px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 4px;
  margin-bottom: 9px;
}
.observe-empty { color: var(--muted); font-size: 12px; padding: 12px 10px; }
.observe-item {
  width: 100%;
  height: 34px;
  display: grid;
  grid-template-columns: 1fr 58px 20px;
  align-items: center;
  gap: 6px;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  border-radius: 0;
  background: transparent;
  text-align: left;
}
.observe-item:hover, .observe-item.active { background: rgba(24, 199, 167, 0.08); }
.observe-item span { font-size: 12px; font-weight: 900; }
.observe-item small { display: inline; color: var(--muted); font-size: 10px; margin-left: 6px; font-weight: 700; }
.observe-item strong { text-align: right; font-size: 11px; font-variant-numeric: tabular-nums; }
.observe-item em { color: var(--muted); font-style: normal; text-align: center; font-size: 14px; }
.watchlist { height: calc(100vh - 460px); min-height: 310px; overflow: auto; }
.watch-item {
  width: 100%; border: 0; border-bottom: 1px solid var(--line-soft); border-radius: 0;
  background: transparent; color: var(--text); padding: 6px 8px; text-align: left;
}
.watch-item:hover, .watch-item.active { background: rgba(24, 199, 167, 0.08); }
.watch-top { display: grid; grid-template-columns: 1fr 76px; gap: 8px; font-size: 12px; font-weight: 800; }
.watch-top span:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.watch-meta { display: grid; grid-template-columns: 1fr 70px; gap: 8px; color: var(--muted); font-size: 11px; margin-top: 2px; }
.watch-meta em { font-style: normal; }
.watch-meta span:last-child { text-align: right; font-weight: 800; }
.exchange-status { border: 1px solid var(--line); border-radius: 4px; overflow: hidden; }
.status-row { display: grid; grid-template-columns: 1fr 52px 82px; padding: 7px 8px; border-bottom: 1px solid var(--line-soft); font-size: 11px; }
.status-row:last-child { border-bottom: 0; }
.status-row strong { font-size: 10px; }
.status-row small { text-align: right; color: var(--muted); }

.main { padding: 8px; min-width: 0; overflow: hidden; }
.exchange-tabs {
  height: 46px; display: flex; gap: 4px; align-items: center;
  border: 1px solid var(--line); background: var(--panel); border-radius: 4px; padding: 5px; margin-bottom: 7px;
}
.exchange-tabs button {
  min-width: 112px; height: 34px; border-color: transparent; background: transparent; color: var(--muted);
  font-weight: 800; text-transform: uppercase;
}
.exchange-tabs button.active, .exchange-tabs button:hover { color: var(--text); background: var(--panel-2); border-color: var(--line-soft); }

.contract-strip {
  height: 64px; display: grid; grid-template-columns: 210px 150px repeat(4, 1fr); align-items: center;
  border: 1px solid var(--line); background: var(--panel); border-radius: 4px; margin-bottom: 7px;
}
.contract-main { display: flex; align-items: center; gap: 8px; padding: 0 12px; border-right: 1px solid var(--line); height: 100%; }
.star { width: 24px; padding: 0; border: 0; background: transparent; color: var(--muted); font-size: 18px; }
.star.active, .row-star.active, .alert-star.active { color: var(--amber); }
h1 { margin: 0; font-size: 17px; line-height: 1.05; }
.contract-main span { color: var(--muted); font-size: 11px; }
.contract-stat { padding: 0 14px; border-right: 1px solid var(--line); height: 100%; display: flex; flex-direction: column; justify-content: center; }
.contract-stat:last-child { border-right: 0; }
.contract-stat span { color: var(--muted); font-size: 11px; }
.contract-stat strong { font-size: 15px; margin-top: 5px; font-variant-numeric: tabular-nums; }
.contract-stat.big strong { font-size: 22px; }

.grid { display: grid; grid-template-columns: minmax(0, 1fr) 390px; gap: 8px; }
.chart-panel, .alerts-panel, .table-panel, .card, .resonance-panel {
  background: rgba(10, 25, 33, 0.96);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.resonance-panel { margin-bottom: 8px; overflow: hidden; }
.panel-head.compact { height: 32px; padding: 5px 10px; }
.resonance-board {
  min-height: 42px;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(430px, 1fr);
  grid-template-columns: none;
  gap: 5px;
  padding: 5px;
  overflow-x: auto;
}
.resonance-card {
  height: 34px;
  min-width: 430px;
  display: grid;
  grid-template-columns: 72px 88px 42px 78px 72px 92px minmax(120px, 1fr) 24px;
  align-items: center;
  gap: 7px;
  text-align: left;
  padding: 0 8px;
  border-color: var(--line);
  background: #061218;
  overflow: hidden;
}
.resonance-card:hover, .resonance-card.active { background: rgba(24, 199, 167, 0.08); border-color: rgba(19,214,172,.42); }
.resonance-card.short:hover, .resonance-card.exit:hover, .resonance-card.short.active, .resonance-card.exit.active { border-color: rgba(255,78,99,.42); }
.resonance-card strong { font-size: 13px; letter-spacing: 0; }
.resonance-card span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
.resonance-card .signal { min-width: 76px; height: 20px; }
.res-legs { color: var(--muted); }
.res-observe { color: var(--amber) !important; font-size: 14px !important; text-align: center; cursor: pointer; }
.resonance-empty { grid-column: 1 / -1; color: var(--muted); font-size: 12px; padding: 8px 10px; border: 1px dashed var(--line); border-radius: 4px; }
.chart-panel { height: 640px; overflow: hidden; }
.alerts-panel { height: 640px; overflow: hidden; }
.chart-toolbar {
  height: 40px; display: flex; align-items: center; gap: 8px; padding: 5px 10px; border-bottom: 1px solid var(--line);
}
.tool-tabs { display: flex; gap: 4px; }
.tool-tabs button, .range-buttons button { height: 26px; border-color: transparent; background: transparent; color: var(--muted); }
.tool-tabs button { min-width: 58px; padding: 0 10px; white-space: nowrap; }
.tool-tabs button.active, .range-buttons button.active { background: var(--panel-2); color: var(--text); border-color: var(--line); }
.legend { margin-left: auto; display: flex; gap: 14px; color: var(--muted); font-size: 11px; }
.legend i { display: inline-block; width: 7px; height: 7px; border-radius: 2px; margin-right: 5px; }
.legend .up { background: var(--teal); }
.legend .down { background: var(--red); }
.legend .line { background: var(--blue); }
.legend .funding { background: var(--amber); }
#chart { width: 100%; height: 532px; display: block; }
.range-buttons { height: 34px; border-top: 1px solid var(--line); display: flex; align-items: center; gap: 4px; padding: 4px 10px; color: var(--muted); font-size: 11px; }
.range-buttons span { margin-left: auto; }
.range-buttons .hint { margin-left: 10px; color: var(--muted); }

.panel-head { height: 40px; padding: 8px 12px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
h2 { margin: 0; font-size: 13px; text-transform: uppercase; }
h2 small { color: var(--muted); font-size: 11px; text-transform: none; }
.panel-head span { color: var(--muted); font-size: 11px; }
.anomaly-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 8px; }
.anomaly-card { border: 1px solid var(--line); border-radius: 4px; background: var(--panel-3); padding: 8px; min-height: 96px; }
.anomaly-card.warn { border-color: rgba(242, 184, 75, .55); background: linear-gradient(180deg, rgba(242, 184, 75, .08), var(--panel-3)); }
.anomaly-card.critical { border-color: rgba(255, 82, 99, .68); background: linear-gradient(180deg, rgba(255, 82, 99, .1), var(--panel-3)); }
.anomaly-card h3 { margin: 0 0 8px; font-size: 13px; }
.anomaly-card .big { font-size: 21px; font-weight: 900; line-height: 1; margin-bottom: 7px; font-variant-numeric: tabular-nums; }
.anomaly-card .row { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; line-height: 1.45; }
.anomaly-card .row strong { font-variant-numeric: tabular-nums; }
.alert-title { height: 34px; display: flex; align-items: center; padding: 0 12px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); text-transform: uppercase; font-weight: 800; font-size: 12px; }
.alerts { height: 348px; overflow: auto; padding: 0; }
.alert { display: grid; grid-template-columns: 74px 22px 1fr; gap: 7px; align-items: start; border-bottom: 1px solid var(--line-soft); padding: 6px 10px; background: transparent; }
.alert.warn { border-left: 3px solid var(--amber); }
.alert.critical { border-left: 3px solid var(--red); }
.alert-time { color: var(--muted); font-size: 11px; }
.alert-star, .row-star {
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
}
.row-star { display: inline-block; vertical-align: top; margin-right: 4px; }
.alert-msg { font-size: 11px; line-height: 1.25; cursor: pointer; }
.alert-msg b { color: var(--text); }

.cards { display: none; }
.up { color: var(--teal); }
.down { color: var(--red); }
.warn-text { color: var(--amber); }
.muted { color: var(--muted); }

.table-panel { margin-top: 8px; height: calc(100vh - 872px); min-height: 220px; overflow: hidden; }
.table-panel .panel-head input { width: 160px; height: 28px; }
table { width: 100%; border-collapse: collapse; font-size: 11px; }
thead { position: sticky; top: 0; background: #0b1820; z-index: 1; }
tbody { display: block; height: calc(100vh - 954px); min-height: 156px; overflow: auto; }
thead tr, tbody tr { display: grid; grid-template-columns: 44px 90px 92px 86px 92px 112px repeat(5, 1fr); align-items: center; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); text-align: right; font-variant-numeric: tabular-nums; }
th { color: var(--muted); text-transform: uppercase; font-size: 10px; }
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2), th:nth-child(3), td:nth-child(3) { text-align: left; }
tbody tr:hover, .selected-row { background: rgba(24, 199, 167, 0.08); }
td small { display: block; color: var(--muted); font-size: 10px; margin-top: 1px; }
.signal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 58px;
  height: 19px;
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 3px;
  color: var(--muted);
  background: #061016;
  font-size: 10px;
  font-weight: 800;
}
.signal.long, .signal.cover { color: var(--teal); border-color: rgba(19,214,172,.38); background: rgba(19,214,172,.08); }
.signal.short, .signal.exit { color: var(--red); border-color: rgba(255,78,99,.38); background: rgba(255,78,99,.08); }
.spark { display: block; width: 72px; height: 18px; margin-top: 3px; }
.spark polyline { fill: none; stroke: var(--muted); stroke-width: 1.4; vector-effect: non-scaling-stroke; }

@media (max-width: 1100px) {
  .terminal-top { grid-template-columns: 1fr; height: auto; }
  .app { grid-template-columns: 1fr; height: auto; }
  .sidebar { display: none; }
  .grid { grid-template-columns: 1fr; }
  .resonance-board { grid-auto-columns: minmax(360px, 1fr); }
  .contract-strip { grid-template-columns: 1fr 1fr; height: auto; }
  .contract-main, .contract-stat { min-height: 58px; }
  .table-panel, tbody { height: auto; max-height: none; }
}
