/* =====================================================================
   CRM Atendimento — sistema visual
   Tudo usa as variáveis abaixo: o tema escuro só troca os valores.
   ===================================================================== */
:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-2: #f7f8fa;
  --hover: rgba(11, 20, 26, .06);
  --border: #e4e8eb;
  --text: #111b21;
  --muted: #667781;
  --icon: #54656f;
  --primary: #00a884;
  --primary-hover: #008f72;
  --primary-soft: #d9fdd3;
  --on-primary: #ffffff;
  --danger: #d92d4b;
  --warn: #c77700;
  --ok: #1fa855;
  --input-bg: #ffffff;
  --field: #ffffff;
  --input-border: #d1d7db;
  --shadow: 0 1px 2px rgba(11, 20, 26, .08), 0 4px 14px rgba(11, 20, 26, .06);
  --shadow-lg: 0 12px 40px rgba(11, 20, 26, .22);
  --rail: #ffffff;
  --rail-text: #3b4a54;
  --rail-active: #e7f8f2;
  --rail-active-text: #008069;

  /* chat */
  --chat-bg: #efeae2;
  --wallpaper: url('/bg-light.svg');
  --chat-header: #f0f2f5;
  --composer: #f0f2f5;
  --bubble-in: #ffffff;
  --bubble-out: #d9fdd3;
  --bubble-text: #111b21;
  --bubble-meta: #667781;
  --system-bg: #ffffff;
  --system-text: #54656f;
  --note-bg: #fff3c4;
  --tick: #8696a0;
  --tick-read: #53bdeb;
  --quote-bg: rgba(11, 20, 26, .06);
  --link: #027eb5;
  --radius: 12px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0b141a;
  --surface: #111b21;
  --surface-2: #182229;
  --hover: rgba(255, 255, 255, .07);
  --border: #222d34;
  --text: #e9edef;
  --muted: #8696a0;
  --icon: #aebac1;
  --primary: #00a884;
  --primary-hover: #06cf9c;
  --primary-soft: #103629;
  --on-primary: #ffffff;
  --danger: #f15c6d;
  --warn: #f0b429;
  --ok: #25d366;
  --input-bg: #202c33;
  --field: #2a3942;
  --input-border: #2f3b43;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .25);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, .6);
  --rail: #111b21;
  --rail-text: #aebac1;
  --rail-active: #1f2c34;
  --rail-active-text: #25d366;

  --chat-bg: #0b141a;
  --wallpaper: url('/bg-dark.svg');
  --chat-header: #202c33;
  --composer: #202c33;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --bubble-text: #e9edef;
  --bubble-meta: #ffffff99;
  --system-bg: #182229;
  --system-text: #8696a0;
  --note-bg: #4a4224;
  --tick: #ffffff99;
  --tick-read: #53bdeb;
  --quote-bg: rgba(0, 0, 0, .22);
  --link: #53bdeb;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { font: 14px/1.45 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; }
h3 { font-size: 14px; }
a { color: var(--link); }
#app { height: 100%; }
[hidden] { display: none !important; }
::placeholder { color: var(--muted); opacity: .8; }
* { scrollbar-width: thin; scrollbar-color: color-mix(in srgb, var(--muted) 45%, transparent) transparent; }

