// shared styles used
// on both the login and
// create account modals
.login-modal,
.create-account {
  .modal-body {
    &.has-alt-auth {
      background: var(--tertiary-or-tertiary-low);
    }
  }
  .btn-flat.btn.modal-close svg {
    color: rgba(var(--primary-rgb), 0.5);
    &:hover {
      color: rgba(var(--primary-rgb), 0.85);
    }
  }
  h2.login-with {
    color: var(--secondary);
  }
  #login-buttons:not(.hidden) {
    display: flex;
    flex: 0 1 auto;
    flex-direction: column;
    align-items: stretch;
    min-height: 75px;
    min-width: 200px;
    order: 2;

    &:focus-within,
    &:hover {
      button:not(:hover):not(:focus) {
        opacity: 0.75;
      }
    }

    button {
      margin: 0.35em 0;
      &:first-of-type {
        margin-top: 0;
      }
      &:last-of-type {
        margin-bottom: 0;
      }
      &:lang(zh_CN) {
        min-width: 200px;
      }
      &:first-of-type:last-of-type {
        &.oauth2_basic {
          // Handles a strange fringe case where OAuth2 and account approval are enabled
          margin-left: auto;
          margin-right: auto;
          justify-content: center;
        }
      }
    }
  }

  .tip {
    display: block;
    overflow: hidden;
    word-wrap: break-word;
    margin-bottom: 0;
    max-width: 280px;
    @media screen and (min-width: 500px) {
      max-width: 400px;
    }
  }
}

.has-alt-auth {
  .tip {
    max-width: 100%;
  }
}

.login-modal:not(.hidden).has-alt-auth.no-local-login {
  padding: 0 2em !important;
  min-width: 350px !important;
  .login-right-side {
    width: 100%;
    padding: 2em 0;
    #login-buttons:not(.hidden) {
      width: 80%;
      .btn.btn-social:first-of-type {
        margin-top: 2em;
      }
      .btn.btn-social,
      .btn,
      .login-with-email-button {
        border: 1px solid var(--primary-low-mid);
        margin-bottom: 0.5em;
        &:hover,
        &:focus {
          background: var(--primary-very-low) !important;
        }
      }
    }
  }
}

// styles used on
// login modal only
.login-modal:not(.hidden) {
  padding: 0 !important;
  .login-modal-body.has-alt-auth {
    min-width: 100%;
    .login-left-side {
      align-self: stretch;
    }
    .login-right-side {
      padding: 0 3em;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      #login-buttons {
        button {
          &.login-with-email-button {
            border-radius: 4px;
            .d-icon {
              color: #000 !important;
            }
            &:hover,
            &:focus {
              box-shadow: 0 0 0 2px rgba(var(--primary-rgb), 0.25);
              .d-icon {
                color: #000 !important;
              }
            }
          }
        }
      }
    }
  }
  .login-left-side {
    background: var(--secondary);
    width: calc(100% - 4em);
    display: flex;
    flex-direction: column;
    padding: 3em 3em 2.5em;
    .login-welcome-header {
      .login-title {
        line-height: var(--line-height-small);
        font-size: var(--font-up-6);
      }
      p.login-subheader {
        font-size: var(--font-up-1);
      }
    }
    #credentials {
      display: flex;
      flex-direction: column;
      align-items: flex-start !important;
    }
    #login-form {
      margin: 3em 0 1.25em 0;
    }
    .modal-footer {
      display: flex;
      flex-direction: row;
      width: 100%;
      padding: 0;
      border: 0;
    }
  }

  .modal-body,
  #credentials {
    display: flex;
    align-items: center;

    &.hidden {
      display: none;
    }
  }
}

.login-modal-body.second-factor {
  max-width: 30em;
  .login-left-side {
    width: 100%;
    #login-form {
      margin: 2em 0 0 0;
    }
  }
  #new-account-link {
    display: none;
  }
  .modal-footer {
    margin-top: 1em;
  }
}

.login-form {
  .tip {
    &:not(:empty) {
      min-height: 1.75em;
      &.bad .svg-icon {
        vertical-align: middle;
      }
    }
  }
}

