:root {
  --bg: #050709;
  --surface: #0a1014;
  --surface-raised: #0d161b;
  --surface-active: #112029;
  --line: #1d3039;
  --line-strong: #315766;
  --text: #edf5f7;
  --muted: #80949e;
  --cyan: #38e2ff;
  --green: #b9ff4f;
  --mint: #65e6a6;
  --red: #ff5f79;
  --amber: #ffc857;
  --shadow: 0 12px 30px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  grid-template-columns: 224px minmax(0, 1fr);
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(56, 226, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 226, 255, 0.022) 1px, transparent 1px);
  background-size: 40px 40px;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  font-stretch: normal;
  font-variant-numeric: tabular-nums;
  line-height: 1.45;
  letter-spacing: 0;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(56, 226, 255, 0.025), transparent 260px);
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 3;
  height: 100vh;
  padding: 16px 10px;
  border-right: 1px solid var(--line);
  background: rgba(5, 9, 12, 0.96);
  box-shadow: inset -1px 0 rgba(56, 226, 255, 0.045);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 20px;
}

.brand-mark {
  display: grid;
  flex: 0 0 38px;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(56, 226, 255, 0.62);
  border-radius: 6px;
  background: #0d1b21;
  color: var(--cyan);
  font-size: 17px;
  font-weight: 900;
  box-shadow: inset 0 0 18px rgba(56, 226, 255, 0.08), 0 0 22px rgba(56, 226, 255, 0.1);
}

.brand strong { display: block; font-size: 14px; letter-spacing: 0; }
.brand small {
  display: block;
  margin-top: 1px;
  color: var(--green);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

button,
.nav {
  border: 1px solid transparent;
  color: var(--text);
  background: transparent;
  font: inherit;
  letter-spacing: 0;
  cursor: pointer;
}

.nav {
  width: 100%;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
  border-radius: 6px;
  color: var(--muted);
  transition: color 140ms ease, border-color 140ms ease, background 140ms ease;
}

.nav svg,
button svg,
.metric svg { width: 17px; height: 17px; stroke-width: 1.8; }

.nav.active,
.nav:hover {
  border-color: rgba(56, 226, 255, 0.24);
  background: rgba(56, 226, 255, 0.075);
  color: var(--text);
  box-shadow: inset 2px 0 var(--cyan);
}

.sidebar-footer {
  position: absolute;
  right: 10px;
  bottom: 16px;
  left: 10px;
  display: flex;
  gap: 8px;
}

.shell {
  position: relative;
  z-index: 1;
  min-width: 0;
  padding: 20px;
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

h1,
h2,
h3,
p { letter-spacing: 0; }

h1 { margin: 0; font-size: 25px; line-height: 1.15; }
h2 { margin: 0; font-size: 15px; line-height: 1.25; }
h3 { margin: 0; font-size: 14px; }
p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

.top-actions,
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid rgba(185, 255, 79, 0.28);
  border-radius: 6px;
  background: rgba(185, 255, 79, 0.055);
  color: var(--green);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.live-pill.compact { min-height: 25px; padding: 0 8px; font-size: 10px; }

.live-pill i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px rgba(185, 255, 79, 0.8);
}

button,
.icon-btn {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  border-radius: 6px;
  border-color: rgba(56, 226, 255, 0.55);
  background: var(--cyan);
  color: #051015;
  font-weight: 800;
  transition: 140ms ease;
}

button:hover { filter: brightness(1.08); }

.secondary,
.icon-btn,
.range-tab,
.page-btn {
  border-color: var(--line);
  background: var(--surface-raised);
  color: var(--text);
}

.secondary:hover,
.icon-btn:hover,
.range-tab:hover,
.page-btn:hover {
  border-color: var(--cyan);
  color: var(--cyan);
  filter: none;
}

.icon-btn { width: 38px; padding: 0; }

.view { display: none; }
.view.active { display: grid; gap: 14px; }
.hidden { display: none !important; }

.dashboard-overview { display: grid; gap: 9px; }

.risk-alert {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 95, 121, 0.48);
  border-radius: 6px;
  background: rgba(255, 95, 121, 0.08);
  color: var(--red);
}

