:root {
  --bg: #0B1220;
  --panel: #121B2E;
  --panel-2: #16213A;
  --border: #22314A;
  --text: #E6EDF5;
  --muted: #7F93B3;
  --positive: #35D07F;
  --negative: #FF6B6B;
  --brand: #4C8BF5;
  --warning: #F5A623;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
}

#root { min-height: 100vh; }

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--panel);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
}

.sidebar-brand {
  padding: 0 20px 20px 20px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}

.sidebar-brand .dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--positive);
  margin-right: 8px;
  box-shadow: 0 0 6px var(--positive);
}

.nav-item {
  padding: 10px 20px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  border-left: 3px solid transparent;
  transition: all .15s ease;
}
.nav-item:hover { color: var(--text); background: rgba(255,255,255,0.02); }
.nav-item.active {
  color: var(--text);
  border-left-color: var(--brand);
  background: rgba(76,139,245,0.08);
}

/* ---------- Main ---------- */
.main {
  flex: 1;
  padding: 24px 32px;
  overflow-x: hidden;
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px 0;
}
.page-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin: 0 0 20px 0;
}

/* ---------- Cards / Stats ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}
.stat-label {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 8px;
}
.stat-value {
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.stat-value.positive { color: var(--positive); }
.stat-value.negative { color: var(--negative); }

/* ---------- Panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  margin-bottom: 20px;
}
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
}
.panel-title {
  font-size: 14px;
  font-weight: 600;
}

/* ---------- Toggle ---------- */
.toggle-group {
  display: inline-flex;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.toggle-btn {
  padding: 6px 14px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
  background: transparent;
  border: none;
}
.toggle-btn.active {
  background: var(--brand);
  color: #fff;
}

/* ---------- Table ---------- */
table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
}
.data-table td.text { font-family: var(--font-ui); }
.data-table tr:hover { background: rgba(255,255,255,0.02); cursor: pointer; }
.data-table tr:last-child td { border-bottom: none; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.badge .pulse {
  width: 6px; height: 6px; border-radius: 50%;
}
.badge.connected { background: rgba(53,208,127,0.12); color: var(--positive); }
.badge.connected .pulse { background: var(--positive); box-shadow: 0 0 5px var(--positive); }
.badge.disconnected { background: rgba(127,147,179,0.12); color: var(--muted); }
.badge.disconnected .pulse { background: var(--muted); }
.badge.open { background: rgba(76,139,245,0.12); color: var(--brand); }
.badge.buy { background: rgba(53,208,127,0.12); color: var(--positive); }
.badge.sell { background: rgba(255,107,107,0.12); color: var(--negative); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--muted);
}
.empty-state .title { color: var(--text); font-size: 14px; margin-bottom: 6px; font-weight: 600; }
.empty-state .sub { font-size: 12px; }

/* ---------- Forms ---------- */
.input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font-mono);
}
.input:focus { outline: none; border-color: var(--brand); }

.btn {
  background: var(--brand);
  color: #fff;
  border: none;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { filter: brightness(1.1); }
.btn.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 16px;
}
.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 320px;
  text-align: center;
}
.login-box h2 { margin: 0 0 6px 0; font-size: 17px; }
.login-box p { color: var(--muted); font-size: 12px; margin: 0 0 18px 0; }
.login-box .input { width: 100%; margin-bottom: 12px; }
.login-box .btn { width: 100%; }
.login-error { color: var(--negative); font-size: 12px; margin-top: 10px; }

/* ---------- Filters bar ---------- */
.filters-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

/* ---------- Raw payload ---------- */
.raw-payload {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  background: var(--panel-2);
  padding: 8px;
  border-radius: 4px;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 380px;
}

.skip-reason {
  color: var(--warning);
  font-size: 11px;
}

.topbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}
.topbar .logout {
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
}
.topbar .logout:hover { color: var(--text); }

.back-link {
  color: var(--brand);
  font-size: 12px;
  cursor: pointer;
  margin-bottom: 12px;
  display: inline-block;
}

