/* The language menu, and what changes on the page when it is set to Hebrew or Arabic.
 *
 * Injected on every page after the template's own stylesheet, like nav.css, so
 * it wins on order rather than on !important.
 */

/* --- placement ------------------------------------------------------------- */
/* Every toolbar is `justify-content: space-between`. On the dashboard pages its
   children are the brand and the profile menu; `margin-left: auto` keeps the
   language menu beside the profile picture instead of in the middle. On the
   public pages `.toolbar-nav` already carries that auto margin, so the menu
   follows it without a second one splitting the free space. */
.pn-lang {
  position: relative;
  display: inline-flex;
  align-items: center;
  margin-left: auto;
  margin-right: 12px;
  font-family: 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  line-height: 1;
}

.toolbar-nav ~ .pn-lang {
  margin-left: 8px;
}

.pn-lang:last-child {
  margin-right: 0;
}

.pn-lang-floating {
  position: fixed;
  top: 14px;
  right: 14px;
  margin: 0;
  z-index: 1100;
}

/* --- the button -------------------------------------------------------------- */
.pn-lang-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 38px;
  padding: 0 10px 0 11px;
  border-radius: 12px;
  border: 1px solid rgba(120, 130, 200, 0.22);
  background: rgba(28, 35, 58, 0.55);
  color: #eef1fb;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  transition: border-color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.pn-lang-btn svg {
  width: 17px;
  height: 17px;
  flex: 0 0 auto;
}

.pn-lang-chev {
  display: inline-flex;
  opacity: 0.7;
}

.pn-lang-chev svg {
  width: 14px;
  height: 14px;
  transition: transform 0.2s ease;
}

.pn-lang-btn[aria-expanded="true"] .pn-lang-chev svg {
  transform: rotate(180deg);
}

.pn-lang-btn:hover {
  border-color: rgba(120, 140, 255, 0.45);
  background: rgba(40, 48, 80, 0.7);
}

.pn-lang-btn[aria-expanded="true"] {
  border-color: rgba(120, 140, 255, 0.55);
  box-shadow: 0 0 0 3px rgba(109, 92, 255, 0.18);
}

.pn-lang-btn:focus-visible,
.pn-lang-item:focus-visible {
  outline: 2px solid #5b8bff;
  outline-offset: 2px;
}

/* --- the list ---------------------------------------------------------------- */
.pn-lang-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 240px;
  max-height: min(72vh, 540px);
  overflow-y: auto;
  padding: 6px;
  border-radius: 16px;
  background: rgba(20, 26, 48, 0.97);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  border: 1px solid rgba(120, 130, 200, 0.22);
  box-shadow: 0 24px 60px -18px rgba(0, 0, 0, 0.75), 0 0 40px -20px rgba(109, 92, 255, 0.45);
  z-index: 1100;
  transform-origin: top right;
  animation: pn-lang-in 0.16s ease-out;
  scrollbar-width: thin;
  scrollbar-color: #2a335a transparent;
}

.pn-lang-menu[hidden] {
  display: none;
}

@keyframes pn-lang-in {
  from { opacity: 0; transform: translateY(-6px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.pn-lang-head {
  padding: 8px 10px 7px;
  color: #9aa3c4;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.pn-lang-item {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 8px 10px;
  margin: 1px 0;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: #d7dcf2;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.2;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.pn-lang-item:hover,
.pn-lang-item:focus-visible {
  background: rgba(120, 130, 200, 0.14);
  color: #ffffff;
}

.pn-lang-item[aria-checked="true"] {
  background: linear-gradient(100deg, rgba(91, 139, 255, 0.2), rgba(109, 92, 255, 0.2));
  color: #ffffff;
}

.pn-lang-badge {
  flex: 0 0 auto;
  width: 30px;
  height: 22px;
  display: inline-grid;
  place-items: center;
  border-radius: 6px;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.05em;
  color: #c7d2fe;
  background: rgba(91, 139, 255, 0.12);
  border: 1px solid rgba(120, 140, 255, 0.28);
}

.pn-lang-item[aria-checked="true"] .pn-lang-badge {
  color: #ffffff;
  background: linear-gradient(135deg, #5b8bff, #8b5cf6);
  border-color: transparent;
  box-shadow: 0 6px 16px -8px rgba(109, 92, 255, 0.9);
}

.pn-lang-name {
  flex: 1;
  text-align: start;
}

.pn-lang-check {
  display: inline-flex;
  color: #8aa0ff;
  opacity: 0;
}

.pn-lang-check svg {
  width: 16px;
  height: 16px;
}

.pn-lang-item[aria-checked="true"] .pn-lang-check {
  opacity: 1;
}

@media (max-width: 767px) {
  .pn-lang {
    margin-right: 8px;
  }

  .pn-lang-btn {
    height: 34px;
    padding: 0 8px;
    gap: 5px;
  }

  .pn-lang-chev {
    display: none;
  }

  /* Anchored to the screen, not the button: the button sits near the right
     edge of a narrow header and a 240px list hung from it runs off the left. */
  .pn-lang-menu {
    position: fixed;
    top: 62px;
    right: 10px;
    width: min(260px, calc(100vw - 20px));
  }
}

@media (prefers-reduced-motion: reduce) {
  .pn-lang-menu { animation: none; }
  .pn-lang-chev svg { transition: none; }
}

/* --- right-to-left languages -------------------------------------------------- */
/* The layout is not mirrored: the sidebar and toolbar are fixed-position and a
   flipped `dir` would leave them where they are while everything else moved.
   What matters for reading is that each paragraph takes its direction from its
   own text - so Hebrew sentences end with their punctuation on the correct
   side, and an English role name inside them stays readable. */
html[data-pn-dir="rtl"] :is(p, h1, h2, h3, h4, h5, h6, li, label, td, th, dt, dd, legend,
                            small, span, a, button, option, input, textarea, .form-text) {
  unicode-bidi: plaintext;
}