.risk-alert > svg { flex: 0 0 20px; width: 20px; height: 20px; }
.risk-alert div { min-width: 0; display: grid; gap: 2px; }
.risk-alert strong { font-size: 12px; text-transform: uppercase; }
.risk-alert span { overflow-wrap: anywhere; color: var(--text); font-size: 12px; }

.metrics { display: grid; gap: 9px; }
.primary-metrics { grid-template-columns: repeat(6, minmax(0, 1fr)); }
.secondary-metrics { grid-template-columns: repeat(11, minmax(92px, 1fr)); }

.metric,
.panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(10, 16, 20, 0.96);
  box-shadow: var(--shadow), inset 0 1px rgba(255, 255, 255, 0.025);
}

.metric {
  position: relative;
  min-height: 96px;
  overflow: hidden;
  padding: 14px;
}

.metric::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  left: 0;
  height: 2px;
  background: var(--cyan);
  opacity: 0.72;
}

.primary-metrics .metric:nth-child(2)::before,
.primary-metrics .metric:nth-child(6)::before { background: var(--green); }
.primary-metrics .metric:nth-child(3)::before { background: var(--amber); }
.primary-metrics .metric:nth-child(4)::before { background: var(--red); }
.primary-metrics .metric:nth-child(5)::before { background: var(--mint); }

.secondary-metrics .metric {
  min-height: 70px;
  padding: 10px;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.02);
}

.secondary-metrics .metric::before { height: 1px; opacity: 0.35; }

.metric-label {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
}

.metric-label svg { flex: 0 0 14px; width: 14px; height: 14px; color: var(--cyan); }
.metric-label span,
th {
  min-width: 0;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  line-height: 1.25;
  text-transform: uppercase;
}

.metric strong {
  display: block;
  margin-top: 12px;
  overflow-wrap: anywhere;
  font-size: 23px;
  font-weight: 800;
  line-height: 1.05;
  letter-spacing: 0;
}

.secondary-metrics .metric strong { margin-top: 8px; font-size: 17px; }

.panel { padding: 14px; }
.panel-head { margin-bottom: 12px; align-items: flex-start; }

.panel-count {
  min-width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(56, 226, 255, 0.4);
  border-radius: 50%;
  color: var(--cyan);
  font-size: 12px;
  font-weight: 900;
}

.panel-subhead {
  margin: 22px 0 12px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.grid.two {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(330px, 0.85fr);
  gap: 14px;
}

.chart-panel { padding-bottom: 10px; }
.chart-wrap {
  width: 100%;
  height: 292px;
  overflow: hidden;
  border: 1px solid rgba(56, 226, 255, 0.14);
  border-radius: 5px;
  background-color: #060b0f;
  background-image:
    linear-gradient(rgba(56, 226, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(56, 226, 255, 0.022) 1px, transparent 1px);
  background-size: 36px 36px;
}

#balanceChart { width: 100%; height: 100%; display: block; }
.chart-bg { fill: transparent; }
.chart-grid { stroke: rgba(128, 148, 158, 0.2); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 11px; font-family: Inter, ui-sans-serif, system-ui, sans-serif; }
.chart-area { fill: rgba(56, 226, 255, 0.085); }
.chart-line { fill: none; stroke: var(--cyan); stroke-width: 2.5; filter: drop-shadow(0 0 5px rgba(56, 226, 255, 0.4)); }
.chart-dot { fill: var(--green); stroke: #061015; stroke-width: 2; }
.chart-latest { fill: var(--green); font-size: 15px; font-weight: 900; font-family: Inter, ui-sans-serif, system-ui, sans-serif; }
.chart-empty { fill: var(--muted); font-size: 13px; font-family: Inter, ui-sans-serif, system-ui, sans-serif; }

.range-tabs,
.pager { display: flex; flex-wrap: wrap; gap: 6px; }

.range-tab,
.page-btn {
  min-height: 29px;
  padding: 0 9px;
  font-size: 11px;
}

.range-tab.active,
.page-btn.active {
  border-color: rgba(56, 226, 255, 0.75);
  background: rgba(56, 226, 255, 0.11);
  color: var(--cyan);
}

.pager { justify-content: flex-end; padding-top: 11px; }

.open-trades-panel {
  border-color: rgba(56, 226, 255, 0.25);
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.3), inset 0 1px rgba(56, 226, 255, 0.045);
}

.table-wrap { overflow: auto; scrollbar-color: var(--line-strong) transparent; }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
.open-trades-table { min-width: 1160px; }

th,
td {
  padding: 10px 9px;
  border-bottom: 1px solid rgba(29, 48, 57, 0.8);
  text-align: left;
  white-space: nowrap;
}

th { position: sticky; top: 0; z-index: 1; background: var(--surface); }
td { color: #d8e6ea; font-size: 12px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: rgba(56, 226, 255, 0.035); }

.open-trade-row { cursor: pointer; outline: none; }
.open-trade-row:hover td,
.open-trade-row:focus td { background: rgba(56, 226, 255, 0.065); }
.open-trade-row:focus td:first-child { box-shadow: inset 2px 0 var(--cyan); }

.pair-cell { display: flex; align-items: baseline; gap: 7px; }
.pair-cell strong { color: var(--text); font-size: 13px; }
.pair-cell small { color: var(--muted); font-size: 10px; }

.row-chart-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  color: var(--cyan);
}
.row-chart-icon svg { width: 16px; height: 16px; }

.status-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--mint);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}
.status-label::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mint);
  box-shadow: 0 0 9px rgba(101, 230, 166, 0.65);
}

