:root {
  color-scheme: dark;
  --bg: #080b11;
  --panel: #0e131d;
  --panel-2: #121927;
  --line: #222c3d;
  --line-hot: #33425a;
  --text: #f1f5fb;
  --muted: #8491a6;
  --green: #3ed598;
  --red: #ff6b78;
  --amber: #ffbd59;
  --blue: #63a4ff;
  --cyan: #44d6e8;
  --purple: #d792ff;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    radial-gradient(circle at 24% -18%, rgba(43, 93, 156, .18), transparent 31rem),
    var(--bg);
  font-size: 12px;
  line-height: 1.35;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
h1, h2, p { margin-top: 0; }
h1 { margin: 0; font-size: 16px; letter-spacing: .015em; }
h2 { margin-bottom: 4px; font-size: 15px; letter-spacing: -.015em; }
.eyebrow {
  margin-bottom: 3px;
  color: var(--blue);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: .13em;
  text-transform: uppercase;
}
.muted { color: var(--muted); line-height: 1.4; }
.mono, code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.topbar {
  min-height: 54px;
  padding: 7px 12px;
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(8, 11, 17, .92);
  backdrop-filter: blur(14px);
}
.brand-block { display: flex; align-items: center; gap: 9px; }
.brand-block p { margin: 1px 0 0; color: var(--muted); font-size: 10px; }
.brand-pulse {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 0 5px rgba(255, 189, 89, .1), 0 0 14px rgba(255, 189, 89, .72);
}
.top-actions, .panel-heading, .status-line, .legend, .dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
}

