/* ===========================
   CRYPTOGRID — style.css
   Complete Rewrite
   =========================== */

:root {
  --bg: #080b0f;
  --surface: #0e1218;
  --surface2: #141920;
  --surface3: #1a2030;
  --border: rgba(255,255,255,0.06);
  --green: #00ff87;
  --green-dim: rgba(0,255,135,0.12);
  --red: #ff3b5c;
  --red-dim: rgba(255,59,92,0.12);
  --text: #e8eaf0;
  --text-muted: #5a6070;
  --text-dim: #8890a0;
  --radius: 10px;
  --font-mono: 'Share Tech Mono', monospace;
  --font-main: 'Syne', sans-serif;
}

*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-main);
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  opacity: 0.3;
}

/* TOPBAR */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 60px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-main);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 2px;
  color: var(--text);
  flex-shrink: 0;
  white-space: nowrap;
}

.logo-icon { color: var(--green); font-size: 1.3rem; }

.market-ticker {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-dim);
  flex: 1;
  justify-content: center;
  overflow: hidden;
}

.ticker-label { color: var(--text-muted); letter-spacing: 2px; font-size: 0.62rem; }
.ticker-sep { color: var(--border); }
.ticker-item { white-space: nowrap; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--green-dim);
  border: 1px solid rgba(0,255,135,0.2);
  border-radius: 20px;
  padding: 4px 10px;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--green);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--green);
  animation: pulse 1.6s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.3; transform: scale(0.6); }
}

.refresh-btn {
  background: var(--surface3);
  border: 1px solid var(--border);
  color: var(--text-dim);
  width: 32px;
  height: 32px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  transition: all 0.2s;
}

.refresh-btn:hover { color: var(--green); border-color: rgba(0,255,135,0.3); }
.refresh-btn.spinning i { animation: spin 0.6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* MAIN */
.main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px 20px 80px;
  position: relative;
  z-index: 1;
}

/* STAT CARDS */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  position: relative;
  overflow: hidden;
  transition: border-color 0.3s, transform 0.2s;
  animation: fadeUp 0.5s ease forwards;
  opacity: 0;
}

.stat-card:nth-child(1) { animation-delay: 0.05s; }
.stat-card:nth-child(2) { animation-delay: 0.10s; }
.stat-card:nth-child(3) { animation-delay: 0.15s; }
.stat-card:nth-child(4) { animation-delay: 0.20s; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--green), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.stat-card:hover { border-color: rgba(0,255,135,0.2); transform: translateY(-2px); }
.stat-card:hover::before { opacity: 1; }

.stat-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 2px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-family: var(--font-mono);
}

.stat-price {
  font-family: var(--font-mono);
  font-size: 1.3rem;
  color: var(--text);
  margin-bottom: 5px;
  word-break: break-all;
}

.stat-change { font-family: var(--font-mono); font-size: 0.82rem; font-weight: 600; }
.stat-change.up   { color: var(--green); }
.stat-change.down { color: var(--red); }

/* CONTROLS */
.controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  transition: border-color 0.2s;
  flex: 1;
  max-width: 320px;
}

.search-wrap:focus-within { border-color: rgba(0,255,135,0.35); }
.search-wrap i { color: var(--text-muted); font-size: 0.82rem; flex-shrink: 0; }

.search-wrap input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  width: 100%;
}

.search-wrap input::placeholder { color: var(--text-muted); }

.filter-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: none;
}
.filter-tabs::-webkit-scrollbar { display: none; }

.tab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 6px;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  letter-spacing: 1px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab:hover { color: var(--text); border-color: rgba(255,255,255,0.15); }
.tab.active { background: var(--green-dim); border-color: rgba(0,255,135,0.3); color: var(--green); }

/* TABLE WRAPPER — handles scrolling on desktop */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* TABLE — desktop has min-width, mobile removes it */
.token-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 700px;
}

.token-table thead tr {
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.token-table th {
  padding: 13px 16px;
  text-align: left;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  letter-spacing: 2px;
  color: var(--text-muted);
  font-weight: 400;
  white-space: nowrap;
}

.token-table th:first-child { width: 48px; text-align: center; }
.token-table th:last-child  { text-align: right; padding-right: 20px; }

.token-table tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
  animation: fadeUp 0.4s ease forwards;
  opacity: 0;
}

