/*
 * Seletores no estilo do shadcn/ui (js/seletores.js): Select/Combobox, calendário e hora.
 * Cores do design system (css/style.css); fallback para páginas sem ele.
 */
:root {
  --seletor-primaria: var(--color-primary, #c6254e);
  --seletor-primaria-rgb: 198, 37, 78;
  --seletor-texto: var(--color-black, #2c2c2c);
  --seletor-texto-suave: #6b7280;
  --seletor-borda: #e5e7eb;
  --seletor-fundo: #ffffff;
  --seletor-destaque: rgba(var(--seletor-primaria-rgb), 0.08);
  --seletor-destaque-forte: rgba(var(--seletor-primaria-rgb), 0.14);
  --seletor-anel: 0 0 0 2px #ffffff, 0 0 0 4px rgba(var(--seletor-primaria-rgb), 0.55);
  --seletor-sombra: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
}

/* O original continua no DOM (valor, eventos, validação), fora da vista */
.seletor-nativo {
  position: absolute !important;
  /* --seletor-*: posição do componente, gravada no evento "invalid" (balão de validação) */
  left: var(--seletor-x, auto) !important;
  top: var(--seletor-y, auto) !important;
  width: var(--seletor-w, 1px) !important;
  height: var(--seletor-h, 1px) !important;
  min-width: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  opacity: 0 !important;
  overflow: hidden !important;
  clip-path: inset(50%) !important;
  pointer-events: none !important;
}

/* ------------------------------------------------------------- gatilho do Select */

.seletor-gatilho {
  display: block;
  width: 100%;
  min-width: 0;
  text-align: start;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}

.seletor-gatilho:disabled {
  cursor: not-allowed;
}

.seletor-gatilho .seletor-valor {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
}

.seletor-gatilho.seletor-placeholder .seletor-valor {
  color: var(--seletor-texto-suave);
}

/* Validação do Bootstrap: o estado vem do original, que é o irmão anterior */
.was-validated .seletor-nativo:invalid + .seletor-gatilho {
  --bs-form-select-bg-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
  border-color: var(--bs-form-invalid-border-color);
  padding-right: 4.125rem;
  background-position: right 0.75rem center, center right 2.25rem;
  background-size: 16px 12px, calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.was-validated .seletor-nativo:valid + .seletor-gatilho {
  --bs-form-select-bg-icon: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%23198754' d='M2.3 6.73.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1'/%3e%3c/svg%3e");
  border-color: var(--bs-form-valid-border-color);
  padding-right: 4.125rem;
  background-position: right 0.75rem center, center right 2.25rem;
  background-size: 16px 12px, calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

.was-validated .seletor-nativo:invalid + .seletor-gatilho:focus {
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-danger-rgb), 0.25);
}

.was-validated .seletor-nativo:valid + .seletor-gatilho:focus {
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-success-rgb), 0.25);
}

/* ------------------------------------------------------------- campo de data/hora */

.seletor-campo {
  position: relative;
  min-width: 0;
}

/* O ícone do campo fica no lugar do ícone de validação do Bootstrap. O campo de texto não é
   validado por si (o estado vem do original, abaixo): sem ícone próprio */
.seletor-campo > .seletor-texto {
  padding-right: 2.25rem !important;
  background-image: none !important;
  font-variant-numeric: tabular-nums;
}

.was-validated .seletor-nativo:invalid + .seletor-campo > .seletor-texto {
  border-color: var(--bs-form-invalid-border-color);
}

.was-validated .seletor-nativo:valid + .seletor-campo > .seletor-texto {
  border-color: var(--bs-form-valid-border-color);
}

.was-validated .seletor-nativo:valid + .seletor-campo > .seletor-texto:focus {
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-success-rgb), 0.25);
}

.was-validated .seletor-nativo:invalid + .seletor-campo > .seletor-texto:focus,
.seletor-campo > .seletor-texto.is-invalid:focus {
  box-shadow: 0 0 0 0.25rem rgba(var(--bs-danger-rgb), 0.25);
}

.seletor-icone {
  position: absolute;
  top: 50%;
  right: 0.375rem;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--seletor-texto-suave);
  cursor: pointer;
}

.seletor-icone svg {
  width: 1rem;
  height: 1rem;
}

.seletor-icone:hover:not(:disabled),
.seletor-aberto > .seletor-icone {
  color: var(--seletor-primaria);
  background: var(--seletor-destaque);
}