/* ---------- Icons ---------- */
.icon { flex-shrink: 0; vertical-align: middle; }
.nav-item { display: flex; align-items: center; gap: 10px; }
.btn { display: inline-flex; align-items: center; gap: 6px; }
.btn.icon-only { padding: 8px; }
.btn.danger { background: var(--negative); }
.btn.danger.secondary { background: transparent; border: 1px solid var(--negative); color: var(--negative); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

/* ---------- Page fade-in ---------- */
.page-fade { animation: fadeIn .25s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Transitions everywhere sensible ---------- */
.stat-card, .panel, .btn, .input, .badge, .data-table tr, select.input {
  transition: background .15s ease, border-color .15s ease, transform .1s ease, box-shadow .15s ease;
}
.stat-card:hover { border-color: var(--brand); }
.btn:active:not(:disabled) { transform: scale(0.97); }

/* ---------- Row action buttons ---------- */
.row-actions { display: flex; gap: 6px; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  display: inline-flex;
  transition: all .15s ease;
}
.icon-btn:hover { color: var(--text); border-color: var(--brand); }
.icon-btn.danger:hover { color: var(--negative); border-color: var(--negative); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(5,8,15,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
  animation: fadeIn .15s ease;
}
.modal-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
  width: 480px;
  max-width: 92vw;
  max-height: 86vh;
  overflow-y: auto;
  animation: modalIn .18s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 18px;
}
.modal-header h3 { margin: 0; font-size: 16px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

/* ---------- Forms ---------- */
.form-row { margin-bottom: 14px; }
.form-row label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}
.form-row .input, .form-row select, .form-row textarea {
  width: 100%;
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
select.input {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font-ui);
}
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: 16px; height: 16px; }

/* ---------- Toggle switch (kill switch etc) ---------- */
.switch {
  position: relative;
  width: 40px; height: 22px;
  background: var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: background .2s ease;
  flex-shrink: 0;
}
.switch.on { background: var(--positive); }
.switch.danger-on { background: var(--negative); }
.switch::after {
  content: "";
  position: absolute; top: 2px; left: 2px;
  width: 18px; height: 18px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s ease;
}
.switch.on::after { transform: translateX(18px); }

/* ---------- Kill switch banner ---------- */
.kill-switch-banner {
  background: rgba(255,107,107,0.12);
  border: 1px solid var(--negative);
  color: var(--negative);
  padding: 10px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  animation: fadeIn .2s ease;
}

/* ---------- Status pill (active/paused) ---------- */
.badge.active { background: rgba(53,208,127,0.12); color: var(--positive); }
.badge.paused { background: rgba(245,166,35,0.12); color: var(--warning); }
.badge.closed { background: rgba(127,147,179,0.12); color: var(--muted); }

/* ---------- Settings key/value display + edit ---------- */
.kv-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.kv-row:last-child { border-bottom: none; }
.kv-row .k { color: var(--muted); }
.kv-row .v { font-family: var(--font-mono); }
.kv-row .v.editing { width: 55%; }

/* ---------- Section header with action ---------- */
.section-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 12px;
}
.section-header h2 { font-size: 15px; margin: 0; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 8px 14px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  border-bottom: 2px solid transparent;
  transition: all .15s ease;
}
.tab.active { color: var(--text); border-bottom-color: var(--brand); }
.tab:hover { color: var(--text); }

/* ---------- Toast ---------- */
.toast-wrap {
  position: fixed; bottom: 20px; right: 20px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  animation: toastIn .2s ease;
}
.toast.error { border-color: var(--negative); color: var(--negative); }
.toast.success { border-color: var(--positive); color: var(--positive); }
@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Health page dots ---------- */
.health-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.health-dot.ok { background: var(--positive); box-shadow: 0 0 6px var(--positive); }
.health-dot.bad { background: var(--negative); box-shadow: 0 0 6px var(--negative); }

/* ---------- Running trades live pulse ---------- */
.live-pulse {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--positive);
  display: inline-block;
  animation: pulseAnim 1.4s infinite;
}
@keyframes pulseAnim {
  0% { box-shadow: 0 0 0 0 rgba(53,208,127,0.5); }
  70% { box-shadow: 0 0 0 8px rgba(53,208,127,0); }
  100% { box-shadow: 0 0 0 0 rgba(53,208,127,0); }
}
