@use "~styles/mixins" as *;
@use "~styles/basic/defaults/fonts" as *;

/*
  The WordPress login screen, wearing this design.

  WHY THIS FILE EXISTS AND /vhod/ DOES NOT. The obvious move was a login page of
  our own inside the site frame. It was the wrong one, for four reasons found by
  reading core rather than guessing:

    · it would not REPLACE wp-login.php. docker/entrypoint.sh symlinks it at the
      docroot, so the original stays reachable — a second door, not a new one,
      and every security argument for the second evaporates while the first is
      open.
    · not weakening anything means re-implementing the test cookie for both
      cookie paths (wp-login.php:530-535), the use_ssl → secure_cookie promotion
      with its force_ssl_admin side effect (:1294-1308), redirect_to defaults
      with the https rewrite and the capability fallbacks that keep a subscriber
      out of wp-admin (:1310-1318, :1413-1419), reauth cookie clearing (:1485),
      interim_login (:1362-1386), the headers_sent guard (:1325) and the
      login_redirect / wp_login_errors filters. Every one is a place to be
      subtly wrong about authentication.
    · WPS Hide Login is installed on this stack. A public /vhod/ answering on the
      same site defeats its entire purpose the day anyone switches it on.
    · one page carries login, «забыли пароль», the reset form and the logout
      confirmation. Restyling gets all four; a custom form gets one and leaves
      the other three looking like 2010.

  So: not a line of authentication is touched. Only the paint.

  The values are the ones the rest of the site already uses — the modal at
  prototype 999-1058 for the card, its field at 1036, its label at 1035, the
  header's brand mark, and the notice colours from _account.scss. Tokens come
  from the separately enqueued _constants entry, so a rebrand still edits one
  file.
*/

