:root {
  --plum: #34213a;
  --plum-2: #4a3151;
  --lilac: #f4f1f6;
  --line: #e2dce6;
  --ink: #221b26;
  --muted: #74687a;
  --green: #17866b;
  --green-dark: #0f6b55;
  --amber: #b86e0b;
  --amber-bg: #fff4e0;
  --red: #b3372f;
  --red-bg: #fdecea;
  --chat-bg: #efe9e1;
  --bubble-out: #d9f5d0;
  --radius: 10px;
  font-family: 'Figtree', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; background: var(--lilac); font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--green-dark); }
:focus-visible { outline: 2px solid var(--green); outline-offset: 2px; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.side { background: var(--plum); color: #efe6f2; display: flex; flex-direction: column; padding: 20px 12px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 700; font-size: 19px; padding: 4px 12px 22px; letter-spacing: -0.01em; }
.brand small { display: block; font-weight: 500; font-size: 13px; color: #bda9c4; letter-spacing: 0; }
.nav a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 12px; border-radius: 8px; color: #e4d8e9; text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--plum-2); }
.nav a.active { background: #f4f1f6; color: var(--plum); }
.nav .sep { height: 1px; background: #52395a; margin: 12px 8px; }
.pill { background: var(--green); color: #fff; font-size: 12px; font-weight: 700; border-radius: 99px; padding: 0 7px; min-width: 20px; text-align: center; }
.side-foot { margin-top: auto; padding: 12px; font-size: 13px; color: #bda9c4; }
.side-foot b { color: #fff; font-weight: 600; display: block; }
.side-foot button { background: none; border: 0; color: #d7c6dd; padding: 0; cursor: pointer; text-decoration: underline; margin-top: 6px; }
.conn-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: #999; }
.conn-dot.open { background: #4cd08f; }
.conn-dot.close, .conn-dot.sem_instancia { background: #f0655b; }

.main { padding: 28px 32px; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
h1 { font-size: 26px; margin: 0; letter-spacing: -0.02em; }
h2 { font-size: 18px; margin: 0 0 12px; }
.sub { color: var(--muted); margin: 4px 0 0; }

/* Controls */
.btn { border: 1px solid var(--line); background: #fff; padding: 8px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: #c9bfd0; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { background: var(--green-dark); }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=time], input[type=datetime-local], select, textarea {
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; background: #fff; width: 100%;
}
textarea { resize: vertical; min-height: 90px; }
label.f { display: block; margin-bottom: 14px; }
label.f > span { display: block; font-weight: 600; font-size: 14px; margin-bottom: 5px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 4px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; min-width: 160px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label { border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; cursor: pointer; background: #fff; font-size: 14px; }
.checks input { margin-right: 6px; }

/* Panels & tables */
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { font-size: 28px; display: block; letter-spacing: -0.02em; }
.stat span { color: var(--muted); font-size: 14px; }
.meter { height: 6px; background: var(--lilac); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.meter i { display: block; height: 100%; background: var(--green); }
.meter.warn i { background: var(--amber); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 13px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid #f0ebf2; vertical-align: top; }
tr.click { cursor: pointer; }
tr.click:hover td { background: #faf8fb; }
.table-wrap { overflow-x: auto; }
.tag { display: inline-block; background: #efe8f2; color: var(--plum-2); border-radius: 6px; padding: 1px 8px; font-size: 12.5px; margin: 1px 3px 1px 0; }
.status { display: inline-block; border-radius: 6px; padding: 1px 8px; font-size: 13px; font-weight: 600; background: #eee; }
.s-novo { background: #eef0f4; color: #4b5563; }
.s-enviado { background: #e6f0ff; color: #2657a8; }
.s-respondeu { background: #e2f6ee; color: var(--green-dark); }
.s-agendou { background: #d1f0e2; color: #0c5c47; }
.s-retornar { background: var(--amber-bg); color: var(--amber); }
.s-sem_interesse { background: #f1ecee; color: #7a5c67; }
.s-nao_quer { background: var(--red-bg); color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 40px 10px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; color: var(--muted); font-size: 14px; }

/* Campaigns */
.camp { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; }
.camp-top { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.camp h3 { margin: 0; font-size: 17px; }
.camp .meta { color: var(--muted); font-size: 14px; }
.camp .nums { display: flex; gap: 18px; flex-wrap: wrap; margin-top: 12px; font-size: 14px; }
.camp .nums b { font-size: 16px; }
.bar { display: flex; height: 8px; border-radius: 99px; overflow: hidden; background: var(--lilac); margin-top: 10px; }
.bar i { display: block; height: 100%; }
.bar .b-sent { background: #8fb7ea; } .bar .b-reply { background: var(--green); } .bar .b-fail { background: #e08a84; } .bar .b-skip { background: #cfc5d4; }
.cs { font-size: 13px; font-weight: 700; border-radius: 6px; padding: 2px 8px; }
.cs-rodando { background: #e2f6ee; color: var(--green-dark); }
.cs-pausada, .cs-aguardando_confirmacao { background: var(--amber-bg); color: var(--amber); }
.cs-agendada { background: #e6f0ff; color: #2657a8; }
.cs-rascunho, .cs-concluida, .cs-cancelada { background: #eef0f4; color: #4b5563; }
.reason { background: var(--amber-bg); color: #7a4a06; border-radius: 8px; padding: 8px 12px; margin-top: 10px; font-size: 14px; }

/* Chat — o centro do sistema */
.chat { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 56px); background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.chat-list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.chat-search { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.chat-items { overflow-y: auto; flex: 1; }
.ci { display: grid; grid-template-columns: 40px 1fr auto; gap: 10px; padding: 11px 14px; border-bottom: 1px solid #f3eef5; cursor: pointer; align-items: center; }
.ci:hover { background: #faf8fb; }
.ci.active { background: #f1ecf4; }
.avatar { width: 40px; height: 40px; border-radius: 50%; background: #e3d8e8; color: var(--plum); display: grid; place-items: center; font-weight: 700; }
.ci .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci .lt { color: var(--muted); font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ci .tm { font-size: 12px; color: var(--muted); text-align: right; }
.ci .unread { background: var(--green); color: #fff; border-radius: 99px; font-size: 12px; font-weight: 700; padding: 0 7px; display: inline-block; margin-top: 3px; }
.chat-pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat-head { padding: 10px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.chat-head .who b { display: block; }
.chat-head .who span { color: var(--muted); font-size: 13.5px; }
.outcomes { display: flex; gap: 6px; flex-wrap: wrap; }
.msgs { flex: 1; overflow-y: auto; background: var(--chat-bg); padding: 18px 6%; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; background: #fff; color: var(--muted); font-size: 12.5px; padding: 3px 12px; border-radius: 8px; margin: 10px 0 6px; box-shadow: 0 1px 1px rgba(60,40,60,.08); }
.msg { max-width: 72%; padding: 7px 10px 5px; border-radius: 9px; background: #fff; box-shadow: 0 1px 1px rgba(60,40,60,.1); white-space: pre-wrap; word-wrap: break-word; }
.msg.out { align-self: flex-end; background: var(--bubble-out); }
.msg .mt { font-size: 11.5px; color: #6f7a6c; text-align: right; margin-top: 2px; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.msg .by { font-size: 12px; font-weight: 600; color: var(--green-dark); margin-bottom: 2px; }
.ticks { letter-spacing: -3px; }
.ticks.lido { color: #3494d9; }
.ticks.falhou { color: var(--red); letter-spacing: 0; }
.composer { display: flex; gap: 10px; padding: 10px 14px; border-top: 1px solid var(--line); background: #f7f4f8; }
.composer textarea { min-height: 42px; max-height: 140px; height: 42px; }
.chat-empty { flex: 1; display: grid; place-items: center; background: var(--chat-bg); color: var(--muted); text-align: center; padding: 20px; }

/* Template preview */
.phone-prev { background: var(--chat-bg); border-radius: var(--radius); padding: 16px; }
.phone-prev .msg { max-width: 100%; }
.var-list code { background: #efe8f2; border-radius: 5px; padding: 1px 6px; margin-right: 4px; cursor: pointer; font-family: inherit; font-size: 13px; }
.variation { position: relative; margin-bottom: 10px; }
.variation .rm { position: absolute; top: 6px; right: 6px; }

/* QR */
.qr-box { display: grid; grid-template-columns: 300px 1fr; gap: 28px; align-items: start; }
.qr-box img { width: 280px; height: 280px; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; padding: 10px; }
.qr-ph { width: 280px; height: 280px; border: 2px dashed var(--line); border-radius: var(--radius); display: grid; place-items: center; color: var(--muted); text-align: center; padding: 20px; }
ol.steps { padding-left: 20px; } ol.steps li { margin-bottom: 6px; }

/* Modal, alerts, toast */
.backdrop { position: fixed; inset: 0; background: rgba(34,20,38,.45); display: grid; place-items: center; padding: 20px; z-index: 50; }
.modal { background: #fff; border-radius: 12px; width: min(640px, 100%); max-height: 90vh; overflow-y: auto; padding: 22px 24px; }
.modal.wide { width: min(980px, 100%); }
.modal h2 { font-size: 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.banner { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; display: flex; justify-content: space-between; gap: 12px; align-items: center; flex-wrap: wrap; }
.banner.warn { background: var(--amber-bg); color: #6d4206; border: 1px solid #f1d59f; }
.banner.err { background: var(--red-bg); color: #7d241e; border: 1px solid #f3c3bf; }
.big-alert { text-align: center; }
.big-alert b.n { font-size: 56px; display: block; letter-spacing: -0.03em; color: var(--amber); line-height: 1.1; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; }
#toast div { background: var(--plum); color: #fff; padding: 10px 18px; border-radius: 8px; margin-top: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
#toast div.err { background: var(--red); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; background: var(--plum); padding: 20px; }
.login form { background: #fff; border-radius: 14px; padding: 30px; width: min(380px, 100%); }
.login h1 { font-size: 24px; }
.login p { color: var(--muted); margin: 4px 0 20px; }
.err-text { color: var(--red); font-size: 14px; margin: 0 0 10px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; }
  .brand { padding: 4px 10px; }
  .nav { display: flex; flex-wrap: wrap; gap: 2px; }
  .nav .sep, .side-foot { display: none; }
  .main { padding: 16px; }
  .chat { grid-template-columns: 1fr; height: auto; }
  .chat.has-open .chat-list { display: none; }
  .chat:not(.has-open) .chat-pane { display: none; }
  .msgs { min-height: 60vh; }
  .qr-box { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
