/* Layout: sidebar de navegação | lista de conversas | chat | painel de detalhes */
:root {
  --bg: #eef2f3; --panel: #ffffff; --panel-2: #f6f8f9; --line: #d9e1e4;
  --fg: #2f2c2b; --muted: #526478; --accent: #0057a8; --accent-fg: #ffffff; --accent-soft: #dcecff;
  --amber: #e7a321; --amber-soft: #fbefd3; --ok: #1f8a4c; --ok-soft: #dcf1e4; --warn: #b5541b; --warn-soft: #f9e2d4;
  --bubble-in: #ffffff; --bubble-out: #dcecff; --note: #fff4cc; --chat-bg: #edf3fa;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-head: 'Space Grotesk', 'Inter', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'SFMono-Regular', Menlo, monospace;
}
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) {
  --bg: #0d1517; --panel: #142024; --panel-2: #192a2f; --line: #26393f;
  --fg: #e3ecee; --muted: #8fa4aa; --accent: #85bdff; --accent-fg: #10243c; --accent-soft: #203c5a;
  --amber: #f0b442; --amber-soft: #3a2f16; --ok: #4cc283; --ok-soft: #16352a; --warn: #f08a54; --warn-soft: #3d2416;
  --bubble-in: #1b2a2f; --bubble-out: #203c5a; --note: #3b3517; --chat-bg: #0f1b1e; color-scheme: dark; } }
:root[data-theme="dark"] {
  --bg: #0d1517; --panel: #142024; --panel-2: #192a2f; --line: #26393f;
  --fg: #e3ecee; --muted: #8fa4aa; --accent: #85bdff; --accent-fg: #10243c; --accent-soft: #203c5a;
  --amber: #f0b442; --amber-soft: #3a2f16; --ok: #4cc283; --ok-soft: #16352a; --warn: #f08a54; --warn-soft: #3d2416;
  --bubble-in: #1b2a2f; --bubble-out: #203c5a; --note: #3b3517; --chat-bg: #0f1b1e; color-scheme: dark; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.45 var(--font-body); }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { font-family: var(--font-head); margin: 0; text-wrap: balance; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.btn { border: 1px solid var(--line); background: var(--panel); padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); font-weight: 600; }
.btn.warn { color: var(--warn); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
input, select, textarea { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; }
label { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
label > span { font-weight: 600; letter-spacing: .02em; }

.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); white-space: nowrap; }
.pill.open { background: var(--ok-soft); color: var(--ok); }
.pill.queued { background: var(--amber-soft); color: var(--warn); }
.pill.bot { background: var(--accent-soft); color: var(--accent); }
.pill.closed { background: var(--panel-2); color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); display: inline-block; }
.dot.on { background: var(--ok); }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 24px max(16px, env(safe-area-inset-right, 0px)) 24px max(16px, env(safe-area-inset-left, 0px)); }
.login form { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 28px; display: grid; gap: 14px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-fg); display: grid; place-items: center; font: 700 15px var(--font-head); }
.demo-users { display: grid; gap: 6px; }
.demo-users button { text-align: left; }
.error { color: var(--warn); font-size: 13px; min-height: 1em; }

/* App */
.app { display: grid; grid-template-columns: 64px 320px minmax(0, 1fr) 280px; height: 100%; }
.app.no-info { grid-template-columns: 64px 320px minmax(0, 1fr); }
.app.full { grid-template-columns: 64px minmax(0, 1fr); }
.nav { background: var(--accent); color: var(--accent-fg); display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 12px 0; }
.nav .mark { width: 38px; height: 38px; border-radius: 10px; background: var(--accent-fg); color: var(--accent); display: grid; place-items: center; font: 700 14px var(--font-head); margin-bottom: 10px; }
.nav button { width: 48px; height: 48px; border-radius: 10px; border: 0; background: transparent; color: inherit; cursor: pointer; display: grid; place-items: center; font-size: 9.5px; gap: 1px; opacity: .8; overflow: hidden; }
.nav button.active, .nav button:hover { background: rgba(255,255,255,.16); opacity: 1; }
.nav svg { width: 20px; height: 20px; }
.nav .spacer { flex: 1; }

