/* ═══════════════════════════════════════════════════════════
   base.css — Reset, variáveis base, layout principal
   ═══════════════════════════════════════════════════════════ */

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

img,
canvas {
  display: block;
  max-width: 100%;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  font: inherit;
}

input,
select {
  font: inherit;
}

table {
  border-collapse: collapse;
  width: 100%;
}

/* ── Tokens base ──────────────────────────────────────────── */
:root {
  --bg: #0a0a0f;
  --surface: #111118;
  --surface-2: #16161f;
  --border: #1e1e2e;
  --accent: #4493f8;
  --accent-muted: #4493f815;
  --up: #22c55e;
  --down: #ef4444;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --text-dim: #334155;

  --font-sans: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --font-display: var(--font-sans);

  --gap: 16px;
  --radius: 8px;
  --radius-lg: 12px;

  --theme-transition: background-color 0.3s ease, color 0.3s ease,
    border-color 0.3s ease, box-shadow 0.3s ease;
}

/* ── Base ─────────────────────────────────────────────────── */
html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  transition: var(--theme-transition);
  -webkit-font-smoothing: antialiased;
  /* Evita scroll horizontal global */
  overflow-x: hidden;
}

/* ── Navbar ───────────────────────────────────────────────── */
.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 56px;
  background-color: var(--bg);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  transition: var(--theme-transition);
}

.navbar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
}

.navbar__icon {
  font-size: 20px;
  color: var(--accent);
  line-height: 1;
}

.navbar__name {
  font-size: 17px;
  font-weight: 700;
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  color: var(--text);
}

.navbar__right {
  display: flex;
  align-items: center;
  gap: 20px;
}

/* ── Theme Dropdown ───────────────────────────────────────── */
.theme-dropdown {
  position: relative;
}

.theme-dropdown__btn {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  white-space: nowrap;
}

.theme-dropdown__btn:hover {
  border-color: var(--accent);
  background: var(--surface-2);
}

.theme-dropdown__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.3s;
}

.theme-dropdown__label {
  font-weight: 600;
}

.theme-dropdown__arrow {
  font-size: 11px;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.theme-dropdown.open .theme-dropdown__arrow {
  transform: rotate(180deg);
}

.theme-dropdown__menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  min-width: 200px;
  z-index: 200;
  display: none;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  animation: fadeIn 0.15s ease;
}

.theme-dropdown.open .theme-dropdown__menu {
  display: block;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 12px;
  border-radius: 7px;
  cursor: pointer;
  background: none;
  border: none;
  text-align: left;
  transition: background 0.15s;
}

.theme-option:hover {
  background: var(--surface-2);
}

.theme-option.active {
  background: var(--accent-muted);
}

.theme-option__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.theme-option__name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

.theme-option__desc {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Connection Status ────────────────────────────────────── */
.connection-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.connection-status__dot {
  width: 7px;
  height: 7px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background 0.3s;
}

.connection-status--connected .connection-status__dot {
  background: var(--up);
  box-shadow: 0 0 6px var(--up);
}

/* ── Main layout ──────────────────────────────────────────── */
.main {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px var(--gap);
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Market Stats (topo) ──────────────────────────────────── */
.market-stats {
  display: flex;
  gap: var(--gap);
  flex-wrap: wrap;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  flex: 1;
  min-width: 150px;
  transition: var(--theme-transition);
}

.stat-item__label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 500;
}

.stat-item__value {
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-mono);
  color: var(--text);
}

/* skeleton no stat enquanto carrega */
.stat-item__value.is-loading {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.5s infinite;
  border-radius: 4px;
  color: transparent;
  min-width: 80px;
  height: 1.1em;
  display: inline-block;
}

/* ── Coins Section ────────────────────────────────────────── */
.coins-section {
  /* NÃO usar overflow: hidden aqui — cortava os cards */
  position: relative;
}

/* Seta/fade indicando que há mais cards à direita */
.coins-section::after {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 60px;
  height: calc(100% - 8px);
  /* desconta o padding-bottom do scroll */
  background: linear-gradient(to right, transparent, var(--bg));
  pointer-events: none;
  z-index: 1;
  transition: opacity 0.3s;
}

.coins-section.at-end::after {
  opacity: 0;
}

.coins-grid {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
  /* Scrollbar fina e visível */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
  cursor: grab;
}

.coins-grid::-webkit-scrollbar {
  height: 4px;
}

.coins-grid::-webkit-scrollbar-track {
  background: transparent;
}

.coins-grid::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.coins-grid::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

.coins-grid.is-dragging {
  cursor: grabbing;
  user-select: none;
}

