/* =========================================================
   Paleta inspirada no WhatsApp Web (claro / escuro)
   ========================================================= */
:root {
  --deep: #eae6df;
  --panel: #ffffff;
  --panel-head: #f0f2f5;
  --hover: #f5f6f6;
  --active: #f0f2f5;
  --border: #e9edef;
  --text: #111b21;
  --muted: #667781;
  --icon: #54656f;
  --accent: #00a884;
  --accent-strong: #008069;
  --accent-soft: #d9fdd3;
  --danger: #ea0038;
  --warn: #e9a23b;
  --chat-bg: #efeae2;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --meta-in: #667781;
  --meta-out: #667781;
  --read: #53bdeb;
  --pill: #ffffff;
  --search: #f0f2f5;
  --quote: rgba(11, 20, 26, .05);
  --avatar-bg: #dfe5e7;
  --avatar-fg: #ffffff;
  --drawer-gap: #f0f2f5;
  --shadow: 0 1px .5px rgba(11, 20, 26, .13);
  --doodle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23000' stroke-opacity='.06' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 18h22a6 6 0 0 1 6 6v10a6 6 0 0 1-6 6H24l-7 6v-6h-3a6 6 0 0 1-6-6V24a6 6 0 0 1 6-6z'/%3E%3Cpath d='M98 22c-4-6-13-3-12 4 1 6 12 12 12 12s11-6 12-12c1-7-8-10-12-4z'/%3E%3Cpath d='M128 70l4 9 10 1-7 7 2 10-9-5-9 5 2-10-7-7 10-1z'/%3E%3Ccircle cx='52' cy='86' r='9'/%3E%3Cpath d='M20 120c6-8 12 8 18 0s12 8 18 0'/%3E%3Cpath d='M100 124v20M90 134h20'/%3E%3Cpath d='M70 40l8 8M78 40l-8 8'/%3E%3Crect x='120' y='118' width='22' height='16' rx='3'/%3E%3Cpath d='M126 118v-4h10v4'/%3E%3Cpath d='M30 64a8 8 0 1 0 0 1'/%3E%3C/g%3E%3C/svg%3E");
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --deep: #0c1317;
    --panel: #111b21;
    --panel-head: #202c33;
    --hover: #202c33;
    --active: #2a3942;
    --border: #222d34;
    --text: #e9edef;
    --muted: #8696a0;
    --icon: #aebac1;
    --accent: #00a884;
    --accent-strong: #00a884;
    --accent-soft: #0a332c;
    --danger: #f15c6d;
    --warn: #f1b44c;
    --chat-bg: #0b141a;
    --bubble-in: #202c33;
    --bubble-out: #005c4b;
    --meta-in: #8696a0;
    --meta-out: rgba(233, 237, 239, .6);
    --pill: #182229;
    --search: #202c33;
    --quote: rgba(0, 0, 0, .25);
    --avatar-bg: #6a7175;
    --avatar-fg: #cfd4d6;
    --drawer-gap: #0c1317;
    --shadow: 0 1px .5px rgba(11, 20, 26, .13);
    --doodle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160' viewBox='0 0 160 160'%3E%3Cg fill='none' stroke='%23fff' stroke-opacity='.045' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 18h22a6 6 0 0 1 6 6v10a6 6 0 0 1-6 6H24l-7 6v-6h-3a6 6 0 0 1-6-6V24a6 6 0 0 1 6-6z'/%3E%3Cpath d='M98 22c-4-6-13-3-12 4 1 6 12 12 12 12s11-6 12-12c1-7-8-10-12-4z'/%3E%3Cpath d='M128 70l4 9 10 1-7 7 2 10-9-5-9 5 2-10-7-7 10-1z'/%3E%3Ccircle cx='52' cy='86' r='9'/%3E%3Cpath d='M20 120c6-8 12 8 18 0s12 8 18 0'/%3E%3Cpath d='M100 124v20M90 134h20'/%3E%3Cpath d='M70 40l8 8M78 40l-8 8'/%3E%3Crect x='120' y='118' width='22' height='16' rx='3'/%3E%3Cpath d='M126 118v-4h10v4'/%3E%3Cpath d='M30 64a8 8 0 1 0 0 1'/%3E%3C/g%3E%3C/svg%3E");
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--deep);
  color: var(--text);
  font: 14.2px/1.4 "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Helvetica, Roboto, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: #027eb5; }