.list { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.list header { padding: 14px 14px 10px; display: grid; gap: 10px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 5px 9px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; font-size: 12.5px; }
.tabs button.active { background: var(--accent-soft); color: var(--accent); }
.tabs .count { font-family: var(--font-mono); margin-left: 3px; }
.items { overflow-y: auto; flex: 1; }
.item { display: grid; gap: 3px; padding: 11px 14px; border-bottom: 1px solid var(--line); cursor: pointer; border-left: 3px solid transparent; }
.item:hover { background: var(--panel-2); }
.item.active { background: var(--accent-soft); border-left-color: var(--accent); }
.item.queued { border-left-color: var(--amber); }
.item .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .last { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .meta { display: flex; gap: 6px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

.chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--chat-bg); }
.chat-head { background: var(--panel); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.chat-head .who { flex: 1; min-width: 180px; }
.chat-head .actions { display: flex; gap: 6px; flex-wrap: wrap; }
.msgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.bubble { max-width: min(560px, 80%); padding: 7px 11px 5px; border-radius: 10px; background: var(--bubble-in); box-shadow: 0 1px 0 rgba(0,0,0,.06); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.out { align-self: flex-end; background: var(--bubble-out); }
.bubble .by { font-size: 11.5px; font-weight: 700; color: var(--accent); }
.bubble .time { font-size: 11px; color: var(--muted); text-align: right; margin-top: 2px; }
.bubble .failed { color: var(--warn); font-weight: 600; }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 3px 12px; text-align: center; }
.note { align-self: center; max-width: min(560px, 90%); background: var(--note); border-radius: 8px; padding: 6px 10px; font-size: 13px; }
.composer { background: var(--panel); border-top: 1px solid var(--line); padding: 10px 14px; display: grid; gap: 6px; }
.composer .row { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { resize: none; height: 44px; max-height: 140px; }
.composer.note-mode textarea { background: var(--note); }
.composer .hint { font-size: 12px; color: var(--muted); display: flex; gap: 12px; flex-wrap: wrap; justify-content: space-between; }
.composer .hint label { display: inline-flex; flex-direction: row; align-items: center; gap: 5px; }
.composer .hint input { width: auto; }
.locked { background: var(--panel); border-top: 1px solid var(--line); padding: 14px; text-align: center; color: var(--muted); }

.info { background: var(--panel); border-left: 1px solid var(--line); padding: 16px; overflow-y: auto; display: grid; gap: 16px; align-content: start; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; margin: 0; font-size: 13px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; overflow-wrap: anywhere; }
.info h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.hist { display: grid; gap: 6px; }
.hist button { text-align: left; border: 1px solid var(--line); background: var(--panel-2); border-radius: 8px; padding: 7px 9px; cursor: pointer; font-size: 12.5px; }
.guard { font-size: 12px; color: var(--muted); border: 1px dashed var(--line); border-radius: 8px; padding: 8px 10px; }

/* Páginas de administração */
.page { overflow-y: auto; padding: 22px max(16px, env(safe-area-inset-right, 0px)) 40px max(22px, env(safe-area-inset-left, 0px)); display: grid; gap: 18px; align-content: start; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 16px; display: grid; gap: 12px; min-width: 0; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.tablewrap { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px; }
.stat b { display: block; font: 600 24px var(--font-head); font-variant-numeric: tabular-nums; }

/* Simulador */
.sim { display: grid; grid-template-columns: minmax(0, 360px) minmax(0, 1fr); gap: 20px; align-items: start; }
.phone { background: #0b141a; border-radius: 26px; padding: 10px; max-width: 360px; width: 100%; }
.phone .screen { background: #efe7de; border-radius: 18px; overflow: hidden; display: flex; flex-direction: column; height: 560px; color: #111b21; }
.phone .top { background: #075e54; color: #fff; padding: 10px 14px; font-weight: 600; }
.phone .top small { display: block; font-weight: 400; opacity: .8; }
.phone .thread { flex: 1; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 5px; }
.phone .b { max-width: 85%; padding: 6px 9px; border-radius: 8px; background: #fff; white-space: pre-wrap; font-size: 13.5px; overflow-wrap: anywhere; }
.phone .b.me { align-self: flex-end; background: #d9fdd3; }
.phone form { display: flex; gap: 6px; padding: 8px; background: #f0f2f5; }
.phone input { background: #fff; color: #111b21; border-color: #ddd; }
.phone .send { background: #00a884; color: #fff; border: 0; border-radius: 50%; width: 40px; flex: none; cursor: pointer; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(5, 15, 18, .55); display: grid; place-items: center; padding: 16px; z-index: 20; }
.modal { background: var(--panel); border-radius: 14px; padding: 20px; width: min(520px, 100%); max-height: 90vh; overflow-y: auto; display: grid; gap: 14px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 8px; }
.member { display: grid; grid-template-columns: auto 1fr minmax(0, 160px); gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.member input[type=checkbox] { width: auto; }
.toast { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 9px 16px; border-radius: 9px; z-index: 30; max-width: calc(100% - 32px); }

.back { display: none; }
@media (max-width: 1100px) { .app { grid-template-columns: 64px 300px minmax(0, 1fr); } .info { display: none; } }
@media (max-width: 760px) {
  .app, .app.no-info, .app.full { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .nav { flex-direction: row; order: 2; padding: 4px max(8px, env(safe-area-inset-left, 0px)) calc(4px + env(safe-area-inset-bottom, 0px)); justify-content: space-around; }
  .nav .mark, .nav .spacer { display: none; }
  .app.chatting .list { display: none; }
  .app:not(.chatting) .chat { display: none; }
  .back { display: inline-flex; }
  .sim { grid-template-columns: 1fr; }
}
