:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, 'Liberation Mono', monospace;

  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --bg-hover: #f2f2f2;
  --bg-active: #ededed;
  --border: #eaeaea;
  --border-strong: #d4d4d4;
  --fg: #111111;
  --fg-muted: #666666;
  --fg-faint: #999999;
  --accent: #0070f3;
  --accent-soft: #e8f1fe;
  --warning-bg: #fff8e6;
  --warning-border: #ffe6a1;
  --warning-fg: #8a6100;
  --danger: #e5484d;
  --success: #17803d;

  --radius: 6px;
  --sidebar-w: 244px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.55;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

#shell { display: flex; min-height: 100vh; }

/* ---------- Sidebar (the signature) ---------- */
#sidebar { display: none; }
body.authed #sidebar {
  display: flex;
  flex-direction: column;
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px;
  height: 57px;
  font-weight: 600;
  font-size: 14.5px;
  letter-spacing: -0.01em;
  border-bottom: 1px solid var(--border);
}
.brand-mark {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: #000;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-mark svg { width: 13px; height: 13px; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 10px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: var(--radius);
  color: var(--fg-muted);
  text-decoration: none;
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--fg); }
.nav-item.active { background: var(--bg-active); color: var(--fg); }
.nav-item.active svg { color: var(--accent); }

.side-footer {
  border-top: 1px solid var(--border);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.user { display: flex; align-items: center; gap: 8px; min-width: 0; padding: 0 4px; }
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  flex-shrink: 0;
}
.user-email {
  font-size: 12.5px;
  color: var(--fg-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Main content ---------- */
#app { flex: 1; min-width: 0; }
body.authed #app { padding: 36px 44px; max-width: 1080px; }
body:not(.authed) #app {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 100vh;
  padding: 24px;
}

/* ---------- Typography ---------- */
h2 { font-size: 22px; font-weight: 600; letter-spacing: -0.02em; margin: 0 0 4px; }
h3 {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 26px 0 10px;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Sections / forms in content ---------- */
body.authed section { margin-top: 6px; }
body.authed form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin: 4px 0 6px;
}

/* ---------- Inputs & selects ---------- */
input, select {
  font-family: inherit;
  font-size: 14px;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  outline: none;
  transition: border-color .12s ease, box-shadow .12s ease;
}
select { padding-right: 6px; }
input::placeholder { color: var(--fg-faint); }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- Buttons: secondary default, primary for form submits ---------- */
button {
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, color .12s ease;
}
button:hover { background: var(--bg-hover); border-color: var(--border-strong); }
button:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }

/* primary = a real submit button inside a form */
form button:not([type='button']) {
  background: #000;
  border-color: #000;
  color: #fff;
}
form button:not([type='button']):hover { background: #383838; border-color: #383838; }

/* logout / explicit ghost stays subtle even in the footer */
.btn-ghost { width: 100%; color: var(--fg-muted); }

/* ---------- Auth card (login / troca-senha) ---------- */
body:not(.authed) form {
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 26px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.04);
}
body:not(.authed) input { width: 100%; }
body:not(.authed) h2 { margin-bottom: 2px; text-align: center; }

/* Olho de mostrar/ocultar senha */
.senha-wrap { position: relative; display: block; }
.senha-wrap > input { padding-right: 40px; }
.olho-btn {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0;
  background: none; border: none; cursor: pointer; color: var(--fg-muted);
}
.olho-btn:hover { color: var(--fg); }
.olho-btn svg { width: 18px; height: 18px; }

/* ---------- Tables ---------- */
table {
  border-collapse: collapse;
  width: 100%;
  margin-top: 14px;
  font-size: 13px;
}
th {
  text-align: left;
  font-weight: 500;
  color: var(--fg-muted);
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-subtle);
  white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border); }
tbody tr:hover td { background: var(--bg-subtle); }
td button { height: 30px; padding: 0 10px; font-size: 13px; }
td.td-nowrap { white-space: nowrap; } /* telefone e botões de ação ficam numa linha só */

/* ---------- Live queue panel ---------- */
#painel { margin-top: 10px; }
#painel p { margin: 6px 0; color: var(--fg-muted); font-size: 13px; }
#painel p strong { color: var(--fg); }

/* ---------- Banner / messages ---------- */
.banner {
  background: var(--warning-bg);
  border: 1px solid var(--warning-border);
  color: var(--warning-fg);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 22px;
  font-size: 13px;
}
.banner a { color: var(--accent); font-weight: 500; }
.erro { color: var(--danger); font-size: 13px; margin: 6px 0; }

/* ---------- Config: um card por integração ---------- */
body.authed form.config-form { display: block; }
.cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin: 12px 0 20px;
}
.card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
  background: var(--bg);
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.card-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
  color: var(--fg);
  text-transform: none;
  letter-spacing: -0.01em;
}
.card-fields { display: flex; flex-direction: column; gap: 11px; }
.card-fields label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12.5px;
  color: var(--fg-muted);
}
.card-fields input { width: 100%; }
.btn-sm { height: 30px; padding: 0 11px; font-size: 13px; }
.card-actions { display: flex; gap: 8px; align-items: center; }
.test-msg { margin: 12px 0 0; font-size: 12.5px; color: var(--fg-muted); min-height: 1em; }
.test-msg.ok { color: var(--success); }
.test-msg.erro { color: var(--danger); }
/* ---------- Cabeçalho de página com ação ---------- */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}
.btn-primary { background: #000; border-color: #000; color: #fff; }
.btn-primary:hover { background: #383838; border-color: #383838; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #cf3a3f; border-color: #cf3a3f; }

/* ---------- Modal (popup de cadastro) ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 900;
}
.modal-overlay[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 420px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  padding: 22px 24px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.modal-head h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--fg);
  text-transform: none;
  letter-spacing: -0.01em;
}
.modal-head .btn-sm { padding: 0 9px; color: var(--fg-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.modal-text { margin: 0; color: var(--fg-muted); font-size: 13.5px; }

/* ---------- Campo de telefone com DDI fixo (+55) ---------- */
.tel-br { position: relative; display: inline-flex; }
.tel-br > .ddi {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--fg-muted);
  font-size: 14px;
  pointer-events: none;
}
.tel-br > input { padding-left: 46px; }
.card-fields .tel-br { display: flex; }
.card-fields .tel-br > input { width: 100%; }

/* ---------- Telefone de envio fixo (operador) ---------- */
.envio-fixo {
  margin: 0 0 8px;
  padding: 8px 12px;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--fg-muted);
  font-size: 13.5px;
}
.envio-fixo strong { color: var(--fg); }

