:root {
  --fundo: #f4f5f7;
  --cartao: #ffffff;
  --texto: #1c2230;
  --rotulo: #475467;
  --suave: #667085;
  --borda: #e3e6eb;
  --primaria: #1f4fd8;
  --primaria-escura: #1a41b3;
  --marinho: #0f1b3d;
  --ok: #12805c;
  --erro: #c4320a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--fundo);
  color: var(--texto);
  font: 14px/1.45 Inter, system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topo { background: var(--marinho); color: #fff; }
.topo-in { max-width: 1200px; margin: 0 auto; padding: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.marca { display: flex; align-items: center; gap: 12px; }
.marca strong { display: block; font-size: 17px; }
.marca small { color: #aab4d0; }
.logo { width: 40px; height: 40px; border-radius: 9px; background: var(--primaria); display: grid; place-items: center; font-weight: 700; }
.selo { font-size: 12px; background: #fff2; padding: 4px 10px; border-radius: 99px; white-space: nowrap; }

.pagina { flex: 1; width: 100%; max-width: 1200px; margin: 0 auto; padding: 24px 16px 48px; display: grid; grid-template-columns: minmax(0, 1fr) 260px; gap: 20px; align-items: start; }

.cartao { background: var(--cartao); border: 1px solid var(--borda); border-radius: 10px; padding: 16px 18px; margin-bottom: 14px; }
.cartao > h2 {
  margin: -16px -18px 14px; padding: 11px 18px; border-bottom: 1px solid var(--borda);
  font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--primaria);
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  border-left: 4px solid var(--primaria); border-radius: 10px 10px 0 0;
}
.cartao > h2 .btn-link { text-transform: none; letter-spacing: 0; font-size: 13px; }

.grade { display: grid; grid-template-columns: repeat(12, 1fr); gap: 10px 12px; }
.grade label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 500; color: var(--rotulo); min-width: 0; }
.c3 { grid-column: span 3; } .c4 { grid-column: span 4; } .c6 { grid-column: span 6; } .c8 { grid-column: span 8; } .c12 { grid-column: span 12; }

input, select, textarea {
  font: inherit; font-size: 13.5px; color: var(--texto); background: #fff;
  border: 1px solid var(--borda); border-radius: 7px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; }
input, select { height: 38px; }
/* Seta própria no select: a nativa encosta na borda e muda de altura entre navegadores. */
select {
  appearance: none; -webkit-appearance: none;
  padding-right: 32px; cursor: pointer;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 11px center;
  text-overflow: ellipsis; white-space: nowrap; overflow: hidden;
}
select:disabled { cursor: default; }
input[type=checkbox] { height: auto; }
input::placeholder, textarea::placeholder { color: #a6adb8; }
input:focus, select:focus, textarea:focus { outline: 2px solid #1f4fd833; border-color: var(--primaria); }
.invalido { border-color: var(--erro) !important; background: #fff6f3; }

.check { display: flex; align-items: center; gap: 8px; margin-top: 12px; font-size: 12.5px; font-weight: 500; color: var(--rotulo); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--primaria); }
.dica { font-size: 12px; color: var(--suave); font-weight: 400; }
.objeto { margin: 10px 0 0; font-size: 12.5px; color: var(--suave); }
.objeto strong { color: var(--texto); }

button { font: inherit; cursor: pointer; }
.btn-principal { background: var(--primaria); color: #fff; border: 0; border-radius: 8px; font-weight: 600; padding: 11px 20px; }
.btn-principal:hover { background: var(--primaria-escura); }
.btn-principal:disabled { opacity: .6; cursor: wait; }
.btn-sec { background: #fff; color: var(--primaria); border: 1px solid var(--primaria); border-radius: 7px; font-weight: 600; padding: 9px 16px; text-decoration: none; display: inline-block; text-transform: none; letter-spacing: 0; font-size: 13px; }
.btn-branco { background: #fff; color: var(--texto); border: 1px solid var(--borda); border-radius: 8px; font-weight: 600; padding: 10px; }
.btn-branco:hover { border-color: var(--primaria); color: var(--primaria); }
.btn-link { background: none; border: 0; color: var(--primaria); font-weight: 500; padding: 0; }
.btn-perigo { background: none; border: 0; color: var(--erro); font-size: 12px; }

.acoes { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.erro { color: var(--erro); font-size: 13px; }
.ok { color: var(--ok); font-size: 13px; }

.lateral { display: flex; flex-direction: column; gap: 10px; position: sticky; top: 16px; }
.bloco-clientes { margin: 0; padding: 14px; }
.bloco-clientes strong { display: block; font-size: 13px; }
.bloco-clientes small { display: block; font-size: 11px; color: var(--suave); margin-bottom: 8px; }
#lista-clientes { list-style: none; margin: 8px 0 0; padding: 0; max-height: 300px; overflow: auto; }
#lista-clientes li { padding: 8px 4px; border-top: 1px solid #f0f1f3; font-size: 12.5px; color: var(--suave); }
#lista-clientes li[data-id] { cursor: pointer; color: var(--texto); display: flex; align-items: center; gap: 8px; }
#lista-clientes li[data-id]:hover { color: var(--primaria); }
#lista-clientes li small { color: var(--suave); white-space: nowrap; font-size: 11px; line-height: 20px; margin: 0; }

.resultado { border-color: #12805c55; margin-top: 16px; scroll-margin-top: 16px; }
.resultado > h2 { color: var(--ok); border-left-color: var(--ok); }
.lista-docs { list-style: none; margin: 0 0 12px; padding: 0; }
.lista-docs li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 11px 0; border-top: 1px solid var(--borda); flex-wrap: wrap; }
.lista-docs li:first-child { border-top: 0; }
.lista-docs li > span { font-weight: 500; display: flex; align-items: center; gap: 10px; }
.lista-docs .pdf { font-size: 10px; font-weight: 700; color: #fff; background: #d92d20; border-radius: 4px; padding: 2px 6px; }
.lista-docs .botoes { display: flex; gap: 8px; }
.lista-docs .botoes .btn-sec { padding: 6px 12px; }

.rodape { background: var(--marinho); color: #aab4d0; text-align: center; padding: 22px 16px; font-size: 12px; }

.modal { border: 0; border-radius: 12px; padding: 20px; width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 48px); box-shadow: 0 10px 40px #0004; }
.modal.largo { width: min(900px, calc(100vw - 32px)); }
/* Com popup aberto, a página de trás não rola (e a barra de rolagem não some, pra nada pular). */
html { scrollbar-gutter: stable; }
html:has(dialog[open]) { overflow: hidden; }
.modal { overscroll-behavior: contain; }
.modal::backdrop { background: #0f1b3d99; }
.modal-topo { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.modal-topo h3 { margin: 0; font-size: 18px; }
.modal h4 { display: flex; justify-content: space-between; align-items: center; margin: 20px 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--primaria); }
.fechar { background: none; border: 0; font-size: 26px; line-height: 1; color: var(--suave); }
.lista-itens { list-style: none; margin: 0; padding: 0; border: 1px solid var(--borda); border-radius: 8px; }
.lista-itens li { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border-top: 1px solid var(--borda); position: relative; }
.lista-itens li:first-child { border-top: 0; }
.lista-itens .info { min-width: 0; }
.lista-itens .info strong { display: block; font-size: 13.5px; }
.lista-itens .info small { display: block; color: var(--suave); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mais { background: none; border: 0; border-radius: 6px; width: 32px; height: 32px; font-size: 20px; line-height: 1; color: var(--suave); flex: none; }
.mais:hover, .mais[aria-expanded="true"] { background: #eef1f6; color: var(--texto); }
.menu-item { position: absolute; right: 12px; top: 44px; z-index: 5; background: #fff; border: 1px solid var(--borda); border-radius: 8px; box-shadow: 0 6px 20px #0002; padding: 4px; min-width: 140px; }
.menu-item button { display: block; width: 100%; text-align: left; background: none; border: 0; border-radius: 6px; padding: 8px 10px; font-size: 13px; color: var(--texto); }
.menu-item button:hover { background: #f3f6fd; }
.menu-item button.perigo { color: var(--erro); }
.menu-item button.perigo:hover { background: #fff3f0; }
.acoes-item { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin-top: 18px; }
.acoes-item .erro { margin-right: auto; }
#modal-item { width: min(620px, calc(100vw - 32px)); }
.acoes-config { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) 230px; gap: 14px; margin: 10px 0 4px; }
#editor-area { height: min(46vh, 460px); font: 13px/1.55 ui-monospace, 'SFMono-Regular', Menlo, monospace; }
.editor-texto .dica { margin: 6px 0 0; }
.nome-modelo { display: flex; flex-direction: column; gap: 4px; font-size: 12px; font-weight: 500; color: var(--rotulo); margin-bottom: 10px; }
.nome-modelo[hidden] { display: none; }
.lista-itens .info strong .pdf { font-size: 10px; font-weight: 700; color: #fff; background: #d92d20; border-radius: 4px; padding: 2px 6px; margin-right: 8px; vertical-align: 1px; }
#modal-modelos .acoes-config { margin-top: 14px; }
#modal-modelos .acoes-config #novo-modelo { margin-left: auto; }
code { background: #eef1f6; border-radius: 4px; padding: 1px 4px; font-size: 11.5px; }
.editor-campos { max-height: min(58vh, 560px); overflow: auto; border: 1px solid var(--borda); border-radius: 8px; padding: 10px; }
.editor-campos strong { display: block; font-size: 12px; }
.editor-campos small { display: block; font-size: 11px; color: var(--suave); margin-bottom: 6px; }
.editor-campos > div { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.chip { text-align: left; background: #f3f6fd; border: 1px solid #dbe4fb; border-radius: 6px; padding: 5px 8px; font-size: 12px; color: var(--texto); }
.chip:hover { border-color: var(--primaria); }
.chip code { background: none; padding: 0; color: var(--primaria); font-size: 11px; display: block; }
.marcado { background: #fff8e1; color: #8a5a00; font-size: 10px; font-weight: 600; border-radius: 4px; padding: 1px 6px; }

/* campos de seleção com menu ⋮ */
.campo-com-menu { display: flex; flex-direction: column; gap: 4px; min-width: 0; position: relative; }
.campo-com-menu > label { font-size: 12px; font-weight: 500; color: var(--rotulo); }
.linha-select { display: flex; gap: 6px; align-items: center; }
.linha-select select { flex: 1; min-width: 0; }
.campo-com-menu .menu-item { top: 100%; right: 0; margin-top: 4px; min-width: 200px; }
.menu-item button:disabled { color: #b0b6c0; cursor: default; background: none; }

.grade label.check { flex-direction: row; align-items: center; font-size: 12.5px; }
.bloco-declarante { margin-top: 12px; padding: 12px; background: #f6f8fc; border: 1px dashed #c9d3ea; border-radius: 8px; }
.bloco-declarante[hidden] { display: none; }

#lista-clientes li[data-id] > span { line-height: 20px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.remover-cliente { flex: none; display: grid; place-items: center; width: 20px; height: 20px; background: none; border: 0; border-radius: 4px; color: #b0b6c0; padding: 0; }
.remover-cliente svg { display: block; }
.remover-cliente:hover { background: #fff3f0; }
.remover-cliente:hover { color: var(--erro); }

.vinculos { margin-top: 10px; border: 1px solid var(--borda); border-radius: 8px; padding: 10px 12px; }
.vinculos strong { display: block; font-size: 12px; margin-bottom: 6px; }
#editor-servicos { display: flex; flex-wrap: wrap; gap: 4px 16px; }
#editor-servicos .check { margin: 0; font-weight: 400; }
#editor-servicos .check.todos { width: 100%; font-weight: 600; }

@media (max-width: 900px) {
  .editor { grid-template-columns: 1fr; }
  .pagina { grid-template-columns: 1fr; }
  .lateral { position: static; }
}
@media (max-width: 640px) {
  .grade { grid-template-columns: 1fr; }
  .grade > * { grid-column: auto !important; }
  .selo { display: none; }
}
