:root {
  --bg0: #eef2f7;
  --bg1: #f7f9fc;
  --surface: #ffffff;
  --ink: #152033;
  --muted: #5b6b81;
  --line: #dfe5ee;
  --line-soft: #eef2f7;
  --brand: #1c4f9c;
  --brand-soft: #e8f0fb;
  --brand-deep: #143a75;
  --ok: #0b7a4b;
  --ok-bg: #e8f8f0;
  --miss: #b42318;
  --miss-bg: #fef3f2;
  --font: "IBM Plex Sans", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(21, 32, 51, 0.04), 0 8px 24px rgba(21, 32, 51, 0.04);
  --wrap: min(1280px, calc(100% - 2.5rem));
}

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

html {
  scroll-behavior: smooth;
  overflow-x: hidden;
  max-width: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 480px at 8% -10%, rgba(28, 79, 156, 0.12), transparent 55%),
    radial-gradient(900px 420px at 92% 0%, rgba(11, 122, 75, 0.07), transparent 50%),
    linear-gradient(180deg, var(--bg1), var(--bg0));
  line-height: 1.45;
  overflow-x: hidden;
  max-width: 100%;
}

.wrap {
  width: var(--wrap);
  max-width: 100%;
  margin-inline: auto;
  min-width: 0;
}

.app-header {
  background: rgba(255, 255, 255, 0.86);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(223, 229, 238, 0.9);
  position: sticky;
  top: 0;
  z-index: 20;
  max-width: 100%;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 58px;
  padding: 0.6rem 0;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 0.7rem;
}

.brand strong {
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.brand span {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.status {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f79009;
  box-shadow: 0 0 0 3px rgba(247, 144, 9, 0.18);
}

.status.is-on .status-dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(11, 122, 75, 0.16);
}

.status.is-off .status-dot {
  background: var(--miss);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.14);
}

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  padding: 0.48rem 0.9rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.btn:hover {
  background: #f7f9fc;
  border-color: #cfd7e4;
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.42;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
}

.btn-primary:hover {
  background: var(--brand-deep);
  border-color: var(--brand-deep);
}

main.wrap {
  padding: 1.35rem 0 2.2rem;
  display: grid;
  gap: 1.1rem;
  max-width: 100%;
  min-width: 0;
}

.summary {
  display: grid;
  gap: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem 1.3rem;
  animation: rise 0.45s ease both;
}

.summary-main h1 {
  margin: 0 0 0.25rem;
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.summary-main p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.65rem;
}

