/* R-Sender — tema azul moderno, escuro por padrão com toggle claro */
:root {
  --bg: #0a1628;
  --bg-2: #0d1d35;
  --surface: #132647;
  --surface-2: #1a3158;
  --border: #24406b;
  --text: #e6f0ff;
  --muted: #8aa3c7;
  --primary: #2196f3;
  --primary-dark: #1565c0;
  --primary-light: #4fc3f7;
  --grad: linear-gradient(135deg, #1565c0 0%, #4fc3f7 100%);
  --success: #26a69a;
  --warn: #ffa726;
  --danger: #ef5350;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --radius: 14px;
}
[data-theme="light"] {
  --bg: #eef3fa;
  --bg-2: #e4ecf7;
  --surface: #ffffff;
  --surface-2: #f4f8fd;
  --border: #d3e0f0;
  --text: #0d1b2e;
  --muted: #5a7192;
  --shadow: 0 8px 30px rgba(21,60,110,.12);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  transition: background .25s, color .25s;
}
a { color: var(--primary-light); text-decoration: none; }
[data-theme="light"] a { color: var(--primary-dark); }
code { background: var(--bg-2); padding: 2px 6px; border-radius: 6px; font-size: .85em; color: var(--primary-light); }
small, .small { font-size: .85em; }
.muted { color: var(--muted); }
.center { text-align: center; }
.right { text-align: right; }
.text-danger { color: var(--danger); }
.text-warn { color: var(--warn); }

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px; flex-shrink: 0; background: var(--bg-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 50;
  transform: translateX(0); transition: transform .25s;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.brand-logo { width: 42px; height: 42px; object-fit: contain; border-radius: 10px; background: #fff; padding: 2px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-nav { flex: 1; padding: 12px 8px; overflow-y: auto; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--muted); padding: 14px 12px 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: var(--text); margin-bottom: 2px; font-size: 14px; transition: background .15s;
}
.nav-item:hover { background: var(--surface); }
.nav-item.active { background: var(--grad); color: #fff; box-shadow: 0 4px 14px rgba(33,150,243,.35); }
.nav-item.logout { color: var(--danger); }
.sidebar-footer { padding: 12px 8px; border-top: 1px solid var(--border); }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 40; }

.main-col { flex: 1; margin-left: 260px; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 22px;
  background: var(--bg-2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 30; backdrop-filter: blur(8px);
}
.topbar-title { font-weight: 600; font-size: 16px; flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.icon-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer; position: relative;
  display: inline-flex; align-items: center; justify-content: center; transition: .15s;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary-light); }
.wa-status-dot { position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; border: 2px solid var(--surface); }
.menu-toggle { display: none; }
.user-chip { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--border); padding: 4px 12px 4px 4px; border-radius: 30px; }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--grad); color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 10px; background: var(--surface-2); padding: 2px 6px; border-radius: 6px; color: var(--muted); text-transform: uppercase; }
[data-theme="dark"] .icon-moon { display: none; }
[data-theme="light"] .icon-sun { display: none; }