@media (prefers-color-scheme: dark) { a { color: #53bdeb; } }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
svg.ic { width: 24px; height: 24px; fill: currentColor; flex-shrink: 0; display: block; }
svg.ic.sm { width: 18px; height: 18px; }
svg.ic.xs { width: 15px; height: 15px; }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 7px 16px;
  border-radius: 20px;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.sm { padding: 4px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  border: 0; background: none; color: var(--icon); width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer; flex-shrink: 0;
}
.icon-btn:hover { background: rgba(134, 150, 160, .15); }

input[type=text], input[type=password], input[type=search], input[type=tel], select {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); }
label { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 4px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--deep); }
.login-card { background: var(--panel); border-radius: 12px; box-shadow: 0 2px 12px rgba(0,0,0,.12); width: 100%; max-width: 360px; padding: 30px; }
.login-card h1 { font-size: 21px; margin: 0 0 4px; font-weight: 500; }
.login-card .btn { width: 100%; margin-top: 18px; padding: 10px; }
.error { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 1em; }

/* =========================================================
   Estrutura: trilho de ícones à esquerda + conteúdo
   ========================================================= */
.app { height: 100%; display: flex; }
.rail {
  width: 64px; flex-shrink: 0; background: var(--panel-head); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 6px;
}
.rail .spacer { flex: 1; }
.rail-btn {
  position: relative; border: 0; background: none; color: var(--icon); width: 42px; height: 42px; border-radius: 50%;
  display: grid; place-items: center; cursor: pointer;
}
.rail-btn:hover { background: rgba(134, 150, 160, .18); }
.rail-btn.active { background: rgba(134, 150, 160, .28); color: var(--text); }
.rail-btn[data-tip]:hover::after {
  content: attr(data-tip); position: absolute; left: 52px; top: 50%; transform: translateY(-50%);
  background: #111b21; color: #fff; font-size: 12.5px; padding: 4px 9px; border-radius: 6px; white-space: nowrap; z-index: 80;
}
.rail-me { width: 34px; height: 34px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 14px; margin-top: 6px; }
.live { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); margin-bottom: 4px; }
.live.on { background: #25d366; }

.views { flex: 1; min-width: 0; display: flex; }
.view { flex: 1; min-width: 0; min-height: 0; overflow: auto; background: var(--panel); }
.page { max-width: 1200px; margin: 0 auto; padding: 24px 22px 40px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 21px; font-weight: 500; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; }
.page > .card + .card { margin-top: 14px; }
.card-pad { padding: 16px; }
.section-title { font-size: 15px; font-weight: 500; margin: 28px 0 10px; color: var(--accent-strong); }

/* ---------- painel ---------- */
.segmented { display: inline-flex; gap: 6px; }
.segmented button { border: 0; background: var(--search); color: var(--muted); padding: 6px 14px; border-radius: 16px; cursor: pointer; }
.segmented button.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 500; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 11px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12.5px; color: var(--muted); font-weight: 500; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--hover); }
.table-wrap { overflow-x: auto; }
.wait-bad { color: var(--danger); font-weight: 500; }
.wait-mid { color: var(--warn); font-weight: 500; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.cell-person { display: flex; align-items: center; gap: 10px; }

/* ---------- painel de desempenho ---------- */
:root {
  --series-1: #2a78d6; /* recebidas */
  --series-2: #1baf7a; /* enviadas */
  --good: #1f8a4c;
  --bad: #d4351c;
  --grid: rgba(102, 119, 129, .18);
}
@media (prefers-color-scheme: dark) {
  :root { --series-1: #3987e5; --series-2: #199e70; --good: #3fb871; --bad: #f2705e; --grid: rgba(134, 150, 160, .14); }
}
.page.wide { max-width: 1480px; }
.dash-filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.custom-range { display: flex; align-items: center; gap: 6px; }
.custom-range input { width: auto; padding: 5px 8px; }
.switch { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: 13.5px; color: var(--text); cursor: pointer; }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 10px; background: var(--search); position: relative; transition: background .15s; border: 1px solid var(--border); }
.switch span::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked + span { background: var(--accent); border-color: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); background: #fff; }
#d-caption { margin: -8px 0 16px; }

.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
@media (max-width: 1250px) { .kpis { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.kpi { padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; }
.kpi .label { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 26px; font-weight: 500; font-variant-numeric: tabular-nums; line-height: 1.25; }
.kpi .sub { font-size: 12px; color: var(--muted); }
.delta { font-size: 12px; display: inline-flex; align-items: center; gap: 3px; font-weight: 500; }
.delta.good { color: var(--good); }
.delta.bad { color: var(--bad); }
.delta.flat { color: var(--muted); font-weight: 400; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(440px, 100%), 1fr)); gap: 14px; margin-top: 14px; }
.grid-2 > * { min-width: 0; }
#heatmap { overflow-x: auto; }
.scroll-hint { display: none; }
.card-title { font-size: 15px; font-weight: 500; margin-bottom: 10px; }
.card-title.pad { padding: 14px 16px 6px; margin: 0; }
.card-title.spaced { margin-top: 22px; }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--muted); margin-bottom: 6px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.legend i.line { height: 2px; border-radius: 1px; vertical-align: 3px; width: 14px; }
.legend i.dash { height: 0; border-top: 2px dashed var(--muted); width: 14px; vertical-align: 3px; border-radius: 0; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: 220px; overflow: visible; }
.chart .axis { font-size: 10.5px; fill: var(--muted); }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: default; }
.chart .hit:hover { fill: rgba(134, 150, 160, .1); }
.empty-chart { height: 220px; display: grid; place-items: center; color: var(--muted); font-size: 13px; }
.viz-tip {
  position: fixed; z-index: 90; pointer-events: none; background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 14px rgba(0,0,0,.18); min-width: 140px;
}
.viz-tip b { display: block; margin-bottom: 4px; font-weight: 500; }
.viz-tip div { display: flex; justify-content: space-between; gap: 14px; }
.viz-tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 6px; }

