:root {
  --bg: #f2f7f3;
  --card: #ffffff;
  --primary: #16a34a;
  --primary-dark: #14532d;
  --primary-light: #16a34a;
  --accent: #16a34a;
  --danger: #dc2626;
  --warn: #d97706;
  --text: #1e2a24;
  --muted: #6b7784;
  --border: #e5ece7;
  --border-strong: #d6e0d9;
  --field-bg: #fbfdfc;
  --sidebar-width: 224px;

  --side-bg: #eef4f0;
  --side-text: #35473d;
  --side-text-muted: #62766b;
  --side-hover: #e2ede6;
  --side-active-bg: #16a34a;
  --side-active-text: #ffffff;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

/* ---------- Menu lateral ---------- */
.topbar {
  background: var(--side-bg);
  color: var(--side-text);
  padding: 18px 12px;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  overflow-y: auto;
  z-index: 10;
  border-right: 3px solid var(--primary);
}

.topbar .brand {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-bottom: 22px;
}

.topbar .brand-box {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border-radius: 12px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
}

.topbar .brand-box img.icon { height: 34px; border-radius: 6px; }
.topbar .brand-box img.wordmark { height: 30px; }

.topbar nav { display: flex; flex-direction: column; width: 100%; gap: 3px; }

.topbar nav a {
  color: var(--side-text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: 10px;
  width: 100%;
}

.topbar nav a:hover { background: var(--side-hover); color: var(--primary-dark); }

.topbar nav a.active {
  background: var(--side-active-bg);
  color: var(--side-active-text);
  font-weight: 600;
}

.topbar nav a.has-sub { position: relative; padding-right: 28px; }
.topbar nav a.has-sub .caret {
  position: absolute; right: 8px; top: 50%;
  width: 16px; height: 16px; margin-top: -8px; border-radius: 5px;
}
.topbar nav a.has-sub .caret::before {
  content: "\203A";
  position: absolute; inset: 0; text-align: center; line-height: 16px;
  font-size: 16px; color: currentColor; opacity: 0.6; transition: transform 0.12s;
}
.topbar nav a.has-sub.expanded .caret::before { transform: rotate(90deg); }
.topbar nav a.has-sub .caret:hover { background: rgba(0,0,0,0.06); }

.topbar nav .subnav {
  display: none; flex-direction: column; gap: 1px; margin: 2px 0 6px;
}
.topbar nav .subnav.open { display: flex; }

.topbar nav .subnav a {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--side-text);
  padding: 7px 12px 7px 26px;
  border-radius: 8px;
}
.topbar nav .subnav a:hover { background: var(--side-hover); color: var(--primary-dark); }

[id^="sec-"], #byCampaignTitle { scroll-margin-top: 20px; }

.in-shell .topbar { display: none !important; }
.in-shell .container { margin-left: auto !important; }

/* ---------- Conteúdo ---------- */
.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 28px 24px 64px;
  margin-left: calc(var(--sidebar-width) + 28px);
}

@media (max-width: 800px) {
  .topbar { position: static; width: 100%; flex-direction: row; flex-wrap: wrap; padding: 12px 16px; }
  .topbar nav { flex-direction: row; flex-wrap: wrap; }
  .container { margin-left: auto; padding: 20px 16px 48px; }
}

h1 { font-size: 25px; font-weight: 700; margin: 0 0 4px; letter-spacing: -0.01em; }
h3 { font-size: 16px; font-weight: 700; margin: 0 0 12px; }
.subtitle { color: var(--muted); margin: 0 0 26px; font-size: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px 20px;
  box-shadow: 0 1px 2px rgba(20,40,30,0.04);
}

