:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #172033;
  --muted: #6b7688;
  --line: #e5e9f0;
  --line-soft: #eef1f6;
  --brand: #0b4f9c;
  --brand-dark: #083c78;
  --brand-soft: #eaf1fb;
  --ok: #1c8a4d;
  --ok-soft: #e4f4ea;
  --warn: #b4690e;
  --warn-soft: #fbf0dd;
  --danger: #c0392b;
  --danger-soft: #fbe6e3;
  --radius: 12px;
  --radius-sm: 9px;
  /* Sombra discreta: a separação vem das bordas, não de camadas empilhadas */
  --shadow: 0 1px 2px rgba(16, 30, 54, .04);
  --max: 1040px;
}

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

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Topbar — chapada, sem gradiente nem sombra */
.topbar {
  background: var(--brand);
  color: #fff;
}
.topbar-inner {
  max-width: var(--max);
  margin: 0 auto;
  padding: 16px 24px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .14);
  border-radius: var(--radius-sm);
  font-weight: 700; font-size: 14px; letter-spacing: .5px;
}
.brand-text strong { display: block; font-size: 16px; font-weight: 600; letter-spacing: -.1px; }
.brand-text small { color: rgba(255, 255, 255, .7); font-size: 12px; }
.env-badge {
  font-size: 12px;
  background: rgba(255, 255, 255, .15);
  border: 1px solid rgba(255, 255, 255, .28);
  padding: 5px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
.user-nome { font-size: 13px; font-weight: 600; color: #fff; opacity: .95; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Login */
.login-overlay { align-items: center; }
.login-modal { max-width: 400px; }
.login-brand { display: flex; align-items: center; gap: 12px; padding: 20px 20px 0; }
.login-brand .brand-mark { background: var(--brand); color: #fff; }
.login-brand strong { display: block; }
.login-brand small { color: var(--muted); }

/* Logs */
.logs-box { display: flex; flex-direction: column; gap: 6px; max-height: 420px; overflow-y: auto; }
.log-item {
  display: grid; grid-template-columns: 150px 150px 1fr; gap: 10px; align-items: baseline;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px;
}
.log-item .log-ts { color: var(--muted); font-variant-numeric: tabular-nums; }
.log-item .log-user { font-weight: 600; }
.log-item .log-op { color: var(--brand-dark); }
.log-item .log-det { color: var(--muted); }
@media (max-width: 640px) { .log-item { grid-template-columns: 1fr; gap: 2px; } }
#logUserBox .log-item { grid-template-columns: 150px 1fr; }
@media (max-width: 640px) { #logUserBox .log-item { grid-template-columns: 1fr; } }
.log-filtros { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.log-filtros .cfg-label { flex: 0 0 auto; }
.log-filtros button { height: 38px; }

/* Usuários (tabela) */
.acoes-topo { display: flex; gap: 8px; }
.tabela-wrap { overflow-x: auto; }
.tabela { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabela th, .tabela td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tabela thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.tabela tbody tr:hover { background: #f7f9fc; }
.tabela td.col-acoes, .tabela th.col-acoes { text-align: right; white-space: nowrap; }
.tabela .cpf-cel { font-variant-numeric: tabular-nums; font-weight: 600; }
.btn-mini {
  font-size: 12px; font-weight: 600; padding: 5px 10px; margin-left: 6px;
  background: transparent; color: var(--brand); border: 1px solid var(--line); border-radius: 7px; cursor: pointer;
}
.btn-mini:hover { background: var(--brand-soft); }
.btn-mini.danger { color: var(--danger); }
.btn-mini.danger:hover { background: var(--danger-soft); }
.badge-role { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); }
.badge-role.admin { background: #fff2cc; color: #7a5a00; }
.badge-sit { font-size: 12px; font-weight: 600; }
.badge-sit.ativo { color: var(--ok); }
.badge-sit.inativo { color: var(--danger); }
.cfg-toggle {
  font-size: 15px; line-height: 1; background: rgba(255, 255, 255, .12); color: #fff;
  border: none; border-radius: var(--radius-sm);
  min-width: 32px; height: 32px; padding: 0 10px; cursor: pointer; transition: background .15s;
}
.cfg-toggle:hover { background: rgba(255, 255, 255, .24); }

/* Modal de configuração */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(10, 20, 40, .5); display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto;
}
.modal {
  background: var(--card); border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(16, 30, 54, .1), 0 24px 48px rgba(16, 30, 54, .12);
  width: 100%; max-width: 520px;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-close {
  background: transparent; border: none; font-size: 18px; cursor: pointer; color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px;
}
.modal-close:hover { background: var(--bg); color: var(--ink); }
.modal-body { padding: 20px; display: flex; flex-direction: column; align-items: stretch; gap: 14px; }
.modal-body .cfg-label input { width: 100%; box-sizing: border-box; }
.cfg-label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 13px; }
.cfg-label input {
  font: inherit; font-weight: 400; font-size: 15px; padding: 10px 12px;
  border: 1.5px solid var(--line); border-radius: 10px; outline: none;
}
.cfg-label input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.cfg-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cfg-grid .cfg-label:first-child { grid-column: 1 / -1; }
.cfg-check { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.modal-note { padding: 0 20px 16px; font-size: 12px; margin: 0; }
@media (max-width: 520px) { .cfg-grid { grid-template-columns: 1fr; } }

/* Navegacao superior */
.mainnav {
  max-width: var(--max); margin: 0 auto; padding: 0 24px;
  display: flex; gap: 2px; overflow-x: auto;
}
.navbtn {
  background: transparent; color: rgba(255, 255, 255, .75);
  border: none; border-radius: var(--radius-sm) var(--radius-sm) 0 0; margin: 0;
  padding: 10px 16px; font-weight: 500; font-size: 14px; white-space: nowrap;
  transition: background .15s, color .15s;
}
.navbtn:hover { background: rgba(255, 255, 255, .1); color: #fff; }
.navbtn.active { background: var(--bg); color: var(--brand-dark); font-weight: 600; }

/* Layout */
.container { max-width: var(--max); margin: 28px auto 56px; padding: 0 24px; }
.section { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.search-card, .result {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 26px 28px;
}
.search-card h1 { margin: 0 0 5px; font-size: 19px; font-weight: 600; letter-spacing: -.2px; }
.muted { color: var(--muted); }
.search-card .muted { margin: 0 0 20px; font-size: 14px; }

.tabs { display: flex; gap: 2px; margin-bottom: 22px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  background: transparent; color: var(--muted); border: none;
  border-bottom: 2px solid transparent; border-radius: 0;
  padding: 9px 14px; font-weight: 500; font-size: 14px; white-space: nowrap;
  transition: color .15s, border-color .15s;
}
.tab:hover { background: transparent; color: var(--ink); }
.tab.active { color: var(--brand); font-weight: 600; border-bottom-color: var(--brand); }

form { display: flex; gap: 14px; align-items: flex-end; flex-wrap: wrap; }
.field input#nome { letter-spacing: .3px; font-size: 16px; text-transform: uppercase; }
/* CNPJ alfanumérico: letras sempre exibidas em maiúsculas */
.field input#cnpj { text-transform: uppercase; }

/* Combobox de pesquisa incremental (município) */
.combo { position: relative; }
.combo-list {
  position: absolute; z-index: 30; top: calc(100% + 4px); left: 0; right: 0;
  margin: 0; padding: 4px; list-style: none;
  background: #fff; border: 1.5px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); max-height: 280px; overflow-y: auto;
}
.combo-list li {
  padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 14px;
  display: flex; gap: 8px; align-items: baseline;
}
.combo-list li .cod { color: var(--muted); font-variant-numeric: tabular-nums; min-width: 46px; }
.combo-list li:hover, .combo-list li.ativo { background: var(--brand-soft); }
.combo-list li.vazio { color: var(--muted); cursor: default; font-style: italic; }
.combo-list li.vazio:hover { background: transparent; }

/* Lista de resultados */
.result-list {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 24px; margin-top: 18px;
}
.result-list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.result-list-head h2 { margin: 0; font-size: 16px; }
#btnCsvPj { flex: none; font-size: 13px; padding: 8px 14px; }
.hits { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.hit {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  cursor: pointer; transition: border-color .12s, background .12s;
}
.hit:hover { border-color: var(--brand); background: var(--brand-soft); }
.hit .hit-main { min-width: 0; }
.hit .hit-nome { font-weight: 700; }
.hit .hit-sub { font-size: 13px; color: var(--muted); }
.hit .hit-cpf { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--brand-dark); white-space: nowrap; }
.rl-more { margin-top: 12px; text-align: center; }
.field { display: flex; flex-direction: column; gap: 6px; flex: 1 1 260px; }
.field label { font-weight: 600; font-size: 12.5px; color: var(--muted); letter-spacing: .2px; }
.field input {
  font-size: 17px;
  letter-spacing: .6px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field select {
  font-size: 15px; padding: 11px 14px; border: 1px solid var(--line);
  border-radius: var(--radius-sm); outline: none; background: #fff; cursor: pointer;
  transition: border-color .15s, box-shadow .15s;
}
.field select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field small { font-size: 12px; }
/* Par de datas (de/ate) — mantidas lado a lado como um unico item do form */
.campo-periodo { display: flex; gap: 12px; align-items: flex-end; flex: 0 1 auto; }
/* CAEPF: um card por inscrição, empilhados na lista de resultados */
#caepfLista { display: flex; flex-direction: column; gap: 16px; }
#caepfLista .result { animation: none; }
.field-data { flex: 0 1 175px; min-width: 150px; }
.field-data input { font-size: 15px; letter-spacing: 0; }
@media (max-width: 420px) { .campo-periodo { flex-wrap: wrap; } }
.input-row { display: flex; gap: 8px; align-items: stretch; }
.input-row input { flex: 1; min-width: 0; }
.copy-field {
  flex: none; background: transparent; color: var(--brand);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 0 14px; font-weight: 600; font-size: 13px; white-space: nowrap;
}
.copy-field:hover { background: var(--brand-soft); }
.copy-field.copiado { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }

/* Botão copiar dentro dos itens de listagem (CNPJ) */
.hit-cpf { display: flex; align-items: center; gap: 8px; }
.copy-hit {
  flex: none; background: transparent; color: var(--brand);
  border: 1px solid var(--line); border-radius: 7px;
  padding: 3px 8px; font-size: 12px; font-weight: 600; line-height: 1.4;
}
.copy-hit:hover { background: var(--brand-soft); }
.copy-hit.copiado { color: var(--ok); border-color: var(--ok); }

button {
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 20px;
  background: var(--brand);
  color: #fff;
  transition: background .15s, transform .05s;
}
button:hover { background: var(--brand-dark); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .6; cursor: default; }
button.ghost { background: transparent; color: var(--brand); border: 1px solid var(--line); }
button.ghost:hover { background: var(--brand-soft); }

/* Status / mensagens */
.status {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}
.status.loading { background: var(--brand-soft); border-color: #cadcf3; color: var(--brand-dark); }
.status.error { background: var(--danger-soft); border-color: #f2c9c3; color: var(--danger); }
.status.empty { background: var(--warn-soft); border-color: #f0dcb9; color: var(--warn); }
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 3px solid #cadcf3; border-top-color: var(--brand);
  animation: spin .7s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Resultado */
.result { margin-top: 18px; }
.result-head {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 16px; border-bottom: 1px solid var(--line); padding-bottom: 16px; margin-bottom: 18px;
}
.result-head h2 { margin: 0 0 8px; font-size: 20px; font-weight: 600; letter-spacing: -.2px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  font-size: 13px; font-weight: 600;
  padding: 4px 12px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-dark);
}
.chip-cpf { font-variant-numeric: tabular-nums; letter-spacing: .5px; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.cell { background: #fff; padding: 12px 15px; }
.cell.full { grid-column: 1 / -1; }
.cell .k { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.cell .v { font-size: 15px; font-weight: 600; margin-top: 2px; word-break: break-word; }
.cell .v.empty-v { font-weight: 400; color: var(--muted); font-style: italic; }

.group-title {
  grid-column: 1 / -1;
  background: var(--line-soft);
  padding: 9px 15px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--brand);
}

.raw { margin-top: 18px; }
.raw summary { cursor: pointer; color: var(--brand); font-weight: 600; }
.raw pre {
  margin-top: 10px; background: #0f1729; color: #d7e3f6;
  padding: 14px; border-radius: 10px; overflow: auto; font-size: 13px;
}

/* Painel de preparacao (aba Prepare) */
.prep-status {
  margin: 14px 0 10px; padding: 12px 14px; border-radius: 10px;
  border: 1px solid var(--line); background: #f7f9fc; font-size: 14px;
}
.prep-status.ok { background: var(--ok-soft); border-color: #bfe6cd; color: var(--ok); }
.prep-status.building { background: var(--brand-soft); border-color: #cadcf3; color: var(--brand-dark); }

/* Quadro societario */
.socios { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.socio {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfe;
}
.socio-id { font-weight: 700; font-variant-numeric: tabular-nums; }
.socio-meta { font-size: 13px; color: var(--muted); }
.link-cnpj { color: var(--brand); text-decoration: none; font-weight: 700; }
.link-cnpj:hover { text-decoration: underline; }

/* Mapa embutido (endereço da empresa) */
.btn-mapa { font-size: 13px; padding: 8px 14px; }
.mapa-box { margin-top: 10px; }
.mapa-frame { width: 100%; height: 300px; border: 1px solid var(--line); border-radius: 10px; display: block; }
.mapa-link { margin-top: 6px; font-size: 13px; }
.mapa-link a { color: var(--brand); font-weight: 600; text-decoration: none; }
.mapa-link a:hover { text-decoration: underline; }

.footer { max-width: var(--max); margin: 0 auto; padding: 0 24px 40px; color: var(--muted); text-align: center; font-size: 12.5px; }

@media print {
  .topbar, .search-card, .footer, #btnPrint, .raw { display: none !important; }
  body { background: #fff; }
  .result { box-shadow: none; border: none; padding: 0; }
}
