/* ═══════════════════════════════════════════════════════════════════
   Email Marketing - app interno do painel RR.
   Layout split: formulario esquerda + preview direita.
   ═══════════════════════════════════════════════════════════════════ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background-color: #0a0a0b;
  color: #ededeb;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Layout principal ──────────────────────────────────────────── */
.em-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 0;
  min-height: calc(100vh - 76px);
}

/* ─── Painel esquerdo: formulario ───────────────────────────────── */
.em-form-pane {
  background: #0d0d10;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  padding: 36px 32px;
  overflow-y: auto;
  max-height: calc(100vh - 76px);
}

.em-pane-head {
  margin-bottom: 28px;
}
.em-eyebrow {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #c9a24f;
  margin-bottom: 10px;
}
.em-title {
  margin: 0;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ededeb;
}
.em-subtitle {
  margin: 8px 0 0 0;
  font-size: 13px;
  line-height: 20px;
  color: rgba(237, 237, 235, 0.55);
}

/* ─── Form ─────────────────────────────────────────────────────── */
/* O formulário tradicional vive escondido atrás do botão "Modelo
   simplificado"; quando revelado, aparece como um card. */
.em-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 14px;
  padding: 20px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
}
.em-form[hidden] { display: none; }

/* ─── Toggle Com IA / Sem IA ───────────────────────────────────── */
.em-mode-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
}
.em-mode-option {
  position: relative;
  cursor: pointer;
}
.em-mode-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.em-mode-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: rgba(237, 237, 235, 0.55);
  background: transparent;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  user-select: none;
}
.em-mode-option:hover .em-mode-label {
  color: rgba(237, 237, 235, 0.8);
}
.em-mode-option input:checked + .em-mode-label {
  background: linear-gradient(135deg, rgba(201, 162, 79, 0.18), rgba(201, 162, 79, 0.08));
  color: #c9a24f;
  box-shadow: 0 0 0 1px rgba(201, 162, 79, 0.35);
}
.em-mode-icon {
  display: inline-flex;
  align-items: center;
}

/* ─── Linha de botões de ação (Editor / Extrair da Web) ────────────
   Ficam logo abaixo do toggle Com IA / Sem IA. NÃO são radios: cada
   botão dispara uma ação (abre o editor de blocos ou o diálogo de
   extração). Estilo: cartões clicáveis coerentes com o tema escuro. */
.em-action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.em-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: rgba(237, 237, 235, 0.8);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}
.em-action-btn:hover {
  background: rgba(201, 162, 79, 0.08);
  border-color: rgba(201, 162, 79, 0.40);
  color: #ededeb;
  transform: translateY(-1px);
}
.em-action-btn:active {
  transform: translateY(0);
}
.em-action-icon {
  display: inline-flex;
  align-items: center;
  color: #c9a24f;
}

/* ─── Botão "Modelo simplificado" ──────────────────────────────────
   Fica abaixo dos 2 botões de ação e expande/recolhe o card do
   formulário tradicional. */
.em-simple-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-top: 8px;
  padding: 11px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: rgba(237, 237, 235, 0.8);
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.em-simple-toggle:hover {
  background: rgba(201, 162, 79, 0.08);
  border-color: rgba(201, 162, 79, 0.40);
  color: #ededeb;
}
.em-simple-chevron {
  display: inline-flex;
  color: #c9a24f;
  transition: transform 0.18s ease;
}
/* A seta gira quando o card esta aberto. */
.em-simple-toggle[aria-expanded="true"] .em-simple-chevron {
  transform: rotate(180deg);
}

/* ─── Diálogo "Extrair da Web" ─────────────────────────────────────
   Reaproveita as classes do modal Resend (.em-modal, .em-modal-card).
   Estilos abaixo são só dos elementos exclusivos da extração. */
.em-extract-intro {
  margin: 0;
  font-size: 12.5px;
  line-height: 19px;
  color: rgba(237, 237, 235, 0.55);
}
.em-extract-check {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  font-size: 12.5px;
  line-height: 18px;
  color: rgba(237, 237, 235, 0.78);
  cursor: pointer;
}
.em-extract-check input {
  width: 16px;
  height: 16px;
  margin-top: 1px;
  accent-color: #c9a24f;
  cursor: pointer;
  flex-shrink: 0;
}
.em-extract-error {
  margin: 0;
  padding: 10px 13px;
  background: rgba(217, 124, 124, 0.08);
  border: 1px solid rgba(217, 124, 124, 0.35);
  border-radius: 8px;
  font-size: 12px;
  line-height: 18px;
  color: #d97c7c;
}
/* Botão de extrair com spinner enquanto a Function busca a página. */
.em-extract-confirm-loading .em-btn-label { opacity: 0.6; }
.em-extract-confirm-loading .em-btn-spinner { display: inline-block; }

/* Esconde campos do modo oposto */
.em-field[hidden] { display: none !important; }

.em-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.em-field label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(237, 237, 235, 0.65);
}
.em-field input,
.em-field select,
.em-field textarea {
  width: 100%;
  padding: 11px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  color: #ededeb;
  font-family: inherit;
  font-size: 14px;
  line-height: 20px;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}
.em-field input::placeholder,
.em-field textarea::placeholder {
  color: rgba(237, 237, 235, 0.30);
}
.em-field input:focus,
.em-field select:focus,
.em-field textarea:focus {
  border-color: rgba(201, 162, 79, 0.55);
  background: rgba(201, 162, 79, 0.04);
}
.em-field textarea {
  resize: vertical;
  min-height: 140px;
  font-family: inherit;
}
.em-field select {
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'><path d='M1 1l5 5 5-5' stroke='%23a3a3a8' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 38px;
}
.em-field select option,
.em-field select optgroup {
  background: #15151a;
  color: #ededeb;
}
.em-hint {
  font-size: 11px;
  color: rgba(237, 237, 235, 0.40);
  line-height: 16px;
}

/* ─── Botao primario ───────────────────────────────────────────── */
.em-btn-primary {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 14px 20px;
  background: linear-gradient(135deg, #c9a24f 0%, #b58a3f 100%);
  border: none;
  border-radius: 10px;
  color: #0a0a0b;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.15s;
  margin-top: 4px;
  overflow: hidden;
}
.em-btn-primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 8px 24px -8px rgba(201, 162, 79, 0.55);
}
.em-btn-primary:active:not(:disabled) {
  transform: translateY(0);
}
.em-btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.em-btn-primary[data-loading="true"] .em-btn-label {
  opacity: 0.6;
}
.em-btn-spinner {
  display: none;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(10, 10, 11, 0.25);
  border-top-color: #0a0a0b;
  border-radius: 50%;
  animation: em-spin 0.8s linear infinite;
}
.em-btn-primary[data-loading="true"] .em-btn-spinner {
  display: inline-block;
}
@keyframes em-spin {
  to { transform: rotate(360deg); }
}