/* ---------- Toast (notificação flutuante) ---------- */
#toasts {
  position: fixed;
  top: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}
.toast {
  padding: 11px 16px;
  border-radius: 8px;
  font-size: 13.5px;
  font-weight: 500;
  color: #fff;
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(-8px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-ok { background: var(--success); }
.toast-erro { background: var(--danger); }
@media (max-width: 720px) { .cards { grid-template-columns: 1fr; } }

/* ---------- Relatórios ---------- */
.rel-filtros {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin: 10px 0 22px;
}
.rel-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12.5px;
  color: var(--fg-muted);
  font-weight: 500;
}
.rel-totais {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 12px 0 4px;
}
.rel-card {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-subtle);
  min-width: 110px;
}
.rel-card-label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--fg-muted);
}
.rel-card-val {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}
.rel-card-val.enviados { color: var(--success); }
.rel-card-val.pulados { color: #d97706; }
.rel-card-val.erros { color: var(--danger); }
.rel-empty {
  color: var(--fg-muted);
  font-size: 13px;
  margin: 4px 0;
}

/* Bar chart */
.bar-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 5px 0;
  border-bottom: 1px solid var(--border);
}
.bar-row:last-child { border-bottom: none; }
.bar-label {
  width: 140px;
  flex-shrink: 0;
  font-size: 12.5px;
  color: var(--fg-muted);
  padding-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bar-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
}
.bar-line {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bar-track {
  flex: 1;
  height: 14px;
  background: var(--bg-subtle);
  border-radius: 99px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.bar-fill {
  height: 100%;
  border-radius: 99px;
  transition: width 0.3s ease;
}
.bar-fill.enviados { background: var(--success); }
.bar-fill.pulados { background: #d97706; }
.bar-val {
  font-size: 12px;
  color: var(--fg-muted);
  min-width: 28px;
  text-align: right;
}

/* ---------- Relatório: colunas verticais (mensagens por dia) ---------- */
.rel-legenda { font-size: 12px; color: var(--fg-muted); margin: 2px 0 10px; }
.rel-legenda .leg { display: inline-block; width: 11px; height: 11px; border-radius: 3px; vertical-align: -1px; margin-right: 3px; }
.rel-legenda .leg.enviados { background: var(--success); }
.rel-legenda .leg.pulados { background: #d97706; }
.rel-legenda .leg.erros { background: var(--danger); }
.col-chart { display: flex; align-items: flex-end; gap: 12px; height: 180px; padding-top: 16px; overflow-x: auto; }
.col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; min-width: 34px; }
.col-total { font-size: 11px; color: var(--fg-muted); margin-bottom: 3px; }
.col-stack { width: 24px; min-height: 2px; display: flex; flex-direction: column; border-radius: 4px 4px 0 0; overflow: hidden; }
.col-seg { transition: height 0.3s ease; }
.col-seg.enviados { background: var(--success); }
.col-seg.pulados { background: #d97706; }
.col-seg.erros { background: var(--danger); }
.col-label { font-size: 11px; color: var(--fg-muted); margin-top: 5px; white-space: nowrap; }

/* ---------- Paginação da lista de pendentes ---------- */
.pag { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.pag-info { font-size: 13px; color: var(--fg-muted); }
.pag button[disabled] { opacity: 0.5; cursor: default; }

/* ---------- Responsive: sidebar becomes a top bar ---------- */
@media (max-width: 768px) {
  #shell { flex-direction: column; }
  body.authed #sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
  }
  .brand { border-bottom: none; border-right: 1px solid var(--border); height: 52px; white-space: nowrap; }
  .nav { flex-direction: row; padding: 8px; gap: 2px; }
  .nav-item { white-space: nowrap; }
  .side-footer { border-top: none; border-left: 1px solid var(--border); flex-direction: row; align-items: center; }
  .btn-ghost { width: auto; }
  .user-email { display: none; }
  body.authed #app { padding: 22px 18px; }
}

/* ---------- Modal de conexão do WhatsApp (Z-API) ---------- */
.zapi-corpo { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 6px 0; }
.zapi-status { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 15px; }
.zapi-status.ok { color: var(--success); }
.zapi-status.off { color: var(--danger); }
.zapi-ico svg { width: 20px; height: 20px; display: block; }
.zapi-qr { width: 240px; height: 240px; border: 1px solid var(--border); border-radius: 8px; }
.zapi-dica { font-size: 13px; color: var(--fg-muted); text-align: center; max-width: 320px; }
.zapi-acoes { display: flex; gap: 8px; }
.zapi-num { font-size: 14px; color: var(--fg-muted); }
/* Bolinha de status do WhatsApp ao lado do botão "Conexão do WhatsApp": verde=conectado, vermelho=off. */
.zapi-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; background: var(--fg-muted); }
.zapi-dot.on { background: var(--success); }
.zapi-dot.off { background: var(--danger); }