.shell {
  width: 100%;
  margin: 0;
  padding: 7px 8px 20px;
  display: grid;
  gap: 6px;
}
.panel {
  min-width: 0;
  padding: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: rgba(14, 19, 29, .95);
}
.panel:hover { border-color: var(--line-hot); }
.hero-grid {
  display: grid;
  grid-template-columns: minmax(290px, 1.08fr) minmax(260px, 1fr) minmax(290px, 1.08fr);
  gap: 6px;
}
.hero-grid .panel { min-height: 108px; }
.hero-grid .muted { margin-bottom: 6px; font-size: 10px; }
.control-panel { background: linear-gradient(135deg, rgba(20, 27, 39, .98), rgba(13, 18, 27, .98)); }
.runtime-card, .market-card { display: flex; flex-direction: column; justify-content: space-between; }
.market-card h2 { font-variant-numeric: tabular-nums; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 5px;
}
.metric {
  min-width: 0;
  min-height: 63px;
  padding: 7px 9px;
  background: rgba(12, 17, 26, .96);
}
.metric span, .metric small {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 9px;
  letter-spacing: .035em;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.metric span { text-transform: uppercase; }
.metric b {
  display: block;
  margin: 2px 0 1px;
  overflow: hidden;
  font-size: clamp(14px, 1.15vw, 18px);
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-line { justify-content: flex-start; }
.status-line h2 { margin: 0; }
.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--amber);
  box-shadow: 0 0 12px currentColor;
}
.status-dot.ready { background: var(--green); }
.status-dot.bad { background: var(--red); }
.status-dot.off { background: var(--muted); }
code {
  width: fit-content;
  padding: 3px 6px;
  color: #aab8c9;
  border-radius: 4px;
  background: #090d13;
  font-size: 9px;
}
.toggle {
  width: 54px;
  height: 28px;
  padding: 3px;
  flex: 0 0 auto;
  border: 1px solid #364354;
  border-radius: 999px;
  background: #252e3a;
  transition: .18s;
}
.toggle span {
  width: 20px;
  height: 20px;
  display: block;
  border-radius: 50%;
  background: #9aa6b6;
  transition: .18s;
}
.toggle.on { border-color: var(--red); background: rgba(255, 107, 120, .2); }
.toggle.on span { transform: translateX(26px); background: var(--red); box-shadow: 0 0 14px rgba(255, 107, 120, .6); }
.intent-warning {
  margin-top: 6px;
  padding: 6px 8px;
  color: #d5ad66;
  border: 1px solid rgba(255, 189, 89, .12);
  border-radius: 5px;
  background: rgba(255, 189, 89, .055);
  font-size: 9px;
  line-height: 1.35;
}
.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.mini-grid span { padding: 5px 7px; color: var(--muted); border-radius: 4px; background: #0b1017; font-size: 10px; }
.mini-grid b { float: right; color: var(--text); font-variant-numeric: tabular-nums; }

.chart-panel { padding: 0; background: #090d14; }
.chart-panel > .panel-heading { min-height: 43px; padding: 6px 10px; border-bottom: 1px solid var(--line); }
.chart-heading { min-width: 0; display: flex; align-items: baseline; gap: 7px; }
.chart-heading .eyebrow, .chart-heading h2 { margin: 0; white-space: nowrap; }
.chart-range { color: var(--muted); font-size: 9px; font-variant-numeric: tabular-nums; white-space: nowrap; }
#price-chart {
  width: 100%;
  height: clamp(300px, 42vh, 480px);
  display: block;
  background: #090d14;
}
.legend { justify-content: flex-end; flex-wrap: wrap; color: var(--muted); font-size: 9px; }
.legend span { white-space: nowrap; }
.legend span::before {
  width: 12px;
  height: 2px;
  margin-right: 4px;
  display: inline-block;
  vertical-align: middle;
  border-radius: 2px;
  background: currentColor;
  content: "";
}
.twap-key { color: var(--green); }
.local-chainlink-key { color: var(--cyan); }
.local-gmx-key { color: #b58cff; }
.chainlink-key { color: var(--blue); }
.gmx-key { color: var(--purple); }
.start-key { color: var(--amber); }

.two-column { display: grid; grid-template-columns: minmax(0, .9fr) minmax(0, 1.1fr); gap: 6px; }
.two-column > .panel { min-height: 116px; }
.pill { padding: 3px 6px; color: var(--muted); border: 1px solid var(--line); border-radius: 999px; font-size: 9px; }
.health-grid { display: grid; grid-template-columns: repeat(5, minmax(110px, 1fr)); gap: 4px; }
.health-item {
  min-width: 0;
  padding: 5px 6px;
  display: flex;
  justify-content: space-between;
  gap: 5px;
  color: var(--muted);
  border-radius: 4px;
  background: #0b1017;
  font-size: 9px;
}
.health-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.health-item b { flex: 0 0 auto; }
.health-item b.good { color: var(--green); }
.health-item b.bad { color: var(--red); }
.empty-state { padding: 13px 0; color: var(--muted); }
.position-row, .order-row {
  padding: 6px 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  border-bottom: 1px solid var(--line);
  font-size: 10px;
}

.table-panel { padding: 8px 10px 0; }
.table-scroll { overflow-x: auto; }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: left; font-size: 10px; }
th { color: var(--muted); font-size: 9px; font-weight: 650; letter-spacing: .045em; text-transform: uppercase; }
select, input { padding: 6px 8px; color: var(--text); border: 1px solid var(--line); border-radius: 5px; background: #090d13; }
.ghost, .primary, .danger-button {
  padding: 6px 9px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
}
.ghost:hover { border-color: var(--line-hot); }
.primary { border: 0; background: var(--blue); color: #07101c; font-weight: 800; }
.wide { width: 100%; padding: 10px; }
.danger-button { border: 0; background: var(--red); color: #21070b; font-weight: 800; }
.danger-button:disabled { opacity: .35; cursor: not-allowed; }
.freshness { color: var(--muted); font-size: 10px; font-variant-numeric: tabular-nums; }
.freshness.live { color: var(--green); }
.positive { color: var(--green); }
.negative, .danger, .error-text { color: var(--red); }

dialog {
  width: min(500px, calc(100% - 30px));
  padding: 0;
  color: var(--text);
  border: 1px solid #71313d;
  border-radius: 9px;
  background: var(--panel);
}
dialog::backdrop { background: rgba(0, 0, 0, .75); backdrop-filter: blur(4px); }
.dialog-card { padding: 20px; }
.dialog-card p { color: var(--muted); line-height: 1.55; }
.confirm-row { margin: 15px 0; display: flex; align-items: center; gap: 8px; color: #e6ebf2; }
.confirm-row input { accent-color: var(--red); }
.dialog-actions { justify-content: flex-end; }

.login-body { display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(400px, 100%);
  padding: 30px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(14, 19, 29, .97);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .45);
}
.brand-mark {
  width: 42px;
  height: 42px;
  margin-bottom: 20px;
  display: grid;
  place-items: center;
  color: #190d00;
  border-radius: 9px;
  background: #f7931a;
  font-size: 1.45rem;
  font-weight: 900;
}
.login-form { margin-top: 22px; display: grid; gap: 9px; }
.login-form label { color: var(--muted); font-size: 10px; }
.error-text { min-height: 1.2em; font-size: 10px; }

@media (min-width: 1700px) {
  .metrics-grid { grid-template-columns: repeat(10, minmax(120px, 1fr)); }
}

@media (max-width: 1180px) {
  .health-grid { grid-template-columns: repeat(2, minmax(110px, 1fr)); }
  .hero-grid { grid-template-columns: 1fr 1fr; }
  .market-card { grid-column: 1 / -1; min-height: 82px !important; }
}

@media (max-width: 820px) {
  .topbar { padding-inline: 9px; }
  .shell { padding-inline: 6px; }
  .hero-grid, .two-column { grid-template-columns: 1fr; }
  .market-card { grid-column: auto; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-panel > .panel-heading { align-items: flex-start; flex-direction: column; }
  .chart-heading { flex-wrap: wrap; }
  .legend { justify-content: flex-start; }
  #price-chart { height: 310px; }
}

@media (max-width: 520px) {
  .brand-block p { display: none; }
  .top-actions { gap: 6px; }
  .hero-grid .panel { min-height: 0; }
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric b { font-size: 13px; }
  .health-grid { grid-template-columns: 1fr; }
  .legend { max-height: 34px; overflow: hidden; }
}
