/* ─── RESET & BASE ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --red:    #DE0B17;
  --red-dk: #B50912;
  --black:  #141414;
  --white:  #FFFFFF;
  --gray:   #F5F5F5;
  --gray2:  #E8E8E8;
  --gray3:  #999;
  --empty:  #E57373;
  --font:   'Segoe UI', Arial, sans-serif;
}

html, body { height: 100%; }

body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--black);
  background: var(--gray);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ─── HEADER ────────────────────────────────────────────────── */
.header {
  background: var(--black);
  color: var(--white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 24px;
  height: 80px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

.header-brand { display: flex; align-items: center; gap: 16px; }

.logo {
  display: flex;
  flex-direction: column;
  line-height: 1;
  border-left: 3px solid var(--red);
  padding-left: 10px;
}
.logo-nippon { font-size: 18px; font-weight: 800; color: var(--white); letter-spacing: 2px; }
.logo-sub    { font-size: 9px;  font-weight: 400; color: var(--gray3); letter-spacing: 3px; text-transform: uppercase; }

.header-title { font-size: 16px; font-weight: 400; color: #ccc; }

.doc-nav { display: flex; flex-direction: column; gap: 6px; align-items: flex-end; }
.doc-tabs { display: flex; gap: 6px; }

.tab-btn {
  background: transparent;
  border: 2px solid var(--gray3);
  color: #ccc;
  padding: 6px 16px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
}
.tab-btn:hover  { border-color: var(--red); color: var(--white); }
.tab-btn.active { background: var(--red); border-color: var(--red); color: var(--white); }

/* Toggle Contrato / Instrumento */
.doc-toggle {
  display: flex;
  background: var(--gray3);
  border-radius: 4px;
  padding: 2px;
}
.doc-toggle-btn {
  background: transparent;
  border: none;
  color: #ccc;
  padding: 4px 18px;
  border-radius: 3px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  transition: all .15s;
}
.doc-toggle-btn:hover  { color: var(--white); }
.doc-toggle-btn.active  { background: var(--white); color: var(--black); }

/* Aviso de preenchimento automático (CNPJ) */
.aviso-auto {
  font-size: 11px;
  color: #856404;
  background: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
  padding: 6px 10px;
  margin-top: -4px;
  margin-bottom: 8px;
}

/* Seletor de tipo de pessoa */
.tipo-pessoa { display: flex; gap: 6px; }
.tp-btn {
  flex: 1;
  background: var(--white);
  border: 1.5px solid #d0d0d0;
  color: #555;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all .15s;
}
.tp-btn:hover  { border-color: var(--red); }
.tp-btn.active { background: var(--red); border-color: var(--red); color: var(--white); }

/* ─── SETUP BANNER ──────────────────────────────────────────── */
.setup-banner {
  background: #fff3cd;
  border-bottom: 2px solid #ffc107;
  padding: 12px 24px;
}
.setup-inner { max-width: 900px; display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.setup-files { display: flex; gap: 16px; flex-wrap: wrap; }

.file-label {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--white);
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 6px 12px;
  cursor: pointer;
  font-size: 13px;
}
.file-label input[type="file"] { display: none; }
.file-label span:first-child { font-weight: 600; }

.file-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
  background: #eee;
  color: #666;
}
.file-status.ok { background: #d4edda; color: #155724; }

/* ─── MAIN LAYOUT ───────────────────────────────────────────── */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 80px);
}

/* ─── PAINEL FORMULÁRIO ─────────────────────────────────────── */
.painel-form {
  width: 40%;
  min-width: 340px;
  overflow-y: auto;
  padding: 20px 16px 100px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--gray);
  border-right: 1px solid var(--gray2);
}

.card {
  background: var(--white);
  border-radius: 6px;
  border-left: 4px solid var(--red);
  padding: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--red);
  margin-bottom: 14px;
}

.campo-grupo {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}
.campo-grupo:last-child { margin-bottom: 0; }

.campo-grupo label {
  font-size: 12px;
  font-weight: 600;
  color: #444;
}

.campo-linha-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.campo-linha-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.campo-linha-2 .campo-grupo,
.campo-linha-3 .campo-grupo { margin-bottom: 0; }

input[type="text"],
input[type="number"],
input[type="date"],
select {
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 7px 10px;
  font-size: 13px;
  font-family: var(--font);
  color: var(--black);
  background: var(--white);
  transition: border-color .15s;
  width: 100%;
}
input:focus, select:focus {
  outline: none;
  border-color: var(--red);
  box-shadow: 0 0 0 2px rgba(222,11,23,.12);
}

