:root {
  --bg: #f5f6f8;
  --card: #ffffff;
  --text: #1f2430;
  --muted: #6b7280;
  --primary: #6c5ce7;
  --primary-dark: #5a4bd1;
  --danger: #e5484d;
  --danger-dark: #cc3c40;
  --border: #e5e7eb;
  --radius: 10px;
}

* { box-sizing: border-box; }

.hidden { display: none !important; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.btn {
  display: inline-block;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: none;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background .15s ease;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn-secondary { background: #eef0ff; color: var(--primary-dark); }
.btn-secondary:hover:not(:disabled) { background: #dfe2ff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-dark); }
.btn-ghost { background: transparent; color: var(--text); }
.btn-ghost:hover { background: rgba(0,0,0,.05); }
.btn-large { padding: 12px 28px; font-size: 15px; }
.btn-small { padding: 5px 10px; font-size: 12px; }

/* landing */
.landing {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.landing-card {
  background: var(--card);
  padding: 48px;
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,.06);
  max-width: 420px;
  text-align: center;
}
.landing-card h1 { margin: 0 0 8px; font-size: 22px; }
.subtitle { color: var(--muted); margin-bottom: 28px; font-size: 14px; }
.footnote { color: var(--muted); font-size: 12px; margin-top: 20px; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 13px; text-align: left; }
.alert-error { background: #fdecec; color: #b3261e; }

/* dashboard */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  padding: 14px 24px;
  border-bottom: 1px solid var(--border);
}
.topbar-left { display: flex; align-items: baseline; gap: 12px; }
.agent-name { color: var(--muted); font-size: 13px; }

body { overflow-x: hidden; } /* nada de scroll horizontal na pagina toda */
.container { max-width: 1180px; margin: 24px auto; padding: 0 20px; }

/* a tabela rola dentro do proprio container em vez de quebrar a pagina */
.table-wrap { width: 100%; overflow-x: auto; }

.org-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 12px;
}
.org-label { font-size: 13px; font-weight: 600; }
.org-bar input {
  width: 220px;
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 13px;
}
.org-select {
  min-width: 260px;
  max-width: 380px;
  padding: 7px 10px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 13px;
  background: #fff;
  cursor: pointer;
}
.org-active { font-size: 12px; font-weight: 600; color: var(--primary-dark); }
.org-hint { color: var(--muted); font-size: 12px; flex-basis: 100%; }

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar input[type="search"] {
  flex: 1;
  min-width: 220px;
  padding: 9px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  font-size: 14px;
}

/* indicador de carregamento (spinner + contador + barra animada) */
.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 13px; color: var(--muted); }
.loading-count { font-size: 13px; font-weight: 700; color: var(--primary-dark); }
.loading-bar {
  flex-basis: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.loading-bar-fill {
  width: 40%;
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  animation: indeterminate 1.1s ease-in-out infinite;
}
/* modo determinado: sem animacao, largura controlada via JS (0-100%) */
.loading.determinate .loading-bar-fill {
  animation: none;
  transition: width .25s ease;
}
@keyframes indeterminate {
  0%   { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}

.status {
  min-height: 20px;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 10px;
}
.status.error { color: var(--danger); }
.status.success { color: #1a9e5f; }

/* resumo de canais detectados */
.channel-summary {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.channel-summary-head {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.channel-summary-head strong { font-size: 14px; }
.channel-summary-hint { color: var(--muted); font-size: 12px; flex: 1; }
.channel-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.channel-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fafafa;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  transition: all .12s ease;
}
.channel-chip:hover { background: #eef0ff; border-color: var(--primary); }
.channel-chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}
.channel-chip .chip-label { overflow-wrap: anywhere; }
.channel-chip .chip-count {
  font-size: 11px;
  font-weight: 700;
  background: rgba(0,0,0,.08);
  border-radius: 999px;
  padding: 1px 7px;
}
.channel-chip.active .chip-count { background: rgba(255,255,255,.25); }

.contacts-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.contacts-table th, .contacts-table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.contacts-table th { background: #fafafa; color: var(--muted); font-weight: 600; }
.contacts-table tbody tr:hover { background: #fafaff; }
.contacts-table .muted { color: var(--muted); font-style: italic; }
.contacts-table .channel-id {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  color: var(--muted);
  word-break: break-all; /* UUID longo quebra em vez de esticar a tabela */
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--muted);
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.35);
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-box {
  background: #fff;
  padding: 28px;
  border-radius: 14px;
  max-width: 380px;
  width: 90%;
}
.modal-box h3 { margin-top: 0; }
.modal-warning { color: var(--danger); font-size: 13px; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}
