/* components/email-preferences.css — layout for partials/email-preferences.hbs,
   the signed-in view of /newsletters/: Portal's Email preferences screen as a
   centred panel, one row per newsletter with a switch, then "Unsubscribe from
   all emails".
   The switch is the checkbox (.sr-only, role="switch") plus a presentational
   track after it, drawn like the footer's .theme-toggle__track so the two
   switches match. The list is a <fieldset disabled> until
   assets/js/email-preferences.js has loaded the member. */

.email-preferences {
  display: grid;
  gap: var(--space-6);
  max-inline-size: 32rem;
  margin-block: var(--space-16);
  margin-inline: auto;
  padding: var(--space-6);
  border: var(--border-width) solid var(--color-border-soft);
  border-radius: var(--radius);
  font-family: var(--font-ui);
}

@media (width >= 48rem) {
  .email-preferences {
    padding: var(--space-10);
  }
}

.email-preferences__title {
  margin: 0;
  font-family: var(--font-heading);
  font-size: var(--text-2xl);
  font-weight: var(--weight-heading);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-snug);
  text-align: center;
}

.email-preferences__list {
  display: grid;
  min-inline-size: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

/* The whole row is the <label>, so it all toggles, as in Portal. */
.email-preferences__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-6);
  padding-block: var(--space-4);
  border-block-end: var(--border-width) solid var(--color-border-soft);
  cursor: pointer;
}

.email-preferences__list:disabled .email-preferences__item {
  cursor: progress;
  opacity: var(--card-hover-opacity);
}

.email-preferences__detail {
  display: grid;
  gap: var(--space-1);
}

.email-preferences__name {
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  line-height: var(--leading-snug);
}

.email-preferences__description {
  color: var(--color-fg-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

/* The switch */

.email-preferences__switch {
  position: relative;
  flex-shrink: 0;
  inline-size: 2.5rem;
  block-size: 1.375rem;
  border: var(--border-width) solid var(--color-border);
  border-radius: 999px;
  transition: background-color var(--transition);
}

/* Knob sized off the track so they stay concentric. */
.email-preferences__switch::after {
  content: "";
  position: absolute;
  inset-block-start: 50%;
  inset-inline-start: 0.1875rem;
  inline-size: 0.875rem;
  block-size: 0.875rem;
  border-radius: 50%;
  background-color: currentColor;
  translate: 0 -50%;
  transition: translate var(--transition), background-color var(--transition);
}

/* On: knob right, track filled with the ink and the knob the page colour. */
.email-preferences__input:checked + .email-preferences__switch {
  background-color: var(--color-fg);
}

.email-preferences__input:checked + .email-preferences__switch::after {
  background-color: var(--color-bg);
  translate: 1.125rem -50%;
}

.email-preferences__input:focus-visible + .email-preferences__switch {
  outline: var(--focus-width) solid var(--color-focus);
  outline-offset: var(--focus-offset);
}

/* Unsubscribe, messages, note */

.email-preferences__unsubscribe {
  inline-size: 100%;
  margin-block-start: var(--space-6);
  color: var(--color-danger);
  border-color: var(--color-danger);
}

.email-preferences__unsubscribe:is(:hover, :focus-visible):not(:disabled) {
  background-color: var(--color-danger);
  color: var(--color-bg);
}

/* Beats .button--outline's hover fill, which would otherwise still show. */
.email-preferences__unsubscribe.button--outline:disabled {
  background-color: transparent;
  color: var(--color-danger);
  opacity: var(--card-hover-opacity);
  cursor: not-allowed;
}

.email-preferences__message,
.email-preferences__note {
  margin: 0;
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
  text-align: center;
}

/* Empty until email-preferences.js writes into it. */
.email-preferences__message:empty {
  display: none;
}

.email-preferences__message--error {
  color: var(--color-danger);
}

.email-preferences__note {
  color: var(--color-fg-muted);
}
