:root {
  --bg: #f1f5f9;
  --bg-elevated: #ffffff;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-secondary: #475569;
  --muted: #64748b;
  --accent: #15803d;
  --accent-soft: #dcfce7;
  --accent-hover: #166534;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.07), 0 2px 4px -2px rgba(15, 23, 42, 0.05);
  --radius: 12px;
  --radius-sm: 8px;
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  background-image: radial-gradient(ellipse 100% 60% at 50% -10%, rgba(22, 163, 74, 0.08), transparent 50%);
  line-height: 1.45;
}

code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: var(--accent-hover);
  background: var(--accent-soft);
  padding: 0.12em 0.35em;
  border-radius: 4px;
}

.topbar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
  padding: 1rem 1.5rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-wrap {
  padding: 0.15rem 0;
  background: transparent;
  border-radius: var(--radius-sm);
}

.logo {
  display: block;
  height: 40px;
  width: auto;
  object-fit: contain;
  vertical-align: middle;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
}

.subtitle {
  margin: 0.2rem 0 0;
  font-size: 12px;
  color: var(--muted);
  max-width: 36rem;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  padding: 0.5rem 0.85rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 5.5rem;
}

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

.stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.layout {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  width: 100%;
  display: grid;
  grid-template-columns: minmax(220px, 270px) 1fr;
  gap: 1rem;
  padding: 1rem 1.25rem calc(5.75rem + env(safe-area-inset-bottom, 0px));
  max-width: 1680px;
  margin: 0 auto;
  align-items: stretch;
}

.layout > * {
  min-height: 0;
}

.site-footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 50;
  padding: 1.35rem 1.5rem calc(1.5rem + env(safe-area-inset-bottom, 0px));
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
  color: var(--text-secondary);
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(15, 23, 42, 0.04);
}

.site-footer p {
  margin: 0;
}

@media (max-width: 1024px) {
  body {
    max-height: none;
    height: auto;
    min-height: 100dvh;
    overflow-y: auto;
  }

  .layout {
    grid-template-columns: 1fr;
    min-height: auto;
    overflow: visible;
  }

  .mun-panel {
    height: auto;
    max-height: min(42vh, 380px);
  }

  .table-wrap {
    height: auto;
    min-height: 280px;
  }

  .table-scroll {
    flex: none;
    max-height: min(50vh, 420px);
  }
}

.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
}

.table-wrap {
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.mun-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  position: sticky;
  top: 0.75rem;
  align-self: stretch;
}

/** Painel só com um município: não estica à altura da tabela. */
.mun-panel.mun-panel--locked {
  height: auto;
  align-self: start;
  max-height: min(calc(100dvh - 8rem), 100%);
}

.mun-panel.mun-panel--locked .mun-list {
  flex: 0 0 auto;
  overflow: visible;
  min-height: 0;
}

.mun-panel-head h2 {
  margin: 0 0 0.65rem;
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.mun-search {
  width: 100%;
  margin-bottom: 0.65rem;
  font-family: var(--font);
  font-size: 13px;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
}

.mun-search:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.mun-list {
  overflow-y: auto;
  flex: 1 1 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-right: 2px;
}

.mun-chart-block {
  flex-shrink: 0;
  margin-top: 0.65rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}

.mun-chart-title {
  margin: 0 0 0.5rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
}

.mun-chart-wrap {
  position: relative;
  height: 200px;
  width: 100%;
}

.mun-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  text-align: left;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 500;
  padding: 0.5rem 0.65rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.mun-btn:hover {
  background: var(--bg);
  border-color: var(--border);
}

.mun-btn.is-active {
  background: var(--accent-soft);
  border-color: rgba(22, 163, 74, 0.35);
  color: var(--accent-hover);
}

.mun-btn .mun-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mun-btn .mun-count {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  flex-shrink: 0;
}

.mun-btn.is-active .mun-count {
  color: var(--accent);
}

.table-controls {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem 1rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.control-search {
  flex: 1 1 200px;
  min-width: 160px;
  max-width: 360px;
  font-family: var(--font);
  font-size: 13px;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

.control-search:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 0.75rem;
}

.field > span:first-child {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.field.row {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
}

.field.row span {
  text-transform: none;
  letter-spacing: normal;
  font-weight: 500;
  color: var(--text);
  font-size: 13px;
}

.field.inline {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0;
}

input[type="search"],
select {
  font-family: var(--font);
  font-size: 13px;
  padding: 0.5rem 0.65rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}

input[type="search"]:focus,
select:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}

input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  accent-color: var(--accent);
}

.toolbar {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.pager-info {
  color: var(--text-secondary);
  font-size: 13px;
}

.btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.btn:hover:not(:disabled) {
  background: var(--bg);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table thead {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--bg-elevated);
  box-shadow: 0 1px 0 var(--border);
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.65rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.data-table tbody tr:hover {
  background: rgba(22, 163, 74, 0.06);
}

.cell-profile {
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
}

.cell-mun {
  font-weight: 600;
  color: var(--accent-hover);
}

.cell-pin {
  font-family: var(--font-mono);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.cell-pin.masked {
  color: var(--muted);
  letter-spacing: 0.15em;
}

.status {
  flex-shrink: 0;
  margin: 0.65rem 0 0;
  font-size: 13px;
  color: var(--muted);
}

.status.error {
  color: #b91c1c;
}
