* {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
  padding: 0;
}

@media (max-width: 600px) {
  html,
  body {
    overflow-x: hidden;
    max-width: 100%;
  }
}

body {
  background: var(--bg-base);
  font-family: var(--fonte-corpo);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  transition:
    background 0.2s,
    color 0.2s;
}
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--bg-surface);
}
::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #484f58;
}
h1,
h2,
h3 {
  margin: 0;
}
button {
  font-family: inherit;
  cursor: pointer;
}
input,
select {
  font-family: inherit;
}

/* ---------- Header ---------- */
.header {
  background: var(--azul);
  border-bottom: 3px solid var(--laranja);
  position: sticky;
  top: 0;
  z-index: 50;
}
.header-inner {
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.header-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.header-logo {
  width: 46px;
  height: 46px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.header-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.header-titles {
  min-width: 0;
}
.header-titles h1 {
  font-family: var(--fonte-display);
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--branco);
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-titles .subtitle {
  font-family: var(--fonte-display);
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--amarelo);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 2px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}
.btn-header {
  white-space: nowrap;
  flex: none;
}
.last-update {
  font-family: var(--fonte-mono);
  font-size: 11px;
  color: rgba(255, 255, 255, 0.55);
  white-space: nowrap;
}
.theme-toggle {
  flex: 0 0 auto;
  width: 30px;
  height: 30px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition:
    border-color var(--trans),
    background var(--trans);
  color: var(--text-secondary);
}
.theme-toggle:hover {
  border-color: var(--amarelo);
  background: var(--amarelo-dim);
}

/* ---------- Filter bar ---------- */
.filter-bar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-soft);
  position: sticky;
  top: 74px;
  z-index: 45;
  transition:
    background 0.2s,
    border-color 0.2s;
}
.filter-bar-inner {
  padding: 0.6rem 20px;
  display: flex;
  align-items: flex-end;
  flex-wrap: wrap;
  gap: 0.75rem;
}
.filter-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.filter-group label {
  font-family: var(--fonte-display);
  font-weight: 600;
  font-size: 0.58rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.filter-group select {
  height: 32px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-primary);
  padding: 0 22px 0 8px;
  font-size: 0.78rem;
  font-family: var(--fonte-corpo);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b98c4' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 14px;
  transition: border-color 0.2s;
}
.filter-group select:focus {
  outline: none;
  border-color: var(--border);
  box-shadow: 0 0 0 3px var(--border-soft);
}
.filter-summary {
  margin-left: auto;
  font-family: var(--fonte-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  align-self: center;
}

/* ---------- Layout ---------- */
.app {
  padding: 22px 20px 70px;
}

/* ---------- Upload / status screen ---------- */
.upload-screen {
  max-width: 640px;
  margin: 40px auto 0;
}
.upload-intro {
  text-align: center;
  margin-bottom: 22px;
}
.upload-intro h2 {
  font-family: var(--fonte-display);
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--text-primary);
}
.upload-intro p {
  font-family: var(--fonte-corpo);
  font-size: 0.92rem;
  color: var(--text-secondary);
  margin-top: 8px;
  line-height: 1.5;
}
.upload-zone {
  position: relative;
  overflow: hidden;
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-elevated);
  padding: 46px 24px;
  text-align: center;
  cursor: default;
}
.upload-zone svg.upload-icon {
  width: 48px;
  height: 48px;
  stroke: var(--text-primary);
}
.upload-zone h2 {
  font-family: var(--fonte-display);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
  margin-top: 16px;
}
.upload-zone p {
  font-size: 0.86rem;
  color: var(--text-secondary);
  margin-top: 6px;
}
.upload-error {
  margin-top: 14px;
  background: rgba(220, 38, 38, 0.12);
  border: 1px solid var(--erro);
  color: var(--erro);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 0.84rem;
  display: none;
  text-align: left;
  white-space: pre-line;
}
.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--amarelo);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
  margin: 0 auto 14px;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Overlay de carregamento (requisições HTTP) ---------- */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(7, 9, 26, 0.55);
  align-items: center;
  justify-content: center;
  z-index: 400;
}
.loading-overlay.show {
  display: flex;
}

[hidden] {
  display: none !important;
}

/* ---------- Responsive ---------- */
@media (max-width: 599px) {
  .header-titles h1 {
    font-size: 1rem;
  }
  .header-titles .subtitle,
  .last-update {
    display: none;
  }
}
@media (max-width: 720px) {
  .header-inner {
    padding: 12px 14px;
  }
  .header-titles h1 {
    font-size: 1rem;
  }
  .filter-bar {
    top: 68px;
  }
  .filter-bar-inner {
    padding: 10px 14px;
  }
  .app {
    padding: 16px 12px 60px;
  }
  .kpi-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  }
  .kpi-card {
    padding: 16px 16px 14px;
  }
  .kpi-label {
    font-size: 0.72rem;
  }
  .kpi-value {
    font-size: 1.4rem;
  }
  .kpi-sub {
    font-size: 0.76rem;
  }
  .charts-grid {
    grid-template-columns: 1fr;
  }
  .chart-card .secao-inner {
    height: 260px;
  }
  .filter-summary {
    width: 100%;
    margin-left: 0;
    order: 5;
  }
  .modal-box {
    width: 100%;
    max-height: 94vh;
  }
}