.em-status {
  margin: 4px 0 0 0;
  font-size: 12px;
  line-height: 18px;
  min-height: 18px;
  color: rgba(237, 237, 235, 0.55);
}
.em-status[data-state="error"] { color: #d97c7c; }
.em-status[data-state="ok"]    { color: #6fc784; }

/* ─── Painel direito: preview ──────────────────────────────────── */
.em-preview-pane {
  background: #050507;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.em-preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: rgba(13, 13, 16, 0.6);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  backdrop-filter: blur(8px);
  /* position+z-index garantem que dropdowns abertos na barra (ex:
     "Perfil de envio") fiquem ACIMA do iframe do preview, que e um
     irmao posterior no DOM e por isso pintaria por cima. */
  position: relative;
  z-index: 5;
}
.em-preview-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.em-preview-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #c9a24f;
}
.em-preview-info {
  font-size: 12px;
  color: rgba(237, 237, 235, 0.50);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.em-preview-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.em-btn-secondary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 8px;
  color: rgba(237, 237, 235, 0.85);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.em-btn-secondary:hover:not(:disabled) {
  background: rgba(201, 162, 79, 0.08);
  border-color: rgba(201, 162, 79, 0.40);
  color: #ededeb;
}
.em-btn-secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.em-btn-secondary[data-copied="true"] {
  border-color: rgba(111, 199, 132, 0.55);
  color: #6fc784;
}

/* Botao ghost (sem fundo, para acoes secundarias tipo Historico) */
.em-btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 14px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  color: rgba(237, 237, 235, 0.6);
  font-family: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.em-btn-ghost:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.03);
  border-color: rgba(255, 255, 255, 0.12);
  color: #ededeb;
}
/* Ghost desabilitado (ex: "Edição avançada" sem e-mail no preview):
   visivelmente inativo e sem resposta ao hover. O :hover acima é
   escopado com :not(:disabled) justamente para o botão desabilitado
   nao "acender" e parecer clicavel. */
.em-btn-ghost:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Dropdown "Perfil de envio" ────────────────────────────────────
   Seletor do membro do time que assina o e-mail. Fica no inicio da
   barra de acoes do preview (esquerda dos botoes Templates etc.). */
.em-sender-select {
  position: relative;
  flex-shrink: 0;
}
/* Botao do dropdown: reaproveita o visual ghost, mas com duas linhas
   (rotulo discreto em cima, nome do perfil em destaque embaixo). */
.em-sender-btn {
  padding: 6px 11px;
}
.em-sender-btn-icon {
  display: inline-flex;
  color: rgba(201, 162, 79, 0.85);
}
.em-sender-btn-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  line-height: 1.15;
  text-align: left;
}
.em-sender-btn-label {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: rgba(237, 237, 235, 0.40);
}
.em-sender-btn-name {
  font-size: 12px;
  font-weight: 700;
  color: rgba(237, 237, 235, 0.88);
}
.em-sender-caret {
  display: inline-flex;
  color: rgba(237, 237, 235, 0.45);
  transition: transform 0.15s;
}
.em-sender-btn[aria-expanded="true"] .em-sender-caret {
  transform: rotate(180deg);
}

/* Menu suspenso do dropdown: lista de perfis. */
.em-sender-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 60;
  min-width: 230px;
  padding: 6px;
  background: #1a1a18;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 10px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  display: none;
}
.em-sender-menu[data-open="true"] {
  display: block;
}

/* Cada item do menu: avatar + nome do perfil. */
.em-sender-opt {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 9px;
  background: transparent;
  border: 0;
  border-radius: 7px;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  transition: background 0.12s;
}
.em-sender-opt:hover {
  background: rgba(255, 255, 255, 0.04);
}
.em-sender-opt[aria-checked="true"] {
  background: rgba(201, 162, 79, 0.10);
}
.em-sender-opt-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  border: 1px solid rgba(201, 162, 79, 0.45);
  background: #fff;
}
.em-sender-opt-name {
  flex: 1;
  font-size: 13px;
  font-weight: 600;
  color: rgba(237, 237, 235, 0.90);
}
/* Marca de selecionado (check) a direita do item ativo. */
.em-sender-opt-check {
  display: none;
  color: #c9a24f;
}
.em-sender-opt[aria-checked="true"] .em-sender-opt-check {
  display: inline-flex;
}

/* Variante "perigo" do botao ghost: usada no "Descartar e-mail".
   Mantem o ghost neutro em repouso (para nao competir com o CTA
   Resend) e revela o tom de alerta vermelho apenas no hover. */
.em-btn-ghost-danger:hover:not(:disabled) {
  background: rgba(217, 124, 124, 0.06);
  border-color: rgba(217, 124, 124, 0.45);
  color: #d97c7c;
}

/* Botao Resend: destaque dourado pra acao "envio" */
.em-btn-resend {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: linear-gradient(135deg, rgba(201, 162, 79, 0.18), rgba(201, 162, 79, 0.10));
  border: 1px solid rgba(201, 162, 79, 0.45);
  border-radius: 8px;
  color: #c9a24f;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}
.em-btn-resend:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(201, 162, 79, 0.30), rgba(201, 162, 79, 0.18));
  border-color: rgba(201, 162, 79, 0.75);
  color: #e0bd6e;
  transform: translateY(-1px);
}
.em-btn-resend:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ─── Modal Resend ─────────────────────────────────────────────── */
.em-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  animation: em-modal-fade-in 0.18s ease-out;
}
@keyframes em-modal-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.em-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 7, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.em-modal-card {
  position: relative;
  width: 100%;
  max-width: 460px;
  background: #0d0d10;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  box-shadow:
    0 32px 96px -16px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(201, 162, 79, 0.06);
  overflow: hidden;
  animation: em-modal-pop 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes em-modal-pop {
  from { transform: translateY(8px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0)   scale(1);    opacity: 1; }
}

.em-modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.em-modal-eyebrow {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: #c9a24f;
  margin-bottom: 4px;
}
.em-modal-title {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #ededeb;
}
.em-modal-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: rgba(237, 237, 235, 0.6);
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
  flex-shrink: 0;
}
.em-modal-close:hover {
  background: rgba(255, 255, 255, 0.04);
  color: #ededeb;
  border-color: rgba(255, 255, 255, 0.15);
}

