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

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

:root {
  --bg: #0d1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --border: #30363d;
  --text: #c9d1d9;
  --text-muted: #8b949e;
  --accent: #58a6ff;
  --gain: #3fb950;
  --gain-bg: rgba(63, 185, 80, 0.08);
  --loss: #f85149;
  --loss-bg: rgba(248, 81, 73, 0.08);
  --flash: rgba(210, 153, 34, 0.35);
  --header-h: 60px;
  --toolbar-h: 56px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Header ── */
header {
  height: var(--header-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: -0.3px;
}

.logo-flag { font-size: 20px; }

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

.last-update {
  color: var(--text-muted);
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
}

/* ── Toolbar ── */
.toolbar {
  height: var(--toolbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  flex-shrink: 0;
}

.search-wrap {
  position: relative;
  flex: 1;
  max-width: 320px;
}

.search-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

input[type="search"] {
  width: 100%;
  padding: 7px 12px 7px 34px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

input[type="search"]:focus { border-color: var(--accent); }
input[type="search"]::placeholder { color: var(--text-muted); }

select {
  padding: 7px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  cursor: pointer;
}

.toolbar-stats {
  margin-left: auto;
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

/* ── Buttons ── */
button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: opacity 0.15s, background 0.15s;
}

.btn-primary {
  background: var(--accent);
  color: #0d1117;
  border-color: var(--accent);
}
.btn-primary:hover { opacity: 0.85; }

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg3); color: var(--text); }

.btn-ghost.active {
  color: var(--gain);
  border-color: var(--gain);
}

.spin {
  display: inline-block;
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Table container ── */
.table-wrap {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
}

.table-wrap::-webkit-scrollbar { width: 6px; height: 6px; }
.table-wrap::-webkit-scrollbar-track { background: var(--bg); }
.table-wrap::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'JetBrains Mono', monospace;
  font-size: 13px;
}

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

th {
  background: var(--bg2);
  color: var(--text-muted);
  font-weight: 500;
  text-align: right;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  user-select: none;
  cursor: pointer;
  transition: color 0.15s;
}

th:first-child, th:nth-child(2) { text-align: left; }
th:hover { color: var(--text); }
th.sort-asc::after { content: ' ↑'; color: var(--accent); }
th.sort-desc::after { content: ' ↓'; color: var(--accent); }

td {
  padding: 9px 14px;
  text-align: right;
  border-bottom: 1px solid rgba(48, 54, 61, 0.5);
  white-space: nowrap;
  transition: background-color 0.8s;
}

td:first-child, td:nth-child(2) { text-align: left; }

tr:hover td { background: var(--bg3); }

tr.gain td { background-color: var(--gain-bg); }
tr.loss td { background-color: var(--loss-bg); }
tr.gain:hover td, tr.loss:hover td { background: var(--bg3); }

tr.error td { opacity: 0.5; }
tr.error .ticker-badge { border-color: var(--text-muted); color: var(--text-muted); }
tr.error .error-reason { font-family: 'Inter', sans-serif; font-size: 12px; }

.ticker-badge {
  display: inline-block;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.3px;
  color: var(--accent);
}

.name-cell {
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
}

.price-cell { font-weight: 600; color: var(--text); }
.price-cell.flash { background-color: var(--flash) !important; }

.gain-text { color: var(--gain); font-weight: 600; }
.loss-text { color: var(--loss); font-weight: 600; }
.neutral-text { color: var(--text-muted); }

/* ── Loading / Empty states ── */
.state-row td {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
}

.loading-dots::after {
  content: '...';
  animation: dots 1.2s steps(4, end) infinite;
}
@keyframes dots {
  0%, 20% { content: ''; }
  40% { content: '.'; }
  60% { content: '..'; }
  80%, 100% { content: '...'; }
}

/* ── Status bar ── */
.statusbar {
  height: 28px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--gain);
  display: inline-block;
}
.status-dot.loading { background: #d29922; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

/* ── Responsive ── */
@media (max-width: 900px) {
  .col-mcap, .col-52h, .col-52l { display: none; }
}
@media (max-width: 600px) {
  .col-vol, .col-dh, .col-dl { display: none; }
  .name-cell { max-width: 120px; }
}