/* ── Coin Card ────────────────────────────────────────────── */
.coin-card {
  flex: 0 0 175px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, background 0.2s;
  position: relative;
  overflow: hidden;
}

.coin-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.coin-card.active {
  border-color: var(--accent);
  background: var(--accent-muted);
}

.coin-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.coin-card__symbol {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  letter-spacing: 0.05em;
}

.coin-card__change {
  font-size: 11px;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 2px 6px;
  border-radius: 4px;
}

.coin-card__change--up {
  color: var(--up);
  background: #22c55e18;
}

.coin-card__change--down {
  color: var(--down);
  background: #ef444418;
}

.coin-card__price {
  font-size: 16px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  letter-spacing: -0.02em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.coin-card__price.flash-up {
  animation: flashUp 0.4s ease;
}

.coin-card__price.flash-down {
  animation: flashDown 0.4s ease;
}

.coin-card__sparkline {
  margin-top: 10px;
  height: 36px;
}

/* ── Skeleton card ────────────────────────────────────────── */
.coin-card--skeleton {
  pointer-events: none;
}

.coin-card--skeleton .coin-card__symbol,
.coin-card--skeleton .coin-card__change,
.coin-card--skeleton .coin-card__price {
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.5s infinite;
  border-radius: 4px;
  color: transparent;
}

.coin-card--skeleton .coin-card__symbol {
  width: 36px;
  height: 12px;
}

.coin-card--skeleton .coin-card__change {
  width: 44px;
  height: 12px;
}

.coin-card--skeleton .coin-card__price {
  width: 100px;
  height: 18px;
  margin-top: 4px;
}

.coin-card--skeleton .coin-card__sparkline {
  background: var(--surface-2);
  border-radius: 4px;
}

/* ── Dashboard Grid ───────────────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: var(--gap);
  min-width: 0;
  align-items: stretch;
  /* ambas colunas mesma altura */
}

.panel--chart {
  display: flex;
  flex-direction: column;
}

.panel--chart .panel__header {
  flex-shrink: 0;
}

.panel--chart .panel__body--chart {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 16px 16px;
}

.chart-candlestick {
  flex: 1;
  position: relative;
  min-height: 260px;
}

.chart-volume {
  height: 80px;
  position: relative;
  flex-shrink: 0;
}

.panel-sidebar {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

/* ── Panel ────────────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: var(--theme-transition);
  min-width: 0;
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
}

.panel__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  font-family: var(--font-display);
  white-space: nowrap;
}

.panel__subtitle {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--accent);
  letter-spacing: -0.03em;
}

.panel__title-group {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.panel__body {
  padding: 16px 20px;
}

/* ── Chart Controls ───────────────────────────────────────── */
.chart-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.chart-coin-select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 5px 10px;
  font-size: 13px;
  font-weight: 600;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}

.chart-coin-select:focus {
  border-color: var(--accent);
}

.timeframe-btns {
  display: flex;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 3px;
}

.tf-btn {
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}

.tf-btn.active {
  background: var(--accent-muted);
  color: var(--accent);
}

.tf-btn:hover:not(.active) {
  color: var(--text);
}

/* ── Donut ────────────────────────────────────────────────── */
.panel__body--donut {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.donut-center {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
}

.donut-center__label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.donut-center__value {
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
}

/* ── Fear & Greed ─────────────────────────────────────────── */
.panel__body--fear {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 20px;
}

.fear-gauge__bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.fear-gauge__fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(to right, var(--down), #f59e0b, var(--up));
  transition: width 0.8s ease;
  width: 0%;
}

.fear-gauge__labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 4px;
}