.heat { display: grid; grid-template-columns: 34px repeat(24, 1fr); gap: 2px; font-size: 10.5px; color: var(--muted); }
.heat .cell { aspect-ratio: 1.2; border-radius: 3px; background: var(--search); }
.heat .hl { display: flex; align-items: center; }
.heat .hh { text-align: center; }
.heat-legend { display: flex; align-items: center; gap: 6px; justify-content: flex-end; font-size: 11.5px; color: var(--muted); margin-top: 8px; }
.heat-legend span { width: 18px; height: 10px; border-radius: 2px; }

.hbar { display: grid; grid-template-columns: 120px 1fr 64px; align-items: center; gap: 10px; margin: 7px 0; font-size: 13px; }
.hbar .track { height: 10px; background: var(--search); border-radius: 0 4px 4px 0; overflow: hidden; }
.hbar .fill { height: 100%; background: var(--series-2); border-radius: 0 4px 4px 0; }
.hbar .v { text-align: right; font-variant-numeric: tabular-nums; }

table.rank { font-size: 13.5px; }
table.rank th, table.rank td { padding: 10px 9px; }
table.rank th { cursor: pointer; user-select: none; white-space: normal; vertical-align: bottom; line-height: 1.25; min-width: 64px; }
table.rank th:first-child { min-width: 190px; }
table.rank th.sorted { color: var(--text); }
table.rank td { white-space: nowrap; }
table.rank tr.total td { font-weight: 500; background: var(--hover); }
.list { max-height: 360px; overflow-y: auto; padding-bottom: 6px; }
.list-item { display: flex; align-items: center; gap: 12px; padding: 9px 16px; cursor: pointer; }
.list-item:hover { background: var(--hover); }
.list-item .t { flex: 1; min-width: 0; }
.list-item .t div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-item .r { text-align: right; font-size: 13px; white-space: nowrap; }
.list-empty { padding: 18px 16px; color: var(--muted); font-size: 13px; }
.glossary { margin-top: 18px; }
.glossary summary { cursor: pointer; font-weight: 500; }
.glossary dl { display: grid; grid-template-columns: 170px 1fr; gap: 8px 16px; margin: 14px 0 0; font-size: 13.5px; }
.glossary dt { color: var(--muted); }
.glossary dd { margin: 0; }
.sched-row { display: grid; grid-template-columns: 110px 1fr; align-items: center; gap: 10px; margin: 6px 0; }
.sched-row .times { display: flex; align-items: center; gap: 6px; }
.sched-row input[type=time] { width: auto; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel); }
.sched-row label { margin: 0; display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 14px; }
.ignore-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* ---------- status ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 2px 9px; border-radius: 999px; background: var(--search); color: var(--muted); white-space: nowrap; }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--accent-strong); background: var(--accent-soft); }
.badge.warn { color: var(--warn); background: rgba(233, 162, 59, .14); }
.badge.bad { color: var(--danger); background: rgba(234, 0, 56, .1); }

/* ---------- conexões ---------- */
.conn-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
.conn { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.conn-top { display: flex; gap: 12px; align-items: center; }
.conn-top > div:not(.avatar) { flex: 1; min-width: 0; }
.conn-name { font-weight: 500; font-size: 16px; }
.conn-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: auto; }

