:root {
  --bg: #eef2f4;
  --surface: #ffffff;
  --brand: #4ab1e5;
  --brand-dark: #348cbe;
  --orange: #f26522;
  --text: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --input-br: #a8b2bc;
  --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
  --radius: 16px;
  --font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(74, 177, 229, 0.18), transparent),
    radial-gradient(900px 400px at 100% 0%, rgba(242, 101, 34, 0.1), transparent),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* Author `display:` would otherwise override the HTML hidden attribute */
.gate[hidden],
.app[hidden],
[hidden] {
  display: none !important;
}

.gate-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: 24px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.7);
}

.gate-card h1 {
  margin: 12px 0 4px;
  font-size: 1.75rem;
  letter-spacing: -0.03em;
}

.gate-sub {
  margin: 0 0 24px;
  color: var(--muted);
}

.logo {
  display: block;
  object-fit: contain;
}

.logo--gate {
  width: min(220px, 70%);
  height: auto;
  margin-bottom: 8px;
}

.logo--header {
  width: 148px;
  height: auto;
  flex-shrink: 0;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: white;
  font-weight: 700;
  font-size: 1.25rem;
  box-shadow: 0 10px 24px rgba(74, 177, 229, 0.35);
}

.brand-mark--sm {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  font-size: 1.05rem;
}

.gate-error {
  margin: 0 0 12px;
  color: #dc2626;
  font-size: 0.9rem;
}

.app {
  width: min(1280px, calc(100% - 32px));
  margin: 24px auto 48px;
  display: grid;
  gap: 18px;
}

.topbar,
.filters,
.table-wrap,
.stats,
.chart-card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(228, 228, 231, 0.9);
  box-shadow: var(--shadow);
}

.charts {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 16px;
}

.chart-card {
  padding: 16px 18px 18px;
  min-width: 0;
}

.chart-card--wide {
  grid-column: 1 / -1;
}

.chart-head h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.chart-head .muted {
  margin: 4px 0 0;
}

.chart-body {
  position: relative;
  margin-top: 12px;
  min-height: 220px;
}

.chart-body--center {
  max-width: 360px;
  margin-left: auto;
  margin-right: auto;
}

.map-body {
  position: relative;
  display: grid;
  grid-template-columns: 1.4fr 0.8fr;
  gap: 12px;
  align-items: start;
  min-height: 280px;
}

#brazil-map {
  width: 100%;
  height: auto;
  max-height: 360px;
}

#brazil-map path {
  stroke: #fff;
  stroke-width: 1.1;
  transition: opacity 0.15s, stroke-width 0.15s;
  cursor: pointer;
}

#brazil-map path:hover {
  stroke: #0f172a;
  stroke-width: 2;
  opacity: 0.95;
}

.map-tooltip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  background: #0f172a;
  color: #fff;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 0.82rem;
  box-shadow: 0 10px 24px rgba(15, 23, 42, 0.25);
  transform: translate(-50%, -120%);
  white-space: nowrap;
}

.map-top {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.map-top li {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  background: #f8fafc;
  font-size: 0.88rem;
}

.map-top .uf {
  font-weight: 700;
  color: var(--brand-dark);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px 22px;
  flex-wrap: wrap;
}

.topbar-brand {
  display: flex;
  gap: 14px;
  align-items: center;
}

.topbar-brand h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.muted {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0;
  overflow: hidden;
}

.stat {
  padding: 18px 20px;
  border-right: 1px solid var(--line);
}

.stat:last-child {
  border-right: none;
}

.stat-label {
  color: var(--muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stat-value {
  margin-top: 6px;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.stat-value span {
  color: var(--brand-dark);
}

.filters {
  display: grid;
  grid-template-columns: 2fr repeat(4, minmax(120px, 1fr));
  gap: 12px;
  padding: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field.grow {
  min-width: 0;
}

.field > span {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--input-br);
  border-radius: 12px;
  padding: 11px 12px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus,
.field select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(74, 177, 229, 0.2);
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.12s, background 0.12s, border-color 0.12s;
}

.btn:hover {
  transform: translateY(-1px);
  border-color: #cbd5e1;
}

.btn:active {
  transform: translateY(0);
}

.btn-primary {
  background: linear-gradient(180deg, var(--brand), var(--brand-dark));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 8px 18px rgba(74, 177, 229, 0.28);
}

.btn-primary:hover {
  border-color: transparent;
}

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

.btn-block {
  width: 100%;
}

.gate-card .btn-block {
  margin-top: 16px;
}

.table-wrap {
  padding: 8px 8px 16px;
  overflow: hidden;
}

.table-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px 12px;
  color: var(--muted);
  font-size: 0.92rem;
}

.check {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  cursor: pointer;
}

.table-scroll {
  overflow: auto;
  max-height: min(70vh, 820px);
  border-radius: 12px;
  border: 1px solid var(--line);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
  background: #fff;
}

th,
td {
  text-align: left;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 0.92rem;
}

th {
  position: sticky;
  top: 0;
  background: #f8fafc;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  z-index: 1;
}

tbody tr:hover {
  background: #f8fbfe;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 700;
}

.badge-a {
  background: rgba(74, 177, 229, 0.15);
  color: #1d6f9a;
}

.badge-b {
  background: rgba(242, 101, 34, 0.14);
  color: #b44a12;
}

.product {
  font-weight: 600;
}

.city {
  color: var(--muted);
}

.linkish {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--brand-dark);
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

.linkish:hover {
  text-decoration: underline;
}

.empty {
  padding: 40px 16px;
  text-align: center;
  color: var(--muted);
}

.detail {
  border: none;
  border-radius: 20px;
  padding: 0;
  width: min(720px, calc(100% - 24px));
  box-shadow: var(--shadow);
  background: transparent;
}

.detail::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(4px);
}

.detail-card {
  background: var(--surface);
  border-radius: 20px;
  overflow: hidden;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  padding: 20px 22px 12px;
  border-bottom: 1px solid var(--line);
}

.detail-header h2 {
  margin: 0;
  font-size: 1.2rem;
}

.detail-body {
  padding: 18px 22px 24px;
  display: grid;
  gap: 14px;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.detail-item {
  background: #f8fafc;
  border-radius: 12px;
  padding: 12px 14px;
}

.detail-item .label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
}

.detail-item .value {
  font-weight: 600;
  word-break: break-word;
}

.ranking-list {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 6px;
}

@media (max-width: 960px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stat:nth-child(2) {
    border-right: none;
  }

  .stat:nth-child(1),
  .stat:nth-child(2) {
    border-bottom: 1px solid var(--line);
  }

  .charts {
    grid-template-columns: 1fr;
  }

  .map-body {
    grid-template-columns: 1fr;
  }

  .filters {
    grid-template-columns: 1fr 1fr;
  }

  .filters .grow {
    grid-column: 1 / -1;
  }

  .logo--header {
    width: 120px;
  }
}

@media (max-width: 640px) {
  .app {
    width: calc(100% - 16px);
    margin-top: 12px;
  }

  .filters {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: 1fr;
  }

  .stat {
    border-right: none;
    border-bottom: 1px solid var(--line);
  }

  .stat:last-child {
    border-bottom: none;
  }

  .topbar-brand {
    flex-wrap: wrap;
  }
}
