:root {
  --brand: #16a34a; --brand-h: #15803d; --brand-soft: #dcfce7;
  --bg: #f6f7f9; --card: #fff; --line: #e5e7eb; --side: #0f172a; --side-t: #cbd5e1;
  --radius: 12px;
}
[data-bs-theme="dark"] { --bg: #0b1020; --card: #111832; --line: #1f2a48; --brand-soft: #0f2a1c; --bs-body-bg: #0b1020; --bs-body-color: #e2e8f0; --bs-tertiary-bg: #151d3a; }
body { font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); font-size: .925rem; }
.min-w-0 { min-width: 0; }
.btn-brand { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 500; }
.btn-brand:hover, .btn-brand:focus { background: var(--brand-h); border-color: var(--brand-h); color: #fff; }
.btn-ghost { background: transparent; border: 1px solid transparent; color: inherit; }
.btn-ghost:hover { background: rgba(127,127,127,.15); }
.form-control, .form-select { border-radius: 8px; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 .2rem rgba(22,163,74,.18); }
.modal-content { border-radius: var(--radius); border: 1px solid var(--line); }
.modal-header, .modal-footer { border-color: var(--line); }

/* auth */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem;
  background: radial-gradient(1000px 500px at 50% -10%, var(--brand-soft), transparent), var(--bg); }
.auth.d-none { display: none !important; }
.auth-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 2rem; box-shadow: 0 10px 40px rgba(15,23,42,.08); }

/* brand */
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff; display: grid; place-items: center; }

