/* Language switcher — shared by the front, landing, admin and auth shells.
   ======================================================================
   Built on <details>/<summary>, so it opens and closes with no JavaScript
   and keeps working if the script fails. Everything is a logical property,
   so the same file serves Arabic and English.

   Each shell drops the control onto a different background — a white
   navbar, a purple hero bar, the AdminLTE header — so the surface colours
   come from custom properties on `.lang-switcher` and a variant only has
   to restate the two or three that differ. */

.lang-switcher {
  /* Toggle */
  --ls-toggle-fg: currentColor;
  --ls-toggle-bg: transparent;
  --ls-toggle-bg-hover: rgba(17, 24, 39, 0.06);
  --ls-toggle-border: rgba(17, 24, 39, 0.16);
  --ls-toggle-border-hover: rgba(17, 24, 39, 0.28);
  --ls-toggle-radius: 999px;
  --ls-toggle-padding: 7px 13px;

  /* Menu */
  --ls-surface: #fff;
  --ls-surface-border: rgba(17, 24, 39, 0.1);
  --ls-fg: #111827;
  --ls-fg-muted: #6b7280;
  --ls-accent: #4f46e5;
  --ls-accent-soft: rgba(79, 70, 229, 0.1);
  --ls-badge-bg: rgba(17, 24, 39, 0.06);
  --ls-shadow:
    0 1px 2px rgba(17, 24, 39, 0.06),
    0 8px 16px -6px rgba(17, 24, 39, 0.12),
    0 20px 40px -12px rgba(17, 24, 39, 0.2);
  --ls-focus: rgba(79, 70, 229, 0.45);

  position: relative;
  display: inline-block;
  font-size: 14px;
  line-height: 1.2;
}

.lang-switcher__details {
  position: relative;
}

/* ── Toggle ──────────────────────────────────────────────────────────── */

.lang-switcher__details > summary {
  list-style: none;
  cursor: pointer;
}

/* Both spellings: WebKit still uses the pseudo-element, the rest use ::marker. */
.lang-switcher__details > summary::-webkit-details-marker {
  display: none;
}

.lang-switcher__details > summary::marker {
  content: "";
}

.lang-switcher__toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: var(--ls-toggle-padding);
  border: 1px solid var(--ls-toggle-border);
  border-radius: var(--ls-toggle-radius);
  background: var(--ls-toggle-bg);
  color: var(--ls-toggle-fg);
  font-weight: 600;
  white-space: nowrap;
  user-select: none;
  transition:
    background-color 0.18s ease,
    border-color 0.18s ease,
    box-shadow 0.18s ease;
}

.lang-switcher__toggle:hover {
  background: var(--ls-toggle-bg-hover);
  border-color: var(--ls-toggle-border-hover);
}

.lang-switcher__details[open] > .lang-switcher__toggle {
  background: var(--ls-toggle-bg-hover);
  border-color: var(--ls-toggle-border-hover);
}

/* Keyboard users get the ring; mouse users do not. The <summary> is itself
   the toggle, so the ring goes on the same element. */
.lang-switcher__details > summary:focus {
  outline: none;
}

.lang-switcher__details > summary:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ls-focus);
}

/* Names the toggle for assistive tech without showing twice on screen. */
.lang-switcher__sr {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.lang-switcher__label {
  /* The two names are different widths, so the bar would shift on switch. */
  min-width: 3.5em;
  text-align: center;
}

.lang-switcher__caret {
  width: 15px;
  height: 15px;
  flex: 0 0 15px;
  opacity: 0.6;
  transition: transform 0.2s ease;
}

.lang-switcher__details[open] .lang-switcher__caret {
  transform: rotate(180deg);
}

/* ── Menu ────────────────────────────────────────────────────────────── */

.lang-switcher__menu {
  position: absolute;
  z-index: 1200;
  top: calc(100% + 10px);
  inset-inline-end: 0;
  min-width: 200px;
  padding: 6px;
  border-radius: 14px;
  background: var(--ls-surface);
  border: 1px solid var(--ls-surface-border);
  box-shadow: var(--ls-shadow);
  animation: lang-switcher-in 0.16s ease-out;
}

/* A <details> cannot animate shut without JS, so this is the open only. */
@keyframes lang-switcher-in {
  from {
    opacity: 0;
    transform: translateY(-6px) scale(0.985);
  }
}

.lang-switcher__menu-title {
  margin: 0;
  padding: 7px 12px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ls-fg-muted);
  text-transform: uppercase;
}