.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.stat-label { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

.section-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin: 30px 0 12px;
}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border-radius: 9px;
  border: 1px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  color: #fff;
  background: var(--primary);
  transition: filter 0.12s, background 0.12s;
}
.btn:hover { filter: brightness(0.95); }
.btn.secondary { background: #e5ebe8; color: var(--text); border-color: #bcccc3; }
.btn.secondary:hover { background: #d8e1dc; filter: none; }
.btn.success { background: var(--accent); }
.btn.warn { background: var(--warn); }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* "Tem coisa pra fazer aqui" — o botão fica verde forte com um anel e um pontinho,
   pra você não esquecer de clicar (salvar / enviar) depois de mexer num campo. */
.btn.needs-save {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 139, 84, 0.22);
}
.btn.needs-save::before { content: "\2022"; margin-right: 6px; font-size: 15px; line-height: 0; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* Botãozinho "copiar" ao lado de um texto (campanha, template) */
.copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 7px;
  border: 1px solid #bcccc3;
  background: #e5ebe8;
  color: var(--text);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
}
.copy-btn:hover { background: #d8e1dc; }

/* ---------- Campanhas ---------- */
.campaign-card { margin-bottom: 14px; }
.campaign-card .row1 { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; }
.campaign-card .name { font-weight: 700; font-size: 16px; }

/* Lista de campanhas compacta: info à esquerda, botões à direita, mais campanhas por tela */
.campaign-row { display: flex; align-items: center; gap: 16px; padding: 12px 14px; margin-bottom: 8px; }
.campaign-row .cr-info { flex: 1; min-width: 0; }
.campaign-row .cr-head { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.campaign-row .cr-head .name { font-size: 14.5px; }
.campaign-row .progress-bar { margin: 6px 0; }
.campaign-row .cr-stats { font-size: 12px; margin: 0; }
.campaign-row .cr-actions { flex-shrink: 0; margin: 0; gap: 6px; }
.campaign-row .cr-actions .btn { padding: 6px 12px; font-size: 12.5px; }
@media (max-width: 720px) {
  .campaign-row { flex-direction: column; align-items: stretch; }
  .campaign-row .cr-actions { justify-content: flex-end; }
}

.tag {
  display: inline-block;
  background: #e7f6ec;
  color: #15633a;
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  margin-left: 6px;
  font-weight: 600;
}
.status-badge { font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; }
.status-draft { background: #eef1f0; color: #5b6b63; }
/* "enviando" em destaque: verde e maior — dá pra ver de longe que está rodando */
.status-sending { background: #16a34a; color: #fff; font-size: 14px; padding: 5px 16px; }
.status-pausada { background: #fee2e2; color: #991b1b; }
.status-concluida { background: #e7f6ec; color: #15633a; }
.status-encerrada { background: #e5e7eb; color: #374151; }

/* ---------- Janelas do próprio sistema (confirm/alert/prompt) ---------- */
.ui-modal-overlay {
  position: fixed; inset: 0; z-index: 9999;
  background: rgba(18, 40, 28, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.ui-modal {
  background: #fff; border-radius: 14px;
  width: 100%; max-width: 460px;
  padding: 20px 22px 18px;
  border-top: 5px solid var(--primary);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.ui-modal-title { font-weight: 700; font-size: 15px; color: var(--primary-dark); margin-bottom: 8px; }
.ui-modal-msg { font-size: 13.5px; color: var(--text); line-height: 1.55; white-space: pre-wrap; }
.ui-modal-input { width: 100%; margin-top: 12px; }
.ui-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 18px; flex-wrap: wrap; }

.progress-bar { background: #e9eeeb; border-radius: 999px; height: 7px; margin: 10px 0; overflow: hidden; }
.progress-fill { background: var(--accent); height: 100%; }
.progress-fill.failed { background: var(--danger); }

.meta-line { color: var(--muted); font-size: 13px; }

/* ---------- Formulários ---------- */
form .field { margin-bottom: 16px; }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--text); }
input[type=text], input[type=number], input[type=password], input[type=url], input[type=file], select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #bcccc3;
  border-radius: 9px;
  font-size: 14px;
  background: var(--field-bg);
  color: var(--text);
  font-family: inherit;
  box-shadow: 0 1px 2px rgba(22, 60, 40, 0.05);
}
input:hover, select:hover, textarea:hover { border-color: #9fb4a8; }
/* Ao clicar pra digitar: fundo amarelo bem fraco + borda verde, pra ficar claro
   em qual campo você está. Vale pra todo o sistema. */
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: #fefce8;
  box-shadow: 0 0 0 3px rgba(22,163,74,0.12);
}
textarea { min-height: 100px; font-family: ui-monospace, Menlo, Consolas, monospace; }
.hint { color: var(--muted); font-size: 12px; margin-top: 4px; }

.template-option {
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 10px;
  cursor: pointer;
}
.template-option:hover { border-color: var(--primary); }
.template-option.selected { border-color: var(--primary); background: #e7f6ec; }
.template-option .tname { font-weight: 700; }
.template-option .tbody { font-size: 13px; color: var(--muted); margin-top: 6px; white-space: pre-wrap; }

.preview-box { background: #ece5dd; border-radius: 14px; padding: 16px; max-width: 340px; }
.preview-bubble { background: #fff; border-radius: 10px; padding: 14px; font-size: 14px; }
.preview-bubble img { width: 100%; border-radius: 8px; margin-bottom: 8px; }

/* ---------- Alertas ---------- */
.alert { padding: 11px 15px; border-radius: 10px; font-size: 13px; margin-bottom: 16px; }
.alert.error {
  background: #dc2626;
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  border: 1px solid #991b1b;
  box-shadow: 0 2px 10px rgba(220,38,38,0.28);
}
.alert.error a { color: #ffe4e4; text-decoration: underline; }
.alert.success { background: #e7f6ec; color: #15633a; }
.alert.info { background: #eef4f7; color: #234b5e; }

/* Balão de aviso flutuante — sempre visível, não importa onde a página esteja rolada */
#floatingAlertHost {
  position: fixed;
  top: 78px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10001;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: min(92vw, 460px);
  pointer-events: none;
}
#floatingAlertHost .floating-alert {
  margin: 0;
  pointer-events: auto;
  cursor: pointer;
  max-height: 60vh;
  overflow-y: auto;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.22);
  transition: opacity .25s ease;
  animation: floatingAlertIn .2s ease;
}
#floatingAlertHost .floating-alert.success { border: 1px solid #9fd3b4; }
#floatingAlertHost .floating-alert.info { border: 1px solid #bcd4de; }
@keyframes floatingAlertIn {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Tabelas ---------- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