.tp-progress { color: var(--cyan); font-weight: 800; }
.pos { color: var(--green) !important; }
.neg { color: var(--red) !important; }
.warn { color: var(--amber) !important; }

.badge,
.side {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  padding: 0 7px;
  border: 1px solid var(--line);
  border-radius: 5px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
}

.badge.good {
  border-color: rgba(185, 255, 79, 0.33);
  background: rgba(185, 255, 79, 0.065);
  color: var(--green);
}

.side.long {
  border-color: rgba(101, 230, 166, 0.34);
  background: rgba(101, 230, 166, 0.07);
  color: var(--mint);
}

.side.short {
  border-color: rgba(255, 95, 121, 0.36);
  background: rgba(255, 95, 121, 0.07);
  color: #ff8798;
}

.bars { display: grid; gap: 9px; }
.bar-row {
  display: grid;
  grid-template-columns: minmax(145px, 1.1fr) minmax(120px, 1fr) 42px;
  align-items: center;
  gap: 9px;
}
.bar-row span { color: #d5e2e6; font-size: 12px; }
.bar-row strong { text-align: right; color: var(--text); font-size: 12px; }
.bar { height: 7px; overflow: hidden; border-radius: 4px; background: rgba(29, 48, 57, 0.9); }
.bar i { display: block; height: 100%; border-radius: 4px; background: var(--cyan); }

.event-list { max-height: 380px; display: grid; gap: 7px; overflow: auto; }
.event {
  display: grid;
  grid-template-columns: 145px 135px 1fr;
  gap: 10px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(5, 9, 12, 0.65);
}
.event small { color: var(--muted); }
.event strong { color: var(--cyan); }

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
}
.form-grid.compact { grid-template-columns: repeat(4, minmax(150px, 1fr)); align-items: end; }
label { display: grid; gap: 6px; color: var(--muted); font-weight: 700; }
label.wide { grid-column: 1 / -1; }

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 5px;
  outline: none;
  background: #060b0e;
  color: var(--text);
  padding: 10px;
  font: inherit;
  letter-spacing: 0;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(56, 226, 255, 0.075);
}

textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.toggle { display: flex; align-items: center; gap: 10px; padding-top: 24px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--cyan); }
.source-list { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }

.output {
  margin: 14px 0 0;
  padding: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #060b0e;
  color: #dfe8eb;
}

