/**
 * Header Widgets Styles
 * Estilos customizados para widgets no header
 * Suporta widgets de lista suspensa (GTranslate, etc) com estilo nativo
 * 
 * @package Velociraptor
 */

/* Container de Widgets do Header */
.header-widgets-area {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.header-widgets-container {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

/* Widget Individual */
.header-widget {
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0;
  line-height: 1;
}

/* Estilização de Dropdowns (GTranslate, etc) */
.header-widget select,
.header-widget .gtranslate_wrapper select,
.header-widget .gtranslate_wrapper .gt_container select,
.header-widget .gt-container select {
  background-color: var(--background);
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
  color: var(--foreground);
  cursor: pointer;
  transition: all 0.2s ease;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 1rem;
  min-width: 120px;
  height: 2.25rem;
}

.header-widget select:hover,
.header-widget .gtranslate_wrapper select:hover,
.header-widget .gt-container select:hover {
  border-color: var(--primary);
  background-color: var(--accent);
}

.header-widget select:focus,
.header-widget .gtranslate_wrapper select:focus,
.header-widget .gt-container select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px color-mix(in oklch, var(--primary) 20%, transparent);
}

/* GTranslate específico - múltiplas variações */
.header-widget .gtranslate_wrapper,
.header-widget .gt-container,
.header-widget .gtranslate_wrapper .gt_container {
  display: flex;
  align-items: center;
  margin: 0;
  padding: 0;
}

.header-widget .gtranslate_wrapper select,
.header-widget .gt-container select {
  margin: 0;
}

/* GTranslate com flags/icons */
.header-widget .gtranslate_wrapper .gt_flag,
.header-widget .gt-container .gt_flag {
  margin-right: 0.5rem;
}

/* Outros widgets (texto, links, etc) */
.header-widget .textwidget,
.header-widget .widget_text {
  margin: 0;
  padding: 0;
}

.header-widget .textwidget p,
.header-widget .widget_text p {
  margin: 0;
  line-height: 1.5;
}

.header-widget a {
  color: var(--foreground);
  text-decoration: none;
  transition: color 0.2s;
  display: inline-flex;
  align-items: center;
}

.header-widget a:hover {
  color: var(--primary);
}

/* Shortcode no header — reserva slot fixo antes do GTranslate/async (evita salto do menu) */
.header-shortcode {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
  box-sizing: border-box;
  /* Alinha com .custom-lang-button (2.5rem) + margem para ícone + código (ex.: pt, en) */
  min-height: 2.5rem;
  min-width: 4rem;
}

.header-shortcode > * {
  margin: 0;
}

/* Contêineres do GTranslate: mantêm altura/largura mínimas mesmo vazios ou antes do .loaded */
.header-shortcode .gtranslate_wrapper,
.header-shortcode [class*="gt_container"] {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  min-height: 2.5rem;
  min-width: 2.5rem;
  box-sizing: border-box;
}

/* Garantir que widgets não quebrem layout */
.header-widgets-area * {
  box-sizing: border-box;
}

/* ============================================
   Custom Language Selector (Dropdown Estilizado)
   ============================================ */

/* Ocultar select original do GTranslate até ser transformado */
/* Isso previne FOUT (Flash of Unstyled Text) */
.gtranslate_wrapper:not(:has(.custom-language-selector)) select.gt_selector,
.gtranslate_wrapper:not(:has(.custom-language-selector)) .gt_selector,
.gt_container:not(:has(.custom-language-selector)) select.gt_selector,
[id*="gtranslate"]:not(:has(.custom-language-selector)) select,
.custom-language-selector:not(.loaded) ~ select {
  opacity: 0;
  visibility: hidden;
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border-width: 0;
  padding: 0;
  margin: 0;
}

/* Versão mais ampla para navegadores que não suportam :has() */
/* Ocultar selects do GTranslate até serem transformados */
.gtranslate_wrapper select.gt_selector:not([data-transformed="true"]),
.gt_container select.gt_selector:not([data-transformed="true"]),
[id*="gtranslate"] select:not([data-transformed="true"]),
select.gt_selector:not([data-transformed="true"]):not([data-customized="true"]),
select.gt_selector.goog-te-combo:not([data-transformed="true"]) {
  opacity: 0 !important;
  visibility: hidden !important;
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border-width: 0 !important;
  padding: 0 !important;
  margin: 0 !important;
}

/* Garantir que o container customizado apareça imediatamente */
.custom-language-selector.loaded {
  opacity: 1 !important;
  visibility: visible !important;
  display: inline-flex !important;
}

.custom-language-selector {
  position: relative;
  display: inline-flex;
  opacity: 1;
  visibility: visible;
  transition: opacity 0.2s ease;
  min-width: 2.5rem;
  height: 2.5rem;
  vertical-align: middle;
}

.custom-lang-button-wrapper {
  position: relative;
  display: inline-flex;
  width: auto;
  min-width: 2.5rem;
  height: 2.5rem;
  vertical-align: middle;
}

/* Botão do Seletor — ghost + foco estilo shadcn (outline/ring), ícone herda currentColor */
.custom-lang-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  height: 2.5rem;
  min-height: 2.5rem;
  max-height: 2.5rem;
  width: auto;
  min-width: 2.5rem;
  padding: 0 0.5rem;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  text-transform: uppercase;
  color: var(--foreground);
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  border-radius: calc(var(--radius, 0.375rem));
  white-space: nowrap;
  box-sizing: border-box;
  vertical-align: middle;
  outline: none;
}