.seletor-icone:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.form-control-sm + .seletor-icone {
  width: 1.5rem;
  height: 1.5rem;
}

/* ------------------------------------------------------------- popover */

.seletor-popover {
  position: fixed;
  z-index: 1070;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  max-width: calc(100vw - 16px);
  overflow: auto;
  color: var(--seletor-texto);
  background: var(--seletor-fundo);
  border: 1px solid var(--seletor-borda);
  border-radius: var(--radius-sm, 6px);
  box-shadow: var(--seletor-sombra);
  font-family: var(--font-primary, inherit);
  font-size: 14px;
  line-height: 1.4;
  text-align: start;
  -webkit-tap-highlight-color: transparent;
}

.seletor-popover.seletor-entrando {
  animation: seletor-entrar 0.12s ease-out;
}

@keyframes seletor-entrar {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(-2px);
  }
}

.seletor-popover[data-lado="top"].seletor-entrando {
  animation-name: seletor-entrar-cima;
}

@keyframes seletor-entrar-cima {
  from {
    opacity: 0;
    transform: scale(0.97) translateY(2px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .seletor-popover.seletor-entrando {
    animation: none;
  }
}

.seletor-popover button {
  font-family: inherit;
}

.seletor-popover :focus {
  outline: none;
}

.seletor-popover :focus-visible {
  box-shadow: var(--seletor-anel);
}

/* ------------------------------------------------------------- lista (Select/Combobox) */

.seletor-popover-lista {
  overflow: hidden;
  width: max-content;
  max-width: min(calc(100vw - 16px), 32rem);
}

.seletor-busca {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 0 0 auto;
  padding: 0 0.75rem;
  border-bottom: 1px solid var(--seletor-borda);
  color: var(--seletor-texto-suave);
}

.seletor-busca[hidden] {
  display: none;
}

.seletor-busca svg {
  flex: 0 0 auto;
  width: 1rem;
  height: 1rem;
  opacity: 0.6;
}

.seletor-busca-campo {
  flex: 1 1 auto;
  min-width: 0;
  height: 2.5rem;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--seletor-texto);
  font: inherit;
  /* 16px evita o zoom automático do iOS ao focar */
  font-size: max(14px, 1em);
}

@media (pointer: coarse) {
  .seletor-busca-campo {
    font-size: 16px;
  }
}

.seletor-busca-campo::placeholder {
  color: var(--seletor-texto-suave);
}

.seletor-popover .seletor-busca-campo:focus-visible {
  box-shadow: none;
}

.seletor-lista {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  max-height: 18rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.25rem;
}

.seletor-popover .seletor-lista:focus-visible {
  box-shadow: none;
}

.seletor-grupo-rotulo {
  padding: 0.375rem 0.5rem;
  color: var(--seletor-texto-suave);
  font-size: 12px;
  font-weight: 600;
}

.seletor-opcao {
  position: relative;
  display: flex;
  align-items: center;
  padding: 0.375rem 2rem 0.375rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  overflow-wrap: anywhere;
}

.seletor-opcao.seletor-ativo {
  background: var(--seletor-destaque);
}

.seletor-lista:focus-visible .seletor-opcao.seletor-ativo,
.seletor-busca:focus-within ~ .seletor-lista .seletor-opcao.seletor-ativo {
  background: var(--seletor-destaque-forte);
}

.seletor-opcao[aria-selected="true"] {
  font-weight: 600;
}

.seletor-opcao[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

.seletor-check {
  position: absolute;
  right: 0.5rem;
  display: none;
  color: var(--seletor-primaria);
}

.seletor-check svg {
  width: 1rem;
  height: 1rem;
}

.seletor-opcao[aria-selected="true"] .seletor-check {
  display: inline-flex;
}

/* "Criar «texto»" no fim da lista (data-seletor-criar) */
.seletor-opcao-criar {
  gap: 0.375rem;
  margin-top: 0.125rem;
  color: var(--seletor-primaria);
  font-weight: 600;
}

.seletor-opcao-icone {
  display: inline-flex;
  flex: none;
}

.seletor-opcao-icone svg {
  width: 1rem;
  height: 1rem;
}

.seletor-sem-resultado,
.seletor-aviso {
  padding: 1.25rem 0.5rem;
  color: var(--seletor-texto-suave);
  text-align: center;
}

.seletor-aviso {
  padding: 0.375rem 0.5rem;
  border-top: 1px solid var(--seletor-borda);
  font-size: 12px;
}

.seletor-sem-resultado[hidden],
.seletor-aviso[hidden] {
  display: none;
}

/* ------------------------------------------------------------- calendário */

.seletor-popover-calendario {
  padding: 0.75rem;
  width: max-content;
}

.seletor-cal-cabecalho {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
}

.seletor-cal-nav {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border: 1px solid var(--seletor-borda);
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--seletor-texto);
  opacity: 0.6;
}

.seletor-cal-nav:hover {
  opacity: 1;
  background: var(--seletor-destaque);
}

.seletor-cal-nav svg {
  width: 1rem;
  height: 1rem;
}

.seletor-cal-titulo {
  flex: 1 1 auto;
  padding: 0.25rem 0.5rem;
  border: 0;
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--seletor-texto);
  font-size: 14px;
  font-weight: 600;
}

