/* The language / currency switchers (Switchers.tsx, popup.js): a pill in the
   desktop bar and one modal <dialog> per list — a centred card on a wide
   screen, the whole screen on a phone. */

/* --- The bar's pill: language code | currency code ----------------------- */
.switcher-pill {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--color-border-input);
  border-radius: var(--r-pill);
  background: var(--color-surface);
}

.switcher-pill__part {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border: 0;
  background: none;
  font: inherit;
  font-size: var(--text-sm);
  font-weight: 500;
  color: var(--ink-600);
  cursor: pointer;
}

.switcher-pill__part + .switcher-pill__part {
  border-inline-start: 1px solid var(--color-border-input);
}

.switcher-pill__part:hover {
  color: var(--color-action);
}

/* --- The dialog ---------------------------------------------------------- */
/* `margin: auto` centres the modal; the reset zeroes the UA's own. */
.switcher {
  margin: auto;
  width: min(448px, calc(100vw - var(--space-4) * 2));
  max-height: min(640px, calc(100dvh - var(--space-6) * 2));
  padding: 0;
  border: 0;
  border-radius: var(--r-lg);
  background: var(--color-surface);
  color: var(--color-text);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.2);
}

.switcher::backdrop {
  background: rgba(0, 0, 0, 0.4);
}

html:has(dialog.switcher[open]) {
  overflow: hidden;
}

/* The panel fills the dialog, so a click on the dialog itself is a backdrop
   click (popup.js). */
.switcher__panel {
  display: flex;
  flex-direction: column;
  max-height: inherit;
  padding: var(--space-4) var(--space-4) var(--space-2);
}

.switcher__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex: none;
}

.switcher__title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--color-heading);
}

.switcher__close {
  border: 0;
  background: none;
  padding: var(--space-1);
  font-size: 1.25rem;
  line-height: 1;
  color: var(--ink-500);
  cursor: pointer;
}

.switcher__intro {
  flex: none;
  margin: var(--space-2) 0 0;
  font-size: var(--text-sm);
  color: var(--ink-600);
}

.switcher__filter {
  position: relative;
  flex: none;
  margin-top: var(--space-4);
}

.switcher__filter-icon {
  position: absolute;
  inset-inline-start: var(--space-3);
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-500);
  pointer-events: none;
}

.switcher__filter-input {
  width: 100%;
  padding: var(--space-3) var(--space-3) var(--space-3) calc(var(--space-3) * 2 + 1em);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--color-bg-alt);
  /* 16px, never less: iOS zooms into a smaller field when it is tapped. */
  font: inherit;
  font-size: 1rem;
  color: var(--color-text);
}

.switcher__filter-input:focus {
  outline: none;
  border-color: var(--color-action);
}

.switcher__body {
  flex: 1;
  min-height: 0;
  margin-top: var(--space-3);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* --- Rows ------------------------------------------------------------------ */
.switcher__list {
  list-style: none;
  margin: 0;
  padding: 2px;
}

.switcher__list button,
.switcher__list a {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 56px;
  padding: var(--space-2) var(--space-3);
  border: 1.5px solid transparent;
  border-radius: var(--r-md);
  background: none;
  font: inherit;
  color: var(--color-text);
  text-align: start;
  text-decoration: none;
  cursor: pointer;
}

.switcher__list button:hover,
.switcher__list a:hover {
  background: var(--color-bg-alt);
}

.switcher__list [aria-current="true"] {
  border-color: var(--color-action);
  background: var(--color-bg-alt);
}

.switcher__flag {
  width: 26px;
  height: 18px;
  border-radius: 3px;
}

.switcher__names {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.switcher__name {
  font-size: var(--text-body);
}

[aria-current="true"] .switcher__name {
  font-weight: 600;
}

.switcher__sub,
.switcher__meta {
  font-size: var(--text-sm);
  color: var(--ink-500);
}

.switcher__meta {
  flex: none;
}

.switcher__tick {
  flex: none;
  width: 1.25em;
  color: var(--color-action);
  visibility: hidden;
}

[aria-current="true"] > .switcher__tick {
  visibility: visible;
}

/* --- Phone: the dialog is the whole screen ------------------------------- */
@media (max-width: 640px) {
  .switcher {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
  }

  .switcher__panel {
    height: 100%;
  }
}
