:root {
  --bg: #eae6df;
  --panel: #ffffff;
  --panel-2: #f0f2f5;
  --border: #e3e6e8;
  --text: #111b21;
  --muted: #667781;
  --green: #00a884;
  --green-dark: #008069;
  --green-light: #d9fdd3;
  --chat-bg: #efeae2;
  --danger: #ea0038;
  --warn: #e9a100;
  --info: #027eb5;
  --rail: #f0f2f5;
  --shadow: 0 2px 10px rgba(11, 20, 26, .12);
  --radius: 8px;
  --tick: #667781;
  --tick-read: #53bdeb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1317; --panel: #111b21; --panel-2: #202c33; --border: #2a3942; --text: #e9edef;
    --muted: #8696a0; --green-light: #005c4b; --chat-bg: #0b141a; --rail: #202c33; --shadow: 0 2px 10px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.4 "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--text); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

.app { display: flex; height: 100vh; }
.app[hidden] { display: none; }
.rail { width: 76px; background: var(--rail); border-right: 1px solid var(--border); display: flex; flex-direction: column; align-items: center; padding: 10px 0; gap: 4px; }
.rail .brand { width: 42px; height: 42px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 700; margin-bottom: 10px; }
.rail button { position: relative; width: 64px; padding: 8px 0 6px; border: 0; background: none; border-radius: 10px; cursor: pointer; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 10.5px; }
.rail button svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.rail button:hover { background: rgba(0,0,0,.05); }
.rail button.active { color: var(--green-dark); background: rgba(0,168,132,.12); }
.rail .spacer { flex: 1; }
.rail .badge { position: absolute; top: 2px; right: 10px; background: var(--green); color: #fff; border-radius: 10px; font-size: 10px; padding: 0 5px; min-width: 16px; }
.conn { width: 12px; height: 12px; border-radius: 50%; background: var(--danger); margin: 10px 0; cursor: pointer; }
.conn.ok { background: var(--green); }
.conn.wait { background: var(--warn); }

main { flex: 1; min-width: 0; display: flex; }

/* ---------- comuns ---------- */
.btn { border: 1px solid var(--border); background: var(--panel); padding: 7px 14px; border-radius: 20px; cursor: pointer; white-space: nowrap; }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger.fill { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.sm { padding: 4px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: none; cursor: pointer; padding: 6px; border-radius: 50%; color: var(--muted); }
.icon-btn:hover { background: rgba(0,0,0,.06); }
input[type=text], input[type=number], input[type=time], input[type=search], input[type=tel], select, textarea {
  border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 8px 10px; width: 100%; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--green); }
textarea { resize: vertical; min-height: 80px; }
label { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 4px; }
label.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-size: 14px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; min-width: 0; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 10px; font-size: 11.5px; color: #fff; background: var(--muted); margin: 1px 2px 1px 0; white-space: nowrap; }
.chip.outline { background: none; border: 1px solid var(--border); color: var(--muted); }
.tag-red { background: var(--danger); }

.page { flex: 1; overflow: auto; padding: 24px 32px; background: var(--panel-2); }
.page h1 { margin: 0 0 4px; font-size: 22px; font-weight: 600; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head .grow { flex: 1; }
.card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }

table { width: 100%; border-collapse: collapse; background: var(--panel); }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--panel-2); position: sticky; top: 0; }
tr:hover td { background: rgba(0,0,0,.02); }
.table-wrap { border-radius: var(--radius); overflow: auto; box-shadow: var(--shadow); max-height: calc(100vh - 220px); }

.overlay { position: fixed; inset: 0; background: rgba(11,20,26,.55); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border-radius: 12px; width: min(640px, 100%); max-height: 92vh; overflow: auto; padding: 22px; box-shadow: var(--shadow); }
.modal.wide { width: min(980px, 100%); }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

#toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 99; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #323739; color: #fff; padding: 10px 18px; border-radius: 8px; box-shadow: var(--shadow); max-width: 520px; }
.toast.error { background: var(--danger); }