.em-modal-body {
  padding: 22px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.em-modal-body[data-state="sending"],
.em-modal-body[data-state="success"],
.em-modal-body[data-state="error"] {
  align-items: center;
  text-align: center;
  padding: 32px 24px 28px;
}

.em-modal-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
  width: 100%;
}
.em-btn-primary-modal {
  margin-top: 0 !important;
}

/* Botao "Descartar" do modal de confirmacao: acao destrutiva, tom
   vermelho. Mesma estrutura dos botoes secundarios do modal. */
.em-btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: linear-gradient(135deg, rgba(217, 124, 124, 0.20), rgba(217, 124, 124, 0.10));
  border: 1px solid rgba(217, 124, 124, 0.50);
  border-radius: 8px;
  color: #e58f8f;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.15s;
}
.em-btn-danger:hover:not(:disabled) {
  background: linear-gradient(135deg, rgba(217, 124, 124, 0.32), rgba(217, 124, 124, 0.18));
  border-color: rgba(217, 124, 124, 0.80);
  color: #f0a6a6;
  transform: translateY(-1px);
}
.em-btn-danger:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Texto de corpo do modal de descarte. */
.em-discard-text {
  margin: 0;
  font-size: 14px;
  line-height: 1.55;
  color: rgba(237, 237, 235, 0.78);
}

.em-resend-from-wrap label {
  margin-bottom: 4px;
}
.em-resend-from {
  padding: 11px 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  font-size: 13px;
  color: rgba(237, 237, 235, 0.7);
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}
.em-resend-from[data-missing="true"] {
  border-color: rgba(217, 124, 124, 0.45);
  color: #d97c7c;
}

.em-resend-warning {
  margin: 0;
  padding: 11px 14px;
  background: rgba(217, 124, 124, 0.08);
  border: 1px solid rgba(217, 124, 124, 0.35);
  border-radius: 8px;
  font-size: 12px;
  line-height: 18px;
  color: #d97c7c;
}

/* Checkbox "Enviar e-mail individualmente" no modal de envio.
   Estilo discreto pra nao competir com os campos principais. */
.em-checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 8px;
  font-size: 13px;
  color: rgba(237, 237, 235, 0.78);
  cursor: pointer;
  user-select: none;
  margin-bottom: 0;
  transition: border-color 0.15s, background 0.15s;
}
.em-checkbox-row:hover {
  border-color: rgba(201, 162, 79, 0.30);
  background: rgba(201, 162, 79, 0.04);
}
.em-checkbox-row input[type="checkbox"] {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: #c9a24f;
  cursor: pointer;
}
/* Hint do textarea de e-mails em estado warning (e-mails invalidos). */
#em-resend-emails-hint[data-state="warn"],
#em-resend-ignored-hint[data-state="warn"] {
  color: #d97c7c;
}

/* Checkbox "lista de ignorados" desabilitado quando o modo individual
   esta ativo (lista de ignorados so faz sentido no modo segmento). */
.em-checkbox-row.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

/* Toast de confirmacao quando um envio comeca em segundo plano.
   Aparece no canto inferior direito, some sozinho em ~8s. */
.em-send-toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  max-width: 360px;
  background: #15151a;
  border: 1px solid rgba(201, 162, 79, 0.45);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  color: #ededeb;
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  animation: em-send-toast-in 0.25s ease-out;
}
.em-send-toast > svg {
  color: #c9a24f;
  flex-shrink: 0;
  margin-top: 2px;
}
.em-send-toast-text {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
}
.em-send-toast-text strong {
  font-size: 13px;
  letter-spacing: 0.005em;
}
.em-send-toast-text span {
  font-size: 12px;
  color: rgba(237, 237, 235, 0.6);
}
.em-send-toast-close {
  background: none;
  border: 0;
  color: rgba(237, 237, 235, 0.45);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 0 4px;
  margin-left: 4px;
  margin-top: -2px;
  transition: color 0.15s;
}
.em-send-toast-close:hover { color: #ededeb; }
.em-send-toast-out {
  animation: em-send-toast-out 1s ease-in forwards;
}
@keyframes em-send-toast-in {
  from { transform: translateY(20px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes em-send-toast-out {
  from { transform: translateY(0); opacity: 1; }
  to   { transform: translateY(20px); opacity: 0; }
}
@media (max-width: 720px) {
  .em-send-toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }
}

/* Estado sending */
.em-resend-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 320px;
  /* Centraliza o bloco inteiro de animacao no corpo do modal: o
     max-width sozinho deixava o bloco encostado a esquerda. */
  margin: 0 auto;
}
.em-resend-loading-icon {
  width: 84px;
  height: 84px;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(201, 162, 79, 0.12), rgba(201, 162, 79, 0.04));
  border: 1px solid rgba(201, 162, 79, 0.30);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c9a24f;
  box-shadow: 0 0 28px rgba(201, 162, 79, 0.18);
  animation: em-resend-send-fly 1.6s ease-in-out infinite;
}
@keyframes em-resend-send-fly {
  0%, 100% { transform: translate(0, 0) rotate(0); }
  50%      { transform: translate(2px, -3px) rotate(-3deg); }
}
.em-resend-loading-title {
  margin: 6px 0 0 0;
  font-size: 17px;
  font-weight: 700;
  color: #ededeb;
}
.em-resend-loading-sub {
  margin: 0;
  font-size: 13px;
  line-height: 20px;
  color: rgba(237, 237, 235, 0.55);
}

/* Linha de progresso "X de Y enviados" durante o acompanhamento. */
.em-resend-loading-progress {
  margin: 6px 0 0;
  font-size: 13px;
  font-weight: 600;
  line-height: 18px;
  color: #c9a24f;
  font-variant-numeric: tabular-nums;
}
.em-resend-loading-progress:empty {
  display: none;
}

/* Estado success */
.em-resend-success-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(111, 199, 132, 0.12);
  border: 1px solid rgba(111, 199, 132, 0.45);
  color: #6fc784;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: em-resend-success-pop 0.45s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes em-resend-success-pop {
  from { transform: scale(0.5); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}
.em-resend-success-title {
  margin: 4px 0 0 0;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #ededeb;
}
.em-resend-success-sub {
  margin: 0;
  font-size: 13px;
  line-height: 20px;
  color: rgba(237, 237, 235, 0.65);
  max-width: 320px;
}
.em-resend-success-meta {
  margin: 0;
  font-size: 11px;
  color: rgba(237, 237, 235, 0.40);
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

/* Estado error */
.em-resend-error-icon {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(217, 124, 124, 0.10);
  border: 1px solid rgba(217, 124, 124, 0.45);
  color: #d97c7c;
  display: flex;
  align-items: center;
  justify-content: center;
}
.em-resend-error-title {
  margin: 4px 0 0 0;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
  color: #ededeb;
}
.em-resend-error-sub {
  margin: 0;
  font-size: 13px;
  line-height: 20px;
  color: #d97c7c;
  max-width: 360px;
  /* Mensagens de erro podem trazer URLs ou tokens longos: quebra dentro
     da palavra para não estourar a largura do card no celular. */
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* ─── Dialog: Historico de envios (HTML5 <dialog>) ─────────────── */
.em-history-dialog {
  border: none;
  padding: 0;
  background: transparent;
  max-width: 720px;
  width: 92%;
  max-height: 86vh;
  border-radius: 16px;
  color: #ededeb;
}
.em-history-dialog::backdrop {
  background: rgba(5, 5, 7, 0.78);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.em-history-card {
  background: #0d0d10;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 16px;
  box-shadow:
    0 32px 96px -16px rgba(0, 0, 0, 0.8),
    0 0 0 1px rgba(201, 162, 79, 0.06);
  display: flex;
  flex-direction: column;
  max-height: 86vh;
  overflow: hidden;
}
.em-history-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 18px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}
.em-history-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 24px;
}

.em-history-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 20px;
  font-size: 13px;
  color: rgba(237, 237, 235, 0.55);
}
.em-history-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(201, 162, 79, 0.22);
  border-top-color: #c9a24f;
  border-radius: 50%;
  animation: em-spin 0.8s linear infinite;
}

