:root {
  --bg: #f5f3fa; --card: #fff; --line: #e8e3f2; --ink: #1d1530; --soft: #6d6485;
  --side: #1e1238; --side-soft: #b9aed8; --brand: #6d28d9; --brand-2: #8b5cf6;
  --accent: #f97316; --ok: #059669; --warn: #b45309; --bad: #dc2626;
  --mine: #ede5ff; --radius: 14px;
}
* { box-sizing: border-box; }
html, body, #root { height: 100%; margin: 0; }
body { font: 15px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--ink); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; border-radius: 10px; padding: 10px 18px; background: var(--brand); color: #fff; font-weight: 600; }
button:hover { filter: brightness(1.08); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: #efeaf8; color: var(--ink); }
button.danger { background: #fdecec; color: var(--bad); }
button.link { background: none; color: var(--brand); padding: 6px 8px; }
input, textarea { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: #fff; }
input:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 12px; }
.soft { color: var(--soft); }
.error { color: var(--bad); min-height: 1.4em; margin: 6px 0 0; }
.hidden { display: none !important; }

/* entrada */
.gate { height: 100%; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(circle at 20% 10%, #4c1d95, #1e1238 60%); }
.gate form { width: min(380px, 100%); background: var(--card); border-radius: 20px; padding: 28px; display: grid; gap: 12px; }
.logo { font-weight: 800; font-size: 20px; letter-spacing: -.3px; }
.logo b { color: var(--accent); }

/* estrutura */
.shell { display: grid; grid-template-columns: 216px 1fr; height: 100%; }
nav { background: var(--side); color: #fff; display: flex; flex-direction: column; padding: 18px 12px; gap: 4px; }
nav .logo { padding: 0 10px 18px; }
nav a { color: var(--side-soft); text-decoration: none; padding: 10px 12px; border-radius: 10px; display: flex; gap: 10px; align-items: center; }
nav a:hover { background: #ffffff12; color: #fff; }
nav a.on { background: var(--brand); color: #fff; }
nav .grow { flex: 1; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #9ca3af; display: inline-block; flex: none; }
.dot.connected { background: #22c55e; }
.dot.qr, .dot.connecting { background: var(--accent); }
nav .state { font-size: 13px; color: var(--side-soft); display: flex; gap: 8px; align-items: center; padding: 8px 12px; }
nav button { background: none; color: var(--side-soft); text-align: left; font-weight: 500; padding: 10px 12px; }
main { min-width: 0; min-height: 0; overflow: auto; }
.page { max-width: 1080px; margin: 0 auto; padding: 28px 24px; display: grid; gap: 18px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }

/* painel */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat { text-decoration: none; color: inherit; }
.stat strong { display: block; font-size: 30px; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat.hot strong { color: var(--accent); }
.chart { display: flex; align-items: flex-end; gap: 3px; height: 150px; }
.chart .day { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; min-width: 3px; gap: 1px; }
.chart i { display: block; border-radius: 3px 3px 0 0; background: var(--brand-2); }
.chart i.sent { background: var(--accent); border-radius: 0; }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--soft); margin-top: 10px; }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; background: var(--brand-2); }
.legend span.sent::before { background: var(--accent); }
.bar { height: 8px; background: var(--line); border-radius: 8px; overflow: hidden; margin-top: 10px; }
.bar i { display: block; height: 100%; background: var(--brand); }
.banner { border-left: 4px solid var(--accent); }

/* conversas */
.inbox { display: grid; grid-template-columns: 340px minmax(0, 1fr) 280px; height: 100%; }
.list, .side { background: var(--card); min-height: 0; display: flex; flex-direction: column; }
.list { border-right: 1px solid var(--line); }
.side { border-left: 1px solid var(--line); padding: 20px; gap: 12px; overflow: auto; }
.search { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; gap: 6px; }
.tabs button { background: #efeaf8; color: var(--soft); padding: 6px 12px; font-size: 13px; }
.tabs button.on { background: var(--brand); color: #fff; }
.items { overflow: auto; flex: 1; }
.chat { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 2px 10px; padding: 11px 14px; width: 100%;
  background: none; color: inherit; text-align: left; border-radius: 0; border-bottom: 1px solid #f3f0f9; font-weight: 400; }
.chat:hover { background: #faf8ff; filter: none; }
.chat.on { background: var(--mine); }
.avatar { grid-row: span 2; width: 40px; height: 40px; border-radius: 50%; background: #e4d9fb; color: var(--brand); display: grid; place-items: center; font-weight: 700; }
.chat .who { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat .when { font-size: 12px; color: var(--soft); }
.chat .last { grid-column: 2; font-size: 13px; color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat .wait { justify-self: end; align-self: center; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.thread { display: flex; flex-direction: column; min-height: 0; }
.thread header { padding: 12px 18px; background: var(--card); border-bottom: 1px solid var(--line); display: flex; gap: 12px; align-items: center; }
.thread header .back { display: none; }
.msgs { flex: 1; overflow: auto; padding: 16px clamp(12px, 4%, 48px); display: flex; flex-direction: column; gap: 6px; }
.date { align-self: center; font-size: 12px; background: #e7e1f5; color: var(--soft); border-radius: 20px; padding: 3px 12px; margin: 8px 0; }
.msg { max-width: min(78%, 560px); padding: 8px 12px; border-radius: 12px; background: #fff; border: 1px solid var(--line); align-self: flex-start; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.me { align-self: flex-end; background: var(--mine); border-color: #dccbff; }
.msg time { display: block; text-align: right; font-size: 11px; color: var(--soft); margin-top: 2px; }
.msg img { max-width: 100%; max-height: 320px; border-radius: 8px; display: block; }
.msg audio { width: 260px; max-width: 100%; display: block; }
.msg a { color: var(--brand); }
.readonly { text-align: center; padding: 12px; font-size: 13px; color: var(--soft); background: var(--card); border-top: 1px solid var(--line); }
.empty { margin: auto; text-align: center; color: var(--soft); padding: 30px; }
.side .avatar { width: 64px; height: 64px; font-size: 24px; grid-row: auto; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; margin: 0; }
.facts dt { color: var(--soft); }
.facts dd { margin: 0; text-align: right; }

/* contatos, conexão, ajustes */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); }
.table th { font-size: 12px; color: var(--soft); text-transform: uppercase; letter-spacing: .4px; }
.table tbody tr { cursor: pointer; }
.table tbody tr:hover { background: #faf8ff; }
.scroll { overflow-x: auto; }
.stack { display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.stack h2, .stack p { margin: 0; }
.stack .full { align-self: stretch; }
.qr { width: min(320px, 100%); border-radius: 12px; border: 1px solid var(--line); }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.pill { font-size: 12px; font-weight: 700; border-radius: 20px; padding: 3px 10px; background: #eceaf1; color: var(--soft); }
.pill.ok { background: #d8f5e8; color: var(--ok); }
.pill.warn { background: #fdf0d5; color: var(--warn); }
.key { display: grid; gap: 8px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.key:last-child { border: 0; }
.key form { display: flex; gap: 8px; }

@media (max-width: 1180px) {
  .inbox { grid-template-columns: 300px minmax(0, 1fr); }
  .side { display: none; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto minmax(0, 1fr); }
  nav { flex-direction: row; overflow-x: auto; padding: 8px; align-items: center; }
  nav .logo, nav .grow, nav .state { display: none; }
  nav a { padding: 8px 10px; white-space: nowrap; }
  .page { padding: 16px; }
  .inbox { grid-template-columns: 1fr; }
  .inbox.open .list { display: none; }
  .inbox:not(.open) .thread { display: none; }
  .thread header .back { display: inline-block; }
  .key form { flex-wrap: wrap; }
}