/* shell */
.shell { display: flex; min-height: 100vh; }
.shell.d-none { display: none !important; }
.side { width: 248px; flex: none; background: var(--side); color: var(--side-t); padding: 1.1rem; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side .brand { color: #fff; padding: .25rem .4rem 1.25rem; }
.nav-side { display: flex; flex-direction: column; gap: .2rem; }
.nav-item { text-decoration: none; display: flex; align-items: center; gap: .7rem; width: 100%; padding: .6rem .75rem; border: 0; background: transparent; color: var(--side-t); border-radius: 8px; text-align: left; font-weight: 500; }
.nav-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(22,163,74,.2); color: #fff; }
.nav-item.d-none { display: none !important; }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255,255,255,.1); padding-top: 1rem; }
.side-foot .btn-ghost { color: var(--side-t); }
.user-chip { display: flex; align-items: center; gap: .6rem; color: #fff; }
.user-chip .text-secondary { color: #94a3b8 !important; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 600; flex: none; }
.main { flex: 1; min-width: 0; }
.topbar { display: flex; align-items: center; gap: .75rem; padding: 1rem 1.5rem; border-bottom: 1px solid var(--line); background: var(--card); position: sticky; top: 0; z-index: 5; }
.content { padding: 1.5rem; max-width: 1180px; }
.side-backdrop { display: none; }
@media (max-width: 991.98px) {
  .side { position: fixed; z-index: 30; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; }
  body.menu .side { transform: none; }
  body.menu .side-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 20; }
  .content { padding: 1rem; }
  .topbar { padding: .75rem 1rem; }
}

/* cards & stats */
.panel-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { display: flex; gap: .85rem; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat-ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; background: #e0e7ff; color: #4338ca; font-size: 1.2rem; }
.stat-ico.ok { background: var(--brand-soft); color: var(--brand); }
.stat-ico.off { background: #f1f5f9; color: #64748b; }
.stat-n { font-size: 1.5rem; font-weight: 700; line-height: 1.1; }
.stat-l { color: #64748b; font-size: .8rem; }

/* instâncias */
.inst-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 1rem; }
.inst { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; display: flex; flex-direction: column; gap: .85rem; transition: box-shadow .15s, border-color .15s; }
.inst:hover { box-shadow: 0 6px 24px rgba(15,23,42,.07); }
.inst-top { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; }
.inst-name { font-weight: 600; font-size: 1rem; }
.inst-id { color: #94a3b8; font-size: .75rem; font-family: ui-monospace, monospace; }
.pill { display: inline-flex; align-items: center; gap: .4rem; padding: .22rem .65rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill-open { background: var(--brand-soft); color: #15803d; }
.pill-connecting, .pill-pairing, .pill-qr { background: #fef3c7; color: #b45309; }
.pill-disconnected { background: #f1f5f9; color: #475569; }
[data-bs-theme="dark"] .pill-disconnected, [data-bs-theme="dark"] .stat-ico.off { background: #1e293b; color: #94a3b8; }
.inst-meta { display: flex; flex-wrap: wrap; gap: .4rem 1rem; color: #64748b; font-size: .8rem; }
.inst-meta i { margin-right: .25rem; }
.keybox { display: flex; gap: .25rem; align-items: center; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: .25rem .25rem .25rem .6rem; font-family: ui-monospace, monospace; font-size: .8rem; }
.keybox .k { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inst-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-top: auto; }
.inst-actions .spacer { flex: 1; }
.btn-icon { width: 34px; padding: .3rem 0; }
.empty { grid-column: 1 / -1; text-align: center; padding: 3.5rem 1rem; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); color: #64748b; }
.empty i { font-size: 2.5rem; color: var(--brand); }

/* tabelas */
.table-clean thead th { font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: #64748b; font-weight: 600; border-bottom: 1px solid var(--line); padding: .8rem 1rem; background: transparent; }
.table-clean td { padding: .8rem 1rem; border-color: var(--line); background: transparent; }
.skeleton { height: 150px; border-radius: var(--radius); background: linear-gradient(90deg, var(--card), var(--line), var(--card)); background-size: 200% 100%; animation: sk 1.2s infinite; }
@keyframes sk { to { background-position: -200% 0; } }

/* ciclo 1: lista, detalhe, conexão */
.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.stat-ico.wait { background: #fef3c7; color: #b45309; }
.pill-wait { background: #fef3c7; color: #b45309; }
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip { border: 1px solid var(--line); background: var(--card); color: inherit; border-radius: 999px; padding: .3rem .85rem; font-size: .82rem; font-weight: 500; }
.chip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-h); }
.search { max-width: 300px; }
tr.clickable { cursor: pointer; }
.row-ico { width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; flex: none; font-size: 1.2rem; background: #f1f5f9; color: #64748b; }
.row-ico.open { background: var(--brand-soft); color: var(--brand); }
.row-ico.wait { background: #fef3c7; color: #b45309; }
.row-ico.lg { width: 52px; height: 52px; font-size: 1.5rem; }
.crumb { font-size: .82rem; color: #64748b; margin-bottom: .75rem; }
.crumb a { color: inherit; text-decoration: none; }
.crumb a:hover { text-decoration: underline; }
.d-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.d-stack { display: flex; flex-direction: column; gap: 1rem; }
@media (max-width: 860px) { .d-grid-2 { grid-template-columns: 1fr; } }
.conn-ok { display: flex; align-items: center; gap: .9rem; background: var(--brand-soft); color: var(--brand-h); border-radius: 10px; padding: 1rem; }
.conn-check { width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 1.1rem; }
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; text-align: center; margin-top: 1.25rem; }
.m-n { font-size: 1.4rem; font-weight: 700; }
.m-l { font-size: .8rem; color: #64748b; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; color: inherit; padding: .25rem .8rem; border-radius: 6px; font-size: .82rem; font-weight: 500; }
.seg button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.qr-box { position: relative; min-height: 240px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .5rem; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: #334155; margin-bottom: 1rem; padding: .75rem; }
.qr-time { position: absolute; right: 10px; bottom: 8px; background: #fef3c7; color: #b45309; border-radius: 999px; font-size: .72rem; font-weight: 600; padding: .1rem .55rem; }
.pair-code { font-family: ui-monospace, monospace; font-size: 2rem; font-weight: 700; letter-spacing: .1em; }
.steps { padding-left: 0; list-style: none; counter-reset: s; color: #64748b; font-size: .85rem; }
.steps li { counter-increment: s; display: flex; align-items: center; gap: .65rem; margin-bottom: .55rem; }
.steps li::before { content: counter(s); width: 22px; height: 22px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-h); display: grid; place-items: center; font-size: .72rem; font-weight: 700; flex: none; }
.code-block { background: #0f172a; color: #e2e8f0; border-radius: 10px; padding: 1rem; font-size: .8rem; margin: 0; overflow-x: auto; }
.choice { display: flex; align-items: center; gap: .65rem; border: 1px solid var(--line); border-radius: 10px; padding: .7rem .8rem; cursor: pointer; height: 100%; }
.choice i { font-size: 1.3rem; color: var(--brand); }
.choice span { display: flex; flex-direction: column; line-height: 1.2; }
.choice small { color: #64748b; }
.btn-check:checked + .choice { border-color: var(--brand); background: var(--brand-soft); }
.dropdown-item i { margin-right: .5rem; }

@media (max-width: 575.98px) {
  .stats { grid-template-columns: 1fr 1fr; gap: .6rem; }
  .stat { padding: .7rem; gap: .6rem; }
  .stat-ico { width: 34px; height: 34px; font-size: 1rem; }
  .stat-n { font-size: 1.2rem; }
  .search { max-width: 100%; width: 100%; }
}

/* mensagens (depuração) */
.mm-body { min-height: 360px; max-height: 60vh; overflow-y: auto; background: var(--bg); }
.mm-chat { display: flex; align-items: center; gap: .75rem; width: 100%; border: 0; border-bottom: 1px solid var(--line); background: var(--card); color: inherit; text-align: left; padding: .7rem 1rem; }
.mm-chat:hover { background: var(--brand-soft); }
.mm-chat .t { flex: 1; min-width: 0; }
.mm-chat .p { color: #64748b; font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mm-thread { display: flex; flex-direction: column; gap: .4rem; padding: 1rem; }
.bubble { max-width: 80%; padding: .4rem .7rem; border-radius: 12px; background: var(--card); border: 1px solid var(--line); word-break: break-word; white-space: pre-wrap; }
.bubble.me { align-self: flex-end; background: var(--brand-soft); border-color: transparent; }
.bubble .meta { display: block; font-size: .68rem; color: #64748b; text-align: right; margin-top: .1rem; }
.mm-empty { padding: 3rem 1rem; text-align: center; color: #64748b; }
.mm-img { max-width: 240px; max-height: 240px; border-radius: 8px; display: block; }
.bubble audio { max-width: 100%; display: block; }
