:root {
  --bg: #0b1220;
  --bg-2: #111a2e;
  --bg-3: #1a2540;
  --line: #243151;
  --fg: #e5edff;
  --muted: #8aa0c8;
  --accent: #0ea5a4;   /* teal */
  --accent-2: #22c55e; /* verde conexão */
  --warn: #f59e0b;
  --danger: #ef4444;
  --info: #3b82f6;
  --ok: #22c55e;
  --off: #6b7280;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--fg); }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { background: var(--bg-3); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--fg); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.loading { padding: 40px; text-align: center; color: var(--muted); }

/* LOGIN */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 16px; padding: 32px; max-width: 380px; width: 100%; }
.login-card h1 { margin: 0 0 4px; color: var(--accent); font-size: 24px; }
.login-card h1 small { color: var(--muted); font-size: 14px; font-weight: 400; }
.login-card form { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.login-card input { padding: 12px; }
.login-card button { background: var(--accent); color: #001110; border: 0; padding: 12px; border-radius: 8px; font-weight: 600; cursor: pointer; }
.login-card .error { color: var(--danger); font-size: 13px; margin: 0; }

/* TOPBAR */
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 20px; background: var(--bg-2); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar h1 { margin: 0; color: var(--accent); font-size: 18px; }
.topbar h1 small { color: var(--muted); font-weight: 400; }
.topbar .actions { display: flex; gap: 8px; }
.topbar select { min-width: 280px; }
.topbar button { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--bg-3); cursor: pointer; }
.topbar button.primary { background: var(--accent); color: #001110; border-color: transparent; font-weight: 600; }

/* MAIN */
main { padding: 20px; max-width: 1100px; margin: 0 auto; }
.empty { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty.small { padding: 20px; }

.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin-bottom: 16px; }
.card h2 { margin: 0 0 4px; }
.card h3 { margin: 0; font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 12px; flex-wrap: wrap; }
.row.right { justify-content: flex-end; }

button { background: var(--bg-3); color: var(--fg); border: 1px solid var(--line); padding: 8px 14px; border-radius: 8px; cursor: pointer; }
button.primary { background: var(--accent); color: #001110; border-color: transparent; font-weight: 600; }
button.ghost { background: transparent; }
button.danger { background: var(--danger); color: white; border-color: transparent; }
button:hover { filter: brightness(1.1); }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.ok { background: rgba(34, 197, 94, 0.15); color: #4ade80; border: 1px solid #4ade8033; }
.badge.warn { background: rgba(245, 158, 11, 0.15); color: #fbbf24; border: 1px solid #fbbf2433; }
.badge.info { background: rgba(59, 130, 246, 0.15); color: #60a5fa; border: 1px solid #60a5fa33; }
.badge.off { background: rgba(107, 114, 128, 0.15); color: #9ca3af; border: 1px solid #9ca3af33; }

/* CONV LIST */
.conv-list { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.conv-item { padding: 10px 12px; border-radius: 8px; background: var(--bg-3); cursor: pointer; border: 1px solid transparent; }
.conv-item:hover { border-color: var(--line); }
.conv-item.active { border-color: var(--accent); background: rgba(14, 165, 164, 0.1); }
.conv-row1 { display: flex; justify-content: space-between; align-items: center; }
.conv-row2 { display: flex; gap: 8px; align-items: center; margin-top: 4px; }
.conv-time { font-size: 11px; color: var(--muted); }

/* QR */
.qr-card img { width: 240px; height: 240px; display: block; margin: 12px auto 0; background: white; padding: 8px; border-radius: 8px; }

/* CHAT PANEL */
.chat-panel { position: fixed; top: 0; right: -440px; width: 440px; max-width: 100vw; height: 100vh; background: var(--bg-2); border-left: 1px solid var(--line); display: flex; flex-direction: column; transition: right 0.25s ease; z-index: 20; }
.chat-panel.open { right: 0; }
.chat-header { display: flex; gap: 8px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.chat-header strong { flex: 1; }
.chat-body { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.chat-input { padding: 12px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.chat-input textarea { min-height: 60px; resize: vertical; }
.msg { display: flex; flex-direction: column; max-width: 80%; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.msg.ai { align-self: flex-end; align-items: flex-end; }
.msg-bubble { background: var(--bg-3); padding: 8px 12px; border-radius: 12px; word-wrap: break-word; white-space: pre-wrap; }
.msg.in .msg-bubble { background: var(--bg-3); border-top-left-radius: 2px; }
.msg.out .msg-bubble, .msg.ai .msg-bubble { background: var(--accent); color: #001110; border-top-right-radius: 2px; }
.msg.ai .msg-bubble { background: var(--info); color: white; }
.msg-time { font-size: 10px; color: var(--muted); margin-top: 2px; padding: 0 4px; }

/* MODAL */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: grid; place-items: center; padding: 20px; z-index: 30; }
.modal { background: var(--bg-2); border: 1px solid var(--line); border-radius: 12px; padding: 20px; max-width: 600px; width: 100%; max-height: 90vh; overflow-y: auto; }
.modal h2 { margin: 0 0 12px; }
.modal form { display: flex; flex-direction: column; gap: 10px; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.modal input, .modal select, .modal textarea { color: var(--fg); }

@media (max-width: 600px) {
  .topbar { flex-direction: column; gap: 10px; align-items: stretch; }
  .topbar .actions { flex-direction: column; }
  .topbar select { min-width: 0; }
  main { padding: 12px; }
}