/* Arabic has no case, and letter-spacing breaks its joined forms. */
:lang(ar) .lang-switcher__menu-title,
[dir="rtl"] .lang-switcher__menu-title {
  text-transform: none;
  letter-spacing: 0;
  font-size: 12px;
}

.lang-switcher__list {
  margin: 0;
  padding: 0;
  list-style: none;
}

.lang-switcher__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 10px;
  color: var(--ls-fg);
  text-decoration: none;
  font-weight: 500;
  transition:
    background-color 0.14s ease,
    color 0.14s ease;
}

.lang-switcher__item:hover,
.lang-switcher__item:focus-visible {
  background: var(--ls-accent-soft);
  color: var(--ls-accent);
  text-decoration: none;
  outline: none;
}

.lang-switcher__item:focus-visible {
  box-shadow: 0 0 0 2px var(--ls-focus);
}

.lang-switcher__item.is-active {
  background: var(--ls-accent-soft);
  color: var(--ls-accent);
  font-weight: 600;
}

/* The code badge that replaced the flag emoji. Fixed box so the names below
   it line up whether the code is "EN" or a single Arabic letter. */
.lang-switcher__badge {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 24px;
  padding: 0 6px;
  border-radius: 7px;
  background: var(--ls-badge-bg);
  color: inherit;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}

.lang-switcher__item.is-active .lang-switcher__badge {
  background: var(--ls-accent);
  color: #fff;
}

/* The same badge on the toggle: a size smaller, and always filled, because
   it is showing the language that is currently on. */
.lang-switcher__toggle .lang-switcher__badge {
  min-width: 26px;
  height: 21px;
  padding: 0 5px;
  border-radius: 6px;
  background: var(--ls-accent);
  color: #fff;
  font-size: 11px;
}

/* The name carries its own `dir`, so it renders correctly in its own script.
   Its alignment, though, has to follow the PAGE — with `text-align: start`
   each name aligned to its own direction instead, and the two sat at
   opposite ends of the menu instead of forming a column. */
.lang-switcher__name {
  flex: 1 1 auto;
  text-align: left;
}

[dir="rtl"] .lang-switcher__name {
  text-align: right;
}

.lang-switcher__check {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  opacity: 0;
  transition: opacity 0.14s ease;
}

.lang-switcher__item.is-active .lang-switcher__check {
  opacity: 1;
}

/* ── Variants ────────────────────────────────────────────────────────── */

/* Front theme: sits on a white navbar next to the nav links. */
.lang-switcher--front {
  --ls-accent: #d97706;
  --ls-accent-soft: rgba(217, 119, 6, 0.12);
}

/* Landing hero: the toggle sits on the purple bar (and on the dark navy one
   once the header goes sticky), so it is glass rather than a grey outline —
   a plain border is nearly invisible on either. The whole treatment lives
   here now; landing-header.css only decides where it sits. */
.lang-switcher--landing {
  --ls-accent: #262261;
  --ls-accent-soft: rgba(38, 34, 97, 0.1);
  margin-inline-start: 12px;
}

