:root {
  --bg: #f6f7f9; --panel: #fff; --text: #111827; --muted: #6b7280; --line: #e5e7eb;
  --green: #16a34a; --green-soft: #dcfce7; --amber: #b45309; --amber-soft: #fef3c7;
  --red: #dc2626; --red-soft: #fee2e2; --blue: #2563eb; --blue-soft: #dbeafe; --gray-soft: #f3f4f6;
  --radius: 12px; --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0f14; --panel: #121821; --text: #e5e7eb; --muted: #9ca3af; --line: #233041;
    --green-soft: #052e16; --amber-soft: #3a2a07; --red-soft: #3b0d0d; --blue-soft: #0c1f44; --gray-soft: #1a2230;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-weight: 400; }
.err { color: var(--red); min-height: 1.2em; margin: 0; }
h2 { font-size: 18px; margin: 0; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; }
.brand.big { font-size: 22px; justify-content: center; }
.logo { width: 26px; height: 26px; border-radius: 7px; background: var(--green) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 22l3-7 4 4 7-9' stroke='white' stroke-width='3' fill='none' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/100%; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow); text-align: center; }

.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 24px; padding: 12px 24px; background: var(--panel); border-bottom: 1px solid var(--line); }
.top nav { display: flex; gap: 4px; flex: 1; }
.tab { background: none; border: 0; padding: 8px 12px; border-radius: 8px; color: var(--muted); font: inherit; cursor: pointer; }
.tab.active, .tab:hover { background: var(--gray-soft); color: var(--text); }
.who { display: flex; align-items: center; gap: 10px; }
main { max-width: 1200px; margin: 0 auto; padding: 24px; }
.bar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 12px; }

input, select, textarea { width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); color: var(--text); font: inherit; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
textarea { min-height: 80px; resize: vertical; }
label { display: grid; gap: 4px; font-size: 13px; font-weight: 500; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
label.check input { width: auto; }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--text); padding: 8px 14px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--gray-soft); }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn.primary:hover { filter: brightness(.95); }
.btn.danger { color: var(--red); }
.btn.ghost { border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .6; cursor: progress; }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--gray-soft); color: var(--muted); }
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.badge.connected { background: var(--green-soft); color: var(--green); }
.badge.qr, .badge.connecting { background: var(--amber-soft); color: var(--amber); }
.badge.banned, .badge.replaced { background: var(--red-soft); color: var(--red); }
.badge.role { background: var(--blue-soft); color: var(--blue); }
.badge.role::before { display: none; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: grid; gap: 12px; box-shadow: var(--shadow); }
.card-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.card-head h3 { margin: 0; font-size: 16px; word-break: break-word; }
.meta { display: grid; gap: 2px; font-size: 13px; color: var(--muted); }
.meta b { color: var(--text); font-weight: 500; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.empty { grid-column: 1 / -1; text-align: center; padding: 48px 16px; color: var(--muted); border: 1px dashed var(--line); border-radius: var(--radius); }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.table tr:last-child td { border-bottom: 0; }

.token { display: inline-flex; align-items: center; gap: 6px; }
.token code { background: var(--gray-soft); padding: 2px 6px; border-radius: 6px; }

dialog { border: 0; border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 32px)); background: var(--panel); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.modal-body { padding: 24px; display: grid; gap: 14px; max-height: 85vh; overflow: auto; }
.modal-body h3 { margin: 0; font-size: 17px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0; display: grid; gap: 8px; }
legend { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 6px; text-transform: uppercase; letter-spacing: .03em; }

