:root {
  --market-bg: #05080b;
  --market-panel: rgba(10, 18, 23, 0.94);
  --market-line: rgba(100, 255, 210, 0.22);
  --market-cyan: #63ffcf;
  --market-blue: #55d9ff;
  --market-violet: #a884ff;
  --market-red: #ff5678;
  --market-amber: #ffc85b;
  --market-text: #eafff8;
  --market-muted: #87a39c;
}

body {
  background:
    radial-gradient(circle at 78% 8%, rgba(84, 40, 160, 0.19), transparent 30rem),
    linear-gradient(rgba(99, 255, 207, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99, 255, 207, 0.035) 1px, transparent 1px),
    var(--market-bg);
  background-size: auto, 32px 32px, 32px 32px, auto;
  color: var(--market-text);
}

.market-console {
  min-height: calc(100dvh - 142px);
  padding: 1rem clamp(0.75rem, 2.4vw, 2rem) 2rem;
  font-family: "DM Sans", sans-serif;
}

.market-auth {
  width: min(28rem, 100%);
  margin: 10vh auto 0;
  padding: 2.4rem;
  border: 1px solid var(--market-line);
  background: var(--market-panel);
  text-align: center;
  box-shadow: 0 0 40px rgba(99, 255, 207, 0.08), inset 0 0 40px rgba(99, 255, 207, 0.03);
}

.market-lock-icon { color: var(--market-cyan); font-size: 2rem; }
.market-auth h1 { margin: 0.5rem 0; letter-spacing: 0.18em; font-size: 1.2rem; }
.market-auth p { color: var(--market-muted); }
.market-auth a {
  display: inline-flex;
  padding: 0.8rem 1.2rem;
  border: 1px solid var(--market-cyan);
  color: var(--market-bg);
  background: var(--market-cyan);
  text-decoration: none;
  font-weight: 800;
}

.market-dashboard { width: min(1440px, 100%); margin: 0 auto; }
.market-dashboard[hidden], .market-auth[hidden] { display: none !important; }

.market-command-bar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--market-line);
  background: linear-gradient(90deg, rgba(99, 255, 207, 0.08), rgba(168, 132, 255, 0.04));
}

.market-title { display: flex; align-items: center; gap: 0.6rem; color: var(--market-cyan); }
.market-title h1 { margin: 0; font: 800 1rem/1 "DM Sans", sans-serif; letter-spacing: 0.18em; }

.environment-switch { display: flex; justify-content: center; gap: 0.5rem; }
.environment-switch button {
  min-height: 2.4rem;
  padding: 0.45rem 1rem;
  border: 1px solid rgba(135, 163, 156, 0.3);
  background: transparent;
  color: var(--market-muted);
  font-weight: 800;
  letter-spacing: 0.08em;
}
.environment-switch .active { border-color: var(--market-cyan); color: var(--market-cyan); box-shadow: inset 0 0 18px rgba(99, 255, 207, 0.1); }
.environment-switch button:disabled { opacity: 0.52; }

.snapshot-age { display: flex; align-items: center; gap: 0.5rem; color: var(--market-muted); font-size: 0.74rem; letter-spacing: 0.08em; }
.snapshot-age > span { width: 0.65rem; height: 0.65rem; border-radius: 50%; background: var(--market-amber); box-shadow: 0 0 10px currentColor; }
.snapshot-age.live > span { background: var(--market-cyan); }
.snapshot-age.stale > span { background: var(--market-red); }

.market-message { min-height: 1.25rem; margin: 0.45rem 0; color: var(--market-amber); font-size: 0.78rem; }

.status-grid,
.pnl-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}

.status-grid article,
.pnl-grid article,
.market-section,
.market-controls {
  border: 1px solid var(--market-line);
  background: var(--market-panel);
  box-shadow: inset 0 0 24px rgba(99, 255, 207, 0.02);
}

