/* love8.me — language-switcher.css
   Single shared stylesheet for the [data-language-switcher] component.
   Mounts into per-language headers without overriding their grid layout
   (we replicate the .lang-switcher placement here so existing pages keep
   their visual position). All component internals use a `.ls-…` namespace
   to avoid colliding with legacy per-language CSS.

   ── Direction policy ──────────────────────────────────────────────
   The dropdown menu and every menu row are LATCHED to LTR flow so all
   languages line up in one tidy column. The RTL languages (Arabic,
   Persian, Urdu, Hebrew, …) get `dir="rtl"` on the inner <span class
   ="ls-label"> element ONLY — that lets the glyphs render in their
   natural reading direction without dragging the row to the right edge.
   We rely on `unicode-bidi: isolate` to keep the bidi context contained.
*/

[data-language-switcher] {
  position: relative;
  grid-column: 3;
  justify-self: end;
  min-width: max-content;
  font-family: inherit;
}

[data-language-switcher].is-busy .ls-button {
  opacity: 0.6;
  cursor: wait;
}

/* ── Toggle button ─────────────────────────────────────────────── */
.ls-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border: 1px solid rgba(150, 150, 150, 0.45);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.6);
  color: #1f2633;
  font: inherit;
  font-size: 13px;
  line-height: 1.2;
  cursor: pointer;
  min-height: 32px;
  white-space: nowrap;
  /* Button itself is LTR — caret stays on the right of the label even
     when the current language is Arabic. */
  direction: ltr;
}

.ls-button:hover,
.ls-button:focus-visible {
  border-color: #1f2633;
  color: #1f2633;
  outline: none;
}

.ls-button:focus-visible {
  box-shadow: 0 0 0 2px rgba(192, 38, 90, 0.35);
}

.ls-current {
  font-weight: 600;
  /* Isolate the current language label so an Arabic / Hebrew current
     value doesn't reorder the caret. */
  unicode-bidi: isolate;
}

.ls-caret {
  font-size: 10px;
  opacity: 0.7;
}

[data-language-switcher].is-open .ls-caret {
  transform: rotate(180deg);
}

/* ── Menu (scrollable) ─────────────────────────────────────────── */
.ls-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  inset-inline-end: 0;
  z-index: 50;
  margin: 0;
  padding: 6px;
  list-style: none;
  background: #fff;
  border: 1px solid rgba(150, 150, 150, 0.45);
  border-radius: 8px;
  box-shadow: 0 12px 28px rgba(16, 24, 40, 0.16);

  /* The whole list reads LTR regardless of host page or current language. */
  direction: ltr;
  text-align: left;

  /* scrollable when language list grows */
  max-height: min(420px, 60vh);
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;

  /* width is content-driven but capped so labels like "Bahasa Indonesia"
     don't blow up the dropdown on narrow screens */
  min-width: 200px;
  max-width: min(280px, calc(100vw - 24px));
}

[data-language-switcher].is-open .ls-menu {
  display: block;
}

.ls-menu li {
  margin: 0;
  list-style: none;
}

/* Each menu row is a flex container that ALWAYS starts at the left edge
   of the dropdown, regardless of the row's text direction. */
.ls-link {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  padding: 8px 10px;
  border-radius: 4px;
  color: #1f2633;
  font-size: 13px;
  line-height: 1.4;
  text-decoration: none;
  text-align: left;
  /* The row itself stays LTR; only the inner .ls-label can flip to rtl. */
  direction: ltr;
  /* Keep long labels (e.g. "Bahasa Indonesia") tidy. Soft-wrap rather
     than ellipsing — Thai / Hindi / Vietnamese composed glyphs don't
     truncate well with text-overflow. */
  white-space: normal;
  word-break: normal;
  overflow-wrap: anywhere;
}

.ls-link:hover,
.ls-link:focus-visible {
  background: #fdeaf1;
  color: #c0265a;
  outline: none;
}

.ls-menu li[aria-current="true"] .ls-link {
  background: #fdeaf1;
  color: #c0265a;
  font-weight: 600;
}

/* The label is the ONLY element inside .ls-link that may change reading
   direction. unicode-bidi: isolate stops the bidi algorithm from leaking
   the RTL context out into the surrounding row. */
.ls-label {
  display: inline-block;
  max-width: 100%;
  unicode-bidi: isolate;
}

.ls-label[dir="rtl"] {
  direction: rtl;
}

/* ── Mobile ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  [data-language-switcher] {
    grid-column: auto;
    justify-self: auto;
  }
  .ls-button {
    padding: 4px 8px;
    font-size: 12px;
    min-height: 30px;
  }
  .ls-menu {
    inset-inline-end: 0;
    inset-inline-start: auto;
    max-height: min(70vh, 480px);
  }
  .ls-link {
    padding: 10px 12px;
    font-size: 14px;
    min-height: 40px; /* finger-friendly */
    line-height: 1.4; /* breathe a little for Thai / Devanagari stacks */
  }
}

/* ── RTL host page (Arabic) ─────────────────────────────────────────
   When the page itself is RTL we flip the dropdown's anchor edge so it
   doesn't open off-screen, but the menu's INTERNAL flow stays LTR so
   every language row still aligns to the same starting column. */
html[dir="rtl"] [data-language-switcher] {
  justify-self: start;
}

html[dir="rtl"] .ls-menu {
  inset-inline-end: auto;
  inset-inline-start: 0;
}