.token-table tbody tr:last-child { border-bottom: none; }
.token-table tbody tr:hover { background: var(--surface2); }

.token-table td {
  padding: 13px 16px;
  font-size: 0.86rem;
  white-space: nowrap;
  vertical-align: middle;
}

.td-rank {
  text-align: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-muted);
}

.token-name-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.token-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.token-name { font-weight: 700; font-size: 0.88rem; color: var(--text); }
.token-symbol { font-family: var(--font-mono); font-size: 0.68rem; color: var(--text-muted); letter-spacing: 1px; margin-top: 1px; }

.td-price { font-family: var(--font-mono); font-size: 0.88rem; color: var(--text); }
.td-change { font-family: var(--font-mono); }

.change-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 0.75rem;
  font-weight: 600;
}

.change-badge.up   { background: var(--green-dim); color: var(--green); }
.change-badge.down { background: var(--red-dim);   color: var(--red); }

.td-mcap, .td-vol, .td-supply {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-dim);
}

.td-supply { text-align: right; padding-right: 20px; }

/* SKELETON */
.skeleton-row td { padding: 15px 16px; }
.skeleton-cell {
  height: 13px;
  background: linear-gradient(90deg, var(--surface2) 25%, var(--surface3) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: 4px;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* LOAD MORE */
.load-more-wrap { display: flex; justify-content: center; margin-top: 24px; }

.load-more-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-dim);
  padding: 11px 32px;
  border-radius: 8px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  letter-spacing: 1.5px;
  cursor: pointer;
  transition: all 0.2s;
}

.load-more-btn:hover { border-color: rgba(0,255,135,0.3); color: var(--green); }
.load-more-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* FOOTER */
.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  position: relative;
  z-index: 1;
}

.footer a { color: var(--green); text-decoration: none; }

/* ===========================
   RESPONSIVE
   =========================== */

/* Tablet */
@media (max-width: 900px) {
  .market-ticker { display: none; }
  .stat-cards { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .main { padding: 20px 16px 60px; }
  .topbar { padding: 0 20px; }
}

/* ===========================
   MOBILE — complete table rebuild
   No min-width, fixed layout, 4 columns only
   =========================== */
@media (max-width: 600px) {
  .topbar { padding: 0 14px; height: 54px; }
  .stat-cards { gap: 10px; margin-bottom: 16px; }
  .stat-card { padding: 14px; }
  .stat-price { font-size: 1rem; }
  .stat-label { font-size: 0.6rem; }
  .stat-change { font-size: 0.72rem; }

  .controls { flex-direction: column; align-items: stretch; }
  .search-wrap { max-width: 100%; }
  .filter-tabs { width: 100%; }

  /* Remove scroll wrapper constraint */
  .table-wrap {
    overflow-x: visible;
    border-radius: 8px;
  }

  /* Kill min-width — let table fit screen */
  .token-table {
    min-width: unset;
    width: 100%;
    table-layout: fixed;
  }

  /* Hide columns 5, 6, 7 */
  .token-table th:nth-child(n+5),
  .token-table td:nth-child(n+5) {
    display: none;
  }

  /* Fixed widths for 4 visible columns */
  .token-table th:nth-child(1),
  .token-table td:nth-child(1) {
    width: 32px;
    padding: 10px 6px;
  }

  .token-table th:nth-child(2),
  .token-table td:nth-child(2) {
    width: 42%;
    padding: 10px 8px;
  }

  .token-table th:nth-child(3),
  .token-table td:nth-child(3) {
    width: 30%;
    padding: 10px 8px;
  }

  .token-table th:nth-child(4),
  .token-table td:nth-child(4) {
    width: 24%;
    padding: 10px 8px;
  }

  .token-icon { width: 26px; height: 26px; }
  .token-name { font-size: 0.8rem; max-width: 90px; overflow: hidden; text-overflow: ellipsis; }
  .token-symbol { font-size: 0.6rem; }
  .token-name-cell { gap: 7px; }
  .td-price { font-size: 0.78rem; }
  .change-badge { font-size: 0.68rem; padding: 2px 5px; }

  .footer { flex-direction: column; text-align: center; }
}