:root {
  --bg-app: #111b21;
  --bg-sidebar: #111b21;
  --bg-sidebar-hover: #202c33;
  --bg-sidebar-active: #2a3942;
  --bg-chat: #0b141a;
  --bubble-in: #202c33;
  --bubble-out: #005c4b;
  --text: #e9edef;
  --text-muted: #8696a0;
  --accent: #00a884;
  --border: #222d34;
  --tag: #1f3a33;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; font-family: var(--font); background: var(--bg-app); color: var(--text); }
.app { display: grid; grid-template-columns: minmax(300px, 400px) 1fr; height: 100vh; max-height: 100dvh; }
.sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--bg-sidebar); min-height: 0; }
.sidebar-head { padding: 1rem 1rem 0.75rem; border-bottom: 1px solid var(--border); }
.sidebar-head h1 { margin: 0; font-size: 1.2rem; font-weight: 600; }
.sub { margin: 0.25rem 0 0.75rem; font-size: 0.8rem; color: var(--text-muted); }
.filters { display: flex; flex-direction: column; gap: 0.45rem; }
.filters input[type="search"], .filters select, .filters input[type="date"] {
  width: 100%; padding: 0.45rem 0.65rem; border: none; border-radius: 8px;
  background: var(--bg-sidebar-active); color: var(--text); font-size: 0.85rem;
}
.filter-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; }
.filter-row label { font-size: 0.72rem; color: var(--text-muted); display: flex; flex-direction: column; gap: 0.2rem; }
.check { font-size: 0.8rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.4rem; }
.contact-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.contact-item {
  display: grid; grid-template-columns: 44px 1fr; gap: 0.65rem; padding: 0.6rem 1rem;
  cursor: pointer; border-bottom: 1px solid var(--border); transition: background 0.12s;
}
.contact-item:hover { background: var(--bg-sidebar-hover); }
.contact-item.active { background: var(--bg-sidebar-active); }
.contact-avatar {
  width: 44px; height: 44px; border-radius: 50%; background: linear-gradient(135deg, #3a4a55, #1f2c34);
  display: flex; align-items: center; justify-content: center; font-weight: 600; color: var(--accent);
}
.contact-body { min-width: 0; }
.contact-row { display: flex; justify-content: space-between; gap: 0.5rem; align-items: baseline; }
.contact-name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-time { font-size: 0.7rem; color: var(--text-muted); flex-shrink: 0; }
.contact-preview { margin: 0.15rem 0 0; font-size: 0.78rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-tags { margin-top: 0.2rem; display: flex; flex-wrap: wrap; gap: 0.2rem; }
.tag-chip {
  font-size: 0.65rem; padding: 0.1rem 0.35rem; border-radius: 999px;
  background: var(--tag); color: var(--accent);
}
.chat { display: flex; flex-direction: column; min-height: 0; background: var(--bg-chat); }
.hidden { display: none !important; }
.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--text-muted); padding: 2rem; text-align: center;
}
.empty-icon { font-size: 3rem; opacity: 0.5; margin-bottom: 0.5rem; }
.chat-active { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.65rem 1.25rem;
  background: var(--bg-sidebar); border-bottom: 1px solid var(--border);
}
.chat-head .avatar {
  width: 40px; height: 40px; border-radius: 50%; background: var(--bg-sidebar-active);
  display: flex; align-items: center; justify-content: center; font-weight: 600; color: var(--accent);
}
.chat-head-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.chat-head-text strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head-text > span { font-size: 0.78rem; color: var(--text-muted); }
.tags { display: flex; flex-wrap: wrap; gap: 0.25rem; }
.badge { font-size: 0.75rem; color: var(--text-muted); background: var(--bg-sidebar-active); padding: 0.2rem 0.5rem; border-radius: 999px; }
.messages { flex: 1; overflow-y: auto; padding: 1rem 4%; display: flex; flex-direction: column; gap: 0.35rem; }
.msg-row { display: flex; width: 100%; }
.msg-row.in { justify-content: flex-start; }
.msg-row.out { justify-content: flex-end; }
.bubble {
  max-width: min(540px, 85%); padding: 0.45rem 0.65rem 0.35rem; border-radius: 8px;
  box-shadow: 0 1px 0.5px rgba(0,0,0,0.15);
}
.msg-row.in .bubble { background: var(--bubble-in); border-top-left-radius: 2px; }
.msg-row.out .bubble { background: var(--bubble-out); border-top-right-radius: 2px; }
.msg-row.sistema .bubble { background: #1a2330; opacity: 0.85; max-width: min(420px, 90%); }
.bubble-text { margin: 0; font-size: 0.92rem; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.bubble-meta { display: flex; justify-content: flex-end; align-items: center; gap: 0.4rem; margin-top: 0.2rem; flex-wrap: wrap; }
.bubble-origem {
  font-size: 0.65rem; text-transform: uppercase; letter-spacing: 0.03em;
  padding: 0.05rem 0.35rem; border-radius: 4px; background: rgba(0,0,0,0.25); color: rgba(233,237,239,0.85);
}
.bubble-time { font-size: 0.68rem; color: rgba(233,237,239,0.65); }
.day-sep {
  align-self: center; margin: 0.75rem 0; padding: 0.25rem 0.75rem; font-size: 0.75rem;
  color: var(--text-muted); background: var(--bg-sidebar-active); border-radius: 8px;
}
.load-error { padding: 1.5rem; color: #f87171; line-height: 1.5; font-size: 0.9rem; }
@media (max-width: 720px) { .app { grid-template-columns: 1fr; } }