.status-grid article,
.pnl-grid article { min-width: 0; padding: 0.8rem 0.95rem; }
.status-grid small,
.pnl-grid small { display: block; color: var(--market-muted); font-size: 0.62rem; font-weight: 800; letter-spacing: 0.15em; }
.status-grid strong { display: block; margin: 0.25rem 0; font-size: 0.92rem; color: var(--market-cyan); text-transform: uppercase; }
.status-grid span { display: block; overflow: hidden; color: var(--market-muted); font-size: 0.68rem; text-overflow: ellipsis; white-space: nowrap; }
.status-grid .stop-state strong { color: var(--market-amber); }
.status-grid .stop-state.paused strong { color: var(--market-red); }
.status-grid .strategy-state { grid-column: span 2; border-color: rgba(85, 217, 255, 0.42); }
.status-grid .strategy-state strong { color: var(--market-blue); }
.pnl-grid strong { display: block; margin-top: 0.25rem; font: 700 clamp(1.15rem, 2.5vw, 1.8rem)/1 "DM Sans", sans-serif; }
.pnl-grid .positive { color: var(--market-cyan); text-shadow: 0 0 18px rgba(99, 255, 207, 0.25); }
.pnl-grid .negative { color: var(--market-red); text-shadow: 0 0 18px rgba(255, 86, 120, 0.22); }
.pnl-total { border-color: rgba(99, 255, 207, 0.55) !important; }

.market-controls {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem;
  margin-bottom: 0.65rem;
}
.market-controls form { display: grid; grid-template-columns: auto 7rem auto auto; align-items: center; gap: 0.5rem; }
.market-controls label { color: var(--market-cyan); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.12em; }
.market-controls input {
  min-width: 0;
  padding: 0.58rem;
  border: 1px solid rgba(99, 255, 207, 0.45);
  border-radius: 0;
  background: #020506;
  color: var(--market-text);
  font: 700 0.95rem/1 "DM Sans", sans-serif;
}
.market-controls form span, .control-note { color: var(--market-muted); font-size: 0.68rem; }
.market-controls button {
  min-height: 2.35rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--market-cyan);
  border-radius: 0;
  background: transparent;
  color: var(--market-cyan);
  font-weight: 850;
  letter-spacing: 0.07em;
}
.market-controls button:disabled { opacity: 0.45; cursor: wait; }
.market-controls .pause-button { margin-left: auto; border-color: var(--market-red); color: var(--market-red); }
.market-controls .resume-button { margin-left: auto; border-color: var(--market-amber); color: var(--market-amber); }

.market-section { min-width: 0; padding: 0.75rem; margin-bottom: 0.65rem; }
.market-section > header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.65rem; }
.market-section h2 { margin: 0; font-size: 0.78rem; letter-spacing: 0.15em; }
.market-section > header > span { color: var(--market-cyan); font-weight: 800; }
.position-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr)); gap: 0.65rem; }
.position-card { padding: 0.75rem; border: 1px solid rgba(85, 217, 255, 0.24); background: rgba(2, 7, 10, 0.86); }
.position-card header { display: flex; justify-content: space-between; align-items: baseline; }
.position-card h3 { margin: 0; color: var(--market-blue); font-size: 1.2rem; letter-spacing: 0.08em; }
.position-card header strong { font-size: 1rem; }
.position-meta { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.35rem; margin: 0.65rem 0; }
.position-meta span { min-width: 0; }
.position-meta small { display: block; color: var(--market-muted); font-size: 0.56rem; letter-spacing: 0.1em; }
.position-meta b { display: block; overflow: hidden; font-size: 0.76rem; text-overflow: ellipsis; }
.trade-chart { display: block; width: 100%; height: 94px; background: rgba(0, 0, 0, 0.25); }
.chart-line { fill: none; stroke: var(--market-cyan); stroke-width: 2; vector-effect: non-scaling-stroke; }
.chart-current { stroke: var(--market-blue); }
.chart-target { stroke: var(--market-cyan); stroke-dasharray: 4 3; }
.chart-stop { stroke: var(--market-red); stroke-dasharray: 4 3; }
.chart-buy { fill: var(--market-cyan); }
.chart-sell { fill: var(--market-red); }
.empty-state { padding: 1.5rem; color: var(--market-muted); text-align: center; border: 1px dashed rgba(135, 163, 156, 0.22); }