input.campo-invalido, select.campo-invalido {
  border-color: var(--red) !important;
  background: #fff5f5;
}

.campo-descricao {
  font-size: 12px;
  color: #555;
  margin-bottom: 12px;
  line-height: 1.5;
}

/* ─── LISTA DE PEÇAS ────────────────────────────────────────── */
.peca-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 13px;
}
.peca-item:last-child { border-bottom: none; }
.peca-item input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--red); flex-shrink: 0; }
.peca-item .peca-nome { flex: 1; }
.peca-item .btn-remover-peca {
  background: none;
  border: none;
  color: #bbb;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 4px;
  transition: color .15s;
}
.peca-item .btn-remover-peca:hover { color: var(--red); }

.adicionar-peca {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}
.adicionar-peca input { flex: 1; }

.btn-adicionar {
  background: var(--black);
  color: var(--white);
  border: none;
  border-radius: 4px;
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
}
.btn-adicionar:hover { background: var(--red); }

.preview-frase {
  margin-top: 14px;
  background: var(--gray);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 12px;
  line-height: 1.6;
  border-left: 3px solid var(--red);
}

/* ─── AÇÕES ─────────────────────────────────────────────────── */
.acoes {
  display: flex;
  gap: 10px;
  padding: 0 4px;
}

.btn-acao {
  flex: 1;
  background: var(--red);
  color: var(--white);
  border: none;
  border-radius: 5px;
  padding: 12px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .1s;
  text-align: center;
}
.btn-acao:hover   { background: var(--red-dk); }
.btn-acao:active  { transform: scale(.98); }

.msg-sucesso {
  background: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
  border-radius: 4px;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
}

/* ─── PAINEL PREVIEW ────────────────────────────────────────── */
.painel-preview {
  flex: 1;
  overflow-y: auto;
  background: #d9d9d9;
  display: flex;
  flex-direction: column;
}

.preview-header {
  background: var(--black);
  padding: 8px 20px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.preview-tipo {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.5px;
  color: var(--red);
  text-transform: uppercase;
}

.preview-container {
  flex: 1;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

/* "Folha" de papel no preview */
.folha {
  background: var(--white);
  width: 100%;
  max-width: 720px;
  min-height: 200px;
  padding: 48px 52px;
  box-shadow: 0 2px 12px rgba(0,0,0,.15);
  font-family: Calibri, 'Segoe UI', Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.5;
  color: #1a1a1a;
}

.folha-titulo {
  text-align: center;
  font-weight: 700;
  font-size: 13pt;
  margin-bottom: 6px;
  text-transform: uppercase;
}
.folha-subtitulo {
  text-align: center;
  font-size: 10pt;
  color: #555;
  margin-bottom: 24px;
}

.folha-secao { margin-bottom: 20px; }

.folha-secao-titulo {
  font-weight: 700;
  font-size: 10pt;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: #333;
  margin-bottom: 8px;
  border-bottom: 1px solid #eee;
  padding-bottom: 4px;
}

.folha-linha { margin-bottom: 6px; text-align: justify; }
.folha-clausula { margin-bottom: 10px; text-align: justify; }
.folha-clausula-num { font-weight: 700; }

.campo-vazio {
  color: var(--empty);
  font-style: italic;
}

.folha-assinatura {
  margin-top: 32px;
  display: flex;
  justify-content: space-between;
  gap: 32px;
}
.folha-assina-bloco {
  flex: 1;
  border-top: 1px solid #333;
  padding-top: 8px;
  font-size: 10pt;
  text-align: center;
}

.folha-separador {
  height: 1px;
  background: #eee;
  margin: 16px 0;
}

/* ─── SCROLLBAR ─────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; }
::-webkit-scrollbar-track { background: #eee; }
::-webkit-scrollbar-thumb { background: #bbb; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--red); }

/* ─── RESPONSIVO BÁSICO ─────────────────────────────────────── */
@media (max-width: 900px) {
  .main-layout { flex-direction: column; height: auto; }
  .painel-form  { width: 100%; height: auto; padding-bottom: 20px; }
  .painel-preview { min-height: 400px; }
  .header { flex-wrap: wrap; height: auto; padding: 10px 16px; gap: 10px; }
}