.kpis article {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.7rem 0.8rem;
  background: linear-gradient(180deg, #fff, #f8fafc);
  min-width: 0;
}

.kpis .ok {
  background: linear-gradient(180deg, #f4fcf7, var(--ok-bg));
  border-color: #b7ebcf;
}

.kpis .miss {
  background: linear-gradient(180deg, #fff8f7, var(--miss-bg));
  border-color: #fecdca;
}

.kpi-label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.kpis strong {
  display: block;
  font-size: 1.22rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.kpis .ok strong {
  color: var(--ok);
}

.kpis .miss strong {
  color: var(--miss);
}

.bar-track {
  margin-top: 0.55rem;
  height: 6px;
  border-radius: 999px;
  background: #e4e7ec;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand), #3d78c7);
  transition: width 0.85s cubic-bezier(0.22, 1, 0.36, 1);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0;
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  animation: rise 0.55s ease 0.05s both;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1.05rem 1.2rem 0.95rem;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #fcfdff, #f7f9fc);
}

.panel-head h2 {
  margin: 0 0 0.2rem;
  font-size: 1.12rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.tabs {
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.22rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #eef2f7;
}

.tab {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.82rem;
  font-weight: 650;
  padding: 0.42rem 0.95rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  background: #fff;
  color: var(--brand);
  box-shadow: 0 1px 2px rgba(21, 32, 51, 0.08);
}

.filters {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(5.5rem, 0.45fr) minmax(6.5rem, 0.55fr) minmax(0, 1.5fr) minmax(11rem, 0.85fr) minmax(6.5rem, 0.5fr) auto;
  gap: 0.7rem;
  padding: 0.95rem 1.2rem;
  background: #fbfcfe;
  border-bottom: 1px solid var(--line-soft);
  align-items: end;
}

.score-filter {
  display: grid;
  grid-template-columns: 1fr 4.2rem;
  gap: 0.35rem;
  min-width: 0;
}

.score-filter input:disabled {
  opacity: 0.45;
  background: #f3f5f8;
}

.field-action .btn {
  white-space: nowrap;
  height: 2.55rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  min-width: 0;
}

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

.field input,
.field select {
  width: 100%;
  font: inherit;
  font-size: 0.9rem;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0.58rem 0.7rem;
  background: #fff;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:hover,
.field select:hover {
  border-color: #c9d3e2;
}

.field input:focus,
.field select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(28, 79, 156, 0.15);
}

.table-wrap {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  max-height: min(62vh, 620px);
  overflow: auto;
  overscroll-behavior: contain;
  background: #fff;
}

.table-wrap::-webkit-scrollbar {
  height: 10px;
  width: 10px;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: #b7c2d2;
  border-radius: 999px;
  border: 2px solid #fff;
}

.table-wrap::-webkit-scrollbar-track {
  background: #f4f6f9;
}

table {
  width: max-content;
  max-width: none;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.8rem;
  table-layout: fixed;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #f3f6fa;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: #3f5168;
  padding: 0;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  line-height: 1.2;
  vertical-align: middle;
  box-shadow: inset 0 -1px 0 var(--line);
}

th.th-sort {
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

th.th-sort .th-inner {
  display: flex;
  align-items: center;
  gap: 0.28rem;
  min-height: 40px;
  padding: 0.55rem 0.65rem;
  box-sizing: border-box;
}

th.th-sort:hover,
th.th-sort:focus-visible {
  color: var(--brand);
  background: #eaf0f8;
  outline: none;
}

th.th-sort .th-label {
  display: inline-block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

th.th-sort .th-arrow {
  flex: 0 0 auto;
  font-size: 0.7rem;
  opacity: 0.45;
  line-height: 1;
}

th.th-sort.is-sorted {
  color: var(--brand);
  background: #e8f0fb;
}

th.th-sort.is-sorted .th-arrow {
  opacity: 1;
}

tbody td {
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: #243247;
  height: 40px;
}

tbody tr {
  transition: background 0.15s ease;
}

tbody tr:nth-child(even) td {
  background: #fafbfd;
}

tbody tr:hover td {
  background: #eef4fb;
}

tbody td strong {
  font-weight: 650;
  color: var(--ink);
}

tbody td.mono {
  font-family: var(--mono);
  font-size: 0.75rem;
  letter-spacing: -0.01em;
  color: #3a4a61;
}

th.align-right .th-inner,
td.align-right {
  justify-content: flex-end;
  text-align: right;
}

th.align-center .th-inner,
td.align-center {
  justify-content: center;
  text-align: center;
}

/* larguras via colgroup + classes */
th.col-id,
td.col-id,
th.col-xs,
td.col-xs,
th.col-sm,
td.col-sm,
th.col-md,
td.col-md,
th.col-lg,
td.col-lg,
th.col-xl,
td.col-xl,
th.col-cnpj,
td.col-cnpj,
th.col-inep,
td.col-inep {
  box-sizing: border-box;
}

.tag {
  display: inline-block;
  padding: 0.16rem 0.45rem;
  border-radius: 6px;
  font-size: 0.74rem;
  font-weight: 650;
  font-family: var(--mono);
}

.tag-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.tag-miss {
  background: var(--miss-bg);
  color: var(--miss);
  font-family: var(--font);
}

.muted {
  margin-top: 0.15rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.2rem 1rem;
  border-top: 1px solid var(--line-soft);
  background: #fbfcfe;
  flex-wrap: wrap;
}

.pager p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  font-variant-numeric: tabular-nums;
}

.pager-btns {
  display: flex;
  gap: 0.45rem;
}

.foot {
  padding: 0 0 1.6rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.foot p {
  margin: 0;
}

.foot code {
  font-family: var(--mono);
  font-size: 0.75rem;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--line);
  padding: 0.12rem 0.32rem;
  border-radius: 5px;
}

.empty {
  padding: 2.4rem 1rem;
  text-align: center;
  color: var(--muted);
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 40, 0.48);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.modal-dialog {
  position: relative;
  z-index: 1;
  width: min(860px, 100%);
  max-height: min(88vh, 820px);
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 24px 64px rgba(16, 24, 40, 0.22);
  animation: rise 0.28s ease both;
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.2rem 0.85rem;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #fcfdff, #f7f9fc);
  position: sticky;
  top: 0;
  z-index: 2;
}

.modal-kicker {
  margin: 0 0 0.15rem;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--brand);
}

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

.modal-close {
  flex: 0 0 auto;
}

.modal-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.85rem 1.2rem 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.28rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #f7f9fc;
  font-size: 0.78rem;
  color: #334155;
}

.chip strong {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--ink);
}

.chip.ok {
  background: var(--ok-bg);
  border-color: #b7ebcf;
  color: var(--ok);
}

.chip.miss {
  background: var(--miss-bg);
  border-color: #fecdca;
  color: var(--miss);
}

.modal-body {
  padding: 0.85rem 1.2rem 1.25rem;
  display: grid;
  gap: 0.65rem;
}

.compare-row {
  display: grid;
  grid-template-columns: 7.5rem 1fr 1fr;
  gap: 0.55rem;
  align-items: stretch;
  padding: 0.7rem;
  border: 1px solid var(--line-soft);
  border-radius: 10px;
  background: #fbfcfe;
}

.compare-field {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
}

.compare-sim {
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0;
  text-transform: none;
  color: var(--brand);
}

.compare-side {
  min-width: 0;
  padding: 0.55rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
}

.compare-side .side-label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.68rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.compare-side .side-value {
  font-size: 0.9rem;
  line-height: 1.35;
  color: var(--ink);
  word-break: break-word;
  white-space: pre-wrap;
}

.compare-side.is-match {
  border-color: #b7ebcf;
  background: #f4fcf7;
}

.compare-side.is-diff {
  border-color: #f5c4bf;
  background: #fff8f7;
}

.compare-side.is-empty {
  color: var(--muted);
}

tbody tr.is-clickable {
  cursor: pointer;
}

tbody tr.is-clickable:focus-visible td {
  outline: 2px solid rgba(28, 79, 156, 0.35);
  outline-offset: -2px;
}

html.modal-open,
body.modal-open {
  overflow: hidden !important;
  overscroll-behavior: none;
  touch-action: none;
}

body.modal-open {
  position: fixed;
  left: 0;
  right: 0;
  width: 100%;
}

body.modal-open .table-wrap {
  overflow: hidden !important;
}

@media (max-width: 720px) {
  .compare-row {
    grid-template-columns: 1fr;
  }

  .compare-field {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
  }
}

@media (max-width: 900px) {
  .kpis {
    grid-template-columns: 1fr 1fr;
  }

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

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

@media (max-width: 560px) {
  .brand {
    flex-direction: column;
    gap: 0.1rem;
  }

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

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

  .panel-head {
    align-items: flex-start;
  }
}