// styles used on the
// create account
// modal only
.d-modal.create-account {
  .create-account-body {
    min-width: 100%;
  }
  .modal-body {
    overflow: hidden;
  }
  .has-alt-auth .create-account-form {
    display: grid;
    grid-template-columns: 60% 40%;
    grid-template-rows: auto 1fr;
    grid-template-areas:
      "header login-buttons"
      "form login-buttons"
      "footer login-buttons";
  }
  .create-account-form {
    display: flex;
    flex-direction: column;
    width: 100%;
    position: relative;
  }
  .create-account-login-buttons {
    display: none;
  }
  .has-alt-auth .create-account-login-buttons {
    grid-area: login-buttons;
    padding: 1em;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    h3 {
      color: var(--secondary);
      text-align: center;
    }
    #login-buttons {
      button:first-of-type {
        margin-top: 0;
      }
    }
  }
  .modal-body {
    display: flex;
    padding: 0;
  }
  .modal-footer {
    grid-area: footer;
    background-color: var(--secondary);
    position: relative;
    &:before {
      content: "";
      display: block;
      position: absolute;
      width: 100%;
      pointer-events: none;
      top: calc(-2em - 1px);
      left: 0;
      height: 2em;
      background-image: linear-gradient(
        to bottom,
        rgba(var(--secondary-rgb), 0),
        rgba(var(--secondary-rgb), 1)
      );
    }
  }
  .login-welcome-header {
    grid-area: header;
    padding: 3em 2em 1em;

    .login-title {
      font-size: var(--font-up-6);
      line-height: var(--line-height-medium);
    }
    p.login-subheader {
      font-size: var(--font-up-1);
      align-self: start;
    }
  }

  .modal-body:not(.has-alt-auth) .login-form {
    &:after {
      width: 100%;
    }
  }

  .has-alt-auth .login-form,
  .login-form {
    background: var(--secondary);
    padding: 1em 0 0 0;
    grid-area: form;
    overflow-y: scroll;

    .input-group {
      padding: 0 2em;
      margin-bottom: 1em;
      input {
        width: 100%;
      }
      input:not(.value-entered):not(:focus) + label.alt-placeholder {
        top: 12px;
        left: 3em;
      }
      input:focus + label.alt-placeholder,
      input.value-entered + label.alt-placeholder {
        top: -8px;
        left: calc(3em - 0.25em);
      }
    }
    .password-confirmation {
      display: none;
    }
    scrollbar-color: rgba(var(--primary-rgb), 0.5) transparent;
    &::-webkit-scrollbar {
      width: 15px;
    }

    &::-webkit-scrollbar-track {
      box-shadow: inset 0 0 14px 14px transparent;
      border: 4px solid transparent;
    }

    &::-webkit-scrollbar-thumb {
      box-shadow: inset 0 0 14px 14px rgba(var(--primary-rgb), 0.5);
      border: 4px solid transparent;
      border-radius: 14px;
    }

    /* set button(top and bottom of the scrollbar) */
    &::-webkit-scrollbar-button {
      display: none;
    }
  }

  .user-fields {
    margin-bottom: 1em;
  }

  .user-field {
    &.text {
      label.control-label {
        left: 3em !important;
        max-width: calc(100% - 6em) !important;
      }
      &.value-entered label.control-label,
      label.control-label.value-entered {
        left: calc(3em - 0.25em) !important;
      }
    }
    display: flex;
    flex-direction: column;
    &.confirm {
      margin-top: 5px;
    }
  }

  .invites-show {
    padding-top: 20px;

    .two-col {
      margin-top: 30px;
    }
    .col-form {
      margin-left: 200px;
      .inline-invite-img {
        display: none;
      }
    }
    form {
      .controls,
      .input {
        margin-left: 20px;
      }
      input,
      label {
        margin-bottom: 0;
      }
      .user-field .control-label:not(.checkbox-label) {
        margin-left: 20px;
      }
    }
  }

  .tos-agree {
    margin-bottom: 12px;
  }
}

.password-reset,
.invites-show {
  .col-form {
    padding: 0.5em 2em 1em;
    max-width: 30em;
  }
  .col-image {
    width: 175px;
    img {
      width: 100%;
    }
  }
  details {
    width: 100%;
  }
  h2 {
    margin-bottom: 12px;
  }
  input:not([type="checkbox"]) {
    // 80% width on checkboxes messes up the layout for custom fields
    width: 80%;
  }
  .invite-form,
  .invite-success {
    box-shadow: shadow("card");
  }
}

.password-reset {
  .col-form {
    padding-top: 40px;
  }
}

// styling for small-width desktop screens
// when editing, test with DiscourseHub auth window on iPadOS
// it has a window width of ~650px
@media screen and (max-width: 700px) {
  .d-modal.create-account,
  .d-modal.login-modal {
    .modal-inner-container {
      width: 100%;
    }

    .modal-body:not(.reorder-categories):not(.poll-ui-builder):not(.poll-breakdown) {
      max-height: 90vh !important; // overrides base/modal.scss
    }
    .login-welcome-header,
    .login-left-side .login-welcome-header {
      padding-top: 1em;
      .login-title {
        font-size: var(--font-up-4);
      }
      p.login-subheader {
        font-size: var(--font-0);
      }
    }

    .modal-footer .btn:last-of-type {
      margin-right: 0;
    }
  }

  .d-modal.login-modal .login-modal-body.has-alt-auth {
    .login-left-side {
      padding-left: 1.5em;
      padding-right: 1em;
      padding-top: 1em;
      .modal-footer {
        width: auto;
        .btn-large {
          padding-left: 12px;
          padding-right: 12px;
        }
      }
    }
    .login-right-side {
      padding: 1em;
    }
  }
}

.email-login {
  width: 550px;
  .password-reset-img {
    height: 150px;
  }
}
