:root {
  color-scheme: dark;
  --bg: #111412;
  --panel: #171b18;
  --panel-2: #1b211d;
  --border: #2b342f;
  --text: #e7eee9;
  --muted: #8e9a93;
  --grid: rgba(231, 238, 233, 0.07);
  --btc: #5ec6d6;
  --yes: #52d273;
  --ft: #e0b44c;
  --ok: #49c979;
  --warning: #d7a84b;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(82, 210, 115, 0.06), transparent 30%),
    var(--bg);
  color: var(--text);
  font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

.shell {
  width: min(1440px, 100vw);
  min-height: 100vh;
  margin: 0 auto;
  padding: 18px 20px 16px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 12px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 46px;
}

h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 680;
  letter-spacing: 0;
}

.subtle {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.connection-strip,
.legend,
.chart-tools {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.chip {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.02);
  font-size: 12px;
  white-space: nowrap;
}

.chip.ok {
  color: var(--ok);
  border-color: rgba(73, 201, 121, 0.35);
}

.chip.warn {
  color: var(--warning);
  border-color: rgba(224, 180, 76, 0.35);
}

.chip.offline {
  color: #ee6d6d;
  border-color: rgba(238, 109, 109, 0.35);
}

.timestamp {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  padding: 14px 16px 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.22);
}

.chart-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.tool {
  height: 28px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 10px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.tool:hover,
.tool.active {
  color: var(--text);
  border-color: rgba(82, 210, 115, 0.42);
  background: rgba(82, 210, 115, 0.08);
}

.analysis-bar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.analysis-bar div {
  min-width: 0;
  border: 1px solid rgba(231, 238, 233, 0.08);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.018);
  padding: 7px 9px;
}

.analysis-bar span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.analysis-bar strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  font-weight: 660;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.analysis-bar strong.positive {
  color: var(--ok);
}

.analysis-bar strong.negative {
  color: #ee6d6d;
}

.legend span {
  color: var(--muted);
  white-space: nowrap;
}

.legend strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-weight: 620;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
}

.dot.btc {
  background: var(--btc);
}

.dot.yes {
  background: var(--yes);
}

.dot.ft {
  background: var(--ft);
}

.chart-wrap {
  position: relative;
  min-height: 360px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
}

.y-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: flex-end;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  padding: 2px 0 4px;
}

.plot-area {
  position: relative;
  min-width: 0;
  min-height: 360px;
  cursor: crosshair;
}

.chart {
  width: 100%;
  height: 100%;
  min-height: 360px;
  border: 1px solid rgba(231, 238, 233, 0.08);
  border-radius: 6px;
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 100% 25%, 10% 100%;
}

.shade {
  opacity: 0.13;
  pointer-events: none;
}

.shade.split {
  fill: var(--btc);
}

.shade.trade {
  fill: var(--yes);
}

.shade.merge {
  fill: var(--ft);
}

.reference-layer line {
  stroke: rgba(231, 238, 233, 0.16);
  stroke-dasharray: 6 8;
  vector-effect: non-scaling-stroke;
}

.reference-layer .midline {
  stroke: rgba(231, 238, 233, 0.24);
  stroke-dasharray: 0;
}

