/* Apptonomia — locale picker (dropdown de siglas).
   Estilos del componente reutilizable. Cada app lo carga con UN solo
   <link rel="stylesheet" href="assets/css/locale-picker.css">.

   Diseño:
   - Botón compacto: sigla uppercase + chevron.
   - Panel flotante debajo del botón con sombra suave.
   - Opciones: sigla uppercase + nombre nativo, alineados.
   - Animación de 120ms al abrir/cerrar.
   - Hover y foco accesibles (WCAG AA).
   - Responsive: en móvil el panel ocupa el ancho disponible.

   Las apps pueden sobreescribir variables CSS (--lp-bg, --lp-border,
   --lp-text, --lp-accent) para adaptar el componente a su paleta
   de marca sin tener que tocar el CSS. */

#locale-picker {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: inherit;
  font-size: 14px;
  line-height: 1;
}

/* Botón trigger */
.locale-picker-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  min-height: 40px;
  background: var(--lp-bg, var(--color-surface, #FFFFFF));
  color: var(--lp-text, var(--color-text, #1A1A2E));
  border: 1px solid var(--lp-border, var(--color-border, #D8D2C8));
  border-radius: 999px;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.locale-picker-btn:hover {
  border-color: var(--lp-accent, var(--accent, #1B6CA8));
  background: var(--lp-bg-hover, var(--accent-soft, #E3EEF6));
}

.locale-picker-btn:focus-visible {
  outline: 3px solid var(--lp-accent, var(--accent, #1B6CA8));
  outline-offset: 2px;
}

.locale-picker-current {
  /* Sigla en uppercase, no crece */
  display: inline-block;
  min-width: 1.5em;
  text-align: center;
}

.locale-picker-chevron {
  display: inline-block;
  width: 10px;
  height: 6px;
  color: currentColor;
  opacity: 0.65;
  transition: transform 0.15s ease;
}

.locale-picker-btn[aria-expanded="true"] .locale-picker-chevron {
  transform: rotate(180deg);
}

/* Panel desplegable */
.locale-picker-panel {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 180px;
  margin: 0;
  padding: 6px 0;
  list-style: none;
  background: var(--lp-bg, var(--color-surface, #FFFFFF));
  border: 1px solid var(--lp-border, var(--color-border, #D8D2C8));
  border-radius: 12px;
  box-shadow: 0 6px 16px rgba(26, 26, 46, 0.12);
  z-index: 100;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0s linear 0.12s;
}

.locale-picker-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
  transition: opacity 0.12s ease, transform 0.12s ease, visibility 0s;
}

/* Opciones */
.locale-picker-panel li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  color: var(--lp-text, var(--color-text, #1A1A2E));
  transition: background-color 0.1s ease;
}

.locale-picker-panel li:hover {
  background: var(--lp-bg-hover, var(--accent-soft, #E3EEF6));
}

.locale-picker-panel li:focus-visible {
  outline: 2px solid var(--lp-accent, var(--accent, #1B6CA8));
  outline-offset: -2px;
}

.locale-picker-panel li[aria-selected="true"] {
  background: var(--lp-bg-active, var(--accent-soft, #E3EEF6));
  font-weight: 700;
}

.locale-picker-sigla {
  display: inline-block;
  min-width: 2em;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  color: var(--lp-accent, var(--accent, #1B6CA8));
  text-align: center;
}

.locale-picker-nombre {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
}

/* Móvil: panel a ancho completo */
@media (max-width: 480px) {
  .locale-picker-panel {
    right: auto;
    left: 0;
    min-width: 200px;
  }
}

/* Shared accessibility settings drawer. */
.locale-settings-trigger {
  display: inline-grid;
  place-items: center;
  width: 40px;
  min-height: 40px;
  padding: 0;
  border: 1px solid var(--lp-border, var(--color-border, #D8D2C8));
  border-radius: 999px;
  background: var(--lp-bg, var(--color-surface, #FFFFFF));
  color: var(--lp-text, var(--color-text, #1A1A2E));
  font: inherit;
  font-size: 18px;
  cursor: pointer;
}
.locale-settings-trigger:hover,
.locale-settings-trigger:focus-visible { border-color: var(--lp-accent, var(--accent, #1B6CA8)); }
.locale-settings-trigger:focus-visible,
.locale-settings-close:focus-visible,
.locale-settings-options button:focus-visible { outline: 3px solid var(--lp-accent, var(--accent, #1B6CA8)); outline-offset: 2px; }
.locale-settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 900;
  background: rgba(26, 26, 46, 0.38);
  opacity: 0;
  transition: opacity 0.16s ease;
}
.locale-settings-backdrop.is-open { opacity: 1; }
.locale-settings-drawer {
  position: fixed;
  z-index: 901;
  top: 0;
  right: 0;
  width: min(390px, 100vw);
  height: 100vh;
  overflow-y: auto;
  padding: 24px;
  box-sizing: border-box;
  background: var(--color-surface, var(--surface, #FFFFFF));
  color: var(--color-text, var(--ink, #1A1A2E));
  border-left: 2px solid var(--color-border, var(--line, #D8D2C8));
  box-shadow: -10px 0 28px rgba(26, 26, 46, 0.18);
  transform: translateX(100%);
  visibility: hidden;
  transition: transform 0.16s ease;
}
.locale-settings-drawer.is-open { transform: translateX(0); visibility: visible; }
.locale-settings-drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.locale-settings-drawer h2 { margin: 0; font-size: 1.35em; }
.locale-settings-close { min-width: 44px; min-height: 44px; border: 2px solid currentColor; border-radius: 10px; background: transparent; color: inherit; cursor: pointer; }
.locale-settings-drawer-body { display: grid; gap: 22px; margin-top: 26px; }
.locale-settings-row { display: grid; gap: 10px; font-weight: 700; }
.locale-settings-options { display: flex; flex-wrap: wrap; gap: 8px; }
.locale-settings-options button { min-height: 44px; padding: 8px 12px; border: 2px solid var(--color-border, var(--line, #D8D2C8)); border-radius: 10px; background: var(--color-surface, var(--surface, #FFFFFF)); color: inherit; cursor: pointer; }
.locale-settings-options button[aria-pressed="true"] { border-color: var(--lp-accent, var(--accent, #1B6CA8)); background: var(--accent-soft, #E3EEF6); }
.locale-settings-check { display: flex; align-items: center; justify-content: space-between; min-height: 44px; }
.locale-settings-check input { width: 24px; height: 24px; accent-color: var(--lp-accent, var(--accent, #1B6CA8)); }
.locale-settings-more { color: inherit; font-weight: 700; text-underline-offset: 3px; }
.locale-settings-help { margin: 0; color: var(--color-text-soft, var(--muted, #4A4A68)); font-size: 0.9em; }

html[data-a11y-text="small"] { --text-scale: 0.9; --escala-texto: 0.9; }
html[data-a11y-text="normal"] { --text-scale: 1; --escala-texto: 1; }
html[data-a11y-text="large"] { --text-scale: 1.15; --escala-texto: 1.15; }
html[data-a11y-contrast="high"] {
  --color-bg: #FFFFFF; --color-fondo: #FFFFFF; --paper: #FFFFFF;
  --color-surface: #FFFFFF; --color-superficie: #FFFFFF; --surface: #FFFFFF;
  --color-surface-2: #F2F2F2; --color-text: #000000; --color-texto: #000000; --ink: #000000;
  --color-text-soft: #202020; --color-texto-suave: #202020; --muted: #202020;
  --color-border: #000000; --color-borde: #000000; --line: #000000;
  --color-focus: #0044AA; --accent: #005A9C; --accent-soft: #E6F0FF;
}
html[data-a11y-contrast="high"] body { color: #000 !important; background: #FFF !important; }
html[data-a11y-contrast="high"] a { text-decoration: underline; }
html[data-a11y-contrast="high"] button,
html[data-a11y-contrast="high"] input,
html[data-a11y-contrast="high"] select,
html[data-a11y-contrast="high"] textarea { border-color: currentColor; }
@media (prefers-reduced-motion: reduce) {
  .locale-settings-backdrop, .locale-settings-drawer { transition: none; }
}
