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

:root {
  --bg: #0a0a0f;
  --bg-card: #12121a;
  --bg-card-hover: #1a1a25;
  --border: #1e1e2e;
  --text: #e4e4ef;
  --text-dim: #8888a0;
  --text-bright: #ffffff;
  --accent: #6c5ce7;
  --accent-light: #a29bfe;
  --green: #00d68f;
  --green-dim: rgba(0,214,143,0.12);
  --red: #ff6b6b;
  --red-dim: rgba(255,107,107,0.12);
  --yellow: #ffd93d;
  --yellow-dim: rgba(255,217,61,0.12);
  --blue: #5b9aff;
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --mono: 'JetBrains Mono', 'SF Mono', monospace;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

/* ── Header ──────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 100;
  backdrop-filter: blur(12px);
}

.header-left { display: flex; align-items: center; gap: 12px; }
.header h1 { font-size: 1.25rem; font-weight: 700; color: var(--text-bright); }

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--border);
  color: var(--text-dim);
}
.badge.running { background: var(--green-dim); color: var(--green); }
.badge.sandbox { background: var(--yellow-dim); color: var(--yellow); }
.badge.production { background: var(--red-dim); color: var(--red); }
.badge.stopped { background: rgba(255,255,255,0.06); color: var(--text-dim); }

/* ── Tabs ────────────────────────────────────────────────── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 57px;
  z-index: 99;
}

.tab {
  flex: 1;
  padding: 12px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-dim);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }
.tab:active { background: rgba(108,92,231,0.08); }

/* ── Panels ──────────────────────────────────────────────── */
.panel { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.panel.hidden { display: none; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-bright);
  margin-bottom: 12px;
}

/* ── Mode Selector ───────────────────────────────────────── */
.mode-toggle {
  display: flex;
  gap: 8px;
  background: var(--bg);
  padding: 4px;
  border-radius: var(--radius);
}
.mode-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  border: 2px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.2s;
  font-family: var(--font);
}
.mode-btn.active {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--text-bright);
}
.mode-btn.active[data-mode="production"] { border-color: var(--red); }
.mode-icon { font-size: 1.5rem; }
.mode-label { font-size: 0.8rem; font-weight: 600; }

/* ── Stats Grid ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.stat-label { font-size: 0.7rem; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.04em; margin-bottom: 6px; }
.stat-value { font-size: 1.3rem; font-weight: 700; font-family: var(--mono); color: var(--text-bright); }
.stat-value.positive { color: var(--green); }
.stat-value.negative { color: var(--red); }

/* ── Controls ────────────────────────────────────────────── */
.control-row { display: flex; gap: 10px; align-items: center; }
.input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.2s;
}
.input:focus { border-color: var(--accent); }
.input.mono { font-family: var(--mono); font-size: 0.8rem; }
select.input { -webkit-appearance: none; appearance: none; }

.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-start { background: var(--green); color: #000; }
.btn-start:hover:not(:disabled) { background: #00e89c; }
.btn-stop { background: var(--red); color: #fff; }
.btn-stop:hover:not(:disabled) { background: #ff8787; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg-card-hover); }
.btn-icon { background: none; border: none; color: var(--text-dim); font-size: 1.3rem; cursor: pointer; padding: 4px 8px; }
.btn-sm { padding: 6px 12px; font-size: 0.75rem; background: var(--border); color: var(--text-dim); border: none; border-radius: var(--radius-sm); cursor: pointer; font-family: var(--font); }

.hint { font-size: 0.75rem; color: var(--text-dim); margin-top: 8px; }
.hint.warning { color: var(--yellow); }
.hint.success { color: var(--green); }
.hint.error { color: var(--red); }

/* ── Form Sections ───────────────────────────────────────── */
.form-section { margin-bottom: 20px; }
.form-section h4 {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--accent-light);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.form-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}
.form-label > span { font-size: 0.8rem; font-weight: 500; color: var(--text-dim); }

.key-status {
  font-size: 0.8rem;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
}
.key-status.set { background: var(--green-dim); color: var(--green); }
.key-status.unset { background: var(--yellow-dim); color: var(--yellow); }

/* ── Trades List ─────────────────────────────────────────── */
.trades-list { max-height: 300px; overflow-y: auto; }
.trade-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.trade-item:last-child { border-bottom: none; }
.trade-slug { font-family: var(--mono); font-size: 0.75rem; color: var(--text-dim); }
.trade-pnl { font-family: var(--mono); font-weight: 600; }
.trade-pnl.positive { color: var(--green); }
.trade-pnl.negative { color: var(--red); }
.empty { color: var(--text-dim); font-size: 0.85rem; font-style: italic; text-align: center; padding: 20px; }

/* ── Log Viewer ──────────────────────────────────────────── */
.log-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 0.8rem; color: var(--text-dim); }
.log-controls label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

.log-viewer {
  background: #000;
  color: #b0ffa0;
  font-family: var(--mono);
  font-size: 0.72rem;
  line-height: 1.5;
  padding: 12px;
  border-radius: var(--radius-sm);
  max-height: 400px;
  overflow-y: auto;
  overflow-x: hidden;
  word-break: break-all;
  white-space: pre-wrap;
  min-height: 100px;
}

.log-files-list { max-height: 300px; overflow-y: auto; }
.log-file-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  cursor: pointer;
  transition: background 0.15s;
}
.log-file-item:hover { background: var(--bg-card-hover); }
.log-file-name { font-family: var(--mono); font-size: 0.75rem; color: var(--blue); }
.log-file-meta { color: var(--text-dim); font-size: 0.7rem; }

/* ── Scrollbar ───────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ──────────────────────────────────────────── */
@media (min-width: 600px) {
  #app { max-width: 600px; margin: 0 auto; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.badge.running { animation: pulse 2s infinite; }