.em-history-empty,
.em-history-error {
  padding: 40px 24px;
  text-align: center;
  color: rgba(237, 237, 235, 0.45);
  font-size: 13px;
}
.em-history-error { color: #d97c7c; }

.em-history-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.em-history-item {
  position: relative;
  display: grid;
  /* status fica na esquerda alinhado ao topo do card; o restante vai
     pra .em-history-main, que empilha subject -> meta -> stats -> when. */
  grid-template-columns: auto 1fr;
  gap: 12px;
  align-items: start;
  padding: 14px 16px;
  background: rgba(255, 255, 255, 0.025);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 10px;
  transition: background 0.15s, border-color 0.15s;
}
.em-history-item:hover {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.10);
}

.em-history-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.10em;
  text-transform: uppercase;
  white-space: nowrap;
}
.em-history-status[data-status="sent"] {
  background: rgba(111, 199, 132, 0.14);
  color: #6fc784;
  border: 1px solid rgba(111, 199, 132, 0.30);
}
.em-history-status[data-status="failed"] {
  background: rgba(217, 124, 124, 0.12);
  color: #d97c7c;
  border: 1px solid rgba(217, 124, 124, 0.30);
}
.em-history-status[data-status="pending"] {
  background: rgba(201, 162, 79, 0.14);
  color: #c9a24f;
  border: 1px solid rgba(201, 162, 79, 0.35);
}

/* Envio em andamento: borda dourada discreta + barra de progresso. */
.em-history-item-pending {
  border-color: rgba(201, 162, 79, 0.25);
  background: rgba(201, 162, 79, 0.04);
}
.em-history-item-pending:hover {
  background: rgba(201, 162, 79, 0.06);
}
.em-history-progress {
  height: 4px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}
.em-history-progress-fill {
  height: 100%;
  background: #c9a24f;
  transition: width 0.4s ease;
}
.em-history-cancel {
  position: absolute;
  top: 8px;
  right: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(220, 38, 38, 0.10);
  border: 1px solid rgba(239, 68, 68, 0.35);
  border-radius: 8px;
  color: #ef4444;
  cursor: pointer;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: background 0.16s, border-color 0.16s;
  z-index: 1;
}
.em-history-cancel:hover {
  background: rgba(220, 38, 38, 0.18);
  border-color: rgba(239, 68, 68, 0.60);
}

.em-history-main {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}
.em-history-subject {
  font-size: 13.5px;
  font-weight: 700;
  color: #ededeb;
  letter-spacing: -0.005em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.em-history-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: rgba(237, 237, 235, 0.45);
  flex-wrap: wrap;
}
.em-history-meta-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(237, 237, 235, 0.25);
  display: inline-block;
  flex-shrink: 0;
}
.em-history-meta-tag {
  padding: 1px 7px;
  background: rgba(201, 162, 79, 0.08);
  border: 1px solid rgba(201, 162, 79, 0.20);
  border-radius: 4px;
  color: #c9a24f;
  font-weight: 600;
  text-transform: lowercase;
  /* O tag pode ser um identificador longo sem espaços (slug de campanha):
     limita à largura disponível e quebra dentro da palavra. */
  max-width: 100%;
  overflow-wrap: anywhere;
  word-break: break-word;
}

/* Rodape do card: data/hora de envio. Antes era 3a coluna do grid
   centralizada vertical; agora vive dentro de .em-history-main como
   ultima linha pra dar contexto sem competir com o titulo. */
.em-history-when {
  display: block;
  margin-top: 6px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  font-size: 11px;
  color: rgba(237, 237, 235, 0.40);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Lixeira flutuante no canto superior direito do item.
   Ficar dentro do grid mexia no layout do "when" (data). Posicionando
   absolute, o botao paira sobre o card sem reservar espaco -- aparece
   so no hover (desktop) ou sempre (touch). Hit area 32x32. */
.em-history-del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  padding: 0;
  background: rgba(20, 20, 22, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: rgba(237, 237, 235, 0.55);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: translateY(-2px);
  transition:
    opacity 0.16s ease,
    transform 0.16s ease,
    background 0.16s ease,
    border-color 0.16s ease,
    color 0.16s ease;
  z-index: 1;
}
.em-history-item:hover .em-history-del,
.em-history-del:focus-visible {
  opacity: 1;
  transform: translateY(0);
}
.em-history-del:hover {
  background: rgba(220, 38, 38, 0.18);
  border-color: rgba(239, 68, 68, 0.45);
  color: #ef4444;
}
.em-history-del:focus-visible {
  outline: 2px solid rgba(201, 162, 79, 0.55);
  outline-offset: 2px;
}
@media (hover: none) {
  .em-history-del {
    opacity: 0.85;
    transform: translateY(0);
  }
}

/* Relatório de entrega (Resend) dentro de cada item do histórico. */
.em-history-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 3px;
}
.em-history-stat {
  display: inline-flex;
  align-items: baseline;
  gap: 4px;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  font-size: 10.5px;
  color: rgba(237, 237, 235, 0.5);
}
.em-history-stat strong {
  font-weight: 700;
  color: #ededeb;
  font-size: 11px;
}
.em-history-stat em {
  font-style: normal;
  font-weight: 600;
  color: #c9a24f;
  font-size: 10px;
}
.em-history-stats-empty {
  color: rgba(237, 237, 235, 0.32);
  font-size: 10.5px;
  font-style: italic;
}