.lang-switcher--landing .lang-switcher__toggle {
  height: 40px;
  padding: 0 14px;
  font-size: 13px;
  letter-spacing: 0.01em;
  color: #fff;
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.lang-switcher--landing .lang-switcher__toggle:hover {
  background: rgba(255, 255, 255, 0.24);
  border-color: rgba(255, 255, 255, 0.5);
}

/* Open, it goes solid and hands its colour to the menu underneath, so the
   two read as one surface instead of a pill with a card floating below. */
.lang-switcher--landing .lang-switcher__details[open] > .lang-switcher__toggle {
  color: #262261;
  background: #fff;
  border-color: #fff;
  box-shadow: 0 6px 16px -6px rgba(17, 24, 39, 0.45);
}

/* On the glass the badge is the bright element; once the toggle turns solid
   white it swaps, so it never disappears into whatever is behind it. */
.lang-switcher--landing .lang-switcher__toggle .lang-switcher__badge {
  background: rgba(255, 255, 255, 0.92);
  color: #262261;
}

.lang-switcher--landing .lang-switcher__details[open] > .lang-switcher__toggle .lang-switcher__badge {
  background: #262261;
  color: #fff;
}

.lang-switcher--landing .lang-switcher__menu {
  border: 0;
}

/* AdminLTE navbar: the toggle reads as one of the nav links, not a button. */
.lang-switcher--admin {
  --ls-toggle-border: transparent;
  --ls-toggle-border-hover: transparent;
  --ls-accent: #0d6efd;
  --ls-accent-soft: rgba(13, 110, 253, 0.1);
}

.lang-switcher--admin .lang-switcher__toggle {
  padding: 7px 10px;
  border-radius: 10px;
}

/* Compact, icon-first — for tight bars where the name does not fit. */
.lang-switcher--compact {
  --ls-toggle-border: transparent;
  --ls-toggle-border-hover: transparent;
}

.lang-switcher--compact .lang-switcher__toggle {
  padding: 4px 7px;
  gap: 5px;
  font-size: 12px;
}

.lang-switcher--compact .lang-switcher__label {
  min-width: 0;
}

.lang-switcher--compact .lang-switcher__menu {
  top: auto;
  bottom: calc(100% + 10px);
}

/* The landing header goes `overflow: hidden` and absolutely positions its
   children on phones, so the toggle has to shrink to clear the hamburger. */
@media (max-width: 767px) {
  .lang-switcher--landing .lang-switcher__toggle {
    height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }

  .lang-switcher--landing .lang-switcher__label {
    min-width: 0;
  }
}

/* ── Dark ────────────────────────────────────────────────────────────── */

/* Opt-in only. The previous version also had a bare
   `@media (prefers-color-scheme: dark)` block, which turned this one
   dropdown dark navy on any visitor whose OS is in dark mode — while the
   page around it stayed white, because the app has no dark theme. These
   hooks are left in place so the switcher follows a dark theme on the day
   one is added; nothing sets them today. Only the tokens change here, so
   no rule is duplicated. */
[data-theme="dark"] .lang-switcher,
.dark .lang-switcher {
  --ls-toggle-bg-hover: rgba(255, 255, 255, 0.1);
  --ls-toggle-border: rgba(255, 255, 255, 0.2);
  --ls-toggle-border-hover: rgba(255, 255, 255, 0.35);
  --ls-surface: #1b2130;
  --ls-surface-border: rgba(255, 255, 255, 0.1);
  --ls-fg: #e5e7eb;
  --ls-fg-muted: #9ca3af;
  --ls-accent: #93c5fd;
  --ls-accent-soft: rgba(147, 197, 253, 0.16);
  --ls-badge-bg: rgba(255, 255, 255, 0.1);
  --ls-shadow: 0 16px 40px -12px rgba(0, 0, 0, 0.7);
}

@media (prefers-reduced-motion: reduce) {
  .lang-switcher__menu {
    animation: none;
  }

  .lang-switcher__toggle,
  .lang-switcher__caret,
  .lang-switcher__item,
  .lang-switcher__check {
    transition: none;
  }
}
