* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #f4f5f7;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  color: #1a1a2e;
}

.container {
  background: #fff;
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 720px;
  box-shadow: 0 2px 20px rgba(0,0,0,0.08);
}

.hidden { display: none !important; }

/* HEADER */
.header {
  margin-bottom: 32px;
  border-bottom: 1px solid #eee;
  padding-bottom: 24px;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}

.logo-icon {
  font-size: 32px;
  background: #1a1a2e;
  color: #fff;
  width: 52px;
  height: 52px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.logo-title {
  font-size: 22px;
  font-weight: 700;
  color: #1a1a2e;
  letter-spacing: -0.5px;
}

.logo-sub {
  font-size: 13px;
  color: #888;
  margin-top: 1px;
}

.tagline {
  font-size: 15px;
  color: #555;
  margin-top: 4px;
}

/* FORM */
.field-group {
  margin-bottom: 24px;
}

.field-group label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  color: #333;
  margin-bottom: 8px;
}

.opcional {
  font-weight: 400;
  color: #999;
  font-size: 12px;
}

select, textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  color: #333;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}

select:focus, textarea:focus {
  border-color: #1a1a2e;
}

select {
  background: #fff;
  cursor: pointer;
  height: 44px;
}

textarea {
  height: 90px;
  resize: vertical;
}

/* UPLOAD */
.upload-area {
  border: 2px dashed #d0d0d0;
  border-radius: 10px;
  padding: 32px 24px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  background: #fafafa;
}

.upload-area:hover, .upload-area.dragover {
  border-color: #1a1a2e;
  background: #f0f0f5;
}

.upload-area.has-file {
  border-color: #22c55e;
  background: #f0fdf4;
}

.upload-icon {
  font-size: 32px;
  margin-bottom: 10px;
}

.upload-text {
  font-size: 14px;
  color: #444;
  margin-bottom: 4px;
}

.upload-link {
  color: #1a1a2e;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
}

.upload-hint {
  font-size: 12px;
  color: #999;
}

/* BOTÕES */
.btn-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: #1a1a2e;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.2s, opacity 0.2s;
}

.btn-primary:hover:not(:disabled) {
  background: #2d2d4e;
}

.btn-primary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn-secondary {
  display: block;
  width: 100%;
  padding: 14px;
  background: #fff;
  color: #1a1a2e;
  border: 2px solid #1a1a2e;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  margin-top: 12px;
}

.btn-secondary:hover {
  background: #f4f5f7;
}

.btn-group {
  margin-top: 24px;
}

/* LOADING */
.loading-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 60px 0;
  gap: 20px;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid #eee;
  border-top-color: #1a1a2e;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.barra-progresso-wrap {
  width: 280px;
  height: 3px;
  background: #e5e7eb;
  border-radius: 2px;
  margin: 12px auto;
  overflow: hidden;
}

.barra-progresso {
  height: 100%;
  background: #1a3a5c;
  border-radius: 2px;
  width: 0%;
  animation: encher 90s linear forwards;
}

@keyframes encher {
  from { width: 0%; }
  to { width: 95%; }
}

.tempo-estimado {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 4px;
}

.loading-msg {
  font-size: 16px;
  font-weight: 600;
  color: #1a1a2e;
  transition: opacity 0.3s ease;
}

.loading-sub {
  font-size: 13px;
  color: #999;
}

/* RESULTADO */
.resultado-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.resultado-badge {
  font-size: 15px;
  font-weight: 600;
  color: #16a34a;
}

.tempo-geracao {
  font-size: 12px;
  color: #aaa;
}

.dados-extraidos {
  background: #f8f9fa;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: 16px 20px;
  margin-bottom: 24px;
  font-size: 13px;
  line-height: 1.8;
}

.dados-extraidos strong {
  color: #1a1a2e;
}

.dado-item {
  display: flex;
  gap: 8px;
}

.dado-label {
  color: #888;
  min-width: 120px;
}

.dado-valor {
  color: #333;
  font-weight: 500;
}

.preview-formatada {
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 24px 28px;
  max-height: 500px;
  overflow-y: auto;
  font-family: 'Times New Roman', serif;
  font-size: 13px;
  line-height: 1.8;
  text-align: justify;
  color: #1a1a1a;
  margin-top: 8px;
}