.fear-value {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.fear-value__number {
  font-size: 36px;
  font-weight: 700;
  font-family: var(--font-mono);
  color: var(--text);
  line-height: 1;
}

.fear-value__label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

/* ── Table ────────────────────────────────────────────────── */
.table-search {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 6px 12px;
  font-size: 13px;
  width: 200px;
  max-width: 100%;
  outline: none;
  transition: border-color 0.2s;
}

.table-search:focus {
  border-color: var(--accent);
}

.table-search::placeholder {
  color: var(--text-dim);
}

.panel__body--table {
  padding: 0;
  overflow-x: auto;
  /* Scrollbar visível mas fina na tabela */
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.market-table th {
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: right;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
  transition: color 0.15s;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.market-table th:first-child,
.market-table th:nth-child(2) {
  text-align: left;
}

.market-table th:hover {
  color: var(--text);
}

/* indicador de ordenação */
.market-table th.sort-asc::after {
  content: ' ↑';
  color: var(--accent);
}

.market-table th.sort-desc::after {
  content: ' ↓';
  color: var(--accent);
}

.market-table td {
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text);
  text-align: right;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  transition: color 0.2s;
}

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

.market-table tbody tr {
  transition: background 0.15s;
  cursor: pointer;
}

.market-table tbody tr:hover {
  background: var(--surface-2);
}

.market-table tbody tr:last-child td {
  border-bottom: none;
}

.table-coin {
  display: flex;
  align-items: center;
  gap: 10px;
}

.table-coin__img {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
}

.table-coin__name {
  font-weight: 600;
  font-size: 13px;
}

.table-coin__symbol {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
}

.td-price {
  font-family: var(--font-mono);
  font-weight: 600;
}

.td-change {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
}

.td-change--up {
  color: var(--up);
}

.td-change--down {
  color: var(--down);
}

.td-volume,
.td-marketcap {
  font-family: var(--font-mono);
  color: var(--text-muted);
}

/* Skeleton linhas da tabela */
.table-skeleton td {
  pointer-events: none;
}

.table-skeleton .skel {
  display: inline-block;
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: skeleton 1.5s infinite;
}

/* ── Loading overlay ──────────────────────────────────────── */
.loading-msg {
  text-align: center;
  padding: 32px;
  color: var(--text-muted);
  font-size: 13px;
}

/* ── Responsivo ───────────────────────────────────────────── */
@media (max-width: 1100px) {
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .panel-sidebar {
    flex-direction: row;
  }

  .panel--donut,
  .panel--fear {
    flex: 1;
    min-width: 0;
  }
}

@media (max-width: 768px) {
  .navbar {
    padding: 0 16px;
  }

  .navbar__name {
    font-size: 15px;
  }

  .main {
    padding: 12px;
    gap: 12px;
  }

  .market-stats {
    gap: 8px;
  }

  .stat-item {
    min-width: 130px;
    padding: 10px 14px;
  }

  .panel__header {
    padding: 12px 16px;
  }

  .panel__body {
    padding: 12px 16px;
  }

  .chart-controls {
    gap: 6px;
  }
}

@media (max-width: 640px) {
  .panel-sidebar {
    flex-direction: column;
  }

  .chart-controls {
    flex-direction: column;
    align-items: flex-start;
  }

  .table-search {
    width: 100%;
  }

  .panel__header {
    flex-direction: column;
    align-items: flex-start;
  }
}

/* ── Scrollbar global fina ────────────────────────────────── */
::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ── Utilitários ──────────────────────────────────────────── */
@keyframes skeleton {
  0% {
    background-position: 200% 0;
  }

  100% {
    background-position: -200% 0;
  }
}

/* ── Accordion mobile — tabela expansível ─────────────────────────────────────
   No mobile (≤768px) a tabela mostra só rank + moeda + chevron.
   Ao clicar, um <tr class="expand-row"> é inserido abaixo com os detalhes.
   O desktop não é afetado — estes estilos só existem dentro do @media. */
@media (max-width: 768px) {

  /* Esconde as colunas da tabela que não existem no modo mobile */
  .market-table thead {
    display: none;
  }

  /* Linha mobile compacta */
  .mobile-row {
    cursor: pointer;
    transition: background 0.15s;
  }

  .mobile-row:hover,
  .mobile-row.row-expanded {
    background: var(--surface-2);
  }

  /* Célula do chevron — alinhada à direita */
  .td-chevron-cell {
    text-align: right;
    width: 32px;
    padding-right: 16px !important;
  }

  .td-chevron {
    font-size: 12px;
    color: var(--text-dim);
    transition: color 0.15s;
    user-select: none;
  }

  .mobile-row.row-expanded .td-chevron {
    color: var(--accent);
  }

  /* Linha de detalhes expandida — aparece abaixo da linha clicada */
  .expand-row {
    background: var(--bg);
  }

  .expand-row td {
    padding: 0 !important;
    border-bottom: 1px solid var(--border);
  }

  /* Grid de detalhes em duas colunas: label à esquerda, valor à direita */
  .expand-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1px;
    background: var(--border);
    border-top: 1px solid var(--border);
    animation: expandIn 0.18s ease;
  }

  .expand-item {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 12px 16px;
    background: var(--surface);
  }

  .expand-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
  }

  .expand-value {
    font-size: 14px;
    font-weight: 600;
    font-family: var(--font-mono);
    color: var(--text);
  }

  /* Animação suave de abertura */
  @keyframes expandIn {
    from {
      opacity: 0;
      transform: translateY(-4px);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  /* Navbar: esconde label do status de conexão — só o dot fica visível */
  .connection-status__label {
    display: none;
  }

  /* Tabela mobile: remove overflow-x — o accordion elimina a necessidade de scroll horizontal */
  .panel__body--table {
    overflow-x: hidden;
  }
}