.qr-box { display: grid; place-items: center; gap: 10px; padding: 8px; text-align: center; }
.qr-box img { width: 280px; height: 280px; border-radius: 12px; background: #fff; padding: 8px; }
.qr-wait { width: 280px; height: 280px; display: grid; place-items: center; border-radius: 12px; background: var(--gray-soft); color: var(--muted); }
.pair-code { font: 700 28px/1 ui-monospace, monospace; letter-spacing: .15em; padding: 12px 18px; background: var(--gray-soft); border-radius: 10px; }

.doc-tools { display: flex; gap: 12px; align-items: end; margin-bottom: 16px; flex-wrap: wrap; }
.doc-tools input[type=search] { flex: 1; min-width: 220px; }
.doc-inst { min-width: 240px; }
.doc-note { background: var(--amber-soft); color: var(--text); border-radius: 8px; padding: 8px 10px; font-size: 13px; }
.doc-auth { font-size: 12px; }
.doc-layout { display: grid; grid-template-columns: 200px minmax(0, 1fr); gap: 24px; align-items: start; }
.doc-nav { position: sticky; top: 76px; display: grid; gap: 2px; }
.doc-nav a { color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: 13px; }
.doc-nav a:hover { background: var(--gray-soft); color: var(--text); }
.docs { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; min-width: 0; }
/* Wide <pre> blocks must scroll inside, not stretch the grid. */
.docs .card { gap: 8px; grid-template-columns: minmax(0, 1fr); }
.doc-body { grid-template-columns: minmax(0, 1fr); }
.docs .card h3 { margin: 0; font-size: 16px; }
.docs .card p { margin: 0; overflow-wrap: anywhere; }
.docs pre { margin: 0; padding: 12px; background: var(--gray-soft); border-radius: 8px; overflow-x: auto; white-space: pre; }
.doc-group { margin: 20px 0 4px; font-size: 15px; scroll-margin-top: 76px; }
#doc-intro { scroll-margin-top: 76px; }
.doc-ep { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.doc-ep summary { display: flex; align-items: center; gap: 10px; padding: 10px 14px; cursor: pointer; list-style: none; min-width: 0; }
.doc-ep summary::-webkit-details-marker { display: none; }
.doc-ep[open] summary { border-bottom: 1px solid var(--line); }
.doc-path { font-weight: 600; white-space: nowrap; }
.doc-desc { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.doc-ep[open] .doc-desc { white-space: normal; }
.doc-body { padding: 14px; display: grid; gap: 10px; }
.method { flex: none; width: 58px; text-align: center; font: 700 11px/1 ui-monospace, monospace; padding: 5px 0; border-radius: 6px; }
.m-get { background: var(--blue-soft); color: var(--blue); }
.m-post { background: var(--green-soft); color: var(--green); }
.m-put, .m-patch { background: var(--amber-soft); color: var(--amber); }
.m-delete { background: var(--red-soft); color: var(--red); }
.doc-fields { border-collapse: collapse; font-size: 13px; }
.doc-fields td { padding: 4px 12px 4px 0; vertical-align: top; }
.doc-fields td:first-child { white-space: nowrap; }
.doc-json { min-height: 170px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.doc-result { max-height: 360px; overflow: auto; border-left: 3px solid var(--line); }
.doc-result.ok { border-left-color: var(--green); }
.doc-result.fail { border-left-color: var(--red); }

.ok { color: var(--green); }
.connect-card { max-width: 420px; }
.connect-card .qr-wait { margin: 0 auto; }

/* Sistema */
.bar-right { display: flex; align-items: center; gap: 10px; font-size: 12px; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { display: grid; gap: 2px; text-align: left; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; font: inherit; color: inherit; cursor: pointer; box-shadow: var(--shadow); transition: border-color .15s; min-width: 0; }
.kpi:hover:not(:disabled) { border-color: var(--muted); }
.kpi:disabled { cursor: default; opacity: 1; }
.kpi-label { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.kpi b { font-size: 22px; font-weight: 650; line-height: 1.25; }
.kpi-sub { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi.good .dot { background: var(--green); }
.kpi.warn .dot { background: var(--amber); }
.kpi.bad .dot { background: var(--red); }
.kpi.bad { border-color: var(--red); }
.kpi.off b { color: var(--muted); }

.seg { display: flex; gap: 2px; box-shadow: inset 0 -1px var(--line); margin-bottom: 20px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.seg button { background: none; border: 0; border-bottom: 2px solid transparent; padding: 10px 14px; font: inherit; color: var(--muted); cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button.active { color: var(--text); border-bottom-color: var(--green); font-weight: 600; }

.notice { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; border-radius: 10px; margin-bottom: 16px; }
.notice.bad { background: var(--red-soft); color: var(--red); }
.notice.warn { background: var(--amber-soft); color: var(--text); margin: 16px 0 0; }
.engine { margin: 16px 0 0; font-size: 12.5px; }
.engine-notice { margin-top: 16px; display: block; }
.engine-notice > div { display: grid; gap: 6px; }
.changes { margin: 6px 0 0; padding-left: 18px; display: grid; gap: 3px; font-size: 13px; }
.changes .crit { font-weight: 600; }
.stack { display: grid; gap: 20px; }
.panel .token { display: flex; align-items: start; gap: 8px; }
.panel .token code { flex: 1; min-width: 0; overflow-wrap: anywhere; padding: 8px 10px; }
.panel .notice.warn { margin: 0; }
.hgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 16px; }
.hcard { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; display: grid; gap: 14px; box-shadow: var(--shadow); align-content: start; }
.hcard.down { border-color: var(--red); }
.hcard-head { display: flex; justify-content: space-between; align-items: start; gap: 8px; }
.hcard-head > div { display: grid; min-width: 0; }
.hcard-head b { font-size: 15px; overflow-wrap: anywhere; }
.hcard-head .muted { font-size: 12.5px; }
.alert-line { background: var(--red-soft); color: var(--red); border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 500; }
.hstats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; }
.hstats div { display: grid; gap: 1px; }
.hstats .muted { font-size: 12px; }
.hstats b { font-weight: 550; }
.meter { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; font-size: 12.5px; font-weight: 400; }
.meter-bar { grid-column: 1 / -1; height: 6px; background: var(--gray-soft); border-radius: 99px; overflow: hidden; }
.meter-bar i { display: block; height: 100%; background: var(--green); border-radius: 99px; }
.meter-bar i.warm { background: var(--amber); }
.meter-bar i.hot { background: var(--red); }
.hcard-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.pill { display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; background: var(--gray-soft); color: var(--muted); }
.pill.green { background: var(--green-soft); color: var(--green); }
.pill.red { background: var(--red-soft); color: var(--red); }
.pill.amber { background: var(--amber-soft); color: var(--amber); }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; display: grid; gap: 18px; box-shadow: var(--shadow); }
.panel-sec { display: grid; gap: 12px; padding-top: 18px; border-top: 1px solid var(--line); transition: opacity .15s; }
.panel.is-off .panel-sec { opacity: .45; }
.panel h4, .side h4 { margin: 0; font-size: 13px; font-weight: 650; }
.panel > p { margin: 0; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.field { display: grid; gap: 5px; font-size: 13px; font-weight: 500; }
.field small { font-size: 12px; font-weight: 400; }
.field > .btn { justify-self: start; }
.side { display: grid; gap: 12px; padding: 18px; border-radius: var(--radius); background: var(--gray-soft); position: sticky; top: 76px; }
.side .btn { justify-self: start; }
.side .actions .btn { justify-self: auto; }
.side p { margin: 0; font-size: 13px; }
.steps { margin: 0; padding-left: 18px; display: grid; gap: 6px; font-size: 13px; }
.files { list-style: none; margin: 0; padding: 0; display: grid; font-size: 13px; }
.files li { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid var(--line); }
.files li:last-child { border-bottom: 0; }
.help summary { cursor: pointer; font-size: 13px; font-weight: 500; }
.help ol { margin: 8px 0; padding-left: 18px; font-size: 13px; display: grid; gap: 4px; }
.status-line { display: flex; gap: 10px; align-items: start; }
.status-line .dot { margin-top: 6px; }
.status-line > div { display: grid; font-size: 13px; }
.status-line.good .dot { background: var(--green); }
.status-line.bad .dot { background: var(--red); }

.switch { display: flex; align-items: center; gap: 12px; cursor: pointer; font-weight: 400; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { flex: none; width: 40px; height: 22px; border-radius: 99px; background: var(--line); position: relative; transition: background .15s; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.3); transition: transform .15s; }
.switch input:checked + .track { background: var(--green); }
.switch input:checked + .track::after { transform: translateX(18px); }
.switch input:focus-visible + .track { outline: 2px solid var(--blue); outline-offset: 2px; }
.switch-text { display: grid; }
.switch-text b { font-size: 14px; font-weight: 600; }
.switch-text .muted { font-size: 12.5px; }

.suffix { display: flex; align-items: stretch; }
.suffix input { border-top-right-radius: 0; border-bottom-right-radius: 0; min-width: 0; }
.suffix span { display: flex; align-items: center; padding: 0 10px; border: 1px solid var(--line); border-left: 0; border-radius: 0 8px 8px 0; background: var(--gray-soft); color: var(--muted); font-size: 12.5px; font-weight: 400; }
.reveal { display: flex; gap: 6px; }
.reveal input { min-width: 0; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
.chips:focus-within { outline: 2px solid var(--blue-soft); border-color: var(--blue); }
.chips input { flex: 1; min-width: 160px; width: auto; border: 0; padding: 4px 6px; }
.chips input:focus { outline: none; }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 4px 3px 10px; border-radius: 99px; background: var(--green-soft); color: var(--green); font-size: 13px; font-weight: 500; }
.chip button { border: 0; background: none; color: inherit; font-size: 16px; line-height: 1; cursor: pointer; padding: 0 4px; border-radius: 99px; }
.chip button:hover { background: rgba(0,0,0,.08); }
.warmup { display: flex; gap: 6px; align-items: end; height: 120px; }
.wday { flex: 1; min-width: 0; height: 100%; display: grid; grid-template-rows: 1fr auto auto; justify-items: center; gap: 2px; font-size: 11px; }
.wday i { align-self: end; width: 100%; max-width: 36px; background: var(--green); border-radius: 4px 4px 0 0; opacity: .8; }
.wday b { font-weight: 600; }
.wday span { color: var(--muted); white-space: nowrap; }
.savebar { position: sticky; bottom: 16px; margin-top: 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 12px 10px 16px; border-radius: 12px; background: #111827; color: #fff; box-shadow: 0 8px 24px rgba(0,0,0,.25); z-index: 4; }
.savebar .btn:not(.primary) { background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }

/* Conversas */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr); height: calc(100vh - 170px); min-height: 420px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.inbox-list { border-right: 1px solid var(--line); display: grid; grid-template-rows: auto 1fr; min-height: 0; }
.inbox-list input { margin: 10px; width: calc(100% - 20px); }
#inboxChats { overflow-y: auto; min-height: 0; }
#inboxChats .empty, .inbox-chat .empty { border: 0; }
.chat-item { display: grid; gap: 2px; width: 100%; text-align: left; padding: 10px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; color: inherit; font: inherit; cursor: pointer; position: relative; }
.chat-item:hover { background: var(--gray-soft); }
.chat-item.active { background: var(--green-soft); }
.chat-top { display: flex; justify-content: space-between; gap: 8px; }
.chat-top b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-top .muted { font-size: 12px; flex: none; }
.chat-last { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 28px; }
.unread { position: absolute; right: 14px; bottom: 10px; background: var(--green); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 7px; }
.inbox-chat { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.inbox-chat > .empty { grid-row: 1 / -1; align-self: center; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: baseline; }
.msgs { overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; min-height: 0; background: var(--bg); }
.msg { max-width: min(75%, 560px); align-self: flex-start; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px; display: grid; gap: 4px; word-break: break-word; }
.msg.me { align-self: flex-end; background: var(--green-soft); }
.msg .btn { justify-self: start; }
.msg-from { font-size: 12px; font-weight: 600; color: var(--blue); }
.msg-time { font-size: 11px; color: var(--muted); justify-self: end; }
.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.composer textarea { flex: 1; resize: none; }

/* Respostas automáticas */
.kw { display: grid; gap: 6px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.kw .btn { justify-self: start; }
.hours { border-collapse: collapse; font-size: 13px; }
.hours td { padding: 3px 8px 3px 0; }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; opacity: 0; transition: .2s; pointer-events: none; z-index: 50; max-width: calc(100vw - 32px); }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--red); }

@media (max-width: 640px) {
  .top { flex-wrap: wrap; gap: 8px; padding: 10px 16px; }
  .top nav { order: 3; width: 100%; }
  main { padding: 16px; }
  .row, .checks, .row2, .row3 { grid-template-columns: 1fr; }
  .split { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi b { font-size: 18px; }
  .hstats { grid-template-columns: 1fr 1fr; }
  .inbox { grid-template-columns: minmax(0, 1fr); height: auto; }
  .inbox-list { border-right: 0; border-bottom: 1px solid var(--line); max-height: 40vh; }
  .inbox-chat { height: 70vh; }
  .doc-layout { grid-template-columns: minmax(0, 1fr); }
  .doc-nav { display: none; }
  .doc-ep summary { flex-wrap: wrap; }
  .doc-path { white-space: normal; word-break: break-all; }
}
