/* 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;
}

/* Native details keeps the static navigation usable before/without JS.
   Hide the browser marker; the existing caret and dimensions stay unchanged. */
summary.ls-button {
  list-style: none;
}

summary.ls-button::-webkit-details-marker {
  display: none;
}

.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: 400;
  /* Isolate the current language label so an Arabic / Hebrew current
     value doesn't reorder the caret. */
  unicode-bidi: isolate;
}

.ls-caret {
  font-size: 22px;
  line-height: 0.8;
  opacity: 0.7;
}

[data-language-switcher].is-open .ls-caret,
details[data-language-switcher][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,
details[data-language-switcher][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) {
  /* On narrow screens the switcher gives way first, so the brand subtitle
     next to it keeps one line: the mount may shrink down to 72px, and a long
     current-language label such as "English (United Kingdom)" is ellipsized
     instead of pushing the brand onto extra lines. The menu still shows
     every label in full. The flex-shrink is deliberately huge: weighted
     shrinking then leaves the brand (flex-shrink: 1) a share far below the
     1/64px layout unit, so a subtitle that fits is never wrapped by a
     sub-pixel loss (1000 still cost the brand 3/64px). Once the switcher is
     frozen at its minimum, the brand takes the rest of the squeeze. */
  [data-language-switcher] {
    grid-column: auto;
    justify-self: auto;
    min-width: 72px;
    flex-shrink: 1000000;
  }
  .ls-button {
    padding: 4px 8px;
    font-size: 12px;
    min-height: 30px;
    max-width: 100%;
  }
  .ls-current {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .ls-caret {
    flex-shrink: 0;
  }
  /* Keep some air between the brand and the switcher once the row is tight.
     A gap on the shared row instead of a margin on the mount, because the
     RTL headers that reverse the row would put a logical margin on the
     wrong side. Templates that set their own gap keep it (higher
     specificity). */
  :has(> [data-language-switcher]) {
    column-gap: 8px;
  }
  .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;
}
.site-home-nav {
  box-sizing: border-box;
  width: min(1160px, calc(100% - 32px));
  margin: 12px auto;
  display: flex;
  justify-content: flex-start;
}

.site-home-nav a {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  background: #fff;
  color: #c2346e;
  font-weight: 700;
  text-decoration: none;
}

.site-home-nav a:hover,
.site-home-nav a:focus-visible {
  border-color: #f06292;
  background: #fff7fa;
}
