:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --border: #e6e5e1;
  --text: #1a1a1a;
  --text-secondary: #6b6b68;
  --text-muted: #9a9a96;
  --accent: #2f6f4f;
  --accent-bg: #eaf3ee;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

[data-theme="dark"] {
  --bg: #121212;
  --surface: #1c1c1c;
  --border: #2c2c2c;
  --text: #f2f2f0;
  --text-secondary: #a8a8a4;
  --text-muted: #78786f;
  --accent: #6fcf9b;
  --accent-bg: #16261e;
  --danger: #e0736e;
  --danger-bg: #2c1515;
  --shadow: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background 0.15s ease, color 0.15s ease;
}

/* --- Gate (chave de acesso) --- */
.gate {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.gate-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px 28px;
  max-width: 360px;
  width: 100%;
  text-align: center;
}
.gate-card h1 { font-size: 20px; margin: 0 0 8px; }
.gate-card p { font-size: 13.5px; color: var(--text-secondary); margin: 0 0 18px; line-height: 1.5; }
.gate-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  margin-bottom: 12px;
}
.gate-card button {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: none;
  background: var(--text);
  color: var(--surface);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.gate-error { color: var(--danger); font-size: 12.5px; margin-top: 10px; }

/* --- App shell --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 26px; height: 26px;
  background: var(--text);
  color: var(--surface);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px;
}
.brand-name { font-weight: 700; font-size: 15px; letter-spacing: 0.2px; }
.brand-tag { font-size: 11px; color: var(--text-muted); letter-spacing: 1.2px; font-weight: 600; }
.topbar-actions { display: flex; gap: 6px; }
.icon-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--bg); }

.content { max-width: 860px; margin: 0 auto; padding: 24px 20px 60px; }
.page-title { font-size: 26px; font-weight: 700; margin: 4px 0 4px; }
.range-label { color: var(--text-secondary); font-size: 13.5px; margin: 0 0 18px; }

.range-picker { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; align-items: center; }
.range-btn {
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.range-btn.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.refresh-btn {
  margin-left: auto;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.refresh-btn:hover { background: var(--bg); }

.error-banner {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 13.5px;
  margin-bottom: 18px;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: var(--shadow);
}
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; font-weight: 600; }
.stat-value { font-size: 26px; font-weight: 700; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}
.card h2 { font-size: 15px; font-weight: 700; margin: 0 0 4px; }
.card-sub { font-size: 12.5px; color: var(--text-muted); margin: 0 0 16px; }

.card-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.gran-picker { display: flex; gap: 4px; background: var(--bg); border-radius: 999px; padding: 3px; flex-shrink: 0; }
.gran-btn {
  padding: 5px 12px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}
.gran-btn.active { background: var(--surface); color: var(--text); }

.chart-wrap { position: relative; height: 240px; }
.chart-wrap-sm { height: 180px; }

.mini-stat-row { display: flex; gap: 12px; flex-wrap: wrap; }
.mini-stat {
  flex: 1;
  min-width: 120px;
  background: var(--bg);
  border-radius: 12px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mini-stat-value { font-size: 22px; font-weight: 700; }
.mini-stat-label { font-size: 12px; color: var(--text-muted); }

.mini-divider { height: 1px; background: var(--border); margin: 16px 0; }

.chip-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.chip-list li {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
}

.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  padding: 0 8px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table th.num, .data-table td.num { text-align: right; }
.data-table td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.rank-cell { color: var(--text-muted); width: 24px; }

.empty-state { color: var(--text-muted); font-size: 13px; text-align: center; padding: 16px 0 4px; }

.footnote { color: var(--text-muted); font-size: 11.5px; text-align: center; margin-top: 28px; }

@media (max-width: 620px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .content { padding: 18px 14px 48px; }
}
