/* ============================================================
   Trading Bot Dashboard — Design System
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ---------- Custom Properties ---------- */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #1c2128;
  --bg-terminal: #010409;
  --border: #30363d;
  --border-light: #3d444d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  --accent-start: #00d4aa;
  --accent-end: #00bcd4;
  --accent: #00d4aa;
  --success: #3fb950;
  --warning: #d29922;
  --error: #f85149;
  --info: #58a6ff;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
  --transition: 0.2s ease;
  --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', monospace;
}

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

html { font-size: 15px; }

body {
  font-family: var(--font-ui);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-light); }

/* ---------- Animations ---------- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes slideDown {
  from { opacity: 0; transform: translateY(-12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes terminalBlink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

.fade-in { animation: fadeIn 0.35s ease both; }

/* ---------- Layout ---------- */
.container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ---------- Login View ---------- */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-primary);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(0,212,170,.06) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 50%, rgba(0,188,212,.06) 0%, transparent 60%);
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  animation: fadeIn 0.5s ease;
}

.login-card .logo { font-size: 2.4rem; margin-bottom: 8px; }

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 4px;
  background: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.login-card .subtitle {
  color: var(--text-secondary);
  font-size: .9rem;
  margin-bottom: 32px;
}

.login-card .step { margin-bottom: 20px; }

.login-card .message {
  font-size: .85rem;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  display: none;
}
.login-card .message.success { display: block; background: rgba(63,185,80,.12); color: var(--success); border: 1px solid rgba(63,185,80,.25); }
.login-card .message.error { display: block; background: rgba(248,81,73,.1); color: var(--error); border: 1px solid rgba(248,81,73,.2); }

/* ---------- Form Elements ---------- */
input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: .95rem;
  transition: border-color var(--transition);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0,212,170,.12);
}

.otp-input {
  font-family: var(--font-mono) !important;
  font-size: 1.8rem !important;
  text-align: center;
  letter-spacing: 0.5em;
  padding: 14px !important;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius-md);
  font-family: var(--font-ui);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  outline: none;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary {
  background: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  color: #0d1117;
}
.btn-primary:hover:not(:disabled) {
  box-shadow: 0 4px 20px rgba(0,212,170,.3);
  transform: translateY(-1px);
}

.btn-danger {
  background: rgba(248,81,73,.15);
  color: var(--error);
  border: 1px solid rgba(248,81,73,.3);
}
.btn-danger:hover:not(:disabled) { background: rgba(248,81,73,.25); }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--border);
  color: var(--text-primary);
}

.btn-sm { padding: 6px 14px; font-size: .8rem; }
.btn-block { width: 100%; }
.btn .spinner {
  width: 16px; height: 16px;
  border: 2px solid transparent;
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ---------- Navigation ---------- */
#main-nav {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.nav-inner {
  display: flex;
  align-items: center;
  gap: 0;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
}

.nav-brand {
  font-weight: 700;
  font-size: 1rem;
  padding: 14px 20px 14px 0;
  background: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  border-right: 1px solid var(--border);
  margin-right: 4px;
  white-space: nowrap;
}

.nav-tab {
  padding: 14px 18px;
  color: var(--text-secondary);
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
  -webkit-user-select: none;
  user-select: none;
}
.nav-tab:hover { color: var(--text-primary); }
.nav-tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.nav-spacer { flex: 1; }

.nav-status {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px;
  font-size: .8rem;
  color: var(--text-muted);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex-shrink: 0;
}
.status-dot.connected { background: var(--success); box-shadow: 0 0 6px rgba(63,185,80,.5); }
.status-dot.disconnected { background: var(--error); }
.status-dot.running { background: var(--warning); animation: pulse 1.2s ease infinite; }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  animation: fadeIn 0.35s ease both;
}
.card-glass {
  background: rgba(22,27,34,.7);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title {
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ---------- Stat Cards Grid ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 16px;
  animation: fadeIn 0.35s ease both;
}
.stat-label {
  font-size: .75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 6px;
}
.stat-value {
  font-size: 1.3rem;
  font-weight: 700;
}
.stat-value.accent { color: var(--accent); }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-success { background: rgba(63,185,80,.12); color: var(--success); }
.badge-warning { background: rgba(210,153,34,.12); color: var(--warning); }
.badge-error   { background: rgba(248,81,73,.1);  color: var(--error); }
.badge-info    { background: rgba(88,166,255,.1);  color: var(--info); }
.badge-neutral { background: rgba(110,118,129,.12); color: var(--text-secondary); }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .85rem;
}
thead th {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
  white-space: nowrap;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(255,255,255,.02); }

