/* The language menu, shared by every public page (alert, qr, home, 404).

   A button that shows the flag of the language the page is in, and discloses the
   list of languages. The flags live here as data: URIs, so there is one copy of
   the art, nothing to fetch, and they draw the same on Windows, where flag emoji
   come out as the letters "MK" and "GB". (The CSP on /alert/** and /qr/** already
   allows img-src data:.)

   The component takes its colours from whichever token set the page defines,
   falling back to the brand values, so it needs nothing from the page but the
   markup. The behaviour is in i18n.js (wireMenus). */

.lang-menu {
  --lm-ink: var(--text, var(--on-surface, #101615));
  --lm-dim: var(--text-dim, var(--on-surface-variant, #48534F));
  --lm-surface: var(--surface, #FFFFFF);
  --lm-line: var(--outline, var(--border, rgba(0, 0, 0, 0.12)));
  --lm-accent: var(--brand, var(--green, var(--primary, #006B5A)));
  /* A hovered row, the popover's shadow and the hairline round a flag are dark
     on a light page and light on a dark one. The page says which; a page with no
     dark theme (home, 404) keeps the light values. */
  --lm-hover: var(--hover-tint, rgba(0, 0, 0, 0.05));
  --lm-shadow: var(--pop-shadow, 0 12px 32px rgba(0, 0, 0, 0.14));
  --lm-flag-ring: var(--flag-ring, rgba(0, 0, 0, 0.14));

  /* North Macedonia: a gold sun with eight rays on red. */
  --flag-mk: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 16'%3E%3Crect width='24' height='16' fill='%23D20000'/%3E%3Cg fill='%23FFE600'%3E%3Ccircle cx='12' cy='8' r='3'/%3E%3Cpath d='M12 8L10.6-12 13.4-12z'/%3E%3Cpath d='M12 8L10.6-12 13.4-12z' transform='rotate(45 12 8)'/%3E%3Cpath d='M12 8L10.6-12 13.4-12z' transform='rotate(90 12 8)'/%3E%3Cpath d='M12 8L10.6-12 13.4-12z' transform='rotate(135 12 8)'/%3E%3Cpath d='M12 8L10.6-12 13.4-12z' transform='rotate(180 12 8)'/%3E%3Cpath d='M12 8L10.6-12 13.4-12z' transform='rotate(225 12 8)'/%3E%3Cpath d='M12 8L10.6-12 13.4-12z' transform='rotate(270 12 8)'/%3E%3Cpath d='M12 8L10.6-12 13.4-12z' transform='rotate(315 12 8)'/%3E%3C/g%3E%3C/svg%3E");

  /* The United Kingdom, simplified: the counterchange is dropped, which is not
     visible at 22px. */
  --flag-en: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 60 40'%3E%3Crect width='60' height='40' fill='%23012169'/%3E%3Cpath d='M0 0L60 40M60 0L0 40' stroke='%23fff' stroke-width='7'/%3E%3Cpath d='M0 0L60 40M60 0L0 40' stroke='%23C8102E' stroke-width='3'/%3E%3Cpath d='M30 0V40M0 20H60' stroke='%23fff' stroke-width='12'/%3E%3Cpath d='M30 0V40M0 20H60' stroke='%23C8102E' stroke-width='7'/%3E%3C/svg%3E");

  position: relative;
  display: inline-block;
}

.lang-flag {
  display: block;
  flex: none;
  width: 22px;
  height: 15px;
  border-radius: 3px;
  background: center / cover no-repeat;
  box-shadow: 0 0 0 1px var(--lm-flag-ring);
}
.lang-flag--mk { background-image: var(--flag-mk); }
.lang-flag--en { background-image: var(--flag-en); }

/* The button shows the language the page is in. i18n.js keeps <html lang> current,
   and sets it before the first paint. */
html[lang="mk"] .lang-menu-trigger .lang-flag { background-image: var(--flag-mk); }
html[lang="en"] .lang-menu-trigger .lang-flag { background-image: var(--flag-en); }

.lang-menu-trigger {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 11px 0 9px;
  color: var(--lm-dim);
  background: transparent;
  border: 1px solid var(--lm-line);
  border-radius: 999px;
  cursor: pointer;
  font: inherit;
  line-height: 1;
  transition: color 0.15s, border-color 0.15s;
}
.lang-menu-trigger:hover,
.lang-menu-trigger[aria-expanded="true"] {
  color: var(--lm-ink);
  border-color: var(--lm-ink);
}
.lang-chevron {
  display: block;
  width: 10px;
  height: 6px;
  transition: transform 0.15s;
}
.lang-menu-trigger[aria-expanded="true"] .lang-chevron { transform: rotate(180deg); }

/* Pages round every focused control to a few pixels; the pill and the rows keep
   their own shape. */
.lang-menu-trigger:focus-visible,
.lang-menu-item:focus-visible {
  outline: 2px solid var(--lm-accent);
  outline-offset: 2px;
}
.lang-menu-trigger:focus-visible { border-radius: 999px; }
.lang-menu-item:focus-visible { border-radius: 8px; }

.lang-menu-list {
  position: absolute;
  z-index: 30;
  top: calc(100% + 6px);
  right: 0;
  min-width: 172px;
  list-style: none;
  padding: 4px;
  background: var(--lm-surface);
  border: 1px solid var(--lm-line);
  border-radius: 12px;
  box-shadow: var(--lm-shadow);
}
/* `display` above would otherwise beat the UA's [hidden]. */
.lang-menu-list[hidden] { display: none; }

.lang-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  text-align: left;
  color: var(--lm-ink);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-size: 15px;
}
.lang-menu-item:hover { background: var(--lm-hover); }
.lang-menu-item.is-active { font-weight: 600; }
/* The current language gets a tick as well as the weight. */
.lang-menu-item.is-active::after {
  content: "";
  flex: none;
  width: 5px;
  height: 10px;
  margin: -3px 2px 0 auto;
  border: solid var(--lm-accent);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

@media (prefers-reduced-motion: reduce) {
  .lang-menu-trigger,
  .lang-chevron { transition: none; }
}
