:root {
  color-scheme: light;
  --bg: #f0f3f8;
  --card: #ffffff;
  --ink: #1c2430;
  --muted: #5f6c80;
  --primary: #0a4fd4;
  --primary-dark: #083a9e;
  --accent: #0d7c5c;
  --line: #dbe2ef;
  --pro-badge: #e8f4ef;
  --pro-badge-ink: #0d5c44;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.app {
  max-width: 820px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

.topo h1 {
  margin: 0;
  font-size: 1.55rem;
}

.topo p {
  margin: 4px 0 12px;
  color: var(--muted);
}

.topo {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  padding-bottom: 4px;
  margin-bottom: 4px;
}

.badge-pro {
  display: inline-block;
  background: var(--pro-badge);
  color: var(--pro-badge-ink);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 8px;
}

.abas,
.sub-abas {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.aba,
.sub-aba {
  flex: 1;
  border: 1px solid var(--line);
  background: #e9eef8;
  color: #2f4a72;
  border-radius: 10px;
  padding: 12px 10px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.92rem;
  min-height: 44px;
  -webkit-tap-highlight-color: transparent;
}

.aba-ativa,
.sub-aba-ativa {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.sub-abas {
  flex-direction: column;
}

@media (min-width: 560px) {
  .sub-abas {
    flex-direction: row;
  }
}

.painel-oculto[hidden] {
  display: none !important;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
}

.card h2,
.subtitulo {
  margin: 0 0 10px;
  font-size: 1.05rem;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

label {
  display: block;
  margin-bottom: 10px;
}

label span {
  display: block;
  margin-bottom: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  font-size: 16px;
  font-family: inherit;
}

textarea {
  resize: vertical;
  min-height: 72px;
}

input:focus,
textarea:focus {
  outline: 2px solid #c9dcff;
  border-color: #9cc0ff;
}

.acoes {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.acoes-inicio {
  justify-content: flex-start;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 12px 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  font-size: 0.95rem;
  -webkit-tap-highlight-color: transparent;
}

.btn-pequeno {
  padding: 8px 12px;
  font-size: 0.88rem;
}

.primario {
  background: var(--primary);
  color: #ffffff;
}

.primario:hover {
  background: var(--primary-dark);
}

.secundario {
  background: #e9eef8;
  color: #2f4a72;
}

.status {
  color: var(--muted);
}

.aviso {
  font-size: 0.85rem;
  color: var(--muted);
  line-height: 1.45;
  margin: 0 0 10px;
}

.aviso a {
  color: var(--primary);
}

.item h3 {
  margin: 0 0 6px;
  font-size: 1.02rem;
}

.meta {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 0.92rem;
}

.texto {
  margin: 8px 0;
  line-height: 1.45;
  font-size: 0.93rem;
}

.botoes-card {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.lista-compacta .item-selecionavel {
  border-color: #c5d4ef;
}

.item-selecionavel .selecionar,
.item-selecionavel .selecionar-reg {
  margin-top: 8px;
}

.ref-selecionada {
  background: #f7fafc;
  border: 1px solid #c5d4ef;
  border-radius: 10px;
  padding: 12px;
  font-size: 0.93rem;
  line-height: 1.45;
}

.resultado-elaboracao {
  border-color: var(--accent);
  border-width: 2px;
}

.resultado-topo {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.resultado-topo h2 {
  margin: 0;
}

.teor-texto {
  margin: 12px 0;
  line-height: 1.55;
  font-size: 0.93rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: min(65vh, 520px);
  overflow-y: auto;
}

dialog {
  border: 0;
  border-radius: 14px;
  padding: 0;
  width: min(860px, 96vw);
  max-height: 92vh;
  margin: auto;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.detalhe-card {
  margin: 0;
  border: 0;
}

.reg-texto {
  max-height: 160px;
  overflow: hidden;
}

@media (max-width: 560px) {
  .grid {
    grid-template-columns: 1fr;
  }

  .topo h1 {
    font-size: 1.35rem;
  }

  .abas {
    position: sticky;
    top: 0;
    z-index: 9;
    background: var(--bg);
    padding: 4px 0 8px;
  }

  .acoes {
    flex-direction: column;
  }

  .acoes button {
    width: 100%;
  }

  .acoes-inicio {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .acoes-inicio button {
    flex: 1;
    min-width: 140px;
  }

  .resultado-topo {
    flex-direction: column;
    align-items: stretch;
  }

  .resultado-topo button {
    width: 100%;
  }

  .botoes-card {
    flex-direction: column;
  }

  .botoes-card button {
    width: 100%;
  }

  .item-selecionavel .selecionar,
  .item-selecionavel .selecionar-reg {
    width: 100%;
  }

  .teor-texto {
    max-height: min(55vh, 420px);
  }
}
