:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e3e6ea;
  --text: #1f2933;
  --muted: #6b7682;
  --brand: #16a34a;
  --brand-dark: #12813b;
  --brand-soft: #e7f6ec;
  --danger: #dc2626;
  --warn: #b45309;
  --warn-soft: #fff7e0;
  --info: #2563eb;
  --info-soft: #e8efff;
  --bubble-in: #ffffff;
  --bubble-out: #dcf8c6;
  --radius: 10px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0 0 12px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.hidden { display: none !important; }

/* botões e campos */
.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 14px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { background: #f0f2f4; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--danger); border-color: #f3c2c2; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; background: #fff; width: 100%; }
textarea { resize: vertical; }
label.field { display: block; margin-bottom: 10px; }
label.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
label.check { display: flex; gap: 6px; align-items: center; cursor: pointer; }
label.check input { width: auto; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; }
.login form { width: 340px; background: var(--panel); padding: 28px; border-radius: 14px; box-shadow: 0 6px 30px rgba(0,0,0,.08); }
.logo { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; margin-bottom: 18px; }
.logo i { width: 30px; height: 30px; border-radius: 50%; background: var(--brand); display: inline-block; }

/* estrutura */
.shell { display: grid; grid-template-columns: 210px 1fr; height: 100vh; }
.sidebar { background: #10241a; color: #d5e6db; display: flex; flex-direction: column; padding: 16px 10px; }
.sidebar .logo { color: #fff; padding: 0 8px; }
.sidebar nav a { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 8px; color: inherit; text-decoration: none; margin-bottom: 2px; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); }
.sidebar nav a.active { background: rgba(255,255,255,.14); color: #fff; }
.sidebar nav a .count { margin-left: auto; background: var(--brand); color: #fff; border-radius: 10px; padding: 0 7px; font-size: 11px; }
.sidebar .me { margin-top: auto; padding: 10px; border-top: 1px solid rgba(255,255,255,.12); font-size: 13px; }
.sidebar .me .btn { background: transparent; color: #d5e6db; border-color: rgba(255,255,255,.2); }
main { overflow: auto; min-width: 0; }
.page { padding: 22px 26px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }

.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; margin: 8px 0; }
.switch input { display: none; }
.switch i { width: 34px; height: 19px; background: #5b6b62; border-radius: 10px; position: relative; transition: .2s; }
.switch i::after { content: ""; position: absolute; width: 15px; height: 15px; background: #fff; border-radius: 50%; top: 2px; left: 2px; transition: .2s; }
.switch input:checked + i { background: var(--brand); }
.switch input:checked + i::after { left: 17px; }

/* chips */
.chip { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; background: #eef0f2; color: var(--muted); }
.chip.pending { background: var(--warn-soft); color: var(--warn); }
.chip.open { background: var(--brand-soft); color: var(--brand-dark); }
.chip.bot { background: var(--info-soft); color: var(--info); }
.chip.closed { background: #eceef0; color: #59636e; }
.chip.connected { background: var(--brand-soft); color: var(--brand-dark); }
.chip.qrcode, .chip.connecting, .chip.reconnecting { background: var(--warn-soft); color: var(--warn); }
.chip.error { background: #fde8e8; color: var(--danger); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: #b8c0c8; }
.dot.on { background: var(--brand); }

/* atendimentos */
.inbox { display: grid; grid-template-columns: 330px 1fr 270px; height: 100vh; }
.ticket-col { border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { flex: 1; border: 0; background: none; padding: 12px 4px; cursor: pointer; border-bottom: 2px solid transparent; color: var(--muted); }
.tabs button.active { color: var(--brand-dark); border-bottom-color: var(--brand); font-weight: 600; }
.tabs .count { background: var(--warn); color: #fff; border-radius: 9px; padding: 0 6px; font-size: 11px; margin-left: 4px; }
.ticket-col .search { padding: 10px; border-bottom: 1px solid var(--line); }
.ticket-list { overflow: auto; flex: 1; }
.ticket-item { padding: 11px 14px; border-bottom: 1px solid #f0f1f3; cursor: pointer; }
.ticket-item:hover { background: #f8f9fa; }
.ticket-item.active { background: var(--brand-soft); }
.ticket-item .top { display: flex; justify-content: space-between; gap: 8px; }
.ticket-item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ticket-item .preview { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 3px 0; }
.empty { padding: 30px; text-align: center; color: var(--muted); }

.chat-col { display: flex; flex-direction: column; min-height: 0; background: #efeae2; }
.chat-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; gap: 10px; align-items: center; }
.messages { flex: 1; overflow: auto; padding: 16px 22px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 68%; padding: 7px 10px 5px; border-radius: 9px; box-shadow: 0 1px 1px rgba(0,0,0,.06); white-space: pre-wrap; word-wrap: break-word; }
.msg.in { background: var(--bubble-in); align-self: flex-start; }
.msg.out { background: var(--bubble-out); align-self: flex-end; }
.msg.internal { align-self: center; background: var(--warn-soft); color: #6b4b10; font-size: 12.5px; max-width: 80%; text-align: center; }
.msg.internal.note { background: #fff1c2; text-align: left; border-left: 3px solid #e3b23c; }
.msg .who { font-size: 11.5px; font-weight: 600; color: var(--brand-dark); margin-bottom: 2px; }
.msg.internal .who { color: inherit; }
.msg .meta { font-size: 10.5px; color: var(--muted); text-align: right; margin-top: 2px; }
.msg .meta .failed { color: var(--danger); font-weight: 600; }
.msg .opts { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 14px; }
.composer textarea { min-height: 42px; max-height: 160px; }
.composer.note textarea { background: #fffbea; }
.banner { background: var(--warn-soft); color: var(--warn); padding: 10px 16px; text-align: center; }
.info-col { border-left: 1px solid var(--line); background: var(--panel); overflow: auto; padding: 16px; }
.info-col dl { margin: 0 0 14px; display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; font-size: 13px; }
.info-col dt { color: var(--muted); }
.info-col dd { margin: 0; word-break: break-word; }

/* tabelas */
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); }
table.grid th, table.grid td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.grid th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfc; }
table.grid tr.click { cursor: pointer; }
table.grid tr.click:hover td { background: #f6f8f9; }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; margin-bottom: 14px; }

/* modal */
.overlay { position: fixed; inset: 0; background: rgba(15, 23, 20, .45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: var(--panel); border-radius: 14px; width: 480px; max-width: 100%; max-height: 92vh; display: flex; flex-direction: column; }
.modal.wide { width: 1100px; }
.modal header { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; }
.modal header h3 { margin: 0; }
.modal .content { padding: 18px 20px; overflow: auto; }
.modal footer { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.x { border: 0; background: none; font-size: 20px; cursor: pointer; color: var(--muted); }

/* auditoria */
.audit-detail { display: grid; grid-template-columns: 1fr 340px; gap: 16px; }
.audit-detail .messages { background: #efeae2; border-radius: 10px; max-height: 62vh; }
.timeline { list-style: none; margin: 0; padding: 0; max-height: 62vh; overflow: auto; }
.timeline li { border-left: 2px solid var(--line); padding: 0 0 12px 12px; position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--brand); }
.timeline li.transferred::before { background: var(--warn); }
.timeline li.closed::before { background: #59636e; }

/* conexões */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.qr { display: block; width: 230px; height: 230px; margin: 12px auto; image-rendering: pixelated; }
.code { background: #f4f5f7; border-radius: 6px; padding: 6px 8px; word-break: break-all; }

/* fluxos */
.flows { display: grid; grid-template-columns: 220px 1fr 340px; gap: 14px; height: calc(100vh - 90px); }
.flows .list a { display: block; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.flows .list a.active, .flows .list a:hover { background: var(--brand-soft); }
.flows textarea.mono { height: 340px; }
.validation .err { color: var(--danger); }
.validation .warn { color: var(--warn); }
.flowmap { font-size: 12.5px; }
.flowmap .node { border: 1px solid var(--line); border-radius: 8px; padding: 6px 9px; margin-bottom: 6px; }
.flowmap .node b { color: var(--brand-dark); }
.sim { display: flex; flex-direction: column; min-height: 0; }
.sim .messages { background: #efeae2; border-radius: 10px; flex: 1; min-height: 260px; }

/* toasts */
#toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1f2933; color: #fff; padding: 10px 14px; border-radius: 8px; max-width: 360px; box-shadow: 0 4px 16px rgba(0,0,0,.2); }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--brand-dark); }

@media (max-width: 1100px) {
  .inbox { grid-template-columns: 290px 1fr; }
  .info-col { display: none; }
  .flows { grid-template-columns: 1fr; height: auto; }
  .audit-detail { grid-template-columns: 1fr; }
}

/* time atual no menu */
.team-picker { display: block; margin: 0 6px 14px; }
.team-picker span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; opacity: .7; margin-bottom: 4px; }
.team-picker select { background: rgba(255,255,255,.1); color: #fff; border-color: rgba(255,255,255,.2); }
.team-picker select option { color: var(--text); }
.team-name { margin: -8px 8px 14px; font-size: 12.5px; opacity: .75; }
