/* ------------------------------------------------
 * Language Selector Styles
 * Author: Rodrigo Sánchez
 * Website: https://sanchezdev.com
 * ------------------------------------------------ */

/* Language Selector Container */
.language-selector {
  position: relative;
  display: inline-block;
  margin-right: 1rem;
  z-index: 1000;
}

/* Language Switcher Button */
.language-switcher {
  width: 4.4rem;
  height: 4.4rem;
  border-radius: 2rem;
  color: var(--t-muted);
  font-size: 1.6rem;
  transition: all 0.3s ease-in-out;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media only screen and (min-width: 992px) {
  .language-switcher {
    width: 5rem;
    height: 5rem;
    border-radius: var(--_radius-m);
    backdrop-filter: blur(10px);
  }
  
  .no-touch .language-switcher:hover {
    color: var(--t-bright);
    transform: translateY(-1px);
  }
}

@media only screen and (min-width: 1600px) {
  .language-switcher {
    width: 6rem;
    height: 6rem;
  }
}

/* Flag Icons */
.flag-icon {
  width: 2.4rem;
  height: 1.8rem;
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  border-radius: 0.3rem;
  display: inline-block;
  transition: transform 0.3s ease-in-out;
}

@media only screen and (min-width: 992px) {
  .flag-icon {
    width: 2.8rem;
    height: 2.1rem;
  }
}

@media only screen and (min-width: 1600px) {
  .flag-icon {
    width: 3.2rem;
    height: 2.4rem;
  }
}

/* Flag Specific Styles */
.flag-gb {
  background-image: url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 30"><defs><clipPath id="s"><path d="m30,15 h30 v15 z v15 h-30 z h-30 v-15 z v-15 h30 z"/></clipPath></defs><path d="M0,0 v30 h60 v-30 z" fill="%23012169"/><path d="m0,0 L60,30 M60,0 L0,30" stroke="%23fff" stroke-width="6"/><path d="m0,0 L60,30 M60,0 L0,30" stroke="%23C8102E" stroke-width="4" clip-path="url(%23s)"/><path d="M30,0 v30 M0,15 h60" stroke="%23fff" stroke-width="10"/><path d="M30,0 v30 M0,15 h60" stroke="%23C8102E" stroke-width="6"/></svg>');
}

.flag-cl {
  background: linear-gradient(to bottom, white 0%, white 50%, #D52B1E 50%, #D52B1E 100%);
  position: relative;
  overflow: hidden;
}

.flag-cl::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 37.5%;
  height: 50%;
  background: #0039A6;
}

.flag-cl::after {
  content: '★';
  position: absolute;
  top: 25%;
  left: 18.75%;
  transform: translate(-50%, -50%);
  color: white;
  font-size: 0.8rem;
  line-height: 1;
  font-weight: bold;
  text-shadow: 0 0 1px rgba(0,0,0,0.3);
}

@media only screen and (min-width: 992px) {
  .flag-cl::after {
    font-size: 1rem;
  }
}

@media only screen and (min-width: 1600px) {
  .flag-cl::after {
    font-size: 1.2rem;
  }
}

/* Language Dropdown */
/* Language Dropdown */
.language-dropdown {
  position: absolute;
  top: calc(100% + 0.8rem);
  right: 0;
  min-width: 16rem;
  width: max-content;
  background: rgba(30, 30, 30, 0.95);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--_radius-m);
  backdrop-filter: blur(10px);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-1rem);
  transition: all 0.3s ease-in-out;
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.3);
  z-index: 9999; /* Z-index muy alto para estar por encima de todo */
  pointer-events: none; /* No clickeable cuando está oculto */
}

.language-dropdown.show {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  pointer-events: auto; /* Clickeable cuando está visible */
}