body.login {
  background: var(--theme-bg-page);
  font-family: var(--theme-text-ff);
  color: var(--theme-text-color-default);

  &, *, *::before, *::after {
    box-sizing: border-box;
  }

  // Core centres #login with `margin: auto` and a fixed padding; the design's
  // own centred panel (prototype 1000) uses a 24px gutter, which is what keeps
  // a card off the edges of a 375px screen.
  #login {
    width: 100%;
    max-width: #{toRem(420px)};
    padding: #{toRem(48px)} #{toRem(24px)};

    @media (max-width: 480px) {
      padding: #{toRem(32px)} #{toRem(16px)};
    }
  }

  // ---- the brand, in place of the WordPress mark ----

  // Core ships `h1 a` as a text-indented block with the W logo as a background
  // image. The whole thing is rebuilt: the text comes back, the image goes, and
  // the letter square is drawn the way the site header draws it.
  h1 a {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: #{toRem(10px)};
    width: auto;
    height: auto;
    margin: 0 auto #{toRem(24px)};
    padding: 0;
    background: none;
    text-indent: 0;
    overflow: visible;
    font-size: #{toRem(19px)};
    font-weight: 800;
    letter-spacing: #{toRem(-0.4px)};
    line-height: 1;
    color: var(--theme-heading-color);

    &::before {
      content: "A";
      display: flex;
      align-items: center;
      justify-content: center;
      width: #{toRem(32px)};
      height: #{toRem(32px)};
      border-radius: #{toRem(9px)};
      background: var(--theme-primary-color);
      color: var(--theme-base-light);
      font-size: #{toRem(17px)};
      font-weight: 800;
      flex: none;
    }

    &:focus {
      box-shadow: none;
      outline: var(--theme-focus-ring);
      outline-offset: var(--theme-focus-ring-offset);
    }
  }

  // ---- the card ----

  form {
    margin-top: 0;
    padding: #{toRem(26px)} #{toRem(28px)};
    border: 1px solid var(--theme-border-color);
    border-radius: var(--theme-radius-lg);
    background: var(--theme-base-light);
    box-shadow: var(--theme-sm-shadow);
    font-weight: 400;

    @media (max-width: 480px) {
      padding: #{toRem(24px)} #{toRem(20px)};
    }
  }

  label {
    display: block;
    margin-bottom: #{toRem(8px)};
    font-size: #{toRem(12.5px)};
    font-weight: 800;
    letter-spacing: #{toRem(1px)};
    text-transform: uppercase;
    color: var(--theme-text-color-alternative);
  }

  // The prototype's own field (1036). `.input` as well as the bare elements,
  // because core styles them by class and by attribute at once.
  input[type="text"],
  input[type="email"],
  input[type="password"],
  .input {
    width: 100%;
    height: auto;
    margin: 0 0 #{toRem(16px)};
    padding: #{toRem(13px)} #{toRem(16px)};
    border: 1px solid var(--theme-border-interactive);
    border-radius: var(--theme-radius-md);
    background: var(--theme-base-light);
    box-shadow: none;
    font-family: var(--theme-text-ff);
    font-size: #{toRem(15px)};
    font-weight: 600;
    line-height: 1.4;
    color: var(--theme-heading-color);

    &:focus {
      border-color: var(--theme-primary-color);
      box-shadow: none;
      outline: var(--theme-focus-ring);
      outline-offset: var(--theme-focus-ring-offset);
    }
  }

  // The password field wraps its input so the reveal button can sit inside it;
  // the margin has to move to the wrapper or the two rows collide.
  .user-pass-wrap {
    margin-bottom: #{toRem(16px)};

    .input {
      margin-bottom: 0;
      padding-right: #{toRem(48px)};
    }
  }

  .wp-hide-pw {
    top: 0;
    right: 0;
    width: #{toRem(46px)};
    height: 100%;
    color: var(--theme-text-color-alternative);

    &:hover,
    &:focus {
      color: var(--theme-primary-color);
      background: none;
      box-shadow: none;
    }

    &:focus-visible {
      outline: var(--theme-focus-ring);
      outline-offset: #{toRem(-2px)};
    }

    .dashicons {
      width: #{toRem(20px)};
      height: #{toRem(20px)};
      font-size: #{toRem(20px)};
    }
  }

  // ---- «запомнить меня» ----

  // The design has no checkbox anywhere in 1743 lines, so there is nothing to
  // copy — this is core's own control, sized and coloured to sit quietly under
  // the fields rather than restyled into something the design never drew.
  // The checkbox is core's SIBLING of the label, not its child, so the row has
  // to be the flex container — putting it on the label leaves the two stacked.
  // `form` in the selector is load-bearing: core's `.login form .forgetmenot
  // { margin-bottom: 0 }` ties our two-class selector on specificity and wins
  // on order. One extra element outranks it regardless of load order.
  form .forgetmenot {
    // Core floats this row left, which lifts it out of flow — the button
    // rides up over it and the margin below pushes nothing. Un-float first,
    // THEN the flex row and the margin behave.
    float: none;
    display: flex;
    align-items: center;
    gap: #{toRem(8px)};
    margin-bottom: #{toRem(18px)};

    label {
      margin: 0;
      font-size: #{toRem(14px)};
      font-weight: 600;
      letter-spacing: 0;
      text-transform: none;
      color: var(--theme-text-color-default);
      cursor: pointer;
    }

    input[type="checkbox"] {
      width: #{toRem(18px)};
      height: #{toRem(18px)};
      margin: 0;
      border: 1px solid var(--theme-border-interactive);
      border-radius: var(--theme-radius-xs);
      background: var(--theme-base-light);

      &:checked {
        border-color: var(--theme-primary-color);
        background: var(--theme-primary-color);

        &::before {
          margin: #{toRem(-2px)} 0 0 #{toRem(-2px)};
          color: var(--theme-base-light);
        }
      }

      &:focus {
        border-color: var(--theme-primary-color);
        box-shadow: none;
        outline: var(--theme-focus-ring);
        outline-offset: var(--theme-focus-ring-offset);
      }
    }
  }

  // ---- the button ----

  .submit {
    margin: 0;
  }

  // The 18px between the remember-row and the button lives HERE, on the
  // button's own id, after two rounds of core's login.css re-zeroing every
  // margin we hung on .forgetmenot. An id outranks anything core ships, and
  // the intent — space above the button — reads clearer on the button anyway.
  #wp-submit {
    margin-top: #{toRem(18px)};
  }

  .button-primary {
    float: none;
    width: 100%;
    height: auto;
    padding: #{toRem(13px)} #{toRem(26px)};
    border: 0;
    border-radius: var(--theme-button-radius);
    background: var(--theme-primary-color);
    box-shadow: none;
    text-shadow: none;
    font-family: inherit;
    font-size: #{toRem(15px)};
    font-weight: 800;
    line-height: 1.3;
    color: var(--theme-base-light);
    transition: background-color var(--theme-transition);

    &:hover,
    &:active {
      background: var(--theme-primary-hover);
      color: var(--theme-base-light);
    }

    &:focus {
      background: var(--theme-primary-hover);
      box-shadow: none;
      outline: var(--theme-focus-ring);
      outline-offset: var(--theme-focus-ring-offset);
    }
  }

  // ---- messages ----

  // The site has exactly one error style and one success style — `.an-notice`
  // in _account.scss. Core's own red-left-border box is replaced by them rather
  // than by a third invention.
  #login_error,
  .message,
  .notice,
  .success {
    margin: 0 0 #{toRem(20px)};
    padding: #{toRem(14px)} #{toRem(18px)};
    border: 1px solid transparent;
    border-left-width: 1px;
    border-radius: var(--theme-radius-md);
    box-shadow: none;
    font-size: #{toRem(14.5px)};
    font-weight: 700;
    line-height: 1.5;

    a {
      color: inherit;
      text-decoration: underline;
    }
  }

  #login_error {
    background: var(--theme-alternative-soft);
    border-color: var(--theme-alternative-border);
    color: var(--theme-alternative-color);
  }

  .message,
  .notice,
  .success {
    background: var(--theme-primary-soft);
    border-color: var(--theme-primary-color);
    color: var(--theme-primary-link);
  }

  // Core marks a successful password reset with `.notice-success`; that one is
  // the site's green.
  .notice-success,
  #login .success {
    background: var(--theme-secondary-soft);
    border-color: var(--theme-secondary-color);
    color: var(--theme-secondary-strong);
  }

  // ---- the links under the card ----

  #nav,
  #backtoblog {
    margin: #{toRem(16px)} 0 0;
    padding: 0;
    text-align: center;
    font-size: #{toRem(14px)};
    font-weight: 700;

    a {
      color: var(--theme-primary-color);
      text-decoration: none;

      &:hover {
        color: var(--theme-primary-hover);
        text-decoration: underline;
      }

      &:focus {
        box-shadow: none;
        outline: var(--theme-focus-ring);
        outline-offset: var(--theme-focus-ring-offset);
      }
    }
  }

  #backtoblog {
    margin-top: #{toRem(10px)};
    font-weight: 600;

    a {
      color: var(--theme-text-color-alternative);

      &:hover {
        color: var(--theme-primary-color);
      }
    }
  }

  // The strength meter and the reset form's hint text.
  #pass-strength-result {
    margin: #{toRem(-8px)} 0 #{toRem(16px)};
    padding: #{toRem(10px)} #{toRem(14px)};
    border-radius: var(--theme-radius-sm);
    border: 1px solid var(--theme-border-nested);
    background: var(--theme-base-soft);
    font-size: #{toRem(13px)};
    font-weight: 700;
    text-align: left;

    &.short,
    &.bad {
      background: var(--theme-alternative-soft);
      border-color: var(--theme-alternative-border);
      color: var(--theme-alternative-color);
    }

    &.good,
    &.strong {
      background: var(--theme-secondary-soft);
      border-color: var(--theme-secondary-color);
      color: var(--theme-secondary-strong);
    }
  }

  .description,
  .indicator-hint,
  p:not(.submit):not(.forgetmenot) {
    font-size: #{toRem(13.5px)};
    line-height: 1.5;
    color: var(--theme-text-color-alternative);
  }

  // The language picker core puts below the card.
  .language-switcher {
    margin-top: #{toRem(18px)};

    select {
      border-radius: var(--theme-radius-sm);
      border: 1px solid var(--theme-border-interactive);
      font-family: var(--theme-text-ff);
      font-size: #{toRem(13px)};
    }

    .button {
      border-radius: var(--theme-radius-sm);
      border: 1px solid var(--theme-border-interactive);
      background: var(--theme-base-light);
      font-family: var(--theme-text-ff);
      font-size: #{toRem(13px)};
      font-weight: 700;
      color: var(--theme-text-color-default);
    }
  }

  .privacy-policy-page-link {
    margin-top: #{toRem(20px)};

    a {
      font-size: #{toRem(13px)};
      color: var(--theme-text-color-alternative);
    }
  }
}
