/* ═══════════════════════════════════════════════════════════
   Polymarket Terminal — Design System v1
   基于 DESIGN.md 规范
   ═══════════════════════════════════════════════════════════ */

/* ── Fonts ── */
@font-face {
  font-family: 'Satoshi';
  src: url('fonts/Satoshi-Regular.woff2') format('woff2');
  font-weight: 400;
  font-display: swap;
  font-style: normal;
}
@font-face {
  font-family: 'Satoshi';
  src: url('fonts/Satoshi-Medium.woff2') format('woff2');
  font-weight: 500;
  font-display: swap;
  font-style: normal;
}
@font-face {
  font-family: 'Satoshi';
  src: url('fonts/Satoshi-Bold.woff2') format('woff2');
  font-weight: 700;
  font-display: swap;
  font-style: normal;
}
@font-face {
  font-family: 'DM Sans';
  src: url('fonts/DMSans-Regular.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
  font-style: normal;
}
@font-face {
  font-family: 'JetBrains Mono';
  src: url('fonts/JetBrainsMono-Regular.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
  font-style: normal;
}

/* ── Design Tokens ── */
:root {
  /* Color */
  --bg-primary: #0a0e17;
  --bg-surface: #111827;
  --bg-tertiary: #1a2332;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #f59e0b;
  --profit: #00d4aa;
  --loss: #ff4757;
  --border: #1e293b;
  --border-hover: #334155;

  /* Semantic backgrounds */
  --profit-bg: rgba(0, 212, 170, 0.08);
  --loss-bg: rgba(255, 71, 87, 0.08);
  --accent-bg: rgba(245, 158, 11, 0.1);

  /* Typography */
  --font-display: 'Satoshi', -apple-system, 'Segoe UI', sans-serif;
  --font-body: 'DM Sans', -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', 'Fira Code', monospace;

  /* Spacing (4px base) */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 12px;
  --space-lg: 16px;
  --space-xl: 20px;
  --space-2xl: 24px;
  --space-3xl: 32px;

  /* Radius */
  --radius-sm: 2px;
  --radius-md: 4px;
  --radius-full: 9999px;

  /* Motion */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --duration-micro: 50ms;
  --duration-short: 150ms;
  --duration-medium: 200ms;
}

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

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

/* ── Typography Scale ── */
h1 { font-family: var(--font-display); font-size: 28px; font-weight: 700; letter-spacing: -0.03em; }
h2 { font-family: var(--font-display); font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
h3 { font-family: var(--font-display); font-size: 16px; font-weight: 600; }
.text-small { font-size: 12px; }
.text-caption {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.text-mono { font-family: var(--font-mono); }
.text-muted { color: var(--text-muted); }

/* ── Status Bar (Header) ── */
.status-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-md) var(--space-xl);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.status-bar__title {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.status-bar__meta {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: 12px;
  color: var(--text-secondary);
}

/* ── Container ── */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: var(--space-lg);
}

/* ── Grid ── */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
}

.grid-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: var(--space-md);
}

.grid-stats--tight {
  margin-bottom: var(--space-3xl);
}

/* ── Stat Card ── */
.stat-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-lg);
}

.stat-card__label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-xs);
}

.stat-card__value {
  font-family: var(--font-mono);
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stat-card__sub {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-muted);
  margin-top: var(--space-xs);
}

/* ── Module (Section) ── */
.module {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2xl);
  margin-bottom: var(--space-lg);
}

.module__header {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: var(--space-lg);
  display: flex;
  align-items: center;
  gap: var(--space-sm);
}

.module__body--scroll {
  max-height: 300px;
  overflow-y: auto;
}

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 2px var(--space-sm);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 500;
}

.badge--version {
  background: var(--accent);
  color: #000;
}

.badge--count {
  background: var(--accent);
  color: #000;
  font-weight: 600;
}

.badge--profit {
  background: var(--profit-bg);
  color: var(--profit);
}

.badge--loss {
  background: var(--loss-bg);
  color: var(--loss);
}

.badge--accent {
  background: var(--accent-bg);
  color: var(--accent);
}