.preview-formatada h1,
.preview-formatada h2,
.preview-formatada h3 {
  font-family: Arial, sans-serif;
  font-size: 13px;
  font-weight: bold;
  text-transform: uppercase;
  text-align: center;
  margin: 20px 0 10px;
}

.preview-formatada strong { font-weight: bold; }

.preview-formatada hr {
  border: none;
  border-top: 1px solid #ccc;
  margin: 14px 0;
}

.preview-formatada blockquote {
  margin: 12px 24px;
  padding: 8px 12px;
  border-left: 3px solid #ccc;
  font-style: italic;
  color: #444;
}

.preview-formatada p {
  margin-bottom: 10px;
  text-indent: 28px;
}

/* RESPONSIVO */
@media (max-width: 480px) {
  .container { padding: 24px; }
  body { padding: 16px; }
}

/* ===== MODAL EDITOR ===== */
#modal-editor {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.editor-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1001;
}

.editor-janela {
  position: relative;
  z-index: 1002;
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  background: #f0f0f0;
  display: flex;
  flex-direction: column;
}

.editor-topbar {
  background: #1a3a5c;
  color: #fff;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.editor-topbar-left { display: flex; align-items: center; }

.editor-titulo { font-size: 14px; font-weight: 600; }

.editor-aviso {
  font-size: 11px;
  opacity: 0.7;
  margin-left: 16px;
}

.btn-fechar {
  background: rgba(255,255,255,0.15);
  border: none;
  color: #fff;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.btn-fechar:hover { background: rgba(255,255,255,0.25); }

.editor-toolbar {
  background: #fff;
  border-bottom: 1px solid #e5e7eb;
  padding: 6px 16px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
  flex-wrap: nowrap;
  overflow-x: auto;
}

.editor-toolbar button {
  background: transparent;
  border: 1px solid transparent;
  padding: 4px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-family: Arial, sans-serif;
  color: #374151;
  transition: all 0.1s;
  white-space: nowrap;
  flex-shrink: 0;
}
.editor-toolbar button:hover {
  background: #f3f4f6;
  border-color: #e5e7eb;
}

.editor-toolbar select {
  border: 1px solid #e5e7eb;
  border-radius: 4px;
  padding: 3px 6px;
  font-size: 12px;
  font-family: Arial, sans-serif;
  color: #374151;
  background: #fff;
  width: auto;
  flex-shrink: 0;
}

.toolbar-sep {
  width: 1px;
  height: 20px;
  background: #e5e7eb;
  margin: 0 4px;
}

.btn-salvar {
  background: #1a3a5c !important;
  color: #fff !important;
  border-color: #1a3a5c !important;
  font-weight: 600 !important;
  margin-left: auto;
}
.btn-salvar:hover { background: #15304d !important; }

.editor-area {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
  background: #f0f0f0;
  display: flex;
  justify-content: center;
}

.editor-folha {
  background: #fff;
  width: 794px;
  min-height: 1123px;
  height: auto;
  padding: 80px 90px;
  box-shadow: 0 2px 16px rgba(0,0,0,0.15);
  margin-bottom: 32px;
  position: relative;
  /* Linha visual de quebra de página a cada 1123px */
  background-image: repeating-linear-gradient(
    to bottom,
    transparent 0px,
    transparent 1122px,
    #d1d5db 1122px,
    #d1d5db 1124px,
    transparent 1124px
  );
}

/* Número de página — removido da implementação dinâmica */
.editor-folha .num-pagina {
  display: none;
}

.editor-texto {
  font-family: 'Times New Roman', serif;
  font-size: 12pt;
  line-height: 1.8;
  color: #1a1a1a;
  text-align: justify;
  outline: none;
  min-height: 960px;
  height: auto;
}

.editor-texto h1,
.editor-texto h2,
.editor-texto h3 {
  font-family: Arial, sans-serif;
  font-size: 12pt;
  font-weight: bold;
  text-transform: uppercase;
  text-align: left;
  text-indent: 0;
  margin: 20px 0 10px;
}

.editor-texto p {
  margin-bottom: 12px;
  text-indent: 28px;
}

.editor-texto blockquote {
  margin: 12px 40px;
  font-style: italic;
  color: #444;
}

.editor-texto:focus { outline: none; }
.editor-texto ::selection { background: rgba(26,58,92,0.2); }

/* Botões de ação do resultado */
.acoes-resultado {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 24px;
}

/* Barra de cabeçalho do preview */
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
  gap: 12px;
}

.preview-header-titulo {
  font-size: 13px;
  color: #6b7280;
  white-space: nowrap;
}

.preview-acoes {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.preview-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid #e5e7eb;
  border-radius: 5px;
  background: #fff;
  color: #374151;
  font-size: 12px;
  font-family: 'Inter', Arial, sans-serif;
  cursor: pointer;
  transition: all 0.1s;
  white-space: nowrap;
}

.preview-btn:hover {
  background: #f3f4f6;
  border-color: #d1d5db;
}

.preview-btn svg { flex-shrink: 0; color: #6b7280; }
.preview-btn:hover svg { color: #374151; }

.preview-btn-primary {
  background: #1a3a5c;
  border-color: #1a3a5c;
  color: #fff;
}
.preview-btn-primary:hover { background: #15304d; border-color: #15304d; }
.preview-btn-primary svg { color: #fff; }
.preview-btn-primary:hover svg { color: #fff; }

/* CAMPO SUBSÍDIOS */
.campo-subsidios {
  margin-bottom: 16px;
}

.campo-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: #374151;
  margin-bottom: 6px;
}

.campo-opcional {
  font-size: 10px;
  font-weight: 400;
  color: #9ca3af;
  background: #f3f4f6;
  padding: 1px 6px;
  border-radius: 4px;
}

.campo-textarea {
  width: 100%;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 12px;
  font-family: 'Inter', Arial, sans-serif;
  color: #374151;
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color 0.1s;
  background: #fff;
}

.campo-textarea:focus {
  border-color: #1a3a5c;
}

.campo-textarea::placeholder {
  color: #9ca3af;
  font-size: 11px;
  line-height: 1.7;
}

.campo-dica {
  font-size: 11px;
  color: #9ca3af;
  margin-top: 5px;
}

/* UPLOAD DE SUBSÍDIOS */
.subsidios-upload {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.btn-adicionar-docs {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 6px 12px;
  border: 1px dashed #d1d5db;
  border-radius: 5px;
  background: #f9fafb;
  color: #4b5563;
  font-size: 12px;
  font-family: 'Inter', Arial, sans-serif;
  cursor: pointer;
  transition: all 0.1s;
  white-space: nowrap;
}

.btn-adicionar-docs:hover {
  border-color: #1a3a5c;
  color: #1a3a5c;
  background: #f0f4f8;
}

.subsidios-upload-hint {
  font-size: 11px;
  color: #9ca3af;
}

.subsidios-lista {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 8px;
}

.subsidio-arquivo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #f0f4f8;
  border: 1px solid #dbeafe;
  border-radius: 5px;
  font-size: 12px;
  color: #374151;
}

.subsidio-arquivo-icon { font-size: 14px; flex-shrink: 0; }
.subsidio-arquivo-nome { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.subsidio-arquivo-tamanho { font-size: 10px; color: #9ca3af; white-space: nowrap; }

.subsidio-arquivo-remover {
  background: none;
  border: none;
  color: #9ca3af;
  cursor: pointer;
  font-size: 14px;
  padding: 0 2px;
  flex-shrink: 0;
  line-height: 1;
}

.subsidio-arquivo-remover:hover { color: #ef4444; }

.subsidio-arquivo.processando {
  border-color: #fde68a;
  background: #fffbeb;
}

.subsidio-arquivo.erro {
  border-color: #fca5a5;
  background: #fef2f2;
  color: #dc2626;
}

@media (max-width: 600px) {
  .preview-btn span { display: none; }
  .preview-btn { padding: 6px 8px; }
}

@media (max-width: 860px) {
  .editor-folha { width: 100%; padding: 40px 24px; }
  .editor-area { padding: 16px; }
}
