:root {
  --primary: #1f93ff;
  --primary-dark: #1976d2;
  --primary-soft: #e8f3ff;
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e6e9f0;
  --text: #1f2d3d;
  --muted: #6b7a90;
  --green: #44ce4b;
  --amber: #ffb020;
  --red: #ff382d;
  --note: #fff7e0;
  --note-border: #f5d87a;
  --out: #1f93ff;
  --in: #f1f4f9;
  --radius: 8px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--primary); }

/* ---------- botões e campos ---------- */
.btn { border: 1px solid var(--border); background: #fff; padding: 7px 14px; border-radius: 6px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.btn:hover { background: #f7f9fc; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.success { background: var(--green); border-color: var(--green); color: #fff; }
.btn.danger { color: var(--red); }
.btn.small { padding: 4px 10px; font-size: 13px; }
.btn.icon { padding: 6px 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 13px; font-weight: 600; color: #3c4858; }
.field small { color: var(--muted); }
.input, select.input, textarea.input { border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; background: #fff; outline: none; width: 100%; }
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea.input { resize: vertical; min-height: 70px; }
.check { display: flex; align-items: center; gap: 8px; margin: 4px 0; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 36px; width: 100%; max-width: 390px; box-shadow: 0 10px 40px rgba(31,45,61,.06); }
.login-card h1 { font-size: 22px; margin: 14px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.logo { width: 42px; height: 42px; border-radius: 10px; background: var(--primary); display: grid; place-items: center; color: #fff; }

/* ---------- layout ---------- */
.app { display: flex; height: 100vh; overflow: hidden; }
.sidebar { width: 220px; background: #fff; border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; }
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 16px; font-weight: 700; font-size: 16px; }
.sidebar .brand .logo { width: 32px; height: 32px; border-radius: 8px; }
.nav { padding: 6px 10px; flex: 1; overflow-y: auto; }
.nav .section { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 14px 10px 6px; font-weight: 600; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 6px; color: #3c4858; text-decoration: none; font-weight: 500; }
.nav a:hover { background: #f4f6fb; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.nav a .count { margin-left: auto; background: var(--primary); color: #fff; font-size: 11px; border-radius: 10px; padding: 1px 7px; }
.nav svg, .ico { width: 18px; height: 18px; flex-shrink: 0; }
.me { border-top: 1px solid var(--border); padding: 12px; display: flex; align-items: center; gap: 10px; }
.me .info { flex: 1; min-width: 0; }
.me .info b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me .info span { color: var(--muted); font-size: 12px; }

.avatar { width: 36px; height: 36px; border-radius: 50%; background: #c8d6e5; color: #fff; display: grid; place-items: center; font-weight: 600; flex-shrink: 0; overflow: hidden; position: relative; font-size: 13px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.avatar.lg { width: 64px; height: 64px; font-size: 22px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: #c0c8d4; }
.dot.on { background: var(--green); }

.main { flex: 1; display: flex; min-width: 0; }

/* ---------- lista de conversas ---------- */
.conv-list { width: 340px; border-right: 1px solid var(--border); background: #fff; display: flex; flex-direction: column; flex-shrink: 0; }
.conv-list header { padding: 14px 16px 0; }
.conv-list header .top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.conv-list header h2 { font-size: 18px; margin: 0; }
.filters { display: flex; gap: 6px; margin-bottom: 10px; }
.filters select { flex: 1; padding: 5px 8px; font-size: 13px; }
.search { position: relative; margin-bottom: 8px; }
.search input { padding-left: 32px; }
.search svg { position: absolute; left: 10px; top: 9px; width: 16px; color: var(--muted); }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin: 0 -16px; padding: 0 12px; }
.tabs button { background: none; border: none; padding: 10px 8px; color: var(--muted); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; font-size: 13px; }
.tabs button.active { color: var(--primary); border-color: var(--primary); }
.tabs .n { background: #eef1f6; color: var(--muted); border-radius: 10px; padding: 0 6px; font-size: 11px; margin-left: 3px; }
.tabs button.active .n { background: var(--primary-soft); color: var(--primary); }
.conv-items { overflow-y: auto; flex: 1; }
.conv { display: flex; gap: 10px; padding: 12px 16px; border-bottom: 1px solid #f1f3f7; cursor: pointer; position: relative; }
.conv:hover { background: #fafbfd; }
.conv.active { background: var(--primary-soft); }
.conv.active::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--primary); }
.conv .body { flex: 1; min-width: 0; }
.conv .meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: center; margin-bottom: 2px; overflow: hidden; white-space: nowrap; }
.conv .name { font-weight: 600; display: flex; justify-content: space-between; gap: 6px; }
.conv .name span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv .time { font-size: 11px; color: var(--muted); font-weight: 400; flex-shrink: 0; }
.conv .last { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: flex; justify-content: space-between; gap: 6px; margin-top: 2px; }
.conv .last span:first-child { overflow: hidden; text-overflow: ellipsis; }
.badge { background: var(--green); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; font-weight: 600; flex-shrink: 0; line-height: 18px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; padding: 1px 7px; border-radius: 4px; background: #eef1f6; color: #3c4858; white-space: nowrap; }
.tag i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- chat ---------- */
.chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chat-head { background: #fff; border-bottom: 1px solid var(--border); padding: 10px 16px; display: flex; align-items: center; gap: 12px; min-height: 60px; }
.chat-head .who { flex: 1; min-width: 0; }
.chat-head .who b { display: block; font-size: 15px; }
.chat-head .who span { color: var(--muted); font-size: 12px; }
.chat-head .actions { display: flex; gap: 6px; align-items: center; }
.messages { flex: 1; overflow-y: auto; padding: 16px 24px; display: flex; flex-direction: column; gap: 4px; }
.msg-row { display: flex; }
.msg-row.out { justify-content: flex-end; }
.bubble { max-width: min(560px, 75%); padding: 8px 12px; border-radius: 12px; position: relative; word-wrap: break-word; line-height: 1.4; }
.bubble .text { white-space: pre-wrap; }
.msg-row.in .bubble { background: #fff; border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-row.out .bubble { background: var(--out); color: #fff; border-bottom-right-radius: 4px; }
.msg-row.note .bubble { background: var(--note); color: var(--text); border: 1px solid var(--note-border); }
.bubble .foot { font-size: 11px; opacity: .75; margin-top: 3px; display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
.bubble .author { font-size: 11px; font-weight: 600; opacity: .85; margin-bottom: 2px; }
.bubble img.media, .bubble video.media { max-width: 280px; max-height: 320px; border-radius: 8px; display: block; margin-bottom: 4px; cursor: pointer; }
.bubble audio { max-width: 260px; display: block; }
.bubble .file { display: flex; align-items: center; gap: 8px; padding: 8px; background: rgba(0,0,0,.06); border-radius: 6px; color: inherit; text-decoration: none; margin-bottom: 4px; }
.msg-row.out .bubble .file { background: rgba(255,255,255,.18); }
.event { align-self: center; font-size: 12px; color: var(--muted); background: #e9edf4; padding: 3px 12px; border-radius: 12px; margin: 8px 0; }
.day { align-self: center; font-size: 12px; color: var(--muted); margin: 10px 0 4px; font-weight: 600; }
.ticks { font-size: 12px; letter-spacing: -3px; }
.ticks.read { color: #b8f0ff; }
.load-more { align-self: center; margin-bottom: 8px; }

.composer { background: #fff; border-top: 1px solid var(--border); }
.composer .modes { display: flex; gap: 4px; padding: 8px 12px 0; }
.composer .modes button { border: none; background: none; padding: 5px 10px; border-radius: 6px; color: var(--muted); font-weight: 500; font-size: 13px; }
.composer .modes button.active { background: var(--primary-soft); color: var(--primary); }
.composer .modes button.active.note { background: var(--note); color: #9a6b00; }
.composer.note-mode { background: #fffcf2; }
.composer textarea { width: 100%; border: none; outline: none; resize: none; padding: 10px 16px; min-height: 52px; max-height: 180px; background: transparent; }
.composer .bar { display: flex; align-items: center; gap: 6px; padding: 6px 12px 10px; }
.composer .bar .spacer { flex: 1; }
.composer .hint { font-size: 12px; color: var(--muted); }
.composer .pending { padding: 6px 16px; font-size: 13px; display: flex; gap: 8px; align-items: center; background: #f7f9fc; }
.quick { position: absolute; bottom: 100%; left: 12px; right: 12px; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.08); max-height: 240px; overflow-y: auto; }
.quick div { padding: 8px 12px; cursor: pointer; }
.quick div.sel, .quick div:hover { background: var(--primary-soft); }
.quick b { color: var(--primary); margin-right: 8px; }
.banner { padding: 12px 16px; background: #fff8e6; border-top: 1px solid #f5e1a4; display: flex; align-items: center; gap: 12px; justify-content: space-between; }

.no-chat { flex: 1; display: grid; place-items: center; color: var(--muted); text-align: center; }
.no-chat svg { width: 64px; height: 64px; color: #c8d1de; }

/* ---------- painel do contato ---------- */
.contact-panel { width: 290px; background: #fff; border-left: 1px solid var(--border); overflow-y: auto; flex-shrink: 0; }
.contact-panel .head { padding: 20px 16px; text-align: center; border-bottom: 1px solid var(--border); }
.contact-panel .head .avatar { margin: 0 auto 10px; }
.contact-panel .head b { font-size: 16px; display: block; }
.contact-panel .head span { color: var(--muted); }
.contact-panel .sec { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.contact-panel .sec h4 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.kv { display: flex; justify-content: space-between; margin-bottom: 8px; gap: 10px; font-size: 13px; }
.kv span:first-child { color: var(--muted); }

/* ---------- páginas de configuração ---------- */
.page { flex: 1; overflow-y: auto; padding: 24px 32px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; gap: 12px; }
.page-head h2 { margin: 0; font-size: 20px; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 16px; border-bottom: 1px solid var(--border); font-weight: 600; }
td { padding: 12px 16px; border-bottom: 1px solid #f1f3f7; vertical-align: middle; }
tr:last-child td { border-bottom: none; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.conn-card { padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.conn-card .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.conn-card h3 { margin: 0; font-size: 16px; }
.status { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 10px; }
.status.connected { background: #e3f9e5; color: #1f8a26; }
.status.disconnected { background: #ffe9e8; color: #c42318; }
.status.qr, .status.connecting { background: #fff4dc; color: #9a6b00; }
.qr-box { text-align: center; padding: 10px; background: #fafbfd; border-radius: 8px; }
.qr-box img { width: 240px; height: 240px; }
.qr-box p { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat { padding: 16px 18px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat b { display: block; font-size: 28px; margin-top: 4px; }

/* ---------- modal e toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(31,45,61,.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.2); }
.modal header { padding: 18px 22px 0; display: flex; justify-content: space-between; align-items: center; }
.modal header h3 { margin: 0; font-size: 17px; }
.modal .content { padding: 18px 22px; }
.modal footer { padding: 0 22px 18px; display: flex; justify-content: flex-end; gap: 8px; }
#toast-root { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #1f2d3d; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: 360px; animation: up .2s; }
.toast.error { background: #c42318; }
@keyframes up { from { transform: translateY(10px); opacity: 0; } }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.85); display: grid; place-items: center; z-index: 60; cursor: zoom-out; }
.lightbox img { max-width: 92vw; max-height: 92vh; }

.mobile-back { display: none; }
@media (max-width: 1200px) { .contact-panel { display: none; } .contact-panel.show { display: block; position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: -8px 0 30px rgba(0,0,0,.1); } }
@media (max-width: 860px) {
  .sidebar { width: 60px; }
  .sidebar .brand span, .nav a span, .nav .section, .me .info, .nav a .count { display: none; }
  .conv-list { width: 100%; }
  .main.has-chat .conv-list { display: none; }
  .main:not(.has-chat) .chat { display: none; }
  .mobile-back { display: inline-flex; }
  .page { padding: 16px; }
}