.reference-layer text {
  fill: rgba(231, 238, 233, 0.52);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.crosshair {
  position: absolute;
  top: 1px;
  bottom: 1px;
  width: 1px;
  left: 45.6667%;
  background: rgba(231, 238, 233, 0.35);
  pointer-events: none;
}

.crosshair.hidden,
.cursor-card.hidden {
  display: none;
}

.chart-badges {
  position: absolute;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: min(520px, 55%);
  pointer-events: none;
}

.chart-badges span,
.endpoint-label {
  border: 1px solid rgba(231, 238, 233, 0.12);
  border-radius: 999px;
  background: rgba(16, 19, 17, 0.78);
  color: var(--muted);
  padding: 4px 8px;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.chart-badges span.positive {
  color: var(--ok);
  border-color: rgba(73, 201, 121, 0.25);
}

.chart-badges span.negative {
  color: #ee6d6d;
  border-color: rgba(238, 109, 109, 0.26);
}

.endpoint-label {
  position: absolute;
  right: 10px;
  transform: translateY(-50%);
  pointer-events: none;
}

.endpoint-btc {
  color: var(--btc);
}

.endpoint-yes {
  color: var(--yes);
}

.endpoint-ft {
  color: var(--ft);
}

.cursor-card {
  position: absolute;
  top: 48px;
  left: min(48%, calc(100% - 250px));
  display: grid;
  grid-template-columns: auto auto auto;
  gap: 3px 8px;
  min-width: 250px;
  border: 1px solid rgba(231, 238, 233, 0.13);
  border-radius: 6px;
  background: rgba(16, 19, 17, 0.88);
  padding: 8px 10px;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  pointer-events: none;
}

.cursor-card span:first-child {
  grid-column: 1 / -1;
  color: var(--text);
  font-weight: 660;
}

.cursor-card b {
  color: var(--muted);
  font-weight: 560;
}

.series {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
}

.btc-line {
  stroke: var(--btc);
}

.yes-line {
  stroke: var(--yes);
}

.ft-line {
  stroke: var(--ft);
}

.x-axis {
  display: flex;
  justify-content: space-between;
  padding-left: 52px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.phase-row {
  position: relative;
  height: 28px;
  display: grid;
  grid-template-columns: 20fr 240fr 40fr;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #151916;
}

.phase {
  display: flex;
  align-items: center;
  justify-content: center;
  color: rgba(231, 238, 233, 0.88);
  font-size: 12px;
  font-weight: 620;
  border-right: 1px solid rgba(231, 238, 233, 0.1);
}

.phase:last-of-type {
  border-right: 0;
}

.phase.split {
  background: rgba(94, 198, 214, 0.12);
}

.phase.trade {
  background: rgba(82, 210, 115, 0.1);
}

.phase.merge {
  background: rgba(224, 180, 76, 0.13);
}

.phase-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  left: 45.6667%;
  background: #f4f6f0;
  box-shadow: 0 0 0 1px rgba(244, 246, 240, 0.24);
}

.status-table-panel {
  min-height: 260px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #151916;
  padding: 10px 12px;
}

.status-table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.status-table-head h2 {
  margin: 0;
  font-size: 14px;
  font-weight: 680;
  letter-spacing: 0;
}

.status-table-head p,
.pager span {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.pager,
.page-buttons {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-table-wrap {
  min-height: 0;
  overflow: auto;
  border: 1px solid rgba(231, 238, 233, 0.08);
  border-radius: 6px;
}

.status-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.status-table th,
.status-table td {
  padding: 6px 8px;
  border-bottom: 1px solid rgba(231, 238, 233, 0.07);
  text-align: left;
  white-space: nowrap;
}

.status-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #171b18;
  font-weight: 620;
}

.status-table tr.current-row td {
  background: rgba(82, 210, 115, 0.07);
}

.status-table tr.selected-row td {
  background: rgba(94, 198, 214, 0.1);
}

.status-table tr.current-row.selected-row td {
  background: linear-gradient(
    90deg,
    rgba(82, 210, 115, 0.1),
    rgba(94, 198, 214, 0.12)
  );
}

.status-table tbody tr {
  cursor: pointer;
}

.status-table tbody tr:hover td,
.status-table tbody tr:focus-visible td {
  background: rgba(231, 238, 233, 0.045);
}

.status-table td:last-child {
  min-width: 280px;
  white-space: normal;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  border: 1px solid rgba(231, 238, 233, 0.1);
  border-radius: 999px;
  padding: 2px 7px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.018);
  font-size: 11px;
}

.status-pill.ok {
  color: var(--ok);
  border-color: rgba(73, 201, 121, 0.25);
}

.status-pill.warn {
  color: var(--warning);
  border-color: rgba(224, 180, 76, 0.28);
}

.status-pill.idle {
  color: var(--muted);
}

.page-button {
  min-width: 30px;
  height: 26px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.02);
  color: var(--muted);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.page-button.active {
  color: var(--text);
  border-color: rgba(82, 210, 115, 0.42);
  background: rgba(82, 210, 115, 0.08);
}

@media (max-width: 860px) {
  .shell {
    padding: 12px;
  }

  .topbar,
  .chart-head {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .status-table-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .chart-wrap {
    min-height: 360px;
    grid-template-columns: 34px minmax(0, 1fr);
  }

  .chart {
    min-height: 360px;
  }

  .phase {
    font-size: 10px;
  }
}
