:root {
  --bg: #f3f5f9; --card: #ffffff; --ink: #0f172a; --muted: #64748b; --line: #e2e8f0; --soft: #f1f5f9;
  --blue: #0b6bcb; --teal: #0ea5a4; --ok: #16a34a; --warn: #d97706; --bad: #dc2626;
  --bubble-in: #ffffff; --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 14px rgba(15, 23, 42, .06);
  --r: 12px; color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b1120; --card: #131c2e; --ink: #e8edf6; --muted: #93a3bd; --line: #243049; --soft: #19243a; --bubble-in: #1a2438; --shadow: 0 1px 2px rgba(0, 0, 0, .4); color-scheme: dark; }
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; }
body.app { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
a { color: var(--blue); }
h1, h2, h3 { margin: 0 0 8px; line-height: 1.25; }
h2 { font-size: 20px; } h3 { font-size: 16px; }
.muted { color: var(--muted); } .small { font-size: 13px; } .grow { flex: 1; } .center { text-align: center; padding: 20px; }
.row { display: flex; gap: 8px; align-items: center; } .row.end { justify-content: flex-end; } .row.wrap { flex-wrap: wrap; }
.stack { display: grid; gap: 12px; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; }

/* ---- controles ---- */
input, select, textarea, button { font: inherit; color: inherit; }
input:not([type=checkbox]):not([type=radio]):not([type=color]), select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); min-width: 0;
}
input[type=color] { width: 38px; height: 34px; padding: 2px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); cursor: pointer; }
label { display: grid; gap: 4px; font-size: 14px; font-weight: 600; } label.check, label.radio { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
label.check input, label.radio input { margin-top: 4px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--soft); } .btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; } .btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, var(--line)); }
.btn.ghost { border-color: transparent; background: transparent; } .btn.small { padding: 5px 10px; font-size: 13px; } .btn.block { width: 100%; }
.icon-btn { width: 38px; height: 38px; border: 0; border-radius: 10px; background: transparent; cursor: pointer; font-size: 18px; flex: none; }
.icon-btn:hover { background: var(--soft); } .icon-btn.mini { width: 26px; height: 26px; font-size: 15px; } .icon-btn.on { background: color-mix(in srgb, #f59e0b 25%, transparent); }
.icon-btn.danger { color: var(--bad); } .icon-btn:disabled { opacity: .3; cursor: default; }
.badge { min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--ok); color: #fff; font-size: 12px; font-weight: 700; display: inline-grid; place-items: center; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; flex: none; }
.error { color: var(--bad); font-size: 14px; margin: 0; }

/* ---- barra superior ---- */
.topbar { display: flex; align-items: center; gap: 14px; padding: 0 16px; height: 54px; background: #0b1020; color: #fff; flex: none; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; color: #fff; text-decoration: none; letter-spacing: -.2px; }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; flex: none; background: linear-gradient(135deg, var(--blue), var(--teal)) center/contain;
  position: relative; }
.brand-mark::after { content: ""; position: absolute; inset: 6px 5px 7px; background: #fff; border-radius: 4px; clip-path: polygon(0 0, 100% 0, 100% 78%, 40% 78%, 18% 100%, 18% 78%, 0 78%); }
.topbar nav { display: flex; gap: 2px; }
.topbar nav a { color: #c9d5ec; text-decoration: none; padding: 8px 12px; border-radius: 8px; font-weight: 600; font-size: 14px; }
.topbar nav a:hover { background: rgba(255, 255, 255, .08); color: #fff; } .topbar nav a.on { background: rgba(255, 255, 255, .14); color: #fff; }
.user-chip { display: flex; align-items: center; gap: 8px; background: rgba(255, 255, 255, .1); border: 0; color: #fff; padding: 7px 12px; border-radius: 999px; cursor: pointer; font-weight: 600; font-size: 14px; }
.wa-pill { font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 999px; background: #334155; color: #e2e8f0; }
.wa-pill.ok { background: #14532d; color: #bbf7d0; } .wa-pill.warn { background: #78350f; color: #fde68a; } .wa-pill.bad { background: #7f1d1d; color: #fecaca; }
.admin .wa-pill.ok { background: #dcfce7; color: #166534; } .admin .wa-pill.warn { background: #fef3c7; color: #92400e; } .admin .wa-pill.bad { background: #fee2e2; color: #991b1b; }
.offline-banner { display: none; background: var(--bad); color: #fff; text-align: center; padding: 6px; font-size: 13px; font-weight: 600; }
body.offline .offline-banner { display: block; }

/* ---- conversas ---- */
.inbox { flex: 1; display: grid; grid-template-columns: 390px 1fr; min-height: 0; }
.side { display: flex; flex-direction: column; min-height: 0; background: var(--card); border-right: 1px solid var(--line); }
.side-top { padding: 12px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.seg { display: grid; grid-template-columns: repeat(4, 1fr); background: var(--soft); border-radius: 10px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 6px 4px; border-radius: 8px; font-size: 13px; font-weight: 600; cursor: pointer; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.agent-filter { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px 3px 8px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: 12.5px; font-weight: 600; cursor: pointer; }
.chip.on { background: color-mix(in srgb, var(--c, #64748b) 18%, var(--card)); border-color: var(--c, var(--blue)); }
.conv-list { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.conv { all: unset; box-sizing: border-box; display: flex; gap: 11px; width: 100%; padding: 11px 14px; cursor: pointer; border-bottom: 1px solid var(--line); border-left: 4px solid transparent; }
.conv:hover { background: var(--soft); } .conv.active { background: color-mix(in srgb, var(--c) 12%, var(--card)); border-left-color: var(--c); }
.conv:focus-visible { outline: 2px solid var(--blue); outline-offset: -2px; }
.avatar { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; font-size: 15px; flex: none; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.conv-main { flex: 1; min-width: 0; display: grid; gap: 2px; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; } .conv-top time { font-size: 12px; color: var(--muted); flex: none; }
.nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .nm { font-weight: 800; }
.conv-last, .last { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .conv-last { color: var(--ink); font-weight: 600; } .you { color: var(--blue); }
.conv-tags { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.tag { font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 999px; white-space: nowrap; }
.tag.none { background: var(--soft); color: var(--muted); border: 1px dashed var(--line); }
.tag.col { background: color-mix(in srgb, var(--k) 16%, var(--card)); color: var(--ink); border: 1px solid color-mix(in srgb, var(--k) 55%, transparent); }
.tag.owner { max-width: 120px; overflow: hidden; text-overflow: ellipsis; }
.conv-tags .badge { margin-left: auto; } .empty-list { padding: 30px 16px; text-align: center; }

/* ---- painel de conversa ---- */
.chat { min-width: 0; min-height: 0; height: 100%; display: flex; flex-direction: column; background: var(--bg); position: relative; }
.chat-empty[hidden] { display: none; }
.chat-empty { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); } .chat-empty .big { font-size: 46px; }
.chat-main { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.chat-main[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 9px 14px; background: var(--card); border-bottom: 1px solid var(--line); border-top: 3px solid var(--c, #94a3b8); flex-wrap: wrap; }
.head-info { min-width: 0; } .chat-head .name { all: unset; cursor: pointer; font-weight: 800; font-size: 16px; display: block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-head .name:hover { text-decoration: underline; }
.sel { font-size: 11px; color: var(--muted); font-weight: 700; gap: 1px; } .sel select { padding: 5px 8px; font-size: 13px; width: auto; max-width: 150px; font-weight: 600; }
.chat-head .back { display: none; }
.chat-body { flex: 1; overflow: auto; padding: 14px 16px; scroll-behavior: auto; }
.older { text-align: center; margin-bottom: 10px; }
.day { text-align: center; margin: 14px 0 8px; } .day span { background: var(--soft); color: var(--muted); font-size: 12px; font-weight: 700; padding: 3px 12px; border-radius: 999px; }
.msg { display: flex; margin: 3px 0; } .msg.out { justify-content: flex-end; } .msg.note { justify-content: center; }
.bubble { max-width: min(560px, 82%); padding: 7px 11px 5px; border-radius: 14px; border: 1px solid var(--line); background: var(--bubble-in); box-shadow: 0 1px 1px rgba(15, 23, 42, .04); overflow-wrap: anywhere; }
.msg.in .bubble { border-top-left-radius: 4px; }
.msg.out .bubble { border-top-right-radius: 4px; background: color-mix(in srgb, var(--c) 17%, var(--card)); border-color: color-mix(in srgb, var(--c) 45%, transparent); }
.msg .who { display: block; font-size: 12px; font-weight: 800; color: var(--c); margin-bottom: 1px; }
.msg.out .who { filter: brightness(.8); } @media (prefers-color-scheme: dark) { .msg.out .who { filter: brightness(1.25); } }
.msg.note .bubble { background: #fef9c3; border-color: #facc15; color: #422006; max-width: 80%; }
@media (prefers-color-scheme: dark) { .msg.note .bubble { background: #3b3410; border-color: #a16207; color: #fde68a; } }
.msg.note .who { color: #a16207; }
.txt a { word-break: break-all; }
.meta { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--muted); margin-top: 1px; }
.msg time { font-size: 11px; color: var(--muted); } .msg.note time { display: block; text-align: right; }
.tick.read { color: #0ea5e9; font-weight: 800; } .tick.failed { color: var(--bad); }
.fail { color: var(--bad); font-size: 12px; font-weight: 600; }
.media-img { max-width: 280px; max-height: 320px; border-radius: 10px; display: block; cursor: zoom-in; margin-bottom: 4px; }
.media-sticker { width: 130px; height: 130px; object-fit: contain; display: block; }
.bubble audio { width: 260px; max-width: 100%; height: 40px; } .bubble video { max-width: 300px; border-radius: 10px; display: block; }
.doc { display: inline-block; padding: 8px 12px; background: var(--soft); border-radius: 8px; text-decoration: none; font-weight: 600; margin-bottom: 4px; }
.chat-compose { background: var(--card); border-top: 1px solid var(--line); padding: 8px 12px 10px; position: relative; }
.chat-compose.note-mode { background: #fffbeb; } @media (prefers-color-scheme: dark) { .chat-compose.note-mode { background: #2a2410; } }
.compose-row { display: flex; gap: 6px; align-items: flex-end; } .compose-row textarea { resize: none; max-height: 160px; line-height: 1.4; }
.sig { min-height: 18px; padding: 0 2px 4px; }
.quick { position: absolute; left: 12px; right: 12px; bottom: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); max-height: 260px; overflow: auto; z-index: 5; }
.quick .q { all: unset; display: grid; gap: 1px; padding: 8px 12px; cursor: pointer; width: calc(100% - 24px); } .quick .q:hover, .quick .q.on { background: var(--soft); }
.quick .q span { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .pad { padding: 10px 12px; }
.drop-hint { display: none; position: absolute; inset: 0; background: color-mix(in srgb, var(--blue) 14%, transparent); border: 3px dashed var(--blue); place-items: center; font-weight: 800; z-index: 4; pointer-events: none; }
.chat-main.dropping .drop-hint { display: grid; }

/* ---- Kanban ---- */
.kb-tools { display: flex; gap: 12px; align-items: center; padding: 10px 16px; flex-wrap: wrap; background: var(--card); border-bottom: 1px solid var(--line); flex: none; }
#q { width: 100%; } .kb-tools #q { width: 260px; }
.board { flex: 1; display: flex; gap: 14px; padding: 14px 16px 18px; overflow-x: auto; overflow-y: hidden; align-items: stretch; min-height: 0; }
.col { flex: 0 0 300px; display: flex; flex-direction: column; background: color-mix(in srgb, var(--k) 7%, var(--soft)); border: 1px solid var(--line); border-radius: 14px; min-height: 0; }
.col header { display: flex; align-items: center; gap: 8px; padding: 11px 12px 8px; position: relative; }
.col header .bar { width: 10px; height: 10px; border-radius: 3px; background: var(--k); } .col h2 { font-size: 14.5px; margin: 0; flex: 1; text-transform: uppercase; letter-spacing: .4px; }
.count { background: var(--card); border: 1px solid var(--line); font-size: 12px; font-weight: 700; border-radius: 999px; padding: 0 9px; }
.cards { flex: 1; overflow-y: auto; padding: 4px 10px 12px; display: grid; gap: 9px; align-content: start; min-height: 80px; border-radius: 0 0 14px 14px; }
.cards.over { background: color-mix(in srgb, var(--k) 16%, transparent); outline: 2px dashed var(--k); outline-offset: -4px; }
.col-empty { color: var(--muted); font-size: 13px; text-align: center; padding: 22px 6px; border: 2px dashed var(--line); border-radius: 10px; }
.card { background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--c); border-radius: 11px; padding: 9px 10px 8px; cursor: grab; box-shadow: var(--shadow); display: grid; gap: 4px; }
.card:hover { border-color: var(--c); } .card.dragging { opacity: .4; } .card:active { cursor: grabbing; }
.card.active { outline: 2px solid var(--c); } .card.nodono { border-left-color: #cbd5e1; } .card.unread { background: color-mix(in srgb, var(--c) 8%, var(--card)); }
.card-top { display: flex; gap: 8px; align-items: center; } .card-top .nm { flex: 1; font-weight: 700; } .card.unread .nm { font-weight: 800; }
.card-foot { display: flex; gap: 8px; align-items: center; } .card-foot time { margin-left: auto; font-size: 12px; color: var(--muted); }
.drawer { position: fixed; top: 54px; right: 0; bottom: 0; width: min(520px, 100vw); transform: translateX(105%); transition: transform .2s ease; background: var(--bg); box-shadow: -10px 0 30px rgba(15, 23, 42, .2); z-index: 20; border-left: 1px solid var(--line); }
.drawer.open { transform: none; } .drawer .chat-head .sel select { max-width: 120px; }
.popmenu { position: fixed; z-index: 50; background: var(--card); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); width: 210px; padding: 4px; }
.popmenu button { all: unset; display: flex; gap: 8px; align-items: center; width: calc(100% - 20px); padding: 8px 10px; cursor: pointer; border-radius: 8px; } .popmenu button:hover { background: var(--soft); }

/* ---- janelas ---- */
.modal-back { position: fixed; inset: 0; background: rgba(2, 6, 23, .55); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--card); border-radius: 16px; padding: 20px; width: min(560px, 100%); max-height: 90dvh; overflow: auto; box-shadow: var(--shadow); } .modal.small { width: min(420px, 100%); }
.modal-back.zoom img { max-width: 94vw; max-height: 92vh; border-radius: 8px; cursor: zoom-out; }
.cols-edit { list-style: none; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; } .cols-edit li { display: flex; gap: 8px; align-items: center; }
.audit { list-style: none; padding: 0; margin: 8px 0 14px; display: grid; gap: 6px; font-size: 14px; } .audit time { color: var(--muted); font-size: 12px; }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: grid; gap: 8px; z-index: 200; }
.toast { background: #0f172a; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); } .toast.error { background: var(--bad); } .toast.ok { background: var(--ok); }

/* ---- administração ---- */
.admin { flex: 1; overflow: auto; padding: 18px; max-width: 1100px; width: 100%; margin: 0 auto; }
.tabs { display: flex; gap: 4px; margin-bottom: 14px; flex-wrap: wrap; } .tabs button { border: 0; background: transparent; padding: 9px 16px; border-radius: 10px; font-weight: 700; cursor: pointer; color: var(--muted); }
.tabs button.on { background: var(--card); color: var(--ink); box-shadow: var(--shadow); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 18px; margin-bottom: 16px; display: grid; gap: 12px; }
.table-wrap { overflow-x: auto; } .table { width: 100%; border-collapse: collapse; font-size: 14px; } .table th { text-align: left; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; padding: 6px 8px; }
.table td { padding: 6px 8px; border-top: 1px solid var(--line); vertical-align: middle; } .table tr.off { opacity: .55; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; align-items: end; } .grid-form .wide { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: 10px; display: grid; gap: 8px; padding: 12px; margin: 0; } legend { font-weight: 700; padding: 0 6px; }
.qrbox { text-align: center; padding: 14px; border: 1px dashed var(--line); border-radius: 12px; } .qrbox img { background: #fff; padding: 8px; border-radius: 12px; }
.pairing { font-size: 34px; font-weight: 800; letter-spacing: 6px; margin: 8px 0; }
.qr-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; } .qr-list li { display: grid; grid-template-columns: 130px 1fr auto auto; gap: 10px; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.qr-list span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); }
code { background: var(--soft); padding: 1px 6px; border-radius: 6px; }

/* ---- login ---- */
.login-page { display: grid; place-items: center; min-height: 100dvh; background: linear-gradient(120deg, #0b1020 0%, #0b3a7a 60%, #0e8f8e 100%); padding: 16px; }
.login-card { background: var(--card); width: min(400px, 100%); border-radius: 18px; padding: 28px; display: grid; gap: 12px; box-shadow: 0 30px 60px rgba(0, 0, 0, .35); }
.login-card .brand { color: var(--ink); } .login-card form { display: grid; gap: 12px; }

/* ---- celular ---- */
@media (max-width: 600px) {
  .brand span:last-child { display: none; } .topbar nav a { white-space: nowrap; font-size: 13px; padding: 8px 7px; } .topbar { padding: 0 10px; }
  .user-chip { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 7px 10px; }
}
@media (max-width: 900px) {
  .inbox { grid-template-columns: 1fr; } .inbox .side { grid-column: 1; grid-row: 1; } .inbox #chat { grid-column: 1; grid-row: 1; display: none; }
  body.chat-open .inbox .side { display: none; } body.chat-open .inbox #chat { display: flex; }
  .chat-head .back { display: inline-flex; } .topbar nav a { padding: 8px; } .wa-pill { display: none; } .topbar { gap: 8px; }
  .col { flex-basis: 82vw; } .drawer { top: 54px; } .kb-tools #q { width: 100%; } .qr-list li { grid-template-columns: 1fr auto; } .qr-list li span, .qr-list li em { grid-column: 1 / -1; }
}

.agenda-list { list-style: none; margin: 10px 0; padding: 0; max-height: 50dvh; overflow: auto; display: grid; gap: 2px; }
.agenda-list button { all: unset; box-sizing: border-box; display: flex; justify-content: space-between; gap: 12px; width: 100%; padding: 9px 12px; border-radius: 10px; cursor: pointer; }
.agenda-list button:hover, .agenda-list button:focus-visible { background: var(--soft); } .agenda-list span { color: var(--muted); }

.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