.trade-dialog {
  width: min(1380px, calc(100vw - 36px));
  height: min(850px, calc(100vh - 36px));
  max-width: none;
  max-height: none;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: #070c0f;
  color: var(--text);
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.72), 0 0 55px rgba(56, 226, 255, 0.08);
}

.trade-dialog::backdrop { background: rgba(1, 4, 6, 0.82); backdrop-filter: blur(4px); }
.trade-dialog-shell { height: 100%; display: grid; grid-template-rows: auto auto minmax(0, 1fr) auto; }

.trade-dialog-head {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: #091116;
}

.trade-symbol-line { display: flex; align-items: center; gap: 9px; }
.trade-symbol-line h2 { font-size: 19px; }

.trade-chart-stats {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  border-bottom: 1px solid var(--line);
  background: #080e12;
}

.trade-chart-stats > div { min-width: 0; padding: 10px 14px; border-right: 1px solid var(--line); }
.trade-chart-stats > div:last-child { border-right: 0; }
.trade-chart-stats span { display: block; color: var(--muted); font-size: 9px; font-weight: 800; text-transform: uppercase; }
.trade-chart-stats strong { display: block; margin-top: 4px; overflow-wrap: anywhere; font-size: 14px; }

.trade-chart-stage { position: relative; min-height: 0; background: #060b10; }
#tradeChart { position: absolute; inset: 0; width: 100%; height: 100%; }
.trade-chart-loading {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2;
  max-width: min(440px, 80%);
  padding: 10px 13px;
  transform: translate(-50%, -50%);
  border: 1px solid var(--line-strong);
  border-radius: 5px;
  background: rgba(9, 17, 22, 0.94);
  color: var(--muted);
  text-align: center;
}

.trade-chart-footer {
  min-height: 55px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  background: #091116;
  color: var(--muted);
  font-size: 10px;
}

.trade-chart-levels { display: flex; flex-wrap: wrap; gap: 7px 13px; }
.trade-chart-levels span { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); }
.trade-chart-levels i { width: 13px; height: 2px; display: inline-block; }
.trade-chart-levels strong { color: #dbe8ec; font-weight: 700; }

#toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  max-width: 420px;
  padding: 11px 13px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--text);
  opacity: 0;
  transform: translateY(10px);
  transition: 160ms ease;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 1500px) {
  .primary-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .secondary-metrics { grid-template-columns: repeat(6, minmax(105px, 1fr)); }
}

@media (max-width: 1120px) {
  body { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    height: auto;
    display: flex;
    align-items: center;
    gap: 5px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { flex: 0 0 auto; padding: 3px 9px 3px 3px; }
  .nav { width: auto; min-width: max-content; }
  .sidebar-footer { position: static; margin-left: auto; }
  .grid.two { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .shell { padding: 12px; }
  .brand strong,
  .brand small,
  .nav span { display: none; }
  .brand-mark { width: 34px; height: 34px; flex-basis: 34px; }
  .nav { width: 38px; min-width: 38px; justify-content: center; padding: 0; }
  .sidebar-footer { margin-left: 0; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; flex-wrap: wrap; }
  .primary-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .secondary-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric { min-height: 84px; padding: 11px; }
  .metric strong { font-size: 19px; }
  .secondary-metrics .metric { min-height: 66px; }
  .secondary-metrics .metric strong { font-size: 15px; }
  .panel-head { align-items: flex-start; flex-direction: column; }
  .chart-wrap { height: 238px; }
  .bar-row { grid-template-columns: 1fr; }
  .event { grid-template-columns: 1fr; }
  .form-grid,
  .form-grid.compact { grid-template-columns: 1fr; }
  .trade-dialog {
    width: calc(100vw - 12px);
    height: calc(100vh - 12px);
  }
  .trade-dialog-head { min-height: 62px; padding: 10px; }
  .trade-symbol-line { flex-wrap: wrap; }
  .trade-chart-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .trade-chart-stats > div:nth-child(3) { border-right: 0; }
  .trade-chart-stats > div:nth-child(-n + 3) { border-bottom: 1px solid var(--line); }
  .trade-chart-footer { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 420px) {
  .secondary-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  h1 { font-size: 22px; }
}
