/* =========================================================
   Disparo WhatsApp — tema
   ========================================================= */
:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e4e8ee;
  --border-strong: #d3d9e2;
  --text: #0f172a;
  --text-2: #334155;
  --muted: #64748b;
  --primary: #059669;
  --primary-600: #047857;
  --primary-50: #ecfdf5;
  --primary-100: #d1fae5;
  --accent: #25d366;
  --danger: #dc2626;
  --danger-50: #fef2f2;
  --warning: #b45309;
  --warning-50: #fffbeb;
  --info: #2563eb;
  --info-50: #eff6ff;
  --sidebar: #0b1f19;
  --sidebar-2: #10291f;
  --sidebar-text: #a7c4b8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 16px rgba(15, 23, 42, .06);
  --shadow-lg: 0 20px 50px rgba(15, 23, 42, .18);
  --ring: 0 0 0 4px rgba(5, 150, 105, .15);
  --sidebar-w: 248px;
  font-family: "Inter", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
[hidden] { display: none !important; }
h2 { margin: 0; font-size: 22px; font-weight: 700; letter-spacing: -.02em; }
h3 { margin: 0 0 10px; font-size: 15px; font-weight: 650; letter-spacing: -.01em; }
h4 { margin: 4px 0 8px; font-size: 14px; }
code { background: #eef2f6; padding: 2px 6px; border-radius: 6px; font-size: 12.5px; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); font-weight: normal; }
.hint { color: var(--muted); font-size: 12.5px; margin: 6px 0; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0 10px; }

/* permissões por perfil */
body:not(.is-admin) [data-admin] { display: none !important; }
body.is-admin .user-only { display: none !important; }
body:not(.can-templates) [data-tpl-manager] { display: none !important; }

/* =========================================================
   Estrutura: menu lateral + conteúdo
   ========================================================= */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); z-index: 40;
  display: flex; flex-direction: column;
  background: linear-gradient(180deg, var(--sidebar) 0%, #0d2a20 100%);
  color: var(--sidebar-text); padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 8px 22px; color: #fff; }
.brand b { display: block; font-size: 17px; letter-spacing: -.02em; }
.brand small { display: block; font-size: 11.5px; color: var(--sidebar-text); }
.logo {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--primary)); color: #fff;
  box-shadow: 0 6px 18px rgba(37, 211, 102, .35);
}
.logo svg { width: 22px; height: 22px; }
.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; flex: 1; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #6f8f82; padding: 14px 12px 6px; }
.tab {
  display: flex; align-items: center; gap: 12px; width: 100%; text-align: left;
  background: transparent; border: 0; color: var(--sidebar-text); font: inherit; font-weight: 500;
  padding: 10px 12px; border-radius: 10px; cursor: pointer; transition: background .15s, color .15s;
}
.tab:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.tab.active { background: rgba(37, 211, 102, .14); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
.tab.active svg { color: var(--accent); }
.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 14px; margin-top: 10px; }
.user-card { display: flex; align-items: center; gap: 10px; padding: 4px 6px 10px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; flex: none;
  background: #1e4a3a; color: #d1fae5; font-weight: 700; font-size: 13px;
}
.user-meta { min-width: 0; }
.user-meta #user-name { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta small { color: var(--sidebar-text); font-size: 12px; }
.user-actions { display: flex; gap: 6px; }
.side-btn {
  flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  background: rgba(255, 255, 255, .06); border: 0; color: var(--sidebar-text); font: inherit; font-size: 12.5px;
  padding: 8px; border-radius: 9px; cursor: pointer;
}
.side-btn svg { width: 15px; height: 15px; }
.side-btn:hover { background: rgba(255, 255, 255, .12); color: #fff; }

.shell { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.appbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  padding: 12px 32px; background: rgba(243, 245, 248, .85); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.page-title { font-weight: 600; color: var(--text-2); }
.account { margin-left: auto; font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.menu-toggle { display: none; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 7px; cursor: pointer; color: var(--text); }
.backdrop { display: none; }
main { width: 100%; max-width: 1280px; margin: 0 auto; padding: 28px 32px 64px; }

/* =========================================================
   Blocos
   ========================================================= */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.toolbar.small { margin-bottom: 12px; }
.toolbar.small h3 { margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.grid-4 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; }
.top-gap { margin-top: 18px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.empty {
  text-align: center; color: var(--muted); padding: 56px 20px; background: var(--surface);
  border: 1.5px dashed var(--border-strong); border-radius: var(--radius);
}
.alert { background: var(--danger-50); color: #991b1b; border: 1px solid #fecaca; border-radius: var(--radius-sm); padding: 10px 12px; font-size: 13px; margin: 10px 0; }

/* =========================================================
   Formulários
   ========================================================= */
label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: 13px; color: var(--text-2); margin-bottom: 12px; }
.stack-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; min-width: 0; }
.stack-field > span { font-weight: 600; font-size: 13px; color: var(--text-2); }
.stack-field .hint { margin: 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; margin-top: 10px; }
.inline-field { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
input, select, textarea {
  font: inherit; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: #fff; color: var(--text); min-width: 0; transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: #94a3b8; }
input:hover, select:hover, textarea:hover { border-color: #b8c2cf; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 16px; height: 16px; padding: 0; box-shadow: none; }
input[type="file"] { padding: 8px; background: var(--surface-2); }
textarea { resize: vertical; width: 100%; line-height: 1.5; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin: 0 0 16px; display: flex; flex-direction: column; gap: 10px; background: var(--surface-2); }
legend { font-weight: 650; padding: 0 6px; color: var(--text-2); }

.btn {
  font: inherit; font-weight: 600; font-size: 13.5px; border: 1px solid var(--border-strong); background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: var(--radius-sm); cursor: pointer; text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap;
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, transform .05s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); border-color: #b8c2cf; }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 1px 2px rgba(5, 150, 105, .3), 0 4px 12px rgba(5, 150, 105, .2); }
.btn.primary:hover { background: var(--primary-600); border-color: var(--primary-600); }
.btn.danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn.danger:hover { background: var(--danger-50); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: rgba(15, 23, 42, .05); }
.btn.small { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn.block { width: 100%; padding: 12px 16px; font-size: 14.5px; }
.btn:disabled { opacity: .55; cursor: default; }
.linklike { background: none; border: 0; color: var(--primary); cursor: pointer; padding: 0; font: inherit; font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }

/* =========================================================
   Tabelas
   ========================================================= */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .table-wrap { box-shadow: none; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 12px 14px; border-bottom: 1px solid #eef1f5; vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; transition: background .12s; }
tr.clickable:hover td { background: #f6fbf9; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.err { color: #b91c1c; font-size: 12.5px; max-width: 420px; cursor: help; }
.err-hint { color: var(--muted); font-size: 12px; margin-top: 3px; }
.failure-list { display: grid; gap: 8px; }
.failure-item { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 10px 12px;
  border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); cursor: help; }
.failure-item .hint { margin: 2px 0 0; }
.failure-item.clickable-item { cursor: pointer; transition: border-color .15s, background .15s; }
.failure-item.clickable-item:hover { border-color: #9fb3c4; background: #fff; }
.failure-item.selected { border-color: var(--primary); background: var(--primary-50); box-shadow: inset 3px 0 0 var(--primary); }
.failure-count { font-size: 18px; font-weight: 700; color: #b91c1c; font-variant-numeric: tabular-nums; }
td.check, th.check { width: 40px; }
td.fields { color: var(--muted); font-size: 12.5px; max-width: 280px; }
td.detail { font-size: 12.5px; color: var(--muted); max-width: 420px; word-break: break-word; }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 8px; margin-top: 14px; }
#msg-search, #audit-search, #template-search, #optout-search { min-width: 260px; }

/* =========================================================
   Selos, progresso e indicadores
   ========================================================= */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: #f1f5f9; color: #475569; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .7; }
.b-running, .b-sending, .b-pending, .b-scheduled { background: var(--info-50); color: #1d4ed8; }
.b-finished, .b-approved, .b-delivered, .b-read, .b-green { background: var(--primary-50); color: #047857; }
.b-sent { background: #f0fdfa; color: #0f766e; }
.b-paused, .b-yellow, .b-in_appeal { background: var(--warning-50); color: var(--warning); }
.b-failed, .b-rejected, .b-cancelled, .b-disabled, .b-red { background: var(--danger-50); color: #b91c1c; }
.b-skipped, .b-draft { background: #f1f5f9; color: #475569; }

.progress { display: inline-block; width: 120px; height: 8px; background: #e8edf2; border-radius: 99px; overflow: hidden; vertical-align: middle; margin-right: 8px; }
.progress > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 99px; }
.progress.big { width: 100%; height: 10px; margin: 16px 0 0; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.stat .p { color: var(--muted); font-size: 12.5px; font-weight: 600; margin-left: 4px; }
.stat.highlight { background: linear-gradient(135deg, #064e3b, #047857); border-color: transparent; color: #fff; grid-column: span 2; }
.stat.highlight .l, .stat.highlight .p { color: #a7f3d0; }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 6px; }
.stat.highlight .sub { color: #d1fae5; }

.detail-head { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; align-items: flex-start; }
.detail-head h2 { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.detail-head .muted { margin-top: 6px; line-height: 1.7; }
.cost-cell { font-weight: 600; font-variant-numeric: tabular-nums; }

/* =========================================================
   Campanha: mapeamento e agendamento
   ========================================================= */
.slot-row { display: grid; grid-template-columns: minmax(160px, 220px) minmax(160px, 1fr) minmax(160px, 1fr); gap: 10px; align-items: center; margin-bottom: 10px; }
.slot-label { font-weight: 600; font-size: 13px; color: var(--text-2); }
.audience-count { font-weight: 600; color: var(--primary-600); }
.audience-count.warn { color: var(--danger); }
/* quantidade por envio e quem já recebeu o template (fatiar a agenda em vários dias) */
.max-contacts { display: flex; align-items: center; gap: 10px; margin-top: 8px; }
.max-contacts input { width: 140px; }
.audience-plan { margin-top: 8px; padding: 9px 12px; border-radius: var(--radius-sm); background: var(--primary-50); color: var(--text); font-size: 13px; }
.audience-plan.warn { background: #fef2f2; color: var(--danger); }
.when { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.when .check { margin: 0; }
.when input[type="datetime-local"] { margin-left: 26px; }

/* =========================================================
   Templates e pré-visualização WhatsApp
   ========================================================= */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 18px; }
.tpl-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); transition: box-shadow .15s, transform .15s; }
.tpl-card:hover { box-shadow: 0 8px 28px rgba(15, 23, 42, .1); transform: translateY(-1px); }
.tpl-card-head { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.tpl-card-head b { word-break: break-all; }
.tpl-card-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: auto; }
.tpl-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; }
.tpl-side { position: sticky; top: 80px; align-self: start; }
.btn-row { display: grid; grid-template-columns: 110px 1fr 1fr 1fr auto; gap: 6px; align-items: center; }
.btn-row[data-type="QUICK_REPLY"] { grid-template-columns: 110px 1fr auto; }
.btn-row[data-type="PHONE_NUMBER"] { grid-template-columns: 110px 1fr 1fr auto; }
.btn-type { font-size: 12px; color: var(--muted); font-weight: 600; }
#body-examples { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 8px; }
#body-examples label { margin: 0; }

.wa-preview {
  background-color: #efeae2; border-radius: var(--radius); padding: 18px; min-height: 130px;
  background-image: radial-gradient(rgba(0, 0, 0, .035) 1px, transparent 1px); background-size: 14px 14px;
}
.wa-preview.small { padding: 12px; min-height: 0; max-height: 330px; overflow: auto; }
.wa-bubble { background: #fff; border-radius: 0 10px 10px 10px; max-width: 330px; box-shadow: 0 1px .5px rgba(0, 0, 0, .13); overflow: hidden; }
.wa-inner { padding: 8px 10px 6px; }
.wa-head { font-weight: 700; margin-bottom: 4px; }
.wa-media { background: #d6dde3; color: #475569; text-align: center; padding: 30px 8px; font-size: 13px; font-weight: 700; letter-spacing: .04em; }
.wa-media small { display: block; font-weight: normal; word-break: break-all; margin-top: 4px; letter-spacing: 0; }
.wa-media-img { display: block; width: 100%; max-height: 220px; object-fit: cover; }
.wa-body { word-wrap: break-word; line-height: 1.45; color: #111b21; }
.wa-footer { color: #8696a0; font-size: 12px; margin-top: 6px; }
.wa-time { text-align: right; color: #8696a0; font-size: 11px; }
.wa-buttons { border-top: 1px solid #eef0f2; }
.wa-btn { text-align: center; color: #0a7cff; padding: 9px; border-top: 1px solid #eef0f2; font-size: 13.5px; font-weight: 500; }
.wa-btn:first-child { border-top: 0; }
.var { background: #d9fdd3; border-radius: 4px; padding: 0 3px; }

/* =========================================================
   Contatos e tags
   ========================================================= */
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.chip {
  display: inline-flex; flex-direction: row; align-items: center; gap: 7px; padding: 6px 12px;
  border: 1px solid var(--border-strong); border-radius: 999px; background: #fff; cursor: pointer;
  font-size: 13px; font-weight: 500; margin: 0; user-select: none; transition: border-color .15s, background .15s;
}
.chip input { margin: 0; }
.chip:hover { border-color: #9fb3c4; }
.chip:has(input:checked) { border-color: var(--primary); background: var(--primary-50); }
.chip .count { color: var(--muted); font-size: 12px; }
.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; margin: 1px 3px 1px 0; white-space: nowrap; }
.tag-gray { background: #f1f5f9; color: #475569; }
.tag-blue { background: #eff6ff; color: #1d4ed8; }
.tag-green { background: #ecfdf5; color: #047857; }
.tag-yellow { background: #fefce8; color: #a16207; }
.tag-orange { background: #fff7ed; color: #c2410c; }
.tag-red { background: #fef2f2; color: #b91c1c; }
.tag-purple { background: #f5f3ff; color: #6d28d9; }
.tag-teal { background: #f0fdfa; color: #0f766e; }
.filters { margin-bottom: 14px; }
.filters input[type="search"] { min-width: 280px; }
.bulk-bar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; background: var(--primary-50);
  border: 1px solid #a7f3d0; border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px;
}
.bulk-bar #bulk-count { font-weight: 700; color: var(--primary-600); margin-right: 6px; }
.select-all-hint { background: var(--warning-50); border: 1px solid #fde68a; padding: 9px 14px; border-radius: var(--radius-sm); margin-bottom: 10px; font-size: 13px; }
.select-all-hint.warn { background: #fef2f2; border-color: #fecaca; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.select-all-hint.warn > span { flex: 1 1 320px; }
/* situação do WhatsApp do contato (pelo histórico de envios) */
.wa-st { display: inline-block; margin-top: 3px; font-size: 11.5px; white-space: nowrap; }
.wa-st.ok { color: #047857; }
.wa-st.invalid { color: #b91c1c; font-weight: 600; }
.wa-st.unknown { color: var(--muted); }
#ninth-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.ok-text { color: var(--primary-600); }

/* =========================================================
   Segurança
   ========================================================= */
.checks { display: grid; gap: 10px; }
.check-item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; border-radius: var(--radius-sm); background: var(--surface-2); }
.check-item .dot { width: 22px; height: 22px; border-radius: 50%; flex: none; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; font-weight: 700; }
.check-item .dot.ok { background: var(--primary); }
.check-item .dot.bad { background: #d97706; }
.check-item .hint { margin: 2px 0 0; }
.switch { flex-direction: row; align-items: center; gap: 8px; margin: 0; font-weight: 600; cursor: pointer; }
.qr { width: 200px; height: 200px; background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
.qr svg { width: 100%; height: 100%; stroke: none; fill: initial; }

/* =========================================================
   Janelas e avisos
   ========================================================= */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(580px, 94vw); box-shadow: var(--shadow-lg); }
dialog::backdrop { background: rgba(15, 23, 42, .5); backdrop-filter: blur(3px); }
.dlg-body { padding: 24px; display: flex; flex-direction: column; gap: 6px; }
.dlg-body > h3 { font-size: 18px; margin-bottom: 12px; }
.dlg-body > label { margin-bottom: 4px; }
.dlg-actions { display: flex; gap: 8px; align-items: center; margin-top: 16px; }
.spacer { flex: 1; }
.field-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-bottom: 6px; }
.tag-row { display: grid; grid-template-columns: 1fr 130px 60px auto auto; gap: 6px; align-items: center; margin-bottom: 6px; }

#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: #0f172a; color: #fff; padding: 12px 20px; border-radius: 12px; max-width: min(640px, 92vw);
  box-shadow: var(--shadow-lg); font-weight: 500; animation: toast-in .2s ease-out;
}
#toast.err { background: #b91c1c; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* =========================================================
   Login
   ========================================================= */
.login-page { min-height: 100vh; background: var(--bg); }
.login-wrap { display: grid; grid-template-columns: 1.1fr 1fr; min-height: 100vh; }
.login-hero {
  position: relative; overflow: hidden; color: #e7f7f0; padding: 48px 56px; display: flex; flex-direction: column;
  background:
    radial-gradient(800px 400px at 110% 0%, rgba(37, 211, 102, .25), transparent 60%),
    radial-gradient(600px 400px at -10% 110%, rgba(16, 185, 129, .25), transparent 60%),
    linear-gradient(160deg, #0b1f19 0%, #0f3a2c 100%);
}
.login-hero .brand { padding: 0; }
.login-hero h1 { font-size: 38px; line-height: 1.15; letter-spacing: -.03em; margin: auto 0 14px; max-width: 520px; color: #fff; }
.login-hero p { color: #a7c4b8; font-size: 16px; max-width: 480px; margin: 0 0 28px; }
.hero-points { list-style: none; padding: 0; margin: 0 0 auto; display: grid; gap: 10px; color: #d1fae5; }
.hero-points li { display: flex; align-items: center; gap: 10px; }
.hero-points svg { color: var(--accent); }
.hero-chat { position: absolute; right: 48px; top: 110px; display: grid; gap: 10px; width: 260px; opacity: .95; }
.hero-chat .msg { background: #fff; color: #111b21; border-radius: 0 12px 12px 12px; padding: 10px 12px; font-size: 13px; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.hero-chat .msg.out { background: #d9fdd3; border-radius: 12px 0 12px 12px; justify-self: end; width: 80%; }
.hero-chat .msg small { display: block; text-align: right; color: #667781; font-size: 11px; margin-top: 4px; }
.login-panel { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 24px; }
.login-card { width: 100%; max-width: 380px; }
.login-card h2 { font-size: 26px; margin-bottom: 6px; }
.login-card .sub { color: var(--muted); margin: 0 0 26px; }
.login-card label { margin-bottom: 16px; }
.password-field { position: relative; display: flex; }
.password-field input { flex: 1; padding-right: 44px; }
.password-field button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 8px; }
.password-field button:hover { color: var(--text); background: var(--surface-2); }
.login-foot { color: var(--muted); font-size: 12.5px; margin-top: 28px; display: flex; align-items: center; gap: 6px; }
.login-foot svg { width: 14px; height: 14px; color: var(--primary); }
.code-input { text-align: center; font-size: 24px; letter-spacing: .4em; font-weight: 700; padding: 12px; }

/* =========================================================
   Dashboard e gráficos
   ========================================================= */
.chart { position: relative; min-height: 230px; --series-1: #059669; --series-2: #2a78d6; --grid: #e8ecf1; --axis: #cbd3dc; }
.chart svg { width: 100%; height: auto; display: block; stroke: none; fill: none; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .peak { fill: var(--text-2); font-size: 11.5px; font-weight: 600; }
.chart .bar { transition: opacity .12s; }
.chart.hovering .bar { opacity: .35; }
.chart.hovering .bar.on { opacity: 1; }
.chart-empty { display: grid; place-items: center; min-height: 200px; color: var(--muted); }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5; background: #0f172a; color: #fff; border-radius: 10px;
  padding: 10px 12px; font-size: 12.5px; box-shadow: var(--shadow-lg); min-width: 170px; line-height: 1.6;
}
.chart-tip b { display: block; margin-bottom: 2px; }
.chart-tip .k { display: flex; justify-content: space-between; gap: 14px; }
.chart-tip .k span:last-child { font-variant-numeric: tabular-nums; font-weight: 600; }
.chart-tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }
.table-toggle summary { cursor: pointer; font-weight: 600; color: var(--text-2); }
.nav-badge { margin-left: auto; background: #dc2626; color: #fff; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; }
.meter { display: flex; align-items: center; gap: 8px; min-width: 150px; }
.meter-track { flex: 1; height: 8px; border-radius: 99px; background: #d1fae5; overflow: hidden; }
.meter-track > span { display: block; height: 100%; border-radius: 99px; background: var(--primary); }
.meter.warn .meter-track { background: #fef3c7; } .meter.warn .meter-track > span { background: #d97706; }
.meter.crit .meter-track { background: #fee2e2; } .meter.crit .meter-track > span { background: #dc2626; }
.meter small { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.alerts-card h3 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.alert-item { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); }
.alert-item:first-of-type { border-top: 0; }
.alert-icon { width: 26px; height: 26px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 13px; }
.alert-icon.critical { background: #dc2626; } .alert-icon.warning { background: #d97706; } .alert-icon.info { background: #2563eb; }
.alert-item .when { color: var(--muted); font-size: 12px; }

/* =========================================================
   Atendimento
   ========================================================= */
body.inbox-mode main { max-width: none; padding: 16px 20px; }
.inbox {
  display: grid; grid-template-columns: 360px 1fr; height: calc(100vh - 57px - 32px); min-height: 480px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
}
.inbox-side { display: flex; flex-direction: column; border-right: 1px solid var(--border); min-height: 0; }
.inbox-side-head { padding: 14px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.inbox-filters { display: grid; grid-template-columns: 1fr 130px; gap: 6px; }
.inbox-filters input, .inbox-filters select { min-width: 0; padding: 8px 10px; font-size: 13px; }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button {
  border: 0; background: transparent; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted);
  padding: 7px 4px; border-radius: 8px; cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 5px;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.seg-count:empty { display: none; }
.seg-count { background: var(--primary); color: #fff; font-size: 10.5px; border-radius: 99px; padding: 0 6px; line-height: 16px; }
.seg-count.warn { background: #dc2626; }
.conv-list { overflow-y: auto; flex: 1; }
.conv-item {
  display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 12px 14px; cursor: pointer;
  border-bottom: 1px solid var(--border); align-items: start;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: var(--primary-50); box-shadow: inset 3px 0 0 var(--primary); }
.conv-item .avatar { width: 40px; height: 40px; background: #d1fae5; color: #065f46; }
.conv-main { min-width: 0; }
.conv-name { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-prev { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 2px; }
.conv-meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 5px; font-size: 11.5px; color: var(--muted); }
.conv-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 11.5px; color: var(--muted); white-space: nowrap; }
.unread { background: var(--accent); color: #053b22; font-weight: 700; font-size: 11px; border-radius: 99px; min-width: 20px; text-align: center; padding: 1px 6px; }
.pill { display: inline-block; border-radius: 99px; padding: 1px 8px; background: #f1f5f9; color: #475569; font-size: 11px; font-weight: 600; }
.pill.queue { background: var(--warning-50); color: var(--warning); }
.pill.closed { background: #f1f5f9; color: #475569; }
.pill.window-off { background: var(--danger-50); color: #b91c1c; }
.pill.window-on { background: var(--primary-50); color: #047857; }
.conv-empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.inbox-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: #efeae2; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); max-width: 360px; padding: 20px; }
.chat-empty svg { width: 44px; height: 44px; color: #94a3b8; }
.chat-pane { display: flex; flex-direction: column; min-height: 0; height: 100%; overflow: hidden; }
.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.chat-head .avatar { background: #d1fae5; color: #065f46; }
.chat-title { min-width: 0; flex: 1; }
.chat-title b { font-size: 15px; }
.chat-title .hint { margin: 2px 0 0; }
.chat-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.chat-back { display: none; }
.chat-msgs { flex: 1 1 auto; min-height: 0; overscroll-behavior: contain; overflow-y: auto; padding: 18px 6%; display: flex; flex-direction: column; gap: 4px; }
.msg { max-width: min(560px, 78%); padding: 7px 10px 5px; border-radius: 10px; box-shadow: 0 1px .5px rgba(0, 0, 0, .13);
  background: #fff; color: #111b21; word-wrap: break-word; align-self: flex-start; position: relative; line-height: 1.45; }
.msg.out { align-self: flex-end; background: #d9fdd3; }
.msg.out.failed { background: #fee2e2; }
.msg.auto { background: #e7f3ff; }
.msg-text { white-space: pre-wrap; }
.msg-meta { display: flex; justify-content: flex-end; align-items: center; gap: 4px; color: #667781; font-size: 11px; margin-top: 2px; }
.msg-who { font-size: 11.5px; font-weight: 700; color: #047857; margin-bottom: 2px; }
.msg.auto .msg-who { color: #1d4ed8; }
.msg-tpl { font-size: 11px; font-weight: 700; color: #667781; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 3px; }
.msg-img { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; margin: -2px -4px 4px; cursor: zoom-in; }
.msg audio, .msg video { display: block; max-width: 100%; margin-bottom: 4px; }
.msg video { max-height: 320px; border-radius: 6px; }
.msg-file { display: flex; align-items: center; gap: 8px; background: rgba(0, 0, 0, .05); border-radius: 6px; padding: 8px 10px; margin-bottom: 4px;
  color: inherit; text-decoration: none; font-weight: 600; font-size: 13px; }
.msg-file:hover { background: rgba(0, 0, 0, .09); }
.msg-err { font-size: 12px; color: #b91c1c; margin-top: 4px; }
.msg-tick { font-size: 12px; letter-spacing: -3px; padding-right: 3px; }
.msg-tick.read { color: #53bdeb; }
.msg-system { align-self: center; background: #fff8c5; color: #54656f; font-size: 12px; border-radius: 8px; padding: 5px 12px;
  margin: 8px 0; text-align: center; box-shadow: 0 1px .5px rgba(0, 0, 0, .1); max-width: 90%; }
.day-sep { align-self: center; background: #fff; color: #54656f; font-size: 12px; border-radius: 8px; padding: 4px 12px; margin: 10px 0 6px; box-shadow: 0 1px .5px rgba(0, 0, 0, .1); }
.chat-compose { flex-shrink: 0; background: #f0f2f5; border-top: 1px solid var(--border); padding: 10px 14px; position: relative; }
.compose-form { display: flex; gap: 8px; align-items: flex-end; }
.compose-form textarea { flex: 1; resize: none; max-height: 160px; min-height: 42px; border-radius: 10px; }
.icon-btn { background: transparent; border: 0; padding: 9px; border-radius: 10px; cursor: pointer; color: #54656f; }
.icon-btn:hover { background: rgba(0, 0, 0, .06); color: var(--text); }
.icon-btn svg { width: 20px; height: 20px; }
.compose-notice { display: flex; align-items: center; gap: 12px; justify-content: space-between; flex-wrap: wrap; font-size: 13px; color: var(--text-2); }
.compose-file { position: absolute; left: 14px; right: 14px; bottom: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow); padding: 10px 12px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.compose-file img { max-height: 70px; border-radius: 6px; }
.compose-file input { flex: 1; min-width: 160px; }
.qr-popup { position: absolute; left: 14px; right: 14px; bottom: calc(100% + 6px); background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; box-shadow: var(--shadow-lg); max-height: 260px; overflow-y: auto; z-index: 5; }
.qr-item { padding: 9px 12px; cursor: pointer; border-top: 1px solid var(--border); }
.qr-item:first-child { border-top: 0; }
.qr-item:hover, .qr-item.sel { background: var(--primary-50); }
.qr-item b { color: var(--primary-600); }
.qr-item div { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qr-rows { display: grid; gap: 6px; max-height: 300px; overflow-y: auto; margin-bottom: 12px; }
.qr-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: start; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.qr-row .txt { color: var(--text-2); font-size: 13px; white-space: pre-wrap; }
.qr-form { border-top: 1px solid var(--border); padding-top: 12px; }
dialog.wide { width: min(860px, 96vw); }
/* chat interno */
.inbox-side-head > input[type="search"] { padding: 9px 12px; }
.avatar-wrap { position: relative; display: inline-block; }
.avatar-wrap .dot { position: absolute; right: 0; bottom: 0; width: 11px; height: 11px; border-radius: 50%; background: #94a3b8; border: 2px solid #fff; }
.avatar-wrap .dot.on { background: #22c55e; }
.avatar.team { background: var(--primary); color: #fff; }
.team-msgs { background: #f3f5f8; }
.team-msgs .msg.out { background: #dcfce7; }
.team-msgs .msg-who { color: #1d4ed8; }
.icon-btn.recording { color: #dc2626; background: #fee2e2; }
/* ligação */
.call-box {
  position: fixed; right: 20px; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); z-index: 60; width: 320px;
  background: #0b1f19; color: #e7f5ef; border-radius: 18px; padding: 16px; box-shadow: 0 18px 50px rgba(0, 0, 0, .35);
}
.call-box.ringing { animation: call-pulse 1.1s infinite; width: 380px; border: 2px solid #25d366; }
.call-box.ringing .call-head .avatar { animation: call-shake 1.1s infinite; }
.call-box.ringing .call-state b { font-size: 22px; color: #4ade80; }
.call-box.ringing .call-actions .btn { padding: 14px; font-size: 16px; font-weight: 700; }
@keyframes call-shake { 0%, 50%, 100% { transform: rotate(0); } 10%, 30% { transform: rotate(-12deg); } 20%, 40% { transform: rotate(12deg); } }
/* avisos: cartões na tela e faixa para ativar notificações */
.notify-stack { position: fixed; top: calc(64px + env(safe-area-inset-top, 0px)); right: 20px; z-index: 55; display: flex; flex-direction: column;
  gap: 10px; width: min(380px, calc(100vw - 32px)); pointer-events: none; }
.notify-card { pointer-events: auto; display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: start; background: var(--surface);
  border: 1px solid var(--border); border-left: 5px solid var(--accent); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow-lg);
  animation: notify-in .35s ease-out, notify-glow 1.2s ease-in-out 3; }
.notify-icon { font-size: 26px; line-height: 40px; text-align: center; background: var(--primary-50); border-radius: 50%; width: 40px; height: 40px; }
.notify-body { min-width: 0; }
.notify-body b { display: block; font-size: 14.5px; }
.notify-body div { color: var(--text-2); font-size: 13px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box;
  -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.notify-actions { grid-column: 2; display: flex; gap: 6px; }
@keyframes notify-in { from { transform: translateX(110%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes notify-glow { 50% { box-shadow: 0 0 0 6px rgba(37, 211, 102, .35), var(--shadow-lg); } }
.notify-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin: 12px 32px 0;
  padding: 12px 16px; border-radius: 12px; background: #fffbeb; border: 1px solid #fcd34d; color: #78350f; font-size: 13.5px; }
body:has(#notify-banner:not([hidden])) .inbox { height: calc(100vh - 57px - 32px - 64px); }
.update-banner { background: var(--primary-50); border-color: #6ee7b7; color: #065f46; }
.login-card .remember { margin: 4px 0 14px; font-size: 13px; }
.volume-field { flex-direction: row; align-items: center; gap: 10px; margin: 8px 0 0; }
.volume-field input { width: 200px; padding: 0; }
@media (max-width: 900px) { .notify-banner { margin: 10px 16px 0; } .notify-stack { right: 16px; top: 60px; } }
@keyframes call-pulse { 50% { box-shadow: 0 0 0 8px rgba(37, 211, 102, .25), 0 18px 50px rgba(0, 0, 0, .35); } }
.call-box:has(#call-video-wrap:not([hidden])) { width: 460px; }
.call-head { display: flex; align-items: center; gap: 12px; }
.call-head .avatar { width: 46px; height: 46px; background: #1e4a3a; color: #d1fae5; font-size: 15px; }
.call-who { min-width: 0; }
.call-who b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.call-who .hint { color: #a7c4b8; margin: 2px 0 0; }
.call-state { margin: 12px 0 10px; font-size: 13px; color: #a7c4b8; font-variant-numeric: tabular-nums; }
.call-state b { color: #fff; font-size: 20px; }
.call-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.call-actions .btn { flex: 1; justify-content: center; }
.call-btn-accept { background: #16a34a !important; border-color: #16a34a !important; color: #fff !important; }
.call-btn-end { background: #dc2626 !important; border-color: #dc2626 !important; color: #fff !important; }
.call-btn-muted { background: #f59e0b !important; border-color: #f59e0b !important; color: #fff !important; }
.call-video { position: relative; margin-top: 12px; border-radius: 12px; overflow: hidden; background: #000; aspect-ratio: 4 / 3; }
.call-video video { width: 100%; height: 100%; object-fit: cover; display: block; }
#call-local-video { position: absolute; right: 8px; bottom: 8px; width: 30%; height: auto; aspect-ratio: 4 / 3; border-radius: 8px; border: 2px solid #fff; }
.chat-call-btn svg { width: 15px; height: 15px; }
@media (max-width: 900px) { .call-box { left: 12px; right: 12px; width: auto; bottom: 12px; } }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #dc2626; animation: rec-pulse 1s infinite; }
@keyframes rec-pulse { 50% { opacity: .25; } }
/* cabeçalho da conversa no painel: o nome não fica espremido pelos botões (eles descem de linha) */
.chat-head .chat-title { min-width: 220px; }
body.pwa .chat-head .chat-title { min-width: 0; }
/* logo da empresa */
.brand-img { display: block; max-height: 46px; max-width: 200px; object-fit: contain; background: #fff; border-radius: 10px; padding: 5px 9px; }
.brand-sub b { display: block; font-size: 15px; color: #fff; line-height: 1.2; }
.brand-sub small { color: var(--sidebar-text); font-size: 11.5px; }
.sidebar .brand:has(.brand-img) { flex-direction: column; align-items: flex-start; gap: 8px; }
.login-hero .brand:has(.brand-img) { flex-direction: column; align-items: flex-start; gap: 10px; }
.login-hero .brand-img { max-height: 64px; max-width: 260px; }
.pwa-brand-logo { display: none; }
body.pwa .pwa-brand-logo:not([hidden]) { display: block; height: 30px; max-width: 110px; object-fit: contain; background: #fff; border-radius: 7px; padding: 2px 6px; }
.company-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
.brand-preview { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.brand-preview-side { background: linear-gradient(180deg, var(--sidebar) 0%, #0d2a20 100%); border-radius: 12px; padding: 18px; min-width: 240px; }
.brand-preview-side .brand-img + .brand-sub { margin-top: 8px; }
.brand-preview-icon { text-align: center; }
.brand-preview-icon canvas { width: 112px; height: 112px; border-radius: 24px; box-shadow: var(--shadow); display: block; margin-bottom: 4px; }
@media (max-width: 900px) { .company-grid { grid-template-columns: 1fr; } }
.app-open-box { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; margin: 10px 0 14px; }
.app-open-box .check { margin-top: 0; }
/* setores */
.inbox-filters #inbox-sector { grid-column: 1 / -1; }
.pill.sector { background: #eff6ff; color: #1d4ed8; }
.pill.choosing { background: var(--warning-50); color: var(--warning); }
.sector-rows { display: grid; gap: 8px; margin-bottom: 14px; }
.sector-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: start; padding: 12px 14px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.sector-row.inactive { opacity: .6; }
.sector-row .who { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 4px; }
.sector-form { border-top: 1px solid var(--border); padding-top: 14px; }
/* integrações (webhook → chat interno) */
.avatar.bot { background: #fff7ed; color: #c2410c; }
.avatar.bot svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }
.team-msgs .msg.bot { background: #fffbeb; border-left: 3px solid #f59e0b; }
.team-msgs .msg.bot .msg-who { color: #b45309; }
.hook-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: start; margin-bottom: 10px; }
.hook-card.inactive { opacity: .65; }
.hook-card .who { margin: 6px 0; display: flex; flex-wrap: wrap; gap: 4px; }
.hook-actions { flex-wrap: wrap; justify-content: flex-end; }
.hook-pick { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; margin: 6px 0 10px; }
.hook-pick h4 { margin: 0 0 6px; }
.hook-url { display: flex; gap: 8px; }
.hook-url input { flex: 1; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.hook-example { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 10px; overflow-x: auto; font-size: 12px;
  white-space: pre; }
@media (max-width: 700px) { .hook-card, .hook-pick { grid-template-columns: 1fr; } .hook-actions { justify-content: flex-start; } }
.agenda-results { display: grid; gap: 4px; max-height: 300px; overflow-y: auto; margin-bottom: 6px; }
.agenda-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; cursor: pointer; font: inherit; }
.agenda-item:hover { border-color: var(--primary); background: var(--primary-50); }
.agenda-item .avatar { width: 34px; height: 34px; background: #d1fae5; color: #065f46; font-size: 12px; }
.agenda-item b { display: block; }
.agenda-item small { color: var(--muted); }
.wa-btn { white-space: nowrap; }
.agenda-pick { margin: 0 0 0 8px; flex-direction: row; align-items: center; gap: 8px; }
.agenda-pick select { min-width: 220px; }
.inbox-dash { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 18px; }
.hours-grid { display: grid; gap: 6px; margin-bottom: 8px; }
.hours-row { display: grid; grid-template-columns: 110px 90px 1fr; gap: 10px; align-items: center; }
.hours-row label { margin: 0; flex-direction: row; align-items: center; gap: 6px; font-weight: 500; }
.hours-row .times { display: flex; gap: 6px; align-items: center; }
.hours-row input[type="time"] { padding: 6px 8px; }

/* =========================================================
   App de atendimento (PWA, /app): só Atendimento e Chat interno
   ========================================================= */
.pwa-nav { display: none; }
body.pwa { --pwa-nav-h: 62px; background: var(--bg); overscroll-behavior: none; height: 100dvh; overflow: hidden; }
/* a lista/conversa ocupa exatamente o espaço que sobra: só as mensagens rolam, cabeçalho e campo de texto ficam parados */
.inbox { grid-template-rows: minmax(0, 1fr); }
.inbox-side, .inbox-chat { min-height: 0; overflow: hidden; }
.chat-head { flex-shrink: 0; position: sticky; top: 0; z-index: 3; }
body.pwa .sidebar, body.pwa .menu-toggle, body.pwa .backdrop, body.pwa #account { display: none !important; }
/* layout flexível: barra do topo + faixa (se houver) + tela, sempre cabendo na altura do aparelho */
body.pwa .shell { margin-left: 0; height: 100dvh; min-height: 0;
  padding-bottom: calc(var(--pwa-nav-h) + env(safe-area-inset-bottom, 0px)); }
body.pwa main { flex: 1; min-height: 0; display: flex; flex-direction: column; }
body.pwa main > .view:not([hidden]) { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow-y: auto; }
body.pwa main > #view-inbox:not([hidden]), body.pwa main > #view-team:not([hidden]) { overflow: hidden; }
body.pwa .appbar { padding: calc(10px + env(safe-area-inset-top, 0px)) 16px 10px; background: var(--sidebar); border-bottom: 0; }
body.pwa .page-title { display: block !important; color: #fff; font-size: 17px; font-weight: 700; }
body.pwa .appbar #pwa-install { margin-left: auto; }
body.pwa main { padding: 0; max-width: none; }
body.pwa .inbox { border-radius: 0; border: 0; box-shadow: none; height: auto; flex: 1; min-height: 0; }
body.pwa .notify-banner { margin: 8px 10px; padding: 10px 12px; font-size: 13px; }
body.pwa .chat-actions { flex-wrap: nowrap; overflow-x: auto; max-width: 100%; scrollbar-width: none; }
body.pwa .chat-actions .btn { white-space: nowrap; }
body.pwa .pwa-nav {
  display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 45; background: var(--surface);
  border-top: 1px solid var(--border); padding-bottom: env(safe-area-inset-bottom, 0px); height: calc(var(--pwa-nav-h) + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -4px 16px rgba(15, 23, 42, .06);
}
.pwa-tab { flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  background: none; border: 0; font: inherit; font-size: 11.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.pwa-tab svg { width: 24px; height: 24px; }
.pwa-tab.active { color: var(--primary-600); }
.pwa-tab.active svg { stroke-width: 2.4; }
.pwa-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 19px; height: 19px; padding: 0 5px; border-radius: 99px;
  background: #dc2626; color: #fff; font-size: 11px; font-style: normal; font-weight: 700; line-height: 19px; text-align: center; }
body.pwa .call-box { bottom: calc(var(--pwa-nav-h) + 12px + env(safe-area-inset-bottom, 0px)); }
body.pwa .notify-stack { top: calc(64px + env(safe-area-inset-top, 0px)); }
body.pwa .chat-head { padding: 8px 12px; }
body.pwa .chat-compose { padding-bottom: 10px; }
@media (max-width: 900px) {
  body.pwa .chat-actions .btn { padding: 6px 9px; }
  body.pwa .inbox-side-head .row .btn { flex: 1; }
}

/* =========================================================
   App: conversa no estilo WhatsApp (tela cheia, cabeçalho e barra de digitação fixos)
   ========================================================= */
body.pwa.pwa-chat .appbar, body.pwa.pwa-chat .pwa-nav, body.pwa.pwa-chat #notify-banner, body.pwa.pwa-chat #update-banner { display: none !important; }
body.pwa.pwa-chat .shell { padding-bottom: 0; }
body.pwa .chat-head {
  flex-wrap: nowrap; gap: 6px; padding: 8px 6px 8px 2px; background: #fff; border-bottom: 0;
  box-shadow: 0 1px 3px rgba(11, 20, 26, .12); min-height: 60px;
}
body.pwa.pwa-chat .chat-head { padding-top: calc(8px + env(safe-area-inset-top, 0px)); }
.wa-back, .wa-icon { background: none; border: 0; color: #111b21; cursor: pointer; border-radius: 50%; display: grid; place-items: center; flex: none; }
.wa-back { padding: 8px 4px 8px 8px; }
.wa-back svg, .wa-icon svg { width: 24px; height: 24px; stroke-width: 2.2; }
.wa-icon { padding: 10px; }
.wa-icon:disabled { opacity: .35; }
.wa-icon:active, .wa-back:active { background: rgba(11, 20, 26, .08); }
body.pwa .chat-head .avatar { width: 42px; height: 42px; font-size: 14px; }
body.pwa .chat-head .avatar-wrap .avatar { width: 42px; height: 42px; }
body.pwa .chat-title { min-width: 0; flex: 1; }
body.pwa .chat-title b { display: block; font-size: 17px; font-weight: 600; color: #111b21; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
body.pwa .chat-title .hint { font-size: 13px; color: #667781; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 1px 0 0; }
.wa-head-actions { display: flex; align-items: center; position: relative; flex: none; }
.wa-menu { position: absolute; right: 2px; top: 46px; z-index: 30; min-width: 230px; background: #fff; border-radius: 10px; padding: 6px 0;
  box-shadow: 0 4px 22px rgba(11, 20, 26, .22); }
.wa-menu button { display: block; width: 100%; text-align: left; padding: 13px 20px; border: 0; background: none; font: inherit; font-size: 15px;
  color: #111b21; cursor: pointer; }
.wa-menu button:active, .wa-menu button:hover { background: #f5f6f6; }
.wa-menu button.danger { color: #dc2626; }
/* fundo da conversa e balões como no WhatsApp */
body.pwa .chat-msgs, body.pwa .team-msgs {
  background-color: #efeae2; padding: 10px 12px;
  background-image: radial-gradient(rgba(11, 20, 26, .045) 1.2px, transparent 1.3px); background-size: 18px 18px;
}
body.pwa .msg { max-width: 82%; font-size: 15.5px; border-radius: 8px; padding: 6px 8px 4px 9px; }
body.pwa .msg.in { border-top-left-radius: 0; }
body.pwa .msg.out { border-top-right-radius: 0; background: #d9fdd3; }
body.pwa .msg-meta { font-size: 11px; }
/* barra de digitação: pílula branca + botão redondo verde */
body.pwa .chat-compose { background: #efeae2; border-top: 0; padding: 6px 6px 6px; }
body.pwa.pwa-chat .chat-compose { padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
body.pwa .compose-form { gap: 6px; align-items: flex-end; }
.wa-pill { flex: 1; min-width: 0; display: flex; align-items: flex-end; background: #fff; border-radius: 26px; padding: 3px 4px;
  box-shadow: 0 1px 1px rgba(11, 20, 26, .12); }
.wa-pill textarea { flex: 1; min-width: 0; border: 0 !important; box-shadow: none !important; background: transparent; resize: none;
  font-size: 16px; line-height: 1.35; padding: 11px 6px; min-height: 44px; max-height: 140px; border-radius: 0; }
.wa-pill .icon-btn { padding: 10px 8px; color: #54656f; }
.wa-pill .icon-btn svg { width: 23px; height: 23px; }
.wa-round { width: 50px; height: 50px; flex: none; border-radius: 50%; border: 0; background: #00a884; color: #fff; display: grid;
  place-items: center; cursor: pointer; box-shadow: 0 1px 2px rgba(11, 20, 26, .2); padding: 0; }
.wa-round svg { width: 24px; height: 24px; }
.wa-round:disabled { opacity: .6; }
.wa-round.recording { background: #dc2626; animation: call-pulse 1.1s infinite; }
body.pwa .compose-notice { background: #fff; border-radius: 12px; padding: 10px 12px; box-shadow: 0 1px 1px rgba(11, 20, 26, .12); }
body.pwa .compose-file, body.pwa .qr-popup { left: 6px; right: 6px; }

/* =========================================================
   Responsivo
   ========================================================= */
@media (max-width: 1100px) {
  .hero-chat { display: none; }
}
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  body.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  body.nav-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 30; }
  .shell { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .appbar { padding: 10px 16px; }
  main { padding: 20px 16px 48px; }
  .tpl-layout { grid-template-columns: 1fr; }
  .tpl-side { position: static; }
  .slot-row, .btn-row, .btn-row[data-type], .tag-row, .field-row { grid-template-columns: 1fr; }
  .filters input[type="search"] { min-width: 0; width: 100%; }
  #msg-search, #audit-search, #template-search, #optout-search { min-width: 0; width: 100%; }
  .table-wrap td { white-space: nowrap; }
  .page-title { display: none; }
  .stat.highlight { grid-column: 1 / -1; }
  .failure-item { grid-template-columns: 44px 1fr; }
  .failure-item .badge { grid-column: 2; justify-self: start; }
  .login-wrap { grid-template-columns: 1fr; }
  .login-hero { padding: 32px 24px; }
  .login-hero h1 { font-size: 28px; margin-top: 28px; }
  .hero-points { margin-bottom: 0; }
  body.inbox-mode main { padding: 0; }
  .inbox { grid-template-columns: 1fr; height: calc(100vh - 53px); border-radius: 0; border: 0; }
  .inbox.chat-open .inbox-side { display: none; }
  .inbox:not(.chat-open) .inbox-chat { display: none; }
  .chat-back { display: inline-flex; }
  .chat-msgs { padding: 12px; }
  .msg { max-width: 88%; }
  .hours-row { grid-template-columns: 1fr; }
  .inbox-dash { grid-template-columns: 1fr; }
}

/* =========================================================
   Fluxos: editor visual de blocos
   ========================================================= */
body.flow-mode main { max-width: none; padding: 12px 16px; }
.flow-editor {
  display: flex; flex-direction: column; height: calc(100vh - 82px); min-height: 520px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.flow-top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.flow-name { font-size: 15px; font-weight: 650; width: 280px; max-width: 100%; border-color: transparent; background: transparent; box-shadow: none; }
.flow-name:hover, .flow-name:focus { border-color: var(--border-strong); background: var(--surface); }
.flow-dirty { font-size: 12px; color: var(--warning); background: var(--warning-50); padding: 2px 8px; border-radius: 999px; }
.flow-body { flex: 1; min-height: 0; display: grid; grid-template-columns: 172px minmax(0, 1fr) 330px; }
.flow-palette { display: flex; flex-direction: column; gap: 5px; padding: 10px; border-right: 1px solid var(--border); background: var(--surface-2); overflow-y: auto; }
.flow-palette-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 6px 2px 2px; }
.flow-palette button {
  display: flex; align-items: center; gap: 8px; text-align: left; font: inherit; font-size: 12.5px; font-weight: 500; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 7px 8px; cursor: pointer;
}
.flow-palette button:hover { border-color: var(--primary); background: var(--primary-50); }
.fn-ico { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; flex: none;
  font-style: normal; font-size: 12px; font-weight: 700; color: #fff; background: #64748b; }
.fn-ico.fn-start { background: #059669; }
.fn-ico.fn-message { background: #2563eb; }
.fn-ico.fn-menu { background: #7c3aed; }
.fn-ico.fn-question { background: #db2777; }
.fn-ico.fn-hours { background: #d97706; }
.fn-ico.fn-queue { background: #0d9488; }
.fn-ico.fn-forward { background: #0891b2; }
.fn-ico.fn-close { background: #475569; }
.fn-ico.fn-media { background: #4f46e5; }
.fn-ico.fn-wait { background: #94a3b8; }
.fn-ico.fn-condition { background: #ea580c; }
.fn-ico.fn-tag { background: #9333ea; }
.fn-ico.fn-goto { background: #16a34a; }
.flow-edges .fedge.goto { stroke: #16a34a; stroke-dasharray: 3 5; opacity: .7; }
.fgoto { position: absolute; right: -4px; top: 18px; width: 8px; height: 8px; border-radius: 50%; background: #16a34a; }
.flow-media img, .sim-img { display: block; max-width: 100%; max-height: 180px; border-radius: 8px; margin-bottom: 8px; }
.flow-file { padding: 10px; border: 1px dashed var(--border-strong); border-radius: 8px; margin-bottom: 8px; font-size: 13px; word-break: break-all; }
.flow-upload { position: relative; margin-bottom: 6px; cursor: pointer; display: inline-flex; flex-direction: row; font-weight: 600; }

.flow-canvas {
  position: relative; overflow: hidden; cursor: grab; touch-action: none; user-select: none;
  background: radial-gradient(circle, #d3d9e2 1px, transparent 1.2px) 0 0 / 22px 22px, #f6f8fb;
}
.flow-world { position: absolute; left: 0; top: 0; transform-origin: 0 0; }
.flow-edges { position: absolute; left: 0; top: 0; width: 1px; height: 1px; overflow: visible; }
.flow-edges .fedge { fill: none; stroke: #94a3b8; stroke-width: 2; pointer-events: none; }
.flow-edges .fedge.sel { stroke: var(--primary); stroke-width: 3; }
.flow-edges .fedge.temp { stroke: var(--primary); stroke-dasharray: 6 4; }
.flow-edges .fedge-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
.flow-edges marker path { fill: #94a3b8; stroke: none; }
.fnode {
  position: absolute; width: 240px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 12px;
  box-shadow: var(--shadow); cursor: move;
}
.fnode.fn-start { width: 200px; }
.fnode.sel { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(5, 150, 105, .22), var(--shadow); }
.fnode.live { box-shadow: 0 0 0 4px rgba(37, 99, 235, .35), var(--shadow); }
.fnode-head { display: flex; align-items: center; gap: 8px; padding: 9px 10px 4px; font-size: 12.5px; }
.fnode-body {
  padding: 0 10px 9px; font-size: 12px; color: var(--text-2); white-space: pre-wrap; word-break: break-word;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
}
.fnode-ports { border-top: 1px solid var(--border); padding: 3px 0; }
.fport { position: relative; display: flex; justify-content: flex-end; padding: 4px 18px 4px 10px; font-size: 12px; font-weight: 500; }
.fport span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fport.muted { color: var(--muted); font-size: 11.5px; font-weight: 400; }
.fdot, .fin {
  position: absolute; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid #94a3b8;
}
.fdot { right: -8px; top: 50%; margin-top: -7px; cursor: crosshair; }
.fdot.on { background: var(--primary); border-color: var(--primary); }
.fdot:hover { transform: scale(1.3); border-color: var(--primary); }
.fin { left: -8px; top: 14px; }
.flow-zoom { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 4px; }
.flow-zoom button {
  font: inherit; font-size: 13px; font-weight: 600; min-width: 32px; height: 32px; padding: 0 10px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; color: var(--text-2);
}
.flow-help {
  position: absolute; left: 12px; bottom: 12px; max-width: calc(100% - 200px); pointer-events: none;
  font-size: 11.5px; color: var(--muted); background: rgba(255, 255, 255, .88); padding: 4px 8px; border-radius: 8px;
}

.flow-side { border-left: 1px solid var(--border); padding: 14px; overflow-y: auto; min-width: 0; }
.flow-side-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.flow-form label { display: block; }
.flow-form label > input, .flow-form label > textarea, .flow-form label > select { display: block; width: 100%; margin-top: 6px; }
.flow-side-head h3 { margin: 0; }
.flow-side-actions { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.flow-tips { padding-left: 18px; }
.flow-tips li { margin: 4px 0; }
.fopts { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.fopt { display: flex; gap: 4px; align-items: flex-start; }
.fopt-n { width: 18px; padding-top: 9px; text-align: center; font-size: 12px; color: var(--muted); flex: none; }
.fopt-fields { flex: 1; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.fopt .btn { padding: 6px 8px; }

.flow-sim { display: flex; flex-direction: column; height: 100%; min-height: 420px; }
.flow-sim h3 { margin: 0; }
.sim-chat {
  flex: 1; min-height: 220px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px;
  padding: 10px; border-radius: 10px; background: #efeae2;
}
.sim-msg { max-width: 88%; padding: 7px 9px; border-radius: 9px; font-size: 13px; box-shadow: 0 1px 1px rgba(0, 0, 0, .08); word-break: break-word; }
.sim-msg.bot { background: #fff; align-self: flex-start; }
.sim-msg.me { background: #d9fdd3; align-self: flex-end; }
.sim-btns { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
.sim-btns button { font: inherit; font-weight: 600; color: #027eb5; background: none; border: 0; padding: 5px; border-radius: 6px; cursor: pointer; }
.sim-btns button:hover { background: #f0f4f8; }
.sim-btns.list button { text-align: left; font-weight: 500; color: var(--text); }
.sim-btns small { display: block; color: var(--muted); font-weight: 400; }
.sim-sys { align-self: center; text-align: center; font-size: 11.5px; color: var(--muted); background: rgba(255, 255, 255, .85); padding: 3px 8px; border-radius: 8px; }
.sim-sys.err { color: var(--danger); }
.sim-sys.end { color: var(--primary-600); font-weight: 600; }
.sim-send { display: flex; gap: 6px; margin-top: 8px; }
.sim-send input { flex: 1; min-width: 0; }

@media (max-width: 1100px) { .flow-body { grid-template-columns: 140px minmax(0, 1fr) 280px; } }
@media (max-width: 900px) {
  .flow-editor { height: auto; }
  .flow-body { grid-template-columns: 1fr; }
  .flow-palette { flex-direction: row; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--border); }
  .flow-palette button { flex: none; }
  .flow-palette-label { display: none; }
  .flow-canvas { height: 60vh; }
  .flow-side { border-left: 0; border-top: 1px solid var(--border); }
  .flow-help { display: none; }
}