/* Language Options */
.language-option {
  display: flex;
  align-items: center;
  gap: 1rem;
  width: 100%;
  padding: 1.2rem 1.6rem;
  background: transparent;
  border: none;
  border-radius: var(--_radius-s);
  color: var(--t-muted);
  font-size: 1.4rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease-in-out;
  text-align: left;
  white-space: nowrap;
  min-height: 4.8rem;
}

.language-option:hover {
  background: var(--bg-hover, rgba(255, 255, 255, 0.05));
  color: var(--t-bright);
  transform: translateX(0.5rem);
}

.language-option .flag-icon {
  width: 2.4rem;
  height: 1.8rem;
  flex-shrink: 0;
}

.language-option .lang-text {
  flex: 1;
}

/* Active Language Indication */
.language-option[data-lang] {
  position: relative;
}

/* Responsive Adjustments */
@media only screen and (max-width: 767px) {
  .language-selector {
    margin-right: 0.5rem;
  }
  
  .language-switcher {
    touch-action: manipulation; /* Mejora la respuesta táctil */
    -webkit-tap-highlight-color: transparent; /* Elimina el highlight azul en iOS */
  }
  
  /* En móvil, despliegar hacia arriba */
  .language-dropdown {
    top: auto;
    bottom: calc(100% + 1rem); /* Despliega hacia arriba */
    right: -1rem;
    min-width: 15rem;
    max-width: 20rem;
    box-shadow: 0 -0.5rem 2rem rgba(0, 0, 0, 0.4); /* Sombra hacia arriba */
    transform: translateY(1rem); /* Inicial hacia abajo para animación */
    border-radius: 1rem;
    background: rgba(20, 20, 20, 0.98); /* Fondo más sólido en móvil */
    backdrop-filter: blur(20px);
    z-index: 9999; /* Z-index muy alto para móvil */
  }
  
  .language-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0); /* Final en posición */
    pointer-events: auto; /* Asegurar que sea clickeable */
  }
  
  .language-option {
    padding: 1.2rem 1.2rem;
    font-size: 1.4rem;
    min-height: 5rem;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  }
  
  .language-option:last-child {
    border-bottom: none;
  }
  
  .language-option:active {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(0.98);
  }
}

/* Animation for flag change */
.language-switcher .flag-icon {
  animation: flagChange 0.4s ease-in-out;
}

@keyframes flagChange {
  0% { transform: scale(1) rotateY(0deg); }
  50% { transform: scale(0.8) rotateY(90deg); }
  100% { transform: scale(1) rotateY(0deg); }
}

/* Tabletas en landscape con menú inferior */
@media only screen and (max-width: 1024px) and (max-height: 768px) and (orientation: landscape) {
  .language-dropdown {
    top: auto;
    bottom: calc(100% + 1rem);
    transform: translateY(1rem);
    box-shadow: 0 -0.5rem 2rem rgba(0, 0, 0, 0.4);
  }
  
  .language-dropdown.show {
    transform: translateY(0);
  }
}

/* Dropdown direction control via JavaScript */
.language-dropdown.dropdown-up {
  top: auto !important;
  bottom: calc(100% + 1rem) !important;
  transform: translateY(1rem);
  box-shadow: 0 -0.5rem 2rem rgba(0, 0, 0, 0.4) !important;
}

.language-dropdown.dropdown-up.show {
  transform: translateY(0) !important;
}

/* Dark/Light mode adjustments */
[data-theme="light"] .language-dropdown {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(0, 0, 0, 0.1);
  box-shadow: 0 1rem 3rem rgba(0, 0, 0, 0.1);
}

[data-theme="light"] .language-option:hover {
  background: rgba(0, 0, 0, 0.05);
}

/* Focus states for accessibility */
.language-switcher:focus-visible,
.language-option:focus-visible {
  outline: 2px solid var(--accent-color, #6366f1);
  outline-offset: 2px;
}

/* Loading state */
.language-selector.loading .language-switcher {
  pointer-events: none;
  opacity: 0.6;
}

.language-selector.loading .flag-icon {
  animation: pulse 1.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}