.custom-lang-button:hover {
  background-color: var(--muted);
  color: var(--foreground);
}

.custom-lang-button:focus-visible {
  background-color: var(--muted);
  color: var(--foreground);
  box-shadow: 0 0 0 2px var(--ring, #3b82f6), 0 0 0 4px color-mix(in oklab, var(--ring, #3b82f6) 22%, transparent);
}

button.vlr-header-search-btn:hover,
button.vlr-header-search-btn:focus {
  background-color: var(--muted);
  color: var(--foreground);
}

.custom-lang-button svg {
  width: 20px !important;
  height: 20px !important;
  min-width: 20px !important;
  min-height: 20px !important;
  max-width: 20px !important;
  max-height: 20px !important;
  display: inline-block !important;
  vertical-align: middle;
  color: inherit;
  stroke: currentColor;
  flex-shrink: 0;
  flex-grow: 0;
  box-sizing: border-box;
}

.custom-lang-code {
  font-size: 0.875rem;
  font-weight: 500;
  letter-spacing: 0.025em;
  display: inline-block;
  line-height: 1;
  vertical-align: middle;
  min-width: 2ch;
  text-align: left;
}

/* Dropdown */
.custom-lang-dropdown {
  position: absolute;
  right: 0;
  top: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #ffffff !important;
  border: 1px solid var(--border);
  border-radius: 0.375rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  z-index: 50;
  max-height: 0;
  opacity: 0;
  visibility: hidden;
  transition: max-height 0.3s ease, opacity 0.2s ease, visibility 0.2s ease;
  margin-top: 0.25rem;
  min-width: 14rem;
}

.custom-lang-dropdown.open {
  max-height: 700px;
  opacity: 1;
  visibility: visible;
}

.custom-lang-dropdown-inner {
  padding-top: 1.5rem;
  max-height: 700px;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: #ffffff !important;
}

/* Opções do Dropdown */
.custom-lang-option {
  display: inline-flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem 1.5rem;
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1;
  color: var(--foreground);
  text-decoration: none;
  outline: 0;
  transition: background-color 0.15s ease;
  position: relative;
  background-color: transparent;
}

.custom-lang-option:hover,
.custom-lang-option:focus {
  background-color: #f4f4f4;
}

.custom-lang-option.active {
  background-color: #f4f4f4;
  font-weight: 700;
}

.custom-lang-option.active svg {
  margin-left: auto;
  margin-right: 2.5rem;
  width: 24px;
  height: 24px;
  color: var(--foreground);
  flex-shrink: 0;
}

/* Código do idioma no menu (ex: pt-br, en, de) */
.custom-lang-option-code {
  font-size: 0.875rem;
  font-weight: 400;
  text-transform: uppercase;
  color: #676767;
  letter-spacing: 0.025em;
  margin-left: 0.5rem;
}

/* Scrollbar customizada para o dropdown */
.custom-lang-dropdown-inner::-webkit-scrollbar {
  width: 6px;
}

.custom-lang-dropdown-inner::-webkit-scrollbar-track {
  background: transparent;
}

.custom-lang-dropdown-inner::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.custom-lang-dropdown-inner::-webkit-scrollbar-thumb:hover {
  background: var(--muted-foreground);
}

/* Responsive */
@media (max-width: 768px) {
  /* No mobile o tema esconde .custom-lang-code — basta largura do botão-ícone */
  .header-shortcode {
    min-width: 2.75rem;
    min-height: 2.25rem;
  }

  .header-shortcode .gtranslate_wrapper,
  .header-shortcode [class*="gt_container"] {
    min-height: 2.25rem;
    min-width: 2.25rem;
  }

  .header-widgets-area {
    gap: 0.5rem;
  }
  
  .header-widget select,
  .header-widget .gtranslate_wrapper select,
  .header-widget .gt-container select {
    padding: 0.375rem 1.75rem 0.375rem 0.5rem;
    font-size: 0.8125rem;
    min-width: 100px;
    height: 2rem;
  }

  .custom-lang-button {
    height: 2.25rem;
    padding: 0 0.375rem;
  }

  .custom-lang-dropdown {
    min-width: 16rem;
    right: 0;
  }

  .custom-lang-code {
    display: none;
  }
}