.em-history-error-detail {
  grid-column: 1 / -1;
  margin: 8px 0 0;
  padding: 8px 10px;
  background: rgba(217, 124, 124, 0.06);
  border: 1px solid rgba(217, 124, 124, 0.25);
  border-radius: 6px;
  font-size: 11px;
  color: #d97c7c;
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  word-break: break-word;
}

/* ─── Templates: row de salvar atual ───────────────────────────── */
.em-templates-save {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
}
.em-templates-save input {
  /* `min-width: 0` deixa o campo encolher dentro do flex: sem isto, o
     conteúdo/placeholder define uma largura mínima e empurra o botão
     "Salvar email atual" para fora do diálogo no celular. */
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #ededeb;
  font-family: inherit;
  font-size: 13px;
  outline: none;
}
.em-templates-save input:focus { border-color: rgba(201, 162, 79, 0.55); }
.em-templates-save button { flex-shrink: 0; }
.em-templates-save-hint {
  margin: 0 0 18px 0;
  font-size: 11px;
  color: rgba(237, 237, 235, 0.40);
}
.em-templates-save-hint[data-state="ready"] { color: rgba(111, 199, 132, 0.75); }
.em-templates-save-hint[data-state="error"] { color: #d97c7c; }

/* ─── Card de template salvo (visual elegante) ─────────────────── */
.em-template-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0.01));
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  list-style: none;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.em-template-card:hover {
  border-color: rgba(201, 162, 79, 0.32);
  background: linear-gradient(180deg, rgba(201, 162, 79, 0.04), rgba(255, 255, 255, 0.01));
}

.em-template-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.em-template-card-name {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  color: #ededeb;
  letter-spacing: -0.005em;
  line-height: 1.3;
  word-break: break-word;
  min-width: 0;
  flex: 1;
}
.em-template-card-badges {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* Origem (Com IA / Sem IA) - pill */
.em-templates-origin {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}
.em-templates-origin[data-origin="ai"] {
  background: linear-gradient(135deg, rgba(201, 162, 79, 0.20), rgba(201, 162, 79, 0.10));
  color: #c9a24f;
  border: 1px solid rgba(201, 162, 79, 0.40);
}
.em-templates-origin[data-origin="template"] {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.18), rgba(99, 102, 241, 0.08));
  color: #a5a8f0;
  border: 1px solid rgba(99, 102, 241, 0.40);
}

.em-template-card-type {
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.10);
  color: rgba(237, 237, 235, 0.65);
}

/* Subject original do email */
.em-template-card-subject {
  margin: 0;
  font-size: 12.5px;
  line-height: 18px;
  color: rgba(237, 237, 235, 0.55);
  font-style: italic;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Footer: autor + data | actions */
.em-template-card-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  flex-wrap: wrap;
}

.em-template-card-meta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  color: rgba(237, 237, 235, 0.45);
}
.em-template-card-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(237, 237, 235, 0.25);
  display: inline-block;
}
.em-template-card-date {
  font-variant-numeric: tabular-nums;
  color: rgba(237, 237, 235, 0.50);
}

/* Sender pill: avatar + nome */
.em-template-card-sender {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: rgba(237, 237, 235, 0.75);
  font-weight: 600;
}
.em-template-card-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #c9a24f 0%, #b58a3f 100%);
  color: #0a0a0b;
  font-weight: 800;
  font-size: 9px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}
.em-template-card-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.em-template-card-avatar-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #c9a24f 0%, #b58a3f 100%);
  color: #0a0a0b;
  font-weight: 800;
}
.em-template-card-name-text {
  font-size: 11.5px;
  color: rgba(237, 237, 235, 0.75);
}

/* Ações no template item */
.em-templates-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.em-templates-actions button {
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 7px;
  color: rgba(237, 237, 235, 0.75);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  transition: all 0.15s;
}
.em-templates-actions button:hover {
  background: rgba(255, 255, 255, 0.03);
  color: #ededeb;
  border-color: rgba(255, 255, 255, 0.20);
}
.em-templates-actions button.primary {
  background: linear-gradient(135deg, rgba(201, 162, 79, 0.22), rgba(201, 162, 79, 0.12));
  border-color: rgba(201, 162, 79, 0.50);
  color: #c9a24f;
}
.em-templates-actions button.primary:hover {
  background: linear-gradient(135deg, rgba(201, 162, 79, 0.35), rgba(201, 162, 79, 0.22));
  border-color: rgba(201, 162, 79, 0.85);
  color: #e0bd6e;
}
.em-templates-actions button.danger:hover {
  color: #d97c7c;
  background: rgba(217, 124, 124, 0.05);
  border-color: rgba(217, 124, 124, 0.45);
}
/* Substituir: ação secundária com um tom âmbar discreto pra diferenciar
   de Excluir (danger/vermelho) e de Aplicar (primário/dourado). Continua
   neutra no estado normal, ganha tom só no hover. */
.em-templates-actions button.em-templates-replace:hover {
  color: #e3b341;
  background: rgba(227, 179, 65, 0.05);
  border-color: rgba(227, 179, 65, 0.45);
}
/* Renomear: tom azulado, distinto de Substituir (âmbar), Excluir
   (vermelho) e Aplicar (dourado). */
.em-templates-actions button.em-templates-rename:hover {
  color: #7eb1ff;
  background: rgba(126, 177, 255, 0.06);
  border-color: rgba(126, 177, 255, 0.45);
}
.em-templates-actions button[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}
.em-templates-actions button[disabled]:hover {
  background: transparent;
  color: rgba(237, 237, 235, 0.75);
  border-color: rgba(255, 255, 255, 0.10);
}

/* ─── Galeria de mídia: cabeçalho + grade de miniaturas ────────── */

/* Resumo no cabeçalho: total de arquivos + espaço usado. */
.em-gallery-summary {
  margin: 6px 0 0;
  font-size: 12px;
  color: rgba(237, 237, 235, 0.50);
  font-variant-numeric: tabular-nums;
}

/* Grade responsiva: cards se ajustam à largura do modal. */
.em-gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