/* ---------- modal ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(11, 20, 26, .6); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--panel); border-radius: 10px; width: 100%; max-width: 440px; padding: 24px; max-height: 92vh; overflow: auto; box-shadow: 0 17px 50px rgba(11,20,26,.19); }
.modal h3 { margin: 0 0 6px; font-weight: 500; font-size: 19px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.qr-box { display: grid; place-items: center; min-height: 300px; background: #fff; border-radius: 10px; margin-top: 14px; }
.qr-box img { width: 280px; height: 280px; }
.pair-code { font-size: 30px; letter-spacing: 3px; font-weight: 700; color: #111; font-family: ui-monospace, Menlo, monospace; }
.steps { margin: 12px 0 0; padding-left: 18px; color: var(--muted); font-size: 13.5px; }
.radio-row { display: flex; gap: 16px; margin-top: 8px; }
.radio-row label { display: flex; gap: 6px; align-items: center; margin: 0; color: var(--text); font-size: 14px; }

/* =========================================================
   Avatares
   ========================================================= */
.avatar {
  position: relative; border-radius: 50%; overflow: hidden; flex-shrink: 0; background: var(--avatar-bg);
  width: 49px; height: 49px; display: grid; place-items: center; color: var(--avatar-fg);
}
.avatar > svg { width: 100%; height: 100%; }
.avatar > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.avatar.official { background: #25d366; color: #fff; }
.avatar.official > svg { width: 55%; height: 55%; }
.avatar.s40 { width: 40px; height: 40px; }
.avatar.s34 { width: 34px; height: 34px; }
.avatar.s200 { width: 200px; height: 200px; cursor: zoom-in; }

/* =========================================================
   CONVERSAS — layout estilo WhatsApp Web
   ========================================================= */
.wa { display: flex; height: 100%; overflow: hidden; background: var(--panel); }
.wa-side {
  width: 30%; min-width: 340px; max-width: 480px; display: flex; flex-direction: column;
  border-right: 1px solid var(--border); background: var(--panel); min-height: 0;
}
.wa-side-head { height: 59px; display: flex; align-items: center; gap: 10px; padding: 0 12px 0 16px; flex-shrink: 0; }
.wa-side-head h1 { font-size: 22px; font-weight: 600; margin: 0; flex: 1; }
.wa-select {
  width: auto; max-width: 190px; border: 0; background: var(--search); border-radius: 18px; padding: 6px 12px; font-size: 13.5px; color: var(--muted); cursor: pointer;
}
.wa-search { padding: 4px 12px 8px; flex-shrink: 0; }
.wa-search-box { display: flex; align-items: center; gap: 12px; background: var(--search); border-radius: 8px; padding: 0 12px; height: 36px; color: var(--muted); }
.wa-search-box input { border: 0; background: none; padding: 0; height: 100%; flex: 1; }
.wa-search-box input:focus { border: 0; }
.wa-chips { display: flex; gap: 8px; padding: 2px 12px 8px; flex-shrink: 0; overflow-x: auto; }
.wa-chips button { border: 0; background: var(--search); color: var(--muted); border-radius: 16px; padding: 5px 13px; cursor: pointer; white-space: nowrap; font-size: 14px; }
.wa-chips button.active { background: var(--accent-soft); color: var(--accent-strong); }
.wa-list { flex: 1; overflow-y: auto; }
.wa-list-title { color: var(--accent-strong); font-size: 15px; padding: 18px 16px 10px; }

.wa-item { display: flex; align-items: center; height: 72px; padding-left: 13px; cursor: pointer; }
.wa-item:hover { background: var(--hover); }
.wa-item.active { background: var(--active); }
.wa-item .avatar { margin-right: 13px; }
.wa-item-main { flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: center; border-bottom: 1px solid var(--border); padding-right: 15px; }
.wa-item:hover .wa-item-main, .wa-item.active .wa-item-main { border-bottom-color: transparent; }
.wa-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.wa-name { font-size: 17px; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-time { font-size: 12px; color: var(--muted); white-space: nowrap; margin-top: 2px; }
.wa-time.waiting { color: var(--accent); }
.wa-preview { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; align-items: center; gap: 3px; min-width: 0; margin-top: 2px; }
.wa-preview span { overflow: hidden; text-overflow: ellipsis; }
.wa-preview mark { background: none; color: var(--accent); }
.wa-tags { display: flex; align-items: center; gap: 5px; flex-shrink: 0; }
.wa-count { background: var(--accent); color: #fff; font-size: 12px; font-weight: 600; min-width: 20px; height: 20px; border-radius: 10px; display: grid; place-items: center; padding: 0 6px; }
@media (prefers-color-scheme: dark) { .wa-count { color: #111b21; } }
.att-chip { font-size: 11px; padding: 1px 7px; border-radius: 9px; color: #fff; white-space: nowrap; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.wa-more { padding: 14px; text-align: center; color: var(--muted); font-size: 13px; }

/* ----- área principal ----- */
.wa-main { flex: 1; min-width: 0; display: flex; position: relative; }
.wa-conv { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; background: var(--chat-bg); }
.wa-conv::before { content: ""; position: absolute; inset: 0; background-image: var(--doodle); background-size: 320px; pointer-events: none; }
.wa-conv > * { position: relative; }

.wa-intro {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  background: var(--panel-head); border-bottom: 6px solid var(--accent); padding: 30px; color: var(--muted);
}
.wa-intro .big { width: 88px; height: 88px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; margin-bottom: 24px; }
.wa-intro .big svg { width: 44px; height: 44px; }
.wa-intro h2 { font-weight: 300; font-size: 32px; color: var(--text); margin: 0 0 12px; }
.wa-intro p { max-width: 520px; margin: 0; font-size: 14px; line-height: 1.6; }
.wa-intro .foot { margin-top: 40px; display: flex; align-items: center; gap: 6px; font-size: 13px; }

.wa-conv-head {
  height: 59px; flex-shrink: 0; background: var(--panel-head); display: flex; align-items: center; gap: 13px; padding: 0 12px 0 16px;
  border-left: 1px solid var(--border); z-index: 2;
}
.wa-conv-head .who { flex: 1; min-width: 0; cursor: pointer; display: flex; align-items: center; gap: 13px; }
.wa-conv-head .who-text { min-width: 0; }
.wa-conv-head .who-name { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.wa-conv-head .who-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-btn { display: none; }

.wa-messages { flex: 1; overflow-y: auto; padding: 12px 7% 8px; display: flex; flex-direction: column; }
.wa-footer {
  flex-shrink: 0; min-height: 62px; background: var(--panel-head); display: flex; align-items: center; justify-content: center; gap: 8px;
  color: var(--muted); font-size: 13.5px; padding: 8px 16px; text-align: center; border-left: 1px solid var(--border);
}
.wa-down {
  position: absolute; right: 18px; bottom: 80px; width: 42px; height: 42px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--panel-head); color: var(--icon); box-shadow: 0 1px 3px rgba(11,20,26,.3); display: grid; place-items: center; z-index: 3;
}

.day-sep {
  align-self: center; background: var(--pill); color: var(--muted);
  font-size: 12.5px; padding: 5px 12px; border-radius: 7.5px; margin: 10px 0; box-shadow: var(--shadow); text-transform: uppercase;
}
.sys-pill { align-self: center; background: var(--pill); color: var(--muted); font-size: 12.5px; padding: 6px 12px; border-radius: 7.5px; margin: 6px 0; box-shadow: var(--shadow); display: flex; align-items: center; gap: 6px; text-align: center; }
.sys-pill.call svg { color: var(--danger); }
.loader-pill { align-self: center; background: var(--pill); color: var(--muted); font-size: 13px; padding: 7px 14px; border-radius: 16px; margin: 6px 0 10px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px; }
.media-thumb { display: block; width: 100%; max-width: 330px; border-radius: 6px; filter: blur(2px) brightness(.85); }
.spinner { display: inline-block; flex-shrink: 0; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--muted); border-top-color: transparent; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ----- balões ----- */
.msg-row { display: flex; margin-top: 2px; padding: 0 2px; }
.msg-row.first { margin-top: 10px; }
.msg-row.out { justify-content: flex-end; }
.msg {
  position: relative; max-width: 65%; min-width: 72px; padding: 6px 7px 8px 9px; border-radius: 7.5px; box-shadow: var(--shadow);
  font-size: 14.2px; line-height: 19px; overflow-wrap: anywhere; word-break: break-word;
}
.msg.in { background: var(--bubble-in); }
.msg.out { background: var(--bubble-out); }
.msg-row.first .msg.in { border-top-left-radius: 0; }
.msg-row.first .msg.out { border-top-right-radius: 0; }
.msg-row.first .msg.in::before, .msg-row.first .msg.out::before { content: ""; position: absolute; top: 0; width: 8px; height: 13px; }
.msg-row.first .msg.in::before { left: -8px; background: var(--bubble-in); clip-path: polygon(0 0, 100% 0, 100% 100%); }
.msg-row.first .msg.out::before { right: -8px; background: var(--bubble-out); clip-path: polygon(0 0, 100% 0, 0 100%); }
.msg.media-only { padding: 3px; }
.msg.sticker { background: none; box-shadow: none; padding: 0; }
.msg.sticker::before { display: none; }
.msg.deleted { box-shadow: 0 0 0 1.5px var(--danger); }

.msg-sender { font-size: 12.8px; font-weight: 500; line-height: 22px; margin-top: -2px; }
.msg-text { white-space: pre-wrap; }
.msg-text code, .msg-text pre { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.msg-text pre { margin: 0; white-space: pre-wrap; }
.msg-content::after { content: ""; display: block; clear: both; }
.meta {
  float: right; position: relative; top: 5px; margin: -9px 0 -5px 12px; display: flex; align-items: center; gap: 3px;
  font-size: 11px; line-height: 15px; color: var(--meta-in); white-space: nowrap; height: 15px;
}
.msg.out .meta { color: var(--meta-out); }
.meta .tick { width: 16px; height: 16px; }
.meta .tick.read { color: var(--read); }
.meta.overlay {
  position: absolute; right: 7px; bottom: 6px; top: auto; margin: 0; float: none; color: #fff;
  text-shadow: 0 1px 1px rgba(0,0,0,.4); z-index: 1;
}
.meta.overlay::before { content: ""; position: absolute; inset: -10px -7px -6px -30px; background: radial-gradient(at bottom right, rgba(11,20,26,.5), transparent 70%); z-index: -1; border-radius: 0 0 6px 0; }
.meta.overlay .tick.read { color: #fff; }
.deleted-tag { display: flex; align-items: center; gap: 5px; font-size: 12.5px; font-weight: 600; color: var(--danger); margin-bottom: 3px; }
.edit-tag { cursor: pointer; text-decoration: underline dotted; }
.edits { font-size: 12.5px; color: var(--muted); border-top: 1px dashed rgba(134,150,160,.4); margin-top: 6px; padding-top: 4px; }
.edits div { white-space: pre-wrap; margin-top: 2px; }

.quote {
  display: flex; border-radius: 7.5px; background: var(--quote); overflow: hidden; margin: 0 -3px 6px -5px; font-size: 13.2px; line-height: 18px; cursor: default;
}
.quote::before { content: ""; width: 4px; background: #06cf9c; flex-shrink: 0; }
.quote > div { padding: 5px 10px 6px 8px; max-height: 76px; overflow: hidden; color: var(--muted); white-space: pre-wrap; }
.quote b { display: block; font-weight: 500; color: #06cf9c; font-size: 12.8px; }

.media-img { display: block; border-radius: 6px; max-width: 330px; width: 100%; max-height: 360px; object-fit: cover; cursor: zoom-in; background: rgba(134,150,160,.15); min-height: 120px; min-width: 200px; }
.media-sticker { width: 150px; height: 150px; object-fit: contain; display: block; }
video.media-video { display: block; border-radius: 6px; max-width: 330px; width: 100%; max-height: 360px; background: #000; }
.with-caption { margin-bottom: 4px; }
.media-missing { display: flex; align-items: center; gap: 10px; padding: 10px 6px; color: var(--muted); font-size: 13px; min-width: 240px; }

/* áudio */
.ptt { display: flex; align-items: center; gap: 10px; width: 300px; max-width: 100%; padding: 2px 2px 8px; }
.ptt .avatar { width: 48px; height: 48px; }
.ptt .mic { position: absolute; right: -2px; bottom: -2px; color: #4fc3f7; }
.ptt-avatar { position: relative; flex-shrink: 0; }
.ptt-avatar .mic { position: absolute; left: -4px; bottom: -3px; }
.ptt-play { border: 0; background: none; color: var(--icon); cursor: pointer; padding: 0; width: 34px; height: 34px; display: grid; place-items: center; flex-shrink: 0; }
.ptt-play svg { width: 34px; height: 34px; }
.ptt-track { flex: 1; min-width: 0; position: relative; }
.ptt-track input[type=range] { width: 100%; margin: 8px 0 0; accent-color: var(--accent); height: 4px; cursor: pointer; }
.ptt-dur { position: absolute; left: 0; top: 22px; font-size: 11px; color: var(--meta-in); }
.msg.out .ptt-dur { color: var(--meta-out); }
.ptt-speed { border: 0; background: rgba(134,150,160,.35); color: #fff; border-radius: 10px; font-size: 11.5px; font-weight: 600; padding: 2px 6px; cursor: pointer; flex-shrink: 0; }
.ptt.audio-file .ptt-avatar { width: 48px; height: 48px; border-radius: 50%; background: #ff9f43; color: #fff; display: grid; place-items: center; }

/* documento */
.doc { display: flex; align-items: center; gap: 10px; padding: 10px; background: var(--quote); border-radius: 6px; text-decoration: none; color: inherit; min-width: 260px; margin-bottom: 4px; }
.doc-ext { width: 30px; height: 38px; border-radius: 3px; background: #6c7a85; color: #fff; font-size: 9px; font-weight: 700; display: grid; place-items: end center; padding-bottom: 4px; flex-shrink: 0; }
.doc-ext.pdf { background: #e5534b; }
.doc-ext.xls, .doc-ext.xlsx, .doc-ext.csv { background: #1f9d55; }
.doc-ext.doc, .doc-ext.docx { background: #3b82f6; }
.doc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.doc-info { font-size: 12px; color: var(--muted); }
.doc .dl { margin-left: auto; color: var(--icon); width: 34px; height: 34px; border-radius: 50%; border: 1px solid rgba(134,150,160,.5); display: grid; place-items: center; flex-shrink: 0; }

/* localização / contato / link */
.loc { display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; padding: 8px; background: var(--quote); border-radius: 6px; margin-bottom: 4px; min-width: 240px; }
.loc .pin { width: 44px; height: 44px; border-radius: 6px; background: #e5534b; color: #fff; display: grid; place-items: center; flex-shrink: 0; }
.vcard { display: flex; align-items: center; gap: 10px; padding: 4px 2px 10px; min-width: 230px; border-bottom: 1px solid rgba(134,150,160,.3); margin-bottom: 6px; }
.link-prev { background: var(--quote); border-radius: 6px; padding: 8px 10px; margin: 0 -3px 6px -5px; font-size: 13px; }
.link-prev b { display: block; font-weight: 500; }

/* template comercial */
.tpl-title { font-weight: 600; margin-bottom: 2px; }
.tpl-footer { font-size: 13px; color: var(--muted); margin-top: 4px; }
.tpl-buttons { margin: 8px -7px -8px -9px; }
.tpl-btn { display: flex; align-items: center; justify-content: center; gap: 6px; border-top: 1px solid rgba(134,150,160,.25); padding: 9px; color: #027eb5; font-size: 14px; text-decoration: none; }
@media (prefers-color-scheme: dark) { .tpl-btn { color: #53bdeb; } }

.reactions {
  position: absolute; bottom: -18px; display: flex; gap: 1px; background: var(--pill); border-radius: 12px; padding: 1px 6px;
  box-shadow: 0 1px 3px rgba(11,20,26,.25); font-size: 14px; line-height: 20px; z-index: 1;
}
.msg.in .reactions { left: 10px; }
.msg.out .reactions { right: 10px; }
.msg-row.has-reactions { margin-bottom: 16px; }
.msg-row.flash .msg, .sys-pill.flash { animation: flash 2.4s ease-out; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--warn); } 100% { box-shadow: var(--shadow); } }

/* ----- painel "Dados do contato" ----- */
.wa-drawer {
  width: 30%; min-width: 340px; max-width: 460px; flex-shrink: 0; background: var(--drawer-gap); border-left: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0;
}
.drawer-head { height: 59px; background: var(--panel-head); display: flex; align-items: center; gap: 18px; padding: 0 14px; flex-shrink: 0; font-size: 16px; }
.drawer-body { flex: 1; overflow-y: auto; }
.d-sec { background: var(--panel); padding: 16px 28px; margin-bottom: 10px; box-shadow: 0 1px 3px rgba(11,20,26,.08); }
.d-hero { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 28px 28px 20px; }
.d-hero .name { font-size: 24px; margin-top: 16px; }
.d-hero .phone { font-size: 16px; color: var(--muted); margin-top: 4px; }
.d-hero .push { font-size: 14px; color: var(--muted); margin-top: 2px; }
.d-label { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.d-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; cursor: pointer; }
.d-thumbs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.d-thumbs > * { aspect-ratio: 1; border-radius: 6px; overflow: hidden; background: rgba(134,150,160,.15); cursor: pointer; position: relative; }
.d-thumbs img, .d-thumbs video { width: 100%; height: 100%; object-fit: cover; display: block; }
.d-thumbs .play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; text-shadow: 0 0 4px #000; }
.d-line { display: flex; gap: 16px; align-items: flex-start; padding: 8px 0; }
.d-line svg { color: var(--icon); margin-top: 1px; }
.d-line .v { min-width: 0; overflow-wrap: anywhere; }
.d-stat { display: flex; justify-content: space-between; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.d-stat:last-child { border-bottom: 0; }
.d-stat b { font-weight: 500; }
.d-person { display: flex; align-items: center; gap: 14px; padding: 8px 0; }
.d-person .t { flex: 1; min-width: 0; }
.d-person .admin { font-size: 11.5px; color: var(--accent-strong); border: 1px solid var(--accent); border-radius: 4px; padding: 0 5px; }
.d-tabs { display: flex; background: var(--panel); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 1; }
.d-tabs button { flex: 1; border: 0; background: none; padding: 14px 0 12px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; }
.d-tabs button.active { color: var(--accent-strong); border-bottom-color: var(--accent); }
.d-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; padding: 6px; background: var(--panel); }
.d-grid > * { aspect-ratio: 1; overflow: hidden; background: rgba(134,150,160,.15); cursor: pointer; position: relative; }
.d-grid img, .d-grid video { width: 100%; height: 100%; object-fit: cover; display: block; }
.d-list { background: var(--panel); padding: 6px 16px; }
.d-list .doc, .d-list .link-item { margin: 6px 0; }
.link-item { display: block; padding: 10px; background: var(--quote); border-radius: 6px; font-size: 13px; overflow-wrap: anywhere; color: inherit; text-decoration: none; }

.lightbox { position: fixed; inset: 0; background: rgba(11, 20, 26, .94); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 90vh; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #111b21; color: #e9edef; padding: 10px 18px; border-radius: 8px; z-index: 70; font-size: 13.5px; box-shadow: 0 2px 8px rgba(0,0,0,.3); }

/* ---------- responsivo ---------- */
/* telas de toque: dicas de "passar o mouse" ficariam presas na tela */
@media (hover: none) {
  .rail-btn[data-tip]:hover::after { display: none; }
}

@media (max-width: 860px) {
  /* barra de navegação vira barra inferior, como no app do WhatsApp */
  .app { flex-direction: column-reverse; height: 100dvh; }
  .rail {
    width: 100%; height: calc(58px + env(safe-area-inset-bottom)); padding: 0 8px env(safe-area-inset-bottom);
    flex-direction: row; justify-content: space-around; gap: 0; border-right: 0; border-top: 1px solid var(--border);
  }
  .rail .spacer, .rail-me { display: none; }
  .live { margin: 0; }
  .views { min-height: 0; }
  /* dentro de uma conversa a barra some, como no WhatsApp */
  body:has(#view-chats.open:not(.hidden)) .rail { display: none; }

  /* iOS dá zoom em campos com fonte menor que 16px */
  input[type=text], input[type=password], input[type=search], input[type=tel], input[type=date], input[type=time], select { font-size: 16px; }

  .page { padding: 16px 12px 28px; }
  .page-head { margin-bottom: 12px; }
  .page-head h2 { font-size: 20px; }

  /* painel de desempenho */
  .dash-filters { width: 100%; gap: 8px; }
  .dash-filters .wa-select { flex: 1; max-width: none; }
  .segmented { width: 100%; overflow-x: auto; scrollbar-width: none; flex-wrap: nowrap; }
  .segmented::-webkit-scrollbar { display: none; }
  .segmented button { white-space: nowrap; flex-shrink: 0; }
  .custom-range { width: 100%; }
  .custom-range input { flex: 1; min-width: 0; }
  #d-caption { margin: 0 0 12px; }
  .cap-sched { display: none; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 8px; }
  .kpi { padding: 10px 12px; }
  .kpi .label { font-size: 12px; line-height: 1.3; }
  .kpi .value { font-size: 21px; }
  .kpi .sub { font-size: 11.5px; }
  .delta { font-size: 11.5px; }
  .delta .muted { display: none; }
  .grid-2 { gap: 10px; margin-top: 10px; }
  .card-pad { padding: 14px 12px; }
  .chart svg { height: 190px; }
  .heat { min-width: 560px; }
  .hbar { grid-template-columns: 92px 1fr 74px; gap: 8px; font-size: 12.5px; }
  .section-title { margin: 22px 0 8px; }
  table.rank th:first-child, table.rank td:first-child {
    position: sticky; left: 0; z-index: 1; background: var(--panel); min-width: 150px; box-shadow: 1px 0 0 var(--border);
  }
  table.rank tr.total td:first-child { background: var(--hover); }
  .list-item { padding: 9px 12px; align-items: flex-start; }
  .list-item .r { font-size: 12px; }
  .list-item .r .muted { max-width: 110px; white-space: normal; }
  .scroll-hint { display: block !important; font-weight: 400; margin-top: 2px; }
  .glossary dl { grid-template-columns: 1fr; gap: 2px; }
  .glossary dd { margin-bottom: 10px; }

  /* usuários */
  #user-form { flex-wrap: wrap; }
  #user-form input, #user-form select { flex: 1 1 100%; }
  #user-form .btn { width: 100%; }
  .modal { padding: 18px; }
  .sched-row { grid-template-columns: 96px 1fr; }
}
@media (max-width: 1100px) {
  .wa-drawer { position: absolute; right: 0; top: 0; bottom: 0; z-index: 5; width: 100%; max-width: 420px; }
}
@media (max-width: 860px) {
  .wa-side { width: 100%; max-width: none; min-width: 0; }
  .wa.open .wa-side { display: none; }
  .wa:not(.open) .wa-main { display: none; }
  .wa-messages { padding: 10px 12px; }
  .msg { max-width: 85%; }
  .back-btn { display: grid; }
  .wa-drawer { max-width: none; }
}
