/* ZuZap — interface no estilo WhatsApp Web. As cores de marca vêm das configurações (whitelabel). */
:root {
  --primary: #00a884;
  --secondary: #111b21;
  --bubble-out: #d9fdd3;
  --chat-bg: #efeae2;
  --primary-dark: color-mix(in srgb, var(--primary) 80%, black);
  --primary-soft: color-mix(in srgb, var(--primary) 12%, white);
  --bg: #f0f2f5;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #e9edef;
  --text: #111b21;
  --muted: #667781;
  --bubble-in: #ffffff;
  --danger: #ea0038;
  --warn: #e9a23b;
  --tick-read: #53bdeb;
  --shadow: 0 2px 10px rgba(11, 20, 26, .12);
  --radius: 10px;
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, "Lucida Grande", Arial, Ubuntu, Cantarell, "Fira Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14.2px; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--primary-dark); }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.grow { flex: 1; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Botões e formulários ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--panel); border-radius: 24px;
  padding: 8px 16px; cursor: pointer; font-weight: 500; white-space: nowrap; transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%; border: 0; background: transparent; display: inline-grid; place-items: center;
  cursor: pointer; color: var(--muted); flex: none;
}
.icon-btn:hover { background: rgba(11, 20, 26, .06); }
.icon-btn.active { color: var(--primary); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 13px; color: var(--muted); font-weight: 500; }
.input, select.input, textarea.input {
  width: 100%; border: 1px solid #d1d7db; border-radius: 8px; padding: 9px 12px; background: #fff; outline: none;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea.input { resize: vertical; min-height: 80px; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { accent-color: var(--primary); width: 16px; height: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (min-width: 640px) {
  .grid-2 { grid-template-columns: 1fr 1fr; }
  .grid-4 { grid-template-columns: repeat(4, 1fr); }
}

/* ---------- Login ---------- */
.login {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(var(--primary) 0 220px, var(--bg) 220px);
}
.login-card { width: min(420px, 100%); background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); padding: 36px 32px; }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 10px; text-align: center; margin-bottom: 24px; }
.login-brand img { max-height: 72px; max-width: 220px; object-fit: contain; }
.login-brand h1 { margin: 0; font-size: 24px; font-weight: 600; }
.login-brand p { margin: 0; color: var(--muted); }
.login .error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- Layout principal ---------- */
.app { display: flex; flex-direction: column-reverse; height: 100vh; height: 100dvh; overflow: hidden; }
/* Celular: barra de baixo só com os atalhos principais + "Mais" */
.rail {
  flex: none; background: var(--secondary); display: flex; flex-direction: row; align-items: stretch; justify-content: space-around;
  padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); gap: 2px; z-index: 5;
}
.rail .brand, .rail .spacer, .rail > a:not([data-primary]), .rail > button:not(.more) { display: none; }
.rail a, .rail button {
  flex: 1; max-width: 96px; min-height: 52px; border-radius: 12px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  color: rgba(255,255,255,.72); border: 0; background: transparent; cursor: pointer; position: relative; text-decoration: none; padding: 4px 2px;
}
.rail .lbl { font-size: 11px; line-height: 1.1; white-space: nowrap; }
.rail a.active { color: #fff; }
.rail a.active svg { background: var(--primary); border-radius: 12px; padding: 2px 10px; width: auto; box-sizing: content-box; }
.rail .badge { position: absolute; top: 2px; left: calc(50% + 6px); }
.rail .brand img { width: 100%; height: 100%; object-fit: contain; }
@media (min-width: 768px) {
  .app { flex-direction: row; }
  .rail { width: 64px; flex-direction: column; align-items: center; justify-content: flex-start; padding: 10px 0; gap: 4px; }
  .rail .brand { display: grid; width: 44px; height: 44px; border-radius: 12px; place-items: center; margin-bottom: 10px; overflow: hidden; background: rgba(255,255,255,.08); }
  .rail .spacer { display: block; flex: 1; }
  .rail > a:not([data-primary]), .rail > button:not(.more) { display: grid; }
  .rail > button.more { display: none; }
  .rail a, .rail button { flex: none; width: 44px; height: 44px; min-height: 0; max-width: none; display: grid; place-items: center; padding: 0; }
  .rail .lbl { display: none; }
  .rail a:hover, .rail button:hover { background: rgba(255,255,255,.1); color: #fff; }
  .rail a.active { background: var(--primary); }
  .rail a.active svg { background: none; padding: 0; }
  .rail .badge { top: 4px; right: 2px; left: auto; }
  .rail a[data-tip]:hover::after, .rail button[data-tip]:hover::after {
    content: attr(data-tip); position: absolute; left: 54px; top: 50%; transform: translateY(-50%); background: #233138; color: #fff;
    padding: 5px 10px; border-radius: 6px; font-size: 12.5px; white-space: nowrap; pointer-events: none;
  }
}
/* Painel "Mais" (celular) */
.more-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.more-sheet a, .more-sheet button { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 6px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--panel); color: var(--text); text-decoration: none; font-size: 12.5px; text-align: center; cursor: pointer; min-height: 84px; justify-content: center; }
.more-sheet a.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary-dark); }
.more-sheet svg { color: var(--muted); }
.more-sheet .danger { color: var(--danger); }
.me-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; font-weight: 600; }
.view { flex: 1; min-width: 0; display: flex; background: var(--bg); }

