/* =============================================================================
   components.css — botões, cards, tabelas, modais, badges, tags, chat, forms,
   toasts, loaders e estados (vazio/loading/erro). Camada 3 de 3.
   ========================================================================== */

/* ---- Cards --------------------------------------------------------------- */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  /* Base para combinar suavemente com .hover-lift (animations.css). */
  transition: transform var(--dur) var(--ease-out), box-shadow var(--dur) var(--ease-out);
}
.card__body { padding: var(--sp-5); }
.card__header {
  padding: var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  font-weight: 600;
}
.card__footer { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--c-border); }

/* ---- KPI card ------------------------------------------------------------ */
/* KPIs compactos: borda esquerda grossa colorida + contorno fino da mesma cor,
   com fundo levemente tingido. A cor vem de --kpi-color (variantes abaixo). */
.kpi {
  padding: var(--sp-4) var(--sp-5);
  border: 1px solid color-mix(in srgb, var(--kpi-color, var(--c-border)) 55%, transparent);
  border-left: 4px solid var(--kpi-color, var(--c-primary));
  background: color-mix(in srgb, var(--kpi-color, transparent) 6%, var(--c-surface));
}
.kpi__label { color: var(--c-text-soft); font-size: var(--fs-sm); display: flex; align-items: center; gap: var(--sp-2); }
.kpi__value { font-size: var(--fs-xl); font-weight: 700; margin-top: var(--sp-1); letter-spacing: -.02em; }
.kpi__hint { font-size: var(--fs-xs); color: var(--c-text-muted); margin-top: var(--sp-1); }

/* Variantes de cor por métrica (borda + contorno + tingimento). */
.kpi--info    { --kpi-color: var(--c-status-fila); }   /* azul   — fila/informativo */
.kpi--success { --kpi-color: var(--c-status-atend); }  /* verde  — em atendimento   */
.kpi--warning { --kpi-color: var(--c-status-aguard); } /* âmbar  — aguardando/tempo */
.kpi--muted   { --kpi-color: var(--c-status-fim); }    /* cinza  — finalizado       */
.kpi--accent  { --kpi-color: var(--c-accent); }        /* esmeralda — destaque/tema */
.kpi--danger  { --kpi-color: var(--c-danger); }        /* vermelho — alerta         */

