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

:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-tertiary: #21262d;
  --text-primary: #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary: #6e7681;
  --accent: #58a6ff;
  --up: #16c784;
  --down: #ea3943;
  --border: #30363d;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
}

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

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem 1rem; }

/* === Header === */
.header {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 1rem;
  background: rgba(13,17,23,0.85); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
}

.logo {
  font-size: 1.25rem; font-weight: 700;
  color: var(--text-primary) !important;
  text-decoration: none !important;
  white-space: nowrap;
}

.search-wrap { position: relative; flex: 1; max-width: 360px; margin-left: auto; }

#search-input {
  width: 100%; padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-primary);
  font-size: 0.875rem; outline: none;
}
#search-input:focus { border-color: var(--accent); }

.search-results {
  position: absolute; top: 100%; left: 0; right: 0; margin-top: 4px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 8px; max-height: 320px; overflow-y: auto;
}
.search-results.hidden { display: none; }

.search-item {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.6rem 0.75rem; cursor: pointer;
  color: var(--text-primary); text-decoration: none;
}
.search-item:hover { background: var(--bg-tertiary); text-decoration: none; }
.search-item img { width: 24px; height: 24px; border-radius: 50%; }
.search-item .symbol { color: var(--text-secondary); font-size: 0.8rem; margin-left: 0.25rem; }

/* === Section title === */
.section-title { font-size: 1.25rem; font-weight: 600; margin-bottom: 1rem; }

/* === Coin Table (Desktop) === */
.table-wrap { overflow-x: auto; }

.coin-table {
  width: 100%; border-collapse: collapse;
  display: table;
}
.coin-table th, .coin-table td {
  padding: 0.75rem 0.6rem;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.coin-table th {
  font-size: 0.75rem; text-transform: uppercase;
  color: var(--text-secondary); font-weight: 600;
  text-align: left;
}
.text-right { text-align: right !important; }

.coin-table tbody tr { cursor: pointer; }
.coin-table tbody tr:hover { background: var(--bg-tertiary); }

.coin-name-cell {
  display: flex; align-items: center; gap: 0.5rem;
}
.coin-name-cell img { width: 28px; height: 28px; border-radius: 50%; }
.coin-symbol { color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; }

.sparkline-canvas { width: 100px; height: 36px; }

/* === Coin Cards (Mobile) === */
.coin-cards { display: none; flex-direction: column; gap: 0.75rem; }

.coin-card {
  display: flex; align-items: center; gap: 0.75rem;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem; cursor: pointer;
}
.coin-card:hover { border-color: var(--accent); }
.coin-card img { width: 36px; height: 36px; border-radius: 50%; }
.coin-card-info { flex: 1; }
.coin-card-name { font-weight: 600; }
.coin-card-symbol { color: var(--text-secondary); font-size: 0.8rem; text-transform: uppercase; }
.coin-card-right { text-align: right; }
.coin-card-price { font-weight: 600; }

/* === Trend badge === */
.badge { font-size: 0.8rem; font-weight: 600; }
.badge.up { color: var(--up); }
.badge.down { color: var(--down); }

/* === Detail page === */
.back-link {
  display: inline-block; margin-bottom: 1rem;
  color: var(--text-secondary); font-size: 0.9rem;
}

.coin-header {
  display: flex; align-items: center; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1.5rem;
}
.coin-header.hidden { display: none; }
.coin-header img { width: 48px; height: 48px; border-radius: 50%; }
.coin-header h1 { font-size: 1.5rem; font-weight: 700; }
.coin-header .symbol-tag {
  background: var(--bg-tertiary); color: var(--text-secondary);
  padding: 0.15rem 0.5rem; border-radius: 6px;
  font-size: 0.8rem; text-transform: uppercase;
}
.coin-header .rank-tag {
  background: var(--accent); color: #000;
  padding: 0.15rem 0.5rem; border-radius: 6px;
  font-size: 0.75rem; font-weight: 700;
}
.coin-header .price { font-size: 1.75rem; font-weight: 700; margin-left: auto; }

/* === Chart === */
.chart-section.hidden { display: none; }
.chart-toggle { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.toggle-btn {
  padding: 0.4rem 1rem; border: 1px solid var(--border);
  border-radius: 8px; background: transparent;
  color: var(--text-secondary); cursor: pointer; font-size: 0.85rem;
}
.toggle-btn.active { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.chart-container {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem; height: 320px; position: relative;
}

/* === Stats grid === */
.stats-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.75rem; margin-top: 1.5rem;
}
.stats-grid.hidden { display: none; }
.stat-card {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 12px; padding: 1rem;
}
.stat-label { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; margin-bottom: 0.25rem; }
.stat-value { font-size: 1rem; font-weight: 600; }

/* === News === */
.news-grid { display: flex; flex-direction: column; gap: 0; }

.news-item {
  display: block; padding: 0.85rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary); text-decoration: none;
}
.news-item:first-child { padding-top: 0; }
.news-item:last-child { border-bottom: none; }
.news-item:hover .news-item-title { color: var(--accent); }

.news-item-title {
  font-weight: 600; font-size: 0.95rem; line-height: 1.4;
  margin-bottom: 0.25rem; transition: color 0.15s;
}
.news-item-body {
  font-size: 0.8rem; color: var(--text-secondary); line-height: 1.5;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.news-item-meta {
  font-size: 0.7rem; color: var(--text-tertiary); margin-top: 0.3rem;
}
.news-empty {
  text-align: center; padding: 2rem; color: var(--text-secondary);
}

/* === Loading & Error === */
.loading { text-align: center; padding: 2rem; color: var(--text-secondary); }
.loading.hidden { display: none; }
.error { text-align: center; padding: 2rem; color: var(--down); }
.error.hidden { display: none; }

/* === Responsive === */
@media (max-width: 768px) {
  .table-wrap { display: none; }
  .coin-cards { display: flex; }
  .coin-header .price { margin-left: 0; width: 100%; margin-top: 0.5rem; }
  .news-grid { gap: 0; }
  .chart-container { height: 250px; }
}