.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 11.5px; font-weight: 600; display: inline-grid; place-items: center; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; padding: 1px 8px; border-radius: 10px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.tag .dot { width: 7px; height: 7px; border-radius: 50%; }

.avatar { position: relative; flex: none; border-radius: 50%; background: #dfe5e7; color: #fff; display: grid; place-items: center; overflow: hidden; font-weight: 600; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Páginas administrativas ---------- */
.page { flex: 1; overflow: auto; padding: 16px 14px 24px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 600; flex: 1; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(11,20,26,.08); padding: 16px; }
@media (min-width: 768px) {
  .page { padding: 28px clamp(16px, 4vw, 40px); }
  .page-head { margin-bottom: 20px; }
  .page-head h2 { font-size: 22px; }
  .card { padding: 20px; }
}
.card h3 { margin: 0 0 14px; font-size: 16px; font-weight: 600; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); gap: 16px; }
table.table { width: 100%; border-collapse: collapse; background: var(--panel); border-radius: var(--radius); overflow: hidden; box-shadow: 0 1px 2px rgba(11,20,26,.08); }
.table thead { display: none; }
.table, .table tbody, .table tr, .table td { display: block; }
.table tr { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.table tr:last-child { border-bottom: 0; }
.table td { padding: 4px 0; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; min-width: 0; overflow-wrap: anywhere; }
.table td:empty { display: none; }
.table td[data-label]::before { content: attr(data-label); flex: 0 0 34%; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .02em; }
.table td.actions { justify-content: flex-end; padding-top: 6px; }
.table td.actions::before { display: none; }
.table td.check-cell { position: absolute; }
.table tr:has(td.check-cell) { position: relative; padding-left: 44px; }
.table tr:has(td.check-cell) td.check-cell { left: 14px; top: 12px; }
@media (min-width: 640px) {
  .table { display: table; }
  .table thead { display: table-header-group; }
  .table tbody { display: table-row-group; }
  .table tr { display: table-row; padding: 0; border: 0; }
  .table tr:has(td.check-cell) { padding-left: 0; }
  .table td, .table th { display: table-cell; text-align: left; padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
  .table td.check-cell { position: static; }
  .table td[data-label]::before { display: none; }
  .table th { font-size: 12.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; background: #fafbfb; }
  .table tr:last-child td { border-bottom: 0; }
  .table .actions { text-align: right; white-space: nowrap; }
}
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12.5px; background: #0b141a; color: #e9edef; padding: 12px 14px; border-radius: 8px; overflow: auto; white-space: pre; }
code { font-family: Consolas, "Cascadia Mono", monospace; background: var(--panel-2); padding: 1px 6px; border-radius: 4px; font-size: 12.5px; }
.split { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
@media (min-width: 900px) { .split { grid-template-columns: 320px 1fr; } }
.list-select { display: flex; flex-direction: column; }
.list-select button { text-align: left; border: 0; background: transparent; padding: 12px 14px; border-radius: 8px; cursor: pointer; display: flex; gap: 10px; align-items: center; }
.list-select button:hover { background: var(--panel-2); }
.list-select button.active { background: var(--primary-soft); }
.progress { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); transition: width .3s; }
.status-pill { font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 12px; background: var(--panel-2); color: var(--muted); }
.status-pill.ok { background: #d9fdd3; color: #0a7b52; }
.status-pill.warn { background: #fff3d6; color: #9a6400; }
.status-pill.bad { background: #ffe1e6; color: #b3002c; }
.notice { background: #fff8e1; border: 1px solid #f6e3a5; border-radius: 8px; padding: 10px 14px; font-size: 13px; color: #6b5300; }

/* ---------- Conexões ---------- */
.qr-box { display: grid; place-items: center; background: #fff; border: 1px dashed #d1d7db; border-radius: 10px; padding: 14px; min-height: 120px; }
.qr-box img { width: 240px; max-width: 100%; image-rendering: pixelated; }
.qr-steps { margin: 8px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.6; }

/* ---------- Conversas ---------- */
.chats { display: flex; flex: 1; min-width: 0; }
.chat-list { width: 100%; flex: none; background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.chats.has-active .chat-list { display: none; }
.chats:not(.has-active) .chat-panel { display: none; }
@media (min-width: 768px) {
  .chat-list { width: clamp(300px, 30%, 420px); border-right: 1px solid var(--border); }
  .chats.has-active .chat-list { display: flex; }
  .chats:not(.has-active) .chat-panel { display: flex; }
}
.panel-head { height: 60px; flex: none; background: var(--panel-2); display: flex; align-items: center; gap: 10px; padding: 0 12px 0 16px; border-bottom: 1px solid var(--border); }
.panel-head .brand-logo { height: 34px; max-width: 150px; object-fit: contain; }
.panel-head .title { font-size: 17px; font-weight: 600; }
.search { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.search input { width: 100%; border: 0; background: var(--panel-2); border-radius: 8px; padding: 8px 12px 8px 36px; outline: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='%23667781'%3E%3Cpath d='M15.5 14h-.8l-.3-.3A6.5 6.5 0 1 0 14 15.5l.3.3v.8l5 5 1.5-1.5-5-5zm-6 0a4.5 4.5 0 1 1 0-9 4.5 4.5 0 0 1 0 9z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: 10px center; }
.tabs { display: flex; gap: 6px; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs button { border: 0; background: var(--panel-2); color: var(--muted); border-radius: 16px; padding: 5px 12px; cursor: pointer; font-size: 13px; display: inline-flex; gap: 6px; align-items: center; }
.tabs button.active { background: var(--primary-soft); color: var(--primary-dark); font-weight: 600; }
.tabs .count { font-size: 11px; background: var(--primary); color: #fff; border-radius: 9px; padding: 0 6px; }
.chat-items { flex: 1; overflow-y: auto; }
.chat-item { display: flex; gap: 12px; padding: 0 0 0 14px; cursor: pointer; align-items: center; height: 72px; }
.chat-item:hover { background: #f5f6f6; }
.chat-item.active { background: #f0f2f5; }
.chat-item .meta { flex: 1; min-width: 0; height: 100%; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; justify-content: center; gap: 3px; padding-right: 14px; }
.chat-item .line { display: flex; align-items: center; gap: 6px; }
.chat-item .name { flex: 1; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item .time { font-size: 12px; color: var(--muted); }
.chat-item.unread .time { color: var(--primary); font-weight: 600; }
.chat-item .last { flex: 1; color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat-panel { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--chat-bg); position: relative; }
.chat-empty { flex: 1; display: grid; place-items: center; text-align: center; background: var(--panel-2); border-bottom: 6px solid var(--primary); padding: 24px; }
.chat-empty img { max-width: 260px; max-height: 120px; object-fit: contain; margin-bottom: 18px; }
.chat-empty h2 { font-weight: 300; font-size: 30px; margin: 0 0 10px; }
.chat-empty p { color: var(--muted); max-width: 460px; line-height: 1.5; margin: 0 auto; }
.chat-header { cursor: default; }
.chat-header .info { flex: 1; min-width: 0; }
.chat-header .info .name { font-size: 16px; font-weight: 500; }
.chat-header { gap: 8px; padding: 0 6px 0 4px; }
.chat-header .info .sub { font-size: 12.5px; color: var(--muted); display: flex; gap: 6px; align-items: center; flex-wrap: nowrap; overflow: hidden; white-space: nowrap; }
.chat-actions { display: flex; gap: 4px; align-items: center; flex: none; }
/* Celular: só a ação principal + menu "⋮" com as demais */
.chat-actions .hdr-secondary { display: none; }
.popover.hdr-menu { top: 58px; right: 8px; bottom: auto; left: auto; min-width: 220px; padding: 6px 0; }
.popover.hdr-menu button { display: flex; gap: 12px; align-items: center; width: 100%; padding: 12px 16px; border: 0; background: none; text-align: left; cursor: pointer; color: var(--text); }
.popover.hdr-menu button:hover { background: var(--panel-2); }
.popover.hdr-menu button.danger { color: var(--danger); }
@media (min-width: 768px) { .chat-header { gap: 10px; padding: 0 12px 0 16px; } }
/* Todos os botões à vista só quando sobra espaço para o nome do cliente */
@media (min-width: 1100px) {
  .chat-header .info .sub { flex-wrap: wrap; }
  .chat-actions { gap: 6px; }
  .chat-actions .hdr-secondary { display: inline-flex; }
  .chat-actions .hdr-more { display: none; }
}
.chat-header .info { min-width: 80px; }

.messages {
  flex: 1; overflow-y: auto; padding: 12px 10px; display: flex; flex-direction: column; gap: 2px;
  background-color: var(--chat-bg);
  background-image: radial-gradient(color-mix(in srgb, var(--chat-bg) 85%, black) 1px, transparent 1px);
  background-size: 22px 22px;
}
.day-sep { align-self: center; background: #fff; color: var(--muted); font-size: 12.5px; padding: 5px 12px; border-radius: 8px; margin: 10px 0; box-shadow: 0 1px .5px rgba(11,20,26,.13); text-transform: uppercase; }
@media (min-width: 768px) { .messages { padding: 16px clamp(12px, 6%, 64px); } }
.msg { max-width: 86%; padding: 6px 8px 8px 9px; border-radius: 8px; position: relative; box-shadow: 0 1px .5px rgba(11,20,26,.13); word-wrap: break-word; overflow-wrap: anywhere; margin-top: 2px; }
@media (min-width: 768px) { .msg { max-width: min(65%, 560px); } }
.msg.in { align-self: flex-start; background: var(--bubble-in); border-top-left-radius: 0; }
.msg.out { align-self: flex-end; background: var(--bubble-out); border-top-right-radius: 0; }
.msg.cont { border-radius: 8px; }
.msg .sender { font-size: 12.8px; font-weight: 600; color: var(--primary-dark); margin-bottom: 2px; }
.msg .body { white-space: pre-wrap; line-height: 1.38; font-size: 14.2px; }
.msg .body.emoji-only { font-size: 34px; line-height: 1.2; }
.msg .foot { float: right; margin: 6px 0 -4px 10px; font-size: 11px; color: var(--muted); display: inline-flex; gap: 3px; align-items: center; position: relative; top: 4px; }
.msg .foot .agent { font-style: italic; margin-right: 4px; }
.tick { display: inline-flex; color: var(--muted); }
.tick.read { color: var(--tick-read); }
.tick.failed { color: var(--danger); }
.msg img.media, .msg video.media { display: block; max-width: 100%; width: 330px; max-height: 360px; object-fit: cover; border-radius: 6px; cursor: pointer; background: #0001; }
.msg img.sticker { width: 150px; height: 150px; object-fit: contain; background: transparent; }
.msg.sticker-msg { background: transparent; box-shadow: none; }
.msg audio { display: block; width: 280px; max-width: 100%; height: 40px; }
.doc { display: flex; align-items: center; gap: 10px; background: rgba(11,20,26,.05); border-radius: 6px; padding: 10px; text-decoration: none; color: inherit; min-width: min(240px, 100%); }
.doc .ext { width: 34px; height: 40px; border-radius: 4px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 10px; font-weight: 700; text-transform: uppercase; flex: none; }
.revoked { font-style: italic; color: var(--muted); }
.msg .fmt-mono { font-family: Consolas, monospace; font-size: 13px; }

.composer { flex: none; background: var(--panel-2); display: flex; align-items: flex-end; gap: 0; padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); min-height: 58px; position: relative; }
@media (min-width: 768px) { .composer { gap: 4px; padding: 6px 12px; min-height: 62px; } }
.composer textarea {
  flex: 1; border: 0; border-radius: 8px; padding: 10px 12px; resize: none; max-height: 140px; min-height: 42px; outline: none; background: #fff; line-height: 1.4; margin: 4px 4px;
}
.composer .icon-btn { margin-bottom: 5px; }
.composer .send { color: var(--muted); }
.recording { flex: 1; display: flex; align-items: center; gap: 12px; justify-content: flex-end; padding: 0 8px; margin-bottom: 9px; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.composer-note { background: var(--panel-2); text-align: center; padding: 14px; color: var(--muted); font-size: 13.5px; display: flex; gap: 10px; align-items: center; justify-content: center; }

.popover { position: absolute; bottom: 64px; left: 10px; z-index: 20; box-shadow: var(--shadow); border-radius: 10px; overflow: hidden; background: #fff; }
.attach-menu { display: flex; flex-direction: column; padding: 8px 0; min-width: 200px; }
.attach-menu button { border: 0; background: transparent; padding: 10px 18px; display: flex; gap: 12px; align-items: center; cursor: pointer; text-align: left; }
.attach-menu button:hover { background: var(--panel-2); }
.attach-menu .ico { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: #fff; }
emoji-picker { --background: #fff; --border-color: transparent; --indicator-color: var(--primary); --input-border-radius: 8px; --outline-color: var(--primary); --category-emoji-size: 1.2rem; width: 360px; max-width: calc(100vw - 20px); height: 380px; }

.load-more { align-self: center; margin: 6px 0 12px; }
.typing-banner { position: absolute; bottom: 70px; left: 50%; transform: translateX(-50%); }

/* ---------- Modal / toast / lightbox ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(11, 20, 26, .45); display: flex; align-items: stretch; z-index: 100; padding: 0; animation: fade .15s; }
.modal { background: var(--panel); width: 100%; height: 100%; max-height: 100dvh; display: flex; flex-direction: column; border-radius: 0; }
.modal header { padding: 14px 8px 8px 18px; font-size: 18px; font-weight: 600; display: flex; align-items: center; border-bottom: 1px solid var(--border); }
.modal header span { flex: 1; }
.modal .content { padding: 14px 18px; overflow: auto; flex: 1; }
.modal footer { padding: 10px 14px calc(10px + env(safe-area-inset-bottom)); display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; border-top: 1px solid var(--border); }
.modal footer .btn { min-height: 44px; flex: 1 1 auto; }
@media (min-width: 640px) {
  .modal-back { display: grid; place-items: center; padding: 16px; }
  .modal { width: min(520px, 100%); height: auto; max-height: calc(100vh - 32px); border-radius: 12px; box-shadow: var(--shadow); }
  .modal.wide { width: min(760px, 100%); }
  .modal header { padding: 18px 22px 8px; border-bottom: 0; }
  .modal .content { padding: 10px 22px; flex: initial; }
  .modal footer { padding: 14px 22px 18px; border-top: 0; flex-wrap: nowrap; }
  .modal footer .btn { min-height: 0; flex: none; }
}
@keyframes fade { from { opacity: 0; } }
#toasts { position: fixed; bottom: calc(76px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 200; align-items: center; }
.toast { background: #233138; color: #fff; padding: 10px 18px; border-radius: 8px; box-shadow: var(--shadow); font-size: 13.5px; animation: fade .2s; max-width: 90vw; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--primary-dark); }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 150; display: grid; place-items: center; cursor: zoom-out; }
.lightbox img, .lightbox video { max-width: 94vw; max-height: 90vh; }
.preview-media { max-width: 100%; max-height: 320px; display: block; margin: 0 auto 10px; border-radius: 8px; }

/* ---------- Aparência ---------- */
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.swatch { width: 34px; height: 34px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #d1d7db; cursor: pointer; overflow: hidden; display: flex; padding: 0; }
.swatch i { flex: 1; }
.color-field { display: flex; align-items: center; gap: 10px; border: 1px solid #d1d7db; border-radius: 8px; padding: 6px 10px; background: #fff; }
.color-field input[type=color] { width: 34px; height: 34px; border: 0; padding: 0; background: none; cursor: pointer; }
.color-field input[type=text] { border: 0; outline: none; width: 90px; font-family: Consolas, monospace; }
.logo-drop { border: 2px dashed #d1d7db; border-radius: 10px; padding: 18px; text-align: center; display: grid; place-items: center; gap: 10px; min-height: 140px; }
.logo-drop img { max-height: 80px; max-width: 240px; object-fit: contain; }
.mock { border-radius: 10px; overflow: hidden; display: flex; height: 300px; border: 1px solid var(--border); background: #fff; }
.mock .m-rail { width: 46px; display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 8px 0; }
.mock .m-rail i { width: 26px; height: 26px; border-radius: 8px; background: rgba(255,255,255,.15); display: block; }
.mock .m-rail i.on { background: var(--m-primary); }
.mock .m-list { width: 38%; border-right: 1px solid var(--border); }
.mock .m-head { height: 40px; background: #f0f2f5; display: flex; align-items: center; padding: 0 10px; gap: 8px; font-weight: 600; font-size: 13px; }
.mock .m-head img { height: 24px; max-width: 100px; object-fit: contain; }
.mock .m-item { display: flex; gap: 8px; padding: 9px 10px; align-items: center; border-bottom: 1px solid var(--border); font-size: 12px; }
.mock .m-item b { width: 26px; height: 26px; border-radius: 50%; background: #dfe5e7; flex: none; }
.mock .m-chat { flex: 1; display: flex; flex-direction: column; padding: 12px; gap: 8px; }
.mock .m-bubble { max-width: 70%; padding: 6px 10px; border-radius: 8px; font-size: 12px; box-shadow: 0 1px .5px rgba(0,0,0,.13); }
.mock .m-send { margin-top: auto; align-self: flex-end; width: 32px; height: 32px; border-radius: 50%; }

/* ---------- Contatos, tags, configurações ---------- */
.tag-chip { background: color-mix(in srgb, var(--c) 16%, white); color: color-mix(in srgb, var(--c) 75%, black); font-weight: 600; }
.tag-picker { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; border: 1px solid #d1d7db; border-radius: 8px; padding: 6px 8px; background: #fff; min-height: 42px; }
.tag-picker .tag-chip { cursor: pointer; padding: 3px 8px 3px 10px; }
.tag-picker .tag-chip::after { content: "×"; margin-left: 6px; opacity: .6; }
.tag-picker input { border: 0; outline: none; flex: 1; min-width: 140px; padding: 4px; }
.tag-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.tag-suggest button { border: 1px dashed #c4ccd0; background: #fff; border-radius: 12px; padding: 2px 10px; cursor: pointer; font-size: 12px; color: var(--muted); }
.tag-suggest button:hover { border-color: var(--primary); color: var(--primary-dark); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar .search-input { flex: 1 1 100%; min-width: 0; }
@media (min-width: 640px) { #toasts { bottom: 20px; } .toolbar .search-input { flex: 1; min-width: 220px; max-width: 420px; } }
.bulkbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; background: var(--primary-soft); border-radius: 8px; padding: 8px 12px; margin-bottom: 12px; }
.table td.check-cell, .table th.check-cell { width: 36px; }
.table input[type=checkbox] { accent-color: var(--primary); width: 16px; height: 16px; }
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.subtabs button { border: 0; background: transparent; padding: 10px 14px; cursor: pointer; color: var(--muted); font-weight: 500; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.subtabs button.active { color: var(--primary-dark); border-bottom-color: var(--primary); }
.switch-row { display: flex; gap: 14px; align-items: flex-start; padding: 14px 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; }
.switch-row .grow b { display: block; margin-bottom: 2px; }
.switch { position: relative; width: 42px; height: 24px; flex: none; margin-top: 2px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #c4ccd0; border-radius: 12px; cursor: pointer; transition: background .15s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: transform .15s; box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::before { transform: translateX(18px); }
.vars { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.vars button { border: 1px solid var(--border); background: var(--panel-2); border-radius: 6px; padding: 2px 8px; font-family: Consolas, monospace; font-size: 12px; cursor: pointer; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat { background: var(--panel-2); border-radius: 10px; padding: 14px 16px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { font-size: 12.5px; color: var(--muted); }
.nps-bar { display: flex; height: 12px; border-radius: 6px; overflow: hidden; background: var(--panel-2); }
.preview-table { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.preview-table table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.preview-table th, .preview-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.preview-table th { background: #fafbfb; position: sticky; top: 0; }
.map-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.error-list { max-height: 180px; overflow: auto; font-size: 12.5px; background: #fff5f6; border-radius: 8px; padding: 8px 12px; }
.qr-pop { width: min(440px, calc(100vw - 20px)); max-height: 380px; display: flex; flex-direction: column; }
.qr-pop .qr-search { padding: 10px; border-bottom: 1px solid var(--border); }
.qr-pop .qr-items { overflow: auto; }
.qr-pop .qr-cat { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; padding: 8px 14px 4px; letter-spacing: .04em; }
.qr-pop .qr-item { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 8px 14px; cursor: pointer; }
.qr-pop .qr-item:hover, .qr-pop .qr-item.sel { background: var(--primary-soft); }
.qr-pop .qr-item b { display: block; font-size: 13.5px; }
.qr-pop .qr-item span { font-size: 12.5px; color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.queue-bar { flex: none; background: var(--panel-2); display: flex; gap: 12px; align-items: center; justify-content: center; padding: 12px 16px; flex-wrap: wrap; text-align: center; color: var(--muted); }
.msg .foot .agent { display: inline-flex; align-items: center; gap: 4px; }
.msg .foot .agent img { width: 16px; height: 16px; border-radius: 50%; object-fit: cover; }
.chat-item .tags-line { display: flex; gap: 4px; overflow: hidden; flex: none; max-width: 45%; }
.chat-item .tags-line .tag { font-size: 10.5px; padding: 0 6px; }
.me-avatar { overflow: hidden; }
.me-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Toque ---------- */
.back-btn { display: inline-grid; }
@media (min-width: 768px) { .back-btn { display: none !important; } }
/* Dedos precisam de alvos de pelo menos 44px */
@media (pointer: coarse) {
  .icon-btn { width: 44px; height: 44px; }
  .btn { min-height: 40px; }
  .btn.small { min-height: 36px; }
  .tabs button { padding: 8px 14px; }
  .check input, .table input[type=checkbox] { width: 20px; height: 20px; }
}

/* ---------- Enquadramento da foto ---------- */
.crop { display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 6px 0; }
.crop-stage {
  position: relative; overflow: hidden; border-radius: 50%; cursor: grab; touch-action: none; user-select: none;
  background: repeating-conic-gradient(#eef0f1 0 25%, #fff 0 50%) 0 0 / 20px 20px;
  box-shadow: 0 0 0 4px var(--primary-soft), 0 0 0 5px var(--primary); outline: none;
}
.crop-stage:focus-visible { box-shadow: 0 0 0 4px var(--primary-soft), 0 0 0 6px var(--primary-dark); }
.crop-stage.dragging { cursor: grabbing; }
.crop-stage img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; pointer-events: none; }
.crop-zoom { display: flex; align-items: center; gap: 8px; width: 280px; }
.crop-zoom input { flex: 1; accent-color: var(--primary); }
.crop-zoom .icon-btn { font-size: 22px; width: 34px; height: 34px; color: var(--text); }
.photo-edit { display: flex; align-items: center; gap: 16px; }
.photo-edit > .stack { flex: 1; min-width: 0; }

/* ---------- Notificações ---------- */
.rail-dot { position: absolute; top: 9px; right: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--danger); box-shadow: 0 0 0 2px var(--secondary); }
.np-status { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 14px 16px; border-radius: 10px; background: var(--panel-2); }
.np-status > svg { flex: none; color: var(--muted); }
.np-status.ok { background: #eafaf1; }
.np-status.ok > svg { color: #0a7b52; }
.np-status.bad { background: #fff3f5; align-items: flex-start; }
.np-status.bad > svg { color: var(--danger); }
.notif-banner { display: flex; gap: 10px; align-items: center; padding: 8px 12px; background: #fff8e1; border-bottom: 1px solid #f6e3a5; font-size: 13px; color: #6b5300; }
.notif-banner .long { display: none; }
@media (min-width: 768px) { .notif-banner { padding: 10px 14px; } .notif-banner .long { display: inline; } .notif-banner .short { display: none; } }

/* Arquivo arquivado no backup em nuvem */
.msg .archived { display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: 330px; padding: 10px; margin-bottom: 4px; border-radius: 8px; background: rgba(0,0,0,.05); color: var(--muted, #667781); }
.msg .archived .grow { display: flex; flex-direction: column; min-width: 0; color: var(--text, #111b21); }
.msg .archived .btn { white-space: nowrap; }
/* Configuração de backup */
.backup-card .provider-pick { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.backup-card .provider-pick label { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border, #e9edef); border-radius: 8px; cursor: pointer; }
.backup-card .provider-pick label:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary) 8%, transparent); }
.backup-card details { border: 1px dashed var(--border, #e9edef); border-radius: 8px; padding: 8px 12px; }
.backup-card details summary { cursor: pointer; font-weight: 600; }
.backup-card details ol { margin: 8px 0 4px; padding-left: 20px; line-height: 1.6; }
.backup-card .bk-result { padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.backup-card .bk-result.ok { background: #e7f8ee; color: #136c38; }
.backup-card .bk-result.bad { background: #fde8ec; color: #a1112f; word-break: break-word; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
@media (min-width: 640px) { .grid2 { grid-template-columns: 1fr 1fr; } }

/* Menu da mensagem (editar / apagar) */
.msg-menu-btn { position: absolute; top: 2px; right: 2px; z-index: 2; width: 26px; height: 22px; border: 0; border-radius: 0 6px 0 12px; cursor: pointer;
  display: grid; place-items: center; color: var(--muted); background: inherit; opacity: 0; transition: opacity .12s; }
.msg:hover .msg-menu-btn, .msg-menu-btn:focus-visible { opacity: 1; }
@media (hover: none) { .msg-menu-btn { opacity: .7; } }
.msg.sticker-msg .msg-menu-btn { background: var(--panel, #fff); border-radius: 50%; }
.popover.msg-menu { min-width: 210px; max-width: 280px; padding: 6px 0; }
.popover.msg-menu button { display: flex; gap: 12px; align-items: flex-start; width: 100%; padding: 9px 16px; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; color: var(--text); }
.popover.msg-menu button:hover:not(:disabled) { background: var(--hover, #f5f6f6); }
.popover.msg-menu button:disabled { cursor: not-allowed; color: var(--muted); }
.popover.msg-menu button span { display: flex; flex-direction: column; }
.popover.msg-menu small { font-size: 11.5px; color: var(--muted); margin-top: 2px; line-height: 1.3; }
.msg .foot .edited { border: 0; background: none; padding: 0; margin-right: 4px; font: inherit; font-style: italic; color: var(--muted); cursor: pointer; }
.msg .foot .edited:hover { text-decoration: underline; }
/* Mensagem apagada: só a equipe vê, com contorno tracejado e texto riscado */
.msg.deleted { background: transparent !important; box-shadow: none; outline: 1.5px dashed #c4cbd0; outline-offset: -1.5px; opacity: .85; }
.msg.deleted .body:not(.revoked), .msg.deleted .doc { text-decoration: line-through; text-decoration-color: #ea003899; color: var(--muted); }
.msg.deleted img.media, .msg.deleted video.media { filter: grayscale(.8); opacity: .6; }
.msg .deleted-tag { font-size: 11.5px; font-weight: 600; color: #b42318; margin: 0 22px 4px 0; }
.edit-history .ver { padding: 10px 12px; border-radius: 8px; background: var(--bubble-out); }
.edit-history .ver:not(.current) .body { color: var(--muted); }
.edit-history .ver .body { white-space: pre-wrap; margin-top: 4px; }

/* Mensagem editada: palavra antiga riscada, nova destacada */
.msg del.ed-old { color: #b42318; text-decoration: line-through; text-decoration-thickness: 1.5px; opacity: .8; }
.msg ins.ed-new { text-decoration: none; background: rgba(37, 163, 90, .16); border-radius: 3px; padding: 0 2px; }
.msg del.ed-old + ins.ed-new { margin-left: 4px; }

/* Resposta (mensagem citada), encaminhada, não enviada, excluída pelo administrador */
.msg .quoted, .reply-bar .quoted { display: flex; flex-direction: column; gap: 2px; border-left: 4px solid var(--qc, var(--primary)); background: rgba(0, 0, 0, .05);
  border-radius: 6px; padding: 6px 10px; margin: 2px 0 6px; font-size: 13px; min-width: 0; max-width: 100%; }
.msg .quoted[data-jump] { cursor: pointer; }
.msg .quoted[data-jump]:hover { background: rgba(0, 0, 0, .08); }
.quoted b { font-size: 12.5px; }
.quoted span { color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; white-space: pre-wrap; word-break: break-word; }
.reply-bar { display: flex; align-items: center; gap: 8px; padding: 6px 12px 0 16px; background: var(--composer-bg, var(--panel, #f0f2f5)); }
.reply-bar[hidden] { display: none; }
.reply-bar .quoted { flex: 1; margin: 0; }
.msg .fwd { display: flex; align-items: center; gap: 4px; font-size: 12px; font-style: italic; color: var(--muted); margin-bottom: 2px; }
.msg.flash { animation: msgflash 1.8s ease; }
@keyframes msgflash { 0%, 40% { box-shadow: 0 0 0 3px rgba(83, 189, 235, .7); } 100% { box-shadow: none; } }
.send-failed { display: flex; align-items: center; gap: 6px; margin: 6px 0 0; padding-top: 6px; border-top: 1px solid rgba(234, 0, 56, .2); font-size: 12px; color: var(--danger); }
.msg.failed { box-shadow: 0 0 0 1.5px rgba(234, 0, 56, .45); }
.msg.purged { background: transparent !important; box-shadow: none; outline: 1.5px dashed #c4cbd0; outline-offset: -1.5px; }
.msg.purged .body { color: var(--muted); font-size: 13px; }
.popover.msg-menu button.danger:not(:disabled) { color: var(--danger); }
.fwd-preview { border-left: 4px solid var(--primary); white-space: pre-wrap; max-height: 80px; overflow: hidden; color: var(--muted); font-size: 13px; padding: 6px 10px; background: rgba(0, 0, 0, .04); border-radius: 6px; }
.fwd-list { max-height: 320px; overflow-y: auto; display: flex; flex-direction: column; border: 1px solid var(--border, #e9edef); border-radius: 8px; }
.fwd-item { display: flex; align-items: center; gap: 10px; padding: 8px 12px; cursor: pointer; }
.fwd-item:hover { background: var(--hover, #f5f6f6); }
.receipts .rc-title { display: flex; align-items: center; gap: 6px; font-weight: 600; font-size: 13px; padding-bottom: 4px; border-bottom: 1px solid var(--border, #e9edef); }
.receipts .rc-item { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.receipts .rc-empty { padding: 6px 0; }

/* Conexão (instância de WhatsApp) de cada conversa */
.conn-chip { display: inline-flex; align-items: center; gap: 3px; max-width: 150px; padding: 1px 7px 1px 5px; border-radius: 10px; font-size: 11px; line-height: 16px;
  color: var(--cc); background: color-mix(in srgb, var(--cc) 12%, transparent); border: 1px solid color-mix(in srgb, var(--cc) 35%, transparent);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }
.conn-chip svg { flex-shrink: 0; }
.chat-item .line.chips { gap: 4px; margin-top: 3px; min-height: 0; }
.chat-item .line.chips:empty { display: none; }
.chat-item .line.chips .tag { font-size: 11px; }
.search { display: flex; gap: 8px; align-items: center; }
.search input { flex: 1; min-width: 0; }
.conn-filter { max-width: 46%; border: 1px solid var(--border, #e9edef); border-left: 4px solid var(--cc, transparent); border-radius: 8px; padding: 6px 8px; font: inherit; font-size: 13px;
  background: var(--panel, #fff); color: var(--text); }
.conn-filter[hidden] { display: none; }
.conn-color input { width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%; overflow: hidden; cursor: pointer; background: none; }
.conn-color input::-webkit-color-swatch-wrapper { padding: 0; }
.conn-color input::-webkit-color-swatch { border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 1px var(--border, #ddd); }

/* Pesquisa de mensagens na conversa: tela cheia no celular, painel à direita a partir de 768px */
.search-panel { position: absolute; z-index: 16; top: 60px; bottom: 0; left: 0; right: 0; background: var(--panel); display: flex; flex-direction: column; }
.search-panel .sp-head { display: flex; gap: 6px; align-items: center; padding: 8px 10px 8px 4px; border-bottom: 1px solid var(--border); }
.search-panel .sp-head .input { flex: 1; min-width: 0; }
.search-panel .sp-info { padding: 8px 14px; }
.search-panel .sp-results { flex: 1; overflow-y: auto; }
.search-panel .sp-item { display: flex; flex-direction: column; gap: 3px; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: none; padding: 10px 14px; cursor: pointer; min-height: 56px; }
.search-panel .sp-item:hover, .search-panel .sp-item.sel { background: var(--panel-2); }
.search-panel .sp-meta { display: flex; gap: 8px; justify-content: space-between; font-size: 12px; color: var(--muted); min-width: 0; }
.search-panel .sp-meta b { color: var(--text); font-weight: 600; }
.search-panel .sp-text { font-size: 13.5px; color: var(--text); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.search-panel .sp-flag { font-size: 11px; color: var(--muted); background: var(--panel-2); border-radius: 6px; padding: 0 5px; }
.search-panel mark, .msg mark.hit { background: #ffe58f; color: inherit; border-radius: 3px; padding: 0 1px; }
@media (min-width: 768px) {
  .search-panel { left: auto; width: min(380px, 55%); border-left: 1px solid var(--border); box-shadow: -4px 0 12px rgba(11, 20, 26, .06); }
  /* a conversa encolhe ao lado do painel, sem nada ficar escondido atrás dele */
  .chat-panel.searching > .messages, .chat-panel.searching > .composer, .chat-panel.searching > .reply-bar,
  .chat-panel.searching > .queue-bar, .chat-panel.searching > .composer-note { margin-right: min(380px, 55%); }
}
