/* === Trading Bot Dashboard === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --card-bg: #1a1d27;
  --card-border: #2a2d3a;
  --text: #e1e4ed;
  --text-muted: #888ba3;
  --green: #22c55e;
  --red: #ef4444;
  --accent: #6366f1;
  --accent-dim: #4f46e530;
  --radius: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  padding: 0;
  min-height: 100vh;
}

header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--card-border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

header h1 { font-size: 1.25rem; font-weight: 600; }
#status-bar { display: flex; gap: 12px; align-items: center; font-size: 0.8rem; color: var(--text-muted); }
.error-badge { color: var(--red); font-size: 0.8rem; cursor: help; }

main { padding: 20px 24px; max-width: 1200px; margin: 0 auto; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}

.card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 16px; color: var(--accent); }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 16px;
}

.metric { display: flex; flex-direction: column; gap: 2px; }
.metric label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.metric .num { font-size: 1.1rem; font-weight: 600; font-variant-numeric: tabular-nums; }

.num { text-align: right; font-variant-numeric: tabular-nums; }
.ticker { font-weight: 600; font-family: 'SF Mono', 'Fira Code', monospace; }

.green { color: var(--green); }
.red { color: var(--red); }

.table-wrap { overflow-x: auto; }

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

th {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 2px solid var(--card-border);
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

/* Sortable tables */
.sortable th {
  cursor: pointer;
  user-select: none;
}
.sortable th:hover { color: var(--text); }

.sort-asc::after { content: ' \25B2'; font-size: 0.7rem; }
.sort-desc::after { content: ' \25BC'; font-size: 0.7rem; }

td { padding: 6px 10px; border-bottom: 1px solid var(--card-border); white-space: nowrap; }
td.reason { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: help; }

tr:hover td { background: rgba(99, 102, 241, 0.04); }
tr.closed td { color: var(--text-muted); font-style: italic; }

.action-buy { color: var(--green); font-weight: 600; }
.action-sell { color: var(--red); font-weight: 600; }

/* Error section */
.error-toggle {
  background: none;
  border: 1px solid var(--red);
  color: var(--red);
  padding: 2px 12px;
  border-radius: 4px;
  font-size: 0.8rem;
  cursor: pointer;
}
.error-toggle:hover { background: rgba(239, 68, 68, 0.1); }

.error-section ul {
  padding-left: 20px;
  margin: 0;
}
.error-section li {
  margin-bottom: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Button */
.btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 0.8rem;
  cursor: pointer;
  margin-left: 12px;
  vertical-align: middle;
}
.btn:hover { background: #4f46e5; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* Section heading row */
.section-heading {
  display: flex;
  align-items: center;
  margin-bottom: 16px;
}
.section-heading h2 { margin-bottom: 0; }

/* History pagination */
#history-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}
#history-pagination button {
  background: var(--card-border);
  color: var(--text);
  border: none;
  border-radius: 4px;
  padding: 4px 12px;
  font-size: 0.8rem;
  cursor: pointer;
}
#history-pagination button:hover:not(:disabled) { background: var(--accent); }
#history-pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* Chart section */
#chart-section .chart-wrap {
  position: relative;
  height: 250px;
}

/* Market data stale */
.market-stale { color: var(--text-muted); }

/* Learning section */
#learning-section h3 { font-size: 0.85rem; margin: 12px 0 6px; color: var(--accent); }
#learning-section ul { padding-left: 20px; }
#learning-section li { margin-bottom: 4px; font-size: 0.85rem; color: var(--text-muted); }

/* Loading & error overlays */
.loading-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 17, 23, 0.85);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  z-index: 1000;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--card-border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--red); color: white;
  text-align: center; padding: 12px;
  font-size: 0.9rem;
  z-index: 1001;
}

.hidden { display: none; }

@media (max-width: 600px) {
  main { padding: 12px; }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
  td.reason { max-width: 140px; }
}
