:root {
  --fundo: #f4f5f7;
  --superficie: #ffffff;
  --borda: #dfe2e7;
  --texto: #1d2330;
  --sutil: #6b7385;
  --primaria: #1f5fbf;
  --primaria-hover: #174d9d;
  --perigo: #c0392b;
  --ok-fundo: #e5f5ea; --ok-texto: #1e6b3a;
  --erro-fundo: #fbe9e7; --erro-texto: #9b2c1f;
  --raio: 8px;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--texto);
  background: var(--fundo);
}
a { color: var(--primaria); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 .8rem; }
.mono { font-family: var(--mono); font-size: .92em; }
.sutil { color: var(--sutil); font-size: .9em; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.inline { display: inline; }

/* ---------- topo ---------- */
.topbar {
  display: flex; align-items: center; gap: 1.5rem;
  background: #172033; color: #fff; padding: 0 1.25rem; height: 52px;
  position: sticky; top: 0; z-index: 10;
}
.topbar .marca { color: #fff; font-weight: 700; font-size: 1.1rem; letter-spacing: .05em; }
.topbar nav { display: flex; gap: .25rem; flex: 1; overflow-x: auto; }
.topbar nav a { color: #c8d0e0; padding: .45rem .7rem; border-radius: 6px; white-space: nowrap; }
.topbar nav a:hover { background: #24304a; color: #fff; text-decoration: none; }
.topbar nav a.ativo { background: #2c3b5c; color: #fff; }
.topbar .usuario { display: flex; align-items: center; gap: .75rem; white-space: nowrap; }
.topbar .usuario a { color: #c8d0e0; }
button.link { background: none; border: 0; color: #c8d0e0; cursor: pointer; font: inherit; padding: 0; }
button.link:hover { color: #fff; text-decoration: underline; }

.conteudo { max-width: 1280px; margin: 0 auto; padding: 1.25rem; }
.conteudo-login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }

/* ---------- blocos ---------- */
.cabecalho-pagina { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.cartao .cabecalho-pagina { margin-bottom: .6rem; }
.cartao .cabecalho-pagina h2 { margin: 0; }
.cartao { background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); padding: 1rem 1.15rem; margin-bottom: 1rem; }
.alerta { padding: .7rem .9rem; border-radius: var(--raio); margin-bottom: 1rem; }
.alerta-ok { background: var(--ok-fundo); color: var(--ok-texto); }
.alerta-erro { background: var(--erro-fundo); color: var(--erro-texto); }

.indicadores { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .75rem; margin-bottom: 1rem; }
.indicador { background: var(--superficie); border: 1px solid var(--borda); border-radius: var(--raio); padding: .9rem 1rem; color: var(--texto); display: flex; flex-direction: column; gap: .2rem; }
.indicador:hover { border-color: var(--primaria); text-decoration: none; }
.indicador span { color: var(--sutil); font-size: .85rem; }
.indicador strong { font-size: 1.4rem; font-variant-numeric: tabular-nums; }

/* ---------- botões ---------- */
.btn {
  display: inline-block; border: 1px solid var(--borda); background: var(--superficie); color: var(--texto);
  padding: .45rem .85rem; border-radius: 6px; cursor: pointer; font: inherit; line-height: 1.3;
}
.btn:hover { background: #eef0f4; text-decoration: none; }
.btn-primario { background: var(--primaria); border-color: var(--primaria); color: #fff; }
.btn-primario:hover { background: var(--primaria-hover); }
.btn-perigo { color: var(--perigo); }
.btn-perigo:hover { background: var(--erro-fundo); }
.btn-peq { padding: .2rem .55rem; font-size: .85rem; }
.largo { width: 100%; }
.barra-acoes { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ---------- formulários ---------- */
.form label { display: flex; flex-direction: column; gap: .25rem; font-weight: 500; font-size: .9rem; margin-bottom: .75rem; }
.form label.check { flex-direction: row; align-items: center; gap: .4rem; font-weight: 400; display: inline-flex; margin-right: 1.25rem; }
input, select, textarea {
  font: inherit; color: inherit; padding: .45rem .55rem; border: 1px solid var(--borda);
  border-radius: 6px; background: #fff; width: 100%; min-width: 0;
}
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9dbcf0; outline-offset: -1px; border-color: var(--primaria); }
fieldset { border: 1px solid var(--borda); border-radius: var(--raio); margin: 0 0 1rem; padding: .75rem 1rem .25rem; }
legend { font-weight: 600; padding: 0 .35rem; }
.grade { display: grid; gap: 0 1rem; }
.grade-2 { grid-template-columns: repeat(2, 1fr); }
.grade-3 { grid-template-columns: repeat(3, 1fr); }
.grade-4 { grid-template-columns: repeat(4, 1fr); }
.col-2 { grid-column: span 2; }
.col-3 { grid-column: span 3; }
.alinhado-topo { align-items: start; }
.acoes { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .5rem; }
.estreito { max-width: 480px; }

.filtros { display: flex; gap: .5rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.filtros input[type=search] { max-width: 320px; }
.filtros select { width: auto; }
.abas { display: flex; gap: .25rem; margin-right: .5rem; }
.abas a { padding: .4rem .8rem; border-radius: 6px; color: var(--texto); }
.abas a.ativo { background: #dfe8f7; color: var(--primaria); font-weight: 600; }

/* ---------- tabelas ---------- */
.tabela { width: 100%; border-collapse: collapse; }
.tabela th { text-align: left; font-weight: 600; color: var(--sutil); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; border-bottom: 1px solid var(--borda); padding: .5rem .5rem; }
.tabela th.num { text-align: right; }
.tabela td { border-bottom: 1px solid #eef0f3; padding: .55rem .5rem; vertical-align: top; }
.tabela tbody tr:hover { background: #fafbfc; }
.tabela tr.inativo td { opacity: .5; }
.tabela-rolagem { overflow-x: auto; }

.selo { display: inline-block; font-size: .75rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; background: #eceff3; color: #4a5263; margin-right: .2rem; }
.selo-rascunho  { background: #eceff3; color: #4a5263; }
.selo-enviada   { background: #e1ebfa; color: #1f4f9a; }
.selo-aprovada  { background: #e2f4e7; color: #1e6b3a; }
.selo-reprovada { background: #fbe4e1; color: #9b2c1f; }
.selo-cancelada { background: #f1e9e0; color: #7a5a35; }

/* ---------- grade de itens da proposta ---------- */
.tabela-itens td { padding: .35rem .3rem; vertical-align: middle; }
.tabela-itens input { padding: .35rem .45rem; }
.tabela-itens .seq { color: var(--sutil); text-align: center; }
.tabela-itens .total { font-weight: 600; white-space: nowrap; }
.pos-rel { position: relative; }
.autocompletar {
  /* fixed: não é cortada pelo container com rolagem; posição calculada no JS */
  display: none; position: fixed; z-index: 20; min-width: 26rem;
  list-style: none; margin: 0; padding: .25rem 0; background: #fff;
  border: 1px solid var(--borda); border-radius: 6px; box-shadow: 0 8px 24px rgba(20, 30, 50, .12);
  max-height: 300px; overflow-y: auto;
}
.autocompletar li { padding: .4rem .7rem; cursor: pointer; }
.autocompletar li.ativo, .autocompletar li:hover { background: #e9f0fc; }
.autocompletar li.vazio { color: var(--sutil); cursor: default; }

.totais > div { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .35rem 0; }
.totais input { max-width: 150px; }
.totais .total-geral { border-top: 2px solid var(--texto); margin-top: .4rem; padding-top: .6rem; font-size: 1.15rem; }

/* ---------- documento da proposta ---------- */
.documento { padding: 2rem 2.25rem; }
.doc-topo { display: flex; justify-content: space-between; border-bottom: 2px solid var(--texto); padding-bottom: 1rem; margin-bottom: 1rem; gap: 1rem; }
.doc-emissor { font-size: 1.3rem; font-weight: 700; }
.doc-numero { text-align: right; }
.doc-cliente { margin-bottom: 1.25rem; line-height: 1.6; }
.rotulo { font-weight: 600; color: var(--sutil); font-size: .82rem; text-transform: uppercase; letter-spacing: .03em; }
.doc-itens { margin-bottom: 1.25rem; }
.doc-rodape { display: grid; grid-template-columns: 1fr 320px; gap: 2rem; align-items: start; }
.doc-condicoes > div { margin-bottom: .5rem; }
.obs { white-space: pre-line; }

/* ---------- login ---------- */
.login-caixa { background: #fff; border: 1px solid var(--borda); border-radius: 12px; padding: 2rem; width: 100%; max-width: 380px; }
.login-caixa h1 { margin-bottom: .25rem; }

/* ---------- responsivo ---------- */
@media (max-width: 860px) {
  .grade-3, .grade-4 { grid-template-columns: repeat(2, 1fr); }
  .col-3 { grid-column: span 2; }
  .doc-rodape { grid-template-columns: 1fr; }
  .topbar { height: auto; flex-wrap: wrap; padding: .5rem 1rem; gap: .5rem; }
  .topbar nav { order: 3; width: 100%; }
}
@media (max-width: 560px) {
  .grade-2, .grade-3, .grade-4 { grid-template-columns: 1fr; }
  .col-2, .col-3 { grid-column: auto; }
  .tabela { font-size: .9rem; }
}

/* ---------- impressão ---------- */
@media print {
  body { background: #fff; }
  .topbar, .nao-imprimir, .alerta { display: none !important; }
  .conteudo { padding: 0; max-width: none; }
  .cartao { border: 0; padding: 0; }
  .selo { border: 1px solid #ccc; }
  a { color: inherit; }
}

/* ---------- auditoria ---------- */
.nowrap { white-space: nowrap; }
.carimbo-auditoria {
  font-size: .85rem; color: var(--sutil); background: #f7f8fa; border: 1px dashed var(--borda);
  border-radius: 6px; padding: .5rem .75rem; margin: .25rem 0 .75rem;
}
.carimbo-auditoria strong { color: var(--texto); }
.lista-campos { margin: 0; padding-left: 1rem; }
.lista-campos li { margin: .1rem 0; }
.lista-campos .de { color: var(--erro-texto); text-decoration: line-through; }
.lista-campos .para { color: var(--ok-texto); font-weight: 600; }
.tabela-auditoria details summary { cursor: pointer; color: var(--primaria); }
@media print { .carimbo-auditoria { display: none; } }
.form label.check.alinha-base { align-self: end; margin-bottom: 1.1rem; }
.doc-status { font-weight: 400; font-size: .8rem; color: var(--sutil); min-height: 1.1em; }
.doc-status.ok { color: var(--ok-texto); font-weight: 600; }
.doc-status.erro { color: var(--erro-texto); font-weight: 600; }

/* ---------- busca de CNPJ ---------- */
.form .campo { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.form .campo > label { margin-bottom: 0; }
.com-botao { display: flex; gap: .4rem; }
.com-botao input { flex: 1; }
.com-botao .btn { white-space: nowrap; }
.com-botao .btn:disabled { opacity: .5; cursor: not-allowed; }
.receita-info { font-size: .85rem; border-radius: 6px; padding: .55rem .8rem; margin: 0 0 .75rem; background: #eef3fb; color: #1f4f9a; }
.receita-info.ok { background: var(--ok-fundo); color: var(--ok-texto); }
.receita-info.erro { background: var(--erro-fundo); color: var(--erro-texto); }
.receita-info a { color: inherit; text-decoration: underline; display: block; }
input.preenchido-receita { background: #f3faf5; }

/* ---------- contatos da empresa ---------- */
.tabela-contatos td { padding: .3rem .25rem; vertical-align: middle; }
.tabela-contatos input[type=text], .tabela-contatos input[type=tel], .tabela-contatos input[type=email] { padding: .35rem .45rem; }
.tabela-contatos .centro { text-align: center; }
.tabela-contatos th:first-child { width: 4.5rem; text-align: center; }

/* ---------- logotipo / minha empresa ---------- */
.topbar .marca { display: flex; align-items: center; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .marca img { height: 36px; max-width: 200px; object-fit: contain; background: #fff; border-radius: 6px; padding: 3px 8px; display: block; }
.topbar .marca:hover { text-decoration: none; }
.login-logo { text-align: center; margin-bottom: .75rem; }
.login-logo img { max-width: 100%; max-height: 110px; object-fit: contain; }
.logo-area { display: flex; gap: 1.5rem; align-items: flex-start; flex-wrap: wrap; }
.logo-preview {
  width: 280px; height: 120px; display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--borda); border-radius: 8px; padding: .5rem;
  background: repeating-conic-gradient(#f2f3f5 0% 25%, #fff 0% 50%) 50% / 16px 16px; /* xadrez: mostra transparência */
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.logo-controles { flex: 1; min-width: 240px; display: flex; flex-direction: column; gap: .4rem; }
.doc-emissor-bloco { display: flex; gap: 1rem; align-items: flex-start; }
.doc-logo { max-height: 70px; max-width: 200px; object-fit: contain; }
.doc-emissor-dados { font-size: .82rem; color: var(--sutil); line-height: 1.45; margin: .15rem 0 .25rem; }

/* campo ocupando a linha inteira da grade */
.col-4 { grid-column: 1 / -1; }

/* preço vindo do cadastro em EUR/USD: converter para Real na proposta */
input.moeda-estrangeira { background: #fff6d6; border-color: #e0b400; }