.content { padding: 22px; max-width: 1280px; width: 100%; margin: 0 auto; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { font-size: 20px; }

/* ---------- Cards / grid ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden; }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-header h2, .card-header h3 { font-size: 16px; }
.card-body { padding: 18px; }
.grid { display: grid; gap: 16px; margin-bottom: 18px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

.stat-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 30px; font-weight: 700; margin: 6px 0 4px; }
.stat-value.accent { color: var(--primary-light); }
.stat-value.success { color: var(--success); }
.stat-value.warn { color: var(--warn); }
.stat-sub, .stat-link { font-size: 12px; color: var(--muted); }
.stat-link { color: var(--primary-light); }

/* ---------- Cards coloridos do Dashboard (só os que têm a classe .tone) ----------
   Cada card define uma cor-base (--tone, em R,G,B) e uma cor de texto por tema
   (--tone-text); o resto — fundo em degradê, borda, brilho e ícone — é derivado
   disso, então o mesmo CSS serve pro tema escuro e pro claro. */
.stat-card.tone {
  --a-bg: .26; --a-bg2: .07; --a-border: .55; --a-deco: .20; --a-icon: .24;
  position: relative; overflow: hidden;
  background: linear-gradient(145deg, rgba(var(--tone), var(--a-bg)) 0%, rgba(var(--tone), var(--a-bg2)) 70%), var(--surface);
  border: 1px solid rgba(var(--tone), var(--a-border));
  transition: transform .18s ease, box-shadow .18s ease;
}
.stat-card.tone::after {                       /* brilho decorativo no canto */
  content: ''; position: absolute; right: -34px; bottom: -34px; width: 120px; height: 120px;
  border-radius: 50%; background: rgba(var(--tone), var(--a-deco)); pointer-events: none;
}
.stat-card.tone:hover { transform: translateY(-3px); box-shadow: 0 12px 32px rgba(var(--tone), .28); }
.stat-card.tone > * { position: relative; z-index: 1; }
.stat-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.stat-icon {
  width: 40px; height: 40px; flex: 0 0 40px; border-radius: 12px; display: grid; place-items: center;
  background: rgba(var(--tone), var(--a-icon)); color: var(--tone-text);
  border: 1px solid rgba(var(--tone), .35);
}
.stat-card.tone .stat-label { color: var(--tone-text); font-weight: 600; opacity: .95; }
.stat-card.tone .stat-value { color: var(--tone-text); font-size: 34px; }
.stat-card.tone .stat-link { color: var(--tone-text); font-weight: 600; }
.stat-card.tone .stat-link:hover { text-decoration: underline; }
.stat-card.tone .stat-sub { color: var(--muted); }

.tone-green  { --tone: 38,166,154;  --tone-text: #4fe3d3; }
.tone-blue   { --tone: 33,150,243;  --tone-text: #7fc8ff; }
.tone-violet { --tone: 139,92,246;  --tone-text: #b9a3ff; }
.tone-amber  { --tone: 255,167,38;  --tone-text: #ffc76a; }

/* Tema claro: fundo mais suave e texto mais escuro, pra manter contraste */
[data-theme="light"] .stat-card.tone { --a-bg: .17; --a-bg2: .03; --a-border: .42; --a-deco: .13; --a-icon: .16; }
[data-theme="light"] .tone-green  { --tone-text: #0b7a70; }
[data-theme="light"] .tone-blue   { --tone-text: #0f5db8; }
[data-theme="light"] .tone-violet { --tone-text: #5b32c9; }
[data-theme="light"] .tone-amber  { --tone-text: #a35d00; }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer; font-size: 14px; font-weight: 600;
  transition: .15s; text-decoration: none; background: var(--surface); color: var(--text);
}
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: 0 4px 14px rgba(33,150,243,.35); }
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(33,150,243,.5); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary-light); }
.btn-success { background: var(--success); color: #fff; }
.btn-warn { background: var(--warn); color: #1a1a1a; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.flex-1 { flex: 1; min-width: 200px; }

.input, select.input, textarea.input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg-2); color: var(--text); font-size: 14px; outline: none; transition: .15s;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(33,150,243,.2); }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.form-grid label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.form-grid .span-2 { grid-column: span 2; }
.check-line { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--text) !important; }
.section-title { margin: 22px 0 12px; font-size: 15px; color: var(--primary-light); border-bottom: 1px solid var(--border); padding-bottom: 8px; }
.section-title small { color: var(--muted); font-weight: normal; }
.days-checks { display: flex; gap: 10px; flex-wrap: wrap; }
.day-check { flex-direction: row !important; align-items: center; gap: 4px !important; background: var(--bg-2); padding: 6px 10px; border-radius: 8px; border: 1px solid var(--border); }

/* ---------- Badges / progress / alerts ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: uppercase; background: var(--surface-2); color: var(--muted); }
.badge.big { font-size: 14px; padding: 6px 14px; }
.badge-active, .badge-sent, .badge-open, .badge-connected { background: rgba(38,166,154,.2); color: var(--success); }
.badge-paused, .badge-pending, .badge-disconnected { background: rgba(255,167,38,.2); color: var(--warn); }
.badge-error, .badge-failed { background: rgba(239,83,80,.2); color: var(--danger); }
.badge-completed { background: rgba(33,150,243,.2); color: var(--primary-light); }
.badge-role-adm { background: rgba(239,83,80,.2); color: var(--danger); }
.badge-role-reseller { background: rgba(33,150,243,.2); color: var(--primary-light); }
.badge-role-operator { background: rgba(255,167,38,.2); color: var(--warn); }

.progress { height: 8px; background: var(--bg-2); border-radius: 10px; overflow: hidden; }
.progress.big { height: 14px; }
.progress-bar { height: 100%; background: var(--grad); border-radius: 10px; transition: width .5s; }

.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; border: 1px solid; }
.alert-ok { background: rgba(38,166,154,.12); border-color: var(--success); color: var(--success); }
.alert-error { background: rgba(239,83,80,.12); border-color: var(--danger); color: var(--danger); }
.alert-warn { background: rgba(255,167,38,.12); border-color: var(--warn); color: var(--warn); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }

/* Variações + Histórico da campanha: mesma altura nos dois cards, com
   rolagem interna — sem isso a página cresce sem parar conforme os
   registros de envio se acumulam. */
.scroll-card-body { max-height: 460px; overflow-y: auto; padding-top: 0; padding-bottom: 0; }
.scroll-card-body > *:first-child { margin-top: 18px; }
.scroll-card-body > *:last-child { margin-bottom: 18px; }
.scroll-card-body .table-wrap { overflow: visible; } /* a rolagem já é feita pelo .scroll-card-body por fora — dois containers rolando juntos quebravam o cabeçalho fixo */
.scroll-card-body .table { border-collapse: separate; border-spacing: 0; } /* "collapse" + sticky vaza conteúdo por trás do cabeçalho no Chrome — "separate" corrige */
.scroll-card-body .table thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; box-shadow: 0 1px 0 var(--border); }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
.table tr:hover td { background: var(--surface-2); }

/* ---------- Instance / QR ---------- */
.instance-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.instance-groups { color: var(--muted); font-size: 12px; margin: 8px 0 12px; }
.qr-wrap { text-align: center; }
.qr-box { background: #fff; border-radius: 14px; padding: 14px; max-width: 280px; margin: 0 auto 14px; min-height: 280px; display: flex; align-items: center; justify-content: center; }
.qr-img { width: 100%; max-width: 250px; display: block; }
.qr-loading { color: #555; font-size: 13px; }
.qr-connected { color: var(--success); font-weight: 700; font-size: 18px; }

/* ---------- Campaign form ---------- */
.groups-box { max-height: 240px; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; padding: 10px; background: var(--bg-2); margin-bottom: 8px; }
.group-check { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 8px; font-size: 13px; }
.group-check:hover { background: var(--surface); }
.variation-row { background: var(--bg-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin-bottom: 10px; }
.variation-row-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.variation-item { border-left: 3px solid var(--primary); padding: 8px 12px; margin-bottom: 8px; background: var(--bg-2); border-radius: 0 10px 10px 0; }
.variation-media { max-width: 120px; border-radius: 8px; margin-bottom: 6px; display: block; }

/* Carrossel de variações — um slide por vez, com transição suave */
.var-carousel { overflow: hidden; border-radius: 10px; }
.var-carousel-track { display: flex; transition: transform .35s ease; }
.var-carousel-slide {
  flex: 0 0 100%; box-sizing: border-box; border-left: 3px solid var(--primary);
  padding: 10px 14px; background: var(--bg-2); border-radius: 0 10px 10px 0; min-height: 60px;
}
.var-carousel-controls { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.var-carousel-dots { display: flex; gap: 6px; }
.var-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); cursor: pointer; transition: .15s; }
.var-dot.active { background: var(--primary); width: 20px; border-radius: 4px; }

.empty-state { text-align: center; padding: 40px 20px; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); margin-bottom: 18px; }
.empty-state.small { padding: 24px; }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.step { display: flex; gap: 12px; }
.step-num { flex-shrink: 0; width: 32px; height: 32px; border-radius: 50%; background: var(--grad); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; }
.step p { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: radial-gradient(ellipse at top, #132647 0%, var(--bg) 60%); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 36px; width: 100%; max-width: 400px; box-shadow: var(--shadow); text-align: center; position: relative; }
.login-logo-wrap { background: #fff; width: 90px; height: 90px; border-radius: 22px; margin: 0 auto 16px; display: flex; align-items: center; justify-content: center; padding: 8px; box-shadow: 0 8px 30px rgba(33,150,243,.4); }
.login-logo { width: 100%; object-fit: contain; }
.login-card h1 { font-size: 24px; background: var(--grad); -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent; }
.login-sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-form { text-align: left; display: flex; flex-direction: column; gap: 14px; }
.login-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-hint { margin-top: 18px; font-size: 12px; color: var(--muted); }
.theme-toggle-login { position: absolute; top: 14px; right: 14px; }

/* ---------- WhatsApp float ---------- */
.whatsapp-float {
  position: fixed; bottom: 22px; right: 22px; z-index: 60;
  width: 58px; height: 58px; border-radius: 50%; background: #25d366; color: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 6px 20px rgba(37,211,102,.5);
  animation: waPulse 2s infinite;
}
@keyframes waPulse {
  0% { box-shadow: 0 0 0 0 rgba(37,211,102,.5); }
  70% { box-shadow: 0 0 0 16px rgba(37,211,102,0); }
  100% { box-shadow: 0 0 0 0 rgba(37,211,102,0); }
}

/* ---------- Responsivo ---------- */
@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .steps { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-overlay { display: block; }
  .main-col { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .user-name { display: none; }
}
@media (max-width: 640px) {
  .content { padding: 14px; }
  .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
  .topbar { padding: 10px 14px; }
  .topbar-title { font-size: 14px; }
  .user-role { display: none; }
  .login-card { padding: 24px; }
  .whatsapp-float { width: 52px; height: 52px; bottom: 16px; right: 16px; }
}