/* ---------- QR ---------- */
.qr-card { background: var(--panel); border-radius: 12px; padding: 40px; display: flex; gap: 40px; max-width: 900px; box-shadow: var(--shadow); flex-wrap: wrap; }
.qr-text { flex: 1; min-width: 280px; }
.qr-text h2 { font-weight: 300; font-size: 26px; margin-top: 0; }
.qr-text ol { line-height: 2; padding-left: 20px; }
.qr-box { width: 300px; height: 300px; display: grid; place-items: center; text-align: center; color: var(--muted); }
.qr-box img { width: 300px; height: 300px; background: #fff; border-radius: 8px; }
.tip { background: rgba(233,161,0,.12); border-left: 3px solid var(--warn); padding: 10px 12px; border-radius: 6px; font-size: 13px; }
.spinner { width: 36px; height: 36px; border: 3px solid var(--border); border-top-color: var(--green); border-radius: 50%; animation: spin 1s linear infinite; margin: 0 auto 10px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Conversas ---------- */
.conv-list { width: 380px; min-width: 300px; background: var(--panel); border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.conv-list header { padding: 14px 16px 8px; display: flex; align-items: center; gap: 8px; }
.conv-list header h2 { flex: 1; margin: 0; font-size: 20px; }
.conv-search { padding: 0 12px 8px; }
.conv-search input { background: var(--panel-2); border: 0; border-radius: 8px; }
.tabs { display: flex; gap: 6px; padding: 0 12px 8px; }
.tabs button { border: 0; background: var(--panel-2); padding: 5px 12px; border-radius: 16px; cursor: pointer; color: var(--muted); font-size: 13px; }
.tabs button.active { background: rgba(0,168,132,.15); color: var(--green-dark); font-weight: 600; }
.conv-items { overflow: auto; flex: 1; }
.conv-item { display: flex; gap: 12px; padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border); align-items: center; }
.conv-item:hover { background: var(--panel-2); }
.conv-item.active { background: var(--panel-2); }
.avatar { width: 46px; height: 46px; border-radius: 50%; background: #dfe5e7; color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 17px; flex-shrink: 0; }
.conv-item .body { flex: 1; min-width: 0; }
.conv-item .top { display: flex; justify-content: space-between; gap: 8px; }
.conv-item .name { font-size: 15.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-item .time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.conv-item .bottom { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.conv-item .last { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13.5px; }
.conv-item .unread { background: var(--green); color: #fff; border-radius: 12px; font-size: 11.5px; padding: 1px 7px; font-weight: 600; }
.conv-item.has-unread .time { color: var(--green); }

.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.chat-empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); background: var(--panel-2); border-bottom: 6px solid var(--green); }
.chat-empty h2 { font-weight: 300; font-size: 28px; color: var(--text); }
.chat header { background: var(--panel-2); padding: 10px 16px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--border); }
.chat header .info { flex: 1; min-width: 0; }
.chat header .info b { font-weight: 500; font-size: 16px; }
.messages { flex: 1; overflow: auto; padding: 18px 7%; display: flex; flex-direction: column; gap: 3px;
  background-image: radial-gradient(rgba(0,0,0,.035) 1px, transparent 1px); background-size: 18px 18px; }
.msg { max-width: 65%; padding: 6px 9px 4px; border-radius: 8px; background: var(--panel); box-shadow: 0 1px .5px rgba(11,20,26,.13); align-self: flex-start; white-space: pre-wrap; word-wrap: break-word; position: relative; }
.msg.me { align-self: flex-end; background: var(--green-light); }
.msg .meta { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; }
.msg .src { font-style: italic; }
.msg.media .kind { color: var(--muted); font-style: italic; }
.day-sep { align-self: center; background: var(--panel); color: var(--muted); font-size: 12px; padding: 4px 12px; border-radius: 8px; margin: 10px 0; box-shadow: 0 1px .5px rgba(11,20,26,.13); }
.composer { background: var(--panel-2); padding: 10px 16px; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; border-radius: 8px; border: 0; resize: none; padding: 11px 12px; }
.composer .send { width: 44px; height: 44px; border-radius: 50%; border: 0; background: var(--green); color: #fff; cursor: pointer; display: grid; place-items: center; flex-shrink: 0; }
.composer .send svg { width: 20px; fill: currentColor; }
.closed-bar { background: var(--panel-2); padding: 14px; text-align: center; color: var(--muted); }

/* ---------- campanhas ---------- */
.progress { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; display: flex; }
.progress i { display: block; height: 100%; }
.progress .s { background: var(--green); } .progress .f { background: var(--danger); } .progress .k { background: var(--warn); }
.status { font-size: 11.5px; padding: 2px 8px; border-radius: 10px; font-weight: 600; text-transform: uppercase; }
.st-draft { background: var(--panel-2); color: var(--muted); }
.st-running { background: rgba(0,168,132,.15); color: var(--green-dark); }
.st-paused { background: rgba(233,161,0,.18); color: #a06e00; }
.st-completed { background: rgba(2,126,181,.13); color: var(--info); }
.st-cancelled { background: rgba(234,0,56,.12); color: var(--danger); }
.warnings { display: flex; flex-direction: column; gap: 6px; }
.w { padding: 8px 10px; border-radius: 6px; font-size: 13px; border-left: 3px solid; }
.w.danger { background: rgba(234,0,56,.08); border-color: var(--danger); }
.w.warn { background: rgba(233,161,0,.1); border-color: var(--warn); }
.w.info { background: rgba(2,126,181,.08); border-color: var(--info); }
.risk { font-weight: 700; text-transform: uppercase; }
.risk.alto { color: var(--danger); } .risk.médio { color: var(--warn); } .risk.baixo { color: var(--green); }
.preview-bubble { background: var(--green-light); padding: 8px 10px; border-radius: 8px; white-space: pre-wrap; margin-top: 6px; }
.stats { display: flex; gap: 18px; flex-wrap: wrap; margin: 10px 0; }
.stats div b { display: block; font-size: 20px; }
.split { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } .conv-list { width: 100%; } }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.guide li { margin-bottom: 6px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; margin-top: 10px; }
.bulkbar { display: flex; gap: 8px; align-items: center; background: rgba(0,168,132,.1); padding: 8px 12px; border-radius: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.color-dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; vertical-align: middle; }
.group-checks { display: flex; flex-wrap: wrap; gap: 6px 14px; max-height: 160px; overflow: auto; padding: 6px 0; }
.group-checks label { margin: 0; }

/* ---------- login ---------- */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: linear-gradient(180deg, var(--green-dark) 0 220px, var(--bg) 220px); }
.login-card { background: var(--panel); border-radius: 12px; box-shadow: var(--shadow); padding: 32px; width: min(400px, 100%); }
.login-card h1 { margin: 12px 0 2px; font-size: 22px; font-weight: 600; }
.brand.big { width: 52px; height: 52px; border-radius: 50%; background: var(--green); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 18px; }
input[type=password] { border: 1px solid var(--border); background: var(--panel); border-radius: 8px; padding: 8px 10px; width: 100%; outline: none; }
/* personalização */
.brand.has-logo { background: transparent; border-radius: 10px; overflow: hidden; }
.brand img { width: 100%; height: 100%; object-fit: contain; display: block; }
.login-screen.custom-bg { background-size: cover; background-position: center; background-repeat: no-repeat; }
.brand-item { display: flex; gap: 14px; align-items: flex-start; margin-top: 12px; }
.brand-prev { flex: none; display: grid; place-items: center; border: 1px dashed var(--border); border-radius: 8px; overflow: hidden; background: var(--bg); }
.brand-prev.logo { width: 64px; height: 64px; }
.brand-prev.bg { width: 112px; height: 64px; }
.brand-prev img { width: 100%; height: 100%; object-fit: contain; }
.brand-prev.bg img { object-fit: cover; }
.login-error { color: var(--danger); min-height: 18px; font-size: 13px; margin: 10px 0; }
.btn.block { width: 100%; padding: 10px; }

/* ---------- rail extras ---------- */
.rail-sep { width: 40px; border-top: 1px solid var(--border); margin: 6px 0; }
.rail .badge.warn { background: var(--warn); }
.me-btn { border: 0; background: none; cursor: pointer; padding: 2px; border-radius: 50%; margin-bottom: 4px; }
.avatar.sm { width: 30px; height: 30px; font-size: 13px; }
.rail .me-btn .avatar { width: 36px; height: 36px; }

/* ---------- WhatsApp / contas ---------- */
.chip.acc { background: none; color: var(--c); border: 1px solid var(--c); }
.ok-text { color: var(--green-dark); }
.warn-text { color: #a06e00; }
@media (prefers-color-scheme: dark) { .ok-text { color: var(--green); } .warn-text { color: var(--warn); } }
.chat-acc { text-align: right; }
.acc-pick { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.acc-pick .btn { text-align: left; border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; gap: 8px; }
.wa-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 14px; }
.wa-card { display: flex; flex-direction: column; gap: 10px; }
.wa-head { display: flex; align-items: center; gap: 8px; font-size: 16px; }
.wa-head .grow, .wa-actions .grow { flex: 1; }
.wa-live { min-height: 60px; }
.wa-live p { margin: 2px 0; }
.wa-qr { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.wa-qr img { width: 200px; height: 200px; background: #fff; border-radius: 8px; padding: 4px; }
.wa-qr ol { padding-left: 18px; margin: 0; line-height: 1.8; flex: 1; min-width: 140px; }
.wa-wait { display: flex; align-items: center; gap: 12px; }
.wa-wait .spinner { margin: 0; width: 24px; height: 24px; }
.wa-access { border-top: 1px solid var(--border); padding-top: 8px; }
.wa-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; border-top: 1px solid var(--border); padding-top: 10px; }
.empty-state { max-width: 460px; margin: 80px auto; text-align: center; }
tr.inactive td { opacity: .55; }

/* ---------- mensagens: atendente e status ---------- */
.msg .author { font-size: 12.5px; font-weight: 600; margin-bottom: 2px; }
.msg .failed { color: var(--danger); font-size: 12px; margin-top: 3px; }
.msg.error { box-shadow: 0 0 0 1px var(--danger); }
.tick { display: inline-flex; align-items: center; cursor: help; }
.tick svg { width: 16px; height: 11px; fill: none; stroke: var(--tick); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.tick.st-0 svg, .tick.st-1 svg { width: 12px; height: 12px; }
.tick.st-0 svg { stroke: var(--danger); }
.tick.st-4 svg, .tick.st-5 svg { stroke: var(--tick-read); }
.composer-wrap { background: var(--panel-2); }
.sig-hint { font-size: 11.5px; color: var(--muted); padding: 6px 18px 0; }
.composer .send:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- atribuição ---------- */
.tabs.sub button { font-size: 12px; padding: 3px 10px; }
.conv-item .tags { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; margin-top: 2px; }
.assignee { font-size: 11.5px; color: var(--muted); margin-right: 4px; white-space: nowrap; }
.assignee.mine { color: var(--green-dark); font-weight: 600; }
.assignee.none { color: #a06e00; }
@media (prefers-color-scheme: dark) { .assignee.mine { color: var(--green); } .assignee.none { color: var(--warn); } }
.assign { display: flex; gap: 6px; align-items: center; }
.assign select { width: auto; max-width: 190px; padding: 5px 8px; font-size: 13px; border-radius: 16px; }
.assign select.none { color: #a06e00; }
.chat header .icon-btn svg, .composer .icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; display: block; }
.sys-msg { align-self: center; background: rgba(2,126,181,.1); color: var(--info); font-size: 12px; padding: 4px 12px; border-radius: 8px; margin: 6px 0; text-align: center; max-width: 80%; }
.toast.clickable { cursor: pointer; background: var(--green-dark); }

/* ---------- mídias ---------- */
.msg .text { white-space: pre-wrap; }
.msg.media .text { margin-top: 4px; }
.m-img-link { display: block; }
.m-img { display: block; max-width: 100%; width: 320px; max-height: 360px; object-fit: cover; border-radius: 6px; background: rgba(0,0,0,.05); }
.m-video { display: block; max-width: 100%; width: 320px; max-height: 360px; border-radius: 6px; background: #000; }
.msg.sticker { background: none !important; box-shadow: none; }
.m-sticker { width: 140px; height: 140px; object-fit: contain; display: block; }
.m-audio { display: flex; align-items: center; gap: 6px; }
.m-audio audio { width: 280px; max-width: 100%; height: 40px; }
.m-doc { display: flex; align-items: center; gap: 10px; background: rgba(0,0,0,.05); padding: 8px 10px; border-radius: 6px; min-width: 240px; }
.m-doc .doc-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.m-doc .doc-info b { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.m-doc .doc-info small { color: var(--muted); }
.m-doc .btn { text-decoration: none; }
.doc-ico { width: 38px; height: 44px; border-radius: 4px; background: var(--info); color: #fff; font-size: 10.5px; font-weight: 700; display: grid; place-items: center; flex-shrink: 0; }
.media-ph { color: var(--muted); font-style: italic; display: flex; align-items: center; gap: 6px; }
.spinner.xs { width: 14px; height: 14px; border-width: 2px; margin: 0; display: inline-block; }

/* composer: anexos e gravação */
.composer { align-items: center; }
.composer .icon-btn:disabled, .composer .send:disabled { opacity: .4; cursor: not-allowed; }
.composer .send svg { width: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.composer .send svg.fill { width: 20px; fill: currentColor; stroke: none; }
.composer.rec { gap: 10px; padding: 14px 16px; }
.composer.rec .grow { flex: 1; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.upload-bar { padding: 6px 18px 0; font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.chat { position: relative; }
.drop-hint { position: absolute; inset: 0; background: rgba(0,168,132,.14); border: 3px dashed var(--green); display: grid; place-items: center; font-size: 20px; color: var(--green-dark); z-index: 5; pointer-events: none; }
.file-list { display: flex; flex-direction: column; gap: 8px; margin: 12px 0; max-height: 50vh; overflow: auto; }
.file-item { display: flex; gap: 10px; align-items: center; }
.file-item img, .file-item video { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; background: var(--panel-2); }
.file-item b { font-weight: 500; word-break: break-all; }

/* ---------- foto de perfil ---------- */
.avatar { position: relative; overflow: hidden; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 50%; background: var(--panel); }
.ct-name { display: flex; align-items: center; gap: 10px; }