/* Paleta distinta por KPI — uma cor diferente para cada cartão. */
.kpi--emerald { --kpi-color: #10b981; }
.kpi--blue    { --kpi-color: #2563eb; }
.kpi--violet  { --kpi-color: #7c3aed; }
.kpi--amber   { --kpi-color: #d97706; }
.kpi--rose    { --kpi-color: #e11d48; }
.kpi--teal    { --kpi-color: #0d9488; }
.kpi--cyan    { --kpi-color: #0891b2; }
.kpi--indigo  { --kpi-color: #4f46e5; }

/* ---- Botões -------------------------------------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
  padding: 9px 16px; border: 1px solid transparent; border-radius: 12px;
  font-size: var(--fs-base); font-weight: 600; line-height: 1;
  background: var(--c-surface-2); color: var(--c-text);
  transition: background var(--transition), border-color var(--transition), box-shadow var(--transition), transform .12s ease;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
/* Press sutil: recua levemente ao clicar (feedback tátil). */
.btn:active { transform: translateY(0) scale(.97); }
.btn:focus-visible { box-shadow: var(--focus-ring); outline: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none; }
/* Primário usa o accent verde esmeralda. */
.btn--primary { background: var(--c-accent); color: #fff; }
.btn--primary:hover { background: var(--c-accent-dark); }
.btn--secondary { background: var(--c-surface); border-color: var(--c-border-strong); color: var(--c-text); }
.btn--secondary:hover { background: var(--c-surface-2); }
.btn--danger { background: var(--c-danger); color: #fff; }
.btn--danger:hover { filter: brightness(.94); }
.btn--ghost { background: transparent; color: var(--c-text-soft); }
.btn--ghost:hover { background: var(--c-surface-2); }
.btn--sm { padding: 6px 11px; font-size: var(--fs-sm); }
.btn--block { width: 100%; }
.btn--icon { padding: 8px; }

/* ---- Formulários --------------------------------------------------------- */
.field { margin-bottom: var(--sp-4); }
.label { display: block; font-size: var(--fs-sm); font-weight: 600; margin-bottom: var(--sp-2); color: var(--c-text-soft); }
.input, .select, .textarea {
  width: 100%; padding: 10px 12px;
  background: var(--c-surface); color: var(--c-text);
  border: 1px solid var(--c-border-strong); border-radius: 12px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.input:focus, .select:focus, .textarea:focus {
  border-color: rgba(16, 185, 129, .50); box-shadow: var(--focus-ring); outline: none;
}
.textarea { resize: vertical; min-height: 84px; }
.help { font-size: var(--fs-xs); color: var(--c-text-muted); margin-top: var(--sp-2); }
.field--inline { display: flex; align-items: center; gap: var(--sp-3); }

/* checkbox/radio agradáveis */
.check { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--c-primary); }

/* Lista de checkboxes em coluna (ex.: setores do usuário) — rolável se longa. */
.checklist {
  display: flex; flex-direction: column; gap: var(--sp-2);
  max-height: 180px; overflow-y: auto;
  border: 1px solid var(--c-border); border-radius: var(--radius);
  padding: 10px 12px; background: var(--c-surface);
}
.checklist .check { width: 100%; }

/* ---- Tabelas ------------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.table th, .table td { padding: 11px 14px; text-align: left; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.table th { font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--c-text-muted); font-weight: 600; background: var(--c-surface-2); }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--c-surface-2); }
.table td .row-actions { display: flex; gap: var(--sp-2); justify-content: flex-end; }
/* Entrada escalonada das linhas (opt-in nas páginas via .table--rows-in).
   Cada <tr> usa seu próprio --i (definido inline ou via ui.stagger()). */
.table--rows-in tbody tr {
  animation: anim-in var(--dur-slow) var(--ease-out) both;
  animation-delay: calc(var(--i, 0) * 45ms);
}
@media (prefers-reduced-motion: reduce) {
  .table--rows-in tbody tr { animation-duration: .001ms !important; animation-delay: 0ms !important; }
}

/* ---- Badges e tags ------------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: 600; line-height: 1.6;
  background: var(--c-surface-2); color: var(--c-text-soft);
}
.badge--fila   { background: #e1effe; color: #1e429f; }
.badge--atend  { background: #d1f4e3; color: #03543f; }
.badge--aguard { background: #fdf6b2; color: #723b13; }
.badge--fim    { background: #e9edf3; color: #374151; }
.badge--dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: var(--radius-pill);
  font-size: var(--fs-xs); font-weight: 600; color: #fff;
}
.tag__close { cursor: pointer; opacity: .85; font-weight: 700; }
.tag--pick { color: var(--c-text); background: var(--c-surface); border: 1px solid var(--c-border-strong); }
.tag-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---- Modais -------------------------------------------------------------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.55);
  display: grid; place-items: center; padding: var(--sp-4); z-index: 100;
  animation: fade-in 140ms ease;
}
.modal {
  width: 100%; max-width: 520px; background: var(--c-surface);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  max-height: 90vh; display: flex; flex-direction: column;
  animation: pop-in 160ms ease;
}
.modal--lg { max-width: 760px; }
.modal__header { padding: var(--sp-5); border-bottom: 1px solid var(--c-border); display: flex; align-items: center; justify-content: space-between; }
.modal__title { font-size: var(--fs-md); font-weight: 700; }
.modal__body { padding: var(--sp-5); overflow-y: auto; }
.modal__footer { padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--c-border); display: flex; justify-content: flex-end; gap: var(--sp-3); }
.modal__close { background: transparent; border: none; font-size: 22px; line-height: 1; color: var(--c-text-muted); padding: 4px; border-radius: 6px; }
.modal__close:hover { background: var(--c-surface-2); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
/* Saídas (overlay-out / modal-out) e a classe .toast--out vivem em
   animations.css (biblioteca central). ui.js aplica .overlay--out / .modal--out
   ao fechar o modal e .toast--out ao remover o toast. */

/* ---- Toasts -------------------------------------------------------------- */
.toast-stack { position: fixed; top: var(--sp-5); right: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-3); z-index: 200; }
.toast {
  min-width: 260px; max-width: 380px; padding: var(--sp-3) var(--sp-4);
  background: var(--c-surface); border: 1px solid var(--c-border); border-left: 4px solid var(--c-text-muted);
  border-radius: var(--radius); box-shadow: var(--shadow-lg);
  display: flex; gap: var(--sp-3); align-items: flex-start; animation: toast-in 180ms ease;
}
.toast--success { border-left-color: var(--c-success); }
.toast--error   { border-left-color: var(--c-danger); }
.toast--info    { border-left-color: var(--c-info); }
.toast__icon { font-size: var(--fs-md); }
.toast__body { flex: 1; font-size: var(--fs-sm); }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ---- Estados: loading / vazio / erro ------------------------------------ */
.state { padding: var(--sp-10) var(--sp-6); text-align: center; color: var(--c-text-soft); }
.state__icon { font-size: 38px; margin-bottom: var(--sp-3); opacity: .7; }
.state__title { font-weight: 600; color: var(--c-text); margin-bottom: var(--sp-2); }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--c-border); border-top-color: var(--c-primary);
  animation: spin .7s linear infinite; display: inline-block;
}
.spinner--lg { width: 34px; height: 34px; border-width: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }
.skeleton { background: linear-gradient(90deg, #eef1f5 25%, #f6f8fa 37%, #eef1f5 63%); background-size: 400% 100%; animation: shimmer 1.3s ease infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }

/* ---- Paginação ----------------------------------------------------------- */
.pagination { display: flex; align-items: center; gap: var(--sp-3); justify-content: flex-end; padding-top: var(--sp-4); }

/* ---- Chat (inbox) -------------------------------------------------------- */
.chat { display: flex; flex-direction: column; height: 100%; }
.chat__header { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--c-border); display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
.chat__header-left { display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.chat__back { flex: none; }
.chat__num { font-weight: 700; font-size: var(--fs-md); }
/* Identificação do contato clicável (abre o painel de contato). */
.chat__contact { display: flex; align-items: center; gap: var(--sp-3); border: none; background: none; padding: 4px 6px; margin: -4px -6px; border-radius: var(--radius-sm); cursor: pointer; text-align: left; }
.chat__contact:hover { background: var(--c-surface-2); }
.chat__contact .avatar { width: 40px; height: 40px; }
/* Barra de ações no topo da conversa. */
.chat__actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.chat__body { flex: 1; overflow-y: auto; padding: var(--sp-4); background: #eceff3; display: flex; flex-direction: column; gap: var(--sp-3); }
.chat__form { padding: var(--sp-3); border-top: 1px solid var(--c-border); display: flex; gap: var(--sp-2); background: var(--c-surface); }
.bubble {
  max-width: 78%; padding: 9px 13px; border-radius: 12px; font-size: var(--fs-base);
  box-shadow: var(--shadow-sm); position: relative; word-wrap: break-word;
}
.bubble__meta { font-size: 10px; color: var(--c-text-muted); margin-top: 4px; text-align: right; }
.bubble--in  { align-self: flex-start; background: #fff; border-top-left-radius: 3px; }
.bubble--out { align-self: flex-end; background: var(--c-primary-soft); border-top-right-radius: 3px; }
.bubble--bot { align-self: flex-start; background: #e1effe; border-top-left-radius: 3px; }
.bubble__author { font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--c-text-muted); margin-bottom: 3px; }

/* lista de tickets na fila */
.ticket-item { padding: var(--sp-3) var(--sp-4); border-bottom: 1px solid var(--c-border); cursor: pointer; transition: background var(--transition); }
.ticket-item:hover { background: var(--c-surface-2); }
.ticket-item.is-active { background: var(--c-primary-soft); }
.ticket-item__top { display: flex; justify-content: space-between; gap: var(--sp-2); align-items: center; }
.ticket-item__name { font-weight: 600; }
.ticket-item__preview { color: var(--c-text-muted); font-size: var(--fs-sm); margin-top: 2px; }

/* ---- Construtor de fluxo ------------------------------------------------- */
.flow-node { border: 1px solid var(--c-border-strong); border-radius: var(--radius); padding: var(--sp-4); margin-bottom: var(--sp-3); background: var(--c-surface-2); }
.flow-option { display: flex; gap: var(--sp-2); align-items: center; margin-bottom: var(--sp-2); }
.flow-option .input { flex: 1; }

/* ---- Matriz de permissões ------------------------------------------------ */
.perm-matrix th, .perm-matrix td { text-align: center; }
.perm-matrix td:first-child, .perm-matrix th:first-child { text-align: left; }

/* ---- Misc ---------------------------------------------------------------- */
.divider { height: 1px; background: var(--c-border); margin: var(--sp-4) 0; }
.swatch { width: 16px; height: 16px; border-radius: 4px; display: inline-block; border: 1px solid rgba(0,0,0,.1); vertical-align: middle; }
.stars { color: #e3a008; letter-spacing: 2px; }
.kv { display: flex; justify-content: space-between; gap: var(--sp-3); padding: 6px 0; border-bottom: 1px dashed var(--c-border); }
.kv:last-child { border-bottom: none; }
.kv__k { color: var(--c-text-muted); font-size: var(--fs-sm); }
.toolbar { display: flex; gap: var(--sp-3); align-items: center; flex-wrap: wrap; margin-bottom: var(--sp-4); }
.toolbar .grow { min-width: 160px; }

/* ---- Inbox: barra de ferramentas + abas de status + cards ---------------- */
.inbox-toolbar { display: flex; gap: var(--sp-2); align-items: center; flex-wrap: wrap; }
.inbox-toolbar .select { max-width: 150px; }

/* Abas QUEBRAM linha (flex-wrap) — sem barra de rolagem. Todos os tipos de
   atendimento ficam visíveis de uma vez. */
.inbox-tabs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--c-border); }
/* Abas em coluna (ícone em cima, rótulo embaixo), ocupando a linha por igual e
   quebrando o texto quando não couber — estilo "menu" enfileirado. */
.inbox-tab {
  flex: 1 1 0; min-width: 64px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  padding: 8px 6px; border-radius: var(--radius); border: 1px solid var(--c-border);  /* moldura discreta */
  font-size: var(--fs-sm); font-weight: 600; color: var(--c-text-soft);
  background: transparent; cursor: pointer; transition: background var(--transition), border-color var(--transition);
  position: relative; text-align: center;
}
.inbox-tab__icon { font-size: 18px; line-height: 1; }
.inbox-tab__label { font-size: 12px; line-height: 1.15; }   /* sem nowrap: quebra linha */
.inbox-tab:hover { background: var(--c-surface-2); border-color: var(--c-border-strong); }
.inbox-tab.is-active { background: var(--c-primary-soft); color: var(--c-primary-dark); border-color: var(--c-primary); }

/* Modal "Novo atendimento" — lista de contatos sincronizados selecionáveis. */
.novo-contatos { max-height: 280px; overflow-y: auto; border: 1px solid var(--c-border); border-radius: var(--radius); margin-top: var(--sp-2); }
.novo-contato { display: flex; align-items: center; gap: var(--sp-3); width: 100%; text-align: left; padding: 9px 12px; background: transparent; border: none; border-bottom: 1px solid var(--c-border); cursor: pointer; }
.novo-contato:last-child { border-bottom: none; }
.novo-contato:hover { background: var(--c-surface-2); }
.novo-contato.is-selected { background: var(--c-primary-soft); box-shadow: inset 3px 0 0 var(--c-primary); }
.novo-contato__body { min-width: 0; }

/* Modal "Transferir" — alternância setor/atendente. */
.transf-tipo { display: flex; gap: var(--sp-4); margin-bottom: var(--sp-3); }
.inbox-tab__count { position: absolute; top: 3px; right: 6px; background: var(--c-border); color: var(--c-text-soft); border-radius: var(--radius-pill); padding: 0 6px; font-size: 10px; line-height: 1.5; min-width: 16px; text-align: center; }
.inbox-tab.is-active .inbox-tab__count { background: var(--c-primary); color: #fff; }

.ticket-card { display: flex; gap: var(--sp-3); padding: 11px 14px; border-bottom: 1px solid var(--c-border); cursor: pointer; transition: background var(--transition); }
.ticket-card:hover { background: var(--c-surface-2); }
.ticket-card.is-active { background: var(--c-primary-soft); box-shadow: inset 3px 0 0 var(--c-primary); }
.ticket-card__av { width: 40px; height: 40px; flex: none; border-radius: var(--radius-pill); background: var(--c-primary); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: var(--fs-sm); }
.ticket-card__body { flex: 1; min-width: 0; }
.ticket-card__row { display: flex; justify-content: space-between; gap: var(--sp-2); align-items: baseline; }
.ticket-card__name { font-weight: 600; }
.ticket-card__time { font-size: 11px; color: var(--c-text-muted); white-space: nowrap; flex: none; }
.ticket-card__preview { color: var(--c-text-muted); font-size: var(--fs-sm); margin-top: 1px; }
.ticket-card__meta { display: flex; gap: 6px; align-items: center; margin-top: 5px; flex-wrap: wrap; }
.ticket-card__att { font-size: 11px; color: var(--c-text-soft); display: inline-flex; align-items: center; gap: 3px; }
.ticket-card__att--none { color: var(--c-text-muted); font-style: italic; }