.pnl-positive { color: var(--success); }
.pnl-negative { color: var(--error); }

/* ---------- Dashboard Layout ---------- */
.dashboard-grid {
  display: grid;
  gap: 20px;
  padding: 20px 0;
}

.section-title {
  font-size: .95rem;
  font-weight: 600;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ---------- Equity Chart ---------- */
.chart-container {
  position: relative;
  width: 100%;
  height: 280px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.chart-container canvas { width: 100%; height: 100%; }

/* ---------- Terminal ---------- */
.terminal-container {
  background: var(--bg-terminal);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.terminal-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  font-size: .8rem;
  color: var(--text-secondary);
}
.terminal-header .dots { display: flex; gap: 6px; }
.terminal-header .dot { width: 10px; height: 10px; border-radius: 50%; }
.terminal-header .dot.red    { background: #f85149; }
.terminal-header .dot.yellow { background: #d29922; }
.terminal-header .dot.green  { background: #3fb950; }

.terminal-output {
  padding: 14px 16px;
  height: 450px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: .82rem;
  line-height: 1.65;
  color: #c9d1d9;
  white-space: pre-wrap;
  word-break: break-all;
}
.terminal-output::-webkit-scrollbar-track { background: var(--bg-terminal); }

.terminal-line { display: block; }
.terminal-line.system { color: var(--info); }
.terminal-line.error { color: var(--error); }
.terminal-line.success { color: var(--success); }

.terminal-cursor {
  display: inline-block;
  width: 8px; height: 16px;
  background: var(--accent);
  animation: terminalBlink 1s step-end infinite;
  vertical-align: text-bottom;
  margin-left: 2px;
}

/* ---------- Command Controls ---------- */
.command-controls {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.command-controls .field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.command-controls .field label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.command-controls .field.grow { flex: 1; min-width: 200px; }
.command-controls select { min-width: 200px; }

.running-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 18px;
  background: rgba(210,153,34,.08);
  border: 1px solid rgba(210,153,34,.2);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  font-size: .88rem;
  color: var(--warning);
  animation: slideDown 0.3s ease;
}

/* ---------- History ---------- */
.history-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  overflow: hidden;
  animation: fadeIn 0.3s ease both;
}
.history-item-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  transition: background var(--transition);
}
.history-item-header:hover { background: var(--bg-tertiary); }
.history-item-header .cmd-name {
  font-family: var(--font-mono);
  font-weight: 500;
  font-size: .88rem;
}
.history-item-header .cmd-meta {
  margin-left: auto;
  display: flex;
  gap: 14px;
  font-size: .78rem;
  color: var(--text-secondary);
}
.history-item-body {
  display: none;
  padding: 0 16px 14px;
  border-top: 1px solid var(--border);
}
.history-item-body.open { display: block; }
.history-item-body pre {
  font-family: var(--font-mono);
  font-size: .78rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 300px;
  overflow-y: auto;
  padding: 12px 0;
}

/* ---------- Approved Combos Grid ---------- */
.combos-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.combo-card {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.combo-card .combo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.combo-card .combo-pair { font-weight: 600; font-size: .95rem; }
.combo-card .combo-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  font-size: .8rem;
  color: var(--text-secondary);
}
.combo-card .combo-stats span { display: flex; justify-content: space-between; }
.combo-card .combo-stats .val { color: var(--text-primary); font-weight: 500; }

/* ---------- Winner Card ---------- */
.winner-card {
  background: var(--bg-secondary);
  border: 1px solid var(--accent);
  border-radius: var(--radius-lg);
  padding: 20px 24px;
  box-shadow: 0 0 30px rgba(0,212,170,.06);
}
.winner-card .winner-name {
  font-size: 1.2rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-start), var(--accent-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 10px;
}
.winner-card .winner-metrics {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  font-size: .85rem;
}
.winner-card .metric-item { display: flex; flex-direction: column; gap: 2px; }
.winner-card .metric-label {
  font-size: .72rem;
  color: var(--text-muted);
  text-transform: uppercase;
}
.winner-card .metric-val { font-weight: 600; font-size: 1rem; }

/* ---------- Empty State ---------- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 2.5rem; margin-bottom: 10px; }
.empty-state p { font-size: .9rem; }

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .nav-brand { display: none; }
  .command-controls { flex-direction: column; }
  .command-controls .field { width: 100%; }
  .combos-grid { grid-template-columns: 1fr; }
  .winner-card .winner-metrics { gap: 14px; }
  .terminal-output { height: 320px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .nav-tab { padding: 12px 12px; font-size: .82rem; }
  .login-card { padding: 32px 24px; }
}