/* Card de uma mídia: preview + nome/tamanho + botão remover. */
.em-gallery-item {
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.025), rgba(255, 255, 255, 0.01));
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.15s, background 0.15s, opacity 0.2s;
}
.em-gallery-item:hover {
  border-color: rgba(201, 162, 79, 0.32);
  background: linear-gradient(180deg, rgba(201, 162, 79, 0.04), rgba(255, 255, 255, 0.01));
}
/* Estado enquanto a remoção está em andamento. */
.em-gallery-item.is-removing {
  opacity: 0.45;
  pointer-events: none;
}

/* Área da miniatura: imagem cobre o espaço, fundo xadrez sutil
   para enxergar transparência de PNG/GIF. */
.em-gallery-thumb {
  position: relative;
  aspect-ratio: 4 / 3;
  background:
    repeating-conic-gradient(rgba(255, 255, 255, 0.03) 0% 25%, transparent 0% 50%)
      50% / 16px 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.em-gallery-thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

/* Ícone de fallback: aparece só quando a imagem não carrega. */
.em-gallery-thumb-fallback {
  display: none;
  color: rgba(237, 237, 235, 0.30);
}
.em-gallery-thumb.is-broken img { display: none; }
.em-gallery-thumb.is-broken .em-gallery-thumb-fallback { display: inline-flex; }

/* Selo "GIF" no canto da miniatura. */
.em-gallery-tag {
  position: absolute;
  top: 6px;
  left: 6px;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.10em;
  background: rgba(201, 162, 79, 0.85);
  color: #0a0a0b;
}

/* Selo de uso: no canto inferior direito da miniatura.
   "Em uso" tem tom de alerta discreto (terracota); "Sem uso" é neutro.
   Avisa o usuário se a mídia está referenciada em alguma campanha
   salva antes de ele decidir remover. */
.em-gallery-usage {
  position: absolute;
  bottom: 6px;
  right: 6px;
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.02em;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(2px);
}
.em-gallery-usage.is-used {
  background: rgba(217, 124, 124, 0.92);
  color: #0a0a0b;
}
.em-gallery-usage.is-free {
  background: rgba(10, 10, 11, 0.62);
  color: rgba(237, 237, 235, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.10);
}

/* Faixa de informações: nome do arquivo + tamanho + data. */
.em-gallery-info {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 12px 8px;
  min-width: 0;
}
.em-gallery-name {
  font-size: 12.5px;
  font-weight: 600;
  color: #ededeb;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.em-gallery-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: rgba(237, 237, 235, 0.45);
  font-variant-numeric: tabular-nums;
}
.em-gallery-meta-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(237, 237, 235, 0.25);
  display: inline-block;
  flex-shrink: 0;
}

/* Botão remover: largura total na base do card, tom de perigo no hover. */
.em-gallery-del {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin: 0 10px 10px;
  padding: 7px 10px;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.10);
  border-radius: 7px;
  color: rgba(237, 237, 235, 0.65);
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.em-gallery-del:hover {
  color: #d97c7c;
  background: rgba(217, 124, 124, 0.05);
  border-color: rgba(217, 124, 124, 0.45);
}
.em-gallery-del:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Pill do remetente: avatar pequeno + nome curto */
.em-history-sender {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.em-history-sender-avatar {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #c9a24f 0%, #b58a3f 100%);
  color: #0a0a0b;
  font-weight: 800;
  font-size: 8px;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.08) inset;
}
.em-history-sender-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.em-history-sender-initials {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #c9a24f 0%, #b58a3f 100%);
  color: #0a0a0b;
  font-weight: 800;
}
.em-history-sender-name {
  font-weight: 600;
  color: rgba(237, 237, 235, 0.7);
}

@media (max-width: 600px) {
  .em-history-item {
    grid-template-columns: 1fr;
  }
  .em-history-when {
    text-align: left;
  }
  /* Com o item em coluna única, a célula da grade estica o filho na
     largura toda. A pílula de status e o horário não devem esticar:
     `justify-self: start` mantém cada um do tamanho do próprio conteúdo. */
  .em-history-status,
  .em-history-when {
    justify-self: start;
  }
}

/* ─── Frame do preview ─────────────────────────────────────────── */
.em-preview-frame-wrap {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: #18181b;
}
#em-preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
  background: #ffffff;
}

/* Preview de texto puro (modo Textual) */
.em-preview-text-wrap {
  width: 100%;
  height: 100%;
  overflow: auto;
  background: #f5f5f0;
  padding: 32px 28px;
  box-sizing: border-box;
}
.em-preview-text {
  margin: 0 auto;
  max-width: 580px;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, sans-serif;
  font-size: 15px;
  line-height: 24px;
  color: #1c1917;
  white-space: pre-wrap;
  word-wrap: break-word;
  background: #ffffff;
  padding: 28px 26px;
  border-radius: 10px;
  border: 1px solid #e7e5e0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.em-preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: rgba(237, 237, 235, 0.30);
  pointer-events: none;
  padding: 40px 24px;
  text-align: center;
}
.em-empty-icon {
  color: rgba(201, 162, 79, 0.25);
}
.em-preview-empty p {
  margin: 0;
  font-size: 13px;
  max-width: 280px;
  line-height: 20px;
}

/* Garantia: hidden em HTML sempre vence display:flex/grid de classes
   (mesma especificidade, mas atributo + classe somam mais). */
.em-modal[hidden],
.em-modal-body[hidden],
.em-preview-loading[hidden],
.em-preview-text-wrap[hidden],
.em-preview-empty[hidden],
#em-preview-frame[hidden],
.em-history-loading[hidden],
.em-history-list[hidden],
.em-history-empty[hidden],
.em-history-error[hidden],
.em-gallery-grid[hidden],
.em-gallery-summary[hidden] {
  display: none !important;
}

/* ─── Loading overlay (durante geracao) ────────────────────────── */
.em-preview-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  background: radial-gradient(
    ellipse at center,
    rgba(13, 13, 16, 0.95) 0%,
    rgba(5, 5, 7, 0.98) 100%
  );
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 5;
  animation: em-loading-fade-in 0.25s ease-out;
}
@keyframes em-loading-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.em-loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  max-width: 360px;
  text-align: center;
}

