/*
 * Componentes de Pessoa + Vínculo (Fase 4 do refactor).
 *
 * - .avatar-anel  → wrapper com background dinâmico (sólido ou
 *                   conic-gradient para multi-papel) ao redor da foto.
 * - .badge-papel  → chip do tipo do vínculo com texto legível.
 *
 * Estilos seguem o padrão da identidade visual (Bootstrap 5 + FA),
 * respeitam prefers-reduced-motion e dark mode.
 *
 * Plano: docs/REFATORACAO_PESSOA.md §7.4.2.
 */

/* ============================================================
 * Avatar com ring multi-color
 * ============================================================ */

.avatar-anel {
  display: inline-block;
  padding: 3px;
  border-radius: 50%;
  /* background é injetado inline pelo template tag {% avatar_anel %} */
  vertical-align: middle;
  line-height: 0;
  flex-shrink: 0;
}

.avatar-anel .avatar-img,
.avatar-anel .avatar-iniciais {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  display: block;
  object-fit: cover;
  background-color: var(--color-pessoas, #6c757d);
}

.avatar-anel .avatar-iniciais {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 0.875rem;
  line-height: 1;
}

/* Tamanhos padronizados (alinhados com vox-avatar-{xs,sm,md,lg,xl}) */
.avatar-anel-xs { width: 28px; height: 28px; padding: 2px; }
.avatar-anel-xs .avatar-iniciais { font-size: 0.625rem; }

.avatar-anel-sm { width: 36px; height: 36px; padding: 2px; }
.avatar-anel-sm .avatar-iniciais { font-size: 0.75rem; }

.avatar-anel-md { width: 48px; height: 48px; padding: 3px; }
.avatar-anel-md .avatar-iniciais { font-size: 1rem; }

.avatar-anel-lg { width: 64px; height: 64px; padding: 3px; }
.avatar-anel-lg .avatar-iniciais { font-size: 1.25rem; }

.avatar-anel-xl { width: 96px; height: 96px; padding: 4px; }
.avatar-anel-xl .avatar-iniciais { font-size: 2rem; }

/* ============================================================
 * Badge de papel (chip do tipo de vínculo)
 * ============================================================ */

.badge-papel {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.8125rem;
  font-weight: 500;
  white-space: nowrap;
  /* background-color e color injetados inline pelo template */
  line-height: 1.2;
}

.badge-papel i {
  font-size: 0.85em;
}

/* Versão compacta (tabelas estreitas) */
.badge-papel-compacto {
  padding: 0.15rem 0.4rem;
  font-size: 0.6875rem;
  letter-spacing: 0.02em;
}

/* Stack horizontal de badges (lista de papeis na detail page) */
.badges-papel-stack {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
}

/* ============================================================
 * Seletor de vínculo — dropdown com avatar + badge + pills
 * (Produtor / Responsáveis Técnicos no form de Fazenda; reutilizável
 *  em qualquer seletor de Pessoa/Vínculo.)
 *
 * - .vox-seletor-item → linha do dropdown: avatar (anel da cor do tipo)
 *   + nome + badge do papel. SEM nome da org (selects são tenant-scoped).
 * - .vox-pill        → chip estilo Gmail do(s) selecionado(s): avatar +
 *   nome + badge + (×) remover.
 * ============================================================ */

.vox-seletor-menu {
  max-height: 280px;
  overflow-y: auto;
}

.vox-seletor-item {
  white-space: normal;
  cursor: pointer;
}

/* Empurra o badge do papel para a direita da linha. */
.vox-seletor-item .badge-papel {
  margin-left: auto;
  flex-shrink: 0;
}

.vox-seletor-item.active,
.vox-seletor-item:focus-visible {
  outline: none;
}

/* Avatar reduzido dentro de linhas/pills do seletor. */
.vox-seletor-item .avatar-anel,
.vox-pill .avatar-anel {
  width: 24px;
  height: 24px;
  padding: 2px;
}
.vox-seletor-item .avatar-iniciais,
.vox-pill .avatar-iniciais {
  font-size: 0.5625rem;
}

/* Container dos chips selecionados (multi-seleção). */
.vox-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.vox-pills:empty {
  display: none;
}

.vox-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  max-width: 100%;
  padding: 0.2rem 0.5rem 0.2rem 0.25rem;
  border-radius: 999px;
  background: var(--bs-tertiary-bg, #f1f3f5);
  border: 1px solid var(--bs-border-color, #dee2e6);
  font-size: 0.8125rem;
  line-height: 1.2;
}

.vox-pill .vox-pill-nome {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 14rem;
}

.vox-pill .vox-pill-remove {
  border: 0;
  background: transparent;
  line-height: 1;
  padding: 0 0.15rem;
  font-size: 1rem;
  cursor: pointer;
  color: var(--bs-secondary-color, #6c757d);
  border-radius: 50%;
}
.vox-pill .vox-pill-remove:hover {
  color: var(--bs-danger, #dc3545);
}

/* Coroa do produtor principal (picker único do cadastro de fazenda).
 * Ativada: coroa âmbar com "contorno" (glow via drop-shadow no glifo —
 * nunca caixa/borda de botão). Desativada: cinza translúcida; hover/focus
 * pré-visualiza o âmbar. Só vars --bs-* (tema-aware). */
.vox-pill .vox-pill-coroa {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: none;
  line-height: 1;
  padding: 0 0.15rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--bs-secondary-color, #6c757d);
  opacity: 0.35;
  transition: color 0.15s ease, opacity 0.15s ease, filter 0.15s ease;
}
.vox-pill .vox-pill-coroa:hover,
.vox-pill .vox-pill-coroa:focus-visible {
  color: var(--bs-warning, #ffc107);
  opacity: 0.85;
}
.vox-pill .vox-pill-coroa:focus-visible {
  outline: 2px solid #f39c12;
  outline-offset: 2px;
  border-radius: 4px;
}
.vox-pill .vox-pill-coroa.is-principal {
  color: var(--bs-warning, #ffc107);
  opacity: 1;
  cursor: default;
  filter: drop-shadow(0 0 3px rgba(255, 193, 7, 0.6));
}

/* A pill coroada ganha um tom âmbar sutil na borda — reforça a leitura
 * do principal sem gritar (funciona nos dois temas). */
.vox-pill.vox-pill-principal {
  border-color: rgba(255, 193, 7, 0.5);
}

[data-bs-theme="dark"] .vox-pill {
  background: rgba(255, 255, 255, 0.06);
}

/* Pill único embutido no botão do seletor de Produtor. */
.vox-seletor-toggle {
  min-height: 42px;
}
.vox-seletor-toggle .vox-pill {
  border: 0;
  background: transparent;
  padding: 0;
}

/* Coroa do RT principal em telas de ROSTER (ficha / gerenciar acessos).
 * Espelha .vox-pill-coroa do picker, mas aqui alterna com o selo "Principal":
 * quem é o principal mostra o selo (e esconde o botão); as demais linhas
 * elegíveis mostram o botão-coroa "tornar principal". O JS troca .is-principal.
 * Só vars --bs-* (tema-aware) — o selo já é subtle/emphasis. */
.vox-coroa-rt {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  vertical-align: middle;
}
.vox-coroa-rt .vox-coroa-selo {
  display: none;
}
.vox-coroa-rt.is-principal .vox-coroa-selo {
  display: inline-flex;
}
.vox-coroa-rt .vox-coroa-btn {
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: none;
  line-height: 1;
  padding: 0 0.15rem;
  font-size: 0.8rem;
  cursor: pointer;
  color: var(--bs-secondary-color, #6c757d);
  opacity: 0.4;
  transition: color 0.15s ease, opacity 0.15s ease;
}
.vox-coroa-rt.is-principal .vox-coroa-btn {
  display: none;
}
.vox-coroa-rt .vox-coroa-btn:hover,
.vox-coroa-rt .vox-coroa-btn:focus-visible {
  color: var(--bs-warning, #ffc107);
  opacity: 0.9;
}
.vox-coroa-rt .vox-coroa-btn:focus-visible {
  outline: 2px solid #f39c12;
  outline-offset: 2px;
  border-radius: 4px;
}
.vox-coroa-rt .vox-coroa-btn:disabled {
  cursor: progress;
  opacity: 0.3;
}

/* ============================================================
 * Acessibilidade & responsividade
 * ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .avatar-anel,
  .badge-papel,
  .vox-pill .vox-pill-coroa {
    transition: none !important;
  }
}

@media (max-width: 480px) {
  .vox-pill .vox-pill-nome {
    max-width: 9rem;
  }
}

/* Em telas estreitas, badges quebram para nova linha */
@media (max-width: 480px) {
  .badges-papel-stack {
    gap: 0.3rem;
  }
  .badge-papel {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
  }
}


/* ============================================================
 * Ficha compacta — strip identidade + sections empilhadas
 * Padrão B2B admin (cadastros/pessoa_detalhes.html).
 * ============================================================ */

.ficha-strip {
  padding: 1rem 1.25rem;
  border-radius: 0.75rem;
}

.ficha-strip-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.ficha-strip-avatar-placeholder {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-pessoas, #6c757d);
  color: white;
  font-weight: 600;
  font-size: 1.1rem;
  flex-shrink: 0;
}

.ficha-strip-name {
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.2;
  margin-bottom: 0.15rem;
}

.ficha-strip-meta {
  font-size: 0.85rem;
  color: var(--bs-secondary-color, #6c757d);
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.ficha-strip-meta i {
  width: 14px;
  text-align: center;
}

.ficha-strip-meta .meta-divider {
  color: var(--bs-border-color, #dee2e6);
}

.ficha-mini-stat {
  padding: 1rem;
  border-radius: 0.5rem;
  background: var(--bs-tertiary-bg, #f8f9fa);
}

[data-bs-theme="dark"] .ficha-mini-stat {
  background: rgba(255, 255, 255, 0.04);
}

.ficha-mini-stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--bs-secondary-color, #6c757d);
  font-weight: 600;
}

.ficha-mini-stat-value {
  font-size: 1.5rem;
  font-weight: 600;
  line-height: 1.1;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}

.status-pill::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.status-pill-ativa {
  background: rgba(25, 135, 84, 0.12);
  color: #198754;
}

.status-pill-inativa {
  background: rgba(108, 117, 125, 0.12);
  color: #6c757d;
}

[data-bs-theme="dark"] .status-pill-ativa {
  background: rgba(25, 135, 84, 0.18);
  color: #75d99c;
}

[data-bs-theme="dark"] .status-pill-inativa {
  background: rgba(255, 255, 255, 0.06);
  color: var(--bs-secondary-color, #adb5bd);
}


/* ============================================================
 * Tabs da lista de Pessoas (cor pessoas).
 * ============================================================ */

#pessoasTabs {
  border-bottom: 2px solid var(--color-pessoas, #6c757d);
}

#pessoasTabs .nav-link {
  color: #6c757d;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 0.6rem 1.2rem;
  font-weight: 500;
  transition: all 0.2s ease;
}

#pessoasTabs .nav-link:hover {
  color: var(--color-pessoas, #6c757d);
  border-bottom-color: rgba(108, 117, 125, 0.3);
  background-color: rgba(108, 117, 125, 0.05);
}

[data-bs-theme="dark"] #pessoasTabs .nav-link:hover {
  background-color: rgba(255, 255, 255, 0.05);
}

#pessoasTabs .nav-link.active {
  color: var(--color-pessoas, #6c757d);
  border-bottom-color: var(--color-pessoas, #6c757d);
  background-color: rgba(108, 117, 125, 0.08);
  font-weight: 600;
}

[data-bs-theme="dark"] #pessoasTabs .nav-link.active {
  background-color: rgba(255, 255, 255, 0.08);
}

@media (prefers-reduced-motion: reduce) {
  #pessoasTabs .nav-link { transition: none; }
}
