/* ==========================================================================
   M27-04 · Luxury Aligned Flag Language Switcher
   Mounted on the live contract: .hd-lang[data-lang-panel] + button[data-lang]
   3-column row = [20px inline SVG flag] [autonym] [right-aligned code]
   ========================================================================== */

/* Panel: keep rescue.css positioning/z-index; restyle the surface only. */
.hd-lang[data-lang-panel].fy-lang-popover {
  display: block !important;
  width: 396px !important;
  min-width: 0 !important;
  max-width: calc(100vw - 32px) !important;
  padding: 14px !important;
  border: 1px solid rgba(20, 19, 17, .11) !important;
  border-radius: 16px !important;
  background: #fbfaf7 !important;
  box-shadow: 0 20px 48px rgba(20, 19, 17, .14) !important;
  box-sizing: border-box;
}

/* 11 items / 2 columns. */
.fy-lang-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

/* Strict 3-column alignment on every row; !important beats legacy flex rules. */
.hd-lang[data-lang-panel] a.fy-lang-item {
  display: grid !important;
  grid-template-columns: 20px minmax(0, 1fr) auto !important;
  align-items: center !important;
  justify-content: stretch !important;
  gap: 9px !important;
  width: 100%;
  min-height: 38px;
  height: 38px;
  padding: 0 10px !important;
  border: 1px solid transparent;
  border-radius: 9px;
  background: transparent;
  color: #1c1a17;
  font-family: inherit;
  font-size: 13px;
  font-weight: 400;
  letter-spacing: 0;
  text-align: left;
  text-decoration: none;
  text-transform: none;
  cursor: pointer;
  direction: ltr; /* flag always left, code always right, even on RTL pages */
  box-sizing: border-box;
  transition: background-color .14s ease, border-color .14s ease, color .14s ease;
}

.hd-lang[data-lang-panel] a.fy-lang-item:hover {
  background: #f2ede3;
  border-color: rgba(20, 19, 17, .07);
  color: #1c1a17;
}

/* Active = deep-forest tint + forest code pill + tick. */
.hd-lang[data-lang-panel] a.fy-lang-item.is-active,
.hd-lang[data-lang-panel] a.fy-lang-item[aria-current="true"] {
  background: #eef5f1 !important;
  border-color: rgba(27, 77, 62, .28) !important;
  color: #1b4d3e !important;
  font-weight: 600;
}

/* Legacy gold dot from nav-v2.css must not collide with the code pill. */
.hd-lang[data-lang-panel] a.fy-lang-item[aria-current="true"]::after {
  display: none !important;
}

/* Crisp inline SVG flags: never Emoji (Windows splits them into US/JP letters). */
.fy-flag {
  width: 20px;
  height: 14px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(20, 19, 17, .14);
  display: block;
  flex-shrink: 0;
  overflow: hidden;
}

.fy-lang-name {
  font-size: 13px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.hd-lang[data-lang-panel] button[data-lang="ar"] .fy-lang-name { direction: rtl; }

.fy-lang-code {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .04em;
  line-height: 1;
  color: #6b655c;
  background: rgba(20, 19, 17, .05);
  padding: 4px 6px;
  border-radius: 5px;
  min-width: 26px;
  text-align: center;
  box-sizing: border-box;
  justify-self: end;
  font-family: inherit;
  text-transform: none;
}

.hd-lang[data-lang-panel] a.fy-lang-item.is-active .fy-lang-code,
.hd-lang[data-lang-panel] a.fy-lang-item[aria-current="true"] .fy-lang-code {
  background: #1b4d3e;
  color: #ffffff;
}

.fy-lang-code::before { content: ""; }
.hd-lang[data-lang-panel] a.fy-lang-item.is-active .fy-lang-code::before,
.hd-lang[data-lang-panel] a.fy-lang-item[aria-current="true"] .fy-lang-code::before {
  content: "\2713"; /* ✓ — visible active tick */
  margin-right: 3px;
  font-size: 9px;
}

/* Header trigger: swap the globe for the current language's small flag. */
.hd__lang.fy-header-lang-trigger { gap: 6px; }

.hd__lang.fy-header-lang-trigger .fy-flag,
.fy-header-lang-trigger .fy-flag {
  width: 18px !important;
  height: 12px !important;
  margin-right: 0;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(20, 19, 17, .14);
  display: block;
  flex: 0 0 18px;
  overflow: hidden;
  font-size: 0; /* legacy svg { width:15px } cannot win on mobile */
}

@media (max-width: 767px) {
  .fy-lang-grid { gap: 4px; }
  .fy-lang-popover { width: min(396px, calc(100vw - 24px)) !important; }
}