.em-loading-icon {
  width: 88px;
  height: 88px;
  border-radius: 22px;
  background: linear-gradient(135deg, rgba(201, 162, 79, 0.12), rgba(201, 162, 79, 0.04));
  border: 1px solid rgba(201, 162, 79, 0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #c9a24f;
  position: relative;
  box-shadow: 0 0 36px rgba(201, 162, 79, 0.15);
  animation: em-loading-icon-float 3s ease-in-out infinite;
}
@keyframes em-loading-icon-float {
  0%, 100% { transform: translateY(0); }
  50%      { transform: translateY(-4px); }
}

/* Envelope: aba "abrindo" sutilmente */
.em-loading-env {
  transform-origin: center;
}
.em-loading-env-flap {
  stroke-dasharray: 60;
  stroke-dashoffset: 0;
  animation: em-loading-flap 2.4s ease-in-out infinite;
}
@keyframes em-loading-flap {
  0%, 100% { stroke-dashoffset: 0;  opacity: 1; }
  50%      { stroke-dashoffset: 60; opacity: 0.5; }
}

/* Sparks ao redor do envelope (sugerem "IA pensando") */
.em-loading-spark {
  fill: #c9a24f;
  opacity: 0;
  animation: em-loading-spark-pulse 1.8s ease-in-out infinite;
}
.em-loading-spark-1 { animation-delay: 0s; }
.em-loading-spark-2 { animation-delay: 0.4s; }
.em-loading-spark-3 { animation-delay: 0.8s; }
@keyframes em-loading-spark-pulse {
  0%, 100% { opacity: 0; transform: scale(0.6); }
  50%      { opacity: 1; transform: scale(1.1); }
}

.em-loading-title {
  margin: 6px 0 0 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: #ededeb;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}
.em-loading-dots {
  display: inline-flex;
  width: 1em;
  /* width fixa + margin-right negativa de mesmo valor: os pontos nao
     deslocam a centralizacao do texto. So a palavra ("Extraindo" /
     "Enviando") fica centralizada; os pontos animam logo a direita. */
  margin: 0 -1em 0 1px;
}
.em-loading-dots span {
  display: inline-block;
  animation: em-loading-dot-bounce 1.4s infinite;
  color: #c9a24f;
}
.em-loading-dots span:nth-child(2) { animation-delay: 0.18s; }
.em-loading-dots span:nth-child(3) { animation-delay: 0.36s; }
@keyframes em-loading-dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.3; }
  30%           { transform: translateY(-4px); opacity: 1; }
}

.em-loading-sub {
  margin: 0;
  font-size: 13px;
  line-height: 20px;
  color: rgba(237, 237, 235, 0.55);
}

/* Barra de progresso indeterminada */
.em-loading-bar {
  width: 240px;
  height: 3px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
  margin-top: 6px;
}
.em-loading-bar-fill {
  width: 35%;
  height: 100%;
  background: linear-gradient(90deg, transparent, #c9a24f, transparent);
  border-radius: 2px;
  animation: em-loading-bar-sweep 1.6s ease-in-out infinite;
}
@keyframes em-loading-bar-sweep {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(370%); }
}

/* Steps: indica em qual fase esta a geracao */
.em-loading-steps {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  margin-top: 14px;
  width: 100%;
  max-width: 240px;
}
.em-loading-step {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  color: rgba(237, 237, 235, 0.40);
  transition: color 0.3s;
}
.em-loading-step[data-active="true"] {
  color: #ededeb;
}
.em-loading-step[data-done="true"] {
  color: rgba(111, 199, 132, 0.85);
}
.em-loading-step-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  flex-shrink: 0;
  transition: background 0.3s, box-shadow 0.3s;
}
.em-loading-step[data-active="true"] .em-loading-step-dot {
  background: #c9a24f;
  box-shadow: 0 0 12px rgba(201, 162, 79, 0.6);
  animation: em-loading-step-pulse 1.2s ease-in-out infinite;
}
.em-loading-step[data-done="true"] .em-loading-step-dot {
  background: #6fc784;
  box-shadow: 0 0 0 2px rgba(111, 199, 132, 0.18);
}
@keyframes em-loading-step-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.3); }
}

@media (prefers-reduced-motion: reduce) {
  .em-loading-icon,
  .em-loading-env-flap,
  .em-loading-spark,
  .em-loading-dots span,
  .em-loading-bar-fill,
  .em-loading-step[data-active="true"] .em-loading-step-dot {
    animation: none;
  }
}

/* Mobile tabs: invisivel em desktop. */
.em-mobile-tabs { display: none; }

/* ─── Responsivo (mobile: stack vertical) ──────────────────────── */
@media (max-width: 900px) {
  .em-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr;
  }
  .em-form-pane {
    max-height: none;
    border-right: none;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 24px 18px;
  }
  .em-preview-pane {
    min-height: calc(100vh - 76px - 48px); /* topbar + tabs */
  }
  .em-preview-toolbar {
    padding: 12px 18px;
  }

  /* Tabs visiveis: switch entre Editar e Pre-visualizar. */
  .em-mobile-tabs {
    display: flex;
    gap: 0;
    position: sticky;
    top: 0;
    z-index: 50;
    background: #0a0a0c;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    grid-column: 1 / -1;
  }
  .em-mobile-tab {
    flex: 1;
    background: none;
    border: 0;
    color: rgba(237, 237, 235, 0.5);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    padding: 14px 12px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-bottom: 2px solid transparent;
    transition: color 0.15s, border-color 0.15s;
  }
  .em-mobile-tab.is-active {
    color: #c9a24f;
    border-bottom-color: #c9a24f;
  }

  /* Quando o user esta na tab Editar, oculta o preview. E vice-versa.
     O default (sem data-mobile-view definido) eh Editar. */
  body:not([data-mobile-view="preview"]) .em-preview-pane { display: none; }
  body[data-mobile-view="preview"]       .em-form-pane    { display: none; }
}