/* ---------- controles ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--input-border); background: var(--surface); color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s; }
.btn:hover { background: var(--hover); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 500; }
.btn.primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, var(--input-border)); }
.btn.danger:hover { background: color-mix(in srgb, var(--danger) 10%, transparent); }
.btn.small { padding: 4px 10px; font-size: 12.5px; border-radius: 7px; }
.icon-btn { width: 40px; height: 40px; border: 0; border-radius: 50%; background: none; color: var(--icon); display: inline-grid; place-items: center; font-size: 20px; cursor: pointer; flex-shrink: 0; transition: background .12s; }
.icon-btn:hover { background: var(--hover); }
.icon-btn:disabled { opacity: .4; cursor: default; }
.icon-btn.on { background: var(--hover); color: var(--primary); }
input[type=text], input[type=email], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; padding: 8px 11px; border: 1px solid var(--input-border); border-radius: 8px; background: var(--input-bg); color: var(--text); outline: none; transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 16px; height: 16px; }
input[type=color] { padding: 2px; height: 34px; width: 60px; }
select { appearance: auto; }
textarea { resize: vertical; }
label.field { display: block; margin-bottom: 14px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; font-weight: 500; }
.checks { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 14px; }
.checks label { display: flex; align-items: center; gap: 6px; }
label.checks { cursor: pointer; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0; }
.empty { padding: 36px 20px; text-align: center; color: var(--muted); }
.chip { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; color: #fff; background: #64748b; margin: 0 4px 2px 0; line-height: 17px; }
.chip.toggle { cursor: pointer; opacity: .4; }
.chip.toggle.on { opacity: 1; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #94a3b8; margin-right: 7px; flex-shrink: 0; }
.dot.online { background: var(--ok); }
.dot.paused { background: var(--warn); }
.badge { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--primary); color: #fff; font-size: 11.5px; font-weight: 600; }
.badge.gray { background: #64748b; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card h3 { padding: 16px 18px 6px; font-size: 14.5px; }
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: #202c33; color: #e9edef; padding: 11px 18px; border-radius: 10px; z-index: 90; box-shadow: var(--shadow-lg); max-width: 90vw; }

/* ---------- login ---------- */
.login { height: 100%; display: grid; place-items: center; padding: 16px; background: linear-gradient(180deg, var(--primary) 0 220px, var(--bg) 220px); }
.login form { background: var(--surface); padding: 32px; border-radius: 14px; width: 100%; max-width: 380px; box-shadow: var(--shadow-lg); }
.login h1 { font-size: 21px; margin-bottom: 4px; }
.login p { margin: 0 0 20px; color: var(--muted); }
.login .btn { width: 100%; padding: 10px; }