.badge--neutral {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

/* ── Table ── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: left;
  padding: var(--space-sm);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  padding: var(--space-sm);
  border-bottom: 1px solid rgba(30, 41, 59, 0.4);
  vertical-align: middle;
}

tr:hover td {
  background: var(--bg-tertiary);
  transition: background var(--duration-micro) ease-in-out;
}

/* 市场名称用 body 字体 */
td.cell-title {
  font-family: var(--font-body);
  color: var(--text-primary);
}

.truncate {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Chip (Filter) ── */
.chip {
  display: inline-block;
  padding: 3px var(--space-sm);
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 11px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.chip .chip__value {
  color: var(--text-primary);
  font-weight: 700;
}

.chip--accent {
  border-color: rgba(245, 158, 11, 0.3);
  color: var(--accent);
  background: var(--accent-bg);
}

.chip--profit {
  border-color: rgba(0, 212, 170, 0.3);
  color: var(--profit);
  background: var(--profit-bg);
}

.chip--loss {
  border-color: rgba(255, 71, 87, 0.3);
  color: var(--loss);
  background: var(--loss-bg);
}

.filter-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: var(--space-md);
}

/* ── Progress Bar ── */
.progress-bar {
  background: var(--bg-primary);
  border-radius: var(--radius-sm);
  height: 6px;
  overflow: hidden;
  margin-top: var(--space-sm);
}

.progress-bar__fill {
  height: 100%;
  border-radius: var(--radius-sm);
  background: var(--accent);
  transition: width var(--duration-medium) var(--ease-out);
}

/* ── Status Dot ── */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  display: inline-block;
  margin-right: var(--space-xs);
}

.status-dot--on {
  background: var(--profit);
  animation: pulse 2s infinite;
}

.status-dot--off {
  background: var(--loss);
  animation: none;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ── Tag (Category) ── */
.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
}

.tag--sports {
  background: var(--profit-bg);
  color: var(--profit);
}

.tag--geo {
  background: rgba(139, 92, 246, 0.12);
  color: #a78bfa;
}

.tag--politics {
  background: var(--loss-bg);
  color: var(--loss);
}

.tag--other {
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

/* ── Price / PnL ── */
.price {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 11px;
}

.profit { color: var(--profit); }
.loss { color: var(--loss); }
.accent { color: var(--accent); }
.accent-purple { color: #a78bfa; }

/* ── PnL Grid (Win/Lose breakdown) ── */
.pnl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-lg);
  margin-bottom: var(--space-lg);
}

.pnl-box {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-lg);
}

.pnl-box--win {
  border-left: 3px solid var(--profit);
}

.pnl-box--lose {
  border-left: 3px solid var(--loss);
}

.pnl-box h3 {
  font-size: 13px;
  margin-bottom: var(--space-md);
  display: flex;
  align-items: center;
  gap: 6px;
}

.pnl-metric {
  display: flex;
  justify-content: space-between;
  padding: var(--space-xs) 0;
  font-size: 12px;
  border-bottom: 1px solid rgba(30, 41, 59, 0.3);
}

.pnl-metric:last-child {
  border: none;
}

.pnl-metric__value {
  font-weight: 600;
  font-family: var(--font-mono);
}

/* ── Signal Feed ── */
.signal-item {
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  margin-bottom: 2px;
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
}

.signal-item--highlight {
  background: var(--profit-bg);
}

/* ── System Log ── */
.log-feed {
  font-family: var(--font-mono);
  font-size: 11px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
}

.log-feed__line--profit { color: var(--profit); }
.log-feed__line--loss { color: var(--loss); }
.log-feed__line--accent { color: var(--accent); }
.log-feed__line--info { color: #38bdf8; }

/* ── Alert ── */
.alert {
  padding: var(--space-sm) var(--space-lg);
  border: 1px solid;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.alert--success {
  background: var(--profit-bg);
  border-color: rgba(0, 212, 170, 0.2);
  color: var(--profit);
}

.alert--warning {
  background: var(--accent-bg);
  border-color: rgba(245, 158, 11, 0.2);
  color: var(--accent);
}

.alert--error {
  background: var(--loss-bg);
  border-color: rgba(255, 71, 87, 0.2);
  color: var(--loss);
}

/* ── Button ── */
.btn {
  border: none;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  border-radius: var(--radius-md);
  padding: 4px var(--space-md);
}

.btn--primary {
  background: var(--accent);
  color: #000;
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}

/* ── Event Driver Stats Grid ── */
.ed-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

/* ── Backtest Stats Grid ── */
.bt-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-sm);
  margin-bottom: var(--space-lg);
}

/* ── Utility ── */
.text-center { text-align: center; }
.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: var(--space-xl);
  font-size: 12px;
}
.hidden { display: none !important; }

/* ── Card accent borders ── */
.stat-card--arb {
  border-left: 3px solid #a78bfa;
}

.stat-card--mm {
  border-left: 3px solid var(--accent);
}

/* ── Divider ── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: var(--space-md) 0;
}

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

/* ── Value Flash Animation ── */
@keyframes flash-profit {
  0% { color: var(--text-primary); }
  50% { color: var(--profit); }
  100% { color: var(--profit); }
}

@keyframes flash-loss {
  0% { color: var(--text-primary); }
  50% { color: var(--loss); }
  100% { color: var(--loss); }
}

.value-flash--profit { animation: flash-profit var(--duration-medium) var(--ease-out); }
.value-flash--loss { animation: flash-loss var(--duration-medium) var(--ease-out); }

/* ── Signal Slide-in ── */
@keyframes slide-in {
  from { opacity: 0; transform: translateX(-8px); }
  to { opacity: 1; transform: translateX(0); }
}

.signal-item--new { animation: slide-in var(--duration-short) var(--ease-out); }

/* ── Responsive ── */
@media (max-width: 960px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .pnl-grid { grid-template-columns: 1fr; }
  .ed-stats-grid { grid-template-columns: repeat(2, 1fr); }
  .bt-stats-grid { grid-template-columns: repeat(2, 1fr); }
}