/* ─── Mobile (<=720px): tightening + iOS Safari quirks ─────────── */
@media (max-width: 720px) {
  .em-form-pane {
    padding: 20px 16px;
  }
  .em-pane-head {
    margin-bottom: 20px;
  }
  .em-title {
    font-size: 22px;
  }
  .em-subtitle {
    font-size: 12.5px;
  }

  /* Toolbar: meta em cima, ações em linha scrollável embaixo. */
  .em-preview-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    padding: 12px 14px;
  }
  .em-preview-actions {
    gap: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .em-preview-actions::-webkit-scrollbar { display: none; }
  .em-preview-actions > button {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 12px;
  }

  .em-preview-pane {
    min-height: 60vh;
  }

  /* Inputs >= 16px pra evitar zoom automatico no iOS Safari */
  .em-form input,
  .em-form select,
  .em-form textarea {
    font-size: 16px;
  }

  /* Modal Resend: ocupa mais tela em celular */
  .em-modal-card {
    max-width: 100%;
    width: 94%;
    max-height: 88vh;
    overflow-y: auto;
    border-radius: 14px;
  }
  .em-modal-head { padding: 18px 18px 14px; }
  .em-modal-body { padding: 16px 18px 18px; }

  /* Dialogs nativos (Templates + Historico + Galeria) */
  .em-history-dialog {
    width: 96%;
    max-height: 90vh;
    border-radius: 14px;
  }
  .em-history-head { padding: 16px 18px 14px; }
  .em-history-body { padding: 14px 18px; }

  /* Galeria: cards menores no mobile pra caber 2 por linha. */
  .em-gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
  }

  /* ── Preview toolbar no mobile: organizada e compacta ──
     A toolbar do preview tem 7 acoes (perfil, templates, galeria,
     historico, ed. avancada, copiar, descartar) + 1 primaria (enviar).
     Em desktop fica ok inline; em mobile virava uma linha bagunçada
     com mais texto que botao. Solucao:
       - .em-preview-actions: grid 4 colunas, gap regular
       - botoes ghost so com icone (label oculto)
       - perfil de envio mantem nome curto (informacao principal)
       - copiar e enviar (primarias) mantem label
       - botoes quadrados 44x44 (alvo de toque iOS)
  */
  .em-preview-actions {
    display: grid !important;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    overflow: visible !important;     /* substitui o scroll-x antigo */
    padding-bottom: 0 !important;
  }
  .em-preview-actions > * {
    min-height: 44px;
    flex-shrink: 1 !important;
    box-sizing: border-box;
  }
  /* Botoes ghost (Templates/Galeria/Historico/Ed.Avancada/Descartar):
     icon-only, padding compacto. Label vira tooltip. */
  .em-preview-actions .em-btn-ghost:not(.em-sender-btn) {
    padding: 8px;
    gap: 0;
    justify-content: center;
  }
  .em-preview-actions .em-btn-ghost:not(.em-sender-btn) > span:not([aria-hidden]) {
    display: none;
  }
  /* Perfil de envio: ocupa 2 colunas (o nome eh contexto importante). */
  .em-preview-actions .em-sender-select {
    grid-column: span 2;
  }
  .em-preview-actions .em-sender-btn {
    width: 100%;
    justify-content: flex-start;
    padding: 8px 10px;
  }
  .em-preview-actions .em-sender-btn-label { display: none; }
  .em-preview-actions .em-sender-btn-name {
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  /* Botoes primarios (Copiar / Enviar): ocupam 2 colunas cada (=1 linha
     inteira pra cada par). Mantem o label visivel pra reforcar acao. */
  .em-preview-actions .em-btn-secondary,
  .em-preview-actions .em-btn-primary,
  .em-preview-actions .em-btn-resend {
    grid-column: span 2;
    justify-content: center;
    font-weight: 700;
  }

  /* Acoes do modo edicao de campanha (Salvar email pra campanha / Sair):
     mantem icon+label, ocupa 4 cols cada (linha inteira) pra nao
     comprimir. */
  .em-preview-actions .cb-edit-actions {
    grid-column: 1 / -1;
    display: flex;
    gap: 8px;
  }
  .em-preview-actions .cb-edit-actions > button { flex: 1; }
}

/* ─── Mobile extra-pequeno (<=420px) ───────────────────────────── */
@media (max-width: 420px) {
  .em-form-pane {
    padding: 18px 14px;
  }
  .em-title { font-size: 20px; }

  /* Toolbar: esconde os labels dos botoes ghost (Templates / Historico)
     pra reduzir overflow horizontal. Os botoes ficam apenas com icone. */
  .em-btn-ghost > span:not([aria-hidden]) {
    display: none;
  }
  .em-btn-ghost { padding: 8px 10px; }

  /* Excecao: o botao "Perfil de envio" mantem o texto visivel (o nome
     do perfil e a informacao principal do dropdown). O seletor acima e
     mais especifico que .em-sender-btn-text isolado, entao reafirmamos
     o flex aqui para o texto nao sumir no mobile. */
  .em-sender-btn > .em-sender-btn-text { display: flex; }
}

/* ─── Mobile: ajustes finos do Composer (<=600px) ──────────────── */
@media (max-width: 600px) {
  /* Trava overflow horizontal acidental da página. */
  html, body { overflow-x: hidden; }

  /* O switch de modo flutua fixo no rodapé: garante que o conteúdo
     do formulário e do preview role livre por baixo sem ficar coberto. */
  .em-form-pane { padding-bottom: 88px; }

  /* Botões de ação da toolbar: alvo de toque confortável. */
  .em-preview-actions > button { min-height: 40px; }

  /* Modal Resend: botões de ação ocupam a largura para toque fácil. */
  .em-modal-actions {
    flex-wrap: wrap;
  }
  .em-modal-actions .em-btn-primary,
  .em-modal-actions .em-btn-secondary,
  .em-modal-actions .em-btn-danger {
    flex: 1 1 auto;
    justify-content: center;
  }

  /* Diálogo "Templates salvos": a linha "salvar atual" empilha o campo e
     o botão. Lado a lado, o botão "Salvar email atual" não cabe na
     largura do celular e vazava da borda do diálogo. */
  .em-templates-save {
    flex-wrap: wrap;
  }
  .em-templates-save input {
    flex: 1 1 100%;
  }
  .em-templates-save button {
    flex: 1 1 100%;
    justify-content: center;
  }
}

/* Scrollbar custom no form-pane (combina com o tema) */
.em-form-pane::-webkit-scrollbar {
  width: 8px;
}
.em-form-pane::-webkit-scrollbar-track {
  background: transparent;
}
.em-form-pane::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
}
.em-form-pane::-webkit-scrollbar-thumb:hover {
  background: rgba(201, 162, 79, 0.30);
}

/* ─── Subestado "queued" do modal de envio Resend ───────────────────
   Aparece logo apos o enqueue do job (POST /api/resend/send). Mostra
   a barra dourada preenchendo ate 100% em 60s -- o intervalo maximo
   entre o enqueue e o motor (campaign-engine) pegar o job pelo cron.
   Some quando o motor pega (sent_count > 0) ou no timer, o que vier
   primeiro. A transicao de 60s e aplicada via script.js. */
.em-resend-queued {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 24px;
  gap: 12px;
  text-align: center;
}
.em-resend-queued .em-resend-loading-icon {
  color: rgba(201, 162, 79, 0.85);
}
.em-resend-queued-bar {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 8px;
}
.em-resend-queued-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #c9a24f, #d9b66a);
  border-radius: 999px;
}
@media (prefers-reduced-motion: reduce) {
  .em-resend-queued-fill { transition: none !important; }
}