/* ---------- estrutura ---------- */
.layout { display: grid; grid-template-columns: var(--rail-w, 236px) minmax(0, 1fr); height: 100%; transition: grid-template-columns .15s; }
.layout.collapsed { --rail-w: 72px; }
.sidebar { background: var(--rail); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.brand { display: flex; align-items: center; gap: 11px; padding: 16px 16px 10px; font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; }
.brand .logo { width: 36px; height: 36px; border-radius: 10px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 19px; flex-shrink: 0; }
.nav { flex: 1; padding: 6px 10px; overflow-y: auto; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; color: var(--rail-text); text-decoration: none; cursor: pointer; margin-bottom: 2px; white-space: nowrap; position: relative; }
.nav a:hover { background: var(--hover); }
.nav a.active { background: var(--rail-active); color: var(--rail-active-text); font-weight: 600; }
.nav .ic { width: 22px; text-align: center; font-size: 18px; flex-shrink: 0; }
.nav .t { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav .badge { flex-shrink: 0; }
.nav .sep { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); padding: 16px 12px 5px; white-space: nowrap; overflow: hidden; }
.layout.collapsed .brand .bt, .layout.collapsed .nav .t, .layout.collapsed .nav .sep, .layout.collapsed .userbox .ut { display: none; }
.layout.collapsed .nav a { justify-content: center; padding: 11px 0; }
.layout.collapsed .nav .badge { position: absolute; top: 2px; right: 8px; min-width: 16px; height: 16px; font-size: 10px; padding: 0 4px; }
.userbox { border-top: 1px solid var(--border); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.wa-status { font-size: 11.5px; padding: 4px 10px; border-radius: 8px; background: var(--hover); color: var(--muted); display: flex; align-items: center; gap: 7px; white-space: nowrap; overflow: hidden; }
.wa-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #94a3b8; flex-shrink: 0; }
.wa-status.conectado::before { background: var(--ok); }
.wa-status.aguardando_qr::before, .wa-status.conectando::before { background: var(--warn); }
.wa-status.desconectado::before { background: var(--danger); }
.wa-status.inline { display: inline-flex; font-size: 13px; }
.layout.collapsed .wa-status span { display: none; }
.layout.collapsed .wa-status { justify-content: center; padding: 6px; }
.user-row { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 6px; border-radius: 10px; min-width: 0; }
.user-row:hover { background: var(--hover); }
.user-row .ut { min-width: 0; flex: 1; line-height: 1.25; }
.user-row .ut b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .ut small { color: var(--muted); }
.avatar { width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center; color: #fff; font-weight: 600; flex-shrink: 0; position: relative; font-size: 15px; user-select: none; }
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }
.avatar.lg { width: 48px; height: 48px; font-size: 17px; }
.avatar .st { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--rail); background: #94a3b8; }
.avatar .st.online { background: var(--ok); }
.avatar .st.paused { background: var(--warn); }
.menu { position: fixed; z-index: 80; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 6px; min-width: 220px; }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; border: 0; background: none; padding: 9px 12px; border-radius: 8px; cursor: pointer; text-align: left; }
.menu button:hover { background: var(--hover); }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 5px 0; }
.menu .head { padding: 8px 12px 6px; }
.menu select { margin-top: 6px; }
.main { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- páginas ---------- */
.page { padding: 26px clamp(16px, 3vw, 40px) 40px; overflow-y: auto; flex: 1; }
.page > * { max-width: 1240px; margin-left: auto; margin-right: auto; }
.page-head { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h2 { font-size: 21px; flex: 1; min-width: 160px; }
.page-head input[type=search] { max-width: 300px; }
.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: -6px auto 16px; }
.pills { display: flex; gap: 6px; flex-wrap: wrap; }
.pill { border: 1px solid var(--input-border); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 15px; cursor: pointer; font-size: 13px; }
.pill:hover { background: var(--hover); }
.pill.active { background: var(--primary-soft); border-color: var(--primary); color: var(--text); font-weight: 600; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tr.click { cursor: pointer; }
tr.click:hover { background: var(--hover); }
td.actions { text-align: right; white-space: nowrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 16px 18px; }
.stat .v { font-size: 26px; font-weight: 700; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.bar { height: 8px; border-radius: 4px; background: var(--primary); min-width: 2px; }
.days { display: flex; align-items: flex-end; gap: 5px; height: 150px; padding: 12px 18px 16px; }
.days .d { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; font-size: 10px; color: var(--muted); min-width: 0; }
.days .d i { display: block; width: 100%; max-width: 34px; background: var(--primary); border-radius: 5px 5px 0 0; min-height: 2px; }
.tabbar { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0 auto 18px; overflow-x: auto; }
.tabbar button { border: 0; background: none; padding: 11px 16px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabbar button:hover { color: var(--text); }
.tabbar button.active { color: var(--primary); border-bottom-color: var(--primary); }
.pad { padding: 18px; }
.pad > h3:first-child { padding: 0 0 12px; font-size: 15px; }

/* ---------- modais ---------- */
.overlay { position: fixed; inset: 0; background: rgba(11, 20, 26, .55); backdrop-filter: blur(2px); display: grid; place-items: center; padding: 16px; z-index: 70; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 480px; max-height: 92vh; overflow: auto; padding: 24px; box-shadow: var(--shadow-lg); }
.modal.wide { max-width: 680px; }
.modal h2 { font-size: 18px; margin-bottom: 16px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.code { background: #0b141a; color: #e2e8f0; padding: 12px; border-radius: 8px; font: 12px/1.5 Consolas, monospace; overflow-x: auto; white-space: pre; user-select: all; }
.note { background: var(--note-bg); border: 1px solid color-mix(in srgb, var(--warn) 30%, transparent); border-radius: 8px; padding: 8px 11px; margin-bottom: 6px; white-space: pre-wrap; overflow-wrap: anywhere; }
.note small { display: block; color: var(--muted); margin-top: 4px; }
.preview { background: var(--primary-soft); border-radius: 10px; padding: 10px 12px; white-space: pre-wrap; margin: 0; }

/* =====================================================================
   ATENDIMENTO (lista + chat no estilo do WhatsApp)
   ===================================================================== */
.inbox { display: grid; grid-template-columns: 380px minmax(0, 1fr) auto; height: 100%; min-height: 0; }
.conv-list { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.list-head { padding: 14px 16px 6px; display: flex; align-items: center; justify-content: space-between; }
.list-head h2 { font-size: 20px; }
.search { margin: 6px 12px 8px; position: relative; }
.search input { padding-left: 36px; border-radius: 10px; background: var(--surface-2); border-color: transparent; }
.search::before { content: '🔍'; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); font-size: 13px; opacity: .55; }
.tabs { display: flex; gap: 6px; padding: 0 12px 10px; overflow-x: auto; }
.tabs button { border: 0; background: var(--surface-2); color: var(--muted); border-radius: 999px; padding: 6px 13px; cursor: pointer; white-space: nowrap; font-size: 13px; display: inline-flex; align-items: center; gap: 6px; }
.tabs button:hover { background: var(--hover); }
.tabs button.active { background: var(--primary-soft); color: var(--text); font-weight: 600; }
.conv-items { overflow-y: auto; flex: 1; }
.conv-item { display: flex; gap: 12px; padding: 0 0 0 14px; cursor: pointer; align-items: center; }
.conv-item:hover { background: var(--hover); }
.conv-item.active { background: var(--hover); }
.conv-body { min-width: 0; flex: 1; padding: 11px 14px 11px 0; border-bottom: 1px solid var(--border); }
.conv-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conv-name { font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.conv-time { font-size: 12px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.conv-item.unread .conv-time { color: var(--primary); }
.conv-item.unread .conv-name { font-weight: 600; }
.conv-bot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 2px; }
.conv-last { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 13.5px; min-width: 0; flex: 1; }
.conv-last .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-meta { display: flex; align-items: center; gap: 5px; margin-top: 4px; flex-wrap: wrap; }
.status-chip { font-size: 10.5px; padding: 1px 8px; border-radius: 999px; background: var(--hover); color: var(--muted); font-weight: 600; }
.status-chip.queued { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.status-chip.open { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.server-tag { margin-left: 6px; font-size: 10px; padding: 0 7px; vertical-align: middle; font-weight: 600; line-height: 16px; }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); position: relative; }
.chat-empty { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; padding: 24px; background: var(--surface-2); border-bottom: 6px solid var(--primary); }
.chat-empty .big { font-size: 56px; margin-bottom: 10px; }
.chat-empty h3 { font-size: 24px; font-weight: 300; color: var(--text); margin-bottom: 6px; }
.chat-head { min-height: 60px; display: flex; align-items: center; gap: 12px; padding: 8px 14px; background: var(--chat-header); border-bottom: 1px solid var(--border); flex-shrink: 0; }
.chat-head .title { flex: 1; min-width: 0; line-height: 1.25; cursor: pointer; }
.chat-head .title b { display: block; font-size: 16px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .title small { color: var(--muted); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.messages { flex: 1; overflow-y: auto; padding: 14px max(14px, 5%) 12px; display: flex; flex-direction: column; gap: 2px; background: var(--chat-bg) var(--wallpaper); min-height: 0; }
.day-sep { align-self: center; background: var(--system-bg); color: var(--system-text); font-size: 12.5px; padding: 5px 12px; border-radius: 8px; box-shadow: 0 1px 1px rgba(11, 20, 26, .12); margin: 12px 0 8px; text-transform: uppercase; letter-spacing: .02em; }
.msg { position: relative; max-width: min(68%, 560px); padding: 6px 8px 7px 9px; border-radius: 8px; background: var(--bubble-in); color: var(--bubble-text); box-shadow: 0 1px .5px rgba(11, 20, 26, .13); font-size: 14.2px; line-height: 19px; white-space: pre-wrap; overflow-wrap: anywhere; align-self: flex-start; }
.msg.first { margin-top: 8px; }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg.first.in { border-top-left-radius: 0; }
.msg.first.out { border-top-right-radius: 0; }
.msg.first::before { content: ''; position: absolute; top: 0; width: 9px; height: 14px; background: inherit; }
.msg.first.in::before { left: -8px; clip-path: polygon(100% 0, 100% 100%, 0 0); }
.msg.first.out::before { right: -8px; clip-path: polygon(0 0, 100% 0, 0 100%); }
.msg .from { font-size: 12.8px; font-weight: 600; margin-bottom: 1px; line-height: 17px; }
.msg .text { white-space: pre-wrap; }
.msg .text a { color: var(--link); }
.msg .meta { float: right; margin: 5px -2px -3px 12px; font-size: 11px; line-height: 15px; color: var(--bubble-meta); display: inline-flex; align-items: center; gap: 3px; user-select: none; height: 15px; }
.msg .meta .fail { color: var(--danger); font-weight: 700; }
.ticks { display: inline-flex; color: var(--tick); }
.ticks.read { color: var(--tick-read); }
.ticks svg { display: block; }
.msg.internal { background: var(--note-bg); align-self: flex-end; }
.msg.internal .from { color: var(--warn); }
.msg.system { align-self: center; max-width: 82%; background: var(--system-bg); color: var(--system-text); font-size: 12.5px; text-align: center; padding: 5px 12px; border-radius: 8px; margin: 8px 0; }
.msg.system.first::before { display: none; }
.msg.sticker { background: transparent; box-shadow: none; padding: 2px; }
.msg.sticker::before { display: none; }
.msg.sticker .meta { float: none; display: flex; justify-content: flex-end; margin: 0; background: var(--system-bg); border-radius: 8px; padding: 0 6px; width: max-content; margin-left: auto; }
.msg.mediaonly { padding: 3px; }
.msg.mediaonly .meta { position: absolute; right: 8px; bottom: 6px; margin: 0; color: #fff; text-shadow: 0 0 4px rgba(0, 0, 0, .65); }
.msg.mediaonly .ticks { color: #fff; }
.msg.mediaonly .ticks.read { color: var(--tick-read); }
.msg .media { display: block; max-width: 100%; max-height: 320px; border-radius: 6px; }
.msg img.media { cursor: zoom-in; min-width: 120px; background: var(--hover); }
.msg audio.media { width: 260px; max-width: 100%; height: 40px; }
.msg .media.sticker { max-height: 160px; min-width: 0; background: none; cursor: default; }
.msg a.file { display: flex; align-items: center; gap: 10px; padding: 9px 11px; margin-bottom: 4px; border-radius: 7px; background: var(--quote-bg); color: inherit; text-decoration: none; min-width: 200px; }
.msg a.file .fi { font-size: 26px; }
.msg a.file b { font-weight: 500; word-break: break-all; }
.msg-menu { position: absolute; top: 2px; right: 3px; border: 0; background: linear-gradient(90deg, transparent, var(--bubble-in) 40%); color: var(--icon); cursor: pointer; opacity: 0; font-size: 16px; line-height: 1; padding: 2px 4px 2px 14px; border-radius: 0 8px 0 0; }
.msg.out .msg-menu { background: linear-gradient(90deg, transparent, var(--bubble-out) 40%); }
.msg.internal .msg-menu { background: linear-gradient(90deg, transparent, var(--note-bg) 40%); }
.msg:hover .msg-menu { opacity: 1; }
.msg.system .msg-menu, .msg.sticker .msg-menu { display: none; }
.quote { border-left: 4px solid var(--primary); background: var(--quote-bg); border-radius: 6px; padding: 4px 9px 5px 10px; margin: 1px 0 5px; cursor: pointer; font-size: 13px; line-height: 17px; overflow: hidden; }
.quote .qn { font-weight: 600; color: var(--primary); font-size: 12.8px; }
.quote .qt { color: var(--bubble-meta); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-wrap; }
.msg.flash { animation: flashmsg 1.4s ease-out; }
@keyframes flashmsg { 0%, 40% { box-shadow: 0 0 0 100vmax color-mix(in srgb, var(--primary) 18%, transparent) inset; } 100% { box-shadow: 0 1px .5px rgba(11, 20, 26, .13); } }

/* barra de atalhos, resposta e caixa de mensagem */
.quick-bar { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px; background: var(--composer); border-top: 1px solid var(--border); }
.qbtn { background: var(--surface); border: 1px solid var(--input-border); border-radius: 999px; padding: 5px 13px; cursor: pointer; color: var(--text); font-size: 13px; max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qbtn:hover { background: var(--primary-soft); border-color: var(--primary); }
.qbtn.pix { border-color: var(--primary); font-weight: 600; }
.qbtn.static { cursor: default; display: inline-block; }
.qbtn.static:hover { background: var(--surface); border-color: var(--input-border); }
.reply-bar { display: flex; align-items: center; gap: 10px; padding: 8px 14px 0; background: var(--composer); }
.reply-bar .quote { flex: 1; margin: 0; cursor: default; background: var(--surface); }
.composer { position: relative; display: flex; align-items: flex-end; gap: 6px; padding: 8px 12px 10px; background: var(--composer); flex-shrink: 0; }
.composer .grow { flex: 1; min-width: 0; position: relative; }
.composer textarea { width: 100%; min-height: 42px; max-height: 150px; padding: 10px 14px; border: 0; border-radius: 10px; background: var(--field); resize: none; line-height: 21px; display: block; box-shadow: none; }
.composer textarea:focus { box-shadow: none; }
.composer.internal textarea { background: var(--note-bg); }
.composer .send { background: var(--primary); color: #fff; }
.composer .send:hover { background: var(--primary-hover); }
.composer .send svg { display: block; }
.locked { padding: 16px; background: var(--composer); border-top: 1px solid var(--border); color: var(--muted); display: flex; align-items: center; justify-content: center; gap: 12px; text-align: center; flex-wrap: wrap; }
.quick-pop { position: absolute; bottom: calc(100% + 6px); left: 0; right: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); max-height: 240px; overflow: auto; z-index: 5; }
.quick-pop div { padding: 9px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.quick-pop div:last-child { border-bottom: 0; }
.quick-pop div:hover, .quick-pop div.sel { background: var(--hover); }
.quick-pop b { color: var(--primary); margin-right: 8px; }
.attach-menu { position: absolute; bottom: calc(100% + 8px); left: 52px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); padding: 8px; min-width: 220px; z-index: 6; }
.attach-menu button { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; padding: 10px 12px; border-radius: 9px; cursor: pointer; text-align: left; }
.attach-menu button:hover { background: var(--hover); }
.attach-menu .ai { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; color: #fff; font-size: 17px; }

/* emojis e figurinhas */
.picker { position: absolute; bottom: 100%; left: 0; width: min(420px, 100%); height: 340px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px 14px 0 0; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; z-index: 6; overflow: hidden; }
.picker-tabs { display: flex; background: var(--chat-header); border-bottom: 1px solid var(--border); }
.picker-tabs button { flex: 1; border: 0; background: none; padding: 11px 4px; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 500; }
.picker-tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }
.picker-body { overflow: auto; flex: 1; padding: 4px 10px 10px; }
.picker-title { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 2px 4px; }
.picker-grid { display: grid; grid-template-columns: repeat(8, 1fr); }
.emo { border: 0; background: none; font-size: 24px; line-height: 1; padding: 6px 0; cursor: pointer; border-radius: 8px; }
.emo:hover { background: var(--hover); }
.sticker-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 6px 2px; }
.sticker-cell { position: relative; }
.sticker-btn { width: 100%; aspect-ratio: 1; border: 0; background: var(--surface-2); border-radius: 10px; padding: 5px; cursor: pointer; }
.sticker-btn:hover { background: var(--primary-soft); }
.sticker-btn img { width: 100%; height: 100%; object-fit: contain; display: block; }
.sticker-del { position: absolute; top: 3px; right: 3px; border: 0; background: rgba(0, 0, 0, .55); color: #fff; width: 20px; height: 20px; border-radius: 50%; font-size: 10px; line-height: 20px; padding: 0; cursor: pointer; display: none; }
.sticker-cell:hover .sticker-del { display: block; }

/* painel de dados do contato */
.contact-panel { width: 340px; background: var(--surface); border-left: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; display: flex; flex-direction: column; min-height: 0; }
.contact-panel[hidden] { display: none !important; }
.info-head { display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--chat-header); border-bottom: 1px solid var(--border); min-height: 60px; position: sticky; top: 0; z-index: 2; }
.info-head b { flex: 1; font-weight: 500; font-size: 16px; }
.info-body { padding: 4px 16px 24px; }
.info-hero { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 22px 0 14px; text-align: center; }
.info-hero .avatar { width: 96px; height: 96px; font-size: 36px; }
.info-hero b { font-size: 19px; font-weight: 500; }
.info-block { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.info-block h3 { text-transform: uppercase; font-size: 11.5px; letter-spacing: .06em; color: var(--muted); margin: 0 0 8px; padding: 0; display: flex; align-items: center; justify-content: space-between; }
.info-body > h3, .contact-panel > h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 8px; }
.sum-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.sum-line { font-size: 13.5px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 2px 0; overflow-wrap: anywhere; }
.sum-val { font-weight: 500; }
.iptv-card { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: var(--surface); }
.iptv-line { font-size: 13px; overflow-wrap: anywhere; }
.iptv-device { font-size: 13px; padding: 2px 0; display: flex; align-items: center; }
.hist { padding: 6px 0; border-bottom: 1px solid var(--border); font-size: 13px; }

/* ---------- menu automático ---------- */
.bot-block { padding: 18px; margin-bottom: 14px; }
.bot-block.flash { animation: botflash 1.6s ease-out; }
@keyframes botflash { from { box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 55%, transparent); } to { box-shadow: var(--shadow); } }
.bot-block[style*="margin-left"] { border-left: 4px solid color-mix(in srgb, var(--primary) 45%, transparent); }
.bot-block-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.bot-block-head .btn.small:first-child { width: 30px; padding: 4px 0; }
.bot-trail { font-size: 12px; color: var(--muted); margin: -6px 0 10px 40px; }
.bot-trail.warn { color: var(--warn); }
.bot-cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 18px; }
.bot-sub { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; margin: 0 0 8px; padding: 0 !important; }
.bot-option { border: 1px solid var(--border); border-radius: 12px; padding: 10px; margin-bottom: 8px; background: var(--surface-2); }
.bot-option-head { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.bot-option-head b { width: 22px; text-align: center; color: var(--muted); }
.bot-option-body { display: grid; gap: 6px; }
.bot-option-body textarea { resize: vertical; }
.add-option { width: 100%; border: 2px dashed var(--input-border); background: none; border-radius: 12px; padding: 10px; color: var(--primary); cursor: pointer; font-weight: 600; margin-bottom: 8px; }
.add-option:hover { background: var(--primary-soft); border-color: var(--primary); }

/* ---------- funil ---------- */
.kanban { display: flex; gap: 12px; align-items: flex-start; overflow-x: auto; padding-bottom: 12px; min-height: 60vh; }
.kcol { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); width: 250px; flex-shrink: 0; padding: 10px; border-top: 4px solid #64748b; }
.kcol.over { outline: 2px dashed var(--primary); }
.kcol-head { display: flex; align-items: center; justify-content: space-between; font-weight: 600; margin-bottom: 8px; gap: 6px; }
.kcol-head a { cursor: pointer; color: var(--muted); font-weight: 400; font-size: 12px; }
.kcard { background: var(--surface); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.kcard small { display: block; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

/* ---------- responsivo ---------- */
@media (max-width: 1280px) {
  .inbox { grid-template-columns: 330px minmax(0, 1fr) auto; }
  .contact-panel { width: 310px; }
}
@media (max-width: 1020px) {
  .layout { --rail-w: 72px; }
  .layout .brand .bt, .layout .nav .t, .layout .nav .sep, .layout .userbox .ut { display: none; }
  .layout .nav a { justify-content: center; padding: 11px 0; }
  .layout .wa-status span { display: none; }
  .layout .wa-status { justify-content: center; padding: 6px; }
  .contact-panel { position: absolute; right: 0; top: 0; bottom: 0; z-index: 8; box-shadow: var(--shadow-lg); }
  .inbox { position: relative; }
}
@media (max-width: 760px) {
  .inbox { grid-template-columns: 1fr; }
  .inbox .conv-list { display: flex; }
  .inbox.chat-open .conv-list { display: none; }
  .inbox:not(.chat-open) .chat { display: none; }
  .back-btn { display: inline-grid !important; }
  .bot-cols { grid-template-columns: 1fr; }
  .msg { max-width: 86%; }
}
.back-btn { display: none; }

.login .link { display: block; text-align: center; margin-top: 14px; cursor: pointer; font-size: 13px; }
