:root {
  --bg: #0d1117;
  --card: #f8fafc;
  --border: #cbd5e1;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --error: #dc2626;
  --ok: #16a34a;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 32px 16px;
  background: var(--bg);
  color: var(--text);
  font-family: "Open Sans", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.card {
  width: 100%;
  max-width: 480px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  padding: 28px;
}

h1 {
  margin: 0 0 4px;
  font-size: 1.6rem;
}

.sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.92rem;
}

form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
}

input,
select {
  padding: 10px 12px;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.2);
}

fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

legend {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--muted);
  padding: 0 6px;
}

.info {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--muted);
  min-height: 1rem;
}

button {
  margin-top: 6px;
  padding: 12px;
  font-size: 1rem;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s ease;
}

button:hover {
  background: var(--primary-hover);
}

button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.resultado {
  margin-top: 18px;
  padding: 14px;
  border-radius: 6px;
  font-size: 0.92rem;
}

.resultado.ok {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}

.resultado.erro {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--error);
}

.resultado a {
  display: inline-block;
  margin-top: 8px;
  margin-right: 10px;
  color: var(--primary-hover);
  font-weight: 600;
}

.oculto {
  display: none !important;
}

/* ---- Painel de preview + editor ---- */
.painel {
  width: 100%;
  max-width: 860px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.painel-topo {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.painel-topo strong {
  font-size: 1.05rem;
}

.painel-acoes {
  display: flex;
  gap: 8px;
}

.btn-icone {
  margin: 0;
  padding: 8px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.btn-icone:hover {
  background: #f1f5f9;
  border-color: var(--primary);
}

.preview {
  width: 100%;
  height: 70vh;
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #525659;
}

/* ---- Editor manual ---- */
.editor {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.editor-dica {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
}

.editor-blocos {
  max-height: 60vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 22px 26px;
  background: #fff;
  font-size: 0.9rem;
  line-height: 1.5;
}

.ed-linha {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.ed-gutter {
  display: grid;
  grid-template-columns: repeat(2, 22px);
  gap: 2px;
  padding-top: 3px;
  opacity: 0;
  transition: opacity 0.12s ease;
}

.ed-linha:hover .ed-gutter,
.ed-linha:focus-within .ed-gutter {
  opacity: 1;
}

.ed-mini {
  margin: 0;
  width: 22px;
  height: 20px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  font-weight: 700;
  color: var(--muted);
  background: #f1f5f9;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
}

.ed-mini:hover {
  background: #e2e8f0;
  color: var(--text);
}

.ed-mini.ed-perigo:hover {
  background: #fee2e2;
  color: var(--error);
  border-color: #fecaca;
}

.ed-drag {
  cursor: grab;
  font-size: 14px;
}

.ed-drag:active {
  cursor: grabbing;
}

.ed-linha.ed-arrastando {
  opacity: 0.4;
}

/* Indicador de onde a cláusula será solta (sem deslocar o layout). */
.ed-linha.ed-drop-antes {
  box-shadow: 0 -2px 0 0 var(--primary);
}

.ed-linha.ed-drop-depois {
  box-shadow: 0 2px 0 0 var(--primary);
}

.ed-bloco {
  flex: 1;
  min-height: 1.4em;
  border-radius: 4px;
  padding: 2px 4px;
  margin: 1px 0;
  outline: none;
  transition: background 0.12s ease;
  white-space: pre-wrap;
}

.ed-bloco.ed-vazio:empty::before {
  content: "(linha em branco — clique para escrever)";
  color: #cbd5e1;
}

.ed-bloco:hover {
  background: #f1f5f9;
}

.ed-bloco:focus {
  background: #eff6ff;
  box-shadow: inset 0 0 0 1px var(--primary);
}

.ed-bloco.ed-titulo {
  text-align: center;
  font-weight: 700;
  text-decoration: underline;
  margin: 4px 0 10px;
}

.ed-bloco.ed-secao {
  font-weight: 700;
  margin-top: 12px;
}

.editor-acoes {
  display: flex;
  gap: 10px;
}

.editor-acoes button {
  margin: 0;
  flex: 1;
}

button.secundario {
  background: #e2e8f0;
  color: var(--text);
}

button.secundario:hover {
  background: #cbd5e1;
}

/* ============================================================
   Responsivo — celular / telas pequenas
   ============================================================ */

/* Em dispositivos de toque (sem hover) os controles de edição
   ficam sempre visíveis, já que não há mouse para passar por cima. */
@media (hover: none) {
  .ed-gutter {
    opacity: 1;
  }
}

@media (max-width: 600px) {
  body {
    padding: 16px 12px;
    gap: 14px;
  }

  .card {
    padding: 20px 16px;
  }

  h1 {
    font-size: 1.35rem;
  }

  .sub {
    font-size: 0.88rem;
  }

  /* 16px impede o zoom automático do Safari/iOS ao focar o campo */
  input,
  select {
    font-size: 16px;
  }

  fieldset {
    padding: 10px 12px 14px;
  }

  /* ---- Painel de preview + editor no mobile ---- */
  .painel {
    padding: 14px 12px;
  }

  .painel-topo {
    flex-direction: column;
    align-items: stretch;
  }

  .painel-acoes {
    width: 100%;
  }

  .painel-acoes .btn-icone {
    flex: 1;
    text-align: center;
  }

  .preview {
    height: 60vh;
    min-height: 340px;
  }

  .editor-blocos {
    padding: 16px 14px;
    max-height: 55vh;
    font-size: 16px; /* legível e sem zoom ao editar no celular */
  }

  .editor-acoes {
    flex-direction: column;
  }
}