.strategy-checks { padding: 0.7rem; margin-bottom: 0.65rem; border: 1px solid rgba(85, 217, 255, 0.18); background: rgba(2, 7, 10, 0.72); }
.strategy-checks[hidden] { display: none; }
.strategy-checks > header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.55rem; }
.strategy-checks h2 { margin: 0; font-size: 0.72rem; letter-spacing: 0.14em; }
.strategy-checks > header span { color: var(--market-blue); font-size: 0.7rem; font-weight: 850; letter-spacing: 0.08em; }
.strategy-decision { margin: 0 0 0.6rem; color: var(--market-muted); font-size: 0.67rem; line-height: 1.45; }
.strategy-decision strong { color: var(--market-cyan); }
.strategy-checks > div { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0.35rem; }
.strategy-check { min-width: 0; padding: 0.48rem; border: 1px solid rgba(135, 163, 156, 0.16); }
.strategy-check strong, .strategy-check span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strategy-check strong { color: var(--market-muted); font-size: 0.68rem; }
.strategy-check span { margin-top: 0.18rem; color: var(--market-red); font-size: 0.58rem; font-weight: 850; }
.strategy-check.qualified { border-color: rgba(99, 255, 207, 0.35); }
.strategy-check.qualified strong, .strategy-check.qualified span { color: var(--market-cyan); }
.strategy-check.selected { border-color: var(--market-blue); box-shadow: inset 0 0 0 1px rgba(85, 217, 255, 0.3), 0 0 14px rgba(85, 217, 255, 0.1); }

.market-split { display: grid; grid-template-columns: minmax(280px, 0.9fr) minmax(400px, 1.1fr); gap: 0.65rem; }
.readiness-list { display: grid; gap: 0.5rem; max-height: 26rem; overflow: auto; }
.readiness-row { display: grid; grid-template-columns: 3.7rem 1fr auto; align-items: center; gap: 0.55rem; }
.readiness-row strong { color: var(--market-blue); }
.readiness-copy { min-width: 0; }
.readiness-copy span { display: block; overflow: hidden; color: var(--market-muted); font-size: 0.68rem; text-overflow: ellipsis; white-space: nowrap; }
.meter { height: 0.36rem; margin-top: 0.25rem; background: rgba(135, 163, 156, 0.15); }
.meter i { display: block; height: 100%; background: linear-gradient(90deg, var(--market-violet), var(--market-cyan)); box-shadow: 0 0 10px rgba(99, 255, 207, 0.28); }
.readiness-row > span { font-size: 0.72rem; font-weight: 800; color: var(--market-cyan); }
.readiness-row.no-trade .readiness-copy span,
.readiness-row.no-trade > span { color: var(--market-red); }
.readiness-row.no-trade .meter { border: 1px solid rgba(255, 89, 100, 0.3); background: rgba(255, 89, 100, 0.08); }

.trade-table-wrap { max-width: 100%; max-height: 26rem; overflow: auto; }
.trades-section table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
.trades-section th { position: sticky; top: 0; padding: 0.55rem; background: #0a1217; color: var(--market-muted); text-align: left; letter-spacing: 0.08em; }
.trades-section td { padding: 0.58rem; border-top: 1px solid rgba(99, 255, 207, 0.09); white-space: nowrap; }
.trades-section td:first-child { color: var(--market-blue); font-weight: 850; }

@media (max-width: 860px) {
  .market-command-bar { grid-template-columns: 1fr auto; }
  .environment-switch { grid-column: 1 / -1; grid-row: 2; justify-content: stretch; }
  .environment-switch button { flex: 1; }
  .status-grid, .pnl-grid { grid-template-columns: repeat(2, 1fr); }
  .status-grid .strategy-state { grid-column: span 2; }
  .market-split { grid-template-columns: 1fr; }
  .market-controls { align-items: stretch; flex-wrap: wrap; }
  .market-controls form { width: 100%; grid-template-columns: auto minmax(6rem, 1fr) auto auto; }
  .market-controls .pause-button, .market-controls .resume-button { margin-left: 0; }
  .strategy-checks > div { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
  .market-console { padding-inline: 0.5rem; }
  .market-command-bar { padding: 0.65rem; }
  .environment-switch button { padding-inline: 0.45rem; font-size: 0.68rem; }
  .status-grid, .pnl-grid { gap: 0.45rem; }
  .status-grid article, .pnl-grid article { padding: 0.65rem; }
  .status-grid .strategy-state { grid-column: span 2; }
  .market-controls form { grid-template-columns: auto 1fr auto; }
  .market-controls form span { grid-column: 1 / -1; }
  .control-note { width: 100%; }
  .position-meta { grid-template-columns: repeat(2, 1fr); }
  .strategy-checks > div { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .trade-table-wrap { overflow-x: auto; }
  .trades-section table { min-width: 31rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; }
}
