/**
 * @file
 * The Nafath widget, from the "Revamp GEP" Figma design (node 2871:73540).
 *
 * Every value the design pins down is a custom property whose fallback is the
 * Figma token, so a theme can restyle the widget without editing this file.
 * Where a Figma colour is exactly a theme token it is expressed as that token:
 * #1b8354 is --primary-sa-600, #d2d6db is --neutral-gray-300 and #384250 is
 * --neutral-gray-700.
 *
 * Box properties use logical directions, so the same rules serve Arabic and
 * English with no RTL override.
 */

.nafath-card {
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--nafath-card-gap, 24px);
  inline-size: 100%;
  max-inline-size: var(--nafath-card-width, 616px);
  /* The design frames the card at 679px for the sign-in step and 609px for
     the waiting step. A minimum, not a fixed height, so a longer
     translation or a narrow screen grows the card instead of clipping it. */
  min-block-size: var(--nafath-card-height, 679px);
  margin-block: 2rem;
  margin-inline: auto;
  padding: var(--nafath-card-padding, 16px);
  background: var(--nafath-card-background, var(--white, #fff));
  border: 1px solid var(--nafath-card-border-color, var(--neutral-gray-300, #d2d6db));
  border-radius: var(--nafath-card-radius, 16px);
  box-shadow: var(
    --nafath-card-shadow,
    0 2px 4px -2px rgba(16, 24, 40, 0.06),
    0 4px 8px -2px rgba(16, 24, 40, 0.1)
  );
}

/* The fieldset wrapper is replaced by this card, so strip anything a theme
   may still be putting on the group. */
.nafath-card > legend {
  display: none;
}

/* The card's gap is the only vertical spacing; a theme's own stacking
   margins on these children would add to it and break the design's rhythm. */
/* The card's gap is the only vertical spacing between its children.
   The theme sets `.webform-submission-form .form-item { margin-bottom: 24px }`,
   which is two classes like any `.nafath-card .form-item` would be, and its
   stylesheet loads after this one, so it would win a tie. These selectors use
   the two classes Drupal already puts on the wrapper to sit one level above
   it. */
.nafath-card > *,
.nafath-card .js-form-item.form-item {
  margin-block: 0;
}

.nafath-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  inline-size: 100%;
  min-block-size: var(--nafath-logo-block, 173.214px);
  padding-block-start: var(--nafath-logo-space, 24px);
}

.nafath-logo img {
  display: block;
  /* The design places the mark at its natural size. */
  max-inline-size: 100%;
  block-size: auto;
}

/* Headings and the waiting instruction share one type ramp in the design. */
.nafath-card__heading,
.nafath-wait__hint {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-block-size: var(--nafath-heading-block, 97px);
}

.nafath-card__heading,
.nafath-wait__title,
.nafath-wait__hint {
  margin: 0;
  max-inline-size: var(--nafath-text-width, 448px);
  font-family: var(--nafath-font, IBMPlexSansArabic, "IBM Plex Sans Arabic", sans-serif);
  font-size: var(--nafath-heading-size, 25px);
  font-weight: 500;
  line-height: var(--nafath-heading-line, 34px);
  letter-spacing: -0.2px;
  text-align: center;
  color: var(--nafath-text-color, #161616);
}

/* The field column: label, input and buttons all share one width. The theme
   shrinks form items and inputs to fit their content, so this is specific
   enough to win over it. */
.nafath-card .js-form-item.form-item.nafath-card__field {
  inline-size: 100%;
  width: 100%;
  max-inline-size: var(--nafath-field-width, 439px);
}

/* Outranks the theme's fixed 380px on
   `.webform-submission-form .form-item input:not([type=radio]):not([type=checkbox])`. */
.nafath-card .js-form-item.form-item.nafath-card__field input.form-text {
  width: 100%;
  max-width: none;
}

.nafath-card__field label {
  display: flex;
  gap: var(--nafath-label-gap, 4px);
  align-items: flex-end;
  justify-content: flex-start;
  text-align: start;
  margin-block-end: var(--nafath-label-space, 8px);
  font-size: var(--nafath-label-size, 14px);
  line-height: 20px;
  font-weight: 400;
  color: var(--nafath-label-color, #161616);
}

/* Drupal already prints the required marker; this only gives it the design's
   colour, so the asterisk is not drawn twice. */
.nafath-card__field label .form-required::after,
.nafath-card__field label.form-required::after {
  color: var(--nafath-required-color, #b42318);
}

.nafath-card__field input[type="text"] {
  box-sizing: border-box;
  display: block;
  inline-size: 100%;
  block-size: var(--nafath-input-height, 40px);
  padding-inline-start: var(--nafath-input-pad-start, 8px);
  padding-inline-end: var(--nafath-input-pad-end, 16px);
  font-size: var(--nafath-input-size, 14px);
  line-height: 20px;
  /* Follows the page, so Arabic aligns to the right and English to the left,
     as the two language versions of the design show. */
  text-align: start;
  color: var(--nafath-input-color, var(--neutral-gray-700, #384250));
  background: var(--nafath-input-background, var(--white, #fff));
  border: 1px solid var(--nafath-input-border, #9da4ae);
  border-radius: var(--nafath-control-radius, 4px);
}

.nafath-card__field input[type="text"]:focus {
  outline: 2px solid var(--nafath-accent, var(--primary-sa-600, #1b8354));
  outline-offset: 1px;
  border-color: var(--nafath-accent, var(--primary-sa-600, #1b8354));
}

.nafath-card__field .description {
  margin-block-start: 0.375rem;
  font-size: 13px;
  color: var(--nafath-muted-color, var(--neutral-gray-600, #4d5761));
}

.nafath-card .nafath-button {
  box-sizing: border-box;
  inline-size: 100%;
  /* The design gives the action the same 439px as the field, so the two line
     up exactly, and sets it 32px below it. The card's own gap carries 24 of
     those, so 8 is added here. */
  max-inline-size: var(--nafath-field-width, 439px);
  block-size: var(--nafath-button-height, 40px);
  margin-inline: 0;
  margin-block-end: 0;
  margin-block-start: var(--nafath-action-space, 8px);
  padding-block: 0;
  padding-inline: var(--nafath-button-pad, 16px);
  font-family: var(--nafath-font, IBMPlexSansArabic, "IBM Plex Sans Arabic", sans-serif);
  font-size: var(--nafath-button-size, 16px);
  font-weight: 500;
  line-height: 24px;
  text-align: center;
  cursor: pointer;
  border-radius: var(--nafath-control-radius, 4px);
  color: var(--nafath-button-text, var(--white, #fff));
  background: var(--nafath-accent, var(--primary-sa-600, #1b8354));
  border: 1px solid var(--nafath-accent, var(--primary-sa-600, #1b8354));
}

.nafath-card .nafath-button:hover,
.nafath-card .nafath-button:focus {
  background: var(--nafath-accent-strong, var(--primary-sa-700, #166a45));
  border-color: var(--nafath-accent-strong, var(--primary-sa-700, #166a45));
}

/* The design shows the action greyed out until the field is filled. */
.nafath-card .nafath-button[disabled],
.nafath-card .nafath-button[aria-disabled="true"] {
  cursor: not-allowed;
  color: var(--nafath-disabled-text, var(--neutral-gray-600, #4d5761));
  background: var(--nafath-disabled-background, var(--neutral-gray-200, #e5e7eb));
  border-color: var(--nafath-disabled-background, var(--neutral-gray-200, #e5e7eb));
}

/* A second action sits 16px under the first, inside the card's 24px gap. */
.nafath-card .nafath-button + .nafath-button {
  margin-block-start: calc(16px - var(--nafath-card-gap, 24px));
}

/* Secondary actions (continue without Nafath, sign out) read as quiet next to
   the primary. */
.nafath-card .nafath-button--quiet {
  color: inherit;
  background: transparent;
  border-color: var(--nafath-card-border-color, var(--neutral-gray-300, #d2d6db));
}

.nafath-card .nafath-button--quiet:hover,
.nafath-card .nafath-button--quiet:focus {
  background: var(--nafath-disabled-background, var(--neutral-gray-200, #e5e7eb));
  border-color: var(--nafath-card-border-color, var(--neutral-gray-300, #d2d6db));
}

/* Waiting state. */
.nafath-wait {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--nafath-card-gap, 24px);
  inline-size: 100%;
}

.nafath-wait__number {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Sized by the design, but it grows for a wider number: the specification
     places no bound on how many digits Nafath returns. */
  min-inline-size: var(--nafath-code-size, 100px);
  block-size: var(--nafath-code-size, 100px);
  padding-inline: 1rem;
  margin: 0;
  border-radius: 50%;
  background: var(--nafath-code-background, rgba(78, 168, 166, 0.18));
  font-family: var(--nafath-font, IBMPlexSansArabic, "IBM Plex Sans Arabic", sans-serif);
  font-size: var(--nafath-code-text-size, 36px);
  font-weight: 500;
  line-height: 34px;
  text-align: center;
  color: var(--nafath-code-color, #303030);
  /* Keeps the digits in Western order inside an Arabic page. */
  direction: ltr;
  unicode-bidi: isolate;
}

.nafath-wait__state {
  margin: 0;
  text-align: center;
  color: var(--nafath-muted-color, var(--neutral-gray-600, #4d5761));
}

.nafath-wait__state--error {
  font-weight: 600;
  color: var(--nafath-required-color, #b42318);
}

/* Why the visitor was sent back to the sign-in step (expired, rejected). */
.nafath-card__error {
  inline-size: 100%;
  max-inline-size: var(--nafath-text-width, 448px);
  margin: 0;
  text-align: center;
  font-weight: 600;
  color: var(--nafath-required-color, #b42318);
}

/* The [hidden] attribute must win over the card's display rules. */
.nafath-wait__state[hidden] {
  display: none;
}

.nafath-verified {
  inline-size: 100%;
  max-inline-size: var(--nafath-text-width, 448px);
  text-align: center;
  font-weight: 500;
}

/* Verified: a one-line notice above the form instead of the card. */
.nafath-signed-in {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  inline-size: 100%;
  margin-block-end: 24px;
}

.nafath-signed-in .nafath-verified {
  inline-size: auto;
  max-inline-size: none;
  margin: 0;
  text-align: start;
}

.nafath-signed-in .nafath-button {
  inline-size: auto;
  block-size: 32px;
  margin: 0;
  padding-inline: 12px;
  font-size: 14px;
  color: inherit;
  background: transparent;
  border: 1px solid var(--nafath-card-border-color, var(--neutral-gray-300, #d2d6db));
  border-radius: var(--nafath-control-radius, 4px);
  cursor: pointer;
}

.nafath-unavailable {
  margin: 0;
  max-inline-size: var(--nafath-text-width, 448px);
  text-align: center;
  font-weight: 600;
}

@media (max-width: 480px) {
  .nafath-card__heading,
  .nafath-wait__title,
  .nafath-wait__hint {
    font-size: 20px;
    line-height: 28px;
  }
}


/* The waiting step is framed shorter than the sign-in step. */
.nafath-card--wait {
  --nafath-card-height: 609px;
  --nafath-logo-block: 155.357px;
}

/* Below the card's own width the fixed frame heights only add empty space. */
@media (max-width: 680px) {
  .nafath-card {
    --nafath-card-height: 0;
    --nafath-logo-block: 0;
    --nafath-heading-block: 0;
  }
}

/* Outside a webform the theme draws no required marker, so the Nafath page
   adds the design's red asterisk itself. */
.nafath-webform-gate-form .nafath-card__field label.form-required::after {
  content: "*";
}
