:root {
  --verde: #075e54;
  --verde-claro: #25d366;
  --verde-zap: #128c7e;
  --fundo: #ece5dd;
  --vermelho: #e74c3c;
  --azul: #2980b9;
  --texto: #222;
  --cinza: #667781;
  --branco: #fff;
  --borda: #e0e0e0;
}

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

body {
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--fundo);
  color: var(--texto);
  min-height: 100vh;
}

.topo {
  background: var(--verde);
  color: var(--branco);
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.topo-titulo { font-size: 20px; font-weight: 600; }
.topo-dir { display: flex; align-items: center; gap: 10px; }
.usuario-logado { font-size: 13px; color: #fff; opacity: 0.95; }
.btn-logout { background: rgba(255,255,255,0.2); padding: 6px 14px; font-size: 13px; }
.btn-logout:hover { background: rgba(255,255,255,0.35); }

/* Tela de login */
.login-tela {
  position: fixed; inset: 0; z-index: 100;
  background: linear-gradient(135deg, var(--verde) 0%, var(--verde-zap) 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-tela.escondido { display: none; }
.login-card {
  background: #fff; border-radius: 16px; padding: 32px 26px; width: 100%; max-width: 380px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3); text-align: center;
}
.login-logo { font-size: 52px; }
.login-card h1 { color: var(--verde); font-size: 22px; margin: 6px 0; }
.login-sub { color: var(--cinza); font-size: 14px; margin-bottom: 20px; }
.login-card form { display: flex; flex-direction: column; gap: 10px; }
.login-card input { width: 100%; }
.login-card button { width: 100%; padding: 12px; font-size: 15px; }
.login-erro { color: var(--vermelho); font-size: 13px; margin-top: 10px; min-height: 18px; }
.login-troca { font-size: 13px; color: var(--cinza); margin-top: 6px; }
.login-troca a { color: var(--verde-zap); font-weight: 600; text-decoration: none; }
.login-troca a:hover { text-decoration: underline; }
.login-ajuda { margin-top: 18px; font-size: 12.5px; color: var(--cinza); background: #f3f7f5; padding: 12px; border-radius: 10px; line-height: 1.5; text-align: left; }
.login-ajuda code { background: #dcf8c6; padding: 2px 6px; border-radius: 4px; font-weight: 600; color: #075e54; }

/* Esconde elementos conforme o papel (artesao x admin) */
body.papel-artesao .barra-usuario,
body.papel-artesao .aba[data-aba="conexao"],
body.papel-artesao .aba[data-aba="compartilhar"],
body.papel-artesao .aba[data-aba="chat"],
body.papel-artesao .aba[data-aba="usuarios"],
body.papel-artesao .aba[data-aba="uso"],
body.papel-artesao #status-wpp { display: none !important; }
.status-pill {
  background: rgba(255, 255, 255, 0.2);
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 13px;
}
.status-pill.on { background: var(--verde-claro); }
.status-pill.off { background: var(--vermelho); }

.abas {
  display: flex;
  gap: 4px;
  background: var(--verde-zap);
  padding: 0 10px;
  overflow-x: auto;
  position: sticky;
  top: 52px;
  z-index: 9;
}
.aba {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.8);
  padding: 12px 16px;
  cursor: pointer;
  font-size: 14px;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}
.aba.ativa {
  color: var(--branco);
  border-bottom-color: var(--verde-claro);
  font-weight: 600;
}

/* Barra de selecao de usuario (artesao) */
.barra-usuario {
  display: flex; align-items: center; gap: 10px;
  background: #fff; padding: 10px 20px; border-bottom: 1px solid var(--borda);
  flex-wrap: wrap;
}
.barra-usuario label { font-weight: 600; color: var(--verde); }
.barra-usuario select { flex: 0 1 320px; padding: 8px 10px; border: 1px solid var(--borda); border-radius: 8px; }
.btn-sec { background: var(--azul); padding: 8px 14px; font-size: 13px; }
.btn-sec:hover { background: #1f6391; }

main { padding: 20px; max-width: 1000px; margin: 0 auto; }
.conteudo { display: none; animation: surge 0.2s ease; }
.conteudo.ativa { display: block; }
@keyframes surge { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; } }

h2 { margin-bottom: 14px; color: var(--verde); }
h3 { margin-bottom: 10px; font-size: 15px; color: var(--cinza); }

/* Filtro de periodo */
.filtro-periodo { margin-bottom: 16px; }
.filtro-periodo select {
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--borda); font-size: 14px;
}

/* Lembretes no painel */
.lembretes-box { background: #fff; border-radius: 12px; padding: 14px 16px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); margin-bottom: 18px; border-left: 5px solid #f39c12; }
.lembretes-titulo { font-weight: 700; color: var(--verde); margin-bottom: 8px; }
.lembrete-item { font-size: 14px; padding: 8px 10px; border-radius: 8px; background: #fff8e1; margin-bottom: 6px; line-height: 1.4; }
.lembrete-item.alta { background: #fdecea; }
.lembrete-item:last-child { margin-bottom: 0; }

/* Cards KPI */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.card { background: var(--branco); border-radius: 12px; padding: 18px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); border-left: 5px solid var(--cinza); }
.card.verde { border-left-color: var(--verde-claro); }
.card.vermelho { border-left-color: var(--vermelho); }
.card.azul { border-left-color: var(--azul); }
.card-rotulo { font-size: 13px; color: var(--cinza); text-transform: uppercase; }
.card-valor { font-size: 26px; font-weight: 700; margin: 6px 0; }
.card-sub { font-size: 12px; color: var(--cinza); }

/* Graficos */
.graficos { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grafico-box { background: var(--branco); border-radius: 12px; padding: 16px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
.grafico-box canvas { max-height: 280px; }
@media (max-width: 760px) { .graficos { grid-template-columns: 1fr; } }

/* Formularios */
.form-linha, .form-grade { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.form-grade { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
input, select { padding: 10px; border: 1px solid var(--borda); border-radius: 8px; font-size: 14px; flex: 1; min-width: 120px; }
button {
  background: var(--verde-claro); color: var(--branco); border: none; border-radius: 8px;
  padding: 10px 20px; font-size: 14px; font-weight: 600; cursor: pointer; transition: background 0.15s;
}
button:hover { background: var(--verde-zap); }
.dica { font-size: 13px; color: var(--cinza); margin-bottom: 14px; background: #fff8e1; padding: 10px 12px; border-radius: 8px; }
.aviso-forte { background: #fff3cd; border: 1px solid #ffe08a; border-left: 5px solid #f39c12; border-radius: 8px; padding: 12px 14px; font-size: 14px; line-height: 1.5; margin-bottom: 16px; color: #6b5900; }

/* Tabelas */
table { width: 100%; border-collapse: collapse; background: var(--branco); border-radius: 12px; overflow: hidden; box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
th, td { padding: 12px; text-align: left; font-size: 14px; border-bottom: 1px solid var(--borda); }
th { background: var(--verde); color: var(--branco); font-weight: 600; }
tr:last-child td { border-bottom: none; }
tr.linha-total td { font-weight: 700; background: #f3f7f5; }

/* Barra de progresso (limite MEI) */
.limite-box { background: #fff; border-radius: 12px; padding: 18px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); margin-top: 8px; }
.limite-box .rotulo { font-size: 13px; color: var(--cinza); text-transform: uppercase; }
.limite-box .valores { font-size: 22px; font-weight: 700; margin: 6px 0; }
.limite-box .valores small { font-size: 14px; font-weight: 400; color: var(--cinza); }
.barra-progresso { height: 16px; background: #e6e6e6; border-radius: 10px; overflow: hidden; margin: 8px 0; }
.barra-progresso > div { height: 100%; background: var(--verde-claro); border-radius: 10px; transition: width 0.4s; }
.barra-progresso.alerta > div { background: #f39c12; }
.barra-progresso.perigo > div { background: var(--vermelho); }
.badge-pago { color: #128c7e; font-weight: 600; }
.badge-pendente { color: var(--cinza); }

/* Recibo */
.recibo-controles { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.recibo-controles label { font-size: 13px; color: var(--cinza); }
.recibo { border: 1px solid var(--borda); border-radius: 8px; padding: 22px; color: #222; font-size: 14px; line-height: 1.7; }
.recibo h1 { font-size: 20px; color: var(--verde); margin-bottom: 4px; letter-spacing: 2px; }
.recibo .emitente { font-size: 13px; color: var(--cinza); margin-bottom: 14px; border-bottom: 1px solid var(--borda); padding-bottom: 10px; }
.recibo .valor-destaque { font-size: 18px; font-weight: 700; }
.recibo .assinatura { margin-top: 34px; text-align: center; }
.recibo .assinatura .linha { border-top: 1px solid #333; width: 260px; margin: 0 auto 4px; }
.recibo .rodape { margin-top: 16px; font-size: 11px; color: #999; text-align: center; }
.nfe-resultado { margin-top: 12px; font-size: 13px; line-height: 1.6; }
.nfe-resultado .box { border-radius: 8px; padding: 12px 14px; }
.nfe-resultado .ok { background: #e8f5e9; border: 1px solid #a5d6a7; }
.nfe-resultado .aviso { background: #fff8e1; border: 1px solid #ffe082; }
.nfe-resultado .erro { background: #fdecea; border: 1px solid #f5c6c2; }
.nfe-resultado .chave { font-family: monospace; font-size: 11px; word-break: break-all; }

@media print {
  body * { visibility: hidden !important; }
  #recibo-conteudo, #recibo-conteudo * { visibility: visible !important; }
  #recibo-conteudo { position: absolute; left: 0; top: 0; width: 100%; border: none; }
}
td .btn-mini { background: var(--azul); padding: 5px 10px; font-size: 12px; }
.acoes-cel { white-space: nowrap; }
.btn-editar { background: var(--azul); padding: 5px 9px; font-size: 12px; margin-right: 4px; }
.btn-excluir { background: var(--vermelho); padding: 5px 9px; font-size: 12px; }
.btn-excluir:hover { background: #c0392b; }

/* Modal de edicao */
.modal-fundo {
  display: none; position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.5); align-items: center; justify-content: center; padding: 16px;
}
.modal-fundo.aberto { display: flex; }
.modal-caixa {
  background: #fff; border-radius: 14px; padding: 22px; width: 100%; max-width: 420px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3); max-height: 90vh; overflow-y: auto;
}
.modal-caixa h3 { color: var(--verde); margin-bottom: 14px; }
.modal-campos { display: flex; flex-direction: column; gap: 10px; }
.modal-campos label { display: flex; flex-direction: column; font-size: 13px; color: var(--cinza); gap: 4px; font-weight: 600; }
.modal-campos input, .modal-campos select { font-weight: 400; }
.modal-acoes { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* Passos numerados (conexao) */
.passos { margin: 12px 0 16px 22px; }
.passos li { margin-bottom: 8px; font-size: 14px; line-height: 1.5; }

/* Conexao / QR */
.qr-area { display: flex; justify-content: center; padding: 20px; background: var(--branco); border-radius: 12px; margin: 14px 0; min-height: 120px; align-items: center; }
.qr-area img, .qr-area canvas { border: 8px solid var(--branco); }
.qr-img { width: 260px; height: 260px; background: #fff; border: 8px solid #fff; border-radius: 6px; }

/* Compartilhar */
.campo-rotulo { display: block; font-size: 13px; color: var(--cinza); margin: 14px 0 5px; font-weight: 600; }
.compartilhar-numero { font-size: 18px; font-weight: 700; color: var(--verde); background: #fff; padding: 14px; border-radius: 10px; box-shadow: 0 2px 6px rgba(0,0,0,0.08); }
.qr-compartilhar { margin-top: 16px; text-align: center; }
#link-convite { font-size: 13px; color: var(--azul); }

/* Chat de teste */
.chat-janela {
  background: var(--fundo);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40'%3E%3Ccircle cx='20' cy='20' r='1' fill='%23d0c8bf'/%3E%3C/svg%3E");
  border-radius: 12px; padding: 16px; height: 360px; overflow-y: auto; margin-bottom: 12px;
  display: flex; flex-direction: column; gap: 8px;
}
.balao { max-width: 80%; padding: 9px 13px; border-radius: 10px; font-size: 14px; white-space: pre-wrap; line-height: 1.4; box-shadow: 0 1px 1px rgba(0,0,0,0.1); }
.balao.eu { align-self: flex-end; background: #dcf8c6; }
.balao.bot { align-self: flex-start; background: var(--branco); }
.balao b { font-weight: 700; }

/* ===== Marketing (guia editável) ===== */
textarea { padding: 10px; border: 1px solid var(--borda); border-radius: 8px; font-size: 14px; width: 100%; font-family: inherit; resize: vertical; }
.modal-campos textarea { font-weight: 400; }
.form-mkt { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 16px; align-items: end; }
.form-mkt > label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--cinza); font-weight: 600; }
.form-mkt input, .form-mkt select { font-weight: 400; }
.form-mkt .fase2 { color: var(--azul); font-weight: 600; }
.mkt-apps { grid-column: 1 / -1; border: 1px solid var(--borda); border-radius: 8px; padding: 8px 12px; display: flex; flex-wrap: wrap; gap: 14px; }
.mkt-apps legend { font-size: 13px; color: var(--cinza); font-weight: 600; padding: 0 6px; }
.mkt-apps .chk { display: flex; flex-direction: row; align-items: center; gap: 6px; font-weight: 400; color: var(--texto); }
.mkt-apps .chk input { flex: 0; min-width: auto; }
.form-mkt .form-acoes { grid-column: 1 / -1; display: flex; gap: 10px; }

/* Botão de exportar por guia (canto superior direito da seção) */
.btn-export-aba { float: right; margin: 0 0 10px 10px; }

/* ===== Manual do usuário (aba Ajuda) ===== */
.manual { max-width: 820px; line-height: 1.6; }
.manual > .dica { margin-bottom: 16px; }
.manual details { background: var(--branco); border: 1px solid var(--borda); border-radius: 10px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
.manual summary { cursor: pointer; padding: 14px 16px; font-weight: 600; color: var(--verde); font-size: 15px; list-style: none; user-select: none; }
.manual summary::-webkit-details-marker { display: none; }
.manual summary::before { content: '▸'; color: var(--verde-zap); margin-right: 8px; }
.manual details[open] summary::before { content: '▾'; }
.manual details > *:not(summary) { padding: 0 16px 14px; margin-top: 0; }
.manual details ul { margin: 0 0 0 20px; }
.manual details li { margin-bottom: 6px; }
.manual code { background: #dcf8c6; color: #075e54; padding: 2px 7px; border-radius: 5px; font-weight: 600; font-size: 13px; white-space: normal; }
.manual-tab { margin-top: 4px; }
.manual-tab td { vertical-align: top; }
