:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --primary: #25d366;
  --primary-dark: #1da851;
  --text: #1a202c;
  --muted: #718096;
  --danger: #e53e3e;
  --warning: #d69e2e;
  --sidebar-w: 220px;
  --topbar-h: 56px;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ── Login ── */
body.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 40px;
  width: 360px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}
.login-brand {
  font-size: 24px;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  margin-bottom: 8px;
}

/* ── App shell ── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: #1a202c;
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.sidebar-brand {
  padding: 20px 16px;
  font-size: 18px;
  font-weight: 700;
  color: var(--primary);
  border-bottom: 1px solid #2d3748;
}
.sidebar-nav { flex: 1; padding: 8px 0; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  color: #a0aec0;
  text-decoration: none;
  border-radius: 6px;
  margin: 2px 8px;
  transition: background 0.15s;
}
.nav-item:hover, .nav-item.active {
  background: #2d3748;
  color: #fff;
}
.nav-icon { font-size: 16px; }
.nav-label { flex: 1; }
.nav-badge {
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  min-width: 18px;
  text-align: center;
}
.sidebar-footer {
  padding: 16px;
  border-top: 1px solid #2d3748;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.sidebar-agent { font-size: 12px; color: #a0aec0; }
.sidebar-agent-info { display: flex; align-items: center; gap: 8px; }
.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #48bb78;
  flex-shrink: 0;
}

/* ── Main ── */
.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
}
.topbar-title { font-size: 16px; font-weight: 600; }
.topbar-actions { display: flex; gap: 8px; }
.content { flex: 1; overflow: hidden; }

/* ── Inbox shell ── */
.inbox-shell { display: flex; height: 100%; }

/* ── Lista de conversas ── */
.conv-list {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  background: var(--surface);
}
.conv-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.conv-item:hover { background: var(--bg); }
.conv-item.active { background: #f0fff4; border-left: 3px solid var(--primary); }
.conv-item.unread .conv-name { font-weight: 700; }
.conv-item.conv-waiting { border-left: 3px solid var(--danger); background: #fff5f5; }
.conv-item.conv-waiting:hover { background: #fed7d7; }
.filter-btn { background: #e2e8f0; color: var(--text); }
.conv-name { font-size: 14px; font-weight: 500; }
.conv-phone { font-size: 12px; color: var(--muted); margin-top: 2px; }
.conv-preview { font-size: 12px; color: var(--muted); margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.conv-time { font-size: 11px; color: var(--muted); }

/* ── Status badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.badge-waiting { background: #fef3c7; color: #92400e; }
.badge-open    { background: #d1fae5; color: #065f46; }
.badge-resolved{ background: #e2e8f0; color: #4a5568; }

/* ── Chat panel ── */
.chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.chat-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.chat-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.chat-contact-name { font-weight: 600; font-size: 15px; }
.chat-contact-phone { font-size: 12px; color: var(--muted); }
.chat-actions { display: flex; gap: 8px; }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.msg-bubble {
  max-width: 65%;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-break: break-word;
}
.msg-in {
  background: var(--surface);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 2px;
}
.msg-out {
  background: #dcf8c6;
  align-self: flex-end;
  border-bottom-right-radius: 2px;
}
.msg-time {
  font-size: 10px;
  color: var(--muted);
  margin-top: 3px;
  text-align: right;
}
.chat-input-area {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  resize: none;
  outline: none;
  font-family: inherit;
}
.chat-input:focus { border-color: var(--primary); }

/* ── Botões ── */
.btn {
  padding: 8px 16px;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  transition: opacity 0.15s;
}
.btn:hover { opacity: 0.85; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #e2e8f0; color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.active-filter { background: var(--primary); color: #fff; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 6px; color: var(--muted); }
.form-control {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.form-control:focus { border-color: var(--primary); }

/* ── Toast ── */
#toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 9999; }
.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  animation: fadeIn 0.2s ease;
}
.toast-success { background: #38a169; }
.toast-danger  { background: var(--danger); }
.toast-warn    { background: var(--warning); }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-title { font-size: 15px; font-weight: 600; }

/* ── Table ── */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; padding: 8px 12px; color: var(--muted); font-weight: 500; border-bottom: 1px solid var(--border); }
td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 440px;
  max-width: 95vw;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
}
.modal-title { font-size: 16px; font-weight: 600; margin-bottom: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