.seletor-cal-titulo::first-letter {
  text-transform: uppercase;
}

.seletor-cal-titulo:hover {
  background: var(--seletor-destaque);
}

.seletor-cal-grade {
  border-collapse: collapse;
  margin: 0;
}

.seletor-cal-grade th {
  width: 2.25rem;
  padding: 0 0 0.25rem;
  color: var(--seletor-texto-suave);
  font-size: 12px;
  font-weight: 400;
  text-align: center;
  text-transform: capitalize;
}

.seletor-cal-grade td {
  padding: 1px 0;
  text-align: center;
}

.seletor-dia,
.seletor-mes {
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border: 0;
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--seletor-texto);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.seletor-dia:hover,
.seletor-mes:hover {
  background: var(--seletor-destaque);
}

.seletor-dia.seletor-hoje,
.seletor-mes.seletor-hoje {
  background: var(--seletor-destaque-forte);
  font-weight: 600;
}

.seletor-dia.seletor-outro-mes {
  color: var(--seletor-texto-suave);
  opacity: 0.6;
}

.seletor-dia.seletor-selecionado,
.seletor-mes.seletor-selecionado,
.seletor-dia.seletor-selecionado:hover,
.seletor-mes.seletor-selecionado:hover {
  background: var(--seletor-primaria);
  color: #ffffff;
  opacity: 1;
}

.seletor-dia[aria-disabled="true"],
.seletor-mes[aria-disabled="true"] {
  opacity: 0.35;
  text-decoration: line-through;
  cursor: not-allowed;
}

.seletor-dia[aria-disabled="true"]:hover,
.seletor-mes[aria-disabled="true"]:hover {
  background: transparent;
}

.seletor-cal-meses {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.375rem;
  width: 15.75rem;
}

.seletor-mes {
  width: 100%;
  text-transform: capitalize;
}

.seletor-cal-rodape {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--seletor-borda);
}

.seletor-cal-acao {
  padding: 0.25rem 0.625rem;
  border: 1px solid var(--seletor-borda);
  border-radius: var(--radius-sm, 6px);
  background: transparent;
  color: var(--seletor-texto);
  font-size: 13px;
}

.seletor-cal-acao:hover:not(:disabled) {
  background: var(--seletor-destaque);
  border-color: rgba(var(--seletor-primaria-rgb), 0.3);
}

.seletor-cal-acao:disabled {
  opacity: 0.5;
}

/* ------------------------------------------------------------- hora */

.seletor-popover-hora {
  padding: 0.25rem;
}

.seletor-hora-colunas {
  display: flex;
  gap: 0.25rem;
  min-height: 0;
}

.seletor-hora-coluna {
  width: 3.5rem;
  max-height: 14rem;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 0.125rem;
  border-radius: 4px;
  scrollbar-width: thin;
}

.seletor-hora-coluna + .seletor-hora-coluna {
  border-left: 1px solid var(--seletor-borda);
  padding-left: 0.25rem;
}

.seletor-popover .seletor-hora-coluna:focus-visible {
  box-shadow: inset 0 0 0 2px rgba(var(--seletor-primaria-rgb), 0.35);
}

.seletor-hora-item {
  justify-content: center;
  padding: 0.375rem 0;
  font-variant-numeric: tabular-nums;
}

.seletor-hora-item[aria-selected="true"],
.seletor-hora-item[aria-selected="true"].seletor-ativo {
  background: var(--seletor-primaria);
  color: #ffffff;
}

.seletor-hora-coluna:focus-visible .seletor-hora-item.seletor-ativo:not([aria-selected="true"]) {
  background: var(--seletor-destaque-forte);
}
