/* ============================================
   AI-Trading Agent Dashboard — Design System
   Theme: Mono (dark, minimalist)
   ============================================ */

/* --- Reset & Base --- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Mono Palette */
  --bg:           #0a0a0a;
  --bg-card:      #111111;
  --bg-card-hover:#151515;
  --border:       #1e1e1e;
  --border-light: #2a2a2a;

  --text:         #fafafa;
  --text-secondary:#a0a0a0;
  --text-muted:   #525252;

  --positive:     #22c55e;
  --positive-dim: rgba(34,197,94,0.15);
  --negative:     #ef4444;
  --negative-dim: rgba(239,68,68,0.15);

  --accent:       #ffffff;
  --accent-dim:   rgba(255,255,255,0.06);

  /* Spotlight */
  --spotlight-size: 350px;
  --spotlight-color: rgba(255,255,255,0.04);

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', monospace;

  /* Sizing */
  --radius: 12px;
  --radius-sm: 8px;
}

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

/* --- Sparkles Canvas (background) --- */
#sparkles-canvas {
  position: fixed;
  top: 0; left: 0;
  width: 100vw; height: 100vh;
  z-index: 0;
  pointer-events: none;
}

/* --- App Container --- */
.app {
  position: relative;
  z-index: 1;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 24px 60px;
}

/* ============================================
   BLOCK 1: Header
   ============================================ */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 32px;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.header-logo {
  height: 28px;
  width: auto;
  object-fit: contain;
  transition: opacity 0.2s;
  filter: brightness(1.1);
}
.header-logo:hover { opacity: 0.8; }

.header-title {
  font-size: 1.15rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.header-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 1px;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--positive);
  animation: pulse-dot 2s ease-in-out infinite;
}
.status-dot.offline {
  background: var(--negative);
  animation: none;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34,197,94,0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(34,197,94,0); }
}

.start-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ============================================
   BLOCK 2: Stats Grid (Spotlight Cards)
   ============================================ */
.stats-section {
  margin-bottom: 32px;
}

.section-title {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
  margin-bottom: 14px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}

/* Spotlight Card */
.s-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  overflow: hidden;
  transition: border-color 0.3s;
}
.s-card:hover {
  border-color: var(--border-light);
}

/* Spotlight glow effect */
.s-card::before {
  content: '';
  position: absolute;
  top: var(--mouse-y, -100px);
  left: var(--mouse-x, -100px);
  width: var(--spotlight-size);
  height: var(--spotlight-size);
  background: radial-gradient(circle, var(--spotlight-color), transparent 70%);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.s-card:hover::before {
  opacity: 1;
}

.s-card-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 500;
  margin-bottom: 8px;
}

.s-card-value {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: var(--font-mono);
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.s-card-value.large {
  font-size: 2.2rem;
}

.s-card-sub {
  font-size: 0.72rem;
  color: var(--text-secondary);
  margin-top: 4px;
  font-family: var(--font-mono);
}

.s-card-value.positive { color: var(--positive); }
.s-card-value.negative { color: var(--negative); }
.s-card-sub.positive { color: var(--positive); }
.s-card-sub.negative { color: var(--negative); }

/* Primary card (balance) */
.s-card.primary {
  border-color: var(--border-light);
  grid-column: span 2;
}

/* ============================================
   BLOCK 3: PnL Charts
   ============================================ */
.charts-section {
  margin-bottom: 32px;
}

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.chart-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  overflow: hidden;
}
.chart-card::before {
  content: '';
  position: absolute;
  top: var(--mouse-y, -100px);
  left: var(--mouse-x, -100px);
  width: var(--spotlight-size);
  height: var(--spotlight-size);
  background: radial-gradient(circle, var(--spotlight-color), transparent 70%);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.chart-card:hover::before { opacity: 1; }
.chart-card:hover { border-color: var(--border-light); }

.chart-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 12px;
}

.chart-title {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
}

.chart-value {
  font-size: 1rem;
  font-weight: 600;
  font-family: var(--font-mono);
}

.chart-canvas {
  width: 100%;
  height: 120px;
  display: block;
}

/* ============================================
   BLOCK 4 & 5: Tables (Positions + History)
   ============================================ */
.table-section {
  margin-bottom: 32px;
}

.table-card {
  position: relative;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table-card::before {
  content: '';
  position: absolute;
  top: var(--mouse-y, -100px);
  left: var(--mouse-x, -100px);
  width: var(--spotlight-size);
  height: var(--spotlight-size);
  background: radial-gradient(circle, var(--spotlight-color), transparent 70%);
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.table-card:hover::before { opacity: 1; }
.table-card:hover { border-color: var(--border-light); }

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.table-title {
  font-size: 0.85rem;
  font-weight: 600;
}

.table-badge {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--text-muted);
  background: var(--accent-dim);
  padding: 3px 10px;
  border-radius: 12px;
}

.table-wrapper {
  overflow-x: auto;
  max-height: 400px;
  overflow-y: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

th {
  padding: 10px 16px;
  text-align: left;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--accent-dim); }

.side-long {
  color: var(--positive);
  font-weight: 600;
}
.side-short {
  color: var(--negative);
  font-weight: 600;
}

.pnl-positive {
  color: var(--positive);
  font-weight: 500;
}
.pnl-negative {
  color: var(--negative);
  font-weight: 500;
}

.empty-state {
  padding: 32px;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* ============================================
   Drawdown mini-grid
   ============================================ */
.dd-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 4px;
  margin-top: 6px;
}

.dd-item {
  text-align: center;
}

.dd-label {
  font-size: 0.6rem;
  color: var(--text-muted);
  display: block;
}

.dd-val {
  font-size: 0.78rem;
  font-family: var(--font-mono);
  font-weight: 600;
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 900px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .s-card.primary {
    grid-column: span 2;
  }
}

@media (max-width: 600px) {
  .app { padding: 0 12px 40px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .s-card.primary { grid-column: span 2; }
  .header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .s-card-value { font-size: 1.2rem; }
  .s-card-value.large { font-size: 1.6rem; }
}

/* ============================================
   Animations
   ============================================ */
@keyframes fade-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.s-card, .chart-card, .table-card {
  animation: fade-in 0.5s ease both;
}

.s-card:nth-child(2) { animation-delay: 0.05s; }
.s-card:nth-child(3) { animation-delay: 0.1s; }
.s-card:nth-child(4) { animation-delay: 0.15s; }
.s-card:nth-child(5) { animation-delay: 0.2s; }
.s-card:nth-child(6) { animation-delay: 0.25s; }
.s-card:nth-child(7) { animation-delay: 0.3s; }
.s-card:nth-child(8) { animation-delay: 0.35s; }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
